@marigold/system 0.4.0 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +24 -0
- package/dist/index.d.ts +42 -22
- package/dist/index.js +50 -15
- package/dist/index.mjs +49 -15
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,29 @@
|
|
|
1
1
|
# @marigold/system
|
|
2
2
|
|
|
3
|
+
## 0.6.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [#1817](https://github.com/marigold-ui/marigold/pull/1817) [`4cc0ad3b`](https://github.com/marigold-ui/marigold/commit/4cc0ad3b85b993e01b4d85b6f30b1a81cdee2351) Thanks [@sebald](https://github.com/sebald)! - feat(system): Add textSizeAdjust to globals
|
|
8
|
+
|
|
9
|
+
* [#1842](https://github.com/marigold-ui/marigold/pull/1842) [`e053b7b9`](https://github.com/marigold-ui/marigold/commit/e053b7b903f02c56cf10e6b9aecbedd29399895d) Thanks [@ti10le](https://github.com/ti10le)! - feat: extend svg fill prop to handle theme color
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- [#1809](https://github.com/marigold-ui/marigold/pull/1809) [`539d4198`](https://github.com/marigold-ui/marigold/commit/539d41987118db125ee37a4a83231335ea15830a) Thanks [@sebald](https://github.com/sebald)! - feat(create-theme): Introduce helper package to create themes with sensible defaults
|
|
14
|
+
|
|
15
|
+
## 0.5.1
|
|
16
|
+
|
|
17
|
+
### Patch Changes
|
|
18
|
+
|
|
19
|
+
- [#1795](https://github.com/marigold-ui/marigold/pull/1795) [`a178eafe`](https://github.com/marigold-ui/marigold/commit/a178eafe8c8380ee23b4587d953ee52b231414ff) Thanks [@ti10le](https://github.com/ti10le)! - refa: use interface instead of type
|
|
20
|
+
|
|
21
|
+
## 0.5.0
|
|
22
|
+
|
|
23
|
+
### Minor Changes
|
|
24
|
+
|
|
25
|
+
- [#1723](https://github.com/marigold-ui/marigold/pull/1723) [`5936de75`](https://github.com/marigold-ui/marigold/commit/5936de75e5a0134584438117c53c5edfe15c6c5d) Thanks [@sebald](https://github.com/sebald)! - feat(system): add hook that allows to use values based on screen size
|
|
26
|
+
|
|
3
27
|
## 0.4.0
|
|
4
28
|
|
|
5
29
|
### Minor Changes
|
package/dist/index.d.ts
CHANGED
|
@@ -13,8 +13,9 @@ declare type StyleObject = ThemeUIStyleObject;
|
|
|
13
13
|
declare type CSSObject = ThemeUICSSObject;
|
|
14
14
|
declare type CSSProperties = ThemeUICSSProperties;
|
|
15
15
|
|
|
16
|
-
|
|
17
|
-
|
|
16
|
+
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
|
+
}
|
|
18
|
+
interface BoxOwnProps extends StyleProps {
|
|
18
19
|
css?: CSSObject;
|
|
19
20
|
variant?: string | string[];
|
|
20
21
|
/**
|
|
@@ -22,8 +23,9 @@ declare type BoxOwnProps = {
|
|
|
22
23
|
* @internal Used to set default styles for Marigold components
|
|
23
24
|
*/
|
|
24
25
|
__baseCSS?: CSSObject;
|
|
25
|
-
}
|
|
26
|
-
|
|
26
|
+
}
|
|
27
|
+
interface BoxProps extends PolymorphicPropsWithRef<BoxOwnProps, 'div'> {
|
|
28
|
+
}
|
|
27
29
|
declare const Box: PolymorphicComponentWithRef<BoxOwnProps, 'div'>;
|
|
28
30
|
|
|
29
31
|
declare const Global: () => JSX.Element;
|
|
@@ -177,9 +179,9 @@ declare const getNormalizedStyles: (val?: ElementType<any> | undefined) => {
|
|
|
177
179
|
readonly minWidth: 0;
|
|
178
180
|
};
|
|
179
181
|
|
|
180
|
-
|
|
182
|
+
interface SVGProps extends ComponentProps<'svg'> {
|
|
181
183
|
size?: number;
|
|
182
|
-
}
|
|
184
|
+
}
|
|
183
185
|
declare const SVG: React.FC<SVGProps>;
|
|
184
186
|
|
|
185
187
|
/**
|
|
@@ -208,13 +210,21 @@ declare type ScaleValue<T> = T | T[] | NestedScaleDict<T> | undefined;
|
|
|
208
210
|
* descriptive name for the scale (e.g. `small`/`medium`/.. or `body`/`heading`/...),
|
|
209
211
|
* and the value is the CSS value.
|
|
210
212
|
*/
|
|
211
|
-
|
|
213
|
+
interface Scale<T> {
|
|
212
214
|
[key: string]: ScaleValue<T>;
|
|
213
|
-
}
|
|
215
|
+
}
|
|
216
|
+
/**
|
|
217
|
+
* A {@link Scale} that also includes a required `none` value, which is
|
|
218
|
+
* usually used to define the blank value (e.g `0`).
|
|
219
|
+
*/
|
|
220
|
+
interface ZeroScale<T> extends Scale<T> {
|
|
221
|
+
none: ScaleValue<T>;
|
|
222
|
+
}
|
|
214
223
|
/**
|
|
215
224
|
* Predefined {@link Scale} scale which uses size values.
|
|
216
225
|
*/
|
|
217
|
-
|
|
226
|
+
interface SizeScale<T> {
|
|
227
|
+
regular?: ScaleValue<T>;
|
|
218
228
|
xxsmall?: ScaleValue<T>;
|
|
219
229
|
xsmall?: ScaleValue<T>;
|
|
220
230
|
small?: ScaleValue<T>;
|
|
@@ -222,14 +232,17 @@ declare type SizeScale<T> = {
|
|
|
222
232
|
large?: ScaleValue<T>;
|
|
223
233
|
xlarge?: ScaleValue<T>;
|
|
224
234
|
xxlarge?: ScaleValue<T>;
|
|
225
|
-
|
|
235
|
+
xxxlarge?: ScaleValue<T>;
|
|
236
|
+
huge?: ScaleValue<T>;
|
|
237
|
+
epic?: ScaleValue<T>;
|
|
238
|
+
}
|
|
226
239
|
/**
|
|
227
240
|
* A {@link SizeScale} that also includes a required `none` value, which is
|
|
228
241
|
* usually used to define the blank value (e.g `0`).
|
|
229
242
|
*/
|
|
230
|
-
|
|
243
|
+
interface ZeroSizeScale<T> extends SizeScale<T> {
|
|
231
244
|
none: ScaleValue<T>;
|
|
232
|
-
}
|
|
245
|
+
}
|
|
233
246
|
/**
|
|
234
247
|
* Base theme with typings for available scales properties.
|
|
235
248
|
*/
|
|
@@ -246,7 +259,7 @@ interface Theme {
|
|
|
246
259
|
* ```ts
|
|
247
260
|
* {
|
|
248
261
|
* breakpoints: [
|
|
249
|
-
* '40em', '
|
|
262
|
+
* '40em', '50em', '64em',
|
|
250
263
|
* ],
|
|
251
264
|
* }
|
|
252
265
|
* ```
|
|
@@ -257,7 +270,7 @@ interface Theme {
|
|
|
257
270
|
* Used to define a scale for whitspace values,
|
|
258
271
|
* like `padding`, `margin`, `gap`, etc.
|
|
259
272
|
*/
|
|
260
|
-
space?:
|
|
273
|
+
space?: ZeroSizeScale<CSS.Property.Margin<number | string>>;
|
|
261
274
|
/**
|
|
262
275
|
* Used to define a `font-size` scale.
|
|
263
276
|
*/
|
|
@@ -277,12 +290,12 @@ interface Theme {
|
|
|
277
290
|
/**
|
|
278
291
|
* Used to define a `letter-spacing` scale.
|
|
279
292
|
*/
|
|
280
|
-
letterSpacings?:
|
|
293
|
+
letterSpacings?: Scale<CSS.Property.LetterSpacing<string | 0 | number>>;
|
|
281
294
|
/**
|
|
282
295
|
* Used to define a scale for size values,
|
|
283
296
|
* like `height`, `width`, `flexBasis`, etc.
|
|
284
297
|
*/
|
|
285
|
-
sizes?:
|
|
298
|
+
sizes?: ZeroSizeScale<CSS.Property.Height<{}> | CSS.Property.Width<{}>>;
|
|
286
299
|
/**
|
|
287
300
|
* Used to define different `border` styles.
|
|
288
301
|
*/
|
|
@@ -314,9 +327,16 @@ interface Theme {
|
|
|
314
327
|
/**
|
|
315
328
|
* Used to define a `transition` styles.
|
|
316
329
|
*/
|
|
317
|
-
transitions?:
|
|
330
|
+
transitions?: Scale<CSS.Property.Transition>;
|
|
318
331
|
}
|
|
319
332
|
|
|
333
|
+
/**
|
|
334
|
+
* Hook that can be used to return values based on the current screen size,
|
|
335
|
+
* using breakpoints from the theme (`theme.breakpoints`). Note that this
|
|
336
|
+
* hook is client.side only.
|
|
337
|
+
*/
|
|
338
|
+
declare const useResponsiveValue: <T>(values: T[], defaultIndex?: number) => T;
|
|
339
|
+
|
|
320
340
|
/**
|
|
321
341
|
* @internal
|
|
322
342
|
*/
|
|
@@ -325,10 +345,10 @@ declare const useTheme: () => {
|
|
|
325
345
|
theme: Theme;
|
|
326
346
|
css: (style: StyleObject) => _theme_ui_css.CSSObject;
|
|
327
347
|
};
|
|
328
|
-
|
|
348
|
+
interface ThemeProviderProps<T extends Theme> {
|
|
329
349
|
theme: T;
|
|
330
350
|
children: ReactNode;
|
|
331
|
-
}
|
|
351
|
+
}
|
|
332
352
|
declare function ThemeProvider<T extends Theme>({ theme, children, }: ThemeProviderProps<T>): JSX.Element;
|
|
333
353
|
|
|
334
354
|
/**
|
|
@@ -344,13 +364,13 @@ declare const ensureVariantDefault: (val: string) => string;
|
|
|
344
364
|
* Ensures that the `variant` is an array and supports the `__default` key.
|
|
345
365
|
*/
|
|
346
366
|
declare const ensureArrayVariant: <T extends string>(variant?: T | T[] | undefined) => string[];
|
|
347
|
-
|
|
367
|
+
interface State {
|
|
348
368
|
checked?: boolean;
|
|
349
369
|
focus?: boolean;
|
|
350
370
|
hover?: boolean;
|
|
351
371
|
disabled?: boolean;
|
|
352
372
|
error?: boolean;
|
|
353
|
-
}
|
|
373
|
+
}
|
|
354
374
|
/**
|
|
355
375
|
* Appends given `state` to a `variant`.
|
|
356
376
|
*/
|
|
@@ -361,4 +381,4 @@ declare const appendVariantState: (variant: string, state: keyof State) => strin
|
|
|
361
381
|
*/
|
|
362
382
|
declare const conditional: (variant: string, { disabled, ...states }: State) => string[];
|
|
363
383
|
|
|
364
|
-
export { Box, BoxOwnProps, BoxProps, CSSObject, CSSProperties, Global, NormalizedElement, ResponsiveStyleValue, SVG, SVGProps, Scale, ScaleValue, SizeScale, State, StyleObject, StyleProps, Theme, ThemeProvider, ThemeProviderProps, ZeroScale, __defaultTheme, appendVariantState, conditional, ensureArray, ensureArrayVariant, ensureVariantDefault, getNormalizedStyles, normalize, useTheme };
|
|
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 };
|
package/dist/index.js
CHANGED
|
@@ -70,6 +70,7 @@ __export(src_exports, {
|
|
|
70
70
|
ensureVariantDefault: () => ensureVariantDefault,
|
|
71
71
|
getNormalizedStyles: () => getNormalizedStyles,
|
|
72
72
|
normalize: () => normalize,
|
|
73
|
+
useResponsiveValue: () => useResponsiveValue,
|
|
73
74
|
useTheme: () => useTheme
|
|
74
75
|
});
|
|
75
76
|
|
|
@@ -164,13 +165,13 @@ var conditional = (variant, _a) => {
|
|
|
164
165
|
|
|
165
166
|
// src/Box.tsx
|
|
166
167
|
var isNotEmpty = (val) => !(val && Object.keys(val).length === 0 && val.constructor === Object);
|
|
167
|
-
var createThemedStyle = ({ as, __baseCSS, variant, styles, css
|
|
168
|
+
var createThemedStyle = ({ as, __baseCSS, variant, styles, css }) => (theme) => {
|
|
168
169
|
return [
|
|
169
170
|
getNormalizedStyles(as),
|
|
170
171
|
(0, import_css.css)(__baseCSS)(theme),
|
|
171
172
|
...ensureArrayVariant(variant).map((v) => (0, import_css.css)({ variant: v })(theme)),
|
|
172
173
|
(0, import_css.css)(styles)(theme),
|
|
173
|
-
(0, import_css.css)(
|
|
174
|
+
(0, import_css.css)(css)(theme)
|
|
174
175
|
].filter(isNotEmpty);
|
|
175
176
|
};
|
|
176
177
|
var Box = (0, import_react2.forwardRef)((_a, ref) => {
|
|
@@ -179,7 +180,7 @@ var Box = (0, import_react2.forwardRef)((_a, ref) => {
|
|
|
179
180
|
children,
|
|
180
181
|
__baseCSS,
|
|
181
182
|
variant,
|
|
182
|
-
css
|
|
183
|
+
css = {},
|
|
183
184
|
display,
|
|
184
185
|
height,
|
|
185
186
|
width,
|
|
@@ -268,7 +269,7 @@ var Box = (0, import_react2.forwardRef)((_a, ref) => {
|
|
|
268
269
|
as,
|
|
269
270
|
__baseCSS,
|
|
270
271
|
variant,
|
|
271
|
-
css
|
|
272
|
+
css,
|
|
272
273
|
styles: {
|
|
273
274
|
display,
|
|
274
275
|
height,
|
|
@@ -326,8 +327,8 @@ var __defaultTheme = {};
|
|
|
326
327
|
var InternalContext = (0, import_react3.createContext)(__defaultTheme);
|
|
327
328
|
var useTheme = () => {
|
|
328
329
|
const theme = (0, import_react3.useContext)(InternalContext);
|
|
329
|
-
const
|
|
330
|
-
return { theme, css
|
|
330
|
+
const css = (0, import_react3.useCallback)((style) => (0, import_css2.css)(style)(theme), [theme]);
|
|
331
|
+
return { theme, css };
|
|
331
332
|
};
|
|
332
333
|
function ThemeProvider({
|
|
333
334
|
theme,
|
|
@@ -351,10 +352,11 @@ var reduceMotionStyles = {
|
|
|
351
352
|
}
|
|
352
353
|
};
|
|
353
354
|
var Global = () => {
|
|
354
|
-
const { css
|
|
355
|
-
const styles =
|
|
355
|
+
const { css } = useTheme();
|
|
356
|
+
const styles = css({
|
|
356
357
|
html: {
|
|
357
358
|
height: "100%",
|
|
359
|
+
textSizeAdjust: "none",
|
|
358
360
|
variant: "root.html"
|
|
359
361
|
},
|
|
360
362
|
body: {
|
|
@@ -371,17 +373,49 @@ var Global = () => {
|
|
|
371
373
|
|
|
372
374
|
// src/SVG.tsx
|
|
373
375
|
var import_react7 = require("@emotion/react");
|
|
374
|
-
var
|
|
376
|
+
var normalizedStyles = getNormalizedStyles("svg");
|
|
375
377
|
var SVG = (_a) => {
|
|
376
|
-
var _b = _a, {
|
|
377
|
-
|
|
378
|
+
var _b = _a, {
|
|
379
|
+
size = 24,
|
|
380
|
+
fill = "currentcolor",
|
|
381
|
+
children
|
|
382
|
+
} = _b, props = __objRest(_b, [
|
|
383
|
+
"size",
|
|
384
|
+
"fill",
|
|
385
|
+
"children"
|
|
386
|
+
]);
|
|
387
|
+
const { css } = useTheme();
|
|
388
|
+
return (0, import_react7.jsx)("svg", __spreadValues({
|
|
378
389
|
width: size,
|
|
379
390
|
height: size,
|
|
380
391
|
viewBox: "0 0 24 24",
|
|
381
|
-
|
|
382
|
-
}, props),
|
|
383
|
-
|
|
384
|
-
|
|
392
|
+
css: css(__spreadValues({ fill }, normalizedStyles))
|
|
393
|
+
}, props), children);
|
|
394
|
+
};
|
|
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];
|
|
385
419
|
};
|
|
386
420
|
module.exports = __toCommonJS(src_exports);
|
|
387
421
|
// Annotate the CommonJS export names for ESM import in node:
|
|
@@ -398,5 +432,6 @@ module.exports = __toCommonJS(src_exports);
|
|
|
398
432
|
ensureVariantDefault,
|
|
399
433
|
getNormalizedStyles,
|
|
400
434
|
normalize,
|
|
435
|
+
useResponsiveValue,
|
|
401
436
|
useTheme
|
|
402
437
|
});
|
package/dist/index.mjs
CHANGED
|
@@ -121,13 +121,13 @@ var conditional = (variant, _a) => {
|
|
|
121
121
|
|
|
122
122
|
// src/Box.tsx
|
|
123
123
|
var isNotEmpty = (val) => !(val && Object.keys(val).length === 0 && val.constructor === Object);
|
|
124
|
-
var createThemedStyle = ({ as, __baseCSS, variant, styles, css
|
|
124
|
+
var createThemedStyle = ({ as, __baseCSS, variant, styles, css }) => (theme) => {
|
|
125
125
|
return [
|
|
126
126
|
getNormalizedStyles(as),
|
|
127
127
|
transformStyleObject(__baseCSS)(theme),
|
|
128
128
|
...ensureArrayVariant(variant).map((v) => transformStyleObject({ variant: v })(theme)),
|
|
129
129
|
transformStyleObject(styles)(theme),
|
|
130
|
-
transformStyleObject(
|
|
130
|
+
transformStyleObject(css)(theme)
|
|
131
131
|
].filter(isNotEmpty);
|
|
132
132
|
};
|
|
133
133
|
var Box = forwardRef((_a, ref) => {
|
|
@@ -136,7 +136,7 @@ var Box = forwardRef((_a, ref) => {
|
|
|
136
136
|
children,
|
|
137
137
|
__baseCSS,
|
|
138
138
|
variant,
|
|
139
|
-
css
|
|
139
|
+
css = {},
|
|
140
140
|
display,
|
|
141
141
|
height,
|
|
142
142
|
width,
|
|
@@ -225,7 +225,7 @@ var Box = forwardRef((_a, ref) => {
|
|
|
225
225
|
as,
|
|
226
226
|
__baseCSS,
|
|
227
227
|
variant,
|
|
228
|
-
css
|
|
228
|
+
css,
|
|
229
229
|
styles: {
|
|
230
230
|
display,
|
|
231
231
|
height,
|
|
@@ -287,8 +287,8 @@ var __defaultTheme = {};
|
|
|
287
287
|
var InternalContext = createContext(__defaultTheme);
|
|
288
288
|
var useTheme = () => {
|
|
289
289
|
const theme = useContext(InternalContext);
|
|
290
|
-
const
|
|
291
|
-
return { theme, css
|
|
290
|
+
const css = useCallback((style) => transformStyleObject2(style)(theme), [theme]);
|
|
291
|
+
return { theme, css };
|
|
292
292
|
};
|
|
293
293
|
function ThemeProvider({
|
|
294
294
|
theme,
|
|
@@ -312,10 +312,11 @@ var reduceMotionStyles = {
|
|
|
312
312
|
}
|
|
313
313
|
};
|
|
314
314
|
var Global = () => {
|
|
315
|
-
const { css
|
|
316
|
-
const styles =
|
|
315
|
+
const { css } = useTheme();
|
|
316
|
+
const styles = css({
|
|
317
317
|
html: {
|
|
318
318
|
height: "100%",
|
|
319
|
+
textSizeAdjust: "none",
|
|
319
320
|
variant: "root.html"
|
|
320
321
|
},
|
|
321
322
|
body: {
|
|
@@ -332,17 +333,49 @@ var Global = () => {
|
|
|
332
333
|
|
|
333
334
|
// src/SVG.tsx
|
|
334
335
|
import { jsx as jsx2 } from "@emotion/react";
|
|
335
|
-
var
|
|
336
|
+
var normalizedStyles = getNormalizedStyles("svg");
|
|
336
337
|
var SVG = (_a) => {
|
|
337
|
-
var _b = _a, {
|
|
338
|
-
|
|
338
|
+
var _b = _a, {
|
|
339
|
+
size = 24,
|
|
340
|
+
fill = "currentcolor",
|
|
341
|
+
children
|
|
342
|
+
} = _b, props = __objRest(_b, [
|
|
343
|
+
"size",
|
|
344
|
+
"fill",
|
|
345
|
+
"children"
|
|
346
|
+
]);
|
|
347
|
+
const { css } = useTheme();
|
|
348
|
+
return jsx2("svg", __spreadValues({
|
|
339
349
|
width: size,
|
|
340
350
|
height: size,
|
|
341
351
|
viewBox: "0 0 24 24",
|
|
342
|
-
|
|
343
|
-
}, props),
|
|
344
|
-
|
|
345
|
-
|
|
352
|
+
css: css(__spreadValues({ fill }, normalizedStyles))
|
|
353
|
+
}, props), children);
|
|
354
|
+
};
|
|
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];
|
|
346
379
|
};
|
|
347
380
|
export {
|
|
348
381
|
Box,
|
|
@@ -357,5 +390,6 @@ export {
|
|
|
357
390
|
ensureVariantDefault,
|
|
358
391
|
getNormalizedStyles,
|
|
359
392
|
normalize,
|
|
393
|
+
useResponsiveValue,
|
|
360
394
|
useTheme
|
|
361
395
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@marigold/system",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.0",
|
|
4
4
|
"description": "Marigold System Library",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"keywords": [
|
|
@@ -22,14 +22,14 @@
|
|
|
22
22
|
],
|
|
23
23
|
"repository": {
|
|
24
24
|
"type": "git",
|
|
25
|
-
"url": "github
|
|
25
|
+
"url": "https://github.com/marigold-ui/marigold",
|
|
26
26
|
"directory": "packages/system"
|
|
27
27
|
},
|
|
28
28
|
"dependencies": {
|
|
29
29
|
"@emotion/react": "11.7.1",
|
|
30
30
|
"@marigold/types": "0.4.0",
|
|
31
31
|
"@theme-ui/css": "0.13.1",
|
|
32
|
-
"csstype": "3.0.
|
|
32
|
+
"csstype": "3.0.11"
|
|
33
33
|
},
|
|
34
34
|
"peerDependencies": {
|
|
35
35
|
"react": "^16.x || ^17.0.0",
|