Skip to content

Commit f06889f

Browse files
feat: move semantic color story to tailwind
1 parent bbe11ec commit f06889f

File tree

1 file changed

+63
-4
lines changed

1 file changed

+63
-4
lines changed

src/styles/colors.stories.tsx

Lines changed: 63 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
import { type ReactNode } from "react"
2-
import type { Meta, StoryObj } from "@storybook/react/"
2+
import capitalize from "lodash/capitalize"
3+
import type { Meta, StoryObj } from "@storybook/react"
34

45
import { HStack, Stack, VStack } from "@/components/ui/flex"
56

7+
import { cn } from "@/lib/utils/cn"
8+
69
const meta = {
710
title: "Design System/ShadCN Colors",
811
parameters: {
@@ -38,11 +41,12 @@ const getCSSCustomPropIndex = () => {
3841
}
3942
return variables as Record<string, string>
4043
}
44+
45+
const cssVarsEntries = Object.entries(getCSSCustomPropIndex())
46+
4147
const primitiveColorKeys = ["gray", "purple"] as const
4248
export const Primitives: StoryObj = {
4349
render: () => {
44-
const cssVarsEntries = Object.entries(getCSSCustomPropIndex())
45-
4650
return (
4751
<Stack className="gap-16">
4852
{primitiveColorKeys.map((color) => (
@@ -87,4 +91,59 @@ const ColorGroupWrapper = ({
8791
</div>
8892
)
8993

90-
// bg-linear-[180deg,_#1b1b1b_35%,_#fff_35%]
94+
export const SemanticScheme: StoryObj = {
95+
render: () => {
96+
const tokenNames = [
97+
"primary",
98+
"body",
99+
"background",
100+
"disabled",
101+
"success",
102+
"warning",
103+
"error",
104+
] as const
105+
106+
return (
107+
<Stack className="gap-16">
108+
{tokenNames.map((tokenName) => {
109+
const variableObj = cssVarsEntries.filter(([key]) =>
110+
key.startsWith(`--${tokenName}`)
111+
)
112+
113+
return (
114+
<Stack key={tokenName} className="gap-4">
115+
<h2>{capitalize(tokenName)}</h2>
116+
<HStack className="gap-8">
117+
{variableObj.map((variable) => (
118+
<SemanticColorBlock
119+
key={JSON.stringify(variable)}
120+
variable={variable}
121+
/>
122+
))}
123+
</HStack>
124+
</Stack>
125+
)
126+
})}
127+
</Stack>
128+
)
129+
},
130+
}
131+
132+
const SemanticColorBlock = ({
133+
variable: [varName, varValue],
134+
}: {
135+
variable: [string, string]
136+
}) => (
137+
<VStack key={`${varName}-${varValue}`} className="mb-auto">
138+
<div
139+
className={cn(
140+
"size-20",
141+
varName === "--background" || varName === "--body-inverse"
142+
? "border"
143+
: undefined
144+
)}
145+
style={{ background: `hsla(var(${varName}))` }}
146+
/>
147+
<span>{varName}</span>
148+
</VStack>
149+
)

0 commit comments

Comments
 (0)