@koine/react 1.0.105 → 1.1.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/Alert/Alert.d.ts +1 -1
- package/Animations/Reveal.d.ts +1 -1
- package/Animations/useReveal.d.ts +1 -1
- package/Autocomplete/AutocompleteMui.d.ts +4 -4
- package/Autocomplete/helpers.d.ts +1 -1
- package/Bg/BgColor.d.ts +1 -1
- package/Bg/BgPhoto.d.ts +2 -2
- package/Bg/BgSvg.d.ts +1 -1
- package/Breadcrumbs/Breadcrumbs.d.ts +3 -3
- package/Buttons/Button.d.ts +2 -2
- package/Buttons/ButtonComposite.d.ts +3 -3
- package/Buttons/ButtonFab.d.ts +1 -1
- package/Buttons/ButtonLink.d.ts +2 -2
- package/Buttons/IconButton.d.ts +2 -2
- package/Calendar/CalendarDaygridCell.d.ts +6 -6
- package/Calendar/CalendarDaygridNav.d.ts +3 -3
- package/Calendar/CalendarDaygridTable.d.ts +4 -4
- package/Calendar/CalendarLegend.d.ts +3 -3
- package/Calendar/calendar-api-google.d.ts +1 -1
- package/Calendar/types.d.ts +13 -13
- package/Calendar/useCalendar.d.ts +5 -5
- package/Carousel/CarouselCss.d.ts +2 -2
- package/Collapsable/CollapsableReach.js +1 -2
- package/Debug/Debug.d.ts +1 -1
- package/Details/Details.d.ts +6 -6
- package/Dialog/DialogMui.d.ts +8 -8
- package/Dialog/DialogMui.js +1 -1
- package/Dialog/css/bare.d.ts +1 -1
- package/Dialog/m/bare.d.ts +1 -1
- package/Dialog/m/bare.js +1 -1
- package/Dialog/sc/bare.d.ts +1 -1
- package/Dialog/sc/framer.d.ts +1 -1
- package/Dialog/sc/framerMaterial.d.ts +1 -1
- package/Dialog/sc/material.d.ts +1 -1
- package/Dialog/tw/bare.d.ts +7 -7
- package/Dialog/tw/elegant.d.ts +7 -7
- package/Dialog/tw/framer.d.ts +3 -3
- package/Dialog/tw/framerMaterial.d.ts +5 -5
- package/Dialog/tw/material.d.ts +7 -7
- package/Editor/Editor--tiptap.d.ts +2 -2
- package/Favicon/FaviconTags.d.ts +1 -1
- package/Favicon/FaviconTags.js +1 -1
- package/Form/Form.d.ts +7 -7
- package/Forms/Checkbox/Checkbox.d.ts +2 -2
- package/Forms/Feedback/Feedback.d.ts +1 -1
- package/Forms/Field/Field.d.ts +3 -3
- package/Forms/Field/FieldControl.d.ts +2 -2
- package/Forms/Input/Input.d.ts +2 -2
- package/Forms/InputGroup/InputGroup.d.ts +1 -1
- package/Forms/Password/Password.d.ts +2 -2
- package/Forms/Radio/Radio.d.ts +3 -3
- package/Forms/Switch/Switch.d.ts +2 -2
- package/Forms/Textarea/Textarea.d.ts +2 -2
- package/Forms/Textarea/TextareaRich.d.ts +2 -2
- package/Forms/Toggle/Toggle.d.ts +3 -3
- package/Forms/Toggle/useToggle.d.ts +1 -1
- package/Forms/antispam.d.ts +18 -1
- package/Forms/helpers.d.ts +5 -5
- package/Gauge/Gauge.d.ts +1 -1
- package/Grid/Grid.d.ts +6 -6
- package/Hamburger/Hamburger.d.ts +1 -1
- package/Header/useHeader.d.ts +5 -5
- package/Hidden/Hidden.d.ts +1 -1
- package/Img/sc/bare.d.ts +1 -1
- package/Img/types.d.ts +2 -2
- package/Link/Link.d.ts +1 -1
- package/Link/LinkBlank.d.ts +1 -1
- package/Menu/MenuMui.d.ts +5 -5
- package/Menu/MenuMui.js +1 -1
- package/MenuItem/MenuItemMui.d.ts +1 -1
- package/Meta/Meta.d.ts +1 -1
- package/NoJs/NoJs.d.ts +1 -1
- package/Pagination/PaginationNav.d.ts +2 -2
- package/Pagination/PaginationResults.d.ts +1 -1
- package/Pill/Pill.d.ts +1 -1
- package/Progress/ProgressCircular.d.ts +1 -1
- package/Progress/ProgressLinear.d.ts +1 -1
- package/Progress/ProgressOverlay.d.ts +1 -1
- package/Rating/Rating.d.ts +3 -3
- package/Select/SelectDownshift.d.ts +1 -1
- package/Select/components.d.ts +1 -1
- package/Sidebar/Sidebar.d.ts +1 -1
- package/Spacing/Spacing.d.ts +6 -6
- package/Sticky/Sticky.d.ts +1 -1
- package/Sticky/StickyCss.d.ts +1 -1
- package/Tabs/TabsMui.d.ts +11 -11
- package/Tabs/TabsMui.js +1 -1
- package/Tabs/tw/bare.d.ts +4 -4
- package/Tabs/tw/material.d.ts +10 -10
- package/Typography/ReadMore.d.ts +1 -1
- package/Typography/TextLoop.d.ts +2 -2
- package/Typography/TypeStairs.d.ts +1 -1
- package/helpers/classed.d.ts +3 -3
- package/helpers/classed.js +1 -0
- package/helpers/createUseMediaQueryWidth.d.ts +3 -3
- package/helpers/extend-component.d.ts +4 -4
- package/helpers/extend-component.js +1 -0
- package/hooks/index.d.ts +4 -1
- package/hooks/index.js +4 -1
- package/hooks/types.d.ts +2 -2
- package/hooks/useAsyncFn.d.ts +4 -4
- package/hooks/useAsyncFn.js +1 -0
- package/hooks/useDateLocale.d.ts +1 -0
- package/hooks/useDateLocale.js +1 -0
- package/hooks/useEffectOnce.d.ts +1 -0
- package/hooks/useEffectOnce.js +1 -0
- package/hooks/useFirstMountState.d.ts +1 -0
- package/hooks/useFirstMountState.js +1 -0
- package/hooks/useFocus.d.ts +1 -0
- package/hooks/useFocus.js +1 -0
- package/hooks/useId.d.ts +1 -0
- package/hooks/useId.js +1 -0
- package/hooks/useInterval.d.ts +7 -0
- package/hooks/useInterval.js +28 -0
- package/hooks/useIsomorphicLayoutEffect.d.ts +1 -0
- package/hooks/useIsomorphicLayoutEffect.js +1 -0
- package/hooks/useKeyUp.d.ts +2 -0
- package/hooks/useKeyUp.js +23 -0
- package/hooks/useMeasure.d.ts +3 -3
- package/hooks/useMount.d.ts +1 -0
- package/hooks/useMount.js +1 -0
- package/hooks/useMountedState.d.ts +1 -0
- package/hooks/useMountedState.js +1 -0
- package/hooks/useNavigateAway.d.ts +32 -0
- package/hooks/useNavigateAway.js +68 -0
- package/hooks/usePrevious.d.ts +5 -1
- package/hooks/usePrevious.js +11 -7
- package/hooks/usePreviousRef.d.ts +2 -0
- package/hooks/usePreviousRef.js +9 -0
- package/hooks/useScrollPosition.d.ts +3 -3
- package/hooks/useScrollPosition.js +1 -0
- package/hooks/useScrollTo.d.ts +1 -0
- package/hooks/useScrollTo.js +1 -0
- package/hooks/useTraceUpdate.d.ts +1 -0
- package/hooks/useTraceUpdate.js +1 -0
- package/hooks/useUpdateEffect.d.ts +1 -0
- package/hooks/useUpdateEffect.js +1 -0
- package/hooks/useWindowSize.d.ts +1 -0
- package/hooks/useWindowSize.js +4 -2
- package/m/MotionProvider.d.ts +2 -2
- package/node/Collapsable/CollapsableReach.js +1 -2
- package/node/Dialog/DialogMui.js +1 -1
- package/node/Dialog/m/bare.js +1 -1
- package/node/Favicon/FaviconTags.js +1 -1
- package/node/Menu/MenuMui.js +1 -1
- package/node/Tabs/TabsMui.js +1 -1
- package/node/helpers/classed.js +1 -0
- package/node/helpers/extend-component.js +1 -0
- package/node/hooks/index.js +4 -1
- package/node/hooks/useAsyncFn.js +1 -0
- package/node/hooks/useDateLocale.js +4 -2
- package/node/hooks/useEffectOnce.js +1 -0
- package/node/hooks/useFirstMountState.js +1 -0
- package/node/hooks/useFocus.js +1 -0
- package/node/hooks/useInterval.js +32 -0
- package/node/hooks/useIsomorphicLayoutEffect.js +1 -0
- package/node/hooks/useKeyUp.js +27 -0
- package/node/hooks/useMount.js +1 -0
- package/node/hooks/useMountedState.js +1 -0
- package/node/hooks/useNavigateAway.js +72 -0
- package/node/hooks/usePrevious.js +10 -6
- package/node/hooks/usePreviousRef.js +13 -0
- package/node/hooks/useScrollPosition.js +1 -0
- package/node/hooks/useScrollTo.js +1 -0
- package/node/hooks/useTraceUpdate.js +1 -0
- package/node/hooks/useUpdateEffect.js +1 -0
- package/node/hooks/useWindowSize.js +4 -2
- package/package.json +35 -23
- package/styles/media.d.ts +3 -3
- package/styles/spacing.d.ts +7 -7
- package/styles/theme--vanilla.d.ts +4 -4
- package/styles/theme.d.ts +4 -4
- package/types.d.ts +4 -4
- package/hooks/useMediaQueryWidthCreator.d.ts +0 -6
- package/hooks/useMediaQueryWidthCreator.js +0 -169
- package/hooks/useMqWidthCreator.d.ts +0 -3
- package/hooks/useMqWidthCreator.js +0 -225
- package/node/hooks/useId.js +0 -12
|
@@ -20,10 +20,11 @@ function useDateLocale(locale, defaultLocale) {
|
|
|
20
20
|
var importLocaleFile = function () { return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
|
21
21
|
var localeToSet;
|
|
22
22
|
return tslib_1.__generator(this, function (_a) {
|
|
23
|
+
var _b;
|
|
23
24
|
switch (_a.label) {
|
|
24
|
-
case 0: return [4 /*yield*/,
|
|
25
|
+
case 0: return [4 /*yield*/, (_b =
|
|
25
26
|
/* webpackMode: "lazy", webpackChunkName: "df-[index]", webpackExclude: /_lib/ */
|
|
26
|
-
"date-fns/locale/".concat(locale, "/index.js"))); })];
|
|
27
|
+
"date-fns/locale/".concat(locale, "/index.js"), Promise.resolve().then(function () { return tslib_1.__importStar(require(_b)); }))];
|
|
27
28
|
case 1:
|
|
28
29
|
localeToSet = _a.sent();
|
|
29
30
|
setCurrent(locale || current);
|
|
@@ -40,3 +41,4 @@ function useDateLocale(locale, defaultLocale) {
|
|
|
40
41
|
return data;
|
|
41
42
|
}
|
|
42
43
|
exports.useDateLocale = useDateLocale;
|
|
44
|
+
exports.default = useDateLocale;
|
package/node/hooks/useFocus.js
CHANGED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useInterval = void 0;
|
|
4
|
+
var tslib_1 = require("tslib");
|
|
5
|
+
var react_1 = require("react");
|
|
6
|
+
var utils_1 = require("@koine/utils");
|
|
7
|
+
/**
|
|
8
|
+
* @borrows [dan abramov](https://overreacted.io/making-setinterval-declarative-with-react-hooks/)
|
|
9
|
+
*
|
|
10
|
+
* We just add `deps` array argument and typescript support
|
|
11
|
+
*/
|
|
12
|
+
function useInterval(callback, delay, deps) {
|
|
13
|
+
if (deps === void 0) { deps = []; }
|
|
14
|
+
var savedCallback = (0, react_1.useRef)();
|
|
15
|
+
(0, react_1.useEffect)(function () {
|
|
16
|
+
savedCallback.current = callback;
|
|
17
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
18
|
+
}, tslib_1.__spreadArray([callback], deps, true));
|
|
19
|
+
(0, react_1.useEffect)(function () {
|
|
20
|
+
function tick() {
|
|
21
|
+
if (savedCallback.current)
|
|
22
|
+
savedCallback.current();
|
|
23
|
+
}
|
|
24
|
+
if (delay !== null) {
|
|
25
|
+
var id_1 = setInterval(tick, delay);
|
|
26
|
+
return function () { return clearInterval(id_1); };
|
|
27
|
+
}
|
|
28
|
+
return utils_1.noop;
|
|
29
|
+
}, [delay]);
|
|
30
|
+
}
|
|
31
|
+
exports.useInterval = useInterval;
|
|
32
|
+
exports.default = useInterval;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useKeyUp = void 0;
|
|
4
|
+
var tslib_1 = require("tslib");
|
|
5
|
+
var react_1 = require("react");
|
|
6
|
+
var dom_1 = require("@koine/dom");
|
|
7
|
+
function useKeyUp(callback, deps) {
|
|
8
|
+
if (deps === void 0) { deps = []; }
|
|
9
|
+
(0, react_1.useEffect)(function () {
|
|
10
|
+
var listener = (0, dom_1.on)(window, "keyup", function (event) {
|
|
11
|
+
// const { key } = event;
|
|
12
|
+
// be sure we do not intercept keys combinations maybe used for other
|
|
13
|
+
// actions like native browser navigation shortcuts
|
|
14
|
+
// @see https://stackoverflow.com/a/37559790/1938970
|
|
15
|
+
if (!event.ctrlKey &&
|
|
16
|
+
!event.altKey &&
|
|
17
|
+
!event.shiftKey &&
|
|
18
|
+
!event.metaKey) {
|
|
19
|
+
callback(event);
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
return listener;
|
|
23
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
24
|
+
}, tslib_1.__spreadArray([callback], deps, true));
|
|
25
|
+
}
|
|
26
|
+
exports.useKeyUp = useKeyUp;
|
|
27
|
+
exports.default = useKeyUp;
|
package/node/hooks/useMount.js
CHANGED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useNavigateAway = void 0;
|
|
4
|
+
var react_1 = require("react");
|
|
5
|
+
var dom_1 = require("@koine/dom");
|
|
6
|
+
// type UseNavigateAwayPagehideHandler = (event: PageTransitionEvent) => unknown;
|
|
7
|
+
/**
|
|
8
|
+
* @resources
|
|
9
|
+
*
|
|
10
|
+
* About browser's specs see:
|
|
11
|
+
* - https://developer.mozilla.org/en-US/docs/Web/API/Window/pagehide_event
|
|
12
|
+
* - https://developer.apple.com/library/archive/documentation/AppleApplications/Reference/SafariWebContent/HandlingEvents/HandlingEvents.html#//apple_ref/doc/uid/TP40006511-SW5
|
|
13
|
+
* - https://stackoverflow.com/questions/58009424/pagehide-event-on-google-chrome
|
|
14
|
+
*
|
|
15
|
+
* About react see:
|
|
16
|
+
* - https://github.com/jacobbuck/react-beforeunload
|
|
17
|
+
* - https://github.com/dioscarey/react-beforeunload-component
|
|
18
|
+
*
|
|
19
|
+
* About next.js see:
|
|
20
|
+
* - https://github.com/vercel/next.js/issues/2476
|
|
21
|
+
* - https://github.com/vercel/next.js/issues/2694
|
|
22
|
+
*
|
|
23
|
+
* For the callback technique see:
|
|
24
|
+
* - https://stackoverflow.com/a/11835394/1938970
|
|
25
|
+
*/
|
|
26
|
+
var useNavigateAway = function (handler) {
|
|
27
|
+
var beforeUnloadHandlerRef = (0, react_1.useRef)();
|
|
28
|
+
// const pagehideHandlerRef = useRef<UseNavigateAwayPagehideHandler | undefined>();
|
|
29
|
+
(0, react_1.useEffect)(function () {
|
|
30
|
+
beforeUnloadHandlerRef.current = function (event) {
|
|
31
|
+
var customMessageOrCondition = handler(event);
|
|
32
|
+
if (customMessageOrCondition) {
|
|
33
|
+
event.preventDefault();
|
|
34
|
+
}
|
|
35
|
+
// Handle legacy `event.returnValue` property
|
|
36
|
+
// https://developer.mozilla.org/en-US/docs/Web/API/Window/beforeunload_event
|
|
37
|
+
if (typeof customMessageOrCondition === "string") {
|
|
38
|
+
return (event.returnValue = customMessageOrCondition);
|
|
39
|
+
}
|
|
40
|
+
// Chrome doesn't support `event.preventDefault()` on `BeforeUnloadEvent`,
|
|
41
|
+
// instead it requires `event.returnValue` to be set
|
|
42
|
+
// https://developer.mozilla.org/en-US/docs/Web/API/WindowEventHandlers/onbeforeunload#browser_compatibility
|
|
43
|
+
if (event.defaultPrevented) {
|
|
44
|
+
return (event.returnValue = "");
|
|
45
|
+
}
|
|
46
|
+
return;
|
|
47
|
+
};
|
|
48
|
+
// pagehideHandlerRef.current = (event) => {
|
|
49
|
+
// const returnValue = handler?.(event);
|
|
50
|
+
// if (event.persisted) {
|
|
51
|
+
// // If the event's persisted property is `true` the page is about
|
|
52
|
+
// // to enter the Back-Forward Cache, which is also in the frozen state.
|
|
53
|
+
// } else {
|
|
54
|
+
// // If the event's persisted property is not `true` the page is
|
|
55
|
+
// // about to be unloaded.
|
|
56
|
+
// }
|
|
57
|
+
// };
|
|
58
|
+
}, [handler]);
|
|
59
|
+
(0, react_1.useEffect)(function () {
|
|
60
|
+
var listenerBeforeunload = (0, dom_1.on)(window, "beforeunload", function (event) { var _a; return (_a = beforeUnloadHandlerRef.current) === null || _a === void 0 ? void 0 : _a.call(beforeUnloadHandlerRef, event); });
|
|
61
|
+
// const listenerPagehide = on(window, "pagehide", (event) =>
|
|
62
|
+
// pagehideHandlerRef.current?.(event)
|
|
63
|
+
// );
|
|
64
|
+
return listenerBeforeunload;
|
|
65
|
+
// return () => {
|
|
66
|
+
// listenerBeforeunload();
|
|
67
|
+
// // listenerPagehide();
|
|
68
|
+
// };
|
|
69
|
+
}, []);
|
|
70
|
+
};
|
|
71
|
+
exports.useNavigateAway = useNavigateAway;
|
|
72
|
+
exports.default = exports.useNavigateAway;
|
|
@@ -2,11 +2,15 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.usePrevious = void 0;
|
|
4
4
|
var react_1 = require("react");
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
5
|
+
/**
|
|
6
|
+
* @borrows [samselikoff/animated-carousel](https://github.com/samselikoff/2022-06-02-animated-carousel/blob/main/pages/final.jsx)
|
|
7
|
+
*/
|
|
8
|
+
function usePrevious(state, defaulValue) {
|
|
9
|
+
var _a = (0, react_1.useState)([state, defaulValue]), tuple = _a[0], setTuple = _a[1];
|
|
10
|
+
if (tuple[1] !== state) {
|
|
11
|
+
setTuple([tuple[1], state]);
|
|
12
|
+
}
|
|
13
|
+
return tuple[0];
|
|
11
14
|
}
|
|
12
15
|
exports.usePrevious = usePrevious;
|
|
16
|
+
exports.default = usePrevious;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.usePreviousRef = void 0;
|
|
4
|
+
var react_1 = require("react");
|
|
5
|
+
function usePreviousRef(value) {
|
|
6
|
+
var ref = (0, react_1.useRef)();
|
|
7
|
+
(0, react_1.useEffect)(function () {
|
|
8
|
+
ref.current = value;
|
|
9
|
+
});
|
|
10
|
+
return ref.current;
|
|
11
|
+
}
|
|
12
|
+
exports.usePreviousRef = usePreviousRef;
|
|
13
|
+
exports.default = usePreviousRef;
|
|
@@ -2,16 +2,18 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.useWindowSize = void 0;
|
|
4
4
|
var react_1 = require("react");
|
|
5
|
+
var dom_1 = require("@koine/dom");
|
|
5
6
|
function useWindowSize() {
|
|
6
7
|
var _a = (0, react_1.useState)([0, 0]), size = _a[0], setSize = _a[1];
|
|
7
8
|
(0, react_1.useEffect)(function () {
|
|
8
9
|
function updateSize() {
|
|
9
10
|
setSize([window.innerWidth, window.innerHeight]);
|
|
10
11
|
}
|
|
11
|
-
|
|
12
|
+
var listener = (0, dom_1.on)(window, "resize", updateSize);
|
|
12
13
|
updateSize();
|
|
13
|
-
return
|
|
14
|
+
return listener;
|
|
14
15
|
}, []);
|
|
15
16
|
return size;
|
|
16
17
|
}
|
|
17
18
|
exports.useWindowSize = useWindowSize;
|
|
19
|
+
exports.default = useWindowSize;
|
package/package.json
CHANGED
|
@@ -1,28 +1,40 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@koine/react",
|
|
3
3
|
"sideEffects": false,
|
|
4
|
-
"
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
"
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
"@
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
"
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
"
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
"
|
|
21
|
-
|
|
22
|
-
|
|
4
|
+
"peerDependenciesMeta": {
|
|
5
|
+
"@mui/base": {
|
|
6
|
+
"optional": true
|
|
7
|
+
},
|
|
8
|
+
"@tiptap/react": {
|
|
9
|
+
"optional": true
|
|
10
|
+
},
|
|
11
|
+
"@tiptap/starter-kit": {
|
|
12
|
+
"optional": true
|
|
13
|
+
},
|
|
14
|
+
"framer-motion": {
|
|
15
|
+
"optional": true
|
|
16
|
+
},
|
|
17
|
+
"react-hook-form": {
|
|
18
|
+
"optional": true
|
|
19
|
+
},
|
|
20
|
+
"react-icons": {
|
|
21
|
+
"optional": true
|
|
22
|
+
},
|
|
23
|
+
"react-is": {
|
|
24
|
+
"optional": true
|
|
25
|
+
},
|
|
26
|
+
"react-popper": {
|
|
27
|
+
"optional": true
|
|
28
|
+
},
|
|
29
|
+
"react-swipeable": {
|
|
30
|
+
"optional": true
|
|
31
|
+
},
|
|
32
|
+
"styled-components": {
|
|
33
|
+
"optional": true
|
|
34
|
+
}
|
|
23
35
|
},
|
|
24
|
-
"
|
|
25
|
-
"
|
|
26
|
-
"
|
|
27
|
-
"
|
|
36
|
+
"main": "./node/index.js",
|
|
37
|
+
"types": "./index.d.ts",
|
|
38
|
+
"version": "1.1.0",
|
|
39
|
+
"module": "./index.js"
|
|
28
40
|
}
|
package/styles/media.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { Breakpoint, Breakpoints } from "./theme";
|
|
2
2
|
export declare const min: MediaQueryFunction, max: MediaQueryFunction, up: MediaQueryFunction, down: (br: Breakpoint) => string, between: (br1: Breakpoint, br2: Breakpoint) => string, only: (br: Breakpoint) => string;
|
|
3
|
-
export
|
|
4
|
-
export
|
|
5
|
-
export
|
|
3
|
+
export type MediaDirection = "min" | "max";
|
|
4
|
+
export type MediaQuery = `${MediaDirection}:${Breakpoint}`;
|
|
5
|
+
export type MediaQueryFunction = {
|
|
6
6
|
[Breakpoint in keyof Breakpoints]: string;
|
|
7
7
|
} & {
|
|
8
8
|
(breakpoint: Breakpoint): string;
|
package/styles/spacing.d.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import type { Theme } from "./theme";
|
|
2
|
-
export
|
|
3
|
-
export
|
|
2
|
+
export type SpacingSize = "sm" | "md" | "lg";
|
|
3
|
+
export type SpacingProperty = "padding" | "margin";
|
|
4
4
|
/** @default 1 */
|
|
5
|
-
export
|
|
6
|
-
export
|
|
7
|
-
export
|
|
8
|
-
export
|
|
9
|
-
export
|
|
5
|
+
export type SpacingFactor = number;
|
|
6
|
+
export type SpacingDirection = "top" | "bottom";
|
|
7
|
+
export type SpacingDirectionAxis = "vertical" | SpacingDirection;
|
|
8
|
+
export type SpacingDevices = keyof Theme["devices"];
|
|
9
|
+
export type SpacingArgs = Parameters<typeof spacing>;
|
|
10
10
|
export declare function spacing(this: Theme, size?: SpacingSize, factor?: SpacingFactor, property?: SpacingProperty, direction?: SpacingDirectionAxis, devices?: SpacingDevices[]): string;
|
|
11
11
|
export declare function spacingTop(this: Theme, size?: SpacingSize, factor?: SpacingFactor, property?: SpacingProperty, devices?: SpacingDevices[]): string;
|
|
12
12
|
export declare function spacingBottom(this: Theme, size?: SpacingSize, factor?: SpacingFactor, property?: SpacingProperty, devices?: SpacingDevices[]): string;
|
|
@@ -3,16 +3,16 @@ export declare const THEME_KEY = "theme";
|
|
|
3
3
|
export declare const THEME_DEFAULT: ThemeVanillaValue;
|
|
4
4
|
export declare const getInitialThemeFromRequest: (cookie?: string) => ThemeVanillaValue;
|
|
5
5
|
export declare const getInitialThemeFromClient: () => ThemeVanillaValue;
|
|
6
|
-
export
|
|
6
|
+
export type ThemeCookie = {
|
|
7
7
|
[THEME_KEY]: ThemeVanillaValue;
|
|
8
8
|
};
|
|
9
|
-
export
|
|
10
|
-
export
|
|
9
|
+
export type ThemeVanillaValue = "light" | "dark";
|
|
10
|
+
export type ThemeVanillaContextType = {
|
|
11
11
|
theme: ThemeVanillaValue;
|
|
12
12
|
setTheme?: React.Dispatch<React.SetStateAction<ThemeVanillaValue>>;
|
|
13
13
|
};
|
|
14
14
|
export declare const ThemeVanillaContext: import("react").Context<ThemeVanillaContextType>;
|
|
15
|
-
export
|
|
15
|
+
export type ThemeVanillaProviderProps = React.PropsWithChildren<{
|
|
16
16
|
initialTheme: ThemeVanillaValue;
|
|
17
17
|
}>;
|
|
18
18
|
export declare const ThemeVanillaProvider: ({ initialTheme, children, }: ThemeVanillaProviderProps) => JSX.Element;
|
package/styles/theme.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export
|
|
2
|
-
export
|
|
1
|
+
export type Breakpoint = "xs" | "sm" | "md" | "lg" | "xl" | "xxl";
|
|
2
|
+
export type Breakpoints = Record<Breakpoint, number>;
|
|
3
3
|
/**
|
|
4
4
|
* You can override the default breakpoints through the .env variable
|
|
5
5
|
*
|
|
@@ -14,7 +14,7 @@ export declare type Breakpoints = Record<Breakpoint, number>;
|
|
|
14
14
|
export declare const breakpoints: Breakpoints;
|
|
15
15
|
export declare const createTheme: (options: ThemeOptions) => Theme;
|
|
16
16
|
export declare const useTheme: () => Theme;
|
|
17
|
-
export
|
|
17
|
+
export type Theme = {
|
|
18
18
|
maxWidth: number;
|
|
19
19
|
gutter: {
|
|
20
20
|
quarter: number;
|
|
@@ -73,7 +73,7 @@ export declare type Theme = {
|
|
|
73
73
|
logoWidthSticky: [number, number];
|
|
74
74
|
};
|
|
75
75
|
};
|
|
76
|
-
export
|
|
76
|
+
export type ThemeOptions = {
|
|
77
77
|
maxWidth?: number;
|
|
78
78
|
gutter: NonNullable<Theme["gutter"]>;
|
|
79
79
|
devices?: Theme["devices"];
|
package/types.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
export type { KoineImgSmartWrapProps, KoineImgSmartProps } from "./Img/types";
|
|
3
|
-
export
|
|
4
|
-
export
|
|
3
|
+
export type Translate = (i18nKey: any, query?: any, options?: any) => string;
|
|
4
|
+
export type Option = {
|
|
5
5
|
value: string;
|
|
6
6
|
Label?: NonNullable<import("react").ReactNode>;
|
|
7
7
|
label: NonNullable<import("react").ReactChild | import("react").ReactFragment>;
|
|
8
8
|
};
|
|
9
|
-
export
|
|
10
|
-
export
|
|
9
|
+
export type KoineComponentProps<BaseComponentProps, ExtendableProps> = BaseComponentProps & ExtendableProps;
|
|
10
|
+
export type KoineComponent<Props = any> = string | React.ForwardRefExoticComponent<Props> | React.ExoticComponent<Props> | React.FC<Props> | ((props: Props) => JSX.Element);
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import { type GetMediaQueryWidthResolversBreakpoints } from "@koine/utils";
|
|
2
|
-
declare type _MediaQuerWidthDefExplicit<TBreakpoint extends string> = `min-${TBreakpoint}` | `max-${TBreakpoint}` | `up-${TBreakpoint}` | `down-${TBreakpoint}` | `between-${TBreakpoint}_${TBreakpoint}` | `only-${TBreakpoint}`;
|
|
3
|
-
export declare type MediaQuerWidthDef<TBreakpoint extends string> = `${TBreakpoint}` | _MediaQuerWidthDefExplicit<TBreakpoint>;
|
|
4
|
-
export declare type MediaQueryWidth<TBreakpoint extends string> = `@${MediaQuerWidthDef<TBreakpoint>}`;
|
|
5
|
-
export declare function useMediaQueryWidthCreator<TBreakpointsConfig extends GetMediaQueryWidthResolversBreakpoints>(customBreakpoints: TBreakpointsConfig): <TBreakpoints extends Extract<keyof TBreakpointsConfig, string>>(media: `@${TBreakpoints}` | `@min-${TBreakpoints}` | `@max-${TBreakpoints}` | `@up-${TBreakpoints}` | `@down-${TBreakpoints}` | `@between-${TBreakpoints}_${TBreakpoints}` | `@only-${TBreakpoints}`) => boolean;
|
|
6
|
-
export default useMediaQueryWidthCreator;
|
|
@@ -1,169 +0,0 @@
|
|
|
1
|
-
import { useState, useEffect, useMemo } from "react";
|
|
2
|
-
import { isBrowser, isUndefined, getMediaQueryWidthResolvers, } from "@koine/utils";
|
|
3
|
-
export function useMediaQueryWidthCreator(customBreakpoints) {
|
|
4
|
-
var queryResolvers = getMediaQueryWidthResolvers(customBreakpoints);
|
|
5
|
-
return function useMediaQueryWidth(media) {
|
|
6
|
-
var definition = media.substring(1);
|
|
7
|
-
var _a = definition.split("-"), rule = _a[0], ruleBreakpoint = _a[1];
|
|
8
|
-
if (isUndefined(ruleBreakpoint)) {
|
|
9
|
-
ruleBreakpoint = rule;
|
|
10
|
-
}
|
|
11
|
-
if (isUndefined(rule)) {
|
|
12
|
-
rule = "min";
|
|
13
|
-
}
|
|
14
|
-
// with the hook creator approach these breakpoint types cannot be deduced
|
|
15
|
-
// const [br1, br2] = ruleBreakpoint.split("-") as Split<
|
|
16
|
-
// typeof ruleBreakpoint,
|
|
17
|
-
// "-"
|
|
18
|
-
// >;
|
|
19
|
-
var _b = ruleBreakpoint.split("_"), br1 = _b[0], br2 = _b[1];
|
|
20
|
-
var query = queryResolvers[rule](br1, br2);
|
|
21
|
-
var mq = useMemo(function () { return (isBrowser ? window.matchMedia(query) : { matches: false }); }, [query]);
|
|
22
|
-
var _c = useState(mq.matches), matches = _c[0], setMatches = _c[1];
|
|
23
|
-
useEffect(function () {
|
|
24
|
-
var mq = window.matchMedia(query);
|
|
25
|
-
var handleChange = function (event) {
|
|
26
|
-
setMatches(event.matches);
|
|
27
|
-
};
|
|
28
|
-
setMatches(mq.matches);
|
|
29
|
-
// Safari < 14 can't use addEventListener on a MediaQueryList
|
|
30
|
-
// https://developer.mozilla.org/en-US/docs/Web/API/MediaQueryList#Browser_compatibility
|
|
31
|
-
if (!mq.addEventListener) {
|
|
32
|
-
// Update the state whenever the media query match state changes
|
|
33
|
-
mq.addListener(handleChange);
|
|
34
|
-
// Clean up on unmount and if the query changes
|
|
35
|
-
return function () {
|
|
36
|
-
mq.removeListener(handleChange);
|
|
37
|
-
};
|
|
38
|
-
}
|
|
39
|
-
mq.addEventListener("change", handleChange);
|
|
40
|
-
return function () {
|
|
41
|
-
mq.removeEventListener("change", handleChange);
|
|
42
|
-
};
|
|
43
|
-
}, [query]);
|
|
44
|
-
return matches;
|
|
45
|
-
};
|
|
46
|
-
}
|
|
47
|
-
export default useMediaQueryWidthCreator;
|
|
48
|
-
//// without creator it would be:
|
|
49
|
-
//// ---------------------------------------------------------------------------
|
|
50
|
-
// import { useState, useEffect, useMemo } from "react";
|
|
51
|
-
// import { isBrowser, type Split } from "@koine/utils";
|
|
52
|
-
// import { breakpoints as themeBreakpoints } from "@/config/theme/breakpoints";
|
|
53
|
-
// type Breakpoint = "xs" | "sm" | "md" | "lg" | "xl";
|
|
54
|
-
// type Breakpoints = Record<Breakpoint, number>;
|
|
55
|
-
// type MediaQuery =
|
|
56
|
-
// | `max:${Breakpoint}`
|
|
57
|
-
// | `min:${Breakpoint}`
|
|
58
|
-
// | `down:${Breakpoint}`
|
|
59
|
-
// | `up:${Breakpoint}`
|
|
60
|
-
// | `between:${Breakpoint}-${Breakpoint}`
|
|
61
|
-
// | `only:${Breakpoint}`;
|
|
62
|
-
// const breakpoints: Breakpoints = {
|
|
63
|
-
// xs: 0,
|
|
64
|
-
// ...themeBreakpoints,
|
|
65
|
-
// };
|
|
66
|
-
// const sortedBreakpointsNames = (
|
|
67
|
-
// Object.keys(breakpoints).map((key) => {
|
|
68
|
-
// const br = key as keyof typeof breakpoints;
|
|
69
|
-
// return [br, breakpoints[br]];
|
|
70
|
-
// }) as [Breakpoint, number][]
|
|
71
|
-
// )
|
|
72
|
-
// .sort((a, b) => a[1] - b[1])
|
|
73
|
-
// .map((item) => item[0]);
|
|
74
|
-
// const getNextBreakpoint = (breakpoint: Breakpoint) => {
|
|
75
|
-
// const index = sortedBreakpointsNames.indexOf(breakpoint);
|
|
76
|
-
// return sortedBreakpointsNames[index + 1];
|
|
77
|
-
// };
|
|
78
|
-
// /**
|
|
79
|
-
// * It behaves the same as `(min-width: ${value}px)`
|
|
80
|
-
// * where value is the given breakpoint value.
|
|
81
|
-
// * For ease of use this can be used both as a function `min("md")` and as an
|
|
82
|
-
// * object literal `min.md`.
|
|
83
|
-
// */
|
|
84
|
-
// const min = (br: Breakpoint) => `(min-width: ${breakpoints[br]}px)`;
|
|
85
|
-
// /**
|
|
86
|
-
// * It behaves the same as `(max-width: ${value}px)`
|
|
87
|
-
// * where value is the given breakpoint value.
|
|
88
|
-
// * For ease of use this can be used both as a function `max("md")` and as an
|
|
89
|
-
// * object literal `max.md`.
|
|
90
|
-
// */
|
|
91
|
-
// const max = (br: Breakpoint) => `(max-width: ${breakpoints[br] - 0.02}px)`;
|
|
92
|
-
// /**
|
|
93
|
-
// * It behaves the same as `min`
|
|
94
|
-
// * @inheritdoc {max}
|
|
95
|
-
// */
|
|
96
|
-
// const up = min;
|
|
97
|
-
// /**
|
|
98
|
-
// * It behaves similarly to `max` but you will use the "next" breakpoint,
|
|
99
|
-
// * specifying CSS that will apply from the given breakpoint and down.
|
|
100
|
-
// */
|
|
101
|
-
// const down = (br: Breakpoint) => {
|
|
102
|
-
// const brNext = getNextBreakpoint(br);
|
|
103
|
-
// // TODO: if br does not exists otherwise throw Error
|
|
104
|
-
// return brNext && `(max-width: ${breakpoints[brNext] - 0.02}px)`;
|
|
105
|
-
// };
|
|
106
|
-
// /**
|
|
107
|
-
// * Media query between the two given breakpoints
|
|
108
|
-
// */
|
|
109
|
-
// const between = (br1: Breakpoint, br2?: Breakpoint) => {
|
|
110
|
-
// return br2
|
|
111
|
-
// ? `(min-width: ${breakpoints[br1]}px) and (max-width: ${
|
|
112
|
-
// breakpoints[br2] - 0.02
|
|
113
|
-
// }px)`
|
|
114
|
-
// : min(br1);
|
|
115
|
-
// };
|
|
116
|
-
// /**
|
|
117
|
-
// * Media query to apply from the given breakpoint until the next, just for its
|
|
118
|
-
// * full range
|
|
119
|
-
// */
|
|
120
|
-
// const only = (br: Breakpoint) => {
|
|
121
|
-
// const brNext = getNextBreakpoint(br);
|
|
122
|
-
// return brNext ? between(br, brNext) : min(br);
|
|
123
|
-
// };
|
|
124
|
-
// const queryResolvers = {
|
|
125
|
-
// max,
|
|
126
|
-
// min,
|
|
127
|
-
// down,
|
|
128
|
-
// up,
|
|
129
|
-
// between,
|
|
130
|
-
// only,
|
|
131
|
-
// };
|
|
132
|
-
// export function useMqWidth(media: MediaQuery) {
|
|
133
|
-
// const [rule = "min", ruleBreakpoint] = media.split(":") as Split<
|
|
134
|
-
// MediaQuery,
|
|
135
|
-
// ":"
|
|
136
|
-
// >;
|
|
137
|
-
// const [br1, br2] = ruleBreakpoint.split("-") as Split<
|
|
138
|
-
// typeof ruleBreakpoint,
|
|
139
|
-
// "-"
|
|
140
|
-
// >;
|
|
141
|
-
// const query = queryResolvers[rule](br1, br2);
|
|
142
|
-
// const mq = useMemo(
|
|
143
|
-
// () => (isBrowser ? window.matchMedia(query) : { matches: false }),
|
|
144
|
-
// [query]
|
|
145
|
-
// );
|
|
146
|
-
// const [matches, setMatches] = useState(mq.matches);
|
|
147
|
-
// useEffect(() => {
|
|
148
|
-
// const mq = window.matchMedia(query);
|
|
149
|
-
// const handleChange = (event: MediaQueryListEvent) => {
|
|
150
|
-
// setMatches(event.matches);
|
|
151
|
-
// };
|
|
152
|
-
// setMatches(mq.matches);
|
|
153
|
-
// // Safari < 14 can't use addEventListener on a MediaQueryList
|
|
154
|
-
// // https://developer.mozilla.org/en-US/docs/Web/API/MediaQueryList#Browser_compatibility
|
|
155
|
-
// if (!mq.addEventListener) {
|
|
156
|
-
// // Update the state whenever the media query match state changes
|
|
157
|
-
// mq.addListener(handleChange);
|
|
158
|
-
// // Clean up on unmount and if the query changes
|
|
159
|
-
// return () => {
|
|
160
|
-
// mq.removeListener(handleChange);
|
|
161
|
-
// };
|
|
162
|
-
// }
|
|
163
|
-
// mq.addEventListener("change", handleChange);
|
|
164
|
-
// return () => {
|
|
165
|
-
// mq.removeEventListener("change", handleChange);
|
|
166
|
-
// };
|
|
167
|
-
// }, [query]);
|
|
168
|
-
// return matches;
|
|
169
|
-
// }
|
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
declare type MediaQuery<TBreakpoint extends string> = `max:${TBreakpoint}` | `min:${TBreakpoint}` | `down:${TBreakpoint}` | `up:${TBreakpoint}` | `between:${TBreakpoint}-${TBreakpoint}` | `only:${TBreakpoint}`;
|
|
2
|
-
export declare function useMqWidthCreator<TBreakpointsConfig extends Record<string, number>>(customBreakpoints: TBreakpointsConfig): <TBreakpoints extends Extract<keyof TBreakpointsConfig, string>>(media: MediaQuery<TBreakpoints>) => boolean;
|
|
3
|
-
export default useMqWidthCreator;
|