Skip to content

Commit bbe11ec

Browse files
feat: move primitive color story to tailwind
1 parent 3aab0b5 commit bbe11ec

File tree

2 files changed

+92
-1
lines changed

2 files changed

+92
-1
lines changed

.storybook/main.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,9 @@ import type { StorybookConfig } from "@storybook/nextjs"
1717
const config: StorybookConfig = {
1818
stories: [
1919
"../src/components/**/*.stories.{ts,tsx}",
20-
"../src/@chakra-ui/stories/*.stories.tsx",
20+
// "../src/@chakra-ui/stories/*.stories.tsx",
2121
"../src/layouts/stories/*.stories.tsx",
22+
"../src/styles/*.stories.tsx",
2223
],
2324
addons: [
2425
"@storybook/addon-links",

src/styles/colors.stories.tsx

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
import { type ReactNode } from "react"
2+
import type { Meta, StoryObj } from "@storybook/react/"
3+
4+
import { HStack, Stack, VStack } from "@/components/ui/flex"
5+
6+
const meta = {
7+
title: "Design System/ShadCN Colors",
8+
parameters: {
9+
// Do not create snapshots for any stories in the file.
10+
chromatic: { disableSnapshot: true },
11+
},
12+
} satisfies Meta
13+
14+
export default meta
15+
16+
/**
17+
* Get all CSS Variables in the document.
18+
*
19+
* Used to search CSS Variables and retrieve their values.
20+
*
21+
* NOTE: Function created with AI assistance
22+
*/
23+
const getCSSCustomPropIndex = () => {
24+
const rootStyles = document.styleSheets
25+
const variables = {}
26+
27+
for (const sheet of rootStyles) {
28+
for (const rule of sheet.cssRules) {
29+
// Check for CSSStyleRule type as `selectorText` might not always be available
30+
if (rule instanceof CSSStyleRule && rule.selectorText === ":root") {
31+
for (const style of rule.style) {
32+
if (style.startsWith("--")) {
33+
variables[style] = rule.style.getPropertyValue(style).trim()
34+
}
35+
}
36+
}
37+
}
38+
}
39+
return variables as Record<string, string>
40+
}
41+
const primitiveColorKeys = ["gray", "purple"] as const
42+
export const Primitives: StoryObj = {
43+
render: () => {
44+
const cssVarsEntries = Object.entries(getCSSCustomPropIndex())
45+
46+
return (
47+
<Stack className="gap-16">
48+
{primitiveColorKeys.map((color) => (
49+
<ColorGroupWrapper key={color} color={color}>
50+
<HStack className="justify-between gap-4">
51+
{cssVarsEntries
52+
.filter(([key]) => key.startsWith(`--${color}`))
53+
.map(([tokenKey, value]) => (
54+
<VStack key={`${tokenKey}-${value}`}>
55+
<div>
56+
<div
57+
className="size-20"
58+
style={{ background: `hsla(var(${tokenKey}))` }}
59+
/>
60+
</div>
61+
<Stack>
62+
<span>{value}</span>
63+
<span>{tokenKey}</span>
64+
</Stack>
65+
</VStack>
66+
))}
67+
</HStack>
68+
</ColorGroupWrapper>
69+
))}
70+
</Stack>
71+
)
72+
},
73+
}
74+
75+
const ColorGroupWrapper = ({
76+
color,
77+
children,
78+
}: {
79+
color: (typeof primitiveColorKeys)[number]
80+
children: ReactNode
81+
}) => (
82+
<div
83+
key={color}
84+
className="bg-gradient-to-t from-[#1b1b1b] from-65% to-white to-35% p-8 text-white"
85+
>
86+
{children}
87+
</div>
88+
)
89+
90+
// bg-linear-[180deg,_#1b1b1b_35%,_#fff_35%]

0 commit comments

Comments
 (0)