From bfea8baf7d4322d72c4d0fa236426576be0f1e57 Mon Sep 17 00:00:00 2001 From: immi Date: Mon, 20 Jan 2025 19:23:49 +0500 Subject: [PATCH] 1.4.2-beta --- package.json | 2 +- src/components/SideBarColors.tsx | 4 +--- src/components/item.tsx | 41 ++++++++++++++++++-------------- 3 files changed, 25 insertions(+), 22 deletions(-) diff --git a/package.json b/package.json index 15cbfc9..c95a855 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/components/SideBarColors.tsx b/src/components/SideBarColors.tsx index c6877f6..7eb8fd1 100644 --- a/src/components/SideBarColors.tsx +++ b/src/components/SideBarColors.tsx @@ -31,9 +31,7 @@ function SideBarColors() { if (setSavedTheme(currentTheme)) return; // isSavedThemeApplied } - if (typeof colors == "undefined") { - themeEmittor.setDefaultTheme(); - } + themeEmittor.setDefaultTheme(); }, [currentTheme, isMount]); return ( diff --git a/src/components/item.tsx b/src/components/item.tsx index dd59ca0..214c7c8 100644 --- a/src/components/item.tsx +++ b/src/components/item.tsx @@ -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"; @@ -13,40 +13,45 @@ export function Item({ onSave: () => void; }) { const [color, setColor] = useState("#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 (