colibri-ui 0.8.77 → 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/Modal/index.js +1 -1
- package/README.md +65 -0
- package/Theme/breakpoints.d.ts +20 -16
- package/Theme/breakpoints.js +21 -32
- package/Theme/index.d.ts +2 -0
- package/Theme/index.js +3 -0
- package/esm/Autocomplete/index.js +1 -0
- package/esm/Calendar/index.js +1 -0
- package/esm/Card/index.js +1 -0
- package/esm/CodeField/index.js +1 -0
- package/esm/Drawer/index.js +1 -0
- package/esm/Dropzone/index.js +1 -0
- package/esm/Editable/index.js +1 -0
- package/esm/Icons/index.js +21 -0
- package/esm/List/index.js +1 -0
- package/esm/Modal/index.js +1 -1
- package/esm/NumberInput/index.js +1 -0
- package/esm/Progress/index.js +1 -0
- package/esm/Rating/index.js +1 -0
- package/esm/Slider/index.js +1 -0
- package/esm/Theme/breakpoints.d.ts +20 -16
- package/esm/Theme/breakpoints.js +20 -26
- package/esm/Theme/index.d.ts +2 -0
- package/esm/Theme/index.js +1 -0
- package/esm/hooks/useMediaSizes/index.d.ts +6 -2
- package/esm/hooks/useMediaSizes/index.js +25 -31
- package/esm/index.d.ts +2 -1
- package/esm/index.js +1 -0
- package/hooks/useMediaSizes/index.d.ts +6 -2
- package/hooks/useMediaSizes/index.js +23 -33
- package/index.d.ts +2 -1
- package/index.js +3 -0
- package/package.json +1 -1
package/Modal/index.js
CHANGED
|
@@ -51,7 +51,7 @@ var ModalRoot = function ModalRoot(_ref) {
|
|
|
51
51
|
var parentContainer = withinParent ? parentModal === null || parentModal === void 0 ? void 0 : parentModal.container : undefined;
|
|
52
52
|
var isContained = Boolean(parentContainer);
|
|
53
53
|
var isDesktop = index$4.useMediaSizes(function (bp) {
|
|
54
|
-
return bp.up("
|
|
54
|
+
return bp.up("lg");
|
|
55
55
|
});
|
|
56
56
|
var titleId = React.useId();
|
|
57
57
|
var _useState3 = React.useState(0),
|
package/README.md
CHANGED
|
@@ -131,6 +131,71 @@ If you add a theme inside the library itself, create both layers:
|
|
|
131
131
|
|
|
132
132
|
Then export it from `src/components/Theme/index.tsx` and update `scripts/variables.ts` if you want a generated CSS variables file in the package build.
|
|
133
133
|
|
|
134
|
+
## Breakpoints
|
|
135
|
+
|
|
136
|
+
Colibri UI uses one fixed set of breakpoints, shared with the apps that use the kit.
|
|
137
|
+
|
|
138
|
+
| Name | Value | px |
|
|
139
|
+
| ----- | ------- | ---- |
|
|
140
|
+
| `sm` | `40rem` | 640 |
|
|
141
|
+
| `md` | `48rem` | 768 |
|
|
142
|
+
| `lg` | `64rem` | 1024 |
|
|
143
|
+
| `xl` | `80rem` | 1280 |
|
|
144
|
+
| `2xl` | `96rem` | 1536 |
|
|
145
|
+
|
|
146
|
+
The values match the Tailwind CSS defaults on purpose, because they are an industry standard. Tailwind is not a dependency of Colibri UI.
|
|
147
|
+
|
|
148
|
+
Rules:
|
|
149
|
+
|
|
150
|
+
- **Mobile first.** Base styles are for screens narrower than `sm`. There is no `xs`.
|
|
151
|
+
- **rem, not px.** Layout follows the user's browser font size.
|
|
152
|
+
- **Range syntax only.** Write `(width >= 48rem)` and `(width < 48rem)`. Do not use `min-width` / `max-width` or `- 1px` arithmetic: each edge belongs to exactly one side.
|
|
153
|
+
|
|
154
|
+
### CSS
|
|
155
|
+
|
|
156
|
+
CSS cannot read variables inside media queries, so write the value as a literal:
|
|
157
|
+
|
|
158
|
+
```css
|
|
159
|
+
.card {
|
|
160
|
+
padding: var(--space-4);
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
@media (width >= 64rem) {
|
|
164
|
+
.card {
|
|
165
|
+
padding: var(--space-6);
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
Inside the kit, a test and a stylelint rule reject `min-width` / `max-width` and any width value outside the table.
|
|
171
|
+
|
|
172
|
+
### JavaScript
|
|
173
|
+
|
|
174
|
+
```ts
|
|
175
|
+
import { BREAKPOINTS, media, useMediaSizes } from "colibri-ui";
|
|
176
|
+
|
|
177
|
+
BREAKPOINTS.md; // "48rem"
|
|
178
|
+
media.up("md"); // "(width >= 48rem)"
|
|
179
|
+
media.down("md"); // "(width < 48rem)"
|
|
180
|
+
media.between("md", "lg"); // "(48rem <= width < 64rem)"
|
|
181
|
+
|
|
182
|
+
window.matchMedia(media.up("lg")).matches;
|
|
183
|
+
|
|
184
|
+
// in a component
|
|
185
|
+
const isDesktop = useMediaSizes((bp) => bp.up("lg"));
|
|
186
|
+
|
|
187
|
+
// CSS-in-JS: add the @media prefix yourself
|
|
188
|
+
const css = `@media ${media.down("sm")} { … }`;
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
`BREAKPOINTS` and `media` are also exported from `colibri-ui/Theme`.
|
|
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
|
+
|
|
134
199
|
## License
|
|
135
200
|
|
|
136
201
|
MIT
|
package/Theme/breakpoints.d.ts
CHANGED
|
@@ -1,18 +1,22 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
sm:
|
|
7
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Breakpoints shared with the apps that use the kit.
|
|
3
|
+
* The values match the Tailwind CSS defaults on purpose; Tailwind is not a dependency.
|
|
4
|
+
*/
|
|
5
|
+
export declare const BREAKPOINTS: {
|
|
6
|
+
readonly sm: "40rem";
|
|
7
|
+
readonly md: "48rem";
|
|
8
|
+
readonly lg: "64rem";
|
|
9
|
+
readonly xl: "80rem";
|
|
10
|
+
readonly "2xl": "96rem";
|
|
8
11
|
};
|
|
9
|
-
export type BreakpointName = keyof
|
|
10
|
-
export type
|
|
11
|
-
|
|
12
|
-
up: (
|
|
13
|
-
|
|
14
|
-
|
|
12
|
+
export type BreakpointName = keyof typeof BREAKPOINTS;
|
|
13
|
+
export type Media = {
|
|
14
|
+
/** `(width >= <name>)` */
|
|
15
|
+
up: (name: BreakpointName) => string;
|
|
16
|
+
/** `(width < <name>)` */
|
|
17
|
+
down: (name: BreakpointName) => string;
|
|
18
|
+
/** `(<from> <= width < <to>)` */
|
|
19
|
+
between: (from: BreakpointName, to: BreakpointName) => string;
|
|
15
20
|
};
|
|
16
|
-
|
|
17
|
-
declare const
|
|
18
|
-
export default Breakpoints;
|
|
21
|
+
/** Bare media queries, usable in `window.matchMedia`. Prefix with `@media ` in CSS-in-JS. */
|
|
22
|
+
export declare const media: Media;
|
package/Theme/breakpoints.js
CHANGED
|
@@ -1,39 +1,28 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
xs: 320
|
|
19
|
-
},
|
|
20
|
-
up: function up(breakpoint) {
|
|
21
|
-
var isMedia = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
|
|
22
|
-
return "".concat(isMedia ? "@media " : "", "(min-width: ").concat(this.values[breakpoint], "px)");
|
|
3
|
+
/**
|
|
4
|
+
* Breakpoints shared with the apps that use the kit.
|
|
5
|
+
* The values match the Tailwind CSS defaults on purpose; Tailwind is not a dependency.
|
|
6
|
+
*/
|
|
7
|
+
var BREAKPOINTS = {
|
|
8
|
+
sm: "40rem",
|
|
9
|
+
md: "48rem",
|
|
10
|
+
lg: "64rem",
|
|
11
|
+
xl: "80rem",
|
|
12
|
+
"2xl": "96rem"
|
|
13
|
+
};
|
|
14
|
+
/** Bare media queries, usable in `window.matchMedia`. Prefix with `@media ` in CSS-in-JS. */
|
|
15
|
+
var media = {
|
|
16
|
+
up: function up(name) {
|
|
17
|
+
return "(width >= ".concat(BREAKPOINTS[name], ")");
|
|
23
18
|
},
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
return "".concat(isMedia ? "@media " : "", "(max-width: ").concat(this.values[breakpoint] - 1, "px)");
|
|
19
|
+
down: function down(name) {
|
|
20
|
+
return "(width < ".concat(BREAKPOINTS[name], ")");
|
|
27
21
|
},
|
|
28
|
-
between: function between(
|
|
29
|
-
|
|
30
|
-
min = _ref2[0],
|
|
31
|
-
max = _ref2[1];
|
|
32
|
-
var isMedia = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
|
|
33
|
-
var from = this.values[min];
|
|
34
|
-
var to = this.values[max] - 1;
|
|
35
|
-
return "".concat(isMedia ? "@media " : "", "(min-width: ").concat(from, "px) and (max-width: ").concat(to, "px)");
|
|
22
|
+
between: function between(from, to) {
|
|
23
|
+
return "(".concat(BREAKPOINTS[from], " <= width < ").concat(BREAKPOINTS[to], ")");
|
|
36
24
|
}
|
|
37
25
|
};
|
|
38
26
|
|
|
39
|
-
exports.
|
|
27
|
+
exports.BREAKPOINTS = BREAKPOINTS;
|
|
28
|
+
exports.media = media;
|
package/Theme/index.d.ts
CHANGED
package/Theme/index.js
CHANGED
|
@@ -3,10 +3,13 @@
|
|
|
3
3
|
var tokens = require('../Button/tokens.js');
|
|
4
4
|
var jaipur = require('./themes/jaipur.js');
|
|
5
5
|
var buenos_aires = require('./themes/buenos_aires.js');
|
|
6
|
+
var breakpoints = require('./breakpoints.js');
|
|
6
7
|
|
|
7
8
|
var THEMES = {
|
|
8
9
|
JAIPUR: Object.assign(Object.assign({}, jaipur.default), tokens.BUTTON_TOKENS),
|
|
9
10
|
BA: Object.assign(Object.assign({}, buenos_aires.default), tokens.BUTTON_TOKENS)
|
|
10
11
|
};
|
|
11
12
|
|
|
13
|
+
exports.BREAKPOINTS = breakpoints.BREAKPOINTS;
|
|
14
|
+
exports.media = breakpoints.media;
|
|
12
15
|
exports.THEMES = THEMES;
|
|
@@ -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';
|
package/esm/Modal/index.js
CHANGED
|
@@ -41,7 +41,7 @@ var ModalRoot = function ModalRoot(_ref) {
|
|
|
41
41
|
var parentContainer = withinParent ? parentModal === null || parentModal === void 0 ? void 0 : parentModal.container : undefined;
|
|
42
42
|
var isContained = Boolean(parentContainer);
|
|
43
43
|
var isDesktop = useMediaSizes(function (bp) {
|
|
44
|
-
return bp.up("
|
|
44
|
+
return bp.up("lg");
|
|
45
45
|
});
|
|
46
46
|
var titleId = useId();
|
|
47
47
|
var _useState3 = useState(0),
|
|
@@ -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,18 +1,22 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
sm:
|
|
7
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Breakpoints shared with the apps that use the kit.
|
|
3
|
+
* The values match the Tailwind CSS defaults on purpose; Tailwind is not a dependency.
|
|
4
|
+
*/
|
|
5
|
+
export declare const BREAKPOINTS: {
|
|
6
|
+
readonly sm: "40rem";
|
|
7
|
+
readonly md: "48rem";
|
|
8
|
+
readonly lg: "64rem";
|
|
9
|
+
readonly xl: "80rem";
|
|
10
|
+
readonly "2xl": "96rem";
|
|
8
11
|
};
|
|
9
|
-
export type BreakpointName = keyof
|
|
10
|
-
export type
|
|
11
|
-
|
|
12
|
-
up: (
|
|
13
|
-
|
|
14
|
-
|
|
12
|
+
export type BreakpointName = keyof typeof BREAKPOINTS;
|
|
13
|
+
export type Media = {
|
|
14
|
+
/** `(width >= <name>)` */
|
|
15
|
+
up: (name: BreakpointName) => string;
|
|
16
|
+
/** `(width < <name>)` */
|
|
17
|
+
down: (name: BreakpointName) => string;
|
|
18
|
+
/** `(<from> <= width < <to>)` */
|
|
19
|
+
between: (from: BreakpointName, to: BreakpointName) => string;
|
|
15
20
|
};
|
|
16
|
-
|
|
17
|
-
declare const
|
|
18
|
-
export default Breakpoints;
|
|
21
|
+
/** Bare media queries, usable in `window.matchMedia`. Prefix with `@media ` in CSS-in-JS. */
|
|
22
|
+
export declare const media: Media;
|
package/esm/Theme/breakpoints.js
CHANGED
|
@@ -1,31 +1,25 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Breakpoints shared with the apps that use the kit.
|
|
3
|
+
* The values match the Tailwind CSS defaults on purpose; Tailwind is not a dependency.
|
|
4
|
+
*/
|
|
5
|
+
var BREAKPOINTS = {
|
|
6
|
+
sm: "40rem",
|
|
7
|
+
md: "48rem",
|
|
8
|
+
lg: "64rem",
|
|
9
|
+
xl: "80rem",
|
|
10
|
+
"2xl": "96rem"
|
|
11
|
+
};
|
|
12
|
+
/** Bare media queries, usable in `window.matchMedia`. Prefix with `@media ` in CSS-in-JS. */
|
|
13
|
+
var media = {
|
|
14
|
+
up: function up(name) {
|
|
15
|
+
return "(width >= ".concat(BREAKPOINTS[name], ")");
|
|
15
16
|
},
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
return "".concat(isMedia ? "@media " : "", "(max-width: ").concat(this.values[breakpoint] - 1, "px)");
|
|
17
|
+
down: function down(name) {
|
|
18
|
+
return "(width < ".concat(BREAKPOINTS[name], ")");
|
|
19
19
|
},
|
|
20
|
-
between: function between(
|
|
21
|
-
|
|
22
|
-
min = _ref2[0],
|
|
23
|
-
max = _ref2[1];
|
|
24
|
-
var isMedia = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
|
|
25
|
-
var from = this.values[min];
|
|
26
|
-
var to = this.values[max] - 1;
|
|
27
|
-
return "".concat(isMedia ? "@media " : "", "(min-width: ").concat(from, "px) and (max-width: ").concat(to, "px)");
|
|
20
|
+
between: function between(from, to) {
|
|
21
|
+
return "(".concat(BREAKPOINTS[from], " <= width < ").concat(BREAKPOINTS[to], ")");
|
|
28
22
|
}
|
|
29
23
|
};
|
|
30
24
|
|
|
31
|
-
export {
|
|
25
|
+
export { BREAKPOINTS, media };
|
package/esm/Theme/index.d.ts
CHANGED
package/esm/Theme/index.js
CHANGED
|
@@ -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
|
-
import type {
|
|
2
|
-
export type QueryInputFunction = (breakpoints:
|
|
1
|
+
import type { Media } from "../../Theme/breakpoints";
|
|
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
|
|
2
|
-
import {
|
|
3
|
-
import Breakpoints from '../../Theme/breakpoints.js';
|
|
1
|
+
import { useCallback, useSyncExternalStore } from 'react';
|
|
2
|
+
import { media } from '../../Theme/breakpoints.js';
|
|
4
3
|
|
|
5
|
-
var
|
|
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
|
-
|
|
8
|
-
query =
|
|
9
|
-
var
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
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
|
-
|
|
32
|
-
queryList.removeEventListener("change", updateMatch);
|
|
22
|
+
return queryList.removeEventListener("change", onChange);
|
|
33
23
|
};
|
|
34
|
-
});
|
|
35
|
-
|
|
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 };
|
package/esm/index.d.ts
CHANGED
|
@@ -78,7 +78,8 @@ export { TabsPanels } from "./TabsPanels";
|
|
|
78
78
|
export type { TabsPanelsProps } from "./TabsPanels/index.props";
|
|
79
79
|
export { TextArea } from "./TextArea";
|
|
80
80
|
export type { ITextAreaProps } from "./TextArea/index.props";
|
|
81
|
-
export { THEMES } from "./Theme";
|
|
81
|
+
export { THEMES, BREAKPOINTS, media } from "./Theme";
|
|
82
|
+
export type { BreakpointName, Media } from "./Theme";
|
|
82
83
|
export { TimeSelect } from "./TimeSelect";
|
|
83
84
|
export type { TimeSelectProps } from "./TimeSelect/index.props";
|
|
84
85
|
export { Tooltip } from "./Tooltip";
|
package/esm/index.js
CHANGED
|
@@ -65,6 +65,7 @@ export { Setting } from './Icons/Setting.js';
|
|
|
65
65
|
export { Shield } from './Icons/Shield.js';
|
|
66
66
|
export { Trash } from './Icons/Trash.js';
|
|
67
67
|
export { User } from './Icons/User.js';
|
|
68
|
+
export { BREAKPOINTS, media } from './Theme/breakpoints.js';
|
|
68
69
|
export { Body as ModalBody } from './Modal/components/Body/index.js';
|
|
69
70
|
export { Footer as ModalFooter } from './Modal/components/Footer/index.js';
|
|
70
71
|
export { Header as ModalHeader } from './Modal/components/Header/index.js';
|
|
@@ -1,5 +1,9 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
export type QueryInputFunction = (breakpoints:
|
|
1
|
+
import type { Media } from "../../Theme/breakpoints";
|
|
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
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
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
|
-
|
|
14
|
-
query =
|
|
15
|
-
var
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
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
|
-
|
|
38
|
-
queryList.removeEventListener("change", updateMatch);
|
|
24
|
+
return queryList.removeEventListener("change", onChange);
|
|
39
25
|
};
|
|
40
|
-
});
|
|
41
|
-
|
|
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/index.d.ts
CHANGED
|
@@ -78,7 +78,8 @@ export { TabsPanels } from "./TabsPanels";
|
|
|
78
78
|
export type { TabsPanelsProps } from "./TabsPanels/index.props";
|
|
79
79
|
export { TextArea } from "./TextArea";
|
|
80
80
|
export type { ITextAreaProps } from "./TextArea/index.props";
|
|
81
|
-
export { THEMES } from "./Theme";
|
|
81
|
+
export { THEMES, BREAKPOINTS, media } from "./Theme";
|
|
82
|
+
export type { BreakpointName, Media } from "./Theme";
|
|
82
83
|
export { TimeSelect } from "./TimeSelect";
|
|
83
84
|
export type { TimeSelectProps } from "./TimeSelect/index.props";
|
|
84
85
|
export { Tooltip } from "./Tooltip";
|
package/index.js
CHANGED
|
@@ -49,6 +49,7 @@ var index$B = require('./hooks/useScrollLock/index.js');
|
|
|
49
49
|
require('./Icons/index.js');
|
|
50
50
|
var ArrowNext = require('./Icons/ArrowNext.js');
|
|
51
51
|
var Autocomplete = require('./Autocomplete/Autocomplete.js');
|
|
52
|
+
var breakpoints = require('./Theme/breakpoints.js');
|
|
52
53
|
var Calendar = require('./Calendar/Calendar.js');
|
|
53
54
|
var Card = require('./Card/Card.js');
|
|
54
55
|
var Cart = require('./Icons/Cart.js');
|
|
@@ -124,6 +125,8 @@ exports.useMediaSizes = index$A.useMediaSizes;
|
|
|
124
125
|
exports.useScrollLock = index$B.useScrollLock;
|
|
125
126
|
exports.ArrowNext = ArrowNext.ArrowNext;
|
|
126
127
|
exports.Autocomplete = Autocomplete.Autocomplete;
|
|
128
|
+
exports.BREAKPOINTS = breakpoints.BREAKPOINTS;
|
|
129
|
+
exports.media = breakpoints.media;
|
|
127
130
|
exports.Calendar = Calendar.Calendar;
|
|
128
131
|
exports.Card = Card.Card;
|
|
129
132
|
exports.CardContent = Card.CardContent;
|