Skip to content

Commit d4ed504

Browse files
committedAug 9, 2024·
feat: improve types
1 parent 9e2b1ba commit d4ed504

File tree

4 files changed

+13
-21
lines changed

4 files changed

+13
-21
lines changed
 

‎global.d.ts

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
interface Window {
2+
palettez: typeof import('./src')
3+
}

‎package.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "palettez",
3-
"version": "0.0.8",
3+
"version": "0.0.9",
44
"description": "Palettez",
55
"keywords": ["theming"],
66
"repository": {
@@ -32,8 +32,8 @@
3232
},
3333
"jsdelivr": "./dist/palettez.min.js",
3434
"unpkg": "./dist/palettez.min.js",
35-
"types": "./dist/index.d.ts",
36-
"files": ["dist", "palettez.min.txt.d.ts"],
35+
"types": "./global.d.ts",
36+
"files": ["dist", "global.d.ts", "palettez.min.txt.d.ts"],
3737
"scripts": {
3838
"build": "tsup"
3939
},

‎src/index.ts

+4-10
Original file line numberDiff line numberDiff line change
@@ -219,12 +219,6 @@ class ThemeManager<T extends Options['config']> {
219219
)
220220
}
221221

222-
// #applyThemes = (themes: Themes<T>): void => {
223-
// Object.entries(themes).forEach(([theme, optionKey]) => {
224-
// document.documentElement.dataset[theme] = optionKey
225-
// })
226-
// }
227-
228222
#resolveThemeOption = ({
229223
theme,
230224
option,
@@ -277,18 +271,18 @@ class ThemeManager<T extends Options['config']> {
277271

278272
const registry = new Map<string, ThemeManager<Options['config']>>()
279273

280-
export function create(options: Options) {
281-
const themeManager = new ThemeManager(options)
274+
export function create<T extends Options>(options: T) {
275+
const themeManager = new ThemeManager<T['config']>(options)
282276
registry.set(options.key || DEFAULT_OPTIONS.key, themeManager)
283277
return themeManager
284278
}
285279

286-
export function read(key: string = packageName) {
280+
export function read<T extends Options>(key: string = packageName) {
287281
const themeManager = registry.get(key)
288282
if (!themeManager) {
289283
throw new Error(
290284
`[${packageName}] Theme manager with key '${key}' could not be found. Please run \`create\` with key '${key}' first.`,
291285
)
292286
}
293-
return themeManager
287+
return themeManager as ThemeManager<T['config']>
294288
}

‎src/react.ts

+3-8
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,7 @@
11
import * as React from 'react'
2+
import type { Options } from '.'
23

3-
declare global {
4-
interface Window {
5-
palettez: typeof import('.')
6-
}
7-
}
8-
9-
export function usePalettez(key = 'palettez') {
4+
export function usePalettez<T extends Options>(key = 'palettez') {
105
const {
116
themesAndOptions,
127
getThemes,
@@ -16,7 +11,7 @@ export function usePalettez(key = 'palettez') {
1611
sync,
1712
clear,
1813
subscribe,
19-
} = window.palettez.read(key)
14+
} = window.palettez.read<T>(key)
2015

2116
const themes = React.useSyncExternalStore(
2217
React.useCallback((callback) => subscribe(callback), [key]),

0 commit comments

Comments
 (0)
Please sign in to comment.