Skip to content

Commit ae387a5

Browse files
committed
fix : code cleaning
1 parent ed24b15 commit ae387a5

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed

src/lib/convertToTailwind.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
export function generateTailwindGradient({
2+
shape,
3+
direction,
4+
from,
5+
via,
6+
to
7+
}: {
8+
shape: string;
9+
direction: string;
10+
from: string;
11+
via: string;
12+
to: string;
13+
}): string {
14+
return `bg-[radial-gradient(${shape}_at_${direction},_var(--tw-gradient-stops))] from-[${from}] via-[${via}] to-[${to}]`;
15+
}
16+
17+
18+
19+

src/showcase/effects/gradients/CustomGradientGenerator.tsx

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { HexColorPicker } from "react-colorful";
77
import { Fragment, useState } from 'react'
88
import { Listbox, Popover, Transition } from '@headlessui/react'
99
import { gradientDirection, gradientShape } from '@/data/GradientData'
10+
import { generateTailwindGradient } from '@/lib/convertToTailwind'
1011

1112

1213
const CustomGradientGenerator = () => {
@@ -17,9 +18,15 @@ const CustomGradientGenerator = () => {
1718
const [selected, setSelected] = useState(gradientDirection[0])
1819
const [shapes, setShapes] = useState(gradientShape[0])
1920
const gradient = `radial-gradient(${shapes.value} at ${selected.value}, ${fromColor},${viaColor},${toColor})`;
20-
21+
const tailwindGradient= generateTailwindGradient({
22+
shape: shapes.value,
23+
direction: selected.value,
24+
from: fromColor,
25+
via: viaColor,
26+
to: toColor
27+
});
2128
const copyGradient = () => {
22-
navigator.clipboard.writeText(gradient)
29+
navigator.clipboard.writeText(tailwindGradient)
2330
setCopied(true)
2431
setTimeout(() => setCopied(false), 1000)
2532
toast.success('Gradient copied to clipboard!')

0 commit comments

Comments
 (0)