Skip to content

Commit e1f4214

Browse files
committed
Complete Examples
1 parent 2434174 commit e1f4214

File tree

8 files changed

+67
-31
lines changed

8 files changed

+67
-31
lines changed

lib/nthul/src/client/theme-switcher/theme-switcher.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,8 @@ function applyClasses({ targets, theme, resolvedColorScheme, styles }: ApplyClas
9393
targets.forEach(t => {
9494
t?.classList.remove(cls[0]); // dark
9595
t?.classList.remove(cls[1]); // light
96-
t?.classList.forEach(cls => {
97-
if (cls.match(/(^|_)th-/)) t.classList.remove(cls);
96+
t?.classList.forEach(c => {
97+
if (/(?:^|_)th-/.exec(c)) t.classList.remove(c);
9898
});
9999
t?.classList.add(`th-${cls[2]}`); // theme
100100
t?.classList.add(cls[3]); // resolvedColorScheme
@@ -149,6 +149,6 @@ export function ThemeSwitcher({ targetId, dontSync, themeTransition, styles }: T
149149
localStorage.setItem(key, stateToSave);
150150
}
151151
restoreTransitions();
152-
}, [dontSync, targetId, themeState, themeTransition]);
152+
}, [dontSync, styles, targetId, themeState, themeTransition]);
153153
return null;
154154
}

packages/shared-ui/src/globals.css

Lines changed: 36 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -44,15 +44,6 @@
4444
--tile-border: conic-gradient(#00000080, #00000040, #00000030, #00000020, #00000010, #00000010, #00000080);
4545
}
4646

47-
/* dark themes */
48-
.th-.dark,
49-
.th-.dark *,
50-
.th-.dark ~ *,
51-
.th-.dark ~ * * {
52-
--bg-color: var(--bg-dark);
53-
--text-color: var(--color-dark);
54-
}
55-
5647
.dark,
5748
.dark ~ * {
5849
--primary-glow: radial-gradient(rgba(1, 65, 255, 0.4), rgba(1, 65, 255, 0));
@@ -65,36 +56,66 @@
6556
--tile-border: conic-gradient(#ffffff80, #ffffff40, #ffffff30, #ffffff20, #ffffff10, #ffffff10, #ffffff80);
6657
}
6758

68-
/* light themes */
59+
/* dark themes */
60+
.th-.dark,
61+
.th-.dark *,
62+
.th-.dark ~ *,
63+
.th-.dark ~ * *,
64+
/* for increased specificity of localized themes */
65+
.nth-scoped.th-.dark,
66+
.nth-scoped.th-.dark *,
67+
.nth-scoped.th-.dark ~ *,
68+
.nth-scoped.th-.dark ~ * * {
69+
--bg-color: var(--bg-dark);
70+
--text-color: var(--color-dark);
71+
}
6972

73+
/* light themes */
7074
.th-.light,
7175
.th-.light *,
7276
.th-.light ~ *,
73-
.th-.light ~ * * {
77+
.th-.light ~ * *,
78+
/* for increased specificity of localized themes */
79+
.nth-scoped.th-.light,
80+
.nth-scoped.th-.light *,
81+
.nth-scoped.th-.light ~ *,
82+
.nth-scoped.th-.light ~ * * {
7483
--bg-color: var(--bg-light);
7584
--text-color: var(--color-light);
7685
}
7786

7887
.th-theme1.light ~ *,
79-
.th-theme1.light ~ * * {
88+
.th-theme1.light ~ * *,
89+
/* for increased specificity of localized themes */
90+
.nth-scoped.th-theme1.light ~ *,
91+
.nth-scoped.th-theme1.light ~ * * {
8092
--bg-color: var(--th1-bg-light);
8193
--text-color: var(--th1-color-light);
8294
}
8395

8496
.th-theme1.dark ~ *,
85-
.th-theme1.dark ~ * * {
97+
.th-theme1.dark ~ * * ,
98+
/* for increased specificity of localized themes */
99+
.nth-scoped.th-theme1.dark ~ *,
100+
.nth-scoped.th-theme1.dark ~ * * {
86101
--bg-color: var(--th1-bg-dark);
87102
--text-color: var(--th1-color-dark);
88103
}
89104

90105
.th-theme2.light ~ *,
91-
.th-theme2.light ~ * * {
106+
.th-theme2.light ~ * *,
107+
/* for increased specificity of localized themes */
108+
.nth-scoped.th-theme2.light ~ *,
109+
.nth-scoped.th-theme2.light ~ * * {
92110
--bg-color: var(--th2-bg-light);
93111
--text-color: var(--th2-color-light);
94112
}
95113

96114
.th-theme2.dark ~ *,
97-
.th-theme2.dark ~ * * {
115+
.th-theme2.dark ~ * *,
116+
/* for increased specificity of localized themes */
117+
.nth-scoped.th-theme2.dark ~ *,
118+
.nth-scoped.th-theme2.dark ~ * * {
98119
--bg-color: var(--th2-bg-dark);
99120
--text-color: var(--th2-color-dark);
100121
}

packages/shared-ui/src/lib-examples/index.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,18 @@ import { Logo } from "../common/logo";
22
import SimpleColorSwitch from "./simple-color-switch";
33
import ThemeSwitching from "./theme-switching";
44
import styles from "./lib-examples.module.css";
5+
import ThemesList from "./themes-list";
56

67
export default function LibExamples() {
78
return (
89
<div className={styles["lib-example-container"]}>
910
<h1>
1011
<Logo /> examples.
1112
</h1>
13+
<div className={styles.globalThemes}>
14+
<h2>Global Themes</h2>
15+
<ThemesList />
16+
</div>
1217
<SimpleColorSwitch />
1318
<ThemeSwitching />
1419
</div>

packages/shared-ui/src/lib-examples/lib-examples.module.css

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
justify-content: space-evenly;
77
}
88

9-
.lib-example-container h1 {
9+
.lib-example-container h1,
10+
.globalThemes {
1011
text-align: center;
1112
width: 100%;
1213
}

packages/shared-ui/src/lib-examples/simple-color-switch/index.tsx renamed to packages/shared-ui/src/lib-examples/simple-color-switch.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { ColorSwitch, ThemeSwitcher } from "nthul";
22
import { ServerTarget } from "nthul/server";
3-
import styles from "../lib-examples.module.css";
3+
import styles from "./lib-examples.module.css";
44

55
const targetId = "simple-color-switch";
66
export default function SimpleColorSwitch() {

packages/shared-ui/src/lib-examples/theme-switching/theme-button.tsx renamed to packages/shared-ui/src/lib-examples/theme-button.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
"use client";
22

33
import { useTheme } from "nthul/src/hooks";
4-
import styles from "../lib-examples.module.css";
4+
import styles from "./lib-examples.module.css";
55

6-
export default function ThemeButton({ th, targetId }: { th: string; targetId: string }) {
6+
export default function ThemeButton({ th, targetId }: { th: string; targetId?: string }) {
77
const { setTheme } = useTheme(targetId);
88
return (
99
<li>

packages/shared-ui/src/lib-examples/theme-switching/index.tsx renamed to packages/shared-ui/src/lib-examples/theme-switching.tsx

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
import { ColorSwitch, ThemeSwitcher } from "nthul";
22
import { ServerTarget } from "nthul/server";
3-
import styles from "../lib-examples.module.css";
4-
import ThemeButton from "./theme-button";
3+
import styles from "./lib-examples.module.css";
4+
import ThemesList from "./themes-list";
55

6-
export const targetId = "theme-switching";
7-
const themes = ["", "theme1", "theme2"];
6+
const targetId = "theme-switching";
87

98
export default function SimpleColorSwitch() {
109
return (
@@ -16,11 +15,7 @@ export default function SimpleColorSwitch() {
1615
</header>
1716
<main>
1817
Simple scoped multi-theme.
19-
<ul className={styles.themes}>
20-
{themes.map(th => (
21-
<ThemeButton key={th} {...{ targetId, th }} />
22-
))}
23-
</ul>
18+
<ThemesList targetId={targetId} />
2419
</main>
2520
</div>
2621
);
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import ThemeButton from "./theme-button";
2+
import styles from "./lib-examples.module.css";
3+
4+
const themes = ["", "theme1", "theme2"];
5+
6+
export default function ThemesList({ targetId }: { targetId?: string }) {
7+
return (
8+
<ul className={styles.themes}>
9+
{themes.map(th => (
10+
<ThemeButton key={th} {...{ targetId, th }} />
11+
))}
12+
</ul>
13+
);
14+
}

0 commit comments

Comments
 (0)