@koine/react 1.0.82 → 1.0.84
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/Details/Details.d.ts +2 -1
- package/Dialog/DialogMui.d.ts +2 -1
- package/Dialog/DialogMui.js +1 -1
- package/Dialog/tw/bare.d.ts +6 -6
- package/Dialog/tw/elegant.d.ts +6 -6
- package/Dialog/tw/framer.d.ts +2 -2
- package/Dialog/tw/framerMaterial.d.ts +4 -4
- package/Dialog/tw/material.d.ts +6 -6
- package/Form/Form.d.ts +2 -1
- package/Forms/Checkbox/Checkbox.d.ts +1 -1
- package/Forms/Input/Input.d.ts +1 -1
- package/Forms/Password/Password.d.ts +1 -1
- package/Forms/Radio/Radio.d.ts +1 -1
- package/Forms/Switch/Switch.d.ts +1 -1
- package/Tabs/TabsMui.d.ts +2 -1
- package/Tabs/tw/material.d.ts +6 -6
- package/helpers/index.d.ts +0 -1
- package/hooks/index.d.ts +1 -0
- package/hooks/index.js +1 -0
- package/hooks/useMqWidthCreator.d.ts +3 -0
- package/hooks/useMqWidthCreator.js +225 -0
- package/node/hooks/index.js +1 -0
- package/node/hooks/useMqWidthCreator.js +229 -0
- package/node/styles/media.js +1 -0
- package/package.json +2 -3
- package/styles/media.js +1 -0
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
import { __assign } from "tslib";
|
|
2
|
+
import { useState, useEffect, useMemo } from "react";
|
|
3
|
+
import { isBrowser } from "@koine/utils";
|
|
4
|
+
export function useMqWidthCreator(customBreakpoints) {
|
|
5
|
+
var breakpoints = __assign({ xs: 0 }, customBreakpoints);
|
|
6
|
+
var sortedBreakpointsNames = Object.keys(breakpoints).map(function (key) {
|
|
7
|
+
var br = key;
|
|
8
|
+
return [br, breakpoints[br]];
|
|
9
|
+
})
|
|
10
|
+
.sort(function (a, b) { return a[1] - b[1]; })
|
|
11
|
+
.map(function (item) { return item[0]; });
|
|
12
|
+
var getNextBreakpoint = function (breakpoint) {
|
|
13
|
+
var index = sortedBreakpointsNames.indexOf(breakpoint);
|
|
14
|
+
return sortedBreakpointsNames[index + 1];
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* It behaves the same as `(min-width: ${value}px)`
|
|
18
|
+
* where value is the given breakpoint value.
|
|
19
|
+
* For ease of use this can be used both as a function `min("md")` and as an
|
|
20
|
+
* object literal `min.md`.
|
|
21
|
+
*/
|
|
22
|
+
var min = function (br) { return "(min-width: ".concat(breakpoints[br], "px)"); };
|
|
23
|
+
/**
|
|
24
|
+
* It behaves the same as `(max-width: ${value}px)`
|
|
25
|
+
* where value is the given breakpoint value.
|
|
26
|
+
* For ease of use this can be used both as a function `max("md")` and as an
|
|
27
|
+
* object literal `max.md`.
|
|
28
|
+
*/
|
|
29
|
+
var max = function (br) { return "(max-width: ".concat(breakpoints[br] - 0.02, "px)"); };
|
|
30
|
+
/**
|
|
31
|
+
* It behaves the same as `min`
|
|
32
|
+
* @inheritdoc {max}
|
|
33
|
+
*/
|
|
34
|
+
var up = min;
|
|
35
|
+
/**
|
|
36
|
+
* It behaves similarly to `max` but you will use the "next" breakpoint,
|
|
37
|
+
* specifying CSS that will apply from the given breakpoint and down.
|
|
38
|
+
*/
|
|
39
|
+
var down = function (br) {
|
|
40
|
+
var brNext = getNextBreakpoint(br);
|
|
41
|
+
// TODO: if br does not exists otherwise throw Error
|
|
42
|
+
return brNext && "(max-width: ".concat(breakpoints[brNext] - 0.02, "px)");
|
|
43
|
+
};
|
|
44
|
+
/**
|
|
45
|
+
* Media query between the two given breakpoints
|
|
46
|
+
*/
|
|
47
|
+
var between = function (br1, br2) {
|
|
48
|
+
return br2
|
|
49
|
+
? "(min-width: ".concat(breakpoints[br1], "px) and (max-width: ").concat(breakpoints[br2] - 0.02, "px)")
|
|
50
|
+
: min(br1);
|
|
51
|
+
};
|
|
52
|
+
/**
|
|
53
|
+
* Media query to apply from the given breakpoint until the next, just for its
|
|
54
|
+
* full range
|
|
55
|
+
*/
|
|
56
|
+
var only = function (br) {
|
|
57
|
+
var brNext = getNextBreakpoint(br);
|
|
58
|
+
return brNext ? between(br, brNext) : min(br);
|
|
59
|
+
};
|
|
60
|
+
var queryResolvers = {
|
|
61
|
+
max: max,
|
|
62
|
+
min: min,
|
|
63
|
+
down: down,
|
|
64
|
+
up: up,
|
|
65
|
+
between: between,
|
|
66
|
+
only: only,
|
|
67
|
+
};
|
|
68
|
+
return function useMqWidth(media) {
|
|
69
|
+
var _a = media.split(":"), _b = _a[0], rule = _b === void 0 ? "min" : _b, ruleBreakpoint = _a[1];
|
|
70
|
+
// with the hook creator approach these breakpoint types cannot be deduced
|
|
71
|
+
// const [br1, br2] = ruleBreakpoint.split("-") as Split<
|
|
72
|
+
// typeof ruleBreakpoint,
|
|
73
|
+
// "-"
|
|
74
|
+
// >;
|
|
75
|
+
var _c = ruleBreakpoint.split("-"), br1 = _c[0], br2 = _c[1];
|
|
76
|
+
var query = queryResolvers[rule](br1, br2);
|
|
77
|
+
var mq = useMemo(function () { return (isBrowser ? window.matchMedia(query) : { matches: false }); }, [query]);
|
|
78
|
+
var _d = useState(mq.matches), matches = _d[0], setMatches = _d[1];
|
|
79
|
+
useEffect(function () {
|
|
80
|
+
var mq = window.matchMedia(query);
|
|
81
|
+
var handleChange = function (event) {
|
|
82
|
+
setMatches(event.matches);
|
|
83
|
+
};
|
|
84
|
+
setMatches(mq.matches);
|
|
85
|
+
// Safari < 14 can't use addEventListener on a MediaQueryList
|
|
86
|
+
// https://developer.mozilla.org/en-US/docs/Web/API/MediaQueryList#Browser_compatibility
|
|
87
|
+
if (!mq.addEventListener) {
|
|
88
|
+
// Update the state whenever the media query match state changes
|
|
89
|
+
mq.addListener(handleChange);
|
|
90
|
+
// Clean up on unmount and if the query changes
|
|
91
|
+
return function () {
|
|
92
|
+
mq.removeListener(handleChange);
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
mq.addEventListener("change", handleChange);
|
|
96
|
+
return function () {
|
|
97
|
+
mq.removeEventListener("change", handleChange);
|
|
98
|
+
};
|
|
99
|
+
}, [query]);
|
|
100
|
+
return matches;
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
export default useMqWidthCreator;
|
|
104
|
+
//// without creator it would be:
|
|
105
|
+
//// ---------------------------------------------------------------------------
|
|
106
|
+
// import { useState, useEffect, useMemo } from "react";
|
|
107
|
+
// import { isBrowser, type Split } from "@koine/utils";
|
|
108
|
+
// import { breakpoints as themeBreakpoints } from "@/config/theme/breakpoints";
|
|
109
|
+
// type Breakpoint = "xs" | "sm" | "md" | "lg" | "xl";
|
|
110
|
+
// type Breakpoints = Record<Breakpoint, number>;
|
|
111
|
+
// type MediaQuery =
|
|
112
|
+
// | `max:${Breakpoint}`
|
|
113
|
+
// | `min:${Breakpoint}`
|
|
114
|
+
// | `down:${Breakpoint}`
|
|
115
|
+
// | `up:${Breakpoint}`
|
|
116
|
+
// | `between:${Breakpoint}-${Breakpoint}`
|
|
117
|
+
// | `only:${Breakpoint}`;
|
|
118
|
+
// const breakpoints: Breakpoints = {
|
|
119
|
+
// xs: 0,
|
|
120
|
+
// ...themeBreakpoints,
|
|
121
|
+
// };
|
|
122
|
+
// const sortedBreakpointsNames = (
|
|
123
|
+
// Object.keys(breakpoints).map((key) => {
|
|
124
|
+
// const br = key as keyof typeof breakpoints;
|
|
125
|
+
// return [br, breakpoints[br]];
|
|
126
|
+
// }) as [Breakpoint, number][]
|
|
127
|
+
// )
|
|
128
|
+
// .sort((a, b) => a[1] - b[1])
|
|
129
|
+
// .map((item) => item[0]);
|
|
130
|
+
// const getNextBreakpoint = (breakpoint: Breakpoint) => {
|
|
131
|
+
// const index = sortedBreakpointsNames.indexOf(breakpoint);
|
|
132
|
+
// return sortedBreakpointsNames[index + 1];
|
|
133
|
+
// };
|
|
134
|
+
// /**
|
|
135
|
+
// * It behaves the same as `(min-width: ${value}px)`
|
|
136
|
+
// * where value is the given breakpoint value.
|
|
137
|
+
// * For ease of use this can be used both as a function `min("md")` and as an
|
|
138
|
+
// * object literal `min.md`.
|
|
139
|
+
// */
|
|
140
|
+
// const min = (br: Breakpoint) => `(min-width: ${breakpoints[br]}px)`;
|
|
141
|
+
// /**
|
|
142
|
+
// * It behaves the same as `(max-width: ${value}px)`
|
|
143
|
+
// * where value is the given breakpoint value.
|
|
144
|
+
// * For ease of use this can be used both as a function `max("md")` and as an
|
|
145
|
+
// * object literal `max.md`.
|
|
146
|
+
// */
|
|
147
|
+
// const max = (br: Breakpoint) => `(max-width: ${breakpoints[br] - 0.02}px)`;
|
|
148
|
+
// /**
|
|
149
|
+
// * It behaves the same as `min`
|
|
150
|
+
// * @inheritdoc {max}
|
|
151
|
+
// */
|
|
152
|
+
// const up = min;
|
|
153
|
+
// /**
|
|
154
|
+
// * It behaves similarly to `max` but you will use the "next" breakpoint,
|
|
155
|
+
// * specifying CSS that will apply from the given breakpoint and down.
|
|
156
|
+
// */
|
|
157
|
+
// const down = (br: Breakpoint) => {
|
|
158
|
+
// const brNext = getNextBreakpoint(br);
|
|
159
|
+
// // TODO: if br does not exists otherwise throw Error
|
|
160
|
+
// return brNext && `(max-width: ${breakpoints[brNext] - 0.02}px)`;
|
|
161
|
+
// };
|
|
162
|
+
// /**
|
|
163
|
+
// * Media query between the two given breakpoints
|
|
164
|
+
// */
|
|
165
|
+
// const between = (br1: Breakpoint, br2?: Breakpoint) => {
|
|
166
|
+
// return br2
|
|
167
|
+
// ? `(min-width: ${breakpoints[br1]}px) and (max-width: ${
|
|
168
|
+
// breakpoints[br2] - 0.02
|
|
169
|
+
// }px)`
|
|
170
|
+
// : min(br1);
|
|
171
|
+
// };
|
|
172
|
+
// /**
|
|
173
|
+
// * Media query to apply from the given breakpoint until the next, just for its
|
|
174
|
+
// * full range
|
|
175
|
+
// */
|
|
176
|
+
// const only = (br: Breakpoint) => {
|
|
177
|
+
// const brNext = getNextBreakpoint(br);
|
|
178
|
+
// return brNext ? between(br, brNext) : min(br);
|
|
179
|
+
// };
|
|
180
|
+
// const queryResolvers = {
|
|
181
|
+
// max,
|
|
182
|
+
// min,
|
|
183
|
+
// down,
|
|
184
|
+
// up,
|
|
185
|
+
// between,
|
|
186
|
+
// only,
|
|
187
|
+
// };
|
|
188
|
+
// export function useMqWidth(media: MediaQuery) {
|
|
189
|
+
// const [rule = "min", ruleBreakpoint] = media.split(":") as Split<
|
|
190
|
+
// MediaQuery,
|
|
191
|
+
// ":"
|
|
192
|
+
// >;
|
|
193
|
+
// const [br1, br2] = ruleBreakpoint.split("-") as Split<
|
|
194
|
+
// typeof ruleBreakpoint,
|
|
195
|
+
// "-"
|
|
196
|
+
// >;
|
|
197
|
+
// const query = queryResolvers[rule](br1, br2);
|
|
198
|
+
// const mq = useMemo(
|
|
199
|
+
// () => (isBrowser ? window.matchMedia(query) : { matches: false }),
|
|
200
|
+
// [query]
|
|
201
|
+
// );
|
|
202
|
+
// const [matches, setMatches] = useState(mq.matches);
|
|
203
|
+
// useEffect(() => {
|
|
204
|
+
// const mq = window.matchMedia(query);
|
|
205
|
+
// const handleChange = (event: MediaQueryListEvent) => {
|
|
206
|
+
// setMatches(event.matches);
|
|
207
|
+
// };
|
|
208
|
+
// setMatches(mq.matches);
|
|
209
|
+
// // Safari < 14 can't use addEventListener on a MediaQueryList
|
|
210
|
+
// // https://developer.mozilla.org/en-US/docs/Web/API/MediaQueryList#Browser_compatibility
|
|
211
|
+
// if (!mq.addEventListener) {
|
|
212
|
+
// // Update the state whenever the media query match state changes
|
|
213
|
+
// mq.addListener(handleChange);
|
|
214
|
+
// // Clean up on unmount and if the query changes
|
|
215
|
+
// return () => {
|
|
216
|
+
// mq.removeListener(handleChange);
|
|
217
|
+
// };
|
|
218
|
+
// }
|
|
219
|
+
// mq.addEventListener("change", handleChange);
|
|
220
|
+
// return () => {
|
|
221
|
+
// mq.removeEventListener("change", handleChange);
|
|
222
|
+
// };
|
|
223
|
+
// }, [query]);
|
|
224
|
+
// return matches;
|
|
225
|
+
// }
|
package/node/hooks/index.js
CHANGED
|
@@ -10,6 +10,7 @@ tslib_1.__exportStar(require("./useId"), exports);
|
|
|
10
10
|
tslib_1.__exportStar(require("./useIsomorphicLayoutEffect"), exports);
|
|
11
11
|
tslib_1.__exportStar(require("./useMount"), exports);
|
|
12
12
|
tslib_1.__exportStar(require("./useMountedState"), exports);
|
|
13
|
+
tslib_1.__exportStar(require("./useMqWidthCreator"), exports);
|
|
13
14
|
tslib_1.__exportStar(require("./usePrevious"), exports);
|
|
14
15
|
tslib_1.__exportStar(require("./useScrollPosition"), exports);
|
|
15
16
|
// export * from "./useScrollTo";
|
|
@@ -0,0 +1,229 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useMqWidthCreator = void 0;
|
|
4
|
+
var tslib_1 = require("tslib");
|
|
5
|
+
var react_1 = require("react");
|
|
6
|
+
var utils_1 = require("@koine/utils");
|
|
7
|
+
function useMqWidthCreator(customBreakpoints) {
|
|
8
|
+
var breakpoints = tslib_1.__assign({ xs: 0 }, customBreakpoints);
|
|
9
|
+
var sortedBreakpointsNames = Object.keys(breakpoints).map(function (key) {
|
|
10
|
+
var br = key;
|
|
11
|
+
return [br, breakpoints[br]];
|
|
12
|
+
})
|
|
13
|
+
.sort(function (a, b) { return a[1] - b[1]; })
|
|
14
|
+
.map(function (item) { return item[0]; });
|
|
15
|
+
var getNextBreakpoint = function (breakpoint) {
|
|
16
|
+
var index = sortedBreakpointsNames.indexOf(breakpoint);
|
|
17
|
+
return sortedBreakpointsNames[index + 1];
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* It behaves the same as `(min-width: ${value}px)`
|
|
21
|
+
* where value is the given breakpoint value.
|
|
22
|
+
* For ease of use this can be used both as a function `min("md")` and as an
|
|
23
|
+
* object literal `min.md`.
|
|
24
|
+
*/
|
|
25
|
+
var min = function (br) { return "(min-width: ".concat(breakpoints[br], "px)"); };
|
|
26
|
+
/**
|
|
27
|
+
* It behaves the same as `(max-width: ${value}px)`
|
|
28
|
+
* where value is the given breakpoint value.
|
|
29
|
+
* For ease of use this can be used both as a function `max("md")` and as an
|
|
30
|
+
* object literal `max.md`.
|
|
31
|
+
*/
|
|
32
|
+
var max = function (br) { return "(max-width: ".concat(breakpoints[br] - 0.02, "px)"); };
|
|
33
|
+
/**
|
|
34
|
+
* It behaves the same as `min`
|
|
35
|
+
* @inheritdoc {max}
|
|
36
|
+
*/
|
|
37
|
+
var up = min;
|
|
38
|
+
/**
|
|
39
|
+
* It behaves similarly to `max` but you will use the "next" breakpoint,
|
|
40
|
+
* specifying CSS that will apply from the given breakpoint and down.
|
|
41
|
+
*/
|
|
42
|
+
var down = function (br) {
|
|
43
|
+
var brNext = getNextBreakpoint(br);
|
|
44
|
+
// TODO: if br does not exists otherwise throw Error
|
|
45
|
+
return brNext && "(max-width: ".concat(breakpoints[brNext] - 0.02, "px)");
|
|
46
|
+
};
|
|
47
|
+
/**
|
|
48
|
+
* Media query between the two given breakpoints
|
|
49
|
+
*/
|
|
50
|
+
var between = function (br1, br2) {
|
|
51
|
+
return br2
|
|
52
|
+
? "(min-width: ".concat(breakpoints[br1], "px) and (max-width: ").concat(breakpoints[br2] - 0.02, "px)")
|
|
53
|
+
: min(br1);
|
|
54
|
+
};
|
|
55
|
+
/**
|
|
56
|
+
* Media query to apply from the given breakpoint until the next, just for its
|
|
57
|
+
* full range
|
|
58
|
+
*/
|
|
59
|
+
var only = function (br) {
|
|
60
|
+
var brNext = getNextBreakpoint(br);
|
|
61
|
+
return brNext ? between(br, brNext) : min(br);
|
|
62
|
+
};
|
|
63
|
+
var queryResolvers = {
|
|
64
|
+
max: max,
|
|
65
|
+
min: min,
|
|
66
|
+
down: down,
|
|
67
|
+
up: up,
|
|
68
|
+
between: between,
|
|
69
|
+
only: only,
|
|
70
|
+
};
|
|
71
|
+
return function useMqWidth(media) {
|
|
72
|
+
var _a = media.split(":"), _b = _a[0], rule = _b === void 0 ? "min" : _b, ruleBreakpoint = _a[1];
|
|
73
|
+
// with the hook creator approach these breakpoint types cannot be deduced
|
|
74
|
+
// const [br1, br2] = ruleBreakpoint.split("-") as Split<
|
|
75
|
+
// typeof ruleBreakpoint,
|
|
76
|
+
// "-"
|
|
77
|
+
// >;
|
|
78
|
+
var _c = ruleBreakpoint.split("-"), br1 = _c[0], br2 = _c[1];
|
|
79
|
+
var query = queryResolvers[rule](br1, br2);
|
|
80
|
+
var mq = (0, react_1.useMemo)(function () { return (utils_1.isBrowser ? window.matchMedia(query) : { matches: false }); }, [query]);
|
|
81
|
+
var _d = (0, react_1.useState)(mq.matches), matches = _d[0], setMatches = _d[1];
|
|
82
|
+
(0, react_1.useEffect)(function () {
|
|
83
|
+
var mq = window.matchMedia(query);
|
|
84
|
+
var handleChange = function (event) {
|
|
85
|
+
setMatches(event.matches);
|
|
86
|
+
};
|
|
87
|
+
setMatches(mq.matches);
|
|
88
|
+
// Safari < 14 can't use addEventListener on a MediaQueryList
|
|
89
|
+
// https://developer.mozilla.org/en-US/docs/Web/API/MediaQueryList#Browser_compatibility
|
|
90
|
+
if (!mq.addEventListener) {
|
|
91
|
+
// Update the state whenever the media query match state changes
|
|
92
|
+
mq.addListener(handleChange);
|
|
93
|
+
// Clean up on unmount and if the query changes
|
|
94
|
+
return function () {
|
|
95
|
+
mq.removeListener(handleChange);
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
mq.addEventListener("change", handleChange);
|
|
99
|
+
return function () {
|
|
100
|
+
mq.removeEventListener("change", handleChange);
|
|
101
|
+
};
|
|
102
|
+
}, [query]);
|
|
103
|
+
return matches;
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
exports.useMqWidthCreator = useMqWidthCreator;
|
|
107
|
+
exports.default = useMqWidthCreator;
|
|
108
|
+
//// without creator it would be:
|
|
109
|
+
//// ---------------------------------------------------------------------------
|
|
110
|
+
// import { useState, useEffect, useMemo } from "react";
|
|
111
|
+
// import { isBrowser, type Split } from "@koine/utils";
|
|
112
|
+
// import { breakpoints as themeBreakpoints } from "@/config/theme/breakpoints";
|
|
113
|
+
// type Breakpoint = "xs" | "sm" | "md" | "lg" | "xl";
|
|
114
|
+
// type Breakpoints = Record<Breakpoint, number>;
|
|
115
|
+
// type MediaQuery =
|
|
116
|
+
// | `max:${Breakpoint}`
|
|
117
|
+
// | `min:${Breakpoint}`
|
|
118
|
+
// | `down:${Breakpoint}`
|
|
119
|
+
// | `up:${Breakpoint}`
|
|
120
|
+
// | `between:${Breakpoint}-${Breakpoint}`
|
|
121
|
+
// | `only:${Breakpoint}`;
|
|
122
|
+
// const breakpoints: Breakpoints = {
|
|
123
|
+
// xs: 0,
|
|
124
|
+
// ...themeBreakpoints,
|
|
125
|
+
// };
|
|
126
|
+
// const sortedBreakpointsNames = (
|
|
127
|
+
// Object.keys(breakpoints).map((key) => {
|
|
128
|
+
// const br = key as keyof typeof breakpoints;
|
|
129
|
+
// return [br, breakpoints[br]];
|
|
130
|
+
// }) as [Breakpoint, number][]
|
|
131
|
+
// )
|
|
132
|
+
// .sort((a, b) => a[1] - b[1])
|
|
133
|
+
// .map((item) => item[0]);
|
|
134
|
+
// const getNextBreakpoint = (breakpoint: Breakpoint) => {
|
|
135
|
+
// const index = sortedBreakpointsNames.indexOf(breakpoint);
|
|
136
|
+
// return sortedBreakpointsNames[index + 1];
|
|
137
|
+
// };
|
|
138
|
+
// /**
|
|
139
|
+
// * It behaves the same as `(min-width: ${value}px)`
|
|
140
|
+
// * where value is the given breakpoint value.
|
|
141
|
+
// * For ease of use this can be used both as a function `min("md")` and as an
|
|
142
|
+
// * object literal `min.md`.
|
|
143
|
+
// */
|
|
144
|
+
// const min = (br: Breakpoint) => `(min-width: ${breakpoints[br]}px)`;
|
|
145
|
+
// /**
|
|
146
|
+
// * It behaves the same as `(max-width: ${value}px)`
|
|
147
|
+
// * where value is the given breakpoint value.
|
|
148
|
+
// * For ease of use this can be used both as a function `max("md")` and as an
|
|
149
|
+
// * object literal `max.md`.
|
|
150
|
+
// */
|
|
151
|
+
// const max = (br: Breakpoint) => `(max-width: ${breakpoints[br] - 0.02}px)`;
|
|
152
|
+
// /**
|
|
153
|
+
// * It behaves the same as `min`
|
|
154
|
+
// * @inheritdoc {max}
|
|
155
|
+
// */
|
|
156
|
+
// const up = min;
|
|
157
|
+
// /**
|
|
158
|
+
// * It behaves similarly to `max` but you will use the "next" breakpoint,
|
|
159
|
+
// * specifying CSS that will apply from the given breakpoint and down.
|
|
160
|
+
// */
|
|
161
|
+
// const down = (br: Breakpoint) => {
|
|
162
|
+
// const brNext = getNextBreakpoint(br);
|
|
163
|
+
// // TODO: if br does not exists otherwise throw Error
|
|
164
|
+
// return brNext && `(max-width: ${breakpoints[brNext] - 0.02}px)`;
|
|
165
|
+
// };
|
|
166
|
+
// /**
|
|
167
|
+
// * Media query between the two given breakpoints
|
|
168
|
+
// */
|
|
169
|
+
// const between = (br1: Breakpoint, br2?: Breakpoint) => {
|
|
170
|
+
// return br2
|
|
171
|
+
// ? `(min-width: ${breakpoints[br1]}px) and (max-width: ${
|
|
172
|
+
// breakpoints[br2] - 0.02
|
|
173
|
+
// }px)`
|
|
174
|
+
// : min(br1);
|
|
175
|
+
// };
|
|
176
|
+
// /**
|
|
177
|
+
// * Media query to apply from the given breakpoint until the next, just for its
|
|
178
|
+
// * full range
|
|
179
|
+
// */
|
|
180
|
+
// const only = (br: Breakpoint) => {
|
|
181
|
+
// const brNext = getNextBreakpoint(br);
|
|
182
|
+
// return brNext ? between(br, brNext) : min(br);
|
|
183
|
+
// };
|
|
184
|
+
// const queryResolvers = {
|
|
185
|
+
// max,
|
|
186
|
+
// min,
|
|
187
|
+
// down,
|
|
188
|
+
// up,
|
|
189
|
+
// between,
|
|
190
|
+
// only,
|
|
191
|
+
// };
|
|
192
|
+
// export function useMqWidth(media: MediaQuery) {
|
|
193
|
+
// const [rule = "min", ruleBreakpoint] = media.split(":") as Split<
|
|
194
|
+
// MediaQuery,
|
|
195
|
+
// ":"
|
|
196
|
+
// >;
|
|
197
|
+
// const [br1, br2] = ruleBreakpoint.split("-") as Split<
|
|
198
|
+
// typeof ruleBreakpoint,
|
|
199
|
+
// "-"
|
|
200
|
+
// >;
|
|
201
|
+
// const query = queryResolvers[rule](br1, br2);
|
|
202
|
+
// const mq = useMemo(
|
|
203
|
+
// () => (isBrowser ? window.matchMedia(query) : { matches: false }),
|
|
204
|
+
// [query]
|
|
205
|
+
// );
|
|
206
|
+
// const [matches, setMatches] = useState(mq.matches);
|
|
207
|
+
// useEffect(() => {
|
|
208
|
+
// const mq = window.matchMedia(query);
|
|
209
|
+
// const handleChange = (event: MediaQueryListEvent) => {
|
|
210
|
+
// setMatches(event.matches);
|
|
211
|
+
// };
|
|
212
|
+
// setMatches(mq.matches);
|
|
213
|
+
// // Safari < 14 can't use addEventListener on a MediaQueryList
|
|
214
|
+
// // https://developer.mozilla.org/en-US/docs/Web/API/MediaQueryList#Browser_compatibility
|
|
215
|
+
// if (!mq.addEventListener) {
|
|
216
|
+
// // Update the state whenever the media query match state changes
|
|
217
|
+
// mq.addListener(handleChange);
|
|
218
|
+
// // Clean up on unmount and if the query changes
|
|
219
|
+
// return () => {
|
|
220
|
+
// mq.removeListener(handleChange);
|
|
221
|
+
// };
|
|
222
|
+
// }
|
|
223
|
+
// mq.addEventListener("change", handleChange);
|
|
224
|
+
// return () => {
|
|
225
|
+
// mq.removeEventListener("change", handleChange);
|
|
226
|
+
// };
|
|
227
|
+
// }, [query]);
|
|
228
|
+
// return matches;
|
|
229
|
+
// }
|
package/node/styles/media.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
/// TODO:FIXME: this should use code from `useMqWidthCreator`
|
|
2
3
|
var _a;
|
|
3
4
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
5
|
exports.generateMediaQueries = exports.useMedia = exports.only = exports.between = exports.down = exports.up = exports.max = exports.min = void 0;
|
package/package.json
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
"framer-motion": "^7.2.1",
|
|
9
9
|
"react": "^18.2.0",
|
|
10
10
|
"@mui/base": "^5.0.0-alpha.95",
|
|
11
|
-
"@koine/utils": "1.0.
|
|
11
|
+
"@koine/utils": "1.0.84",
|
|
12
12
|
"ts-debounce": "^4.0.0",
|
|
13
13
|
"date-fns-tz": "^1.3.7",
|
|
14
14
|
"react-icons": "^4.4.0",
|
|
@@ -18,12 +18,11 @@
|
|
|
18
18
|
"@tiptap/starter-kit": "^2.0.0-beta.192",
|
|
19
19
|
"@kuus/yup": "^1.0.0-beta.4",
|
|
20
20
|
"react-hook-form": "^7.34.2",
|
|
21
|
-
"type-fest": "^2.19.0",
|
|
22
21
|
"react-popper": "^2.3.0",
|
|
23
22
|
"tslib": "^2.4.0"
|
|
24
23
|
},
|
|
25
24
|
"peerDependencies": {},
|
|
26
|
-
"version": "1.0.
|
|
25
|
+
"version": "1.0.84",
|
|
27
26
|
"module": "./index.js",
|
|
28
27
|
"types": "./index.d.ts"
|
|
29
28
|
}
|
package/styles/media.js
CHANGED