@prom-ui/core 1.3.1 → 1.4.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/Avatar/cjs/index.development.js +99 -67
- package/Avatar/cjs/index.development.v2.js +99 -67
- package/Avatar/cjs/index.production.js +1 -1
- package/Avatar/cjs/index.production.v2.js +1 -1
- package/Avatar/index.d.ts +14 -14
- package/Avatar/package.json +1 -1
- package/Avatar/utils.d.ts +2 -2
- package/Backdrop/cjs/index.development.js +131 -77
- package/Backdrop/cjs/index.development.v2.js +131 -77
- package/Backdrop/cjs/index.production.js +1 -1
- package/Backdrop/cjs/index.production.v2.js +1 -1
- package/Backdrop/index.d.ts +25 -25
- package/Backdrop/package.json +1 -1
- package/Body/cjs/index.development.js +2 -0
- package/Body/cjs/index.development.v2.js +2 -0
- package/Body/index.d.ts +36 -36
- package/Body/package.json +1 -1
- package/BodyContext/cjs/index.development.js +6 -7
- package/BodyContext/cjs/index.development.v2.js +6 -7
- package/BodyContext/cjs/index.production.js +1 -1
- package/BodyContext/cjs/index.production.v2.js +1 -1
- package/BodyContext/index.d.ts +12 -12
- package/BodyContext/package.json +1 -1
- package/BodyProvider/cjs/index.development.js +7 -6
- package/BodyProvider/cjs/index.development.v2.js +7 -6
- package/BodyProvider/index.d.ts +10 -10
- package/BodyProvider/package.json +1 -1
- package/Box/cjs/index.development.js +4 -4
- package/Box/cjs/index.development.v2.js +4 -4
- package/Box/index.d.ts +106 -106
- package/Box/package.json +1 -1
- package/Button/cjs/index.development.js +67 -62
- package/Button/cjs/index.development.v2.js +67 -62
- package/Button/cjs/index.production.js +1 -1
- package/Button/cjs/index.production.v2.js +1 -1
- package/Button/index.d.ts +45 -45
- package/Button/package.json +1 -1
- package/ButtonPageUp/cjs/index.development.js +195 -85
- package/ButtonPageUp/cjs/index.development.v2.js +195 -85
- package/ButtonPageUp/cjs/index.production.js +1 -1
- package/ButtonPageUp/cjs/index.production.v2.js +1 -1
- package/ButtonPageUp/index.d.ts +18 -18
- package/ButtonPageUp/package.json +1 -1
- package/Checkbox/cjs/index.development.js +99 -67
- package/Checkbox/cjs/index.development.v2.js +99 -67
- package/Checkbox/cjs/index.production.js +1 -1
- package/Checkbox/cjs/index.production.v2.js +1 -1
- package/Checkbox/index.d.ts +8 -8
- package/Checkbox/package.json +1 -1
- package/Flex/index.d.ts +34 -34
- package/Flex/package.json +1 -1
- package/Grid/index.d.ts +46 -46
- package/Grid/package.json +1 -1
- package/Icon/index.d.ts +9 -9
- package/Icon/package.json +1 -1
- package/Image/index.d.ts +42 -42
- package/Image/package.json +1 -1
- package/ImageEmoji/cjs/index.development.js +70 -63
- package/ImageEmoji/cjs/index.development.v2.js +70 -63
- package/ImageEmoji/cjs/index.production.js +1 -1
- package/ImageEmoji/cjs/index.production.v2.js +1 -1
- package/ImageEmoji/index.d.ts +9 -9
- package/ImageEmoji/package.json +1 -1
- package/Input/index.d.ts +18 -18
- package/Input/package.json +1 -1
- package/InputField/addons/AfterClearValue.d.ts +3 -3
- package/InputField/addons/AfterCorrectValue.d.ts +2 -2
- package/InputField/addons/AfterLoading.d.ts +2 -2
- package/InputField/addons/AfterTogglePassword.d.ts +6 -6
- package/InputField/addons/ErrorText.d.ts +6 -6
- package/InputField/cjs/index.development.js +237 -173
- package/InputField/cjs/index.development.v2.js +237 -173
- package/InputField/cjs/index.production.js +1 -1
- package/InputField/cjs/index.production.v2.js +1 -1
- package/InputField/index.d.ts +18 -18
- package/InputField/package.json +1 -1
- package/InputField/utils.d.ts +10 -10
- package/KeyPress/cjs/index.development.js +13 -13
- package/KeyPress/cjs/index.development.v2.js +13 -13
- package/KeyPress/index.d.ts +14 -14
- package/KeyPress/package.json +1 -1
- package/Line/index.d.ts +13 -13
- package/Line/package.json +1 -1
- package/Link/cjs/index.development.js +5 -5
- package/Link/cjs/index.development.v2.js +5 -5
- package/Link/index.d.ts +28 -28
- package/Link/package.json +1 -1
- package/List/index.d.ts +23 -23
- package/List/package.json +1 -1
- package/Media/MediaProvider.d.ts +8 -8
- package/Media/cjs/index.development.js +70 -19
- package/Media/cjs/index.development.v2.js +70 -19
- package/Media/cjs/index.production.js +1 -1
- package/Media/cjs/index.production.v2.js +1 -1
- package/Media/index.d.ts +20 -20
- package/Media/package.json +1 -1
- package/OutsideClick/cjs/index.development.js +117 -61
- package/OutsideClick/cjs/index.development.v2.js +117 -61
- package/OutsideClick/cjs/index.production.js +1 -1
- package/OutsideClick/cjs/index.production.v2.js +1 -1
- package/OutsideClick/index.d.ts +12 -12
- package/OutsideClick/package.json +1 -1
- package/Overlay/cjs/index.development.js +197 -183
- package/Overlay/cjs/index.development.v2.js +197 -183
- package/Overlay/cjs/index.production.js +1 -1
- package/Overlay/cjs/index.production.v2.js +1 -1
- package/Overlay/components/OverlayHeader.d.ts +11 -11
- package/Overlay/components/SwipeClose.d.ts +11 -11
- package/Overlay/components/TouchScrollable.d.ts +8 -8
- package/Overlay/index.d.ts +76 -76
- package/Overlay/package.json +1 -1
- package/Overlay/utils.d.ts +10 -10
- package/Picture/index.d.ts +70 -70
- package/Picture/package.json +1 -1
- package/Portal/cjs/index.development.js +11 -11
- package/Portal/cjs/index.development.v2.js +11 -11
- package/Portal/index.d.ts +10 -10
- package/Portal/package.json +1 -1
- package/QRCode/cjs/index.development.js +11 -11
- package/QRCode/cjs/index.development.v2.js +11 -11
- package/QRCode/index.d.ts +17 -17
- package/QRCode/package.json +1 -1
- package/Rating/cjs/index.development.js +75 -69
- package/Rating/cjs/index.development.v2.js +75 -69
- package/Rating/cjs/index.production.js +1 -1
- package/Rating/cjs/index.production.v2.js +1 -1
- package/Rating/index.d.ts +17 -17
- package/Rating/package.json +1 -1
- package/RatingSelect/cjs/index.development.js +148 -68
- package/RatingSelect/cjs/index.development.v2.js +148 -68
- package/RatingSelect/cjs/index.production.js +1 -1
- package/RatingSelect/cjs/index.production.v2.js +1 -1
- package/RatingSelect/index.d.ts +22 -18
- package/RatingSelect/package.json +1 -1
- package/SafeQuery/cjs/index.development.js +158 -110
- package/SafeQuery/cjs/index.development.v2.js +158 -110
- package/SafeQuery/cjs/index.production.js +1 -1
- package/SafeQuery/cjs/index.production.v2.js +1 -1
- package/SafeQuery/components/Error.d.ts +7 -7
- package/SafeQuery/index.d.ts +10 -10
- package/SafeQuery/package.json +1 -1
- package/Scroll/index.d.ts +25 -25
- package/Scroll/package.json +1 -1
- package/ScrollControls/ScrollControlsButton.d.ts +11 -11
- package/ScrollControls/cjs/index.development.js +201 -113
- package/ScrollControls/cjs/index.development.v2.js +201 -113
- package/ScrollControls/cjs/index.production.js +1 -1
- package/ScrollControls/cjs/index.production.v2.js +1 -1
- package/ScrollControls/index.d.ts +16 -16
- package/ScrollControls/package.json +1 -1
- package/SimpleSlider/cjs/index.development.js +270 -158
- package/SimpleSlider/cjs/index.development.v2.js +270 -158
- package/SimpleSlider/cjs/index.production.js +1 -1
- package/SimpleSlider/cjs/index.production.v2.js +1 -1
- package/SimpleSlider/index.d.ts +41 -41
- package/SimpleSlider/package.json +1 -1
- package/SimpleSlider/useAutoPlay.d.ts +3 -3
- package/SimpleSlider/utils.d.ts +19 -19
- package/Skeleton/cjs/index.development.js +118 -64
- package/Skeleton/cjs/index.development.v2.js +118 -64
- package/Skeleton/cjs/index.production.js +1 -1
- package/Skeleton/cjs/index.production.v2.js +1 -1
- package/Skeleton/index.d.ts +37 -37
- package/Skeleton/package.json +1 -1
- package/Spinner/cjs/index.development.js +66 -61
- package/Spinner/cjs/index.development.v2.js +66 -61
- package/Spinner/cjs/index.production.js +1 -1
- package/Spinner/cjs/index.production.v2.js +1 -1
- package/Spinner/index.d.ts +29 -29
- package/Spinner/package.json +1 -1
- package/Text/index.d.ts +25 -25
- package/Text/package.json +1 -1
- package/TextEmoji/cjs/index.development.js +65 -60
- package/TextEmoji/cjs/index.development.v2.js +65 -60
- package/TextEmoji/cjs/index.production.js +1 -1
- package/TextEmoji/cjs/index.production.v2.js +1 -1
- package/TextEmoji/index.d.ts +9 -9
- package/TextEmoji/package.json +1 -1
- package/Tooltip/cjs/index.development.js +80 -91
- package/Tooltip/cjs/index.development.v2.js +80 -91
- package/Tooltip/cjs/index.production.js +1 -1
- package/Tooltip/cjs/index.production.v2.js +1 -1
- package/Tooltip/index.d.ts +87 -87
- package/Tooltip/package.json +1 -1
- package/Tumbler/cjs/index.development.js +98 -66
- package/Tumbler/cjs/index.development.v2.js +98 -66
- package/Tumbler/cjs/index.production.js +1 -1
- package/Tumbler/cjs/index.production.v2.js +1 -1
- package/Tumbler/index.d.ts +8 -8
- package/Tumbler/package.json +1 -1
- package/package.json +7 -5
- package/useBodyTTag/cjs/index.development.js +1 -1
- package/useBodyTTag/cjs/index.development.v2.js +1 -1
- package/useBodyTTag/index.d.ts +2 -2
- package/useBodyTTag/package.json +1 -1
- package/useDebounce/cjs/index.development.js +58 -6
- package/useDebounce/cjs/index.development.v2.js +58 -6
- package/useDebounce/cjs/index.production.js +1 -1
- package/useDebounce/cjs/index.production.v2.js +1 -1
- package/useDebounce/index.d.ts +4 -4
- package/useDebounce/package.json +1 -1
- package/useId/cjs/index.development.js +6 -7
- package/useId/cjs/index.development.v2.js +6 -7
- package/useId/cjs/index.production.js +1 -1
- package/useId/cjs/index.production.v2.js +1 -1
- package/useId/index.d.ts +4 -4
- package/useId/package.json +1 -1
- package/useIsMounted/cjs/index.development.js +3 -3
- package/useIsMounted/cjs/index.development.v2.js +3 -3
- package/useIsMounted/index.d.ts +4 -4
- package/useIsMounted/package.json +1 -1
- package/useKeyPress/cjs/index.development.js +76 -22
- package/useKeyPress/cjs/index.development.v2.js +76 -22
- package/useKeyPress/cjs/index.production.js +1 -1
- package/useKeyPress/cjs/index.production.v2.js +1 -1
- package/useKeyPress/index.d.ts +6 -6
- package/useKeyPress/package.json +1 -1
- package/useMedia/cjs/index.development.js +5 -5
- package/useMedia/cjs/index.development.v2.js +5 -5
- package/useMedia/index.d.ts +21 -21
- package/useMedia/package.json +1 -1
- package/useOutsideClick/cjs/index.development.js +2 -2
- package/useOutsideClick/cjs/index.development.v2.js +2 -2
- package/useOutsideClick/index.d.ts +5 -5
- package/useOutsideClick/package.json +1 -1
- package/usePortal/cjs/index.development.js +32 -27
- package/usePortal/cjs/index.development.v2.js +32 -27
- package/usePortal/index.d.ts +12 -12
- package/usePortal/package.json +1 -1
- package/useScrollPosition/cjs/index.development.js +2 -2
- package/useScrollPosition/cjs/index.development.v2.js +2 -2
- package/useScrollPosition/index.d.ts +5 -5
- package/useScrollPosition/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";function e(e){if(e&&"object"==typeof e&&"default"in e)return e;var t=Object.create(null);return e&&Object.keys(e).forEach((function(
|
|
1
|
+
"use strict";function e(e){if(e&&"object"==typeof e&&"default"in e)return e;var t=Object.create(null);return e&&Object.keys(e).forEach((function(r){if("default"!==r){var n=Object.getOwnPropertyDescriptor(e,r);Object.defineProperty(t,r,n.get?n:{enumerable:!0,get:function(){return e[r]}})}})),t.default=e,Object.freeze(t)}Object.defineProperty(exports,"__esModule",{value:!0});var t=e(require("react"));function r(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var r=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=r){var n,o,u,i,a=[],c=!0,f=!1;try{if(u=(r=r.call(e)).next,0===t){if(Object(r)!==r)return;c=!1}else for(;!(c=(n=u.call(r)).done)&&(a.push(n.value),a.length!==t);c=!0);}catch(l){f=!0,o=l}finally{try{if(!c&&null!=r.return&&(i=r.return(),Object(i)!==i))return}finally{if(f)throw o}}return a}}(e,t)||function(e,t){if(!e)return;if("string"==typeof e)return n(e,t);var r=Object.prototype.toString.call(e).slice(8,-1);"Object"===r&&e.constructor&&(r=e.constructor.name);if("Map"===r||"Set"===r)return Array.from(e);if("Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r))return n(e,t)}(e,t)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function n(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=new Array(t);r<t;r++)n[r]=e[r];return n}exports.useKeyPress=function(e,n,o){var u=r(t.useState(!1),2),i=u[0],a=u[1],c=function(t){t.key===e&&(n?n(t):a(!0))},f=function(t){t.key===e&&(o?o(t):a(!1))};return t.useEffect((function(){return window.addEventListener("keydown",c),window.addEventListener("keyup",f),function(){window.removeEventListener("keydown",c),window.removeEventListener("keyup",f)}}),[e,n,o]),i};
|
package/useKeyPress/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
type handleFn = (e: KeyboardEvent) => void;
|
|
2
|
-
/**
|
|
3
|
-
* Reack hook
|
|
4
|
-
*/
|
|
5
|
-
export declare const useKeyPress: (targetKey: string, handleKeyDown?: handleFn, handleKeyUp?: handleFn) => boolean;
|
|
6
|
-
export {};
|
|
1
|
+
type handleFn = (e: KeyboardEvent) => void;
|
|
2
|
+
/**
|
|
3
|
+
* Reack hook
|
|
4
|
+
*/
|
|
5
|
+
export declare const useKeyPress: (targetKey: string, handleKeyDown?: handleFn, handleKeyUp?: handleFn) => boolean;
|
|
6
|
+
export {};
|
package/useKeyPress/package.json
CHANGED
|
@@ -11,12 +11,12 @@ var SCREEN_BREAKPOINTS = {
|
|
|
11
11
|
wide: 1200,
|
|
12
12
|
huge: 1400
|
|
13
13
|
};
|
|
14
|
-
/**
|
|
15
|
-
* Хук позволяет определять текущее состояние медиа-запроса и обновлять его при изменении размера окна браузера.
|
|
14
|
+
/**
|
|
15
|
+
* Хук позволяет определять текущее состояние медиа-запроса и обновлять его при изменении размера окна браузера.
|
|
16
16
|
*/
|
|
17
|
-
var useMedia = function (
|
|
18
|
-
var minWidth =
|
|
19
|
-
maxWidth =
|
|
17
|
+
var useMedia = function useMedia(_ref) {
|
|
18
|
+
var minWidth = _ref.minWidth,
|
|
19
|
+
maxWidth = _ref.maxWidth;
|
|
20
20
|
return reactResponsive.useMediaQuery({
|
|
21
21
|
minWidth: minWidth ? SCREEN_BREAKPOINTS[minWidth] : 1,
|
|
22
22
|
maxWidth: maxWidth ? SCREEN_BREAKPOINTS[maxWidth] - 1 : undefined
|
|
@@ -11,12 +11,12 @@ var SCREEN_BREAKPOINTS = {
|
|
|
11
11
|
wide: 1200,
|
|
12
12
|
huge: 1400
|
|
13
13
|
};
|
|
14
|
-
/**
|
|
15
|
-
* Хук позволяет определять текущее состояние медиа-запроса и обновлять его при изменении размера окна браузера.
|
|
14
|
+
/**
|
|
15
|
+
* Хук позволяет определять текущее состояние медиа-запроса и обновлять его при изменении размера окна браузера.
|
|
16
16
|
*/
|
|
17
|
-
var useMedia = function (
|
|
18
|
-
var minWidth =
|
|
19
|
-
maxWidth =
|
|
17
|
+
var useMedia = function useMedia(_ref) {
|
|
18
|
+
var minWidth = _ref.minWidth,
|
|
19
|
+
maxWidth = _ref.maxWidth;
|
|
20
20
|
return reactResponsive.useMediaQuery({
|
|
21
21
|
minWidth: minWidth ? SCREEN_BREAKPOINTS[minWidth] : 1,
|
|
22
22
|
maxWidth: maxWidth ? SCREEN_BREAKPOINTS[maxWidth] - 1 : undefined
|
package/useMedia/index.d.ts
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
export declare const SCREEN_BREAKPOINTS: {
|
|
2
|
-
readonly small: 480;
|
|
3
|
-
readonly medium: 768;
|
|
4
|
-
readonly large: 960;
|
|
5
|
-
readonly wide: 1200;
|
|
6
|
-
readonly huge: 1400;
|
|
7
|
-
};
|
|
8
|
-
export type useMedia = (arg: {
|
|
9
|
-
/**
|
|
10
|
-
* Аналог CSS медиа правила `@media (min-width: ...)`
|
|
11
|
-
*/
|
|
12
|
-
minWidth?: keyof typeof SCREEN_BREAKPOINTS;
|
|
13
|
-
/**
|
|
14
|
-
* Аналог CSS медиа правила `@media (max-width: ...)`
|
|
15
|
-
*/
|
|
16
|
-
maxWidth?: keyof typeof SCREEN_BREAKPOINTS;
|
|
17
|
-
}) => boolean;
|
|
18
|
-
/**
|
|
19
|
-
* Хук позволяет определять текущее состояние медиа-запроса и обновлять его при изменении размера окна браузера.
|
|
20
|
-
*/
|
|
21
|
-
export declare const useMedia: useMedia;
|
|
1
|
+
export declare const SCREEN_BREAKPOINTS: {
|
|
2
|
+
readonly small: 480;
|
|
3
|
+
readonly medium: 768;
|
|
4
|
+
readonly large: 960;
|
|
5
|
+
readonly wide: 1200;
|
|
6
|
+
readonly huge: 1400;
|
|
7
|
+
};
|
|
8
|
+
export type useMedia = (arg: {
|
|
9
|
+
/**
|
|
10
|
+
* Аналог CSS медиа правила `@media (min-width: ...)`
|
|
11
|
+
*/
|
|
12
|
+
minWidth?: keyof typeof SCREEN_BREAKPOINTS;
|
|
13
|
+
/**
|
|
14
|
+
* Аналог CSS медиа правила `@media (max-width: ...)`
|
|
15
|
+
*/
|
|
16
|
+
maxWidth?: keyof typeof SCREEN_BREAKPOINTS;
|
|
17
|
+
}) => boolean;
|
|
18
|
+
/**
|
|
19
|
+
* Хук позволяет определять текущее состояние медиа-запроса и обновлять его при изменении размера окна браузера.
|
|
20
|
+
*/
|
|
21
|
+
export declare const useMedia: useMedia;
|
package/useMedia/package.json
CHANGED
|
@@ -8,8 +8,8 @@ function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'defau
|
|
|
8
8
|
|
|
9
9
|
var useOutsideClickRef__default = /*#__PURE__*/_interopDefaultCompat(useOutsideClickRef);
|
|
10
10
|
|
|
11
|
-
/**
|
|
12
|
-
* Reack hook
|
|
11
|
+
/**
|
|
12
|
+
* Reack hook
|
|
13
13
|
*/
|
|
14
14
|
var useOutsideClick = useOutsideClickRef__default.default;
|
|
15
15
|
|
|
@@ -8,8 +8,8 @@ function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'defau
|
|
|
8
8
|
|
|
9
9
|
var useOutsideClickRef__default = /*#__PURE__*/_interopDefaultCompat(useOutsideClickRef);
|
|
10
10
|
|
|
11
|
-
/**
|
|
12
|
-
* Reack hook
|
|
11
|
+
/**
|
|
12
|
+
* Reack hook
|
|
13
13
|
*/
|
|
14
14
|
var useOutsideClick = useOutsideClickRef__default.default;
|
|
15
15
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import useOutsideClickRef from '@rooks/use-outside-click-ref';
|
|
2
|
-
/**
|
|
3
|
-
* Reack hook
|
|
4
|
-
*/
|
|
5
|
-
export declare const useOutsideClick: typeof useOutsideClickRef;
|
|
1
|
+
import useOutsideClickRef from '@rooks/use-outside-click-ref';
|
|
2
|
+
/**
|
|
3
|
+
* Reack hook
|
|
4
|
+
*/
|
|
5
|
+
export declare const useOutsideClick: typeof useOutsideClickRef;
|
|
@@ -4,18 +4,19 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
4
4
|
|
|
5
5
|
var react = require('react');
|
|
6
6
|
|
|
7
|
-
/**
|
|
8
|
-
* Creates DOM element to be used as React root.
|
|
9
|
-
* @returns {HTMLElement}
|
|
7
|
+
/**
|
|
8
|
+
* Creates DOM element to be used as React root.
|
|
9
|
+
* @returns {HTMLElement}
|
|
10
10
|
*/
|
|
11
11
|
function createRootElement(id) {
|
|
12
12
|
var rootContainer = document.createElement('div');
|
|
13
13
|
rootContainer.setAttribute('id', id);
|
|
14
14
|
return rootContainer;
|
|
15
15
|
}
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
*
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Appends element as last child of body.
|
|
19
|
+
* @param {HTMLElement} rootElem
|
|
19
20
|
*/
|
|
20
21
|
function addRootElement(rootElem) {
|
|
21
22
|
try {
|
|
@@ -28,28 +29,31 @@ function addRootElement(rootElem) {
|
|
|
28
29
|
console.warn('Failed to add root element');
|
|
29
30
|
}
|
|
30
31
|
}
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
*
|
|
34
|
-
*
|
|
35
|
-
*
|
|
36
|
-
*
|
|
37
|
-
*
|
|
38
|
-
*
|
|
39
|
-
*
|
|
40
|
-
* @
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Hook to create a React Portal.
|
|
35
|
+
* Automatically handles creating and tearing-down the root elements (no SRR
|
|
36
|
+
* makes this trivial), so there is no need to ensure the parent target already
|
|
37
|
+
* exists.
|
|
38
|
+
* @example
|
|
39
|
+
* const target = usePortal(id, [id]);
|
|
40
|
+
* return createPortal(children, target);
|
|
41
|
+
* @param {String} id The id of the target container, e.g 'modal' or 'spotlight'
|
|
42
|
+
* @returns {HTMLElement} The DOM node to use as the Portal target.
|
|
41
43
|
*/
|
|
42
|
-
var usePortal = function (id) {
|
|
44
|
+
var usePortal = function usePortal(id) {
|
|
43
45
|
var rootElemRef = react.useRef(null);
|
|
44
46
|
react.useEffect(function () {
|
|
45
47
|
// Look for existing target dom element to append to
|
|
46
48
|
var existingParent = document.querySelector("#".concat(id));
|
|
47
49
|
// Parent is either a new root or the existing dom element
|
|
48
50
|
var parentElem = existingParent || createRootElement(id);
|
|
51
|
+
|
|
49
52
|
// If there is no existing DOM element, add a new one.
|
|
50
53
|
if (!existingParent) {
|
|
51
54
|
addRootElement(parentElem);
|
|
52
55
|
}
|
|
56
|
+
|
|
53
57
|
// Add the detached element to the parent
|
|
54
58
|
if (rootElemRef.current) {
|
|
55
59
|
parentElem.appendChild(rootElemRef.current);
|
|
@@ -63,17 +67,18 @@ var usePortal = function (id) {
|
|
|
63
67
|
}
|
|
64
68
|
};
|
|
65
69
|
}, []);
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
*
|
|
69
|
-
*
|
|
70
|
-
*
|
|
71
|
-
*
|
|
72
|
-
*
|
|
73
|
-
*
|
|
74
|
-
*
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* It's important we evaluate this lazily:
|
|
73
|
+
* - We need first render to contain the DOM element, so it shouldn't happen
|
|
74
|
+
* in useEffect. We would normally put this in the constructor().
|
|
75
|
+
* - We can't do 'const rootElemRef = useRef(document.createElement('div))',
|
|
76
|
+
* since this will run every single render (that's a lot).
|
|
77
|
+
* - We want the ref to consistently point to the same DOM element and only
|
|
78
|
+
* ever run once.
|
|
79
|
+
* @link https://reactjs.org/docs/hooks-faq.html#how-to-create-expensive-objects-lazily
|
|
75
80
|
*/
|
|
76
|
-
var getRootElem = function () {
|
|
81
|
+
var getRootElem = function getRootElem() {
|
|
77
82
|
if (!rootElemRef.current && typeof document !== 'undefined') {
|
|
78
83
|
rootElemRef.current = document.createElement('div');
|
|
79
84
|
}
|
|
@@ -4,18 +4,19 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
4
4
|
|
|
5
5
|
var react = require('react');
|
|
6
6
|
|
|
7
|
-
/**
|
|
8
|
-
* Creates DOM element to be used as React root.
|
|
9
|
-
* @returns {HTMLElement}
|
|
7
|
+
/**
|
|
8
|
+
* Creates DOM element to be used as React root.
|
|
9
|
+
* @returns {HTMLElement}
|
|
10
10
|
*/
|
|
11
11
|
function createRootElement(id) {
|
|
12
12
|
var rootContainer = document.createElement('div');
|
|
13
13
|
rootContainer.setAttribute('id', id);
|
|
14
14
|
return rootContainer;
|
|
15
15
|
}
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
*
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Appends element as last child of body.
|
|
19
|
+
* @param {HTMLElement} rootElem
|
|
19
20
|
*/
|
|
20
21
|
function addRootElement(rootElem) {
|
|
21
22
|
try {
|
|
@@ -28,28 +29,31 @@ function addRootElement(rootElem) {
|
|
|
28
29
|
console.warn('Failed to add root element');
|
|
29
30
|
}
|
|
30
31
|
}
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
*
|
|
34
|
-
*
|
|
35
|
-
*
|
|
36
|
-
*
|
|
37
|
-
*
|
|
38
|
-
*
|
|
39
|
-
*
|
|
40
|
-
* @
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Hook to create a React Portal.
|
|
35
|
+
* Automatically handles creating and tearing-down the root elements (no SRR
|
|
36
|
+
* makes this trivial), so there is no need to ensure the parent target already
|
|
37
|
+
* exists.
|
|
38
|
+
* @example
|
|
39
|
+
* const target = usePortal(id, [id]);
|
|
40
|
+
* return createPortal(children, target);
|
|
41
|
+
* @param {String} id The id of the target container, e.g 'modal' or 'spotlight'
|
|
42
|
+
* @returns {HTMLElement} The DOM node to use as the Portal target.
|
|
41
43
|
*/
|
|
42
|
-
var usePortal = function (id) {
|
|
44
|
+
var usePortal = function usePortal(id) {
|
|
43
45
|
var rootElemRef = react.useRef(null);
|
|
44
46
|
react.useEffect(function () {
|
|
45
47
|
// Look for existing target dom element to append to
|
|
46
48
|
var existingParent = document.querySelector("#".concat(id));
|
|
47
49
|
// Parent is either a new root or the existing dom element
|
|
48
50
|
var parentElem = existingParent || createRootElement(id);
|
|
51
|
+
|
|
49
52
|
// If there is no existing DOM element, add a new one.
|
|
50
53
|
if (!existingParent) {
|
|
51
54
|
addRootElement(parentElem);
|
|
52
55
|
}
|
|
56
|
+
|
|
53
57
|
// Add the detached element to the parent
|
|
54
58
|
if (rootElemRef.current) {
|
|
55
59
|
parentElem.appendChild(rootElemRef.current);
|
|
@@ -63,17 +67,18 @@ var usePortal = function (id) {
|
|
|
63
67
|
}
|
|
64
68
|
};
|
|
65
69
|
}, []);
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
*
|
|
69
|
-
*
|
|
70
|
-
*
|
|
71
|
-
*
|
|
72
|
-
*
|
|
73
|
-
*
|
|
74
|
-
*
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* It's important we evaluate this lazily:
|
|
73
|
+
* - We need first render to contain the DOM element, so it shouldn't happen
|
|
74
|
+
* in useEffect. We would normally put this in the constructor().
|
|
75
|
+
* - We can't do 'const rootElemRef = useRef(document.createElement('div))',
|
|
76
|
+
* since this will run every single render (that's a lot).
|
|
77
|
+
* - We want the ref to consistently point to the same DOM element and only
|
|
78
|
+
* ever run once.
|
|
79
|
+
* @link https://reactjs.org/docs/hooks-faq.html#how-to-create-expensive-objects-lazily
|
|
75
80
|
*/
|
|
76
|
-
var getRootElem = function () {
|
|
81
|
+
var getRootElem = function getRootElem() {
|
|
77
82
|
if (!rootElemRef.current && typeof document !== 'undefined') {
|
|
78
83
|
rootElemRef.current = document.createElement('div');
|
|
79
84
|
}
|
package/usePortal/index.d.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Hook to create a React Portal.
|
|
3
|
-
* Automatically handles creating and tearing-down the root elements (no SRR
|
|
4
|
-
* makes this trivial), so there is no need to ensure the parent target already
|
|
5
|
-
* exists.
|
|
6
|
-
* @example
|
|
7
|
-
* const target = usePortal(id, [id]);
|
|
8
|
-
* return createPortal(children, target);
|
|
9
|
-
* @param {String} id The id of the target container, e.g 'modal' or 'spotlight'
|
|
10
|
-
* @returns {HTMLElement} The DOM node to use as the Portal target.
|
|
11
|
-
*/
|
|
12
|
-
export declare const usePortal: (id: string) => HTMLElement | null;
|
|
1
|
+
/**
|
|
2
|
+
* Hook to create a React Portal.
|
|
3
|
+
* Automatically handles creating and tearing-down the root elements (no SRR
|
|
4
|
+
* makes this trivial), so there is no need to ensure the parent target already
|
|
5
|
+
* exists.
|
|
6
|
+
* @example
|
|
7
|
+
* const target = usePortal(id, [id]);
|
|
8
|
+
* return createPortal(children, target);
|
|
9
|
+
* @param {String} id The id of the target container, e.g 'modal' or 'spotlight'
|
|
10
|
+
* @returns {HTMLElement} The DOM node to use as the Portal target.
|
|
11
|
+
*/
|
|
12
|
+
export declare const usePortal: (id: string) => HTMLElement | null;
|
package/usePortal/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { useScrollPosition as useScrollPositionPackage } from '@n8tb1t/use-scroll-position';
|
|
2
|
-
/**
|
|
3
|
-
* Reack hook
|
|
4
|
-
*/
|
|
5
|
-
export declare const useScrollPosition: typeof useScrollPositionPackage;
|
|
1
|
+
import { useScrollPosition as useScrollPositionPackage } from '@n8tb1t/use-scroll-position';
|
|
2
|
+
/**
|
|
3
|
+
* Reack hook
|
|
4
|
+
*/
|
|
5
|
+
export declare const useScrollPosition: typeof useScrollPositionPackage;
|