forked from system-ui/theme-ui
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBox.js
More file actions
43 lines (39 loc) · 1.01 KB
/
Box.js
File metadata and controls
43 lines (39 loc) · 1.01 KB
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
import styled from '@emotion/styled'
import { css, getVariantValue } from '@theme-ui/css'
import deepmerge from 'deepmerge'
import { createShouldForwardProp } from '@styled-system/should-forward-prop'
import space from '@styled-system/space'
import color from '@styled-system/color'
const shouldForwardProp = createShouldForwardProp([
...space.propNames,
...color.propNames,
])
const sx = (props) => css(props.sx)(props.theme)
const base = (props) => css(props.__css)(props.theme)
const variant = ({ theme, variant, __themeKey = 'variants' }) => {
if (Array.isArray(variant)) {
return css(
deepmerge.all(
variant.map((v) => getVariantValue(theme, __themeKey, v) || {}),
{ arrayMerge: (_dest, src) => src }
)
)
}
return css(getVariantValue(theme, __themeKey, variant))
}
export const Box = styled('div', {
shouldForwardProp,
})(
{
boxSizing: 'border-box',
margin: 0,
minWidth: 0,
},
base,
variant,
space,
color,
sx,
(props) => props.css
)
export default Box