import React, { useState } from 'react'; import Image from 'next/image'; import { ColorScheme } from '../utils/colorSchemes'; import { generateYAML } from '../utils/yamlExport'; import { Highlight, themes } from 'prism-react-renderer'; import { motion, useAnimation } from 'framer-motion'; import ColorPalette from './ColorPalette'; interface ColorSchemeCardProps { scheme: ColorScheme; onLike: () => void; onDislike: () => void; index: number; isDarkMode: boolean; } const ColorSchemeCard: React.FC = ({ scheme, onLike, onDislike, index, isDarkMode }) => { const [overlayColor, setOverlayColor] = useState('rgba(0, 0, 0, 0)'); const controls = useAnimation(); const codeExample = ` // User object and function const user = { name: 'DWS', power: 8999 }; class Shape { constructor(color) { this.color = color; } } // Async data fetch simulation async function fetchData() { return await new Promise(resolve => setTimeout(() => resolve('Data loaded'), 500)); } const [even, odd] = [2, 4, 6, 8].reduce(([e, o], n) => n % 2 ? [e, [...o, n]] : [ [...e, n], o ], [ [], [] ]); /* Logging here */ fetchData().then(data => console.log(data)); `; const handleDownload = (e: React.MouseEvent) => { e.stopPropagation(); const yaml = generateYAML(scheme); const blob = new Blob([yaml], { type: 'text/yaml' }); const url = URL.createObjectURL(blob); const a = document.createElement('a'); a.href = url; a.download = `${scheme.name.replace(/\s+/g, '_').toLowerCase()}.yaml`; document.body.appendChild(a); a.click(); document.body.removeChild(a); URL.revokeObjectURL(url); }; const handleLike = () => { setOverlayColor('rgba(0, 255, 0, 0.1)'); controls.start({ x: 300, opacity: 0, transition: { duration: 0.3 } }).then(onLike); }; const handleDislike = () => { setOverlayColor('rgba(255, 0, 0, 0.1)'); controls.start({ x: -300, opacity: 0, transition: { duration: 0.3 } }).then(onDislike); }; return ( { if (offset.x > 100) handleLike(); else if (offset.x < -100) handleDislike(); }} >

{scheme.name}

{({ className, style, tokens, getLineProps, getTokenProps }) => (
                {tokens.slice(0, 20).map((line, i) => (
                  
{line.map((token, key) => { let color = scheme.colors.primary.foreground; if (token.types.includes('keyword')) color = scheme.colors.normal.blue; if (token.types.includes('string')) color = scheme.colors.normal.green; if (token.types.includes('number')) color = scheme.colors.normal.magenta; if (token.types.includes('comment')) color = scheme.colors.bright.black; if (token.types.includes('function')) color = scheme.colors.normal.yellow; if (token.types.includes('operator')) color = scheme.colors.normal.cyan; if (token.types.includes('class-name')) color = scheme.colors.bright.magenta; if (token.types.includes('constant')) color = scheme.colors.bright.red; if (token.types.includes('punctuation')) color = scheme.colors.bright.cyan; if (token.types.includes('variable')) color = scheme.colors.bright.yellow; return ; })}
))}
)}
); }; export default ColorSchemeCard;