colibri-ui 0.8.78 → 0.8.80

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/README.md CHANGED
@@ -190,6 +190,12 @@ const css = `@media ${media.down("sm")} { … }`;
190
190
 
191
191
  `BREAKPOINTS` and `media` are also exported from `colibri-ui/Theme`.
192
192
 
193
+ ### useMediaSizes
194
+
195
+ `useMediaSizes(query)` takes a query string or a function that receives `media`, and returns whether the query matches. It updates when the viewport crosses the edge.
196
+
197
+ Returns `false` on the server and during hydration. Use it to decide whether to mount a heavy component; to show/hide markup use CSS media queries, otherwise the wrong variant renders until hydration.
198
+
193
199
  ## License
194
200
 
195
201
  MIT
@@ -0,0 +1 @@
1
+ export { Autocomplete } from './Autocomplete.js';
@@ -0,0 +1 @@
1
+ export { Calendar } from './Calendar.js';
@@ -0,0 +1 @@
1
+ export { Card, CardContent, CardInnerContent } from './Card.js';
@@ -0,0 +1 @@
1
+ export { CodeField, ONLY_CHARS_PATTERN, ONLY_DIGITS_AND_CHARS_PATTERN, ONLY_DIGITS_PATTERN } from './CodeField.js';
@@ -0,0 +1 @@
1
+ export { Drawer, DrawerContent, DrawerFooter, DrawerHeader } from './Drawer.js';
@@ -0,0 +1 @@
1
+ export { Dropzone } from './Dropzone.js';
@@ -0,0 +1 @@
1
+ export { Editable } from './Editable.js';
@@ -0,0 +1,21 @@
1
+ export { ArrowNext } from './ArrowNext.js';
2
+ export { Cart } from './Cart.js';
3
+ export { Check } from './Check.js';
4
+ export { Chevron } from './Chevron.js';
5
+ export { Close } from './Close.js';
6
+ export { Copy } from './Copy.js';
7
+ export { Cross } from './Cross.js';
8
+ export { CrossFill } from './CrossFill.js';
9
+ export { Edit } from './Edit.js';
10
+ export { Exit } from './Exit.js';
11
+ export { EyeOpen } from './EyeOpen.js';
12
+ export { EyeClosed } from './EyeClosed.js';
13
+ export { Help } from './Help.js';
14
+ export { Info } from './Info.js';
15
+ export { Minus } from './Minus.js';
16
+ export { More } from './More.js';
17
+ export { Plus } from './Plus.js';
18
+ export { Setting } from './Setting.js';
19
+ export { Shield } from './Shield.js';
20
+ export { Trash } from './Trash.js';
21
+ export { User } from './User.js';
@@ -0,0 +1 @@
1
+ export { List, ListItem, ListSection } from './List.js';
@@ -0,0 +1 @@
1
+ export { NumberInput } from './NumberInput.js';
@@ -0,0 +1 @@
1
+ export { Progress } from './Progress.js';
@@ -0,0 +1 @@
1
+ export { Rating } from './Rating.js';
@@ -0,0 +1 @@
1
+ export { Slider } from './Slider.js';
@@ -1,6 +1,7 @@
1
1
  import { BUTTON_TOKENS } from '../Button/tokens.js';
2
2
  import theme_jaipur from './themes/jaipur.js';
3
3
  import THEME_BA from './themes/buenos_aires.js';
4
+ export { BREAKPOINTS, media } from './breakpoints.js';
4
5
 
5
6
  var THEMES = {
6
7
  JAIPUR: Object.assign(Object.assign({}, theme_jaipur), BUTTON_TOKENS),
@@ -1,5 +1,9 @@
1
1
  import type { Media } from "../../Theme/breakpoints";
2
2
  export type QueryInputFunction = (breakpoints: Media) => string;
3
3
  type QueryInput = QueryInputFunction | string;
4
+ /**
5
+ * Returns whether the media query matches.
6
+ * Returns `false` on the server and during hydration, the real value right after.
7
+ */
4
8
  export declare const useMediaSizes: (queryInput: QueryInput) => boolean;
5
9
  export {};
@@ -1,38 +1,32 @@
1
- import _slicedToArray from '@babel/runtime/helpers/slicedToArray';
2
- import { useState, useEffect } from 'react';
1
+ import { useCallback, useSyncExternalStore } from 'react';
3
2
  import { media } from '../../Theme/breakpoints.js';
4
3
 
5
- var supportMatchMedia = typeof window !== "undefined" && typeof window.matchMedia !== "undefined";
4
+ var getServerSnapshot = function getServerSnapshot() {
5
+ return false;
6
+ };
7
+ var getMediaQueryList = function getMediaQueryList(query) {
8
+ return typeof window !== "undefined" && typeof window.matchMedia === "function" ? window.matchMedia(query) : null;
9
+ };
10
+ /**
11
+ * Returns whether the media query matches.
12
+ * Returns `false` on the server and during hydration, the real value right after.
13
+ */
6
14
  var useMediaSizes = function useMediaSizes(queryInput) {
7
- var query = typeof queryInput === "function" ? queryInput(media) : queryInput;
8
- query = query.replace(/^@media( ?)/m, "");
9
- var matchMedia = supportMatchMedia ? window.matchMedia : null;
10
- var _useState = useState(function () {
11
- if (matchMedia) {
12
- return matchMedia(query).matches;
13
- }
14
- return false;
15
- }),
16
- _useState2 = _slicedToArray(_useState, 2),
17
- match = _useState2[0],
18
- setMatch = _useState2[1];
19
- useEffect(function () {
20
- if (!matchMedia) return undefined;
21
- var active = true;
22
- var queryList = matchMedia(query);
23
- var updateMatch = function updateMatch() {
24
- if (active) {
25
- setMatch(queryList.matches);
26
- }
27
- };
28
- updateMatch();
29
- queryList.addEventListener("change", updateMatch);
15
+ // A function input is a new function every render: memoize on the query string.
16
+ var query = (typeof queryInput === "function" ? queryInput(media) : queryInput).replace(/^\s*@media\s*/, "");
17
+ var subscribe = useCallback(function (onChange) {
18
+ var queryList = getMediaQueryList(query);
19
+ if (!queryList) return function () {};
20
+ queryList.addEventListener("change", onChange);
30
21
  return function () {
31
- active = false;
32
- queryList.removeEventListener("change", updateMatch);
22
+ return queryList.removeEventListener("change", onChange);
33
23
  };
34
- });
35
- return match;
24
+ }, [query]);
25
+ var getSnapshot = useCallback(function () {
26
+ var _a, _b;
27
+ return (_b = (_a = getMediaQueryList(query)) === null || _a === void 0 ? void 0 : _a.matches) !== null && _b !== void 0 ? _b : false;
28
+ }, [query]);
29
+ return useSyncExternalStore(subscribe, getSnapshot, getServerSnapshot);
36
30
  };
37
31
 
38
32
  export { useMediaSizes };
@@ -1,5 +1,9 @@
1
1
  import type { Media } from "../../Theme/breakpoints";
2
2
  export type QueryInputFunction = (breakpoints: Media) => string;
3
3
  type QueryInput = QueryInputFunction | string;
4
+ /**
5
+ * Returns whether the media query matches.
6
+ * Returns `false` on the server and during hydration, the real value right after.
7
+ */
4
8
  export declare const useMediaSizes: (queryInput: QueryInput) => boolean;
5
9
  export {};
@@ -1,44 +1,34 @@
1
1
  'use strict';
2
2
 
3
- var _slicedToArray = require('@babel/runtime/helpers/slicedToArray');
4
3
  var React = require('react');
5
4
  var breakpoints = require('../../Theme/breakpoints.js');
6
5
 
7
- function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
8
-
9
- var _slicedToArray__default = /*#__PURE__*/_interopDefault(_slicedToArray);
10
-
11
- var supportMatchMedia = typeof window !== "undefined" && typeof window.matchMedia !== "undefined";
6
+ var getServerSnapshot = function getServerSnapshot() {
7
+ return false;
8
+ };
9
+ var getMediaQueryList = function getMediaQueryList(query) {
10
+ return typeof window !== "undefined" && typeof window.matchMedia === "function" ? window.matchMedia(query) : null;
11
+ };
12
+ /**
13
+ * Returns whether the media query matches.
14
+ * Returns `false` on the server and during hydration, the real value right after.
15
+ */
12
16
  var useMediaSizes = function useMediaSizes(queryInput) {
13
- var query = typeof queryInput === "function" ? queryInput(breakpoints.media) : queryInput;
14
- query = query.replace(/^@media( ?)/m, "");
15
- var matchMedia = supportMatchMedia ? window.matchMedia : null;
16
- var _useState = React.useState(function () {
17
- if (matchMedia) {
18
- return matchMedia(query).matches;
19
- }
20
- return false;
21
- }),
22
- _useState2 = _slicedToArray__default.default(_useState, 2),
23
- match = _useState2[0],
24
- setMatch = _useState2[1];
25
- React.useEffect(function () {
26
- if (!matchMedia) return undefined;
27
- var active = true;
28
- var queryList = matchMedia(query);
29
- var updateMatch = function updateMatch() {
30
- if (active) {
31
- setMatch(queryList.matches);
32
- }
33
- };
34
- updateMatch();
35
- queryList.addEventListener("change", updateMatch);
17
+ // A function input is a new function every render: memoize on the query string.
18
+ var query = (typeof queryInput === "function" ? queryInput(breakpoints.media) : queryInput).replace(/^\s*@media\s*/, "");
19
+ var subscribe = React.useCallback(function (onChange) {
20
+ var queryList = getMediaQueryList(query);
21
+ if (!queryList) return function () {};
22
+ queryList.addEventListener("change", onChange);
36
23
  return function () {
37
- active = false;
38
- queryList.removeEventListener("change", updateMatch);
24
+ return queryList.removeEventListener("change", onChange);
39
25
  };
40
- });
41
- return match;
26
+ }, [query]);
27
+ var getSnapshot = React.useCallback(function () {
28
+ var _a, _b;
29
+ return (_b = (_a = getMediaQueryList(query)) === null || _a === void 0 ? void 0 : _a.matches) !== null && _b !== void 0 ? _b : false;
30
+ }, [query]);
31
+ return React.useSyncExternalStore(subscribe, getSnapshot, getServerSnapshot);
42
32
  };
43
33
 
44
34
  exports.useMediaSizes = useMediaSizes;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "colibri-ui",
3
- "version": "0.8.78",
3
+ "version": "0.8.80",
4
4
  "description": "React UI components library",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",