Skip to content

Commit cefd23a

Browse files
v1.3.0-alpha.1
1 parent 8795951 commit cefd23a

File tree

9 files changed

+91
-12
lines changed

9 files changed

+91
-12
lines changed

README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,17 @@ and use
9393
<img align="center" src="https://raw.githubusercontent.com/programming-with-ia/shadcn-theme-editor/master/screenshots/shadcn-theme-editor.png" alt="logo">
9494
</p>
9595

96+
## Upcoming Features
97+
98+
- Randomize
99+
- use [jln themes](https://ui.jln.dev/) directly in your project
100+
101+
## Special Thanks
102+
103+
I would like to extend my heartfelt thanks to the following individuals and projects:
104+
105+
- **[Julian](https://github.com/jln13x)** - for creating [ui.jln.dev](https://ui.jln.dev/), 10000+ Themes for shadcn/ui.
106+
96107
## 📄 License
97108

98109
This project is licensed under the `ℹ️ MIT` License.

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.2.0-alpha.1",
3+
"version": "1.3.0-alpha.1",
44
"description": "Shadcn Theme Editor",
55
"main": "dist/index.js",
66
"module": "dist/index.mjs",

src/components/random.tsx

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,24 @@ import React, { useState } from 'react'
22
import { Button } from './ui/button'
33
import { createRandomTheme } from '../lib/create-theme-config'
44
import { useTheme } from 'next-themes'
5-
import { getComputedHSLColor, setColorsProperties } from '../lib/utils'
5+
import { getComputedHSLColor, saveTheme, setColorsProperties } from '../lib/utils'
66
import { Dices, Lock, UnLock } from './icons';
7+
import { ReadonlyThemeWithHSLColor, SystemThemes, themeModes } from '../lib/theme'
78

89
function RandomBtn() {
9-
const { systemTheme } = useTheme()
10+
const { resolvedTheme=""+undefined, systemTheme="dark" } = useTheme();
1011
const [lockPrimary, setLockPrimary] = useState(true);
1112
const onClickHandler = ()=>{
12-
const themes = createRandomTheme(lockPrimary ? getComputedHSLColor("--primary"): undefined)
13-
const theme = themes[systemTheme!] ?? themes.dark
14-
// const theme = themes.dark
15-
console.log(theme)
13+
const themes = createRandomTheme(lockPrimary ? getComputedHSLColor("--primary"): undefined)
14+
let theme;
15+
16+
if (SystemThemes.includes(resolvedTheme as any)){
17+
theme = themes[resolvedTheme as themeModes] as ReadonlyThemeWithHSLColor[];
18+
SystemThemes.forEach(theme=> saveTheme(resolvedTheme, themes[theme])) // save both themes
19+
} else {
20+
theme = themes[systemTheme] as ReadonlyThemeWithHSLColor[];
21+
saveTheme(resolvedTheme, theme)
22+
}
1623
setColorsProperties(theme)
1724
}
1825
const LockIcon = lockPrimary? Lock: UnLock

src/components/sidebar-section.tsx

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import React from "react";
2+
import { CompoProps } from "../../app/src/types/types";
3+
import { cn } from "../lib/utils";
4+
5+
function Header({
6+
children,
7+
label,
8+
}: {
9+
children?: React.ReactNode;
10+
label: string;
11+
}) {
12+
return (
13+
<div
14+
className={cn(
15+
"mb-1 flex items-center justify-between pl-2 py-1 text-sm font-semibold gap-2"
16+
)}
17+
>
18+
{label} {children}
19+
</div>
20+
);
21+
}
22+
23+
function Section({
24+
className,
25+
children,
26+
}: {
27+
className?: string;
28+
children: React.ReactNode;
29+
}) {
30+
return (
31+
<div className={cn("text-sm flex flex-col", className)}>{children}</div>
32+
);
33+
}
34+
35+
const SidebarSection = {
36+
Header,
37+
Root: Section,
38+
Seperator() {
39+
return <hr className="my-2" />;
40+
},
41+
};
42+
43+
export default SidebarSection;

src/components/sidebar.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import SideBarColors from "./SideBarColors";
44
import { CopyTheme } from "./copy-theme";
55
import ThemeToggle from "./theme-toggle";
66
import RandomBtn from "./random";
7+
import SidebarSection from "./sidebar-section";
78

89
export function Sidebar({ isOpen }: { isOpen: boolean }) {
910
return (
@@ -17,13 +18,12 @@ export function Sidebar({ isOpen }: { isOpen: boolean }) {
1718
<div className="mb-1 flex items-center px-2 py-1 font-semibold">
1819
Shadcn Theme Editor
1920
</div>
20-
<div className="mb-1 flex items-center justify-between pl-2 py-1 text-sm font-semibold gap-2">
21-
Theming
21+
<SidebarSection.Header label="Theming">
2222
<div className="flex">
2323
<ResetTheme />
2424
<CopyTheme />
2525
</div>
26-
</div>
26+
</SidebarSection.Header>
2727

2828
<div className="text-sm flex flex-col flex-1">
2929
<SideBarColors />

src/hooks/useLocalStroageTheme.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import React, { useEffect, useState } from 'react'
2+
3+
function useLocalStroageTheme(theme?:string) {
4+
const [isLocalThemeApply, setIsLocalThemeApply] = useState(false);
5+
useEffect(() => {
6+
7+
}, [theme]);
8+
return {isLocalThemeApply}
9+
}
10+
11+
export default useLocalStroageTheme

src/lib/create-theme-config.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,9 @@
33
import { Colord, extend } from "colord";
44
import a11yPlugin from "colord/plugins/a11y";
55
import harmoniesPlugin from "colord/plugins/harmonies";
6-
import { getColorTitle, ReadonlyThemeWithHSLColor, ShadCnPropritiesType } from "./theme";
6+
import { getColorTitle, ReadonlyThemeWithHSLColor, type ShadCnPropritiesType, type themeModes } from './theme';
77

88
type Hsl = HslColor;
9-
type themeModes = "light" | "dark"
109
// type Hsl = {
1110
// h: number;
1211
// s: number;

src/lib/theme.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,9 @@ export type ShadCnPropritiesType = (typeof themeColors)[number]["variable"];
9191
export type ReadonlyThemeWithColor = (typeof themeColors)[number] & {
9292
color: string;
9393
};
94+
export const SystemThemes = ["light", "dark"] as const;
95+
export type themeModes = typeof SystemThemes[number]
96+
9497
export type ReadonlyThemeWithHSLColor = (typeof themeColors)[number] & {
9598
color: HslColor;
9699
};

src/lib/utils.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {
44
type ShadCnPropritiesType,
55
themeColors,
66
} from "./theme";
7+
import { LOCAL_STORAGE_KEY } from "./consts";
78

89
export function cn(...inputs: ClassValue[]) {
910
return clsx(inputs);
@@ -103,3 +104,7 @@ export const ls = {
103104
}
104105
},
105106
};
107+
108+
export function saveTheme(key: string | undefined, theme: ReadonlyThemeWithHSLColor[]){
109+
ls.setLocalStorage(LOCAL_STORAGE_KEY + ":" + key, theme);
110+
}

0 commit comments

Comments
 (0)