diff --git a/app/components/ui/color-picker.tsx b/app/components/ui/color-picker.tsx new file mode 100644 index 0000000..7737513 --- /dev/null +++ b/app/components/ui/color-picker.tsx @@ -0,0 +1,76 @@ +import { useEffect, useState } from 'react'; +import { Pipette } from 'lucide-react'; +import { Input } from '~/components/ui/input'; +import { normalizeHex } from '~/lib/color'; +import { cn } from '~/lib/utils'; +import type { ColorPreset } from '~/types/project'; + +const swatch = 'relative h-[26px] w-[26px] shrink-0 cursor-pointer rounded-full transition-shadow'; +const ring = (selected: boolean) => (selected ? 'ring-2 ring-text-primary ring-offset-2 ring-offset-surface-dialog' : 'ring-1 ring-inset ring-text-primary/15'); + +interface ColorPickerProps { + id: string; + label: string; + value: string; + presets: ColorPreset[]; + onChange: (hex: string) => void; +} + +// Preset swatches, a custom swatch that opens the system colour picker, and a hex field +export function ColorPicker({ id, label, value, presets, onChange }: ColorPickerProps) { + const [draft, setDraft] = useState(value); + const isCustom = !presets.some((preset) => preset.value === value); + + // Keep the hex field in step when a swatch or the system picker changes the colour + useEffect(() => setDraft(value), [value]); + + return ( +