feat(new tool): CSS Gradient Generator

Fix #1111
This commit is contained in:
ShareVB committed 2025-11-30 22:48:12 +01:00
1 parent ecb81ec535
commit 86683d81d6
2 files changed
+124

No files matched your search

@@ -0,0 +1,111 @@
<script setup lang="ts">
import _ from 'lodash';
import { useITStorage, useQueryParamOrStorage } from '@/composable/queryParams';
const gradientType = useQueryParamOrStorage({ name: 'type', storageName: 'css-gradients:t', defaultValue: 'linear' });
const angle = useQueryParamOrStorage({ name: 'angle', storageName: 'css-gradients:a', defaultValue: 90 });
const colorStops = useITStorage('css-gradients:s', [
{ color: '#ff0000', position: 0 },
{ color: '#0000ff', position: 100 },
]);
const gradientCSS = computed(() => {
const stops = _.orderBy(colorStops.value, 'position')
.map(({ color, position }) => `${color} ${position}%`)
.join(', ');
return gradientType.value === 'linear'
? `linear-gradient(${angle.value}deg, ${stops})`
: `radial-gradient(${stops})`;
});
function addStop() {
colorStops.value.push({ color: '#ffffff', position: 50 });
}
function removeStop(index: number) {
colorStops.value.splice(index, 1);
}
</script>
<template>
<div>
<NForm label-placement="left">
<n-space justify="center">
<NFormItem label="Gradient Type:">
<NRadioGroup v-model:value="gradientType">
<NRadioButton value="linear">
Linear
</NRadioButton>
<NRadioButton value="radial">
Radial
</NRadioButton>
</NRadioGroup>
</NFormItem>
<NFormItem v-if="gradientType === 'linear'" label="Angle (degrees):">
<NSlider v-model:value="angle" :min="0" :max="360" :step="1" mr-1 />
<n-input-number :value="angle" />
</NFormItem>
</n-space>
<c-card title="Color Stops">
<div class="color-stop-list" w-full>
<div
v-for="(stop, index) in colorStops"
:key="index"
class="color-stop-item"
>
<NColorPicker v-model:value="stop.color" />
<NInputNumber
v-model:value="stop.position"
:min="0"
:max="100"
:step="1"
style="width: 150px"
/>
<NButton size="small" type="error" @click="removeStop(index)">
Remove
</NButton>
</div>
</div>
<n-space justify="center">
<NButton type="primary" size="small" @click="addStop">
Add Color Stop
</NButton>
</n-space>
</c-card>
<c-card title="Preview" mt-1>
<div class="preview" :style="{ background: gradientCSS }" />
</c-card>
<c-card title="Generated CSS" mt-1>
<textarea-copyable :value="gradientCSS" language="css" />
</c-card>
</NForm>
</div>
</template>
<style scoped>
.color-stop-list {
max-height: 300px;
overflow-y: auto;
border: 1px solid #ddd;
padding: 8px;
border-radius: 6px;
margin-bottom: 8px;
}
.color-stop-item {
display: flex;
align-items: center;
gap: 8px;
margin-bottom: 8px;
}
.preview {
height: 150px;
border-radius: 8px;
margin: 16px 0;
border: 1px solid #ccc;
}
</style>
+13
View File
@@ -0,0 +1,13 @@
import { Rainbow } from '@vicons/tabler';
import { defineTool } from '../tool';
export const tool = defineTool({
name: 'CSS Gradient Generator',
path: '/css-gradient-generator',
description: 'Generate CSS Gradient css code for a given set of steps and colors',
keywords: ['css', 'gradient', 'generator'],
component: () => import('./css-gradient-generator.vue'),
icon: Rainbow,
createdAt: new Date('2025-11-29'),
category: 'Web',
});