From 765434b93545be95e65a786e41e735237e233579 Mon Sep 17 00:00:00 2001 From: BaptisteAuscher Date: Wed, 8 Apr 2026 22:23:52 +0200 Subject: [PATCH] code rabbit --- src/components/ui/color-picker.tsx | 33 +++++++++++++++++------------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/src/components/ui/color-picker.tsx b/src/components/ui/color-picker.tsx index eed2f02..a1b78d5 100644 --- a/src/components/ui/color-picker.tsx +++ b/src/components/ui/color-picker.tsx @@ -5,20 +5,24 @@ import { useEffect, useState } from "react"; import { Button } from "./button"; import { Input } from "./input"; -export default function ColorPicker({ - selectedColor, - colorPalette, - translations, - clearBackgroundOption = false, - onUpdateColor, -}: { +type BaseProps = { selectedColor: string; colorPalette: string[]; - translations: Record<"colorWheel" | "colorPalette", string> & - Partial>; - clearBackgroundOption?: boolean; onUpdateColor: (color: string) => void; -}) { +}; + +type ColorPickerProps = + | (BaseProps & { + clearBackgroundOption?: false; + translations: Record<"colorWheel" | "colorPalette", string>; + }) + | (BaseProps & { + clearBackgroundOption: true; + translations: Record<"colorWheel" | "colorPalette" | "clearBackground", string>; + }); + +export default function ColorPicker(props: ColorPickerProps) { + const { selectedColor, colorPalette, translations, onUpdateColor } = props; const [colorMode, setColorMode] = useState<"wheel" | "palette">("wheel"); const [hexInput, setHexInput] = useState(selectedColor); const [transparentColorHSVA, setTransparentColorHSVA] = useState({ @@ -64,6 +68,7 @@ export default function ColorPicker({ }; const toTransparent = (color: string) => { + if (color === "transparent") return; const hsva = hexToHsva(color); hsva.a = 0; return hsva; @@ -137,18 +142,18 @@ export default function ColorPicker({ }} /> )} - {clearBackgroundOption && ( + {props.clearBackgroundOption === true && ( )}