@marigold/system 0.4.0 → 0.5.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 +6 -0
- package/dist/index.d.ts +8 -1
- package/dist/index.js +27 -0
- package/dist/index.mjs +26 -0
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
# @marigold/system
|
|
2
2
|
|
|
3
|
+
## 0.5.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [#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
|
|
8
|
+
|
|
3
9
|
## 0.4.0
|
|
4
10
|
|
|
5
11
|
### Minor Changes
|
package/dist/index.d.ts
CHANGED
|
@@ -317,6 +317,13 @@ interface Theme {
|
|
|
317
317
|
transitions?: ZeroScale<CSS.Property.Transition>;
|
|
318
318
|
}
|
|
319
319
|
|
|
320
|
+
/**
|
|
321
|
+
* Hook that can be used to return values based on the current screen size,
|
|
322
|
+
* using breakpoints from the theme (`theme.breakpoints`). Note that this
|
|
323
|
+
* hook is client.side only.
|
|
324
|
+
*/
|
|
325
|
+
declare const useResponsiveValue: <T>(values: T[], defaultIndex?: number) => T;
|
|
326
|
+
|
|
320
327
|
/**
|
|
321
328
|
* @internal
|
|
322
329
|
*/
|
|
@@ -361,4 +368,4 @@ declare const appendVariantState: (variant: string, state: keyof State) => strin
|
|
|
361
368
|
*/
|
|
362
369
|
declare const conditional: (variant: string, { disabled, ...states }: State) => string[];
|
|
363
370
|
|
|
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 };
|
|
371
|
+
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, 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
|
|
|
@@ -383,6 +384,31 @@ var SVG = (_a) => {
|
|
|
383
384
|
css
|
|
384
385
|
}), children);
|
|
385
386
|
};
|
|
387
|
+
|
|
388
|
+
// src/useResponsiveValue.ts
|
|
389
|
+
var import_react8 = require("react");
|
|
390
|
+
var emptyBreakpoints = ["40em", "52em", "64em"];
|
|
391
|
+
var useResponsiveValue = (values, defaultIndex = 0) => {
|
|
392
|
+
const { theme } = useTheme();
|
|
393
|
+
const breakpoints = theme.breakpoints || emptyBreakpoints;
|
|
394
|
+
if (defaultIndex < 0 || defaultIndex >= breakpoints.length) {
|
|
395
|
+
throw new RangeError(`Default breakpoint index is out of bounds. Theme has ${breakpoints.length} breakpoints, default is ${defaultIndex}.`);
|
|
396
|
+
}
|
|
397
|
+
const [index, setIndex] = (0, import_react8.useState)(defaultIndex);
|
|
398
|
+
(0, import_react8.useEffect)(() => {
|
|
399
|
+
const getIndex = () => breakpoints.filter((breakpoint) => window.matchMedia(`screen and (min-width: ${breakpoint})`).matches).length;
|
|
400
|
+
const handleResize = () => {
|
|
401
|
+
const newIndex = getIndex();
|
|
402
|
+
if (index !== newIndex) {
|
|
403
|
+
setIndex(newIndex);
|
|
404
|
+
}
|
|
405
|
+
};
|
|
406
|
+
handleResize();
|
|
407
|
+
window.addEventListener("resize", handleResize);
|
|
408
|
+
return () => window.removeEventListener("resize", handleResize);
|
|
409
|
+
}, [breakpoints, index]);
|
|
410
|
+
return values[index >= values.length ? values.length - 1 : index];
|
|
411
|
+
};
|
|
386
412
|
module.exports = __toCommonJS(src_exports);
|
|
387
413
|
// Annotate the CommonJS export names for ESM import in node:
|
|
388
414
|
0 && (module.exports = {
|
|
@@ -398,5 +424,6 @@ module.exports = __toCommonJS(src_exports);
|
|
|
398
424
|
ensureVariantDefault,
|
|
399
425
|
getNormalizedStyles,
|
|
400
426
|
normalize,
|
|
427
|
+
useResponsiveValue,
|
|
401
428
|
useTheme
|
|
402
429
|
});
|
package/dist/index.mjs
CHANGED
|
@@ -344,6 +344,31 @@ var SVG = (_a) => {
|
|
|
344
344
|
css
|
|
345
345
|
}), children);
|
|
346
346
|
};
|
|
347
|
+
|
|
348
|
+
// src/useResponsiveValue.ts
|
|
349
|
+
import { useEffect, useState } from "react";
|
|
350
|
+
var emptyBreakpoints = ["40em", "52em", "64em"];
|
|
351
|
+
var useResponsiveValue = (values, defaultIndex = 0) => {
|
|
352
|
+
const { theme } = useTheme();
|
|
353
|
+
const breakpoints = theme.breakpoints || emptyBreakpoints;
|
|
354
|
+
if (defaultIndex < 0 || defaultIndex >= breakpoints.length) {
|
|
355
|
+
throw new RangeError(`Default breakpoint index is out of bounds. Theme has ${breakpoints.length} breakpoints, default is ${defaultIndex}.`);
|
|
356
|
+
}
|
|
357
|
+
const [index, setIndex] = useState(defaultIndex);
|
|
358
|
+
useEffect(() => {
|
|
359
|
+
const getIndex = () => breakpoints.filter((breakpoint) => window.matchMedia(`screen and (min-width: ${breakpoint})`).matches).length;
|
|
360
|
+
const handleResize = () => {
|
|
361
|
+
const newIndex = getIndex();
|
|
362
|
+
if (index !== newIndex) {
|
|
363
|
+
setIndex(newIndex);
|
|
364
|
+
}
|
|
365
|
+
};
|
|
366
|
+
handleResize();
|
|
367
|
+
window.addEventListener("resize", handleResize);
|
|
368
|
+
return () => window.removeEventListener("resize", handleResize);
|
|
369
|
+
}, [breakpoints, index]);
|
|
370
|
+
return values[index >= values.length ? values.length - 1 : index];
|
|
371
|
+
};
|
|
347
372
|
export {
|
|
348
373
|
Box,
|
|
349
374
|
Global,
|
|
@@ -357,5 +382,6 @@ export {
|
|
|
357
382
|
ensureVariantDefault,
|
|
358
383
|
getNormalizedStyles,
|
|
359
384
|
normalize,
|
|
385
|
+
useResponsiveValue,
|
|
360
386
|
useTheme
|
|
361
387
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@marigold/system",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0",
|
|
4
4
|
"description": "Marigold System Library",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"keywords": [
|
|
@@ -22,7 +22,7 @@
|
|
|
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": {
|