Skip to content

Commit 68b0b97

Browse files
committed
added : making custom gradient maker
1 parent b0a5a55 commit 68b0b97

File tree

4 files changed

+126
-2
lines changed

4 files changed

+126
-2
lines changed

package-lock.json

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
"posthog-js": "^1.118.0",
4444
"raw-loader": "^4.0.2",
4545
"react": "^18.2.0",
46+
"react-colorful": "^5.6.1",
4647
"react-dom": "^18.2.0",
4748
"react-highlight-words": "^0.20.0",
4849
"react-syntax-highlighter": "^15.5.0",

src/app/(docs)/effects/gradients/page.mdx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import GradientCards from '@/showcase/effects/gradients/GradientCards'
2-
2+
import CustomGradientGenerator
3+
from '@/showcase/effects/gradients/CustomGradientGenerator'
34
export const metadata = {
45
title: 'Gradients',
56
description: 'A gradient is a color that is applied to an object to create a visual effect.',
@@ -10,5 +11,5 @@ export const metadata = {
1011
Beautiful Tailwind CSS gradients for your next project.
1112

1213
<div className="my-4"></div>
13-
14+
<CustomGradientGenerator/>
1415
<GradientCards />
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
'use client'
2+
import Card from '@/showcase/ui-group/Card'
3+
import { motion, AnimatePresence } from 'framer-motion'
4+
import { Check, Copy } from 'lucide-react'
5+
import { useState } from 'react'
6+
import { toast } from 'sonner'
7+
import { HexColorPicker } from "react-colorful";
8+
import { Popover } from '@headlessui/react'
9+
10+
const CustomGradientGenerator = () => {
11+
const [copied, setCopied] = useState(false)
12+
const [fromColor, setFromColor] = useState("#aabbcc");
13+
const [viaColor, setViaColor] = useState("#aabbcc");
14+
const [toColor, setToColor] = useState("#ddeeff");
15+
let gradient = `radial-gradient(circle, ${fromColor},${viaColor} ,${toColor})`;
16+
17+
const copyGradient = () => {
18+
navigator.clipboard.writeText(gradient)
19+
setCopied(true)
20+
setTimeout(() => setCopied(false), 1000)
21+
toast.success('Gradient copied to clipboard!')
22+
}
23+
24+
const variants = {
25+
hidden: { opacity: 0, scale: 0.5 },
26+
visible: { opacity: 1, scale: 1 },
27+
}
28+
29+
return (
30+
<div className="grid md:grid-cols-2 grid-cols-1 py-2 my-4 gap-4">
31+
<div className='w-full'>
32+
<button className='w-full' onClick={copyGradient}>
33+
<Card title="Your Gradient">
34+
<div
35+
className={`relative flex h-full w-full items-center justify-center rounded-lg rounded-b-none`}
36+
style={{ background: gradient }}
37+
>
38+
<div className="inset-0 flex items-center justify-center rounded-lg bg-gray-900 p-2 text-white opacity-0 transition-opacity duration-300 group-hover:opacity-100">
39+
<AnimatePresence mode="wait" initial={false}>
40+
{copied ? (
41+
<motion.span
42+
key="checkmark"
43+
variants={variants}
44+
initial="hidden"
45+
animate="visible"
46+
exit="hidden"
47+
>
48+
<Check size={16} />
49+
</motion.span>
50+
) : (
51+
<motion.span
52+
key="copy"
53+
variants={variants}
54+
initial="hidden"
55+
animate="visible"
56+
exit="hidden"
57+
>
58+
<Copy size={16} />
59+
</motion.span>
60+
)}
61+
</AnimatePresence>
62+
</div>
63+
</div>
64+
</Card>
65+
</button>
66+
</div>
67+
68+
<div className="flex items-start justify-between px-5 pt-2 gap-3 rounded-xl border border-white ring-1 ring-zinc-200 transition-all ease-in-out hover:cursor-pointer dark:border-transparent dark:ring-zinc-700">
69+
<Popover className="relative ">
70+
<Popover.Button className="p-2 border-2 dark:border-zinc-800 border-zinc-200 flex items-center gap-2 justify-between rounded-lg">
71+
<span>From</span>
72+
<div className='h-5 w-5' style={{ backgroundColor: fromColor }}></div>
73+
</Popover.Button>
74+
75+
76+
<Popover.Panel className="absolute z-10">
77+
<HexColorPicker color={fromColor} onChange={setFromColor} />
78+
</Popover.Panel>
79+
</Popover>
80+
<Popover className="relative ">
81+
82+
83+
<Popover.Button className="p-2 border-2 dark:border-zinc-800 border-zinc-200 flex items-center gap-2 justify-between rounded-lg">
84+
<span>Via</span>
85+
<div className='h-5 w-5' style={{ backgroundColor: viaColor }}></div>
86+
</Popover.Button>
87+
88+
89+
<Popover.Panel className="absolute z-10 right-0">
90+
<HexColorPicker color={viaColor} onChange={setViaColor} />
91+
</Popover.Panel>
92+
</Popover>
93+
<Popover className="relative ">
94+
95+
96+
<Popover.Button className="p-2 border-2 dark:border-zinc-800 border-zinc-200 flex items-center gap-2 justify-between rounded-lg">
97+
<span>To</span>
98+
<div className='h-5 w-5' style={{ backgroundColor: toColor }}></div>
99+
</Popover.Button>
100+
101+
102+
<Popover.Panel className="absolute z-10 right-0">
103+
<HexColorPicker color={toColor} onChange={setToColor} />
104+
</Popover.Panel>
105+
</Popover>
106+
</div>
107+
</div>
108+
);
109+
}
110+
111+
export default CustomGradientGenerator;

0 commit comments

Comments
 (0)