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