|
1 | 1 | 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" |
3 | 4 |
|
4 | 5 | import { HStack, Stack, VStack } from "@/components/ui/flex"
|
5 | 6 |
|
| 7 | +import { cn } from "@/lib/utils/cn" |
| 8 | + |
6 | 9 | const meta = {
|
7 | 10 | title: "Design System/ShadCN Colors",
|
8 | 11 | parameters: {
|
@@ -38,11 +41,12 @@ const getCSSCustomPropIndex = () => {
|
38 | 41 | }
|
39 | 42 | return variables as Record<string, string>
|
40 | 43 | }
|
| 44 | + |
| 45 | +const cssVarsEntries = Object.entries(getCSSCustomPropIndex()) |
| 46 | + |
41 | 47 | const primitiveColorKeys = ["gray", "purple"] as const
|
42 | 48 | export const Primitives: StoryObj = {
|
43 | 49 | render: () => {
|
44 |
| - const cssVarsEntries = Object.entries(getCSSCustomPropIndex()) |
45 |
| - |
46 | 50 | return (
|
47 | 51 | <Stack className="gap-16">
|
48 | 52 | {primitiveColorKeys.map((color) => (
|
@@ -87,4 +91,59 @@ const ColorGroupWrapper = ({
|
87 | 91 | </div>
|
88 | 92 | )
|
89 | 93 |
|
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