@marigold/system 0.0.2 → 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.
Files changed (47) hide show
  1. package/CHANGELOG.md +95 -0
  2. package/dist/Box.d.ts +14 -0
  3. package/dist/Global.d.ts +2 -0
  4. package/dist/SVG.d.ts +6 -0
  5. package/dist/index.d.ts +7 -4
  6. package/dist/normalize.d.ts +143 -5
  7. package/dist/system.cjs.development.js +334 -159
  8. package/dist/system.cjs.development.js.map +1 -1
  9. package/dist/system.cjs.production.min.js +1 -1
  10. package/dist/system.cjs.production.min.js.map +1 -1
  11. package/dist/system.esm.js +324 -156
  12. package/dist/system.esm.js.map +1 -1
  13. package/dist/theme.d.ts +136 -0
  14. package/dist/types.d.ts +8 -0
  15. package/dist/useTheme.d.ts +15 -5
  16. package/dist/variant.d.ts +29 -0
  17. package/package.json +6 -8
  18. package/src/Box.test.tsx +308 -0
  19. package/src/Box.tsx +199 -0
  20. package/src/Colors.stories.mdx +492 -448
  21. package/src/Global.test.tsx +57 -0
  22. package/src/Global.tsx +34 -0
  23. package/src/SVG.stories.mdx +55 -0
  24. package/src/SVG.test.tsx +82 -0
  25. package/src/SVG.tsx +24 -0
  26. package/src/concepts-principles.mdx +1 -1
  27. package/src/index.ts +7 -4
  28. package/src/normalize.test.tsx +15 -0
  29. package/src/normalize.ts +79 -93
  30. package/src/theme.ts +157 -0
  31. package/src/types.ts +14 -0
  32. package/src/useTheme.test.tsx +92 -17
  33. package/src/useTheme.tsx +45 -6
  34. package/src/variant.test.ts +93 -0
  35. package/src/variant.ts +54 -0
  36. package/dist/categories.d.ts +0 -169
  37. package/dist/system.d.ts +0 -37
  38. package/dist/useClassname.d.ts +0 -2
  39. package/dist/useStyles.d.ts +0 -10
  40. package/src/categories.ts +0 -203
  41. package/src/system.test.tsx +0 -84
  42. package/src/system.tsx +0 -55
  43. package/src/useClassname.test.tsx +0 -61
  44. package/src/useClassname.ts +0 -8
  45. package/src/useStyles.test.tsx +0 -313
  46. package/src/useStyles.ts +0 -56
  47. package/src/writeComponent.stories.mdx +0 -126
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
+ );