Skip to content

Commit 49610c9

Browse files
v1.3.2
- editor open button with only icon - add close button on sidebar - double click to copy single color
1 parent 900d5ae commit 49610c9

File tree

10 files changed

+51
-51
lines changed

10 files changed

+51
-51
lines changed

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "shadcn-theme-editor",
3-
"version": "1.3.1",
3+
"version": "1.3.2",
44
"description": "Shadcn Theme Editor",
55
"main": "dist/index.js",
66
"module": "dist/index.mjs",
@@ -16,7 +16,8 @@
1616
"scripts": {
1717
"build": "rollup -c --bundleConfigAsCjs && python ./update-css-file.py && npm link && npm pack",
1818
"test": "echo \"Error: no test specified\" && exit 1",
19-
"release": "release-it"
19+
"release": "release-it",
20+
"clean": "rimraf dist"
2021
},
2122
"keywords": [
2223
"shadcn-theme-editor",

src/components/SideBarColors.tsx

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,10 @@ import { useEmittor } from "emittor";
1010
import { themeEmittor } from "../lib/emittors";
1111

1212
function print(...props: any) {
13-
if (typeof window !== "undefined" && (window as any).shadcnThemeEditorDebugMode) {
13+
if (
14+
typeof window !== "undefined" &&
15+
(window as any).shadcnThemeEditorDebugMode
16+
) {
1417
console.log(...props);
1518
}
1619
}
@@ -28,7 +31,6 @@ const ZodTheme = z.array(
2831
);
2932

3033
function SideBarColors() {
31-
// const { resolvedTheme: currentTheme } = useTheme();
3234

3335
const { resolvedTheme } = useTheme();
3436
const [currentTheme, setCurrentTheme] = useState<string | undefined>();
@@ -53,22 +55,16 @@ function SideBarColors() {
5355
const isValid = ZodTheme.parse(theme);
5456
print("theme is valid and appling", isValid);
5557
print("applied theme", theme);
56-
themeEmittor.applyTheme(theme)
57-
// setColorsProperties(theme);
58-
// setColors(theme);
58+
themeEmittor.applyTheme(theme);
5959
return;
6060
} catch (error) {
6161
print("invalid theme found in localStorage");
6262
// localStorage.removeItem(LOCAL_STORAGE_KEY+":"+currentTheme); //* remove key
6363
}
6464
}
65-
// resetTheme()
66-
// theme = getColors(true) as any;
67-
// theme = getDefaultTheme()
6865
print("theme not found in localStorage");
6966
print("Now theme: ", theme);
70-
// setColors(theme as any);
71-
themeEmittor.setDefaultTheme()
67+
themeEmittor.setDefaultTheme();
7268
}, [currentTheme]);
7369
return (
7470
<>

src/components/editor-open.tsx

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,20 @@
11
"use client";
22
import { useState } from "react";
33
import { Sidebar } from "./sidebar";
4-
import { Button } from "./ui/button";
4+
import { IoColorPalette } from "react-icons/io5";
5+
import clsx from "clsx";
56

67
function EditorOpenBtn() {
7-
const [IsOpen, setIsOpen] = useState(false);
8+
const [isOpen, setIsOpen] = useState(false);
89
return (
910
<div id="shadcn-theme-editor">
10-
<Button
11-
onClick={() => setIsOpen(!IsOpen)}
12-
className="fixed bottom-2 right-2 z-[35] opacity-50 hover:opacity-100"
11+
<button
12+
onClick={() => setIsOpen(!isOpen)}
13+
className={clsx("rounded-full p-3 fixed border shadow-md drop-shadow-sm bottom-2 right-2 z-[35]", isOpen?"bg-primary text-primary-foreground":"text-primary bg-primary-foreground opacity-50 hover:opacity-100")}
1314
>
14-
{IsOpen ? "Close" : "Open"} Theme Editor
15-
</Button>
16-
<Sidebar isOpen={IsOpen} />
15+
<IoColorPalette size={24} />
16+
</button>
17+
<Sidebar state={{isOpen, setIsOpen}} />
1718
</div>
1819
);
1920
}

src/components/icons.tsx

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,3 +81,22 @@ export const Lock = (props: SVGProps<SVGSVGElement>) => (
8181
</g>
8282
</svg>
8383
);
84+
85+
export const X = (props: SVGProps<SVGSVGElement>) => (
86+
<svg
87+
xmlns="http://www.w3.org/2000/svg"
88+
width={24}
89+
height={24}
90+
viewBox="0 0 24 24"
91+
fill="none"
92+
stroke="currentColor"
93+
strokeWidth={2}
94+
strokeLinecap="round"
95+
strokeLinejoin="round"
96+
className="lucide lucide-x"
97+
{...props}
98+
>
99+
<path d="M18 6 6 18" />
100+
<path d="m6 6 12 12" />
101+
</svg>
102+
);

src/components/item.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,10 @@ export function Item({
2727
return (
2828
<Button
2929
variant={"colorbtn"}
30+
className=" select-none"
3031
asChild
3132
title={theme.variable + ": " + HSL2ComputedColor(theme.color) + ";"}
32-
onClick={() =>
33+
onDoubleClick={() =>
3334
copy2clipboard(
3435
theme.variable + ": " + HSL2ComputedColor(theme.color) + ";"
3536
)

src/components/random.tsx

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,13 @@
1-
import React, { useEffect, useState } from "react";
1+
import { useEffect, useState } from "react";
22
import { Button } from "./ui/button";
33
import { createRandomTheme } from "../lib/create-theme-config";
44
import { useTheme } from "next-themes";
55
import {
66
getComputedHSLColor,
77
saveTheme,
8-
setColorsProperties,
98
} from "../lib/utils";
109
import { Dices, Lock, UnLock } from "./icons";
11-
import {
12-
SystemThemes,
13-
themeModes,
14-
ThemeWithHSLColor,
15-
} from "../lib/theme";
10+
import { SystemThemes, themeModes, ThemeWithHSLColor } from "../lib/theme";
1611
import { themeEmittor } from "../lib/emittors";
1712

1813
function RandomBtn() {
@@ -34,17 +29,13 @@ function RandomBtn() {
3429
let theme;
3530

3631
if (SystemThemes.includes(resolvedTheme as any)) {
37-
theme = themes[
38-
resolvedTheme as themeModes
39-
] as ThemeWithHSLColor[];
32+
theme = themes[resolvedTheme as themeModes] as ThemeWithHSLColor[];
4033
SystemThemes.forEach((theme) => saveTheme(theme, themes[theme])); // save both themes
4134
} else {
4235
theme = themes[systemTheme as themeModes] as ThemeWithHSLColor[];
4336
saveTheme(resolvedTheme, theme);
4437
}
45-
themeEmittor.applyTheme(theme)
46-
// themeEmittor.e.setState(theme)
47-
// setColorsProperties(theme);
38+
themeEmittor.applyTheme(theme);
4839
};
4940
const LockIcon = lockPrimary ? Lock : UnLock;
5041
return (

src/components/reset-theme.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,7 @@ export function ResetTheme() {
1616
e.ctrlKey
1717
? ls.deleteAllThemes()
1818
: localStorage.removeItem(LOCAL_STORAGE_KEY + ":" + currentTheme),
19-
// resetTheme(),
2019
themeEmittor.setDefaultTheme()
21-
// window.location.reload()
2220
)}
2321
>
2422
<ResetIcon />

src/components/sidebar.tsx

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,21 @@ import { CopyTheme } from "./copy-theme";
55
import ThemeToggle from "./theme-toggle";
66
import RandomBtn from "./random";
77
import SidebarSection from "./sidebar-section";
8+
import { Button } from "./ui/button";
9+
import { X } from "./icons";
810

9-
export function Sidebar({ isOpen }: { isOpen: boolean }) {
11+
export function Sidebar({ state }: { state: {isOpen: boolean, setIsOpen: (state: boolean)=>void} }) {
1012
return (
1113
<aside
1214
role="dialog"
1315
className={cn(
14-
"fixed customScrollBar duration-500 left-0 inset-y-0 z-50 hidden h-screen max-h-screen w-fit shrink-0 bg-background overflow-y-auto py-6 pl-8 pr-6 lg:py-8 border-r-2 shadow-md drop-shadow-sm",
15-
isOpen && "md:flex flex-col"
16+
"fixed customScrollBar group duration-500 left-0 inset-y-0 z-50 hidden h-screen max-h-screen w-fit shrink-0 bg-background overflow-y-auto py-6 pl-8 pr-6 lg:py-8 border-r-2 shadow-md drop-shadow-sm",
17+
state.isOpen && "md:flex flex-col"
1618
)}
1719
>
20+
<Button onClick={()=>state.setIsOpen(!state.isOpen)} className="fixed top-0 right-0 m-2 opacity-0 group-hover:opacity-50 hover:!opacity-100" size={"toolbtn"} variant={"toolbtn"}>
21+
<X className="size-5" />
22+
</Button>
1823
<div className="flex items-center px-2 py-1 font-semibold">
1924
Shadcn Theme Editor
2025
</div>

src/components/theme-toggle.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
"use client";
21
import { useTheme } from "next-themes";
32
import { cn } from "../lib/utils";
43
import { SVGProps, useEffect, useRef, useState } from "react";

src/hooks/useLocalStroageTheme.ts

Lines changed: 0 additions & 11 deletions
This file was deleted.

0 commit comments

Comments
 (0)