@hh.ru/magritte-ui-full-screen-loader 1.0.1
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/FullScreenLoader.d.ts +5 -0
- package/FullScreenLoader.js +58 -0
- package/FullScreenLoader.js.map +1 -0
- package/index.css +57 -0
- package/index.d.ts +1 -0
- package/index.js +13 -0
- package/index.js.map +1 -0
- package/index.mock.js +3 -0
- package/index.mock.js.map +1 -0
- package/package.json +39 -0
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import './index.css';
|
|
2
|
+
import { jsx } from 'react/jsx-runtime';
|
|
3
|
+
import { useState, useRef, useEffect } from 'react';
|
|
4
|
+
import { createPortal } from 'react-dom';
|
|
5
|
+
import { CSSTransition } from 'react-transition-group';
|
|
6
|
+
import classnames from 'classnames';
|
|
7
|
+
import { useServerEnv } from '@hh.ru/magritte-common-is-server-env';
|
|
8
|
+
import { disableScroll } from '@hh.ru/magritte-common-modal-helper';
|
|
9
|
+
import { Layer } from '@hh.ru/magritte-ui-layer';
|
|
10
|
+
import { Loader } from '@hh.ru/magritte-ui-loader';
|
|
11
|
+
import { ThemeWrapper } from '@hh.ru/magritte-ui-theme-wrapper';
|
|
12
|
+
|
|
13
|
+
var styles = {"animation-timeout":"magritte-animation-timeout___aTdGa_1-0-1","animationTimeout":"magritte-animation-timeout___aTdGa_1-0-1","enter-animation":"magritte-enter-animation___TqSXR_1-0-1","enterAnimation":"magritte-enter-animation___TqSXR_1-0-1","enter-animation-active":"magritte-enter-animation-active___Jfsvw_1-0-1","enterAnimationActive":"magritte-enter-animation-active___Jfsvw_1-0-1","exit-animation":"magritte-exit-animation___6VlKj_1-0-1","exitAnimation":"magritte-exit-animation___6VlKj_1-0-1","exit-animation-active":"magritte-exit-animation-active___VanCA_1-0-1","exitAnimationActive":"magritte-exit-animation-active___VanCA_1-0-1","overlay":"magritte-overlay___YsKtP_1-0-1","loader":"magritte-loader___vx7PF_1-0-1"};
|
|
14
|
+
|
|
15
|
+
const CSS_CLASSES = {
|
|
16
|
+
enter: styles.enterAnimation,
|
|
17
|
+
enterActive: styles.enterAnimationActive,
|
|
18
|
+
exit: styles.exitAnimation,
|
|
19
|
+
exitActive: styles.exitAnimationActive,
|
|
20
|
+
};
|
|
21
|
+
const toInteger = (value) => {
|
|
22
|
+
const result = parseInt(value, 10);
|
|
23
|
+
return !Number.isNaN(result) ? result : 0;
|
|
24
|
+
};
|
|
25
|
+
const FullScreenLoader = ({ loading, ...props }) => {
|
|
26
|
+
const [animationTimeout, setAnimationTimeout] = useState(null);
|
|
27
|
+
const animationTimeoutRef = useRef(animationTimeout);
|
|
28
|
+
animationTimeoutRef.current = animationTimeout;
|
|
29
|
+
const animatedElementRef = useRef(null);
|
|
30
|
+
useEffect(() => {
|
|
31
|
+
const animationTimeoutElement = document.createElement('div');
|
|
32
|
+
animationTimeoutElement.classList.add(styles.animationTimeout);
|
|
33
|
+
document.body.appendChild(animationTimeoutElement);
|
|
34
|
+
const style = window.getComputedStyle(animationTimeoutElement);
|
|
35
|
+
const enter = toInteger(style.getPropertyValue('--enter-animation-duration'));
|
|
36
|
+
const exit = toInteger(style.getPropertyValue('--exit-animation-duration'));
|
|
37
|
+
setAnimationTimeout({ enter, exit });
|
|
38
|
+
document.body.removeChild(animationTimeoutElement);
|
|
39
|
+
}, [setAnimationTimeout]);
|
|
40
|
+
useEffect(() => {
|
|
41
|
+
if (loading) {
|
|
42
|
+
let enableScroll = disableScroll();
|
|
43
|
+
return () => {
|
|
44
|
+
enableScroll?.(animationTimeoutRef.current?.exit);
|
|
45
|
+
enableScroll = undefined;
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
return void 0;
|
|
49
|
+
}, [loading]);
|
|
50
|
+
const isServerEnv = useServerEnv();
|
|
51
|
+
if (!animationTimeout || isServerEnv) {
|
|
52
|
+
return null;
|
|
53
|
+
}
|
|
54
|
+
return createPortal(jsx(CSSTransition, { appear: true, classNames: CSS_CLASSES, in: loading, mountOnEnter: true, nodeRef: animatedElementRef, timeout: animationTimeout, unmountOnExit: true, children: jsx(ThemeWrapper, { children: (themeClass) => (jsx(Layer, { layer: "full-screen-loader", children: jsx("div", { className: classnames(styles.animationTimeout, styles.overlay, themeClass), ref: animatedElementRef, children: jsx("div", { className: styles.loader, children: jsx(Loader, { initial: "contrast", size: 48, ...props }) }) }) })) }) }), document.body);
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
export { FullScreenLoader };
|
|
58
|
+
//# sourceMappingURL=FullScreenLoader.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FullScreenLoader.js","sources":["../src/FullScreenLoader.tsx"],"sourcesContent":["import { useEffect, useRef, useState } from 'react';\nimport { createPortal } from 'react-dom';\nimport { CSSTransition } from 'react-transition-group';\nimport classnames from 'classnames';\n\nimport { useServerEnv } from '@hh.ru/magritte-common-is-server-env';\nimport { disableScroll, TimeoutCallback } from '@hh.ru/magritte-common-modal-helper';\nimport { Layer } from '@hh.ru/magritte-ui-layer';\nimport { Loader, LoaderProps } from '@hh.ru/magritte-ui-loader';\nimport { ThemeWrapper } from '@hh.ru/magritte-ui-theme-wrapper';\n\nimport styles from './full-screen-loader.less';\n\ntype AnimationTimeout = { enter: number; exit: number };\n\nexport interface FullScreenLoaderProps {\n loading: boolean;\n}\n\nconst CSS_CLASSES = {\n enter: styles.enterAnimation,\n enterActive: styles.enterAnimationActive,\n exit: styles.exitAnimation,\n exitActive: styles.exitAnimationActive,\n};\n\nconst toInteger = (value: string) => {\n const result = parseInt(value, 10);\n return !Number.isNaN(result) ? result : 0;\n};\n\nexport const FullScreenLoader: React.FC<FullScreenLoaderProps & Omit<LoaderProps, 'size'>> = ({\n loading,\n ...props\n}) => {\n const [animationTimeout, setAnimationTimeout] = useState<AnimationTimeout | null>(null);\n const animationTimeoutRef = useRef(animationTimeout);\n animationTimeoutRef.current = animationTimeout;\n const animatedElementRef = useRef(null);\n\n useEffect(() => {\n const animationTimeoutElement = document.createElement('div');\n animationTimeoutElement.classList.add(styles.animationTimeout);\n document.body.appendChild(animationTimeoutElement);\n const style = window.getComputedStyle(animationTimeoutElement);\n const enter = toInteger(style.getPropertyValue('--enter-animation-duration'));\n const exit = toInteger(style.getPropertyValue('--exit-animation-duration'));\n setAnimationTimeout({ enter, exit });\n document.body.removeChild(animationTimeoutElement);\n }, [setAnimationTimeout]);\n\n useEffect(() => {\n if (loading) {\n let enableScroll: TimeoutCallback | undefined = disableScroll();\n return () => {\n enableScroll?.(animationTimeoutRef.current?.exit);\n enableScroll = undefined;\n };\n }\n\n return void 0;\n }, [loading]);\n\n const isServerEnv = useServerEnv();\n if (!animationTimeout || isServerEnv) {\n return null;\n }\n\n return createPortal(\n <CSSTransition\n appear\n classNames={CSS_CLASSES}\n in={loading}\n mountOnEnter\n nodeRef={animatedElementRef}\n timeout={animationTimeout}\n unmountOnExit\n >\n <ThemeWrapper>\n {(themeClass) => (\n <Layer layer=\"full-screen-loader\">\n <div\n className={classnames(styles.animationTimeout, styles.overlay, themeClass)}\n ref={animatedElementRef}\n >\n <div className={styles.loader}>\n <Loader initial=\"contrast\" size={48} {...props} />\n </div>\n </div>\n </Layer>\n )}\n </ThemeWrapper>\n </CSSTransition>,\n document.body\n );\n};\n"],"names":["_jsx"],"mappings":";;;;;;;;;;;;;AAmBA,MAAM,WAAW,GAAG;IAChB,KAAK,EAAE,MAAM,CAAC,cAAc;IAC5B,WAAW,EAAE,MAAM,CAAC,oBAAoB;IACxC,IAAI,EAAE,MAAM,CAAC,aAAa;IAC1B,UAAU,EAAE,MAAM,CAAC,mBAAmB;CACzC,CAAC;AAEF,MAAM,SAAS,GAAG,CAAC,KAAa,KAAI;IAChC,MAAM,MAAM,GAAG,QAAQ,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;AACnC,IAAA,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,GAAG,MAAM,GAAG,CAAC,CAAC;AAC9C,CAAC,CAA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S,CAAC;AAC7B,aAAC,CAAC;SACL;QAED,OAAO,KAAK,CAAC,CAAC;AAClB,KAAC,EAAE,CAAC,OAAO,CAAC,CAAC,CAAC;AAEd,IAAA,MAAM,WAAW,GAAG,YAAY,EAAE,CAAC;AACnC,IAAA,IAAI,CAAC,gBAAgB,IAAI,WAAW,EAAE;AAClC,QAAA,OAAO,IAAI,CAAC;KACf;IAED,OAAO,YAAY,CACfA,GAAC,CAAA,aAAa,IACV,MAAM,EAAA,IAAA,EACN,UAAU,EAAE,WAAW,EACvB,EAAE,EAAE,OAAO,EACX,YAAY,QACZ,OAAO,EAAE,kBAAkB,EAC3B,OAAO,EAAE,gBAAgB,EACzB,aAAa,EAEb,IAAA,EAAA,QAAA,EAAAA,GAAA,CAAC,YAAY,EACR,EAAA,QAAA,EAAA,CAAC,UAAU,MACRA,GAAA,CAAC,KAAK,EAAC,EAAA,KAAK,EAAC,oBAAoB,EAAA,QAAA,EAC7BA,GACI,CAAA,KAAA,EAAA,EAAA,SAAS,EAAE,UAAU,CAAC,MAAM,CAAC,gBAAgB,EAAE,MAAM,CAAC,OAAO,EAAE,UAAU,CAAC,EAC1E,GAAG,EAAE,kBAAkB,YAEvBA,GAAK,CAAA,KAAA,EAAA,EAAA,SAAS,EAAE,MAAM,CAAC,MAAM,EACzB,QAAA,EAAAA,GAAA,CAAC,MAAM,EAAC,EAAA,OAAO,EAAC,UAAU,EAAC,IAAI,EAAE,EAAE,KAAM,KAAK,EAAA,CAAI,GAChD,EACJ,CAAA,EAAA,CACF,CACX,EACU,CAAA,EAAA,CACH,EAChB,QAAQ,CAAC,IAAI,CAChB,CAAC;AACN;;;;"}
|
package/index.css
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
:root{
|
|
2
|
+
--magritte-color-background-overlay-v23-2-3:#20262b99;
|
|
3
|
+
--magritte-color-background-constant-secondary-v23-2-3:#303030;
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
:root{
|
|
7
|
+
--magritte-semantic-animation-ease-in-out-200-timing-function-v23-2-3:cubic-bezier(0.25, 0.1, 0.25, 1);
|
|
8
|
+
--magritte-semantic-animation-ease-in-out-200-duration-v23-2-3:200ms;
|
|
9
|
+
--magritte-semantic-animation-ease-in-out-300-timing-function-v23-2-3:cubic-bezier(0.25, 0.1, 0.25, 1);
|
|
10
|
+
--magritte-semantic-animation-ease-in-out-300-duration-v23-2-3:300ms;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
.magritte-night-theme{
|
|
14
|
+
--magritte-color-background-constant-secondary-v23-2-3:#343c43;
|
|
15
|
+
}
|
|
16
|
+
.magritte-animation-timeout___aTdGa_1-0-1{
|
|
17
|
+
--enter-animation-duration:0ms;
|
|
18
|
+
--exit-animation-duration:0ms;
|
|
19
|
+
}
|
|
20
|
+
@media (prefers-reduced-motion: no-preference){
|
|
21
|
+
.magritte-animation-timeout___aTdGa_1-0-1{
|
|
22
|
+
--enter-animation-duration:var(--magritte-semantic-animation-ease-in-out-300-duration-v23-2-3);
|
|
23
|
+
--exit-animation-duration:var(--magritte-semantic-animation-ease-in-out-200-duration-v23-2-3);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
.magritte-enter-animation___TqSXR_1-0-1{
|
|
27
|
+
opacity:0;
|
|
28
|
+
}
|
|
29
|
+
.magritte-enter-animation-active___Jfsvw_1-0-1{
|
|
30
|
+
opacity:1;
|
|
31
|
+
transition-property:opacity;
|
|
32
|
+
transition-duration:var(--enter-animation-duration);
|
|
33
|
+
transition-timing-function:var(--magritte-semantic-animation-ease-in-out-300-timing-function-v23-2-3);
|
|
34
|
+
}
|
|
35
|
+
.magritte-exit-animation___6VlKj_1-0-1{
|
|
36
|
+
opacity:1;
|
|
37
|
+
}
|
|
38
|
+
.magritte-exit-animation-active___VanCA_1-0-1{
|
|
39
|
+
opacity:0;
|
|
40
|
+
transition-property:opacity;
|
|
41
|
+
transition-duration:var(--exit-animation-duration);
|
|
42
|
+
transition-timing-function:var(--magritte-semantic-animation-ease-in-out-200-timing-function-v23-2-3);
|
|
43
|
+
}
|
|
44
|
+
.magritte-overlay___YsKtP_1-0-1{
|
|
45
|
+
display:flex;
|
|
46
|
+
align-items:center;
|
|
47
|
+
justify-content:center;
|
|
48
|
+
position:fixed;
|
|
49
|
+
inset:0;
|
|
50
|
+
background-color:var(--magritte-color-background-overlay-v23-2-3);
|
|
51
|
+
}
|
|
52
|
+
.magritte-loader___vx7PF_1-0-1{
|
|
53
|
+
background-color:var(--magritte-color-background-constant-secondary-v23-2-3);
|
|
54
|
+
border-radius:28px;
|
|
55
|
+
line-height:0;
|
|
56
|
+
padding:20px;
|
|
57
|
+
}
|
package/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '@hh.ru/magritte-ui-full-screen-loader/FullScreenLoader';
|
package/index.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import './index.css';
|
|
2
|
+
export { FullScreenLoader } from './FullScreenLoader.js';
|
|
3
|
+
import 'react/jsx-runtime';
|
|
4
|
+
import 'react';
|
|
5
|
+
import 'react-dom';
|
|
6
|
+
import 'react-transition-group';
|
|
7
|
+
import 'classnames';
|
|
8
|
+
import '@hh.ru/magritte-common-is-server-env';
|
|
9
|
+
import '@hh.ru/magritte-common-modal-helper';
|
|
10
|
+
import '@hh.ru/magritte-ui-layer';
|
|
11
|
+
import '@hh.ru/magritte-ui-loader';
|
|
12
|
+
import '@hh.ru/magritte-ui-theme-wrapper';
|
|
13
|
+
//# sourceMappingURL=index.js.map
|
package/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;"}
|
package/index.mock.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.mock.js","sources":[],"sourcesContent":[],"names":[],"mappings":""}
|
package/package.json
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@hh.ru/magritte-ui-full-screen-loader",
|
|
3
|
+
"version": "1.0.1",
|
|
4
|
+
"main": "index.js",
|
|
5
|
+
"types": "index.d.ts",
|
|
6
|
+
"sideEffects": [
|
|
7
|
+
"index.css"
|
|
8
|
+
],
|
|
9
|
+
"scripts": {
|
|
10
|
+
"build": "yarn root:build $(pwd)",
|
|
11
|
+
"build-test-branch": "yarn root:build-test-branch $(pwd)",
|
|
12
|
+
"prepack": "yarn root:prepack $(pwd)",
|
|
13
|
+
"postpublish": "yarn root:postpublish $(pwd)",
|
|
14
|
+
"stylelint-check": "yarn root:stylelint-check $(pwd)",
|
|
15
|
+
"eslint-check": "yarn root:eslint-check $(pwd)",
|
|
16
|
+
"ts-config": "yarn root:ts-config $(pwd)",
|
|
17
|
+
"ts-check": "yarn root:ts-check $(pwd)",
|
|
18
|
+
"test": "yarn root:test $(pwd)",
|
|
19
|
+
"watch": "yarn root:watch $(pwd)"
|
|
20
|
+
},
|
|
21
|
+
"dependencies": {
|
|
22
|
+
"@hh.ru/magritte-common-is-server-env": "1.0.7",
|
|
23
|
+
"@hh.ru/magritte-common-modal-helper": "1.2.10",
|
|
24
|
+
"@hh.ru/magritte-design-tokens": "23.2.3",
|
|
25
|
+
"@hh.ru/magritte-ui-layer": "3.0.5",
|
|
26
|
+
"@hh.ru/magritte-ui-loader": "2.0.13",
|
|
27
|
+
"@hh.ru/magritte-ui-theme-wrapper": "1.1.3"
|
|
28
|
+
},
|
|
29
|
+
"peerDependencies": {
|
|
30
|
+
"classnames": ">=2.3.2",
|
|
31
|
+
"react": ">=18.2.0",
|
|
32
|
+
"react-dom": ">=18.2.0",
|
|
33
|
+
"react-transition-group": ">=4.4.5"
|
|
34
|
+
},
|
|
35
|
+
"publishConfig": {
|
|
36
|
+
"access": "public"
|
|
37
|
+
},
|
|
38
|
+
"gitHead": "90a91eaf0ef55ef0ae534be060b7bf4c27736f36"
|
|
39
|
+
}
|