1
- import type { Token } from '@pandacss/token-dictionary'
1
+ import type { Token , TokenExtensions } from '@pandacss/token-dictionary'
2
2
import { useState } from 'react'
3
3
import * as context from './panda-context'
4
4
@@ -10,33 +10,36 @@ interface Color {
10
10
path : string [ ]
11
11
}
12
12
13
- type ColorToken = Token & Color
13
+ type ColorToken = Token & Color & TokenExtensions
14
14
15
15
const UNCATEGORIZED_ID = 'uncategorized' as const
16
16
17
- const groupByColorPalette = ( colors : Token [ ] , filterMethod ?: ( token : ColorToken ) => boolean ) => {
17
+ const groupByColorPalette = ( colors : ColorToken [ ] , filterMethod ?: ( token : ColorToken ) => boolean ) => {
18
18
const values = colors . filter ( ( color ) => ! color . isConditional && ! color . extensions . isVirtual )
19
19
20
- return values . reduce < Record < string , any > > ( ( acc , color ) => {
21
- if ( ! filterMethod ?.( color ) ) return acc
20
+ return values . reduce (
21
+ ( acc , color ) => {
22
+ if ( ! filterMethod ?.( color ) ) return acc
22
23
23
- const colorPalette = color . extensions . colorPalette || UNCATEGORIZED_ID
24
+ const colorPalette = color . extensions . colorPalette || UNCATEGORIZED_ID
24
25
25
- if ( ! ( colorPalette in acc ) ) {
26
- acc [ colorPalette ] = [ ]
27
- }
26
+ if ( ! ( colorPalette in acc ) ) {
27
+ acc [ colorPalette ] = [ ]
28
+ }
28
29
29
- const exists = ( acc [ colorPalette ] as any [ ] ) . find ( ( tok ) => tok . name === color . name )
30
- if ( ! exists ) acc [ colorPalette ] . push ( color )
30
+ const exists = ( acc [ colorPalette ] as any [ ] ) . find ( ( tok ) => tok . name === color . name )
31
+ if ( ! exists ) acc [ colorPalette ] . push ( color )
31
32
32
- return acc
33
- } , { } )
33
+ return acc
34
+ } ,
35
+ { } as Record < string , ColorToken [ ] > ,
36
+ )
34
37
}
35
38
36
- const getSemanticTokens = ( allTokens : ColorToken [ ] , filterMethod ?: ( token : ColorToken ) => boolean ) => {
39
+ const getSemanticTokens = ( allTokens : Token [ ] , filterMethod ?: ( token : ColorToken ) => boolean ) => {
37
40
const semanticTokens = allTokens . filter (
38
41
( token ) => token . type === 'color' && token . isConditional && ! token . extensions ?. isVirtual ,
39
- )
42
+ ) as ColorToken [ ]
40
43
return semanticTokens
41
44
. reduce ( ( acc , nxt ) => {
42
45
if ( ! filterMethod ) {
@@ -50,7 +53,7 @@ const getSemanticTokens = (allTokens: ColorToken[], filterMethod?: (token: Color
50
53
}
51
54
return acc
52
55
} , [ ] as ColorToken [ ] )
53
- . reduce < Record < string , any > > (
56
+ . reduce < Record < string , ColorToken > > (
54
57
( acc , nxt ) => ( {
55
58
...acc ,
56
59
[ nxt . extensions ?. prop ] : {
@@ -85,14 +88,17 @@ export const useColorDocs = () => {
85
88
. some ( ( prop ) => prop . includes ( filterQuery ) )
86
89
}
87
90
88
- const colorsInCategories = groupByColorPalette ( colors , filterMethod )
91
+ const colorsInCategories = groupByColorPalette ( colors as ColorToken [ ] , filterMethod )
89
92
const uncategorizedColors = colorsInCategories [ UNCATEGORIZED_ID ]
90
93
91
94
const categorizedColors = Object . entries < any [ ] > ( colorsInCategories ) . filter (
92
95
( [ category ] ) => category !== UNCATEGORIZED_ID ,
93
96
)
94
97
95
- const semanticTokens = Object . entries < Record < string , any > > ( getSemanticTokens ( allTokens , filterMethod ) )
98
+ const semanticTokens = Object . entries < Record < string , any > > ( getSemanticTokens ( allTokens , filterMethod ) ) as [
99
+ string ,
100
+ Record < string , ColorToken > ,
101
+ ] [ ]
96
102
const hasResults =
97
103
! ! categorizedColors . length || ! ! uncategorizedColors ?. length || ! ! Object . values ( semanticTokens ) . length
98
104
0 commit comments