Skip to content

Commit 300be0c

Browse files
refactor(Colors.stories.tsx): add more tokens to Semantic Scheme story
1 parent 852e43c commit 300be0c

File tree

1 file changed

+59
-18
lines changed

1 file changed

+59
-18
lines changed

src/components/BaseStories/Colors.stories.tsx

Lines changed: 59 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import type { Meta, StoryObj } from "@storybook/react"
66
import colors from "@/@chakra-ui/foundations/colors"
77
import semanticTokens from "@/@chakra-ui/semanticTokens"
88

9+
const semanticTokenColors = semanticTokens["colors"]
10+
911
import Heading from "../Heading"
1012

1113
const meta = {
@@ -100,11 +102,23 @@ export const SemanticScheme: StoryObj = {
100102
},
101103
},
102104
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[]> = {
105115
primary: ["light", "dark", "pressed"],
106116
body: ["inverted"],
107117
background: [],
118+
disabled: [],
119+
success: ["neutral", "outline"],
120+
attention: ["neutral", "outline"],
121+
error: ["neutral", "outline"],
108122
}
109123
return (
110124
<Flex direction="column" gap="16">
@@ -113,26 +127,35 @@ export const SemanticScheme: StoryObj = {
113127
tokenName
114128
] as string[]
115129

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+
116139
return (
117140
<Flex key={tokenName} direction="column" gap="4">
118141
<Heading>{capitalize(tokenName)}</Heading>
119142
<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+
)}
136159
</HStack>
137160
</Flex>
138161
)
@@ -141,3 +164,21 @@ export const SemanticScheme: StoryObj = {
141164
)
142165
},
143166
}
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

Comments
 (0)