forked from chakra-ui/chakra-ui-docs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcolor-palette.tsx
68 lines (59 loc) · 1.42 KB
/
color-palette.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import {
Box,
Flex,
FlexProps,
Grid,
GridProps,
useTheme,
} from '@chakra-ui/react'
import React from 'react'
type ColorPaletteProps = FlexProps & { color?: string; name?: string }
export const ColorPalette = (props: ColorPaletteProps) => {
const { color, name, ...rest } = props
const theme = useTheme()
let colorCode = color
const [shade, hue] = color.split('.')
if (shade && hue) {
colorCode = theme.colors[shade][hue]
}
if (color in theme.colors && typeof theme.colors[color] === 'string') {
colorCode = theme.colors[color]
}
return (
<Flex align='center' {...rest}>
<Box
borderRadius='md'
boxSize='3rem'
boxShadow='inner'
mr={3}
bgColor={color}
/>
<Box fontSize='sm'>
<Box fontWeight='semibold' textTransform='capitalize'>
{name}
</Box>
<Box textTransform='uppercase'>{colorCode}</Box>
</Box>
</Flex>
)
}
export const ColorPalettes = (props: { color: string }) => {
const { color } = props
const theme = useTheme()
const keys = Object.keys(theme.colors[color])
return keys.map((item) => (
<ColorPalette
key={`${color}.${item}`}
color={`${color}.${item}`}
name={`${color} ${item}`}
/>
))
}
export const ColorWrapper = (props: GridProps) => (
<Grid
mt={7}
gap={6}
templateColumns='repeat( auto-fit, minmax(200px, 1fr) )'
{...props}
/>
)