Skip to content

Commit 3cd7e01

Browse files
committed
feat(editor): use hex format for checking if a color is selected
1 parent aa254a6 commit 3cd7e01

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

components/editor/color-selector-popover.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import { ColorSelectorTab, usePreferencesStore } from "@/store/preferences-store
1818
import { TAILWIND_PALETTE } from "@/utils/registry/tailwind-colors";
1919
import { Check, LayoutGrid, List } from "lucide-react";
2020
import { useCallback } from "react";
21+
import { formatHex, parse } from "culori";
2122
import { Separator } from "../ui/separator";
2223

2324
type ColorSelectorPopoverProps = {
@@ -42,9 +43,14 @@ export function ColorSelectorPopover({ currentColor, onChange }: ColorSelectorPo
4243
[setColorSelectorTab]
4344
);
4445

46+
const toHex = (c: string) => formatHex(parse(c));
4547
const isColorSelected = useCallback(
4648
(color: string) => {
47-
return currentColor === color;
49+
try {
50+
return toHex(currentColor) === toHex(color);
51+
} catch {
52+
return currentColor === color;
53+
}
4854
},
4955
[currentColor]
5056
);

0 commit comments

Comments
 (0)