From e21173c8e4589ef97350b75f4ca3a3ece9202bbf Mon Sep 17 00:00:00 2001 From: Tanishq Dubey Date: Mon, 9 Sep 2024 16:02:26 -0400 Subject: [PATCH] History, more icons, color palette component --- app/components/ColorPalette.tsx | 79 ++++++++++++++++++++++++++++++ app/components/ColorSchemeCard.tsx | 18 ++----- app/components/HistoryPopup.tsx | 69 ++++++++++++++++++++++++++ app/page.tsx | 34 +++++++++++-- public/close-icon-dark.svg | 7 +++ public/close-icon-light.svg | 7 +++ public/history-icon-dark.svg | 7 +++ public/history-icon-light.svg | 7 +++ 8 files changed, 212 insertions(+), 16 deletions(-) create mode 100644 app/components/ColorPalette.tsx create mode 100644 app/components/HistoryPopup.tsx create mode 100644 public/close-icon-dark.svg create mode 100644 public/close-icon-light.svg create mode 100644 public/history-icon-dark.svg create mode 100644 public/history-icon-light.svg diff --git a/app/components/ColorPalette.tsx b/app/components/ColorPalette.tsx new file mode 100644 index 0000000..03e5408 --- /dev/null +++ b/app/components/ColorPalette.tsx @@ -0,0 +1,79 @@ +import React, { useState, useRef } from 'react'; + +interface ColorPaletteProps { + colors: string[]; + size?: 'small' | 'large'; +} + +const ColorPalette: React.FC = ({ colors, size = 'small' }) => { + const [copiedColor, setCopiedColor] = useState(null); + const [hoveredColor, setHoveredColor] = useState(null); + const textAreaRef = useRef(null); + + const handleColorClick = (color: string) => { + if (navigator.clipboard && navigator.clipboard.writeText) { + navigator.clipboard.writeText(color).then(() => { + setCopiedColor(color); + setTimeout(() => setCopiedColor(null), 1500); + }); + } else { + // Fallback method for iOS and other unsupported browsers + const textArea = textAreaRef.current; + if (textArea) { + textArea.value = color; + textArea.select(); + try { + document.execCommand('copy'); + setCopiedColor(color); + setTimeout(() => setCopiedColor(null), 1500); + } catch (err) { + console.error('Failed to copy color: ', err); + } + textArea.blur(); + } + } + }; + + const sizeClasses = size === 'small' ? 'w-full pt-full' : 'w-8 h-8 pt-full'; + + return ( + <> +
+ {colors.map((color, index) => ( +
handleColorClick(color)} + onMouseEnter={() => setHoveredColor(color)} + onMouseLeave={() => setHoveredColor(null)} + > + {size === 'small' && hoveredColor === color && ( +
+
+ {color} +
+ )} + {size === 'large' && ( +
+ {color} +
+ )} + {copiedColor === color && ( +
+ Copied! +
+ )} +
+ ))} +
+