@atlaskit/react-select 2.3.0 → 2.4.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.
Files changed (33) hide show
  1. package/CHANGELOG.md +22 -0
  2. package/dist/cjs/compiled/components/group.js +1 -1
  3. package/dist/cjs/components/menu.js +5 -225
  4. package/dist/cjs/emotion/components/group.js +1 -1
  5. package/dist/cjs/emotion/components/internal/index.js +34 -0
  6. package/dist/cjs/emotion/components/internal/scroll-manager.js +59 -0
  7. package/dist/cjs/emotion/components/internal/use-scroll-capture.js +132 -0
  8. package/dist/cjs/emotion/components/internal/use-scroll-lock.js +149 -0
  9. package/dist/es2019/compiled/components/group.js +1 -1
  10. package/dist/es2019/components/menu.js +4 -224
  11. package/dist/es2019/emotion/components/group.js +1 -1
  12. package/dist/es2019/emotion/components/internal/index.js +4 -0
  13. package/dist/es2019/emotion/components/internal/scroll-manager.js +51 -0
  14. package/dist/es2019/emotion/components/internal/use-scroll-capture.js +128 -0
  15. package/dist/es2019/emotion/components/internal/use-scroll-lock.js +143 -0
  16. package/dist/esm/compiled/components/group.js +1 -1
  17. package/dist/esm/components/menu.js +6 -228
  18. package/dist/esm/emotion/components/group.js +1 -1
  19. package/dist/esm/emotion/components/internal/index.js +4 -0
  20. package/dist/esm/emotion/components/internal/scroll-manager.js +51 -0
  21. package/dist/esm/emotion/components/internal/use-scroll-capture.js +126 -0
  22. package/dist/esm/emotion/components/internal/use-scroll-lock.js +143 -0
  23. package/dist/types/components/menu.d.ts +1 -1
  24. package/dist/types/emotion/components/internal/index.d.ts +4 -0
  25. package/dist/types/emotion/components/internal/scroll-manager.d.ts +17 -0
  26. package/dist/types/emotion/components/internal/use-scroll-capture.d.ts +12 -0
  27. package/dist/types/emotion/components/internal/use-scroll-lock.d.ts +9 -0
  28. package/dist/types-ts4.5/components/menu.d.ts +1 -1
  29. package/dist/types-ts4.5/emotion/components/internal/index.d.ts +4 -0
  30. package/dist/types-ts4.5/emotion/components/internal/scroll-manager.d.ts +17 -0
  31. package/dist/types-ts4.5/emotion/components/internal/use-scroll-capture.d.ts +12 -0
  32. package/dist/types-ts4.5/emotion/components/internal/use-scroll-lock.d.ts +9 -0
  33. package/package.json +3 -3
@@ -1,243 +1,21 @@
1
1
  import _objectDestructuringEmpty from "@babel/runtime/helpers/objectDestructuringEmpty";
2
- import _defineProperty from "@babel/runtime/helpers/defineProperty";
3
- import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
4
- function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
5
- function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
6
2
  /* eslint-disable @repo/internal/react/no-unsafe-spread-props */
7
- import React, { createContext, useContext, useRef, useState } from 'react';
8
- import useLayoutEffect from 'use-isomorphic-layout-effect';
3
+ import React from 'react';
9
4
  import { fg } from '@atlaskit/platform-feature-flags';
10
- import Compiled, { LoadingMessage as CompiledLoadingMessage, menuCSS as compiledMenuCSS, MenuList as CompiledMenuList, menuListCSS as compiledMenuListCSS, MenuPortal as CompiledMenuPortal, menuPortalCSS as compiledMenuPortalCSS, NoOptionsMessage as CompiledNoOptionsMessage } from '../compiled/components/menu';
11
- import Emotion, { LoadingMessage as EmotionLoadingMessage, menuCSS as emotionMenuCSS, MenuList as EmotionMenuList, menuListCSS as emotionMenuListCSS, MenuPortal as EmotionMenuPortal, menuPortalCSS as emotionMenuPortalCSS, NoOptionsMessage as EmotionNoOptionsMessage } from '../emotion/components/menu';
12
- import { animatedScrollTo, getScrollParent, getScrollTop, normalizedHeight, scrollTo } from '../utils';
13
-
14
- // ==============================
15
- // Menu
16
- // ==============================
17
-
18
- // Get Menu Placement
19
- // ------------------------------
20
-
21
- function getMenuPlacement(_ref) {
22
- var preferredMaxHeight = _ref.maxHeight,
23
- menuEl = _ref.menuEl,
24
- minHeight = _ref.minHeight,
25
- preferredPlacement = _ref.placement,
26
- shouldScroll = _ref.shouldScroll,
27
- isFixedPosition = _ref.isFixedPosition,
28
- controlHeight = _ref.controlHeight;
29
- var scrollParent = getScrollParent(menuEl);
30
- var defaultState = {
31
- placement: 'bottom',
32
- maxHeight: preferredMaxHeight
33
- };
34
-
35
- // something went wrong, return default state
36
- if (!menuEl || !menuEl.offsetParent) {
37
- return defaultState;
38
- }
39
-
40
- // we can't trust `scrollParent.scrollHeight` --> it may increase when
41
- // the menu is rendered
42
- var _scrollParent$getBoun = scrollParent.getBoundingClientRect(),
43
- scrollHeight = _scrollParent$getBoun.height,
44
- scrollParentTop = _scrollParent$getBoun.top;
45
- var _menuEl$getBoundingCl = menuEl.getBoundingClientRect(),
46
- menuBottom = _menuEl$getBoundingCl.bottom,
47
- menuHeight = _menuEl$getBoundingCl.height,
48
- menuTop = _menuEl$getBoundingCl.top;
49
- var _menuEl$offsetParent$ = menuEl.offsetParent.getBoundingClientRect(),
50
- containerTop = _menuEl$offsetParent$.top;
51
- var viewHeight = isFixedPosition ? window.innerHeight : normalizedHeight(scrollParent);
52
- var scrollTop = getScrollTop(scrollParent);
53
- // use menuTop - scrollParentTop for the actual top space of menu in the scroll container
54
- var menuTopFromParent = fg('design-system-select-fix-placement') ? menuTop - scrollParentTop : menuTop;
55
- var marginBottom = parseInt(getComputedStyle(menuEl).marginBottom, 10);
56
- var marginTop = parseInt(getComputedStyle(menuEl).marginTop, 10);
57
- var viewSpaceAbove = containerTop - marginTop;
58
- var viewSpaceBelow = viewHeight - menuTopFromParent;
59
- var scrollSpaceAbove = viewSpaceAbove + scrollTop;
60
- var scrollSpaceBelow = scrollHeight - scrollTop - menuTopFromParent;
61
- var scrollDown = menuBottom - viewHeight + scrollTop + marginBottom;
62
- var scrollUp = scrollTop + menuTop - marginTop;
63
- var scrollDuration = 160;
64
- switch (preferredPlacement) {
65
- case 'auto':
66
- case 'bottom':
67
- // 1: the menu will fit, do nothing
68
- if (viewSpaceBelow >= menuHeight) {
69
- return {
70
- placement: 'bottom',
71
- maxHeight: preferredMaxHeight
72
- };
73
- }
74
-
75
- // 2: the menu will fit, if scrolled
76
- if (scrollSpaceBelow >= menuHeight && !isFixedPosition) {
77
- if (shouldScroll) {
78
- animatedScrollTo(scrollParent, scrollDown, scrollDuration);
79
- }
80
- return {
81
- placement: 'bottom',
82
- maxHeight: preferredMaxHeight
83
- };
84
- }
85
-
86
- // 3: the menu will fit, if constrained
87
- if (!isFixedPosition && scrollSpaceBelow >= minHeight || isFixedPosition && viewSpaceBelow >= minHeight) {
88
- if (shouldScroll) {
89
- animatedScrollTo(scrollParent, scrollDown, scrollDuration);
90
- }
91
-
92
- // we want to provide as much of the menu as possible to the user,
93
- // so give them whatever is available below rather than the minHeight.
94
- var constrainedHeight = isFixedPosition ? viewSpaceBelow - marginBottom : scrollSpaceBelow - marginBottom;
95
- return {
96
- placement: 'bottom',
97
- maxHeight: constrainedHeight
98
- };
99
- }
100
-
101
- // 4. Forked beviour when there isn't enough space below
102
-
103
- // AUTO: flip the menu, render above
104
- if (preferredPlacement === 'auto' || isFixedPosition) {
105
- // may need to be constrained after flipping
106
- var _constrainedHeight = preferredMaxHeight;
107
- var spaceAbove = isFixedPosition ? viewSpaceAbove : scrollSpaceAbove;
108
- if (spaceAbove >= minHeight) {
109
- _constrainedHeight = Math.min(spaceAbove - marginBottom - controlHeight, preferredMaxHeight);
110
- }
111
- return {
112
- placement: 'top',
113
- maxHeight: _constrainedHeight
114
- };
115
- }
116
-
117
- // BOTTOM: allow browser to increase scrollable area and immediately set scroll
118
- if (preferredPlacement === 'bottom') {
119
- if (shouldScroll) {
120
- scrollTo(scrollParent, scrollDown);
121
- }
122
- return {
123
- placement: 'bottom',
124
- maxHeight: preferredMaxHeight
125
- };
126
- }
127
- break;
128
- case 'top':
129
- // 1: the menu will fit, do nothing
130
- if (viewSpaceAbove >= menuHeight) {
131
- return {
132
- placement: 'top',
133
- maxHeight: preferredMaxHeight
134
- };
135
- }
136
-
137
- // 2: the menu will fit, if scrolled
138
- if (scrollSpaceAbove >= menuHeight && !isFixedPosition) {
139
- if (shouldScroll) {
140
- animatedScrollTo(scrollParent, scrollUp, scrollDuration);
141
- }
142
- return {
143
- placement: 'top',
144
- maxHeight: preferredMaxHeight
145
- };
146
- }
147
-
148
- // 3: the menu will fit, if constrained
149
- if (!isFixedPosition && scrollSpaceAbove >= minHeight || isFixedPosition && viewSpaceAbove >= minHeight) {
150
- var _constrainedHeight2 = preferredMaxHeight;
151
-
152
- // we want to provide as much of the menu as possible to the user,
153
- // so give them whatever is available below rather than the minHeight.
154
- if (!isFixedPosition && scrollSpaceAbove >= minHeight || isFixedPosition && viewSpaceAbove >= minHeight) {
155
- _constrainedHeight2 = isFixedPosition ? viewSpaceAbove - marginTop : scrollSpaceAbove - marginTop;
156
- }
157
- if (shouldScroll) {
158
- animatedScrollTo(scrollParent, scrollUp, scrollDuration);
159
- }
160
- return {
161
- placement: 'top',
162
- maxHeight: _constrainedHeight2
163
- };
164
- }
165
-
166
- // 4. not enough space, the browser WILL NOT increase scrollable area when
167
- // absolutely positioned element rendered above the viewport (only below).
168
- // Flip the menu, render below
169
- return {
170
- placement: 'bottom',
171
- maxHeight: preferredMaxHeight
172
- };
173
- default:
174
- throw new Error("Invalid placement provided \"".concat(preferredPlacement, "\"."));
175
- }
176
- return defaultState;
177
- }
5
+ import Compiled, { LoadingMessage as CompiledLoadingMessage, menuCSS as compiledMenuCSS, MenuList as CompiledMenuList, menuListCSS as compiledMenuListCSS, MenuPlacer as CompiledMenuPlacer, MenuPortal as CompiledMenuPortal, menuPortalCSS as compiledMenuPortalCSS, NoOptionsMessage as CompiledNoOptionsMessage } from '../compiled/components/menu';
6
+ import Emotion, { LoadingMessage as EmotionLoadingMessage, menuCSS as emotionMenuCSS, MenuList as EmotionMenuList, menuListCSS as emotionMenuListCSS, MenuPlacer as EmotionMenuPlacer, MenuPortal as EmotionMenuPortal, menuPortalCSS as emotionMenuPortalCSS, NoOptionsMessage as EmotionNoOptionsMessage } from '../emotion/components/menu';
178
7
 
179
8
  // Menu Component
180
9
  // ------------------------------
181
10
 
182
- var coercePlacement = function coercePlacement(p) {
183
- return p === 'auto' ? 'bottom' : p;
184
- };
185
11
  export var menuCSS = function menuCSS(props) {
186
12
  return fg('compiled-react-select') ? compiledMenuCSS() : emotionMenuCSS(props);
187
13
  };
188
- var PortalPlacementContext = /*#__PURE__*/createContext(null);
189
14
 
190
15
  // NOTE: internal only
191
16
  // eslint-disable-next-line @repo/internal/react/require-jsdoc
192
17
  export var MenuPlacer = function MenuPlacer(props) {
193
- var children = props.children,
194
- minMenuHeight = props.minMenuHeight,
195
- maxMenuHeight = props.maxMenuHeight,
196
- menuPlacement = props.menuPlacement,
197
- menuPosition = props.menuPosition,
198
- menuShouldScrollIntoView = props.menuShouldScrollIntoView;
199
- var _ref2 = useContext(PortalPlacementContext) || {},
200
- setPortalPlacement = _ref2.setPortalPlacement;
201
- var ref = useRef(null);
202
- var _useState = useState(maxMenuHeight),
203
- _useState2 = _slicedToArray(_useState, 2),
204
- maxHeight = _useState2[0],
205
- setMaxHeight = _useState2[1];
206
- var _useState3 = useState(null),
207
- _useState4 = _slicedToArray(_useState3, 2),
208
- placement = _useState4[0],
209
- setPlacement = _useState4[1];
210
- // The minimum height of the control
211
- var controlHeight = 38;
212
- useLayoutEffect(function () {
213
- var menuEl = ref.current;
214
- if (!menuEl) {
215
- return;
216
- }
217
-
218
- // DO NOT scroll if position is fixed
219
- var isFixedPosition = menuPosition === 'fixed';
220
- var shouldScroll = menuShouldScrollIntoView && !isFixedPosition;
221
- var state = getMenuPlacement({
222
- maxHeight: maxMenuHeight,
223
- menuEl: menuEl,
224
- minHeight: minMenuHeight,
225
- placement: menuPlacement,
226
- shouldScroll: shouldScroll,
227
- isFixedPosition: isFixedPosition,
228
- controlHeight: controlHeight
229
- });
230
- setMaxHeight(state.maxHeight);
231
- setPlacement(state.placement);
232
- setPortalPlacement === null || setPortalPlacement === void 0 || setPortalPlacement(state.placement);
233
- }, [maxMenuHeight, menuPlacement, menuPosition, menuShouldScrollIntoView, minMenuHeight, setPortalPlacement, controlHeight]);
234
- return children({
235
- ref: ref,
236
- placerProps: _objectSpread(_objectSpread({}, props), {}, {
237
- placement: placement || coercePlacement(menuPlacement),
238
- maxHeight: maxHeight
239
- })
240
- });
18
+ return fg('compiled-react-select') ? /*#__PURE__*/React.createElement(CompiledMenuPlacer, props) : /*#__PURE__*/React.createElement(EmotionMenuPlacer, props);
241
19
  };
242
20
  var Menu = function Menu(props) {
243
21
  return fg('compiled-react-select') ? /*#__PURE__*/React.createElement(Compiled, props) : /*#__PURE__*/React.createElement(Emotion, props);
@@ -263,8 +41,8 @@ export var MenuList = function MenuList(props) {
263
41
  // Menu Notices
264
42
  // ==============================
265
43
 
266
- var noticeCSS = function noticeCSS(_ref3) {
267
- _objectDestructuringEmpty(_ref3);
44
+ var noticeCSS = function noticeCSS(_ref) {
45
+ _objectDestructuringEmpty(_ref);
268
46
  return {
269
47
  textAlign: 'center',
270
48
  padding: "var(--ds-space-100, 8px)".concat(" ", "var(--ds-space-150, 12px)")
@@ -29,7 +29,7 @@ var Group = function Group(props) {
29
29
  selectProps = props.selectProps;
30
30
  return jsx("div", _extends({}, getStyleProps(props, 'group', {
31
31
  group: true
32
- }), innerProps), jsx(Heading, _extends({}, headingProps, {
32
+ }), innerProps), label && jsx(Heading, _extends({}, headingProps, {
33
33
  selectProps: selectProps,
34
34
  getStyles: getStyles,
35
35
  getClassNames: getClassNames,
@@ -0,0 +1,4 @@
1
+ export { default as A11yText } from './a11y-text';
2
+ export { default as DummyInput } from './dummy-input';
3
+ export { default as ScrollManager } from './scroll-manager';
4
+ export { default as RequiredInput } from './required-input';
@@ -0,0 +1,51 @@
1
+ /**
2
+ * @jsxRuntime classic
3
+ * @jsx jsx
4
+ */
5
+ import { Fragment } from 'react';
6
+
7
+ // eslint-disable-next-line @atlaskit/ui-styling-standard/use-compiled
8
+ import { css, jsx } from '@emotion/react';
9
+ import useScrollCapture from './use-scroll-capture';
10
+ import useScrollLock from './use-scroll-lock';
11
+ var styles = css({
12
+ position: 'fixed',
13
+ insetBlockEnd: 0,
14
+ insetBlockStart: 0,
15
+ insetInlineEnd: 0,
16
+ insetInlineStart: 0
17
+ });
18
+ var blurSelectInput = function blurSelectInput(event) {
19
+ var element = event.target;
20
+ return element.ownerDocument.activeElement && element.ownerDocument.activeElement.blur();
21
+ };
22
+ export default function ScrollManager(_ref) {
23
+ var children = _ref.children,
24
+ lockEnabled = _ref.lockEnabled,
25
+ _ref$captureEnabled = _ref.captureEnabled,
26
+ captureEnabled = _ref$captureEnabled === void 0 ? true : _ref$captureEnabled,
27
+ onBottomArrive = _ref.onBottomArrive,
28
+ onBottomLeave = _ref.onBottomLeave,
29
+ onTopArrive = _ref.onTopArrive,
30
+ onTopLeave = _ref.onTopLeave;
31
+ var setScrollCaptureTarget = useScrollCapture({
32
+ isEnabled: captureEnabled,
33
+ onBottomArrive: onBottomArrive,
34
+ onBottomLeave: onBottomLeave,
35
+ onTopArrive: onTopArrive,
36
+ onTopLeave: onTopLeave
37
+ });
38
+ var setScrollLockTarget = useScrollLock({
39
+ isEnabled: lockEnabled
40
+ });
41
+ var targetRef = function targetRef(element) {
42
+ setScrollCaptureTarget(element);
43
+ setScrollLockTarget(element);
44
+ };
45
+ return jsx(Fragment, null, lockEnabled &&
46
+ // eslint-disable-next-line jsx-a11y/click-events-have-key-events, jsx-a11y/no-static-element-interactions
47
+ jsx("div", {
48
+ onClick: blurSelectInput,
49
+ css: styles
50
+ }), children(targetRef));
51
+ }
@@ -0,0 +1,126 @@
1
+ import { useCallback, useEffect, useRef } from 'react';
2
+ import { supportsPassiveEvents } from '../../../utils';
3
+ var cancelScroll = function cancelScroll(event) {
4
+ if (event.cancelable) {
5
+ event.preventDefault();
6
+ }
7
+ event.stopPropagation();
8
+ };
9
+ // TODO: Fill in the hook {description}.
10
+ /**
11
+ * {description}.
12
+ */
13
+ export default function useScrollCapture(_ref) {
14
+ var isEnabled = _ref.isEnabled,
15
+ onBottomArrive = _ref.onBottomArrive,
16
+ onBottomLeave = _ref.onBottomLeave,
17
+ onTopArrive = _ref.onTopArrive,
18
+ onTopLeave = _ref.onTopLeave;
19
+ var isBottom = useRef(false);
20
+ var isTop = useRef(false);
21
+ var touchStart = useRef(0);
22
+ var scrollTarget = useRef(null);
23
+ var handleEventDelta = useCallback(function (event, delta) {
24
+ if (scrollTarget.current === null) {
25
+ return;
26
+ }
27
+ var _scrollTarget$current = scrollTarget.current,
28
+ scrollTop = _scrollTarget$current.scrollTop,
29
+ scrollHeight = _scrollTarget$current.scrollHeight,
30
+ clientHeight = _scrollTarget$current.clientHeight;
31
+ var target = scrollTarget.current;
32
+ var isDeltaPositive = delta > 0;
33
+ var availableScroll = scrollHeight - clientHeight - scrollTop;
34
+ var shouldCancelScroll = false;
35
+
36
+ // reset bottom/top flags
37
+ if (availableScroll > delta && isBottom.current) {
38
+ if (onBottomLeave) {
39
+ onBottomLeave(event);
40
+ }
41
+ isBottom.current = false;
42
+ }
43
+ if (isDeltaPositive && isTop.current) {
44
+ if (onTopLeave) {
45
+ onTopLeave(event);
46
+ }
47
+ isTop.current = false;
48
+ }
49
+
50
+ // bottom limit
51
+ if (isDeltaPositive && delta > availableScroll) {
52
+ if (onBottomArrive && !isBottom.current) {
53
+ onBottomArrive(event);
54
+ }
55
+ target.scrollTop = scrollHeight;
56
+ shouldCancelScroll = true;
57
+ isBottom.current = true;
58
+
59
+ // top limit
60
+ } else if (!isDeltaPositive && -delta > scrollTop) {
61
+ if (onTopArrive && !isTop.current) {
62
+ onTopArrive(event);
63
+ }
64
+ target.scrollTop = 0;
65
+ shouldCancelScroll = true;
66
+ isTop.current = true;
67
+ }
68
+
69
+ // cancel scroll
70
+ if (shouldCancelScroll) {
71
+ cancelScroll(event);
72
+ }
73
+ }, [onBottomArrive, onBottomLeave, onTopArrive, onTopLeave]);
74
+ var onWheel = useCallback(function (event) {
75
+ handleEventDelta(event, event.deltaY);
76
+ }, [handleEventDelta]);
77
+ var onTouchStart = useCallback(function (event) {
78
+ // set touch start so we can calculate touchmove delta
79
+ touchStart.current = event.changedTouches[0].clientY;
80
+ }, []);
81
+ var onTouchMove = useCallback(function (event) {
82
+ var deltaY = touchStart.current - event.changedTouches[0].clientY;
83
+ handleEventDelta(event, deltaY);
84
+ }, [handleEventDelta]);
85
+ var startListening = useCallback(function (el) {
86
+ // bail early if no element is available to attach to
87
+ if (!el) {
88
+ return;
89
+ }
90
+ var notPassive = supportsPassiveEvents ? {
91
+ passive: false
92
+ } : false;
93
+ // eslint-disable-next-line @repo/internal/dom-events/no-unsafe-event-listeners
94
+ el.addEventListener('wheel', onWheel, notPassive);
95
+ // eslint-disable-next-line @repo/internal/dom-events/no-unsafe-event-listeners
96
+ el.addEventListener('touchstart', onTouchStart, notPassive);
97
+ // eslint-disable-next-line @repo/internal/dom-events/no-unsafe-event-listeners
98
+ el.addEventListener('touchmove', onTouchMove, notPassive);
99
+ }, [onTouchMove, onTouchStart, onWheel]);
100
+ var stopListening = useCallback(function (el) {
101
+ // bail early if no element is available to detach from
102
+ if (!el) {
103
+ return;
104
+ }
105
+
106
+ // eslint-disable-next-line @repo/internal/dom-events/no-unsafe-event-listeners
107
+ el.removeEventListener('wheel', onWheel, false);
108
+ // eslint-disable-next-line @repo/internal/dom-events/no-unsafe-event-listeners
109
+ el.removeEventListener('touchstart', onTouchStart, false);
110
+ // eslint-disable-next-line @repo/internal/dom-events/no-unsafe-event-listeners
111
+ el.removeEventListener('touchmove', onTouchMove, false);
112
+ }, [onTouchMove, onTouchStart, onWheel]);
113
+ useEffect(function () {
114
+ if (!isEnabled) {
115
+ return;
116
+ }
117
+ var element = scrollTarget.current;
118
+ startListening(element);
119
+ return function () {
120
+ stopListening(element);
121
+ };
122
+ }, [isEnabled, startListening, stopListening]);
123
+ return function (element) {
124
+ scrollTarget.current = element;
125
+ };
126
+ }
@@ -0,0 +1,143 @@
1
+ import { useCallback, useEffect, useRef } from 'react';
2
+ var STYLE_KEYS = ['boxSizing', 'height', 'overflow', 'paddingRight', 'position'];
3
+ var LOCK_STYLES = {
4
+ boxSizing: 'border-box',
5
+ // account for possible declaration `width: 100%;` on body
6
+ overflow: 'hidden',
7
+ position: 'relative',
8
+ height: '100%'
9
+ };
10
+ function preventTouchMove(e) {
11
+ e.preventDefault();
12
+ }
13
+ function allowTouchMove(e) {
14
+ e.stopPropagation();
15
+ }
16
+ function preventInertiaScroll() {
17
+ var top = this.scrollTop;
18
+ var totalScroll = this.scrollHeight;
19
+ var currentScroll = top + this.offsetHeight;
20
+ if (top === 0) {
21
+ this.scrollTop = 1;
22
+ } else if (currentScroll === totalScroll) {
23
+ this.scrollTop = top - 1;
24
+ }
25
+ }
26
+
27
+ // `ontouchstart` check works on most browsers
28
+ // `maxTouchPoints` works on IE10/11 and Surface
29
+ function isTouchDevice() {
30
+ // eslint-disable-next-line compat/compat
31
+ return 'ontouchstart' in window || navigator.maxTouchPoints;
32
+ }
33
+ var canUseDOM = !!(typeof window !== 'undefined' && window.document && window.document.createElement);
34
+ var activeScrollLocks = 0;
35
+ var listenerOptions = {
36
+ capture: false,
37
+ passive: false
38
+ };
39
+
40
+ // TODO: Fill in the hook {description}.
41
+ /**
42
+ * {description}.
43
+ */
44
+ export default function useScrollLock(_ref) {
45
+ var isEnabled = _ref.isEnabled,
46
+ _ref$accountForScroll = _ref.accountForScrollbars,
47
+ accountForScrollbars = _ref$accountForScroll === void 0 ? true : _ref$accountForScroll;
48
+ var originalStyles = useRef({});
49
+ var scrollTarget = useRef(null);
50
+ var addScrollLock = useCallback(function (touchScrollTarget) {
51
+ if (!canUseDOM) {
52
+ return;
53
+ }
54
+ var target = document.body;
55
+ var targetStyle = target && target.style;
56
+ if (accountForScrollbars) {
57
+ // store any styles already applied to the body
58
+ STYLE_KEYS.forEach(function (key) {
59
+ var val = targetStyle && targetStyle[key];
60
+ originalStyles.current[key] = val;
61
+ });
62
+ }
63
+
64
+ // apply the lock styles and padding if this is the first scroll lock
65
+ if (accountForScrollbars && activeScrollLocks < 1) {
66
+ var currentPadding = parseInt(originalStyles.current.paddingRight, 10) || 0;
67
+ var clientWidth = document.body ? document.body.clientWidth : 0;
68
+ var adjustedPadding = window.innerWidth - clientWidth + currentPadding || 0;
69
+ Object.keys(LOCK_STYLES).forEach(function (key) {
70
+ var val = LOCK_STYLES[key];
71
+ if (targetStyle) {
72
+ targetStyle[key] = val;
73
+ }
74
+ });
75
+ if (targetStyle) {
76
+ targetStyle.paddingRight = "".concat(adjustedPadding, "px");
77
+ }
78
+ }
79
+
80
+ // account for touch devices
81
+ if (target && isTouchDevice()) {
82
+ // Mobile Safari ignores { overflow: hidden } declaration on the body.
83
+ // eslint-disable-next-line @repo/internal/dom-events/no-unsafe-event-listeners
84
+ target.addEventListener('touchmove', preventTouchMove, listenerOptions);
85
+
86
+ // Allow scroll on provided target
87
+ if (touchScrollTarget) {
88
+ // eslint-disable-next-line @repo/internal/dom-events/no-unsafe-event-listeners
89
+ touchScrollTarget.addEventListener('touchstart', preventInertiaScroll, listenerOptions);
90
+ // eslint-disable-next-line @repo/internal/dom-events/no-unsafe-event-listeners
91
+ touchScrollTarget.addEventListener('touchmove', allowTouchMove, listenerOptions);
92
+ }
93
+ }
94
+
95
+ // increment active scroll locks
96
+ activeScrollLocks += 1;
97
+ }, [accountForScrollbars]);
98
+ var removeScrollLock = useCallback(function (touchScrollTarget) {
99
+ if (!canUseDOM) {
100
+ return;
101
+ }
102
+ var target = document.body;
103
+ var targetStyle = target && target.style;
104
+
105
+ // safely decrement active scroll locks
106
+ activeScrollLocks = Math.max(activeScrollLocks - 1, 0);
107
+
108
+ // reapply original body styles, if any
109
+ if (accountForScrollbars && activeScrollLocks < 1) {
110
+ STYLE_KEYS.forEach(function (key) {
111
+ var val = originalStyles.current[key];
112
+ if (targetStyle) {
113
+ targetStyle[key] = val;
114
+ }
115
+ });
116
+ }
117
+
118
+ // remove touch listeners
119
+ if (target && isTouchDevice()) {
120
+ // eslint-disable-next-line @repo/internal/dom-events/no-unsafe-event-listeners
121
+ target.removeEventListener('touchmove', preventTouchMove, listenerOptions);
122
+ if (touchScrollTarget) {
123
+ // eslint-disable-next-line @repo/internal/dom-events/no-unsafe-event-listeners
124
+ touchScrollTarget.removeEventListener('touchstart', preventInertiaScroll, listenerOptions);
125
+ // eslint-disable-next-line @repo/internal/dom-events/no-unsafe-event-listeners
126
+ touchScrollTarget.removeEventListener('touchmove', allowTouchMove, listenerOptions);
127
+ }
128
+ }
129
+ }, [accountForScrollbars]);
130
+ useEffect(function () {
131
+ if (!isEnabled) {
132
+ return;
133
+ }
134
+ var element = scrollTarget.current;
135
+ addScrollLock(element);
136
+ return function () {
137
+ removeScrollLock(element);
138
+ };
139
+ }, [isEnabled, addScrollLock, removeScrollLock]);
140
+ return function (element) {
141
+ scrollTarget.current = element;
142
+ };
143
+ }
@@ -50,7 +50,7 @@ interface MenuPlacerProps<Option, IsMulti extends boolean, Group extends GroupBa
50
50
  children: (childrenProps: ChildrenProps) => ReactElement;
51
51
  }
52
52
  export declare const menuCSS: <Option, IsMulti extends boolean, Group extends GroupBase<Option>>(props: MenuProps<Option, IsMulti, Group>) => CSSObjectWithLabel;
53
- export declare const MenuPlacer: <Option, IsMulti extends boolean, Group extends GroupBase<Option>>(props: MenuPlacerProps<Option, IsMulti, Group>) => React.ReactElement<any, string | React.JSXElementConstructor<any>>;
53
+ export declare const MenuPlacer: <Option, IsMulti extends boolean, Group extends GroupBase<Option>>(props: MenuPlacerProps<Option, IsMulti, Group>) => React.JSX.Element;
54
54
  declare const Menu: <Option, IsMulti extends boolean, Group extends GroupBase<Option>>(props: MenuProps<Option, IsMulti, Group>) => React.JSX.Element;
55
55
  export default Menu;
56
56
  export interface MenuListProps<Option = unknown, IsMulti extends boolean = boolean, Group extends GroupBase<Option> = GroupBase<Option>> extends CommonPropsAndClassName<Option, IsMulti, Group> {
@@ -0,0 +1,4 @@
1
+ export { default as A11yText } from './a11y-text';
2
+ export { default as DummyInput } from './dummy-input';
3
+ export { default as ScrollManager } from './scroll-manager';
4
+ export { default as RequiredInput } from './required-input';
@@ -0,0 +1,17 @@
1
+ /**
2
+ * @jsxRuntime classic
3
+ * @jsx jsx
4
+ */
5
+ import { type ReactElement, type RefCallback } from 'react';
6
+ import { jsx } from '@emotion/react';
7
+ interface ScrollManagerProps {
8
+ readonly children: (ref: RefCallback<HTMLElement>) => ReactElement;
9
+ readonly lockEnabled: boolean;
10
+ readonly captureEnabled: boolean;
11
+ readonly onBottomArrive?: (event: WheelEvent | TouchEvent) => void;
12
+ readonly onBottomLeave?: (event: WheelEvent | TouchEvent) => void;
13
+ readonly onTopArrive?: (event: WheelEvent | TouchEvent) => void;
14
+ readonly onTopLeave?: (event: WheelEvent | TouchEvent) => void;
15
+ }
16
+ export default function ScrollManager({ children, lockEnabled, captureEnabled, onBottomArrive, onBottomLeave, onTopArrive, onTopLeave, }: ScrollManagerProps): jsx.JSX.Element;
17
+ export {};
@@ -0,0 +1,12 @@
1
+ interface Options {
2
+ readonly isEnabled: boolean;
3
+ readonly onBottomArrive?: (event: WheelEvent | TouchEvent) => void;
4
+ readonly onBottomLeave?: (event: WheelEvent | TouchEvent) => void;
5
+ readonly onTopArrive?: (event: WheelEvent | TouchEvent) => void;
6
+ readonly onTopLeave?: (event: WheelEvent | TouchEvent) => void;
7
+ }
8
+ /**
9
+ * {description}.
10
+ */
11
+ export default function useScrollCapture({ isEnabled, onBottomArrive, onBottomLeave, onTopArrive, onTopLeave, }: Options): (element: HTMLElement | null) => void;
12
+ export {};
@@ -0,0 +1,9 @@
1
+ interface Options {
2
+ readonly isEnabled: boolean;
3
+ readonly accountForScrollbars?: boolean;
4
+ }
5
+ /**
6
+ * {description}.
7
+ */
8
+ export default function useScrollLock({ isEnabled, accountForScrollbars }: Options): (element: HTMLElement | null) => void;
9
+ export {};
@@ -50,7 +50,7 @@ interface MenuPlacerProps<Option, IsMulti extends boolean, Group extends GroupBa
50
50
  children: (childrenProps: ChildrenProps) => ReactElement;
51
51
  }
52
52
  export declare const menuCSS: <Option, IsMulti extends boolean, Group extends GroupBase<Option>>(props: MenuProps<Option, IsMulti, Group>) => CSSObjectWithLabel;
53
- export declare const MenuPlacer: <Option, IsMulti extends boolean, Group extends GroupBase<Option>>(props: MenuPlacerProps<Option, IsMulti, Group>) => React.ReactElement<any, string | React.JSXElementConstructor<any>>;
53
+ export declare const MenuPlacer: <Option, IsMulti extends boolean, Group extends GroupBase<Option>>(props: MenuPlacerProps<Option, IsMulti, Group>) => React.JSX.Element;
54
54
  declare const Menu: <Option, IsMulti extends boolean, Group extends GroupBase<Option>>(props: MenuProps<Option, IsMulti, Group>) => React.JSX.Element;
55
55
  export default Menu;
56
56
  export interface MenuListProps<Option = unknown, IsMulti extends boolean = boolean, Group extends GroupBase<Option> = GroupBase<Option>> extends CommonPropsAndClassName<Option, IsMulti, Group> {
@@ -0,0 +1,4 @@
1
+ export { default as A11yText } from './a11y-text';
2
+ export { default as DummyInput } from './dummy-input';
3
+ export { default as ScrollManager } from './scroll-manager';
4
+ export { default as RequiredInput } from './required-input';