@marigold/system 0.7.0 → 1.0.0-beta.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/dist/index.d.ts +224 -154
- package/dist/index.js +183 -65
- package/dist/index.mjs +168 -42
- package/package.json +11 -8
package/dist/index.d.ts
CHANGED
|
@@ -1,17 +1,14 @@
|
|
|
1
|
-
import { PolymorphicPropsWithRef, PolymorphicComponentWithRef, ComponentProps } from '@marigold/types';
|
|
1
|
+
import { Simplify, PolymorphicPropsWithRef, PolymorphicComponentWithRef, ComponentProps, KebabCase } from '@marigold/types';
|
|
2
2
|
import * as _theme_ui_css from '@theme-ui/css';
|
|
3
3
|
import { ResponsiveStyleValue as ResponsiveStyleValue$1, ThemeUIStyleObject, ThemeUICSSObject, ThemeUICSSProperties, NestedScaleDict } from '@theme-ui/css';
|
|
4
|
-
import
|
|
4
|
+
import * as react from 'react';
|
|
5
|
+
import { ReactNode, ElementType } from 'react';
|
|
5
6
|
import * as CSS from 'csstype';
|
|
6
7
|
|
|
7
|
-
/**
|
|
8
|
-
* Create type aliases for `theme-ui` so that it doesn't leak too much into our code.
|
|
9
|
-
*/
|
|
10
|
-
|
|
11
8
|
declare type ResponsiveStyleValue<T> = ResponsiveStyleValue$1<T>;
|
|
12
9
|
declare type StyleObject = ThemeUIStyleObject;
|
|
13
|
-
declare type CSSObject = ThemeUICSSObject
|
|
14
|
-
declare type CSSProperties = ThemeUICSSProperties
|
|
10
|
+
declare type CSSObject = Simplify<ThemeUICSSObject>;
|
|
11
|
+
declare type CSSProperties = Simplify<ThemeUICSSProperties>;
|
|
15
12
|
|
|
16
13
|
interface StyleProps extends Pick<CSSObject, 'display' | 'height' | 'width' | 'minWidth' | 'maxWidth' | 'position' | 'top' | 'bottom' | 'right' | 'left' | 'zIndex' | 'p' | 'px' | 'py' | 'pt' | 'pb' | 'pl' | 'pr' | 'm' | 'mx' | 'my' | 'mt' | 'mb' | 'ml' | 'mr' | 'flexDirection' | 'flexWrap' | 'flexShrink' | 'flexGrow' | 'alignItems' | 'justifyContent' | 'bg' | 'border' | 'borderRadius' | 'boxShadow' | 'opacity' | 'overflow' | 'transition'> {
|
|
17
14
|
}
|
|
@@ -30,160 +27,52 @@ declare const Box: PolymorphicComponentWithRef<BoxOwnProps, 'div'>;
|
|
|
30
27
|
|
|
31
28
|
declare const Global: () => JSX.Element;
|
|
32
29
|
|
|
30
|
+
interface SVGProps extends ComponentProps<'svg'> {
|
|
31
|
+
size?: number | string | number[] | string[];
|
|
32
|
+
}
|
|
33
|
+
declare const SVG: ({ size, fill, children, ...props }: SVGProps) => react.ReactSVGElement;
|
|
34
|
+
|
|
33
35
|
/**
|
|
34
|
-
*
|
|
35
|
-
* Based on https://www.joshwcomeau.com/css/custom-css-reset/
|
|
36
|
+
* Props that every component should accepts to change the styling
|
|
36
37
|
*/
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
};
|
|
50
|
-
readonly p: {
|
|
51
|
-
readonly overflowWrap: "break-word";
|
|
52
|
-
readonly boxSizing: "border-box";
|
|
53
|
-
readonly margin: 0;
|
|
54
|
-
readonly minWidth: 0;
|
|
55
|
-
};
|
|
56
|
-
readonly h1: {
|
|
57
|
-
readonly overflowWrap: "break-word";
|
|
58
|
-
readonly boxSizing: "border-box";
|
|
59
|
-
readonly margin: 0;
|
|
60
|
-
readonly minWidth: 0;
|
|
61
|
-
};
|
|
62
|
-
readonly h2: {
|
|
63
|
-
readonly overflowWrap: "break-word";
|
|
64
|
-
readonly boxSizing: "border-box";
|
|
65
|
-
readonly margin: 0;
|
|
66
|
-
readonly minWidth: 0;
|
|
67
|
-
};
|
|
68
|
-
readonly h3: {
|
|
69
|
-
readonly overflowWrap: "break-word";
|
|
70
|
-
readonly boxSizing: "border-box";
|
|
71
|
-
readonly margin: 0;
|
|
72
|
-
readonly minWidth: 0;
|
|
73
|
-
};
|
|
74
|
-
readonly h4: {
|
|
75
|
-
readonly overflowWrap: "break-word";
|
|
76
|
-
readonly boxSizing: "border-box";
|
|
77
|
-
readonly margin: 0;
|
|
78
|
-
readonly minWidth: 0;
|
|
79
|
-
};
|
|
80
|
-
readonly h5: {
|
|
81
|
-
readonly overflowWrap: "break-word";
|
|
82
|
-
readonly boxSizing: "border-box";
|
|
83
|
-
readonly margin: 0;
|
|
84
|
-
readonly minWidth: 0;
|
|
85
|
-
};
|
|
86
|
-
readonly h6: {
|
|
87
|
-
readonly overflowWrap: "break-word";
|
|
88
|
-
readonly boxSizing: "border-box";
|
|
89
|
-
readonly margin: 0;
|
|
90
|
-
readonly minWidth: 0;
|
|
91
|
-
};
|
|
92
|
-
readonly img: {
|
|
93
|
-
readonly display: "block";
|
|
94
|
-
readonly maxWidth: "100%";
|
|
95
|
-
readonly boxSizing: "border-box";
|
|
96
|
-
readonly margin: 0;
|
|
97
|
-
readonly minWidth: 0;
|
|
98
|
-
};
|
|
99
|
-
readonly picture: {
|
|
100
|
-
readonly display: "block";
|
|
101
|
-
readonly maxWidth: "100%";
|
|
102
|
-
readonly boxSizing: "border-box";
|
|
103
|
-
readonly margin: 0;
|
|
104
|
-
readonly minWidth: 0;
|
|
105
|
-
};
|
|
106
|
-
readonly video: {
|
|
107
|
-
readonly display: "block";
|
|
108
|
-
readonly maxWidth: "100%";
|
|
109
|
-
readonly boxSizing: "border-box";
|
|
110
|
-
readonly margin: 0;
|
|
111
|
-
readonly minWidth: 0;
|
|
112
|
-
};
|
|
113
|
-
readonly canvas: {
|
|
114
|
-
readonly display: "block";
|
|
115
|
-
readonly maxWidth: "100%";
|
|
116
|
-
readonly boxSizing: "border-box";
|
|
117
|
-
readonly margin: 0;
|
|
118
|
-
readonly minWidth: 0;
|
|
119
|
-
};
|
|
120
|
-
readonly svg: {
|
|
121
|
-
readonly display: "block";
|
|
122
|
-
readonly maxWidth: "100%";
|
|
123
|
-
readonly boxSizing: "border-box";
|
|
124
|
-
readonly margin: 0;
|
|
125
|
-
readonly minWidth: 0;
|
|
126
|
-
};
|
|
127
|
-
readonly select: {
|
|
128
|
-
readonly display: "block";
|
|
129
|
-
readonly appearance: "none";
|
|
130
|
-
readonly font: "inherit";
|
|
131
|
-
readonly '&::-ms-expand': {
|
|
132
|
-
readonly display: "none";
|
|
133
|
-
};
|
|
134
|
-
readonly boxSizing: "border-box";
|
|
135
|
-
readonly margin: 0;
|
|
136
|
-
readonly minWidth: 0;
|
|
137
|
-
};
|
|
138
|
-
readonly button: {
|
|
139
|
-
readonly display: "block";
|
|
140
|
-
readonly appearance: "none";
|
|
141
|
-
readonly font: "inherit";
|
|
142
|
-
readonly background: "transparent";
|
|
143
|
-
readonly textAlign: "center";
|
|
144
|
-
readonly boxSizing: "border-box";
|
|
145
|
-
readonly margin: 0;
|
|
146
|
-
readonly minWidth: 0;
|
|
147
|
-
};
|
|
148
|
-
readonly textarea: {
|
|
149
|
-
readonly display: "block";
|
|
150
|
-
readonly appearance: "none";
|
|
151
|
-
readonly font: "inherit";
|
|
152
|
-
readonly boxSizing: "border-box";
|
|
153
|
-
readonly margin: 0;
|
|
154
|
-
readonly minWidth: 0;
|
|
155
|
-
};
|
|
156
|
-
readonly input: {
|
|
157
|
-
readonly display: "block";
|
|
158
|
-
readonly appearance: "none";
|
|
159
|
-
readonly font: "inherit";
|
|
160
|
-
readonly '&::-ms-clear': {
|
|
161
|
-
readonly display: "none";
|
|
38
|
+
declare type ThemeComponentProps = {
|
|
39
|
+
variant?: string;
|
|
40
|
+
size?: string;
|
|
41
|
+
};
|
|
42
|
+
/**
|
|
43
|
+
* Structure for component styles in a theme.
|
|
44
|
+
*/
|
|
45
|
+
declare type ThemeExtension<ComponentName extends string> = {
|
|
46
|
+
[P in ComponentName]?: {
|
|
47
|
+
base?: CSSObject;
|
|
48
|
+
variant?: {
|
|
49
|
+
[key: string]: CSSObject;
|
|
162
50
|
};
|
|
163
|
-
|
|
164
|
-
|
|
51
|
+
size?: {
|
|
52
|
+
[key: string]: CSSObject;
|
|
165
53
|
};
|
|
166
|
-
readonly boxSizing: "border-box";
|
|
167
|
-
readonly margin: 0;
|
|
168
|
-
readonly minWidth: 0;
|
|
169
54
|
};
|
|
170
55
|
};
|
|
171
|
-
declare type NormalizedElement = keyof typeof normalize;
|
|
172
56
|
/**
|
|
173
|
-
*
|
|
174
|
-
* returns the *base* normalization.
|
|
57
|
+
* Structure for component styles in a theme that consists of multiple parts.
|
|
175
58
|
*/
|
|
176
|
-
declare
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
59
|
+
declare type ThemeExtensionsWithParts<ComponentName extends string, Parts extends string[]> = {
|
|
60
|
+
[P in ComponentName]?: {
|
|
61
|
+
base?: {
|
|
62
|
+
[Part in Parts[number]]?: CSSObject;
|
|
63
|
+
};
|
|
64
|
+
variant?: {
|
|
65
|
+
[key: string]: {
|
|
66
|
+
[Part in Parts[number]]?: CSSObject;
|
|
67
|
+
};
|
|
68
|
+
};
|
|
69
|
+
size?: {
|
|
70
|
+
[key: string]: {
|
|
71
|
+
[Part in Parts[number]]?: CSSObject;
|
|
72
|
+
};
|
|
73
|
+
};
|
|
74
|
+
};
|
|
180
75
|
};
|
|
181
|
-
|
|
182
|
-
interface SVGProps extends ComponentProps<'svg'> {
|
|
183
|
-
size?: number;
|
|
184
|
-
}
|
|
185
|
-
declare const SVG: React.FC<SVGProps>;
|
|
186
|
-
|
|
187
76
|
/**
|
|
188
77
|
* Value used to define a scale.
|
|
189
78
|
*
|
|
@@ -330,6 +219,22 @@ interface Theme {
|
|
|
330
219
|
transitions?: Scale<CSS.Property.Transition>;
|
|
331
220
|
}
|
|
332
221
|
|
|
222
|
+
interface ComponentStylesProps {
|
|
223
|
+
variant?: string;
|
|
224
|
+
size?: string;
|
|
225
|
+
}
|
|
226
|
+
declare type ComponentStyleParts<Parts extends string[]> = {
|
|
227
|
+
[P in Parts[number]]: CSSObject;
|
|
228
|
+
};
|
|
229
|
+
declare function useComponentStyles(componentName: string, props?: ComponentStylesProps, options?: {
|
|
230
|
+
parts: never;
|
|
231
|
+
}): CSSObject;
|
|
232
|
+
declare function useComponentStyles<Part extends string, Parts extends ReadonlyArray<Part>>(componentName: string, props?: ComponentStylesProps, options?: {
|
|
233
|
+
parts: Parts;
|
|
234
|
+
}): {
|
|
235
|
+
[P in Parts[number]]: CSSObject;
|
|
236
|
+
};
|
|
237
|
+
|
|
333
238
|
/**
|
|
334
239
|
* Hook that can be used to return values based on the current screen size,
|
|
335
240
|
* using breakpoints from the theme (`theme.breakpoints`). Note that this
|
|
@@ -337,6 +242,21 @@ interface Theme {
|
|
|
337
242
|
*/
|
|
338
243
|
declare const useResponsiveValue: <T>(values: T[], defaultIndex?: number) => T;
|
|
339
244
|
|
|
245
|
+
declare type ComponentState = 'hover' | 'focus' | 'focusVisible' | 'active' | 'visited' | 'disabled' | 'readOnly' | 'checked' | 'selected' | 'indeterminate' | 'expanded' | 'error';
|
|
246
|
+
declare type StateAttrKeyProps = `data-${KebabCase<ComponentState>}`;
|
|
247
|
+
declare type StateAttrProps = {
|
|
248
|
+
[key in StateAttrKeyProps]?: '';
|
|
249
|
+
};
|
|
250
|
+
declare type UseStateProps = {
|
|
251
|
+
[key in ComponentState]?: boolean;
|
|
252
|
+
};
|
|
253
|
+
/**
|
|
254
|
+
* Given a map of states (e.g. `{ hover: true, focus: false }`) returns an
|
|
255
|
+
* object that can be used to set state props on a component
|
|
256
|
+
* (e.g. `[data-hover]` and `[data-focus]`).
|
|
257
|
+
*/
|
|
258
|
+
declare const useStateProps: (states: UseStateProps) => StateAttrProps;
|
|
259
|
+
|
|
340
260
|
/**
|
|
341
261
|
* @internal
|
|
342
262
|
*/
|
|
@@ -344,6 +264,7 @@ declare const __defaultTheme: Theme;
|
|
|
344
264
|
declare const useTheme: () => {
|
|
345
265
|
theme: Theme;
|
|
346
266
|
css: (style: StyleObject) => _theme_ui_css.CSSObject;
|
|
267
|
+
get: (path: string) => any;
|
|
347
268
|
};
|
|
348
269
|
interface ThemeProviderProps<T extends Theme> {
|
|
349
270
|
theme: T;
|
|
@@ -351,6 +272,155 @@ interface ThemeProviderProps<T extends Theme> {
|
|
|
351
272
|
}
|
|
352
273
|
declare function ThemeProvider<T extends Theme>({ theme, children, }: ThemeProviderProps<T>): JSX.Element;
|
|
353
274
|
|
|
275
|
+
/**
|
|
276
|
+
* Normalize styling of certain elements between browsers.
|
|
277
|
+
* Based on https://www.joshwcomeau.com/css/custom-css-reset/
|
|
278
|
+
*/
|
|
279
|
+
|
|
280
|
+
declare const normalize: {
|
|
281
|
+
readonly base: {
|
|
282
|
+
readonly boxSizing: "border-box";
|
|
283
|
+
readonly margin: 0;
|
|
284
|
+
readonly minWidth: 0;
|
|
285
|
+
};
|
|
286
|
+
readonly a: {
|
|
287
|
+
readonly textDecoration: "none";
|
|
288
|
+
readonly boxSizing: "border-box";
|
|
289
|
+
readonly margin: 0;
|
|
290
|
+
readonly minWidth: 0;
|
|
291
|
+
};
|
|
292
|
+
readonly p: {
|
|
293
|
+
readonly overflowWrap: "break-word";
|
|
294
|
+
readonly boxSizing: "border-box";
|
|
295
|
+
readonly margin: 0;
|
|
296
|
+
readonly minWidth: 0;
|
|
297
|
+
};
|
|
298
|
+
readonly h1: {
|
|
299
|
+
readonly overflowWrap: "break-word";
|
|
300
|
+
readonly boxSizing: "border-box";
|
|
301
|
+
readonly margin: 0;
|
|
302
|
+
readonly minWidth: 0;
|
|
303
|
+
};
|
|
304
|
+
readonly h2: {
|
|
305
|
+
readonly overflowWrap: "break-word";
|
|
306
|
+
readonly boxSizing: "border-box";
|
|
307
|
+
readonly margin: 0;
|
|
308
|
+
readonly minWidth: 0;
|
|
309
|
+
};
|
|
310
|
+
readonly h3: {
|
|
311
|
+
readonly overflowWrap: "break-word";
|
|
312
|
+
readonly boxSizing: "border-box";
|
|
313
|
+
readonly margin: 0;
|
|
314
|
+
readonly minWidth: 0;
|
|
315
|
+
};
|
|
316
|
+
readonly h4: {
|
|
317
|
+
readonly overflowWrap: "break-word";
|
|
318
|
+
readonly boxSizing: "border-box";
|
|
319
|
+
readonly margin: 0;
|
|
320
|
+
readonly minWidth: 0;
|
|
321
|
+
};
|
|
322
|
+
readonly h5: {
|
|
323
|
+
readonly overflowWrap: "break-word";
|
|
324
|
+
readonly boxSizing: "border-box";
|
|
325
|
+
readonly margin: 0;
|
|
326
|
+
readonly minWidth: 0;
|
|
327
|
+
};
|
|
328
|
+
readonly h6: {
|
|
329
|
+
readonly overflowWrap: "break-word";
|
|
330
|
+
readonly boxSizing: "border-box";
|
|
331
|
+
readonly margin: 0;
|
|
332
|
+
readonly minWidth: 0;
|
|
333
|
+
};
|
|
334
|
+
readonly img: {
|
|
335
|
+
readonly display: "block";
|
|
336
|
+
readonly maxWidth: "100%";
|
|
337
|
+
readonly boxSizing: "border-box";
|
|
338
|
+
readonly margin: 0;
|
|
339
|
+
readonly minWidth: 0;
|
|
340
|
+
};
|
|
341
|
+
readonly picture: {
|
|
342
|
+
readonly display: "block";
|
|
343
|
+
readonly maxWidth: "100%";
|
|
344
|
+
readonly boxSizing: "border-box";
|
|
345
|
+
readonly margin: 0;
|
|
346
|
+
readonly minWidth: 0;
|
|
347
|
+
};
|
|
348
|
+
readonly video: {
|
|
349
|
+
readonly display: "block";
|
|
350
|
+
readonly maxWidth: "100%";
|
|
351
|
+
readonly boxSizing: "border-box";
|
|
352
|
+
readonly margin: 0;
|
|
353
|
+
readonly minWidth: 0;
|
|
354
|
+
};
|
|
355
|
+
readonly canvas: {
|
|
356
|
+
readonly display: "block";
|
|
357
|
+
readonly maxWidth: "100%";
|
|
358
|
+
readonly boxSizing: "border-box";
|
|
359
|
+
readonly margin: 0;
|
|
360
|
+
readonly minWidth: 0;
|
|
361
|
+
};
|
|
362
|
+
readonly svg: {
|
|
363
|
+
readonly display: "block";
|
|
364
|
+
readonly maxWidth: "100%";
|
|
365
|
+
readonly boxSizing: "border-box";
|
|
366
|
+
readonly margin: 0;
|
|
367
|
+
readonly minWidth: 0;
|
|
368
|
+
};
|
|
369
|
+
readonly select: {
|
|
370
|
+
readonly display: "block";
|
|
371
|
+
readonly appearance: "none";
|
|
372
|
+
readonly font: "inherit";
|
|
373
|
+
readonly '&::-ms-expand': {
|
|
374
|
+
readonly display: "none";
|
|
375
|
+
};
|
|
376
|
+
readonly boxSizing: "border-box";
|
|
377
|
+
readonly margin: 0;
|
|
378
|
+
readonly minWidth: 0;
|
|
379
|
+
};
|
|
380
|
+
readonly button: {
|
|
381
|
+
readonly display: "block";
|
|
382
|
+
readonly appearance: "none";
|
|
383
|
+
readonly font: "inherit";
|
|
384
|
+
readonly background: "transparent";
|
|
385
|
+
readonly textAlign: "center";
|
|
386
|
+
readonly boxSizing: "border-box";
|
|
387
|
+
readonly margin: 0;
|
|
388
|
+
readonly minWidth: 0;
|
|
389
|
+
};
|
|
390
|
+
readonly textarea: {
|
|
391
|
+
readonly display: "block";
|
|
392
|
+
readonly appearance: "none";
|
|
393
|
+
readonly font: "inherit";
|
|
394
|
+
readonly boxSizing: "border-box";
|
|
395
|
+
readonly margin: 0;
|
|
396
|
+
readonly minWidth: 0;
|
|
397
|
+
};
|
|
398
|
+
readonly input: {
|
|
399
|
+
readonly display: "block";
|
|
400
|
+
readonly appearance: "none";
|
|
401
|
+
readonly font: "inherit";
|
|
402
|
+
readonly '&::-ms-clear': {
|
|
403
|
+
readonly display: "none";
|
|
404
|
+
};
|
|
405
|
+
readonly '&::-webkit-search-cancel-button': {
|
|
406
|
+
readonly WebkitAppearance: "none";
|
|
407
|
+
};
|
|
408
|
+
readonly boxSizing: "border-box";
|
|
409
|
+
readonly margin: 0;
|
|
410
|
+
readonly minWidth: 0;
|
|
411
|
+
};
|
|
412
|
+
};
|
|
413
|
+
declare type NormalizedElement = keyof typeof normalize;
|
|
414
|
+
/**
|
|
415
|
+
* Type-safe helper to get normalization. If no normalization is found,
|
|
416
|
+
* returns the *base* normalization.
|
|
417
|
+
*/
|
|
418
|
+
declare const getNormalizedStyles: (val?: ElementType<any> | undefined) => {
|
|
419
|
+
readonly boxSizing: "border-box";
|
|
420
|
+
readonly margin: 0;
|
|
421
|
+
readonly minWidth: 0;
|
|
422
|
+
};
|
|
423
|
+
|
|
354
424
|
/**
|
|
355
425
|
* Ensures that the `val` is an array. Will return an empty array if `val` is falsy.
|
|
356
426
|
*/
|
|
@@ -381,4 +451,4 @@ declare const appendVariantState: (variant: string, state: keyof State) => strin
|
|
|
381
451
|
*/
|
|
382
452
|
declare const conditional: (variant: string, { disabled, ...states }: State) => string[];
|
|
383
453
|
|
|
384
|
-
export { Box, BoxOwnProps, BoxProps, CSSObject, CSSProperties, Global, NormalizedElement, ResponsiveStyleValue, SVG, SVGProps, Scale, ScaleValue, SizeScale, State, StyleObject, StyleProps, Theme, ThemeProvider, ThemeProviderProps, ZeroScale, ZeroSizeScale, __defaultTheme, appendVariantState, conditional, ensureArray, ensureArrayVariant, ensureVariantDefault, getNormalizedStyles, normalize, useResponsiveValue, useTheme };
|
|
454
|
+
export { Box, BoxOwnProps, BoxProps, CSSObject, CSSProperties, ComponentState, ComponentStyleParts, ComponentStylesProps, Global, NormalizedElement, ResponsiveStyleValue, SVG, SVGProps, Scale, ScaleValue, SizeScale, State, StateAttrKeyProps, StateAttrProps, StyleObject, StyleProps, Theme, ThemeComponentProps, ThemeExtension, ThemeExtensionsWithParts, ThemeProvider, ThemeProviderProps, UseStateProps, ZeroScale, ZeroSizeScale, __defaultTheme, appendVariantState, conditional, ensureArray, ensureArrayVariant, ensureVariantDefault, getNormalizedStyles, normalize, useComponentStyles, useResponsiveValue, useStateProps, useTheme };
|
package/dist/index.js
CHANGED
|
@@ -21,7 +21,6 @@ var __spreadValues = (a2, b) => {
|
|
|
21
21
|
return a2;
|
|
22
22
|
};
|
|
23
23
|
var __spreadProps = (a2, b) => __defProps(a2, __getOwnPropDescs(b));
|
|
24
|
-
var __markAsModule = (target) => __defProp(target, "__esModule", { value: true });
|
|
25
24
|
var __objRest = (source, exclude) => {
|
|
26
25
|
var target = {};
|
|
27
26
|
for (var prop in source)
|
|
@@ -38,22 +37,16 @@ var __export = (target, all) => {
|
|
|
38
37
|
for (var name in all)
|
|
39
38
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
40
39
|
};
|
|
41
|
-
var
|
|
42
|
-
if (
|
|
43
|
-
for (let key of __getOwnPropNames(
|
|
44
|
-
if (!__hasOwnProp.call(
|
|
45
|
-
__defProp(
|
|
40
|
+
var __copyProps = (to, from, except, desc) => {
|
|
41
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
42
|
+
for (let key of __getOwnPropNames(from))
|
|
43
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
44
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
46
45
|
}
|
|
47
|
-
return
|
|
48
|
-
};
|
|
49
|
-
var __toESM = (module2, isNodeMode) => {
|
|
50
|
-
return __reExport(__markAsModule(__defProp(module2 != null ? __create(__getProtoOf(module2)) : {}, "default", !isNodeMode && module2 && module2.__esModule ? { get: () => module2.default, enumerable: true } : { value: module2, enumerable: true })), module2);
|
|
46
|
+
return to;
|
|
51
47
|
};
|
|
52
|
-
var
|
|
53
|
-
|
|
54
|
-
return cache && cache.get(module2) || (temp = __reExport(__markAsModule({}), module2, 1), cache && cache.set(module2, temp), temp);
|
|
55
|
-
};
|
|
56
|
-
})(typeof WeakMap !== "undefined" ? /* @__PURE__ */ new WeakMap() : 0);
|
|
48
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod));
|
|
49
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
57
50
|
|
|
58
51
|
// src/index.ts
|
|
59
52
|
var src_exports = {};
|
|
@@ -70,14 +63,18 @@ __export(src_exports, {
|
|
|
70
63
|
ensureVariantDefault: () => ensureVariantDefault,
|
|
71
64
|
getNormalizedStyles: () => getNormalizedStyles,
|
|
72
65
|
normalize: () => normalize,
|
|
66
|
+
useComponentStyles: () => useComponentStyles,
|
|
73
67
|
useResponsiveValue: () => useResponsiveValue,
|
|
68
|
+
useStateProps: () => useStateProps,
|
|
74
69
|
useTheme: () => useTheme
|
|
75
70
|
});
|
|
71
|
+
module.exports = __toCommonJS(src_exports);
|
|
76
72
|
|
|
77
|
-
// src/Box.tsx
|
|
78
|
-
var import_react = require("
|
|
73
|
+
// src/components/Box/Box.tsx
|
|
74
|
+
var import_react = require("react");
|
|
75
|
+
var import_react2 = require("@emotion/react");
|
|
79
76
|
var import_css = require("@theme-ui/css");
|
|
80
|
-
var
|
|
77
|
+
var import_deepmerge = __toESM(require("deepmerge"));
|
|
81
78
|
|
|
82
79
|
// src/normalize.ts
|
|
83
80
|
var base = {
|
|
@@ -153,8 +150,8 @@ var isNil = (value) => value === null || value === void 0;
|
|
|
153
150
|
var ensureArray = (val) => isNil(val) ? [] : Array.isArray(val) ? val : [val];
|
|
154
151
|
var ensureVariantDefault = (val) => val.replace(/\.$/, "");
|
|
155
152
|
var ensureArrayVariant = (variant) => ensureArray(variant).map(ensureVariantDefault);
|
|
156
|
-
var appendVariantState = (variant,
|
|
157
|
-
return `${ensureVariantDefault(variant)}.:${
|
|
153
|
+
var appendVariantState = (variant, state2) => {
|
|
154
|
+
return `${ensureVariantDefault(variant)}.:${state2}`;
|
|
158
155
|
};
|
|
159
156
|
var conditional = (variant, _a) => {
|
|
160
157
|
var _b = _a, { disabled = false } = _b, states = __objRest(_b, ["disabled"]);
|
|
@@ -163,18 +160,74 @@ var conditional = (variant, _a) => {
|
|
|
163
160
|
return [variant, ...stateVariants];
|
|
164
161
|
};
|
|
165
162
|
|
|
166
|
-
// src/Box.
|
|
167
|
-
var
|
|
163
|
+
// src/components/Box/utils.ts
|
|
164
|
+
var createteSelector = (selectors, states, suffix = "") => {
|
|
165
|
+
return selectors.map((selector2) => states.map((state2) => `${selector2}${state2}${suffix ? ` ${suffix}` : ""}`)).flat().join(", ");
|
|
166
|
+
};
|
|
167
|
+
var selector = {
|
|
168
|
+
self: "&",
|
|
169
|
+
grouped: ["[role=group]", "[data-group]"]
|
|
170
|
+
};
|
|
171
|
+
var state = {
|
|
172
|
+
none: [""],
|
|
173
|
+
hover: [":hover", "[data-hover]"],
|
|
174
|
+
focus: [":focus", "[data-focus]"],
|
|
175
|
+
focusVisible: [":focus-visible", "[data-focus-visible]"],
|
|
176
|
+
active: [":active", "[data-active]"],
|
|
177
|
+
disabled: ["[disabled]", "[aria-disabled=true]", "[data-disabled]"],
|
|
178
|
+
readOnly: ["[readonly]", "[aria-readonly=true]", "[data-read-only]"],
|
|
179
|
+
checked: ["[aria-checked=true]", "[data-checked]"],
|
|
180
|
+
indeterminate: ["[aria-checked=mixed]", "[data-indeterminate]"],
|
|
181
|
+
selected: ["[aria-selected=true]", "[data-selected]"],
|
|
182
|
+
error: [":invalid", "[aria-invalid=true]", "[data-error]"],
|
|
183
|
+
expanded: ["[aria-expanded=true]", "[data-expanded]"]
|
|
184
|
+
};
|
|
185
|
+
var pseudos = {
|
|
186
|
+
"&:hover": createteSelector([selector.self], state.hover),
|
|
187
|
+
"&:focus": createteSelector([selector.self], state.focus),
|
|
188
|
+
"&:focus-visible": createteSelector([selector.self], state.focusVisible),
|
|
189
|
+
"&:active": createteSelector([selector.self], state.active),
|
|
190
|
+
"&:disabled": createteSelector([selector.self], state.disabled),
|
|
191
|
+
"&:read-only": createteSelector([selector.self], state.readOnly),
|
|
192
|
+
"&:checked": createteSelector([selector.self], state.checked),
|
|
193
|
+
"&:selected": createteSelector([selector.self], state.selected),
|
|
194
|
+
"&:indeterminate": createteSelector([selector.self], state.indeterminate),
|
|
195
|
+
"&:error": createteSelector([selector.self], state.error),
|
|
196
|
+
"&:expanded": createteSelector([selector.self], state.expanded),
|
|
197
|
+
"&:in-group": createteSelector(selector.grouped, state.none, selector.self),
|
|
198
|
+
"&:hover-group": createteSelector(selector.grouped, state.hover, selector.self),
|
|
199
|
+
"&:focus-group": createteSelector(selector.grouped, state.focus, selector.self),
|
|
200
|
+
"&:active-group": createteSelector(selector.grouped, state.active, selector.self),
|
|
201
|
+
"&:error-group": createteSelector(selector.grouped, state.error, selector.self)
|
|
202
|
+
};
|
|
203
|
+
var transformPseudos = (styles) => {
|
|
204
|
+
let result = {};
|
|
205
|
+
for (let key in styles) {
|
|
206
|
+
const value = styles[key];
|
|
207
|
+
if (key in pseudos) {
|
|
208
|
+
key = pseudos[key];
|
|
209
|
+
}
|
|
210
|
+
if (typeof value === "object") {
|
|
211
|
+
result[key] = transformPseudos(value);
|
|
212
|
+
continue;
|
|
213
|
+
}
|
|
214
|
+
result[key] = value;
|
|
215
|
+
}
|
|
216
|
+
return result;
|
|
217
|
+
};
|
|
218
|
+
|
|
219
|
+
// src/components/Box/Box.tsx
|
|
168
220
|
var createThemedStyle = ({ as, __baseCSS, variant, styles, css }) => (theme) => {
|
|
169
|
-
|
|
221
|
+
const themedStyles = import_deepmerge.default.all([
|
|
170
222
|
getNormalizedStyles(as),
|
|
171
223
|
(0, import_css.css)(__baseCSS)(theme),
|
|
172
224
|
...ensureArrayVariant(variant).map((v) => (0, import_css.css)({ variant: v })(theme)),
|
|
173
225
|
(0, import_css.css)(styles)(theme),
|
|
174
226
|
(0, import_css.css)(css)(theme)
|
|
175
|
-
]
|
|
227
|
+
]);
|
|
228
|
+
return transformPseudos(themedStyles);
|
|
176
229
|
};
|
|
177
|
-
var Box = (0,
|
|
230
|
+
var Box = (0, import_react.forwardRef)((_a, ref) => {
|
|
178
231
|
var _b = _a, {
|
|
179
232
|
as = "div",
|
|
180
233
|
children,
|
|
@@ -264,7 +317,7 @@ var Box = (0, import_react2.forwardRef)((_a, ref) => {
|
|
|
264
317
|
"overflow",
|
|
265
318
|
"transition"
|
|
266
319
|
]);
|
|
267
|
-
return (0,
|
|
320
|
+
return (0, import_react2.jsx)(as, __spreadProps(__spreadValues({}, props), {
|
|
268
321
|
css: createThemedStyle({
|
|
269
322
|
as,
|
|
270
323
|
__baseCSS,
|
|
@@ -315,11 +368,16 @@ var Box = (0, import_react2.forwardRef)((_a, ref) => {
|
|
|
315
368
|
}), children);
|
|
316
369
|
});
|
|
317
370
|
|
|
318
|
-
// src/Global.tsx
|
|
319
|
-
var
|
|
320
|
-
var
|
|
371
|
+
// src/components/Global/Global.tsx
|
|
372
|
+
var import_react8 = __toESM(require("react"));
|
|
373
|
+
var import_react9 = require("@emotion/react");
|
|
374
|
+
|
|
375
|
+
// src/hooks/useComponentStyles.ts
|
|
376
|
+
var import_deepmerge2 = __toESM(require("deepmerge"));
|
|
377
|
+
var import_react5 = require("react");
|
|
378
|
+
var import_react_fast_compare = __toESM(require("react-fast-compare"));
|
|
321
379
|
|
|
322
|
-
// src/useTheme.tsx
|
|
380
|
+
// src/hooks/useTheme.tsx
|
|
323
381
|
var import_react3 = __toESM(require("react"));
|
|
324
382
|
var import_css2 = require("@theme-ui/css");
|
|
325
383
|
var import_react4 = require("@emotion/react");
|
|
@@ -328,7 +386,8 @@ var InternalContext = (0, import_react3.createContext)(__defaultTheme);
|
|
|
328
386
|
var useTheme = () => {
|
|
329
387
|
const theme = (0, import_react3.useContext)(InternalContext);
|
|
330
388
|
const css = (0, import_react3.useCallback)((style) => (0, import_css2.css)(style)(theme), [theme]);
|
|
331
|
-
|
|
389
|
+
const get2 = (0, import_react3.useCallback)((path) => (0, import_css2.get)(theme, path), [theme]);
|
|
390
|
+
return { theme, css, get: get2 };
|
|
332
391
|
};
|
|
333
392
|
function ThemeProvider({
|
|
334
393
|
theme,
|
|
@@ -341,7 +400,86 @@ function ThemeProvider({
|
|
|
341
400
|
}, children));
|
|
342
401
|
}
|
|
343
402
|
|
|
344
|
-
// src/
|
|
403
|
+
// src/hooks/useComponentStyles.ts
|
|
404
|
+
var get = (obj, path, fallback) => {
|
|
405
|
+
const key = path.split(".");
|
|
406
|
+
let result = obj;
|
|
407
|
+
for (let i = 0, length = key.length; i < length; i++) {
|
|
408
|
+
if (!result)
|
|
409
|
+
break;
|
|
410
|
+
result = result[key[i]];
|
|
411
|
+
}
|
|
412
|
+
return result === void 0 ? fallback : result;
|
|
413
|
+
};
|
|
414
|
+
function useComponentStyles(componentName, props = {}, options = {}) {
|
|
415
|
+
var _a, _b;
|
|
416
|
+
const { theme } = useTheme();
|
|
417
|
+
const componentStyles = get(theme, `components.${componentName}`);
|
|
418
|
+
const stylesRef = (0, import_react5.useRef)({});
|
|
419
|
+
if (componentStyles) {
|
|
420
|
+
const base2 = componentStyles.base || {};
|
|
421
|
+
const size = ((_a = componentStyles.size) == null ? void 0 : _a[props.size]) || {};
|
|
422
|
+
const variant = ((_b = componentStyles.variant) == null ? void 0 : _b[props.variant]) || {};
|
|
423
|
+
let styles = import_deepmerge2.default.all([base2, size, variant]);
|
|
424
|
+
if (options.parts) {
|
|
425
|
+
styles = options.parts.reduce((result, part) => {
|
|
426
|
+
result[part] = styles[part] || {};
|
|
427
|
+
return result;
|
|
428
|
+
}, {});
|
|
429
|
+
}
|
|
430
|
+
if (!(0, import_react_fast_compare.default)(stylesRef.current, styles)) {
|
|
431
|
+
stylesRef.current = styles;
|
|
432
|
+
}
|
|
433
|
+
}
|
|
434
|
+
return stylesRef.current;
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
// src/hooks/useResponsiveValue.ts
|
|
438
|
+
var import_react6 = require("react");
|
|
439
|
+
var emptyBreakpoints = ["40em", "52em", "64em"];
|
|
440
|
+
var useResponsiveValue = (values, defaultIndex = 0) => {
|
|
441
|
+
const { theme } = useTheme();
|
|
442
|
+
const breakpoints = theme.breakpoints || emptyBreakpoints;
|
|
443
|
+
if (defaultIndex < 0 || defaultIndex >= breakpoints.length) {
|
|
444
|
+
throw new RangeError(`Default breakpoint index is out of bounds. Theme has ${breakpoints.length} breakpoints, default is ${defaultIndex}.`);
|
|
445
|
+
}
|
|
446
|
+
const [index, setIndex] = (0, import_react6.useState)(defaultIndex);
|
|
447
|
+
(0, import_react6.useEffect)(() => {
|
|
448
|
+
const getIndex = () => breakpoints.filter((breakpoint) => window.matchMedia(`screen and (min-width: ${breakpoint})`).matches).length;
|
|
449
|
+
const handleResize = () => {
|
|
450
|
+
const newIndex = getIndex();
|
|
451
|
+
if (index !== newIndex) {
|
|
452
|
+
setIndex(newIndex);
|
|
453
|
+
}
|
|
454
|
+
};
|
|
455
|
+
handleResize();
|
|
456
|
+
window.addEventListener("resize", handleResize);
|
|
457
|
+
return () => window.removeEventListener("resize", handleResize);
|
|
458
|
+
}, [breakpoints, index]);
|
|
459
|
+
return values[index >= values.length ? values.length - 1 : index];
|
|
460
|
+
};
|
|
461
|
+
|
|
462
|
+
// src/hooks/useStateProps.ts
|
|
463
|
+
var import_react7 = require("react");
|
|
464
|
+
var import_react_fast_compare2 = __toESM(require("react-fast-compare"));
|
|
465
|
+
var KEBAB_REGEX = /[A-Z\u00C0-\u00D6\u00D8-\u00DE]/g;
|
|
466
|
+
var toKebap = (val) => val.replace(KEBAB_REGEX, (match) => `-${match.toLocaleLowerCase()}`);
|
|
467
|
+
var useStateProps = (states) => {
|
|
468
|
+
const statePropsRef = (0, import_react7.useRef)({});
|
|
469
|
+
let stateProps = {};
|
|
470
|
+
for (let state2 in states) {
|
|
471
|
+
if (states[state2]) {
|
|
472
|
+
const key = `data-${toKebap(state2)}`;
|
|
473
|
+
stateProps[key] = "";
|
|
474
|
+
}
|
|
475
|
+
}
|
|
476
|
+
if (!(0, import_react_fast_compare2.default)(statePropsRef.current, stateProps)) {
|
|
477
|
+
statePropsRef.current = stateProps;
|
|
478
|
+
}
|
|
479
|
+
return statePropsRef.current;
|
|
480
|
+
};
|
|
481
|
+
|
|
482
|
+
// src/components/Global/Global.tsx
|
|
345
483
|
var reduceMotionStyles = {
|
|
346
484
|
"@media screen and (prefers-reduced-motion: reduce), (update: slow)": {
|
|
347
485
|
"*": {
|
|
@@ -366,14 +504,16 @@ var Global = () => {
|
|
|
366
504
|
variant: "root.body"
|
|
367
505
|
}
|
|
368
506
|
});
|
|
369
|
-
return /* @__PURE__ */
|
|
507
|
+
return /* @__PURE__ */ import_react8.default.createElement(import_react9.Global, {
|
|
370
508
|
styles: __spreadValues({ reduceMotionStyles }, styles)
|
|
371
509
|
});
|
|
372
510
|
};
|
|
373
511
|
|
|
374
|
-
// src/SVG.tsx
|
|
375
|
-
var
|
|
512
|
+
// src/components/SVG/SVG.tsx
|
|
513
|
+
var import_react10 = require("@emotion/react");
|
|
376
514
|
var normalizedStyles = getNormalizedStyles("svg");
|
|
515
|
+
var toDimension = (value) => Array.isArray(value) ? value.map(ensureNumberOrToken) : ensureNumberOrToken(value);
|
|
516
|
+
var ensureNumberOrToken = (value) => typeof value === "string" && /[0-9]+/.test(value) ? Number(value) : value;
|
|
377
517
|
var SVG = (_a) => {
|
|
378
518
|
var _b = _a, {
|
|
379
519
|
size = 24,
|
|
@@ -385,39 +525,15 @@ var SVG = (_a) => {
|
|
|
385
525
|
"children"
|
|
386
526
|
]);
|
|
387
527
|
const { css } = useTheme();
|
|
388
|
-
return (0,
|
|
389
|
-
width: size,
|
|
390
|
-
height: size,
|
|
528
|
+
return (0, import_react10.jsx)("svg", __spreadValues({
|
|
391
529
|
viewBox: "0 0 24 24",
|
|
392
|
-
css: css(__spreadValues({
|
|
530
|
+
css: css(__spreadProps(__spreadValues({}, normalizedStyles), {
|
|
531
|
+
fill,
|
|
532
|
+
width: toDimension(props.width || size),
|
|
533
|
+
height: toDimension(props.height || size)
|
|
534
|
+
}))
|
|
393
535
|
}, props), children);
|
|
394
536
|
};
|
|
395
|
-
|
|
396
|
-
// src/useResponsiveValue.ts
|
|
397
|
-
var import_react8 = require("react");
|
|
398
|
-
var emptyBreakpoints = ["40em", "52em", "64em"];
|
|
399
|
-
var useResponsiveValue = (values, defaultIndex = 0) => {
|
|
400
|
-
const { theme } = useTheme();
|
|
401
|
-
const breakpoints = theme.breakpoints || emptyBreakpoints;
|
|
402
|
-
if (defaultIndex < 0 || defaultIndex >= breakpoints.length) {
|
|
403
|
-
throw new RangeError(`Default breakpoint index is out of bounds. Theme has ${breakpoints.length} breakpoints, default is ${defaultIndex}.`);
|
|
404
|
-
}
|
|
405
|
-
const [index, setIndex] = (0, import_react8.useState)(defaultIndex);
|
|
406
|
-
(0, import_react8.useEffect)(() => {
|
|
407
|
-
const getIndex = () => breakpoints.filter((breakpoint) => window.matchMedia(`screen and (min-width: ${breakpoint})`).matches).length;
|
|
408
|
-
const handleResize = () => {
|
|
409
|
-
const newIndex = getIndex();
|
|
410
|
-
if (index !== newIndex) {
|
|
411
|
-
setIndex(newIndex);
|
|
412
|
-
}
|
|
413
|
-
};
|
|
414
|
-
handleResize();
|
|
415
|
-
window.addEventListener("resize", handleResize);
|
|
416
|
-
return () => window.removeEventListener("resize", handleResize);
|
|
417
|
-
}, [breakpoints, index]);
|
|
418
|
-
return values[index >= values.length ? values.length - 1 : index];
|
|
419
|
-
};
|
|
420
|
-
module.exports = __toCommonJS(src_exports);
|
|
421
537
|
// Annotate the CommonJS export names for ESM import in node:
|
|
422
538
|
0 && (module.exports = {
|
|
423
539
|
Box,
|
|
@@ -432,6 +548,8 @@ module.exports = __toCommonJS(src_exports);
|
|
|
432
548
|
ensureVariantDefault,
|
|
433
549
|
getNormalizedStyles,
|
|
434
550
|
normalize,
|
|
551
|
+
useComponentStyles,
|
|
435
552
|
useResponsiveValue,
|
|
553
|
+
useStateProps,
|
|
436
554
|
useTheme
|
|
437
555
|
});
|
package/dist/index.mjs
CHANGED
|
@@ -30,10 +30,11 @@ var __objRest = (source, exclude) => {
|
|
|
30
30
|
return target;
|
|
31
31
|
};
|
|
32
32
|
|
|
33
|
-
// src/Box.tsx
|
|
33
|
+
// src/components/Box/Box.tsx
|
|
34
|
+
import { forwardRef } from "react";
|
|
34
35
|
import { jsx } from "@emotion/react";
|
|
35
36
|
import { css as transformStyleObject } from "@theme-ui/css";
|
|
36
|
-
import
|
|
37
|
+
import merge from "deepmerge";
|
|
37
38
|
|
|
38
39
|
// src/normalize.ts
|
|
39
40
|
var base = {
|
|
@@ -109,8 +110,8 @@ var isNil = (value) => value === null || value === void 0;
|
|
|
109
110
|
var ensureArray = (val) => isNil(val) ? [] : Array.isArray(val) ? val : [val];
|
|
110
111
|
var ensureVariantDefault = (val) => val.replace(/\.$/, "");
|
|
111
112
|
var ensureArrayVariant = (variant) => ensureArray(variant).map(ensureVariantDefault);
|
|
112
|
-
var appendVariantState = (variant,
|
|
113
|
-
return `${ensureVariantDefault(variant)}.:${
|
|
113
|
+
var appendVariantState = (variant, state2) => {
|
|
114
|
+
return `${ensureVariantDefault(variant)}.:${state2}`;
|
|
114
115
|
};
|
|
115
116
|
var conditional = (variant, _a) => {
|
|
116
117
|
var _b = _a, { disabled = false } = _b, states = __objRest(_b, ["disabled"]);
|
|
@@ -119,16 +120,72 @@ var conditional = (variant, _a) => {
|
|
|
119
120
|
return [variant, ...stateVariants];
|
|
120
121
|
};
|
|
121
122
|
|
|
122
|
-
// src/Box.
|
|
123
|
-
var
|
|
123
|
+
// src/components/Box/utils.ts
|
|
124
|
+
var createteSelector = (selectors, states, suffix = "") => {
|
|
125
|
+
return selectors.map((selector2) => states.map((state2) => `${selector2}${state2}${suffix ? ` ${suffix}` : ""}`)).flat().join(", ");
|
|
126
|
+
};
|
|
127
|
+
var selector = {
|
|
128
|
+
self: "&",
|
|
129
|
+
grouped: ["[role=group]", "[data-group]"]
|
|
130
|
+
};
|
|
131
|
+
var state = {
|
|
132
|
+
none: [""],
|
|
133
|
+
hover: [":hover", "[data-hover]"],
|
|
134
|
+
focus: [":focus", "[data-focus]"],
|
|
135
|
+
focusVisible: [":focus-visible", "[data-focus-visible]"],
|
|
136
|
+
active: [":active", "[data-active]"],
|
|
137
|
+
disabled: ["[disabled]", "[aria-disabled=true]", "[data-disabled]"],
|
|
138
|
+
readOnly: ["[readonly]", "[aria-readonly=true]", "[data-read-only]"],
|
|
139
|
+
checked: ["[aria-checked=true]", "[data-checked]"],
|
|
140
|
+
indeterminate: ["[aria-checked=mixed]", "[data-indeterminate]"],
|
|
141
|
+
selected: ["[aria-selected=true]", "[data-selected]"],
|
|
142
|
+
error: [":invalid", "[aria-invalid=true]", "[data-error]"],
|
|
143
|
+
expanded: ["[aria-expanded=true]", "[data-expanded]"]
|
|
144
|
+
};
|
|
145
|
+
var pseudos = {
|
|
146
|
+
"&:hover": createteSelector([selector.self], state.hover),
|
|
147
|
+
"&:focus": createteSelector([selector.self], state.focus),
|
|
148
|
+
"&:focus-visible": createteSelector([selector.self], state.focusVisible),
|
|
149
|
+
"&:active": createteSelector([selector.self], state.active),
|
|
150
|
+
"&:disabled": createteSelector([selector.self], state.disabled),
|
|
151
|
+
"&:read-only": createteSelector([selector.self], state.readOnly),
|
|
152
|
+
"&:checked": createteSelector([selector.self], state.checked),
|
|
153
|
+
"&:selected": createteSelector([selector.self], state.selected),
|
|
154
|
+
"&:indeterminate": createteSelector([selector.self], state.indeterminate),
|
|
155
|
+
"&:error": createteSelector([selector.self], state.error),
|
|
156
|
+
"&:expanded": createteSelector([selector.self], state.expanded),
|
|
157
|
+
"&:in-group": createteSelector(selector.grouped, state.none, selector.self),
|
|
158
|
+
"&:hover-group": createteSelector(selector.grouped, state.hover, selector.self),
|
|
159
|
+
"&:focus-group": createteSelector(selector.grouped, state.focus, selector.self),
|
|
160
|
+
"&:active-group": createteSelector(selector.grouped, state.active, selector.self),
|
|
161
|
+
"&:error-group": createteSelector(selector.grouped, state.error, selector.self)
|
|
162
|
+
};
|
|
163
|
+
var transformPseudos = (styles) => {
|
|
164
|
+
let result = {};
|
|
165
|
+
for (let key in styles) {
|
|
166
|
+
const value = styles[key];
|
|
167
|
+
if (key in pseudos) {
|
|
168
|
+
key = pseudos[key];
|
|
169
|
+
}
|
|
170
|
+
if (typeof value === "object") {
|
|
171
|
+
result[key] = transformPseudos(value);
|
|
172
|
+
continue;
|
|
173
|
+
}
|
|
174
|
+
result[key] = value;
|
|
175
|
+
}
|
|
176
|
+
return result;
|
|
177
|
+
};
|
|
178
|
+
|
|
179
|
+
// src/components/Box/Box.tsx
|
|
124
180
|
var createThemedStyle = ({ as, __baseCSS, variant, styles, css }) => (theme) => {
|
|
125
|
-
|
|
181
|
+
const themedStyles = merge.all([
|
|
126
182
|
getNormalizedStyles(as),
|
|
127
183
|
transformStyleObject(__baseCSS)(theme),
|
|
128
184
|
...ensureArrayVariant(variant).map((v) => transformStyleObject({ variant: v })(theme)),
|
|
129
185
|
transformStyleObject(styles)(theme),
|
|
130
186
|
transformStyleObject(css)(theme)
|
|
131
|
-
]
|
|
187
|
+
]);
|
|
188
|
+
return transformPseudos(themedStyles);
|
|
132
189
|
};
|
|
133
190
|
var Box = forwardRef((_a, ref) => {
|
|
134
191
|
var _b = _a, {
|
|
@@ -271,24 +328,33 @@ var Box = forwardRef((_a, ref) => {
|
|
|
271
328
|
}), children);
|
|
272
329
|
});
|
|
273
330
|
|
|
274
|
-
// src/Global.tsx
|
|
331
|
+
// src/components/Global/Global.tsx
|
|
275
332
|
import React2 from "react";
|
|
276
333
|
import { Global as EmotionGlobal } from "@emotion/react";
|
|
277
334
|
|
|
278
|
-
// src/
|
|
335
|
+
// src/hooks/useComponentStyles.ts
|
|
336
|
+
import merge2 from "deepmerge";
|
|
337
|
+
import { useRef } from "react";
|
|
338
|
+
import isEqual from "react-fast-compare";
|
|
339
|
+
|
|
340
|
+
// src/hooks/useTheme.tsx
|
|
279
341
|
import React, {
|
|
280
342
|
createContext,
|
|
281
343
|
useCallback,
|
|
282
344
|
useContext
|
|
283
345
|
} from "react";
|
|
284
|
-
import {
|
|
346
|
+
import {
|
|
347
|
+
css as transformStyleObject2,
|
|
348
|
+
get as getfromTheme
|
|
349
|
+
} from "@theme-ui/css";
|
|
285
350
|
import { ThemeProvider as EmotionProvider } from "@emotion/react";
|
|
286
351
|
var __defaultTheme = {};
|
|
287
352
|
var InternalContext = createContext(__defaultTheme);
|
|
288
353
|
var useTheme = () => {
|
|
289
354
|
const theme = useContext(InternalContext);
|
|
290
355
|
const css = useCallback((style) => transformStyleObject2(style)(theme), [theme]);
|
|
291
|
-
|
|
356
|
+
const get2 = useCallback((path) => getfromTheme(theme, path), [theme]);
|
|
357
|
+
return { theme, css, get: get2 };
|
|
292
358
|
};
|
|
293
359
|
function ThemeProvider({
|
|
294
360
|
theme,
|
|
@@ -301,7 +367,86 @@ function ThemeProvider({
|
|
|
301
367
|
}, children));
|
|
302
368
|
}
|
|
303
369
|
|
|
304
|
-
// src/
|
|
370
|
+
// src/hooks/useComponentStyles.ts
|
|
371
|
+
var get = (obj, path, fallback) => {
|
|
372
|
+
const key = path.split(".");
|
|
373
|
+
let result = obj;
|
|
374
|
+
for (let i = 0, length = key.length; i < length; i++) {
|
|
375
|
+
if (!result)
|
|
376
|
+
break;
|
|
377
|
+
result = result[key[i]];
|
|
378
|
+
}
|
|
379
|
+
return result === void 0 ? fallback : result;
|
|
380
|
+
};
|
|
381
|
+
function useComponentStyles(componentName, props = {}, options = {}) {
|
|
382
|
+
var _a, _b;
|
|
383
|
+
const { theme } = useTheme();
|
|
384
|
+
const componentStyles = get(theme, `components.${componentName}`);
|
|
385
|
+
const stylesRef = useRef({});
|
|
386
|
+
if (componentStyles) {
|
|
387
|
+
const base2 = componentStyles.base || {};
|
|
388
|
+
const size = ((_a = componentStyles.size) == null ? void 0 : _a[props.size]) || {};
|
|
389
|
+
const variant = ((_b = componentStyles.variant) == null ? void 0 : _b[props.variant]) || {};
|
|
390
|
+
let styles = merge2.all([base2, size, variant]);
|
|
391
|
+
if (options.parts) {
|
|
392
|
+
styles = options.parts.reduce((result, part) => {
|
|
393
|
+
result[part] = styles[part] || {};
|
|
394
|
+
return result;
|
|
395
|
+
}, {});
|
|
396
|
+
}
|
|
397
|
+
if (!isEqual(stylesRef.current, styles)) {
|
|
398
|
+
stylesRef.current = styles;
|
|
399
|
+
}
|
|
400
|
+
}
|
|
401
|
+
return stylesRef.current;
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
// src/hooks/useResponsiveValue.ts
|
|
405
|
+
import { useEffect, useState } from "react";
|
|
406
|
+
var emptyBreakpoints = ["40em", "52em", "64em"];
|
|
407
|
+
var useResponsiveValue = (values, defaultIndex = 0) => {
|
|
408
|
+
const { theme } = useTheme();
|
|
409
|
+
const breakpoints = theme.breakpoints || emptyBreakpoints;
|
|
410
|
+
if (defaultIndex < 0 || defaultIndex >= breakpoints.length) {
|
|
411
|
+
throw new RangeError(`Default breakpoint index is out of bounds. Theme has ${breakpoints.length} breakpoints, default is ${defaultIndex}.`);
|
|
412
|
+
}
|
|
413
|
+
const [index, setIndex] = useState(defaultIndex);
|
|
414
|
+
useEffect(() => {
|
|
415
|
+
const getIndex = () => breakpoints.filter((breakpoint) => window.matchMedia(`screen and (min-width: ${breakpoint})`).matches).length;
|
|
416
|
+
const handleResize = () => {
|
|
417
|
+
const newIndex = getIndex();
|
|
418
|
+
if (index !== newIndex) {
|
|
419
|
+
setIndex(newIndex);
|
|
420
|
+
}
|
|
421
|
+
};
|
|
422
|
+
handleResize();
|
|
423
|
+
window.addEventListener("resize", handleResize);
|
|
424
|
+
return () => window.removeEventListener("resize", handleResize);
|
|
425
|
+
}, [breakpoints, index]);
|
|
426
|
+
return values[index >= values.length ? values.length - 1 : index];
|
|
427
|
+
};
|
|
428
|
+
|
|
429
|
+
// src/hooks/useStateProps.ts
|
|
430
|
+
import { useRef as useRef2 } from "react";
|
|
431
|
+
import isEqual2 from "react-fast-compare";
|
|
432
|
+
var KEBAB_REGEX = /[A-Z\u00C0-\u00D6\u00D8-\u00DE]/g;
|
|
433
|
+
var toKebap = (val) => val.replace(KEBAB_REGEX, (match) => `-${match.toLocaleLowerCase()}`);
|
|
434
|
+
var useStateProps = (states) => {
|
|
435
|
+
const statePropsRef = useRef2({});
|
|
436
|
+
let stateProps = {};
|
|
437
|
+
for (let state2 in states) {
|
|
438
|
+
if (states[state2]) {
|
|
439
|
+
const key = `data-${toKebap(state2)}`;
|
|
440
|
+
stateProps[key] = "";
|
|
441
|
+
}
|
|
442
|
+
}
|
|
443
|
+
if (!isEqual2(statePropsRef.current, stateProps)) {
|
|
444
|
+
statePropsRef.current = stateProps;
|
|
445
|
+
}
|
|
446
|
+
return statePropsRef.current;
|
|
447
|
+
};
|
|
448
|
+
|
|
449
|
+
// src/components/Global/Global.tsx
|
|
305
450
|
var reduceMotionStyles = {
|
|
306
451
|
"@media screen and (prefers-reduced-motion: reduce), (update: slow)": {
|
|
307
452
|
"*": {
|
|
@@ -331,9 +476,11 @@ var Global = () => {
|
|
|
331
476
|
});
|
|
332
477
|
};
|
|
333
478
|
|
|
334
|
-
// src/SVG.tsx
|
|
479
|
+
// src/components/SVG/SVG.tsx
|
|
335
480
|
import { jsx as jsx2 } from "@emotion/react";
|
|
336
481
|
var normalizedStyles = getNormalizedStyles("svg");
|
|
482
|
+
var toDimension = (value) => Array.isArray(value) ? value.map(ensureNumberOrToken) : ensureNumberOrToken(value);
|
|
483
|
+
var ensureNumberOrToken = (value) => typeof value === "string" && /[0-9]+/.test(value) ? Number(value) : value;
|
|
337
484
|
var SVG = (_a) => {
|
|
338
485
|
var _b = _a, {
|
|
339
486
|
size = 24,
|
|
@@ -346,37 +493,14 @@ var SVG = (_a) => {
|
|
|
346
493
|
]);
|
|
347
494
|
const { css } = useTheme();
|
|
348
495
|
return jsx2("svg", __spreadValues({
|
|
349
|
-
width: size,
|
|
350
|
-
height: size,
|
|
351
496
|
viewBox: "0 0 24 24",
|
|
352
|
-
css: css(__spreadValues({
|
|
497
|
+
css: css(__spreadProps(__spreadValues({}, normalizedStyles), {
|
|
498
|
+
fill,
|
|
499
|
+
width: toDimension(props.width || size),
|
|
500
|
+
height: toDimension(props.height || size)
|
|
501
|
+
}))
|
|
353
502
|
}, props), children);
|
|
354
503
|
};
|
|
355
|
-
|
|
356
|
-
// src/useResponsiveValue.ts
|
|
357
|
-
import { useEffect, useState } from "react";
|
|
358
|
-
var emptyBreakpoints = ["40em", "52em", "64em"];
|
|
359
|
-
var useResponsiveValue = (values, defaultIndex = 0) => {
|
|
360
|
-
const { theme } = useTheme();
|
|
361
|
-
const breakpoints = theme.breakpoints || emptyBreakpoints;
|
|
362
|
-
if (defaultIndex < 0 || defaultIndex >= breakpoints.length) {
|
|
363
|
-
throw new RangeError(`Default breakpoint index is out of bounds. Theme has ${breakpoints.length} breakpoints, default is ${defaultIndex}.`);
|
|
364
|
-
}
|
|
365
|
-
const [index, setIndex] = useState(defaultIndex);
|
|
366
|
-
useEffect(() => {
|
|
367
|
-
const getIndex = () => breakpoints.filter((breakpoint) => window.matchMedia(`screen and (min-width: ${breakpoint})`).matches).length;
|
|
368
|
-
const handleResize = () => {
|
|
369
|
-
const newIndex = getIndex();
|
|
370
|
-
if (index !== newIndex) {
|
|
371
|
-
setIndex(newIndex);
|
|
372
|
-
}
|
|
373
|
-
};
|
|
374
|
-
handleResize();
|
|
375
|
-
window.addEventListener("resize", handleResize);
|
|
376
|
-
return () => window.removeEventListener("resize", handleResize);
|
|
377
|
-
}, [breakpoints, index]);
|
|
378
|
-
return values[index >= values.length ? values.length - 1 : index];
|
|
379
|
-
};
|
|
380
504
|
export {
|
|
381
505
|
Box,
|
|
382
506
|
Global,
|
|
@@ -390,6 +514,8 @@ export {
|
|
|
390
514
|
ensureVariantDefault,
|
|
391
515
|
getNormalizedStyles,
|
|
392
516
|
normalize,
|
|
517
|
+
useComponentStyles,
|
|
393
518
|
useResponsiveValue,
|
|
519
|
+
useStateProps,
|
|
394
520
|
useTheme
|
|
395
521
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@marigold/system",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "1.0.0-beta.0",
|
|
4
4
|
"description": "Marigold System Library",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"keywords": [
|
|
@@ -26,23 +26,26 @@
|
|
|
26
26
|
"directory": "packages/system"
|
|
27
27
|
},
|
|
28
28
|
"dependencies": {
|
|
29
|
-
"@emotion/react": "11.
|
|
30
|
-
"@marigold/types": "0.
|
|
31
|
-
"@theme-ui/css": "0.
|
|
32
|
-
"csstype": "3.0.11"
|
|
29
|
+
"@emotion/react": "11.9.0",
|
|
30
|
+
"@marigold/types": "0.5.0-beta.0",
|
|
31
|
+
"@theme-ui/css": "0.14.5",
|
|
32
|
+
"csstype": "3.0.11",
|
|
33
|
+
"deepmerge": "^4.2.2",
|
|
34
|
+
"react-fast-compare": "^3.2.0"
|
|
33
35
|
},
|
|
34
36
|
"peerDependencies": {
|
|
35
37
|
"react": "^16.x || ^17.0.0",
|
|
36
38
|
"react-dom": "^16.x || ^17.0.0"
|
|
37
39
|
},
|
|
38
40
|
"devDependencies": {
|
|
41
|
+
"@babel/core": "7.17.10",
|
|
39
42
|
"@marigold/tsconfig": "0.3.0",
|
|
40
|
-
"
|
|
43
|
+
"react": "17.x",
|
|
44
|
+
"tsup": "5.12.7"
|
|
41
45
|
},
|
|
42
46
|
"scripts": {
|
|
43
47
|
"build": "tsup src/index.ts",
|
|
44
48
|
"watch": "tsup src/index.ts --watch",
|
|
45
49
|
"clean": "rm -rf node_modules && rm -rf dist"
|
|
46
|
-
}
|
|
47
|
-
"readme": "# `@marigold/system`\n\n> Marigold system\n"
|
|
50
|
+
}
|
|
48
51
|
}
|