|
| 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