@loomhq/lens 10.63.9 → 10.64.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.
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
function SvgWatchLaterAdd(props) {
|
|
3
3
|
return (React.createElement("svg", Object.assign({ viewBox: "0 0 24 24", fill: "none" }, props),
|
|
4
|
-
React.createElement("path", { fillRule: "evenodd", clipRule: "evenodd", d: "
|
|
4
|
+
React.createElement("path", { fillRule: "evenodd", clipRule: "evenodd", d: "M7 4C6.73478 4 6.48043 4.10536 6.29289 4.29289C6.10536 4.48043 6 4.73478 6 5V19.0568L11.4188 15.1863C11.7665 14.9379 12.2335 14.9379 12.5812 15.1863L18 19.0568V5C18 4.73478 17.8946 4.48043 17.7071 4.29289C17.5196 4.10536 17.2652 4 17 4H7ZM4.87868 2.87868C5.44129 2.31607 6.20435 2 7 2H17C17.7956 2 18.5587 2.31607 19.1213 2.87868C19.6839 3.44129 20 4.20435 20 5V21C20 21.3746 19.7907 21.7178 19.4576 21.8892C19.1245 22.0606 18.7236 22.0315 18.4188 21.8137L12 17.2289L5.58124 21.8137C5.27642 22.0315 4.87549 22.0606 4.54242 21.8892C4.20935 21.7178 4 21.3746 4 21V5C4 4.20435 4.31607 3.44129 4.87868 2.87868ZM12 5C12.5523 5 13 5.44772 13 6V8H15C15.5523 8 16 8.44772 16 9C16 9.55228 15.5523 10 15 10H13V12C13 12.5523 12.5523 13 12 13C11.4477 13 11 12.5523 11 12V10H9C8.44772 10 8 9.55228 8 9C8 8.44771 8.44772 8 9 8H11V6C11 5.44772 11.4477 5 12 5Z", fill: "currentColor" })));
|
|
5
5
|
}
|
|
6
6
|
export default SvgWatchLaterAdd;
|
|
@@ -13,6 +13,7 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
13
13
|
import FocusTrap from 'focus-trap-react';
|
|
14
14
|
import { getColorValue, getPlacement, getRadius, getShadow, getSize, getSizeValue, u, } from '../../utilities';
|
|
15
15
|
import React, { useEffect } from 'react';
|
|
16
|
+
import { usePreventScroll } from '../../hooks/use-prevent-scroll';
|
|
16
17
|
import Backdrop from '../backdrop/backdrop';
|
|
17
18
|
import Container from '../container/container';
|
|
18
19
|
import IconButton from '../icon-button/icon-button';
|
|
@@ -111,9 +112,6 @@ export const ModalCard = (_a) => {
|
|
|
111
112
|
// TODO: LNS-151: Abstract into useKeyDown hook for reuse
|
|
112
113
|
var { children, onCloseClick, isOpen, maxWidth = 60, maxHeight = '70vh', placement = 'center', ariaLabel, ref } = _a, props = __rest(_a, ["children", "onCloseClick", "isOpen", "maxWidth", "maxHeight", "placement", "ariaLabel", "ref"]);
|
|
113
114
|
useEffect(() => {
|
|
114
|
-
if (!isOpen) {
|
|
115
|
-
return;
|
|
116
|
-
}
|
|
117
115
|
const keyListener = e => {
|
|
118
116
|
if (e.key === 'Escape') {
|
|
119
117
|
e.preventDefault();
|
|
@@ -125,6 +123,7 @@ export const ModalCard = (_a) => {
|
|
|
125
123
|
window.removeEventListener('keydown', keyListener);
|
|
126
124
|
};
|
|
127
125
|
}, [isOpen, onCloseClick]);
|
|
126
|
+
usePreventScroll('body', isOpen);
|
|
128
127
|
return (React.createElement(FocusTrap, { active: isOpen, focusTrapOptions: {
|
|
129
128
|
clickOutsideDeactivates: false,
|
|
130
129
|
allowOutsideClick: true,
|
package/dist/hooks/index.js
CHANGED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Usage:
|
|
3
|
+
* usePreventScroll(<level>, <boolean-condition>);
|
|
4
|
+
*
|
|
5
|
+
* `level` allows you to control whether the styles
|
|
6
|
+
* are passed to html or body, whichever level makes more sense
|
|
7
|
+
* for your application.
|
|
8
|
+
**/
|
|
9
|
+
export declare function usePreventScroll(level: 'body' | 'html', enabled?: boolean): void;
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { useLayoutEffect } from 'react';
|
|
2
|
+
/**
|
|
3
|
+
* Usage:
|
|
4
|
+
* usePreventScroll(<level>, <boolean-condition>);
|
|
5
|
+
*
|
|
6
|
+
* `level` allows you to control whether the styles
|
|
7
|
+
* are passed to html or body, whichever level makes more sense
|
|
8
|
+
* for your application.
|
|
9
|
+
**/
|
|
10
|
+
export function usePreventScroll(level, enabled) {
|
|
11
|
+
const safeDocument = document;
|
|
12
|
+
useLayoutEffect(() => {
|
|
13
|
+
const html = safeDocument === null || safeDocument === void 0 ? void 0 : safeDocument.documentElement;
|
|
14
|
+
const body = safeDocument === null || safeDocument === void 0 ? void 0 : safeDocument.body;
|
|
15
|
+
if (safeDocument == undefined || !html || !body) {
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
if (enabled) {
|
|
19
|
+
// Add styles if enabled
|
|
20
|
+
const scrollBarWidth = window.innerWidth - html.clientWidth;
|
|
21
|
+
const bodyPaddingRight = parseInt(window.getComputedStyle(body).getPropertyValue('padding-right'),
|
|
22
|
+
/* Force radixValue to be base-10 system to avoid errors:
|
|
23
|
+
* https://stackoverflow.com/questions/6611824/why-do-we-need-to-use-radix-parameter-when-calling-parseint
|
|
24
|
+
*/
|
|
25
|
+
10) || 0;
|
|
26
|
+
/**
|
|
27
|
+
* [1] iOS and desktop Safari bug: Requires position to make `overflow: hidden`
|
|
28
|
+
* prevent scrolling.
|
|
29
|
+
* [2] Desktop Safari bug: Must override overflow in both directions
|
|
30
|
+
* since `overflowY` won't prevent scroll if `overflowX` is applied.
|
|
31
|
+
* [3] paddingRight takes into account scrollbars by running a check.
|
|
32
|
+
**/
|
|
33
|
+
switch (level) {
|
|
34
|
+
case 'html': {
|
|
35
|
+
html.style.position = 'relative'; /* [1] */
|
|
36
|
+
html.style.overflow = 'hidden'; /* [2] */
|
|
37
|
+
body.style.paddingRight = `${bodyPaddingRight +
|
|
38
|
+
scrollBarWidth}px`; /* [3] */
|
|
39
|
+
break;
|
|
40
|
+
}
|
|
41
|
+
case 'body': {
|
|
42
|
+
body.style.setProperty('position', 'relative'); /* [1] */
|
|
43
|
+
body.style.setProperty('overflow', 'hidden'); /* [2] */
|
|
44
|
+
body.style.setProperty('padding-right', `${bodyPaddingRight + scrollBarWidth}px`); /* [3] */
|
|
45
|
+
break;
|
|
46
|
+
}
|
|
47
|
+
default:
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
return () => {
|
|
52
|
+
switch (level) {
|
|
53
|
+
case 'html': {
|
|
54
|
+
// TODO(LNS-221): Preserve previous style states rather than resetting to empty values for more robust utility
|
|
55
|
+
html.style.position = ''; /* [1] */
|
|
56
|
+
html.style.overflow = ''; /* [2] */
|
|
57
|
+
body.style.paddingRight = ''; /* [3] */
|
|
58
|
+
break;
|
|
59
|
+
}
|
|
60
|
+
case 'body': {
|
|
61
|
+
body.style.removeProperty('position'); /* [1] */
|
|
62
|
+
body.style.removeProperty('overflow'); /* [2] */
|
|
63
|
+
body.style.removeProperty('padding-right'); /* [3] */
|
|
64
|
+
break;
|
|
65
|
+
}
|
|
66
|
+
default:
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
// TODO(LNS-215): Clear styles on return to make utility more extendable for other uses
|
|
71
|
+
}, [safeDocument, enabled, level]);
|
|
72
|
+
}
|