@@ -6,6 +6,8 @@ import type { Meta, StoryObj } from "@storybook/react"
6
6
import colors from "@/@chakra-ui/foundations/colors"
7
7
import semanticTokens from "@/@chakra-ui/semanticTokens"
8
8
9
+ const semanticTokenColors = semanticTokens [ "colors" ]
10
+
9
11
import Heading from "../Heading"
10
12
11
13
const meta = {
@@ -100,11 +102,23 @@ export const SemanticScheme: StoryObj = {
100
102
} ,
101
103
} ,
102
104
render : ( ) => {
103
- const tokenNames = [ "primary" , "body" , "background" ] as const
104
- const deprecatedTokens = {
105
+ const tokenNames = [
106
+ "primary" ,
107
+ "body" ,
108
+ "background" ,
109
+ "disabled" ,
110
+ "success" ,
111
+ "attention" ,
112
+ "error" ,
113
+ ] as const
114
+ const deprecatedTokens : Record < ( typeof tokenNames ) [ number ] , string [ ] > = {
105
115
primary : [ "light" , "dark" , "pressed" ] ,
106
116
body : [ "inverted" ] ,
107
117
background : [ ] ,
118
+ disabled : [ ] ,
119
+ success : [ "neutral" , "outline" ] ,
120
+ attention : [ "neutral" , "outline" ] ,
121
+ error : [ "neutral" , "outline" ] ,
108
122
}
109
123
return (
110
124
< Flex direction = "column" gap = "16" >
@@ -113,26 +127,35 @@ export const SemanticScheme: StoryObj = {
113
127
tokenName
114
128
] as string [ ]
115
129
130
+ const tokenObj = semanticTokenColors [ tokenName ]
131
+
132
+ const filteredTokenObj =
133
+ "base" in tokenObj
134
+ ? Object . keys ( semanticTokens [ "colors" ] [ tokenName ] ) . filter (
135
+ ( key ) => ! currentDeprecatedTokens . includes ( key )
136
+ )
137
+ : undefined
138
+
116
139
return (
117
140
< Flex key = { tokenName } direction = "column" gap = "4" >
118
141
< Heading > { capitalize ( tokenName ) } </ Heading >
119
142
< HStack gap = "8" >
120
- { Object . keys ( semanticTokens [ "colors" ] [ tokenName ] )
121
- . filter ( ( key ) => ! currentDeprecatedTokens . includes ( key ) )
122
- . map ( ( key ) => (
123
- < Flex key = { key } direction = "column" gap = "2" >
124
- < Square
125
- border = {
126
- tokenName === "background" && key === "base"
127
- ? "1px solid"
128
- : undefined
129
- }
130
- size = "20"
131
- bg = { ` ${ tokenName } . ${ key } ` }
132
- > </ Square >
133
- < Text > { key } </ Text >
134
- </ Flex >
135
- ) ) }
143
+ { ! filteredTokenObj ? (
144
+ < SemanticColorBlock
145
+ nestedKey = { tokenName }
146
+ tokenName = { tokenName }
147
+ />
148
+ ) : (
149
+ < >
150
+ { filteredTokenObj . map ( ( nestedKey ) => (
151
+ < SemanticColorBlock
152
+ key = { nestedKey }
153
+ nestedKey = { nestedKey }
154
+ tokenName = { tokenName }
155
+ / >
156
+ ) ) }
157
+ </ >
158
+ ) }
136
159
</ HStack >
137
160
</ Flex >
138
161
)
@@ -141,3 +164,21 @@ export const SemanticScheme: StoryObj = {
141
164
)
142
165
} ,
143
166
}
167
+
168
+ const SemanticColorBlock = ( {
169
+ nestedKey,
170
+ tokenName,
171
+ } : Record < "nestedKey" | "tokenName" , string > ) => (
172
+ < Flex key = { nestedKey } direction = "column" gap = "2" >
173
+ < Square
174
+ border = {
175
+ tokenName === "background" && nestedKey === "base"
176
+ ? "1px solid"
177
+ : undefined
178
+ }
179
+ size = "20"
180
+ bg = { tokenName === nestedKey ? tokenName : `${ tokenName } .${ nestedKey } ` }
181
+ > </ Square >
182
+ < Text > { nestedKey } </ Text >
183
+ </ Flex >
184
+ )
0 commit comments