colibri-ui 0.7.33 → 0.7.34
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/esm/hooks/useMediaSizes/index.js +36 -0
- package/esm/index.d.ts +1 -0
- package/esm/index.js +1 -0
- package/hooks/useMediaSizes/index.js +40 -0
- package/index.d.ts +1 -0
- package/index.js +2 -0
- package/package.json +1 -1
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { useState, useEffect } from 'react';
|
|
2
|
+
import Breakpoints from '../../Theme/breakpoints.js';
|
|
3
|
+
|
|
4
|
+
var supportMatchMedia = typeof window !== "undefined" && typeof window.matchMedia !== "undefined";
|
|
5
|
+
var useMediaSizes = function useMediaSizes(queryInput) {
|
|
6
|
+
var query = typeof queryInput === "function" ? queryInput(Breakpoints) : queryInput;
|
|
7
|
+
query = query.replace(/^@media( ?)/m, "");
|
|
8
|
+
var matchMedia = supportMatchMedia ? window.matchMedia : null;
|
|
9
|
+
var _a = useState(function () {
|
|
10
|
+
if (matchMedia) {
|
|
11
|
+
return matchMedia(query).matches;
|
|
12
|
+
}
|
|
13
|
+
return false;
|
|
14
|
+
}),
|
|
15
|
+
match = _a[0],
|
|
16
|
+
setMatch = _a[1];
|
|
17
|
+
useEffect(function () {
|
|
18
|
+
if (!matchMedia) return undefined;
|
|
19
|
+
var active = true;
|
|
20
|
+
var queryList = matchMedia(query);
|
|
21
|
+
var updateMatch = function updateMatch() {
|
|
22
|
+
if (active) {
|
|
23
|
+
setMatch(queryList.matches);
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
updateMatch();
|
|
27
|
+
queryList.addEventListener("change", updateMatch);
|
|
28
|
+
return function () {
|
|
29
|
+
active = false;
|
|
30
|
+
queryList.removeEventListener("change", updateMatch);
|
|
31
|
+
};
|
|
32
|
+
});
|
|
33
|
+
return match;
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
export { useMediaSizes as default };
|
package/esm/index.d.ts
CHANGED
|
@@ -15,4 +15,5 @@ export { SkeletonText, SkeletonRect } from "./Skeleton";
|
|
|
15
15
|
export { default as Switch } from "./Switch";
|
|
16
16
|
export { THEMES, ThemeProvider } from "./Theme";
|
|
17
17
|
export { default as Typography } from "./Typography";
|
|
18
|
+
export { default as useMediaSizes } from "./hooks/useMediaSizes";
|
|
18
19
|
export * from "./Icons";
|
package/esm/index.js
CHANGED
|
@@ -15,6 +15,7 @@ export { SkeletonRect, SkeletonText } from './Skeleton/index.js';
|
|
|
15
15
|
export { default as Switch } from './Switch/index.js';
|
|
16
16
|
export { THEMES, ThemeProvider } from './Theme/index.js';
|
|
17
17
|
export { default as Typography } from './Typography/index.js';
|
|
18
|
+
export { default as useMediaSizes } from './hooks/useMediaSizes/index.js';
|
|
18
19
|
import './Icons/index.js';
|
|
19
20
|
export { default as Cart } from './Icons/Cart.js';
|
|
20
21
|
export { default as Chevron } from './Icons/Chevron.js';
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var React = require('react');
|
|
6
|
+
var breakpoints = require('../../Theme/breakpoints.js');
|
|
7
|
+
|
|
8
|
+
var supportMatchMedia = typeof window !== "undefined" && typeof window.matchMedia !== "undefined";
|
|
9
|
+
var useMediaSizes = function useMediaSizes(queryInput) {
|
|
10
|
+
var query = typeof queryInput === "function" ? queryInput(breakpoints.default) : queryInput;
|
|
11
|
+
query = query.replace(/^@media( ?)/m, "");
|
|
12
|
+
var matchMedia = supportMatchMedia ? window.matchMedia : null;
|
|
13
|
+
var _a = React.useState(function () {
|
|
14
|
+
if (matchMedia) {
|
|
15
|
+
return matchMedia(query).matches;
|
|
16
|
+
}
|
|
17
|
+
return false;
|
|
18
|
+
}),
|
|
19
|
+
match = _a[0],
|
|
20
|
+
setMatch = _a[1];
|
|
21
|
+
React.useEffect(function () {
|
|
22
|
+
if (!matchMedia) return undefined;
|
|
23
|
+
var active = true;
|
|
24
|
+
var queryList = matchMedia(query);
|
|
25
|
+
var updateMatch = function updateMatch() {
|
|
26
|
+
if (active) {
|
|
27
|
+
setMatch(queryList.matches);
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
updateMatch();
|
|
31
|
+
queryList.addEventListener("change", updateMatch);
|
|
32
|
+
return function () {
|
|
33
|
+
active = false;
|
|
34
|
+
queryList.removeEventListener("change", updateMatch);
|
|
35
|
+
};
|
|
36
|
+
});
|
|
37
|
+
return match;
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
exports.default = useMediaSizes;
|
package/index.d.ts
CHANGED
|
@@ -15,4 +15,5 @@ export { SkeletonText, SkeletonRect } from "./Skeleton";
|
|
|
15
15
|
export { default as Switch } from "./Switch";
|
|
16
16
|
export { THEMES, ThemeProvider } from "./Theme";
|
|
17
17
|
export { default as Typography } from "./Typography";
|
|
18
|
+
export { default as useMediaSizes } from "./hooks/useMediaSizes";
|
|
18
19
|
export * from "./Icons";
|
package/index.js
CHANGED
|
@@ -17,6 +17,7 @@ var index$d = require('./Skeleton/index.js');
|
|
|
17
17
|
var index$e = require('./Switch/index.js');
|
|
18
18
|
var index$f = require('./Theme/index.js');
|
|
19
19
|
var index$g = require('./Typography/index.js');
|
|
20
|
+
var index$h = require('./hooks/useMediaSizes/index.js');
|
|
20
21
|
require('./Icons/index.js');
|
|
21
22
|
var Cart = require('./Icons/Cart.js');
|
|
22
23
|
var Chevron = require('./Icons/Chevron.js');
|
|
@@ -52,6 +53,7 @@ exports.Switch = index$e.default;
|
|
|
52
53
|
exports.THEMES = index$f.THEMES;
|
|
53
54
|
exports.ThemeProvider = index$f.ThemeProvider;
|
|
54
55
|
exports.Typography = index$g.default;
|
|
56
|
+
exports.useMediaSizes = index$h.default;
|
|
55
57
|
exports.Cart = Cart.default;
|
|
56
58
|
exports.Chevron = Chevron.default;
|
|
57
59
|
exports.Close = Close.default;
|