From fca99d6126c31fbb18ed9f1034cee6f940b040e8 Mon Sep 17 00:00:00 2001 From: Maze Winther Date: Tue, 10 Feb 2026 16:28:21 +0100 Subject: refactor --- apps/web/src/components/ui/button.tsx | 7 ++++--- apps/web/src/components/ui/color-picker.tsx | 19 +++++++++++++++---- apps/web/src/components/ui/command.tsx | 2 +- apps/web/src/components/ui/dropdown-menu.tsx | 2 +- apps/web/src/components/ui/font-picker.tsx | 6 +++--- apps/web/src/components/ui/input-with-back.tsx | 4 ++-- apps/web/src/components/ui/label.tsx | 2 +- apps/web/src/components/ui/popover.tsx | 1 - apps/web/src/components/ui/select.tsx | 6 +++--- apps/web/src/components/ui/slider.tsx | 2 +- apps/web/src/components/ui/split-button.tsx | 4 ++-- apps/web/src/components/ui/tabs.tsx | 2 +- 12 files changed, 34 insertions(+), 23 deletions(-) (limited to 'apps/web/src/components/ui') diff --git a/apps/web/src/components/ui/button.tsx b/apps/web/src/components/ui/button.tsx index 6c063eff..2fc2c2e6 100644 --- a/apps/web/src/components/ui/button.tsx +++ b/apps/web/src/components/ui/button.tsx @@ -10,7 +10,7 @@ const buttonVariants = cva( variants: { variant: { default: - "bg-primary text-primary-foreground hover:bg-primary-hover", + "bg-primary text-primary-foreground hover:bg-primary/90", background: "bg-background text-foreground hover:bg-background/90", foreground: @@ -22,13 +22,14 @@ const buttonVariants = cva( outline: "border border-border bg-transparent hover:bg-accent/50", secondary: - "bg-secondary text-secondary-foreground hover:bg-foreground/15 border border-input", + "bg-secondary text-secondary-foreground border border-secondary-border", text: "bg-transparent rounded-none opacity-100 hover:opacity-75", + ghost: "bg-transparent hover:bg-accent", link: "text-primary underline-offset-4 hover:underline !p-0 !h-auto", }, size: { default: "h-9.5 px-4 py-2", - sm: "h-8 px-3 text-xs", + sm: "h-8 p-1 px-2 text-xs rounded-sm", lg: "h-10 p-5 px-6", icon: "size-7", text: "p-0", diff --git a/apps/web/src/components/ui/color-picker.tsx b/apps/web/src/components/ui/color-picker.tsx index a57a86e0..0ea1a14d 100644 --- a/apps/web/src/components/ui/color-picker.tsx +++ b/apps/web/src/components/ui/color-picker.tsx @@ -6,6 +6,7 @@ import { Input } from "./input"; interface ColorPickerProps { value?: string; onChange?: (value: string) => void; + onChangeEnd?: (value: string) => void; className?: string; containerRef?: React.RefObject; } @@ -86,7 +87,7 @@ const hsvToHex = (h: number, s: number, v: number) => { }; const ColorPicker = forwardRef( - ({ className, value = "FFFFFF", onChange, containerRef, ...props }, ref) => { + ({ className, value = "FFFFFF", onChange, onChangeEnd, containerRef, ...props }, ref) => { const [isOpen, setIsOpen] = useState(false); const [isDragging, setIsDragging] = useState<"saturation" | "hue" | null>( null, @@ -102,6 +103,7 @@ const ColorPicker = forwardRef( const saturationRef = useRef(null); const hueRef = useRef(null); const triggerRef = useRef(null); + const latestDragColorRef = useRef(null); const [h, s, v] = hexToHsv(value); const displayHue = s > 0 ? h : internalHue; @@ -144,6 +146,7 @@ const ColorPicker = forwardRef( const newS = x; const newV = 1 - y; const newHex = hsvToHex(displayHue, newS, newV); + latestDragColorRef.current = newHex; onChange?.(newHex); } @@ -157,12 +160,17 @@ const ColorPicker = forwardRef( setInternalHue(newH); if (s > 0) { const newHex = hsvToHex(newH, s, v); + latestDragColorRef.current = newHex; onChange?.(newHex); } } }; const handleMouseUp = () => { + if (latestDragColorRef.current !== null && onChangeEnd) { + onChangeEnd(latestDragColorRef.current); + latestDragColorRef.current = null; + } setIsDragging(null); }; @@ -187,6 +195,7 @@ const ColorPicker = forwardRef( const newS = x; const newV = 1 - y; const newHex = hsvToHex(displayHue, newS, newV); + latestDragColorRef.current = newHex; onChange?.(newHex); }; @@ -201,6 +210,7 @@ const ColorPicker = forwardRef( setInternalHue(newH); if (s > 0) { const newHex = hsvToHex(newH, s, v); + latestDragColorRef.current = newHex; onChange?.(newHex); } }; @@ -235,14 +245,14 @@ const ColorPicker = forwardRef(