@qualtrics/ui-react 2.75.0 → 2.77.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/CHANGELOG.md +18 -0
- package/dist/__node_modules/@radix-ui/primitive/dist/index.js +54 -0
- package/dist/__node_modules/@radix-ui/react-arrow/dist/index.js +28 -0
- package/dist/__node_modules/@radix-ui/react-collection/dist/index.js +605 -0
- package/dist/__node_modules/@radix-ui/react-compose-refs/dist/index.js +45 -0
- package/dist/__node_modules/@radix-ui/react-context/dist/index.js +108 -0
- package/dist/__node_modules/@radix-ui/react-direction/dist/index.js +21 -0
- package/dist/__node_modules/@radix-ui/react-dismissable-layer/dist/index.js +223 -0
- package/dist/__node_modules/@radix-ui/react-dropdown-menu/dist/index.js +350 -0
- package/dist/__node_modules/@radix-ui/react-focus-guards/dist/index.js +35 -0
- package/dist/__node_modules/@radix-ui/react-focus-scope/dist/index.js +248 -0
- package/dist/__node_modules/@radix-ui/react-id/dist/index.js +15 -0
- package/dist/__node_modules/@radix-ui/react-menu/dist/index.js +911 -0
- package/dist/__node_modules/@radix-ui/react-popper/dist/index.js +325 -0
- package/dist/__node_modules/@radix-ui/react-portal/dist/index.js +25 -0
- package/dist/__node_modules/@radix-ui/react-presence/dist/index.js +141 -0
- package/dist/__node_modules/@radix-ui/react-primitive/dist/index.js +34 -0
- package/dist/__node_modules/@radix-ui/react-roving-focus/dist/index.js +216 -0
- package/dist/__node_modules/@radix-ui/react-slot/dist/index.js +127 -0
- package/dist/__node_modules/@radix-ui/react-use-callback-ref/dist/index.js +18 -0
- package/dist/__node_modules/@radix-ui/react-use-controllable-state/dist/index.js +141 -0
- package/dist/__node_modules/@radix-ui/react-use-effect-event/dist/index.js +32 -0
- package/dist/__node_modules/@radix-ui/react-use-escape-keydown/dist/index.js +23 -0
- package/dist/__node_modules/@radix-ui/react-use-layout-effect/dist/index.js +6 -0
- package/dist/__node_modules/@radix-ui/react-use-size/dist/index.js +48 -0
- package/dist/__node_modules/aria-hidden/dist/es2015/index.js +169 -0
- package/dist/__node_modules/detect-node-es/esm/node.js +4 -0
- package/dist/__node_modules/get-nonce/dist/es2015/index.js +15 -0
- package/dist/__node_modules/react-remove-scroll/dist/es2015/Combination.js +9 -0
- package/dist/__node_modules/react-remove-scroll/dist/es2015/SideEffect.js +169 -0
- package/dist/__node_modules/react-remove-scroll/dist/es2015/UI.js +39 -0
- package/dist/__node_modules/react-remove-scroll/dist/es2015/aggresiveCapture.js +21 -0
- package/dist/__node_modules/react-remove-scroll/dist/es2015/handleScroll.js +110 -0
- package/dist/__node_modules/react-remove-scroll/dist/es2015/index.js +1 -0
- package/dist/__node_modules/react-remove-scroll/dist/es2015/medium.js +6 -0
- package/dist/__node_modules/react-remove-scroll/dist/es2015/sidecar.js +8 -0
- package/dist/__node_modules/react-remove-scroll-bar/dist/es2015/component.js +57 -0
- package/dist/__node_modules/react-remove-scroll-bar/dist/es2015/constants.js +10 -0
- package/dist/__node_modules/react-remove-scroll-bar/dist/es2015/index.js +3 -0
- package/dist/__node_modules/react-remove-scroll-bar/dist/es2015/utils.js +31 -0
- package/dist/__node_modules/react-style-singleton/dist/es2015/component.js +19 -0
- package/dist/__node_modules/react-style-singleton/dist/es2015/hook.js +25 -0
- package/dist/__node_modules/react-style-singleton/dist/es2015/index.js +3 -0
- package/dist/__node_modules/react-style-singleton/dist/es2015/singleton.js +51 -0
- package/dist/__node_modules/tslib/tslib.es6.js +403 -0
- package/dist/__node_modules/use-callback-ref/dist/es2015/assignRef.js +24 -0
- package/dist/__node_modules/use-callback-ref/dist/es2015/createRef.js +25 -0
- package/dist/__node_modules/use-callback-ref/dist/es2015/index.js +8 -0
- package/dist/__node_modules/use-callback-ref/dist/es2015/mergeRef.js +21 -0
- package/dist/__node_modules/use-callback-ref/dist/es2015/refToCallback.js +50 -0
- package/dist/__node_modules/use-callback-ref/dist/es2015/transformRef.js +17 -0
- package/dist/__node_modules/use-callback-ref/dist/es2015/useMergeRef.js +48 -0
- package/dist/__node_modules/use-callback-ref/dist/es2015/useRef.js +42 -0
- package/dist/__node_modules/use-callback-ref/dist/es2015/useTransformRef.js +21 -0
- package/dist/__node_modules/use-sidecar/dist/es2015/config.js +8 -0
- package/dist/__node_modules/use-sidecar/dist/es2015/env.js +8 -0
- package/dist/__node_modules/use-sidecar/dist/es2015/exports.js +21 -0
- package/dist/__node_modules/use-sidecar/dist/es2015/hoc.js +18 -0
- package/dist/__node_modules/use-sidecar/dist/es2015/hook.js +44 -0
- package/dist/__node_modules/use-sidecar/dist/es2015/index.js +6 -0
- package/dist/__node_modules/use-sidecar/dist/es2015/medium.js +81 -0
- package/dist/__node_modules/use-sidecar/dist/es2015/renderProp.js +38 -0
- package/dist/__shared/cjs/{index-98bc748b.js → index-58d973dc.js} +3 -3
- package/dist/__shared/cjs/{index-9f6415a6.js → index-fd8ffec5.js} +409 -372
- package/dist/components/Accordion/Accordion2.js +3 -3
- package/dist/components/BreakpointSwitch/BreakpointSwitch.js +3 -2
- package/dist/components/Button/Button.js +3 -3
- package/dist/components/ButtonGroup/ButtonGroup.js +3 -2
- package/dist/components/ButtonGroup/ButtonGroup2.js +3 -3
- package/dist/components/Checkbox/Checkbox2.js +3 -3
- package/dist/components/ColorPicker/ColorPicker.js +7 -8
- package/dist/components/ColorPicker/ColorPicker2.js +3 -3
- package/dist/components/Combobox/Combobox.js +9 -8
- package/dist/components/Combobox/Combobox2.js +3 -3
- package/dist/components/Combobox/ComboboxList.js +5 -6
- package/dist/components/ConfigPane/ConfigPane2.js +3 -3
- package/dist/components/Divider/Divider2.js +3 -3
- package/dist/components/Dropdown/Dropdown.js +1 -1
- package/dist/components/Dropdown/Dropdown2.js +3 -3
- package/dist/components/Dropdown/DropdownButton.js +10 -9
- package/dist/components/Dropdown/DropdownList.js +6 -7
- package/dist/components/FilePicker/FilePicker2.js +3 -3
- package/dist/components/FormField/Caption.js +3 -3
- package/dist/components/FormField/FormField2.js +3 -3
- package/dist/components/FullScreenTakeover/FullScreenTakeover2.js +3 -3
- package/dist/components/IconButton/IconButton2.js +3 -3
- package/dist/components/InlineInput/InlineInput2.js +3 -3
- package/dist/components/Input/Input2.js +3 -3
- package/dist/components/InputGroup/InputGroup2.js +3 -3
- package/dist/components/Label/Label2.js +3 -3
- package/dist/components/Link/Link2.js +3 -3
- package/dist/components/LoadingSpinner/LoadingSpinner2.js +3 -3
- package/dist/components/LogicEditor/ConditionSet.js +2 -2
- package/dist/components/LogicEditor/LogicEditor2.js +3 -3
- package/dist/components/Modal/Modal.js +4 -2
- package/dist/components/Modal/Modal2.js +3 -3
- package/dist/components/NewMenu/BaseMenu.js +31 -25
- package/dist/components/NewMenu/Menu/Menu.js +1 -0
- package/dist/components/NewMenu/NewMenu.js +3 -3
- package/dist/components/NewMenu/SelectMenu/SelectMenu.js +3 -1
- package/dist/components/NewMenu/parts/ArrowNav/ArrowNav.js +10 -4
- package/dist/components/NewMenu/parts/MenuItem.js +1 -1
- package/dist/components/NumberStepper/NumberStepper2.js +3 -3
- package/dist/components/PageLayout/PageLayout.js +3 -3
- package/dist/components/Pagination/Pagination2.js +3 -3
- package/dist/components/Popover/Popover.js +8 -14
- package/dist/components/Popover/Popover2.js +3 -3
- package/dist/components/QuickSearch/QuickSearch2.js +3 -3
- package/dist/components/Radio/Radio2.js +3 -3
- package/dist/components/SearchInput/SearchInput2.js +3 -3
- package/dist/components/SidebarNav/SidebarNav2.js +3 -3
- package/dist/components/Slider/Slider2.js +3 -3
- package/dist/components/Switch/Switch2.js +3 -3
- package/dist/components/Table/Table2.js +3 -3
- package/dist/components/Tabs/TabList.js +3 -2
- package/dist/components/Tabs/TabPanels.js +2 -1
- package/dist/components/Tabs/Tabs2.js +3 -3
- package/dist/components/Tooltip/Tooltip.js +6 -12
- package/dist/components/Tooltip/Tooltip2.js +3 -3
- package/dist/components/deprecated_ColorPicker/ColorPicker.js +5 -6
- package/dist/components/deprecated_ColorPicker/ColorPicker2.js +3 -3
- package/dist/components/deprecated_NumberStepper/NumberStepper2.js +3 -3
- package/dist/components/deprecated_Tabs/Tabs.js +3 -3
- package/dist/components/deprecated_Tabs/Tabs2.js +3 -3
- package/dist/components/deprecated_Toolbar/Toolbar2.js +3 -3
- package/dist/design-tokens/less/typography.js +3 -3
- package/dist/hooks/useOverlay/useOverlay2.js +3 -3
- package/dist/hooks/usePrevious/usePrevious.js +1 -1
- package/dist/hooks/useScreenReaderAnnouncement/useScreenReaderAnnouncement.js +2 -2
- package/dist/hooks/useScreenReaderAnnouncement/useScreenReaderAnnouncement2.js +3 -3
- package/dist/icons/Icon.js +3 -3
- package/dist/icons/index.js +1 -1
- package/dist/index.d.ts +18 -17
- package/dist/index.es.js +1 -1
- package/dist/index.js +4 -5
- package/dist/next/AdvancedTable/AdvancedTable2.js +3 -3
- package/dist/next/CollapsibleSearchInput/CollapsibleSearchInput2.js +3 -3
- package/dist/next/Combobox/Combobox2.js +3 -3
- package/dist/next/Combobox/ComboboxFlyout.js +6 -6
- package/dist/next/Combobox/hooks/useComboboxFocusSequence/useComboboxFocusSequence.js +1 -1
- package/dist/next/Combobox/hooks/useComboboxLoadingState/useComboboxLoadingState.js +1 -1
- package/dist/next/Drawer/Drawer2.js +3 -3
- package/dist/next/FilterAnchor/FilterAnchor2.js +3 -3
- package/dist/next/Form/FormFields/InputField.js +3 -3
- package/dist/next/Indicator/Indicator2.js +3 -3
- package/dist/next/Input/Input2.js +3 -3
- package/dist/next/LoadingSpinner/LoadingSpinner2.js +3 -3
- package/dist/next/Menu/Hooks/usePaneSearch.js +1 -1
- package/dist/next/Menu/Menu.js +5 -3
- package/dist/next/Menu/Menu2.js +3 -3
- package/dist/next/Menu/MenuButton.js +1 -1
- package/dist/next/Menu/MenuItem.js +2 -2
- package/dist/next/Menu/MenuPane.js +14 -7
- package/dist/next/Menu/SubMenu.js +8 -6
- package/dist/next/PhoneNumberInput/PhoneNumberInput.js +90 -41
- package/dist/next/PhoneNumberInput/PhoneNumberInput2.js +3 -3
- package/dist/next/Select/Select.js +4 -2
- package/dist/next/Select/Select2.js +3 -3
- package/dist/next/SplitButton/SplitButton2.js +3 -3
- package/dist/next/TimePicker/TimeDropdown.js +5 -6
- package/dist/next/TimePicker/TimeInput.js +104 -37
- package/dist/next/TimePicker/TimePicker2.js +3 -3
- package/dist/next/ToggleButton/styles.js +3 -3
- package/dist/next/index.d.ts +19 -13
- package/dist/next/index.js +5617 -330
- package/dist/utils/Flyout/Flyout2.js +3 -3
- package/dist/utils/GridChildrenWrapper/GridChildrenWrapper.js +2 -1
- package/dist/utils/Popper/Popper.js +149 -115
- package/dist/utils/Portal/Portal.js +3 -2
- package/dist/utils/Text/Text.js +3 -2
- package/dist/utils/filterChildren/filterChildren.js +3 -2
- package/dist/utils/index.js +1 -0
- package/icons/package.json +3 -4
- package/next/package.json +4 -5
- package/package.json +15 -16
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
var getDefaultParent = function (originalTarget) {
|
|
2
|
+
if (typeof document === 'undefined') {
|
|
3
|
+
return null;
|
|
4
|
+
}
|
|
5
|
+
var sampleTarget = Array.isArray(originalTarget) ? originalTarget[0] : originalTarget;
|
|
6
|
+
return sampleTarget.ownerDocument.body;
|
|
7
|
+
};
|
|
8
|
+
var counterMap = new WeakMap();
|
|
9
|
+
var uncontrolledNodes = new WeakMap();
|
|
10
|
+
var markerMap = {};
|
|
11
|
+
var lockCount = 0;
|
|
12
|
+
var unwrapHost = function (node) {
|
|
13
|
+
return node && (node.host || unwrapHost(node.parentNode));
|
|
14
|
+
};
|
|
15
|
+
var correctTargets = function (parent, targets) {
|
|
16
|
+
return targets
|
|
17
|
+
.map(function (target) {
|
|
18
|
+
if (parent.contains(target)) {
|
|
19
|
+
return target;
|
|
20
|
+
}
|
|
21
|
+
var correctedTarget = unwrapHost(target);
|
|
22
|
+
if (correctedTarget && parent.contains(correctedTarget)) {
|
|
23
|
+
return correctedTarget;
|
|
24
|
+
}
|
|
25
|
+
console.error('aria-hidden', target, 'in not contained inside', parent, '. Doing nothing');
|
|
26
|
+
return null;
|
|
27
|
+
})
|
|
28
|
+
.filter(function (x) { return Boolean(x); });
|
|
29
|
+
};
|
|
30
|
+
/**
|
|
31
|
+
* Marks everything except given node(or nodes) as aria-hidden
|
|
32
|
+
* @param {Element | Element[]} originalTarget - elements to keep on the page
|
|
33
|
+
* @param [parentNode] - top element, defaults to document.body
|
|
34
|
+
* @param {String} [markerName] - a special attribute to mark every node
|
|
35
|
+
* @param {String} [controlAttribute] - html Attribute to control
|
|
36
|
+
* @return {Undo} undo command
|
|
37
|
+
*/
|
|
38
|
+
var applyAttributeToOthers = function (originalTarget, parentNode, markerName, controlAttribute) {
|
|
39
|
+
var targets = correctTargets(parentNode, Array.isArray(originalTarget) ? originalTarget : [originalTarget]);
|
|
40
|
+
if (!markerMap[markerName]) {
|
|
41
|
+
markerMap[markerName] = new WeakMap();
|
|
42
|
+
}
|
|
43
|
+
var markerCounter = markerMap[markerName];
|
|
44
|
+
var hiddenNodes = [];
|
|
45
|
+
var elementsToKeep = new Set();
|
|
46
|
+
var elementsToStop = new Set(targets);
|
|
47
|
+
var keep = function (el) {
|
|
48
|
+
if (!el || elementsToKeep.has(el)) {
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
elementsToKeep.add(el);
|
|
52
|
+
keep(el.parentNode);
|
|
53
|
+
};
|
|
54
|
+
targets.forEach(keep);
|
|
55
|
+
var deep = function (parent) {
|
|
56
|
+
if (!parent || elementsToStop.has(parent)) {
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
Array.prototype.forEach.call(parent.children, function (node) {
|
|
60
|
+
if (elementsToKeep.has(node)) {
|
|
61
|
+
deep(node);
|
|
62
|
+
}
|
|
63
|
+
else {
|
|
64
|
+
try {
|
|
65
|
+
var attr = node.getAttribute(controlAttribute);
|
|
66
|
+
var alreadyHidden = attr !== null && attr !== 'false';
|
|
67
|
+
var counterValue = (counterMap.get(node) || 0) + 1;
|
|
68
|
+
var markerValue = (markerCounter.get(node) || 0) + 1;
|
|
69
|
+
counterMap.set(node, counterValue);
|
|
70
|
+
markerCounter.set(node, markerValue);
|
|
71
|
+
hiddenNodes.push(node);
|
|
72
|
+
if (counterValue === 1 && alreadyHidden) {
|
|
73
|
+
uncontrolledNodes.set(node, true);
|
|
74
|
+
}
|
|
75
|
+
if (markerValue === 1) {
|
|
76
|
+
node.setAttribute(markerName, 'true');
|
|
77
|
+
}
|
|
78
|
+
if (!alreadyHidden) {
|
|
79
|
+
node.setAttribute(controlAttribute, 'true');
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
catch (e) {
|
|
83
|
+
console.error('aria-hidden: cannot operate on ', node, e);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
};
|
|
88
|
+
deep(parentNode);
|
|
89
|
+
elementsToKeep.clear();
|
|
90
|
+
lockCount++;
|
|
91
|
+
return function () {
|
|
92
|
+
hiddenNodes.forEach(function (node) {
|
|
93
|
+
var counterValue = counterMap.get(node) - 1;
|
|
94
|
+
var markerValue = markerCounter.get(node) - 1;
|
|
95
|
+
counterMap.set(node, counterValue);
|
|
96
|
+
markerCounter.set(node, markerValue);
|
|
97
|
+
if (!counterValue) {
|
|
98
|
+
if (!uncontrolledNodes.has(node)) {
|
|
99
|
+
node.removeAttribute(controlAttribute);
|
|
100
|
+
}
|
|
101
|
+
uncontrolledNodes.delete(node);
|
|
102
|
+
}
|
|
103
|
+
if (!markerValue) {
|
|
104
|
+
node.removeAttribute(markerName);
|
|
105
|
+
}
|
|
106
|
+
});
|
|
107
|
+
lockCount--;
|
|
108
|
+
if (!lockCount) {
|
|
109
|
+
// clear
|
|
110
|
+
counterMap = new WeakMap();
|
|
111
|
+
counterMap = new WeakMap();
|
|
112
|
+
uncontrolledNodes = new WeakMap();
|
|
113
|
+
markerMap = {};
|
|
114
|
+
}
|
|
115
|
+
};
|
|
116
|
+
};
|
|
117
|
+
/**
|
|
118
|
+
* Marks everything except given node(or nodes) as aria-hidden
|
|
119
|
+
* @param {Element | Element[]} originalTarget - elements to keep on the page
|
|
120
|
+
* @param [parentNode] - top element, defaults to document.body
|
|
121
|
+
* @param {String} [markerName] - a special attribute to mark every node
|
|
122
|
+
* @return {Undo} undo command
|
|
123
|
+
*/
|
|
124
|
+
var hideOthers = function (originalTarget, parentNode, markerName) {
|
|
125
|
+
if (markerName === void 0) { markerName = 'data-aria-hidden'; }
|
|
126
|
+
var targets = Array.from(Array.isArray(originalTarget) ? originalTarget : [originalTarget]);
|
|
127
|
+
var activeParentNode = parentNode || getDefaultParent(originalTarget);
|
|
128
|
+
if (!activeParentNode) {
|
|
129
|
+
return function () { return null; };
|
|
130
|
+
}
|
|
131
|
+
// we should not hide aria-live elements - https://github.com/theKashey/aria-hidden/issues/10
|
|
132
|
+
// and script elements, as they have no impact on accessibility.
|
|
133
|
+
targets.push.apply(targets, Array.from(activeParentNode.querySelectorAll('[aria-live], script')));
|
|
134
|
+
return applyAttributeToOthers(targets, activeParentNode, markerName, 'aria-hidden');
|
|
135
|
+
};
|
|
136
|
+
/**
|
|
137
|
+
* Marks everything except given node(or nodes) as inert
|
|
138
|
+
* @param {Element | Element[]} originalTarget - elements to keep on the page
|
|
139
|
+
* @param [parentNode] - top element, defaults to document.body
|
|
140
|
+
* @param {String} [markerName] - a special attribute to mark every node
|
|
141
|
+
* @return {Undo} undo command
|
|
142
|
+
*/
|
|
143
|
+
var inertOthers = function (originalTarget, parentNode, markerName) {
|
|
144
|
+
if (markerName === void 0) { markerName = 'data-inert-ed'; }
|
|
145
|
+
var activeParentNode = parentNode || getDefaultParent(originalTarget);
|
|
146
|
+
if (!activeParentNode) {
|
|
147
|
+
return function () { return null; };
|
|
148
|
+
}
|
|
149
|
+
return applyAttributeToOthers(originalTarget, activeParentNode, markerName, 'inert');
|
|
150
|
+
};
|
|
151
|
+
/**
|
|
152
|
+
* @returns if current browser supports inert
|
|
153
|
+
*/
|
|
154
|
+
var supportsInert = function () {
|
|
155
|
+
return typeof HTMLElement !== 'undefined' && HTMLElement.prototype.hasOwnProperty('inert');
|
|
156
|
+
};
|
|
157
|
+
/**
|
|
158
|
+
* Automatic function to "suppress" DOM elements - _hide_ or _inert_ in the best possible way
|
|
159
|
+
* @param {Element | Element[]} originalTarget - elements to keep on the page
|
|
160
|
+
* @param [parentNode] - top element, defaults to document.body
|
|
161
|
+
* @param {String} [markerName] - a special attribute to mark every node
|
|
162
|
+
* @return {Undo} undo command
|
|
163
|
+
*/
|
|
164
|
+
var suppressOthers = function (originalTarget, parentNode, markerName) {
|
|
165
|
+
if (markerName === void 0) { markerName = 'data-suppressed'; }
|
|
166
|
+
return (supportsInert() ? inertOthers : hideOthers)(originalTarget, parentNode, markerName);
|
|
167
|
+
};
|
|
168
|
+
|
|
169
|
+
export { hideOthers, inertOthers, supportsInert, suppressOthers };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
var currentNonce;
|
|
2
|
+
var setNonce = function (nonce) {
|
|
3
|
+
currentNonce = nonce;
|
|
4
|
+
};
|
|
5
|
+
var getNonce = function () {
|
|
6
|
+
if (currentNonce) {
|
|
7
|
+
return currentNonce;
|
|
8
|
+
}
|
|
9
|
+
if (typeof __webpack_nonce__ !== 'undefined') {
|
|
10
|
+
return __webpack_nonce__;
|
|
11
|
+
}
|
|
12
|
+
return undefined;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export { getNonce, setNonce };
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { __assign } from '../../../tslib/tslib.es6.js';
|
|
2
|
+
import * as React from 'react';
|
|
3
|
+
import { RemoveScroll } from './UI.js';
|
|
4
|
+
import SideCar from './sidecar.js';
|
|
5
|
+
|
|
6
|
+
var ReactRemoveScroll = React.forwardRef(function (props, ref) { return (React.createElement(RemoveScroll, __assign({}, props, { ref: ref, sideCar: SideCar }))); });
|
|
7
|
+
ReactRemoveScroll.classNames = RemoveScroll.classNames;
|
|
8
|
+
|
|
9
|
+
export { ReactRemoveScroll as default };
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
import { __spreadArray } from '../../../tslib/tslib.es6.js';
|
|
2
|
+
import * as React from 'react';
|
|
3
|
+
import '../../../react-remove-scroll-bar/dist/es2015/index.js';
|
|
4
|
+
import '../../../react-style-singleton/dist/es2015/index.js';
|
|
5
|
+
import { nonPassive } from './aggresiveCapture.js';
|
|
6
|
+
import { locationCouldBeScrolled, handleScroll } from './handleScroll.js';
|
|
7
|
+
import { styleSingleton } from '../../../react-style-singleton/dist/es2015/component.js';
|
|
8
|
+
import { RemoveScrollBar } from '../../../react-remove-scroll-bar/dist/es2015/component.js';
|
|
9
|
+
|
|
10
|
+
var getTouchXY = function (event) {
|
|
11
|
+
return 'changedTouches' in event ? [event.changedTouches[0].clientX, event.changedTouches[0].clientY] : [0, 0];
|
|
12
|
+
};
|
|
13
|
+
var getDeltaXY = function (event) { return [event.deltaX, event.deltaY]; };
|
|
14
|
+
var extractRef = function (ref) {
|
|
15
|
+
return ref && 'current' in ref ? ref.current : ref;
|
|
16
|
+
};
|
|
17
|
+
var deltaCompare = function (x, y) { return x[0] === y[0] && x[1] === y[1]; };
|
|
18
|
+
var generateStyle = function (id) { return "\n .block-interactivity-".concat(id, " {pointer-events: none;}\n .allow-interactivity-").concat(id, " {pointer-events: all;}\n"); };
|
|
19
|
+
var idCounter = 0;
|
|
20
|
+
var lockStack = [];
|
|
21
|
+
function RemoveScrollSideCar(props) {
|
|
22
|
+
var shouldPreventQueue = React.useRef([]);
|
|
23
|
+
var touchStartRef = React.useRef([0, 0]);
|
|
24
|
+
var activeAxis = React.useRef();
|
|
25
|
+
var id = React.useState(idCounter++)[0];
|
|
26
|
+
var Style = React.useState(styleSingleton)[0];
|
|
27
|
+
var lastProps = React.useRef(props);
|
|
28
|
+
React.useEffect(function () {
|
|
29
|
+
lastProps.current = props;
|
|
30
|
+
}, [props]);
|
|
31
|
+
React.useEffect(function () {
|
|
32
|
+
if (props.inert) {
|
|
33
|
+
document.body.classList.add("block-interactivity-".concat(id));
|
|
34
|
+
var allow_1 = __spreadArray([props.lockRef.current], (props.shards || []).map(extractRef), true).filter(Boolean);
|
|
35
|
+
allow_1.forEach(function (el) { return el.classList.add("allow-interactivity-".concat(id)); });
|
|
36
|
+
return function () {
|
|
37
|
+
document.body.classList.remove("block-interactivity-".concat(id));
|
|
38
|
+
allow_1.forEach(function (el) { return el.classList.remove("allow-interactivity-".concat(id)); });
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
return;
|
|
42
|
+
}, [props.inert, props.lockRef.current, props.shards]);
|
|
43
|
+
var shouldCancelEvent = React.useCallback(function (event, parent) {
|
|
44
|
+
if (('touches' in event && event.touches.length === 2) || (event.type === 'wheel' && event.ctrlKey)) {
|
|
45
|
+
return !lastProps.current.allowPinchZoom;
|
|
46
|
+
}
|
|
47
|
+
var touch = getTouchXY(event);
|
|
48
|
+
var touchStart = touchStartRef.current;
|
|
49
|
+
var deltaX = 'deltaX' in event ? event.deltaX : touchStart[0] - touch[0];
|
|
50
|
+
var deltaY = 'deltaY' in event ? event.deltaY : touchStart[1] - touch[1];
|
|
51
|
+
var currentAxis;
|
|
52
|
+
var target = event.target;
|
|
53
|
+
var moveDirection = Math.abs(deltaX) > Math.abs(deltaY) ? 'h' : 'v';
|
|
54
|
+
// allow horizontal touch move on Range inputs. They will not cause any scroll
|
|
55
|
+
if ('touches' in event && moveDirection === 'h' && target.type === 'range') {
|
|
56
|
+
return false;
|
|
57
|
+
}
|
|
58
|
+
// allow drag selection (iOS); check if selection's anchorNode is the same as target or contains target
|
|
59
|
+
var selection = window.getSelection();
|
|
60
|
+
var anchorNode = selection && selection.anchorNode;
|
|
61
|
+
var isTouchingSelection = anchorNode ? anchorNode === target || anchorNode.contains(target) : false;
|
|
62
|
+
if (isTouchingSelection) {
|
|
63
|
+
return false;
|
|
64
|
+
}
|
|
65
|
+
var canBeScrolledInMainDirection = locationCouldBeScrolled(moveDirection, target);
|
|
66
|
+
if (!canBeScrolledInMainDirection) {
|
|
67
|
+
return true;
|
|
68
|
+
}
|
|
69
|
+
if (canBeScrolledInMainDirection) {
|
|
70
|
+
currentAxis = moveDirection;
|
|
71
|
+
}
|
|
72
|
+
else {
|
|
73
|
+
currentAxis = moveDirection === 'v' ? 'h' : 'v';
|
|
74
|
+
canBeScrolledInMainDirection = locationCouldBeScrolled(moveDirection, target);
|
|
75
|
+
// other axis might be not scrollable
|
|
76
|
+
}
|
|
77
|
+
if (!canBeScrolledInMainDirection) {
|
|
78
|
+
return false;
|
|
79
|
+
}
|
|
80
|
+
if (!activeAxis.current && 'changedTouches' in event && (deltaX || deltaY)) {
|
|
81
|
+
activeAxis.current = currentAxis;
|
|
82
|
+
}
|
|
83
|
+
if (!currentAxis) {
|
|
84
|
+
return true;
|
|
85
|
+
}
|
|
86
|
+
var cancelingAxis = activeAxis.current || currentAxis;
|
|
87
|
+
return handleScroll(cancelingAxis, parent, event, cancelingAxis === 'h' ? deltaX : deltaY, true);
|
|
88
|
+
}, []);
|
|
89
|
+
var shouldPrevent = React.useCallback(function (_event) {
|
|
90
|
+
var event = _event;
|
|
91
|
+
if (!lockStack.length || lockStack[lockStack.length - 1] !== Style) {
|
|
92
|
+
// not the last active
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
var delta = 'deltaY' in event ? getDeltaXY(event) : getTouchXY(event);
|
|
96
|
+
var sourceEvent = shouldPreventQueue.current.filter(function (e) { return e.name === event.type && (e.target === event.target || event.target === e.shadowParent) && deltaCompare(e.delta, delta); })[0];
|
|
97
|
+
// self event, and should be canceled
|
|
98
|
+
if (sourceEvent && sourceEvent.should) {
|
|
99
|
+
if (event.cancelable) {
|
|
100
|
+
event.preventDefault();
|
|
101
|
+
}
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
// outside or shard event
|
|
105
|
+
if (!sourceEvent) {
|
|
106
|
+
var shardNodes = (lastProps.current.shards || [])
|
|
107
|
+
.map(extractRef)
|
|
108
|
+
.filter(Boolean)
|
|
109
|
+
.filter(function (node) { return node.contains(event.target); });
|
|
110
|
+
var shouldStop = shardNodes.length > 0 ? shouldCancelEvent(event, shardNodes[0]) : !lastProps.current.noIsolation;
|
|
111
|
+
if (shouldStop) {
|
|
112
|
+
if (event.cancelable) {
|
|
113
|
+
event.preventDefault();
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
}, []);
|
|
118
|
+
var shouldCancel = React.useCallback(function (name, delta, target, should) {
|
|
119
|
+
var event = { name: name, delta: delta, target: target, should: should, shadowParent: getOutermostShadowParent(target) };
|
|
120
|
+
shouldPreventQueue.current.push(event);
|
|
121
|
+
setTimeout(function () {
|
|
122
|
+
shouldPreventQueue.current = shouldPreventQueue.current.filter(function (e) { return e !== event; });
|
|
123
|
+
}, 1);
|
|
124
|
+
}, []);
|
|
125
|
+
var scrollTouchStart = React.useCallback(function (event) {
|
|
126
|
+
touchStartRef.current = getTouchXY(event);
|
|
127
|
+
activeAxis.current = undefined;
|
|
128
|
+
}, []);
|
|
129
|
+
var scrollWheel = React.useCallback(function (event) {
|
|
130
|
+
shouldCancel(event.type, getDeltaXY(event), event.target, shouldCancelEvent(event, props.lockRef.current));
|
|
131
|
+
}, []);
|
|
132
|
+
var scrollTouchMove = React.useCallback(function (event) {
|
|
133
|
+
shouldCancel(event.type, getTouchXY(event), event.target, shouldCancelEvent(event, props.lockRef.current));
|
|
134
|
+
}, []);
|
|
135
|
+
React.useEffect(function () {
|
|
136
|
+
lockStack.push(Style);
|
|
137
|
+
props.setCallbacks({
|
|
138
|
+
onScrollCapture: scrollWheel,
|
|
139
|
+
onWheelCapture: scrollWheel,
|
|
140
|
+
onTouchMoveCapture: scrollTouchMove,
|
|
141
|
+
});
|
|
142
|
+
document.addEventListener('wheel', shouldPrevent, nonPassive);
|
|
143
|
+
document.addEventListener('touchmove', shouldPrevent, nonPassive);
|
|
144
|
+
document.addEventListener('touchstart', scrollTouchStart, nonPassive);
|
|
145
|
+
return function () {
|
|
146
|
+
lockStack = lockStack.filter(function (inst) { return inst !== Style; });
|
|
147
|
+
document.removeEventListener('wheel', shouldPrevent, nonPassive);
|
|
148
|
+
document.removeEventListener('touchmove', shouldPrevent, nonPassive);
|
|
149
|
+
document.removeEventListener('touchstart', scrollTouchStart, nonPassive);
|
|
150
|
+
};
|
|
151
|
+
}, []);
|
|
152
|
+
var removeScrollBar = props.removeScrollBar, inert = props.inert;
|
|
153
|
+
return (React.createElement(React.Fragment, null,
|
|
154
|
+
inert ? React.createElement(Style, { styles: generateStyle(id) }) : null,
|
|
155
|
+
removeScrollBar ? React.createElement(RemoveScrollBar, { noRelative: props.noRelative, gapMode: props.gapMode }) : null));
|
|
156
|
+
}
|
|
157
|
+
function getOutermostShadowParent(node) {
|
|
158
|
+
var shadowParent = null;
|
|
159
|
+
while (node !== null) {
|
|
160
|
+
if (node instanceof ShadowRoot) {
|
|
161
|
+
shadowParent = node.host;
|
|
162
|
+
node = node.host;
|
|
163
|
+
}
|
|
164
|
+
node = node.parentNode;
|
|
165
|
+
}
|
|
166
|
+
return shadowParent;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
export { RemoveScrollSideCar, getDeltaXY, getTouchXY };
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { __rest, __assign } from '../../../tslib/tslib.es6.js';
|
|
2
|
+
import * as React from 'react';
|
|
3
|
+
import { fullWidthClassName, zeroRightClassName } from '../../../react-remove-scroll-bar/dist/es2015/constants.js';
|
|
4
|
+
import '../../../use-callback-ref/dist/es2015/index.js';
|
|
5
|
+
import { effectCar } from './medium.js';
|
|
6
|
+
import { useMergeRefs } from '../../../use-callback-ref/dist/es2015/useMergeRef.js';
|
|
7
|
+
|
|
8
|
+
var nothing = function () {
|
|
9
|
+
return;
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* Removes scrollbar from the page and contain the scroll within the Lock
|
|
13
|
+
*/
|
|
14
|
+
var RemoveScroll = React.forwardRef(function (props, parentRef) {
|
|
15
|
+
var ref = React.useRef(null);
|
|
16
|
+
var _a = React.useState({
|
|
17
|
+
onScrollCapture: nothing,
|
|
18
|
+
onWheelCapture: nothing,
|
|
19
|
+
onTouchMoveCapture: nothing,
|
|
20
|
+
}), callbacks = _a[0], setCallbacks = _a[1];
|
|
21
|
+
var forwardProps = props.forwardProps, children = props.children, className = props.className, removeScrollBar = props.removeScrollBar, enabled = props.enabled, shards = props.shards, sideCar = props.sideCar, noRelative = props.noRelative, noIsolation = props.noIsolation, inert = props.inert, allowPinchZoom = props.allowPinchZoom, _b = props.as, Container = _b === void 0 ? 'div' : _b, gapMode = props.gapMode, rest = __rest(props, ["forwardProps", "children", "className", "removeScrollBar", "enabled", "shards", "sideCar", "noRelative", "noIsolation", "inert", "allowPinchZoom", "as", "gapMode"]);
|
|
22
|
+
var SideCar = sideCar;
|
|
23
|
+
var containerRef = useMergeRefs([ref, parentRef]);
|
|
24
|
+
var containerProps = __assign(__assign({}, rest), callbacks);
|
|
25
|
+
return (React.createElement(React.Fragment, null,
|
|
26
|
+
enabled && (React.createElement(SideCar, { sideCar: effectCar, removeScrollBar: removeScrollBar, shards: shards, noRelative: noRelative, noIsolation: noIsolation, inert: inert, setCallbacks: setCallbacks, allowPinchZoom: !!allowPinchZoom, lockRef: ref, gapMode: gapMode })),
|
|
27
|
+
forwardProps ? (React.cloneElement(React.Children.only(children), __assign(__assign({}, containerProps), { ref: containerRef }))) : (React.createElement(Container, __assign({}, containerProps, { className: className, ref: containerRef }), children))));
|
|
28
|
+
});
|
|
29
|
+
RemoveScroll.defaultProps = {
|
|
30
|
+
enabled: true,
|
|
31
|
+
removeScrollBar: true,
|
|
32
|
+
inert: false,
|
|
33
|
+
};
|
|
34
|
+
RemoveScroll.classNames = {
|
|
35
|
+
fullWidth: fullWidthClassName,
|
|
36
|
+
zeroRight: zeroRightClassName,
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
export { RemoveScroll };
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
var passiveSupported = false;
|
|
2
|
+
if (typeof window !== 'undefined') {
|
|
3
|
+
try {
|
|
4
|
+
var options = Object.defineProperty({}, 'passive', {
|
|
5
|
+
get: function () {
|
|
6
|
+
passiveSupported = true;
|
|
7
|
+
return true;
|
|
8
|
+
},
|
|
9
|
+
});
|
|
10
|
+
// @ts-ignore
|
|
11
|
+
window.addEventListener('test', options, options);
|
|
12
|
+
// @ts-ignore
|
|
13
|
+
window.removeEventListener('test', options, options);
|
|
14
|
+
}
|
|
15
|
+
catch (err) {
|
|
16
|
+
passiveSupported = false;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
var nonPassive = passiveSupported ? { passive: false } : false;
|
|
20
|
+
|
|
21
|
+
export { nonPassive };
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
var alwaysContainsScroll = function (node) {
|
|
2
|
+
// textarea will always _contain_ scroll inside self. It only can be hidden
|
|
3
|
+
return node.tagName === 'TEXTAREA';
|
|
4
|
+
};
|
|
5
|
+
var elementCanBeScrolled = function (node, overflow) {
|
|
6
|
+
if (!(node instanceof Element)) {
|
|
7
|
+
return false;
|
|
8
|
+
}
|
|
9
|
+
var styles = window.getComputedStyle(node);
|
|
10
|
+
return (
|
|
11
|
+
// not-not-scrollable
|
|
12
|
+
styles[overflow] !== 'hidden' &&
|
|
13
|
+
// contains scroll inside self
|
|
14
|
+
!(styles.overflowY === styles.overflowX && !alwaysContainsScroll(node) && styles[overflow] === 'visible'));
|
|
15
|
+
};
|
|
16
|
+
var elementCouldBeVScrolled = function (node) { return elementCanBeScrolled(node, 'overflowY'); };
|
|
17
|
+
var elementCouldBeHScrolled = function (node) { return elementCanBeScrolled(node, 'overflowX'); };
|
|
18
|
+
var locationCouldBeScrolled = function (axis, node) {
|
|
19
|
+
var ownerDocument = node.ownerDocument;
|
|
20
|
+
var current = node;
|
|
21
|
+
do {
|
|
22
|
+
// Skip over shadow root
|
|
23
|
+
if (typeof ShadowRoot !== 'undefined' && current instanceof ShadowRoot) {
|
|
24
|
+
current = current.host;
|
|
25
|
+
}
|
|
26
|
+
var isScrollable = elementCouldBeScrolled(axis, current);
|
|
27
|
+
if (isScrollable) {
|
|
28
|
+
var _a = getScrollVariables(axis, current), scrollHeight = _a[1], clientHeight = _a[2];
|
|
29
|
+
if (scrollHeight > clientHeight) {
|
|
30
|
+
return true;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
current = current.parentNode;
|
|
34
|
+
} while (current && current !== ownerDocument.body);
|
|
35
|
+
return false;
|
|
36
|
+
};
|
|
37
|
+
var getVScrollVariables = function (_a) {
|
|
38
|
+
var scrollTop = _a.scrollTop, scrollHeight = _a.scrollHeight, clientHeight = _a.clientHeight;
|
|
39
|
+
return [
|
|
40
|
+
scrollTop,
|
|
41
|
+
scrollHeight,
|
|
42
|
+
clientHeight,
|
|
43
|
+
];
|
|
44
|
+
};
|
|
45
|
+
var getHScrollVariables = function (_a) {
|
|
46
|
+
var scrollLeft = _a.scrollLeft, scrollWidth = _a.scrollWidth, clientWidth = _a.clientWidth;
|
|
47
|
+
return [
|
|
48
|
+
scrollLeft,
|
|
49
|
+
scrollWidth,
|
|
50
|
+
clientWidth,
|
|
51
|
+
];
|
|
52
|
+
};
|
|
53
|
+
var elementCouldBeScrolled = function (axis, node) {
|
|
54
|
+
return axis === 'v' ? elementCouldBeVScrolled(node) : elementCouldBeHScrolled(node);
|
|
55
|
+
};
|
|
56
|
+
var getScrollVariables = function (axis, node) {
|
|
57
|
+
return axis === 'v' ? getVScrollVariables(node) : getHScrollVariables(node);
|
|
58
|
+
};
|
|
59
|
+
var getDirectionFactor = function (axis, direction) {
|
|
60
|
+
/**
|
|
61
|
+
* If the element's direction is rtl (right-to-left), then scrollLeft is 0 when the scrollbar is at its rightmost position,
|
|
62
|
+
* and then increasingly negative as you scroll towards the end of the content.
|
|
63
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/Element/scrollLeft
|
|
64
|
+
*/
|
|
65
|
+
return axis === 'h' && direction === 'rtl' ? -1 : 1;
|
|
66
|
+
};
|
|
67
|
+
var handleScroll = function (axis, endTarget, event, sourceDelta, noOverscroll) {
|
|
68
|
+
var directionFactor = getDirectionFactor(axis, window.getComputedStyle(endTarget).direction);
|
|
69
|
+
var delta = directionFactor * sourceDelta;
|
|
70
|
+
// find scrollable target
|
|
71
|
+
var target = event.target;
|
|
72
|
+
var targetInLock = endTarget.contains(target);
|
|
73
|
+
var shouldCancelScroll = false;
|
|
74
|
+
var isDeltaPositive = delta > 0;
|
|
75
|
+
var availableScroll = 0;
|
|
76
|
+
var availableScrollTop = 0;
|
|
77
|
+
do {
|
|
78
|
+
if (!target) {
|
|
79
|
+
break;
|
|
80
|
+
}
|
|
81
|
+
var _a = getScrollVariables(axis, target), position = _a[0], scroll_1 = _a[1], capacity = _a[2];
|
|
82
|
+
var elementScroll = scroll_1 - capacity - directionFactor * position;
|
|
83
|
+
if (position || elementScroll) {
|
|
84
|
+
if (elementCouldBeScrolled(axis, target)) {
|
|
85
|
+
availableScroll += elementScroll;
|
|
86
|
+
availableScrollTop += position;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
var parent_1 = target.parentNode;
|
|
90
|
+
// we will "bubble" from ShadowDom in case we are, or just to the parent in normal case
|
|
91
|
+
// this is the same logic used in focus-lock
|
|
92
|
+
target = (parent_1 && parent_1.nodeType === Node.DOCUMENT_FRAGMENT_NODE ? parent_1.host : parent_1);
|
|
93
|
+
} while (
|
|
94
|
+
// portaled content
|
|
95
|
+
(!targetInLock && target !== document.body) ||
|
|
96
|
+
// self content
|
|
97
|
+
(targetInLock && (endTarget.contains(target) || endTarget === target)));
|
|
98
|
+
// handle epsilon around 0 (non standard zoom levels)
|
|
99
|
+
if (isDeltaPositive &&
|
|
100
|
+
((noOverscroll && Math.abs(availableScroll) < 1) || (!noOverscroll && delta > availableScroll))) {
|
|
101
|
+
shouldCancelScroll = true;
|
|
102
|
+
}
|
|
103
|
+
else if (!isDeltaPositive &&
|
|
104
|
+
((noOverscroll && Math.abs(availableScrollTop) < 1) || (!noOverscroll && -delta > availableScrollTop))) {
|
|
105
|
+
shouldCancelScroll = true;
|
|
106
|
+
}
|
|
107
|
+
return shouldCancelScroll;
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
export { handleScroll, locationCouldBeScrolled };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default as RemoveScroll } from './Combination.js';
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import '../../../use-sidecar/dist/es2015/index.js';
|
|
2
|
+
import { RemoveScrollSideCar } from './SideEffect.js';
|
|
3
|
+
import { effectCar } from './medium.js';
|
|
4
|
+
import { exportSidecar } from '../../../use-sidecar/dist/es2015/exports.js';
|
|
5
|
+
|
|
6
|
+
var SideCar = exportSidecar(effectCar, RemoveScrollSideCar);
|
|
7
|
+
|
|
8
|
+
export { SideCar as default };
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import '../../../react-style-singleton/dist/es2015/index.js';
|
|
3
|
+
import { noScrollbarsClassName, zeroRightClassName, fullWidthClassName, removedBarSizeVariable } from './constants.js';
|
|
4
|
+
import { getGapWidth } from './utils.js';
|
|
5
|
+
import { styleSingleton } from '../../../react-style-singleton/dist/es2015/component.js';
|
|
6
|
+
|
|
7
|
+
var Style = styleSingleton();
|
|
8
|
+
var lockAttribute = 'data-scroll-locked';
|
|
9
|
+
// important tip - once we measure scrollBar width and remove them
|
|
10
|
+
// we could not repeat this operation
|
|
11
|
+
// thus we are using style-singleton - only the first "yet correct" style will be applied.
|
|
12
|
+
var getStyles = function (_a, allowRelative, gapMode, important) {
|
|
13
|
+
var left = _a.left, top = _a.top, right = _a.right, gap = _a.gap;
|
|
14
|
+
if (gapMode === void 0) { gapMode = 'margin'; }
|
|
15
|
+
return "\n .".concat(noScrollbarsClassName, " {\n overflow: hidden ").concat(important, ";\n padding-right: ").concat(gap, "px ").concat(important, ";\n }\n body[").concat(lockAttribute, "] {\n overflow: hidden ").concat(important, ";\n overscroll-behavior: contain;\n ").concat([
|
|
16
|
+
allowRelative && "position: relative ".concat(important, ";"),
|
|
17
|
+
gapMode === 'margin' &&
|
|
18
|
+
"\n padding-left: ".concat(left, "px;\n padding-top: ").concat(top, "px;\n padding-right: ").concat(right, "px;\n margin-left:0;\n margin-top:0;\n margin-right: ").concat(gap, "px ").concat(important, ";\n "),
|
|
19
|
+
gapMode === 'padding' && "padding-right: ".concat(gap, "px ").concat(important, ";"),
|
|
20
|
+
]
|
|
21
|
+
.filter(Boolean)
|
|
22
|
+
.join(''), "\n }\n \n .").concat(zeroRightClassName, " {\n right: ").concat(gap, "px ").concat(important, ";\n }\n \n .").concat(fullWidthClassName, " {\n margin-right: ").concat(gap, "px ").concat(important, ";\n }\n \n .").concat(zeroRightClassName, " .").concat(zeroRightClassName, " {\n right: 0 ").concat(important, ";\n }\n \n .").concat(fullWidthClassName, " .").concat(fullWidthClassName, " {\n margin-right: 0 ").concat(important, ";\n }\n \n body[").concat(lockAttribute, "] {\n ").concat(removedBarSizeVariable, ": ").concat(gap, "px;\n }\n");
|
|
23
|
+
};
|
|
24
|
+
var getCurrentUseCounter = function () {
|
|
25
|
+
var counter = parseInt(document.body.getAttribute(lockAttribute) || '0', 10);
|
|
26
|
+
return isFinite(counter) ? counter : 0;
|
|
27
|
+
};
|
|
28
|
+
var useLockAttribute = function () {
|
|
29
|
+
React.useEffect(function () {
|
|
30
|
+
document.body.setAttribute(lockAttribute, (getCurrentUseCounter() + 1).toString());
|
|
31
|
+
return function () {
|
|
32
|
+
var newCounter = getCurrentUseCounter() - 1;
|
|
33
|
+
if (newCounter <= 0) {
|
|
34
|
+
document.body.removeAttribute(lockAttribute);
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
document.body.setAttribute(lockAttribute, newCounter.toString());
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
}, []);
|
|
41
|
+
};
|
|
42
|
+
/**
|
|
43
|
+
* Removes page scrollbar and blocks page scroll when mounted
|
|
44
|
+
*/
|
|
45
|
+
var RemoveScrollBar = function (_a) {
|
|
46
|
+
var noRelative = _a.noRelative, noImportant = _a.noImportant, _b = _a.gapMode, gapMode = _b === void 0 ? 'margin' : _b;
|
|
47
|
+
useLockAttribute();
|
|
48
|
+
/*
|
|
49
|
+
gap will be measured on every component mount
|
|
50
|
+
however it will be used only by the "first" invocation
|
|
51
|
+
due to singleton nature of <Style
|
|
52
|
+
*/
|
|
53
|
+
var gap = React.useMemo(function () { return getGapWidth(gapMode); }, [gapMode]);
|
|
54
|
+
return React.createElement(Style, { styles: getStyles(gap, !noRelative, gapMode, !noImportant ? '!important' : '') });
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
export { RemoveScrollBar, lockAttribute, useLockAttribute };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
var zeroRightClassName = 'right-scroll-bar-position';
|
|
2
|
+
var fullWidthClassName = 'width-before-scroll-bar';
|
|
3
|
+
var noScrollbarsClassName = 'with-scroll-bars-hidden';
|
|
4
|
+
/**
|
|
5
|
+
* Name of a CSS variable containing the amount of "hidden" scrollbar
|
|
6
|
+
* ! might be undefined ! use will fallback!
|
|
7
|
+
*/
|
|
8
|
+
var removedBarSizeVariable = '--removed-body-scroll-bar-size';
|
|
9
|
+
|
|
10
|
+
export { fullWidthClassName, noScrollbarsClassName, removedBarSizeVariable, zeroRightClassName };
|