Skip to content

Commit cb1ace9

Browse files
committed
chore: restructure to monorepo, add demos
1 parent d0b73e6 commit cb1ace9

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+8098
-549
lines changed

.github/workflows/publish.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ jobs:
3232
run: pnpm i --ignore-scripts
3333

3434
- name: Build
35-
run: pnpm build
35+
run: pnpm --filter=palettez build
3636

3737
- name: Publish
3838
id: changesets

.gitignore

+12-1
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,19 @@ yarn-error.log*
88
.pnpm-debug.log
99

1010
# Builds
11-
dist*
11+
dist
1212
.astro
13+
.next
14+
out
15+
build
16+
.cache
17+
18+
# Verce
19+
.vercel
20+
21+
# typescript
22+
*.tsbuildinfo
23+
next-env.d.ts
1324

1425
# Personal
1526
ideas.md

README.md

+29-8
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
# Palettez
22

3-
A flexible and powerful theme management library for JavaScript applications
3+
A flexible, framework-agnostic theme management library for JavaScript applications
44

55
## Features
66

77
- Manage parallel themes with multiple options, for eg:
88
- Color scheme: light, dark, system
99
- Contrast preference: standard, high
1010
- Spacing: compact, comfortable, spacious
11-
- Persist theme selection to client or server storage
11+
- Persist theme selection to client storage and optionally server storage
1212
- No theme flicker on page load
1313
- Dynamically change themes based on system settings
1414
- Sync theme selection across tabs and windows
@@ -64,9 +64,9 @@ For client-side persistence (eg. localStorage), it's recommended to initialize P
6464
})
6565
6666
themeManager.subscribe((_, resolvedThemes) => {
67-
Object.entries(resolvedThemes).forEach(([theme, optionKey]) => {
67+
for (const [theme, optionKey] of Object.entries(resolvedThemes)) {
6868
document.documentElement.dataset[theme] = optionKey
69-
})
69+
}
7070
})
7171
7272
await themeManager.restore()
@@ -137,7 +137,7 @@ const themeManager = create({
137137
},
138138

139139
// optional, specify your own storage solution. localStorage is used by default.
140-
getStorage: () => {
140+
storageAdapter: () => {
141141
return {
142142
getItem: (key: string) => {
143143
try {
@@ -185,16 +185,37 @@ import { read } from 'palettez'
185185
const themeManager = read('palettez')
186186
```
187187

188-
### Methods
188+
### Properties & Methods
189189

190190
```ts
191+
themeManager.themesAndOptions
192+
// [
193+
// { key: 'colorScheme',
194+
// label: 'Color scheme',
195+
// options: [
196+
// { key: 'system', value: 'System' },
197+
// { key: 'light', value: 'Light' },
198+
// { key: 'dark', value: 'Dark' },
199+
// ]
200+
// },
201+
// {
202+
// key: 'contrast',
203+
// label: 'Contrast',
204+
// options: [
205+
// { key: 'system', value: 'System' },
206+
// { key: 'standard', value: 'Standard' },
207+
// { key: 'high', value: 'High' },
208+
// ]
209+
// }
210+
// ]
211+
191212
themeManager.getThemes() // { colorScheme: 'system', contrast: 'standard' }
192213
themeManager.getResolvedThemes() // { colorScheme: 'light', contrast: 'standard' }
193214
themeManager.setThemes({ contrast: 'high' })
194215
themeManager.restore() // restore persisted theme selection
195216
themeManager.sync() // useful for syncing theme selection across tabs and windows
196217
themeManager.clear() // clear persisted theme selection
197-
themeManager.subscribe((themes, resolvedThemes) => { /* ... */ })
218+
themeManager.subscribe((themes, resolvedThemes) => { /* ... */ }) // return unsubscribe function
198219
```
199220

200221
## React Integration
@@ -215,7 +236,7 @@ export function ThemeSelect() {
215236
sync,
216237
clear,
217238
subscribe,
218-
} = usePalettez('palettez')
239+
} = usePalettez()
219240

220241
return themesAndOptions.map((theme) => (
221242
<div key={theme.key}>

demo/src/pages/_style.css

-63
This file was deleted.

demo/src/pages/ssr.astro

-119
This file was deleted.
File renamed without changes.
File renamed without changes.
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,21 @@
11
{
2-
"name": "demo",
2+
"name": "demo-astro",
33
"private": true,
44
"type": "module",
55
"scripts": {
66
"dev": "astro dev --port 3000"
77
},
88
"dependencies": {
9-
"astro": "4.13.2",
10-
"palettez": "*",
9+
"astro": "4.13.3",
10+
"palettez": "workspace:*",
1111
"react": "18.3.1",
1212
"react-dom": "18.3.1"
1313
},
1414
"devDependencies": {
1515
"@astrojs/node": "8.3.2",
16-
"@astrojs/react": "3.6.1",
16+
"@astrojs/react": "3.6.2",
1717
"@types/react": "18.3.3",
18-
"@types/react-dom": "18.3.0"
18+
"@types/react-dom": "18.3.0",
19+
"typescript": "5.5.4"
1920
}
2021
}
File renamed without changes.
File renamed without changes.

demo/src/pages/_theme-select.tsx demos/astro/src/pages/_client-theme-select.tsx

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
import { usePalettez } from 'palettez/react'
22

3-
export function ThemeSelect() {
4-
const { themesAndOptions, themes, setThemes } = usePalettez('palettez')
3+
export function ClientThemeSelect() {
4+
const { themesAndOptions, themes, setThemes } = usePalettez(
5+
window.palettez.read(),
6+
)
57

68
return themesAndOptions.map((theme) => (
79
<div key={theme.key}>
8-
<label htmlFor={theme.key}>{theme.label}</label>
10+
<label htmlFor={theme.key}>{theme.label}</label>{' '}
911
<select
1012
id={theme.key}
1113
name={theme.key}

0 commit comments

Comments
 (0)