@marigold/system 0.2.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +95 -0
- package/dist/Box.d.ts +14 -0
- package/dist/Global.d.ts +2 -0
- package/dist/SVG.d.ts +6 -0
- package/dist/index.d.ts +6 -4
- package/dist/normalize.d.ts +101 -67
- package/dist/system.cjs.development.js +299 -294
- package/dist/system.cjs.development.js.map +1 -1
- package/dist/system.cjs.production.min.js +1 -1
- package/dist/system.cjs.production.min.js.map +1 -1
- package/dist/system.esm.js +291 -289
- package/dist/system.esm.js.map +1 -1
- package/dist/theme.d.ts +136 -0
- package/dist/types.d.ts +1 -2
- package/dist/useTheme.d.ts +11 -5
- package/dist/variant.d.ts +29 -0
- package/package.json +4 -5
- package/src/Box.test.tsx +308 -0
- package/src/Box.tsx +199 -0
- package/src/Colors.stories.mdx +332 -456
- package/src/Global.test.tsx +57 -0
- package/src/Global.tsx +34 -0
- package/src/SVG.stories.mdx +55 -0
- package/src/SVG.test.tsx +82 -0
- package/src/SVG.tsx +24 -0
- package/src/index.ts +6 -4
- package/src/normalize.test.tsx +9 -36
- package/src/normalize.ts +51 -82
- package/src/theme.ts +157 -0
- package/src/types.ts +0 -2
- package/src/useTheme.test.tsx +22 -14
- package/src/useTheme.tsx +37 -9
- package/src/variant.test.ts +93 -0
- package/src/variant.ts +54 -0
- package/dist/Element.d.ts +0 -8
- package/dist/cache.d.ts +0 -4
- package/dist/reset.d.ts +0 -24
- package/dist/useClassname.d.ts +0 -2
- package/dist/useStyles.d.ts +0 -15
- package/src/Element.test.tsx +0 -203
- package/src/Element.tsx +0 -59
- package/src/cache.ts +0 -4
- package/src/reset.ts +0 -108
- package/src/useClassname.test.tsx +0 -70
- package/src/useClassname.ts +0 -23
- package/src/useStyles.stories.mdx +0 -24
- package/src/useStyles.test.tsx +0 -286
- package/src/useStyles.ts +0 -63
package/src/Box.tsx
ADDED
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
import { jsx, Theme } from '@emotion/react';
|
|
2
|
+
import { css as transformStyleObject } from '@theme-ui/css';
|
|
3
|
+
import { forwardRef } from 'react';
|
|
4
|
+
import {
|
|
5
|
+
PolymorphicPropsWithRef,
|
|
6
|
+
PolymorphicComponentWithRef,
|
|
7
|
+
} from '@marigold/types';
|
|
8
|
+
|
|
9
|
+
import { getNormalizedStyles } from './normalize';
|
|
10
|
+
import { CSSObject } from './types';
|
|
11
|
+
import { ensureArrayVariant } from './variant';
|
|
12
|
+
|
|
13
|
+
export type StyleProps = Pick<
|
|
14
|
+
CSSObject,
|
|
15
|
+
| 'display'
|
|
16
|
+
| 'height'
|
|
17
|
+
| 'width'
|
|
18
|
+
| 'minWidth'
|
|
19
|
+
| 'maxWidth'
|
|
20
|
+
| 'position'
|
|
21
|
+
| 'top'
|
|
22
|
+
| 'bottom'
|
|
23
|
+
| 'right'
|
|
24
|
+
| 'left'
|
|
25
|
+
| 'zIndex'
|
|
26
|
+
| 'p'
|
|
27
|
+
| 'px'
|
|
28
|
+
| 'py'
|
|
29
|
+
| 'pt'
|
|
30
|
+
| 'pb'
|
|
31
|
+
| 'pl'
|
|
32
|
+
| 'pr'
|
|
33
|
+
| 'm'
|
|
34
|
+
| 'mx'
|
|
35
|
+
| 'my'
|
|
36
|
+
| 'mt'
|
|
37
|
+
| 'mb'
|
|
38
|
+
| 'ml'
|
|
39
|
+
| 'mr'
|
|
40
|
+
| 'flexDirection'
|
|
41
|
+
| 'flexWrap'
|
|
42
|
+
| 'flexShrink'
|
|
43
|
+
| 'flexGrow'
|
|
44
|
+
| 'alignItems'
|
|
45
|
+
| 'justifyContent'
|
|
46
|
+
| 'bg'
|
|
47
|
+
| 'border'
|
|
48
|
+
| 'borderRadius'
|
|
49
|
+
| 'boxShadow'
|
|
50
|
+
| 'opacity'
|
|
51
|
+
| 'overflow'
|
|
52
|
+
| 'transition'
|
|
53
|
+
>;
|
|
54
|
+
|
|
55
|
+
export type BoxOwnProps = {
|
|
56
|
+
css?: CSSObject;
|
|
57
|
+
variant?: string | string[];
|
|
58
|
+
/**
|
|
59
|
+
* Use to set base styles for the component
|
|
60
|
+
* @internal Used to set default styles for Marigold components
|
|
61
|
+
*/
|
|
62
|
+
__baseCSS?: CSSObject;
|
|
63
|
+
} & StyleProps;
|
|
64
|
+
|
|
65
|
+
export type BoxProps = PolymorphicPropsWithRef<BoxOwnProps, 'div'>;
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Check if there is any falsy value or empty object
|
|
69
|
+
*/
|
|
70
|
+
const isNotEmpty = (val: any) =>
|
|
71
|
+
!(val && Object.keys(val).length === 0 && val.constructor === Object);
|
|
72
|
+
|
|
73
|
+
type CreateStyleProps = {
|
|
74
|
+
as?: BoxProps['as'];
|
|
75
|
+
__baseCSS?: BoxOwnProps['__baseCSS'];
|
|
76
|
+
variant?: BoxOwnProps['variant'];
|
|
77
|
+
css?: BoxOwnProps['css'];
|
|
78
|
+
styles?: StyleProps;
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
const createThemedStyle =
|
|
82
|
+
({ as, __baseCSS, variant, styles, css }: CreateStyleProps) =>
|
|
83
|
+
(theme: Theme) => {
|
|
84
|
+
return [
|
|
85
|
+
getNormalizedStyles(as),
|
|
86
|
+
transformStyleObject(__baseCSS)(theme),
|
|
87
|
+
...ensureArrayVariant(variant).map(v =>
|
|
88
|
+
transformStyleObject({ variant: v })(theme)
|
|
89
|
+
),
|
|
90
|
+
transformStyleObject(styles)(theme),
|
|
91
|
+
transformStyleObject(css)(theme),
|
|
92
|
+
].filter(isNotEmpty);
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
export const Box: PolymorphicComponentWithRef<BoxOwnProps, 'div'> = forwardRef(
|
|
96
|
+
(
|
|
97
|
+
{
|
|
98
|
+
as = 'div',
|
|
99
|
+
children,
|
|
100
|
+
__baseCSS,
|
|
101
|
+
variant,
|
|
102
|
+
css = {},
|
|
103
|
+
display,
|
|
104
|
+
height,
|
|
105
|
+
width,
|
|
106
|
+
minWidth,
|
|
107
|
+
maxWidth,
|
|
108
|
+
position,
|
|
109
|
+
top,
|
|
110
|
+
bottom,
|
|
111
|
+
right,
|
|
112
|
+
left,
|
|
113
|
+
zIndex,
|
|
114
|
+
p,
|
|
115
|
+
px,
|
|
116
|
+
py,
|
|
117
|
+
pt,
|
|
118
|
+
pb,
|
|
119
|
+
pl,
|
|
120
|
+
pr,
|
|
121
|
+
m,
|
|
122
|
+
mx,
|
|
123
|
+
my,
|
|
124
|
+
mt,
|
|
125
|
+
mb,
|
|
126
|
+
ml,
|
|
127
|
+
mr,
|
|
128
|
+
flexDirection,
|
|
129
|
+
flexWrap,
|
|
130
|
+
flexShrink,
|
|
131
|
+
flexGrow,
|
|
132
|
+
alignItems,
|
|
133
|
+
justifyContent,
|
|
134
|
+
bg,
|
|
135
|
+
border,
|
|
136
|
+
borderRadius,
|
|
137
|
+
boxShadow,
|
|
138
|
+
opacity,
|
|
139
|
+
overflow,
|
|
140
|
+
transition,
|
|
141
|
+
...props
|
|
142
|
+
},
|
|
143
|
+
ref
|
|
144
|
+
) =>
|
|
145
|
+
jsx(
|
|
146
|
+
as,
|
|
147
|
+
{
|
|
148
|
+
...props,
|
|
149
|
+
css: createThemedStyle({
|
|
150
|
+
as,
|
|
151
|
+
__baseCSS,
|
|
152
|
+
variant,
|
|
153
|
+
css,
|
|
154
|
+
styles: {
|
|
155
|
+
display,
|
|
156
|
+
height,
|
|
157
|
+
width,
|
|
158
|
+
minWidth,
|
|
159
|
+
maxWidth,
|
|
160
|
+
position,
|
|
161
|
+
top,
|
|
162
|
+
bottom,
|
|
163
|
+
right,
|
|
164
|
+
left,
|
|
165
|
+
zIndex,
|
|
166
|
+
p,
|
|
167
|
+
px,
|
|
168
|
+
py,
|
|
169
|
+
pt,
|
|
170
|
+
pb,
|
|
171
|
+
pl,
|
|
172
|
+
pr,
|
|
173
|
+
m,
|
|
174
|
+
mx,
|
|
175
|
+
my,
|
|
176
|
+
mt,
|
|
177
|
+
mb,
|
|
178
|
+
ml,
|
|
179
|
+
mr,
|
|
180
|
+
flexDirection,
|
|
181
|
+
flexWrap,
|
|
182
|
+
flexShrink,
|
|
183
|
+
flexGrow,
|
|
184
|
+
alignItems,
|
|
185
|
+
justifyContent,
|
|
186
|
+
bg,
|
|
187
|
+
border,
|
|
188
|
+
borderRadius,
|
|
189
|
+
boxShadow,
|
|
190
|
+
opacity,
|
|
191
|
+
overflow,
|
|
192
|
+
transition,
|
|
193
|
+
},
|
|
194
|
+
}),
|
|
195
|
+
ref,
|
|
196
|
+
},
|
|
197
|
+
children
|
|
198
|
+
)
|
|
199
|
+
);
|