|
| 1 | +import type { ReactNode } from "react" |
| 2 | +import { Box, HStack, Square, Stack, Text } from "@chakra-ui/react" |
| 3 | +import type { Meta, StoryObj } from "@storybook/react" |
| 4 | + |
| 5 | +import colors from "@/@chakra-ui/foundations/colors" |
| 6 | + |
| 7 | +const meta = { |
| 8 | + title: "Design System/Colors", |
| 9 | +} satisfies Meta |
| 10 | + |
| 11 | +export default meta |
| 12 | + |
| 13 | +const primitiveColorKeys = ["gray", "blue", "orange"] |
| 14 | +export const Primitives: StoryObj = { |
| 15 | + render: () => { |
| 16 | + const primitiveColorsMap = Object.entries(colors) |
| 17 | + .filter((obj) => primitiveColorKeys.includes(obj[0])) |
| 18 | + .reduce<{ [tokenKey: string]: [string, string][] }>( |
| 19 | + (acc, [key, value]) => { |
| 20 | + const tokenMap = Object.entries(value) |
| 21 | + return { |
| 22 | + ...acc, |
| 23 | + [key]: tokenMap, |
| 24 | + } |
| 25 | + }, |
| 26 | + {} |
| 27 | + ) |
| 28 | + |
| 29 | + return ( |
| 30 | + <Stack direction="column" gap="16"> |
| 31 | + {primitiveColorKeys.map((color) => ( |
| 32 | + <ColorGroupWrapper key={color} color={color}> |
| 33 | + <HStack> |
| 34 | + {primitiveColorsMap[color].map(([tokenKey, value]) => ( |
| 35 | + <Stack key={`${color}${tokenKey}`} direction="column"> |
| 36 | + <Box> |
| 37 | + <Square size="20" bg={`${color}.${tokenKey}`}></Square> |
| 38 | + </Box> |
| 39 | + <Stack direction="column"> |
| 40 | + <Text size="sm">{value}</Text> |
| 41 | + <Text size="sm"> |
| 42 | + {color}.{tokenKey} |
| 43 | + </Text> |
| 44 | + </Stack> |
| 45 | + </Stack> |
| 46 | + ))} |
| 47 | + </HStack> |
| 48 | + </ColorGroupWrapper> |
| 49 | + ))} |
| 50 | + </Stack> |
| 51 | + ) |
| 52 | + }, |
| 53 | +} |
| 54 | + |
| 55 | +const ColorGroupWrapper = ({ |
| 56 | + color, |
| 57 | + children, |
| 58 | +}: { |
| 59 | + color: string |
| 60 | + children: ReactNode |
| 61 | +}) => { |
| 62 | + return ( |
| 63 | + <Box |
| 64 | + key={color} |
| 65 | + color={color === "orange" ? "white" : undefined} |
| 66 | + px="8" |
| 67 | + py="8" |
| 68 | + bg={ |
| 69 | + color === "gray" |
| 70 | + ? `linear-gradient(180deg, #1b1b1b 35%, #fff 35%)` |
| 71 | + : color === "orange" |
| 72 | + ? "gray.800" |
| 73 | + : undefined |
| 74 | + } |
| 75 | + > |
| 76 | + {children} |
| 77 | + </Box> |
| 78 | + ) |
| 79 | +} |
0 commit comments