File tree 4 files changed +13
-21
lines changed
4 files changed +13
-21
lines changed Original file line number Diff line number Diff line change
1
+ interface Window {
2
+ palettez : typeof import ( './src' )
3
+ }
Original file line number Diff line number Diff line change 1
1
{
2
2
"name" : " palettez" ,
3
- "version" : " 0.0.8 " ,
3
+ "version" : " 0.0.9 " ,
4
4
"description" : " Palettez" ,
5
5
"keywords" : [" theming" ],
6
6
"repository" : {
32
32
},
33
33
"jsdelivr" : " ./dist/palettez.min.js" ,
34
34
"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" ],
37
37
"scripts" : {
38
38
"build" : " tsup"
39
39
},
Original file line number Diff line number Diff line change @@ -219,12 +219,6 @@ class ThemeManager<T extends Options['config']> {
219
219
)
220
220
}
221
221
222
- // #applyThemes = (themes: Themes<T>): void => {
223
- // Object.entries(themes).forEach(([theme, optionKey]) => {
224
- // document.documentElement.dataset[theme] = optionKey
225
- // })
226
- // }
227
-
228
222
#resolveThemeOption = ( {
229
223
theme,
230
224
option,
@@ -277,18 +271,18 @@ class ThemeManager<T extends Options['config']> {
277
271
278
272
const registry = new Map < string , ThemeManager < Options [ 'config' ] > > ( )
279
273
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 )
282
276
registry . set ( options . key || DEFAULT_OPTIONS . key , themeManager )
283
277
return themeManager
284
278
}
285
279
286
- export function read ( key : string = packageName ) {
280
+ export function read < T extends Options > ( key : string = packageName ) {
287
281
const themeManager = registry . get ( key )
288
282
if ( ! themeManager ) {
289
283
throw new Error (
290
284
`[${ packageName } ] Theme manager with key '${ key } ' could not be found. Please run \`create\` with key '${ key } ' first.` ,
291
285
)
292
286
}
293
- return themeManager
287
+ return themeManager as ThemeManager < T [ 'config' ] >
294
288
}
Original file line number Diff line number Diff line change 1
1
import * as React from 'react'
2
+ import type { Options } from '.'
2
3
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' ) {
10
5
const {
11
6
themesAndOptions,
12
7
getThemes,
@@ -16,7 +11,7 @@ export function usePalettez(key = 'palettez') {
16
11
sync,
17
12
clear,
18
13
subscribe,
19
- } = window . palettez . read ( key )
14
+ } = window . palettez . read < T > ( key )
20
15
21
16
const themes = React . useSyncExternalStore (
22
17
React . useCallback ( ( callback ) => subscribe ( callback ) , [ key ] ) ,
You can’t perform that action at this time.
0 commit comments