Skip to content

Commit bfea8ba

Browse files
1.4.2-beta
1 parent a7be70f commit bfea8ba

File tree

3 files changed

+25
-22
lines changed

3 files changed

+25
-22
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "shadcn-theme-editor",
3-
"version": "1.4.1",
3+
"version": "1.4.2-beta",
44
"description": "Shadcn Theme Editor",
55
"module": "dist/index.mjs",
66
"main": "dist/index.js",

src/components/SideBarColors.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,7 @@ function SideBarColors() {
3131
if (setSavedTheme(currentTheme)) return; // isSavedThemeApplied
3232
}
3333

34-
if (typeof colors == "undefined") {
35-
themeEmittor.setDefaultTheme();
36-
}
34+
themeEmittor.setDefaultTheme();
3735
}, [currentTheme, isMount]);
3836

3937
return (

src/components/item.tsx

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { ThemeWithHSLColor } from "../lib/theme";
2-
import React, { useCallback, useEffect, useState } from "react";
2+
import React, { useCallback, useEffect, useRef, useState } from "react";
33
import { Button } from "./ui/button";
44
import { copy2clipboard, HSL2ComputedColor, setStyleColor } from "../lib/utils";
55
import { useDebounceCallback } from "../hooks/useDebounceCallback";
@@ -13,40 +13,45 @@ export function Item({
1313
onSave: () => void;
1414
}) {
1515
const [color, setColor] = useState<string>("#000");
16+
const hslColorRef = useRef(colord(color).toHsl());
1617

1718
useEffect(() => {
1819
setColor(colord(theme.color).toHex());
1920
}, [theme]);
21+
2022
const updateValue = useCallback(
21-
useDebounceCallback((color: string) => {
22-
setStyleColor(theme.variable, colord(color).toHsl());
23-
onSave();
24-
}, 0),
23+
useDebounceCallback(() => {
24+
setStyleColor(theme.variable, hslColorRef.current);
25+
onSave(); // save to localstorage
26+
}, 100),
2527
[theme.variable]
2628
);
29+
30+
const title =
31+
theme.variable + ": " + HSL2ComputedColor(hslColorRef.current) + ";";
32+
2733
return (
2834
<Button
2935
variant={"colorbtn"}
30-
className=" select-none"
36+
className="select-none"
3137
asChild
32-
title={theme.variable + ": " + HSL2ComputedColor(theme.color) + ";"}
33-
onDoubleClick={() =>
34-
copy2clipboard(
35-
theme.variable + ": " + HSL2ComputedColor(theme.color) + ";"
36-
)
37-
}
38+
title={title}
39+
onDoubleClick={() => copy2clipboard(title)}
3840
>
3941
<div>
4042
<div className="relative overflow-hidden rounded border size-6 cursor-pointer shadow-md drop-shadow-md">
4143
<input
42-
onClick={(e) => e.stopPropagation()}
44+
className="absolute cursor-pointer inset-1/2 size-[calc(100%+12px)] -translate-x-1/2 -translate-y-1/2 flex-shrink-0 bg-transparent"
4345
// defaultValue={colord(color).toHex()}
44-
value={color}
4546
type="color"
46-
onChange={(e) => (
47-
setColor(e.target.value), updateValue(e.target.value)
48-
)}
49-
className="absolute cursor-pointer inset-1/2 size-[calc(100%+12px)] -translate-x-1/2 -translate-y-1/2 flex-shrink-0 bg-transparent"
47+
value={color}
48+
onChange={(e) => {
49+
const clr = e.target.value;
50+
hslColorRef.current = colord(clr).toHsl();
51+
setColor(clr);
52+
updateValue();
53+
}}
54+
onClick={(e) => e.stopPropagation()} // disable copy to clipboard
5055
/>
5156
</div>
5257
<span className="flex-shrink-0">{theme.title}</span>

0 commit comments

Comments
 (0)