@homecode/ui 5.20.23 → 5.20.24
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.
|
@@ -6,8 +6,14 @@ import { Button } from '../Button/Button.js';
|
|
|
6
6
|
import { Icon } from '../Icon/Icon.js';
|
|
7
7
|
import S from './LightBox.styl.js';
|
|
8
8
|
|
|
9
|
+
/** Matches the fade-out in LightBox.styl: the blur stays until it ends. */
|
|
10
|
+
const FADE_MS = 200;
|
|
9
11
|
function LightBox({ children, className, onClose, blur, ...props }) {
|
|
10
12
|
const [isOpen, setOpen] = useState(false);
|
|
13
|
+
// A closed light box stays mounted at opacity 0, and an invisible
|
|
14
|
+
// full-screen blur still costs a backdrop pass every frame (a list of cards,
|
|
15
|
+
// each with its own light box, stalled the page). Blur only while it shows.
|
|
16
|
+
const [blurOn, setBlurOn] = useState(false);
|
|
11
17
|
const onKeyDown = useCallback(e => {
|
|
12
18
|
if (isOpen && e.key === 'Escape') {
|
|
13
19
|
e.stopPropagation();
|
|
@@ -18,11 +24,19 @@ function LightBox({ children, className, onClose, blur, ...props }) {
|
|
|
18
24
|
useEffect(() => {
|
|
19
25
|
setOpen(props.isOpen);
|
|
20
26
|
}, [props.isOpen]);
|
|
27
|
+
useEffect(() => {
|
|
28
|
+
if (isOpen) {
|
|
29
|
+
setBlurOn(true);
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
const timer = setTimeout(() => setBlurOn(false), FADE_MS);
|
|
33
|
+
return () => clearTimeout(timer);
|
|
34
|
+
}, [isOpen]);
|
|
21
35
|
useEffect(() => {
|
|
22
36
|
document.addEventListener('keydown', onKeyDown, true);
|
|
23
37
|
return () => document.removeEventListener('keydown', onKeyDown, true);
|
|
24
38
|
}, [isOpen]);
|
|
25
|
-
return (jsxs(Paranja, { className: cn(S.root, isOpen && S.open, className), blur: blur, children: [children, jsx(Button, { className: S.close, onClick: onClose, variant: "clear", children: jsx(Icon, { type: "close", size: "l" }) })] }));
|
|
39
|
+
return (jsxs(Paranja, { className: cn(S.root, isOpen && S.open, className), blur: blur && blurOn, children: [children, jsx(Button, { className: S.close, onClick: onClose, variant: "clear", children: jsx(Icon, { type: "close", size: "l" }) })] }));
|
|
26
40
|
}
|
|
27
41
|
|
|
28
42
|
export { LightBox };
|
|
@@ -503,7 +503,10 @@ class Popup extends Component {
|
|
|
503
503
|
const wrapperClasses = cn(S.contentWrapper, inline && S.inline, isOpen && S.isOpen, animating && S.animating, wrapperProps.className);
|
|
504
504
|
const trigger = this.triggerElem.current;
|
|
505
505
|
const [axis, float] = direction.split('-');
|
|
506
|
-
const classes = cn(S.content, outlined && S.outlined, animated && animating && S.animating, elevation && S[`elevation-${elevation}`], S[`size-${size}`], S[`axis-${axis}`], S[`float-${float || 'middle'}`],
|
|
506
|
+
const classes = cn(S.content, outlined && S.outlined, animated && animating && S.animating, elevation && S[`elevation-${elevation}`], S[`size-${size}`], S[`axis-${axis}`], S[`float-${float || 'middle'}`],
|
|
507
|
+
// A closed popup stays mounted at opacity 0; its blur would still cost
|
|
508
|
+
// a backdrop pass every frame, so blur only while the content is shown.
|
|
509
|
+
blur && isContentVisible && S.blur, round && S.round, contentProps.className);
|
|
507
510
|
if (trigger && !inline && triggerBounds) {
|
|
508
511
|
const shiftTf = boundaryFit.left !== 0 || boundaryFit.top !== 0
|
|
509
512
|
? `translate3d(${boundaryFit.left}px, ${boundaryFit.top}px, 0)`
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import '@testing-library/jest-dom';
|