|
| 1 | +import React, { useState } from 'react'; |
| 2 | +import { Link } from 'react-router-dom'; |
| 3 | +import { ArrowLeftIcon } from '@phosphor-icons/react'; |
| 4 | +import colors from '../../config/colors'; |
| 5 | +import usePageTitle from '../../utils/usePageTitle'; |
| 6 | +import { useToast } from '../../hooks/useToast'; |
| 7 | + |
| 8 | +function ColorPaletteGeneratorPage() { |
| 9 | + usePageTitle('Color Palette Generator'); |
| 10 | + const [palette, setPalette] = useState([]); |
| 11 | + const { addToast } = useToast(); |
| 12 | + |
| 13 | + const generateRandomHexColor = () => { |
| 14 | + return '#' + Math.floor(Math.random() * 16777215).toString(16).padStart(6, '0'); |
| 15 | + }; |
| 16 | + |
| 17 | + const generatePalette = () => { |
| 18 | + const newPalette = Array.from({ length: 5 }, generateRandomHexColor); |
| 19 | + setPalette(newPalette); |
| 20 | + }; |
| 21 | + |
| 22 | + const copyToClipboard = (text) => { |
| 23 | + navigator.clipboard.writeText(text) |
| 24 | + .then(() => { |
| 25 | + addToast({ |
| 26 | + title: 'Success', |
| 27 | + message: `Copied ${text} to clipboard!`, |
| 28 | + duration: 2000, |
| 29 | + }); |
| 30 | + }) |
| 31 | + .catch(() => { |
| 32 | + addToast({ |
| 33 | + title: 'Error', |
| 34 | + message: 'Failed to copy!', |
| 35 | + duration: 2000, |
| 36 | + }); |
| 37 | + }); |
| 38 | + }; |
| 39 | + |
| 40 | + const cardStyle = { |
| 41 | + backgroundColor: colors['app-alpha-10'], |
| 42 | + borderColor: colors['app-alpha-50'], |
| 43 | + color: colors.app, |
| 44 | + }; |
| 45 | + |
| 46 | + return ( |
| 47 | + <div className="py-16 sm:py-24"> |
| 48 | + <div className="mx-auto max-w-7xl px-6 lg:px-8 text-gray-300"> |
| 49 | + <Link |
| 50 | + to="/apps" |
| 51 | + className="text-article hover:underline flex items-center justify-center gap-2 text-lg mb-4" |
| 52 | + > |
| 53 | + <ArrowLeftIcon size={24} /> Back to Apps |
| 54 | + </Link> |
| 55 | + <h1 className="text-4xl font-bold tracking-tight sm:text-6xl mb-4 flex items-center"> |
| 56 | + <span className="codex-color">fc</span> |
| 57 | + <span className="separator-color">::</span> |
| 58 | + <span className="apps-color">apps</span> |
| 59 | + <span className="separator-color">::</span> |
| 60 | + <span className="single-app-color">colors</span> |
| 61 | + </h1> |
| 62 | + <hr className="border-gray-700" /> |
| 63 | + <div className="flex justify-center items-center mt-16"> |
| 64 | + <div |
| 65 | + className="group bg-transparent border rounded-lg shadow-2xl p-6 flex flex-col justify-between relative transform transition-all duration-300 ease-in-out scale-105 overflow-hidden h-full w-full max-w-4xl" |
| 66 | + style={cardStyle} |
| 67 | + > |
| 68 | + <div |
| 69 | + className="absolute top-0 left-0 w-full h-full opacity-10" |
| 70 | + style={{ |
| 71 | + backgroundImage: |
| 72 | + 'radial-gradient(circle, white 1px, transparent 1px)', |
| 73 | + backgroundSize: '10px 10px', |
| 74 | + }} |
| 75 | + ></div> |
| 76 | + <div className="relative z-10 p-1"> |
| 77 | + <div className="flex justify-center gap-4 mb-4"> |
| 78 | + <button |
| 79 | + onClick={generatePalette} |
| 80 | + className="px-6 py-2 rounded-md text-lg font-arvo font-normal transition-colors duration-300 ease-in-out" |
| 81 | + style={{ |
| 82 | + backgroundColor: 'rgba(0, 0, 0, 0.2)', |
| 83 | + color: cardStyle.color, |
| 84 | + borderColor: cardStyle.borderColor, |
| 85 | + border: '1px solid', |
| 86 | + '--hover-bg-color': colors['app-alpha-50'], |
| 87 | + }} |
| 88 | + onMouseEnter={(e) => e.currentTarget.style.backgroundColor = 'var(--hover-bg-color)'} |
| 89 | + onMouseLeave={(e) => e.currentTarget.style.backgroundColor = 'rgba(0, 0, 0, 0.2)'} |
| 90 | + > |
| 91 | + Generate New Palette |
| 92 | + </button> |
| 93 | + </div> |
| 94 | + <div className="grid grid-cols-1 sm:grid-cols-2 md:grid-cols-3 lg:grid-cols-5 gap-4 mt-4"> |
| 95 | + {palette.map((color, index) => ( |
| 96 | + <div |
| 97 | + key={index} |
| 98 | + className="flex flex-col items-center p-4 rounded-md cursor-pointer transition-transform duration-200 hover:scale-105" |
| 99 | + style={{ backgroundColor: color }} |
| 100 | + onClick={() => copyToClipboard(color)} |
| 101 | + > |
| 102 | + <span className="text-white font-semibold text-shadow-sm" style={{ textShadow: '1px 1px 2px rgba(0,0,0,0.8)' }}>{color}</span> |
| 103 | + </div> |
| 104 | + ))} |
| 105 | + </div> |
| 106 | + </div> |
| 107 | + </div> |
| 108 | + </div> |
| 109 | + </div> |
| 110 | + </div> |
| 111 | + ); |
| 112 | +} |
| 113 | + |
| 114 | +export default ColorPaletteGeneratorPage; |
0 commit comments