import { Box, Center, useColorMode } from '@chakra-ui/react'; import { Flex, FlexProps, Text, VStack } from '@chakra-ui/react'; import { Meta } from '@storybook/react'; import { Fragment } from 'react'; import { theme } from '../../modules/theme'; import { primitives } from '../../modules/theme/foundations/colors/primitives'; import { Space } from '../Space'; const spectrum = (value: Object) => { return Object.entries(value).filter(([_, v]) => typeof v !== 'string'); }; const single = (value: Object) => { return Object.entries(value).filter(([_, v]) => typeof v === 'string'); }; const getPaths = (value: any, path: Array, result: Map): any => { for (const [k, v] of Object.entries(value)) { if (typeof v === 'string') { result.set([...path, k].join('.'), v); continue; } getPaths(value[k], [...path, k], result); } }; export default { title: 'Foundations/Color', } as Meta; const hexToRGB = (value: string) => { const bigint = parseInt(value.replace('#', '0x'), 16); const r = (bigint >> 16) & 255; const g = (bigint >> 8) & 255; const b = bigint & 255; return { r, g, b }; }; const Card = ({ label, hex, type, }: { label: string; hex: string; type: 'hex' | 'path' } & FlexProps) => { const { r, g, b } = hexToRGB(hex); const map = new Map(); getPaths(primitives, [], map); return ( {label} {type === 'hex' && hex} {/* TODO: This doesn't work with new colour structure. */} {type === 'path' && map.get(hex)} ); }; const Spectrum = ({ k, v, type }: { k: string; v: Object; type: 'hex' | 'path' }) => { return ( {/* Handle black and white in foreground. */} {typeof v === 'string' ? ( ) : ( Object.entries(v).map(([number, v]) => { return ; }) )} ); }; export const Default = () => { const { colorMode } = useColorMode(); const map = new Map(); getPaths(theme.colors[colorMode], [], map); let previous: string | null = null; const colors: React.ReactNode[] = []; for (const [k, v] of map.entries()) { const key = k.split('.')[0]; if (previous && previous !== key) { colors.push(); } colors.push( {k} , ); previous = key; } return ( {colors.map((it, index) => { return {it}; })} ); }; export const Primitives = () => { const singles = single(primitives); return ( {spectrum(primitives).map(([k, v]) => ( ))} {singles.map(([k, v]) => { return ; })} ); }; /* export const Roles = () => { const { colorMode } = useColorMode(); return ( {spectrum(theme.colors[colorMode]) .filter(([k, _]) => ['foreground', 'background', 'border'].includes(k)) .map(([group, v]) => { return ( {Object.entries(v).map(([k, v]) => ( ))} ); })} ); }; */ export const Shadows = () => { const { colorMode } = useColorMode(); return ( {Object.entries(theme.colors[colorMode].shadow).map(([k, v]) => { return (
); })} ); };