Skip to content

Commit

Permalink
1.4.2-beta
Browse files Browse the repository at this point in the history
  • Loading branch information
programming-with-ia committed Jan 20, 2025
1 parent a7be70f commit bfea8ba
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 22 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "shadcn-theme-editor",
"version": "1.4.1",
"version": "1.4.2-beta",
"description": "Shadcn Theme Editor",
"module": "dist/index.mjs",
"main": "dist/index.js",
Expand Down
4 changes: 1 addition & 3 deletions src/components/SideBarColors.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,7 @@ function SideBarColors() {
if (setSavedTheme(currentTheme)) return; // isSavedThemeApplied
}

if (typeof colors == "undefined") {
themeEmittor.setDefaultTheme();
}
themeEmittor.setDefaultTheme();
}, [currentTheme, isMount]);

return (
Expand Down
41 changes: 23 additions & 18 deletions src/components/item.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ThemeWithHSLColor } from "../lib/theme";
import React, { useCallback, useEffect, useState } from "react";
import React, { useCallback, useEffect, useRef, useState } from "react";
import { Button } from "./ui/button";
import { copy2clipboard, HSL2ComputedColor, setStyleColor } from "../lib/utils";
import { useDebounceCallback } from "../hooks/useDebounceCallback";
Expand All @@ -13,40 +13,45 @@ export function Item({
onSave: () => void;
}) {
const [color, setColor] = useState<string>("#000");
const hslColorRef = useRef(colord(color).toHsl());

useEffect(() => {
setColor(colord(theme.color).toHex());
}, [theme]);

const updateValue = useCallback(
useDebounceCallback((color: string) => {
setStyleColor(theme.variable, colord(color).toHsl());
onSave();
}, 0),
useDebounceCallback(() => {
setStyleColor(theme.variable, hslColorRef.current);
onSave(); // save to localstorage
}, 100),
[theme.variable]
);

const title =
theme.variable + ": " + HSL2ComputedColor(hslColorRef.current) + ";";

return (
<Button
variant={"colorbtn"}
className=" select-none"
className="select-none"
asChild
title={theme.variable + ": " + HSL2ComputedColor(theme.color) + ";"}
onDoubleClick={() =>
copy2clipboard(
theme.variable + ": " + HSL2ComputedColor(theme.color) + ";"
)
}
title={title}
onDoubleClick={() => copy2clipboard(title)}
>
<div>
<div className="relative overflow-hidden rounded border size-6 cursor-pointer shadow-md drop-shadow-md">
<input
onClick={(e) => e.stopPropagation()}
className="absolute cursor-pointer inset-1/2 size-[calc(100%+12px)] -translate-x-1/2 -translate-y-1/2 flex-shrink-0 bg-transparent"
// defaultValue={colord(color).toHex()}
value={color}
type="color"
onChange={(e) => (
setColor(e.target.value), updateValue(e.target.value)
)}
className="absolute cursor-pointer inset-1/2 size-[calc(100%+12px)] -translate-x-1/2 -translate-y-1/2 flex-shrink-0 bg-transparent"
value={color}
onChange={(e) => {
const clr = e.target.value;
hslColorRef.current = colord(clr).toHsl();
setColor(clr);
updateValue();
}}
onClick={(e) => e.stopPropagation()} // disable copy to clipboard
/>
</div>
<span className="flex-shrink-0">{theme.title}</span>
Expand Down

0 comments on commit bfea8ba

Please sign in to comment.