@telus-uds/components-base 1.9.0 → 1.12.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.
Files changed (57) hide show
  1. package/CHANGELOG.md +41 -2
  2. package/component-docs.json +650 -27
  3. package/lib/Carousel/Carousel.js +672 -0
  4. package/lib/Carousel/CarouselContext.js +59 -0
  5. package/lib/Carousel/CarouselItem/CarouselItem.js +92 -0
  6. package/lib/Carousel/CarouselItem/index.js +13 -0
  7. package/lib/Carousel/dictionary.js +23 -0
  8. package/lib/Carousel/index.js +32 -0
  9. package/lib/InputSupports/InputSupports.js +10 -3
  10. package/lib/InputSupports/useInputSupports.js +3 -2
  11. package/lib/Modal/Modal.js +4 -0
  12. package/lib/Skeleton/Skeleton.js +1 -0
  13. package/lib/StepTracker/StepTracker.js +15 -12
  14. package/lib/TextInput/TextInput.js +3 -1
  15. package/lib/index.js +23 -0
  16. package/lib/utils/index.js +9 -0
  17. package/lib/utils/props/clickProps.js +2 -2
  18. package/lib/utils/props/handlerProps.js +77 -31
  19. package/lib/utils/useScrollBlocking.js +66 -0
  20. package/lib/utils/useScrollBlocking.native.js +11 -0
  21. package/lib-module/Carousel/Carousel.js +617 -0
  22. package/lib-module/Carousel/CarouselContext.js +43 -0
  23. package/lib-module/Carousel/CarouselItem/CarouselItem.js +75 -0
  24. package/lib-module/Carousel/CarouselItem/index.js +2 -0
  25. package/lib-module/Carousel/dictionary.js +16 -0
  26. package/lib-module/Carousel/index.js +2 -0
  27. package/lib-module/InputSupports/InputSupports.js +10 -3
  28. package/lib-module/InputSupports/useInputSupports.js +3 -2
  29. package/lib-module/Modal/Modal.js +3 -0
  30. package/lib-module/Skeleton/Skeleton.js +1 -0
  31. package/lib-module/StepTracker/StepTracker.js +14 -12
  32. package/lib-module/TextInput/TextInput.js +3 -1
  33. package/lib-module/index.js +2 -0
  34. package/lib-module/utils/index.js +1 -0
  35. package/lib-module/utils/props/clickProps.js +2 -2
  36. package/lib-module/utils/props/handlerProps.js +78 -31
  37. package/lib-module/utils/useScrollBlocking.js +58 -0
  38. package/lib-module/utils/useScrollBlocking.native.js +2 -0
  39. package/package.json +4 -4
  40. package/src/Carousel/Carousel.jsx +649 -0
  41. package/src/Carousel/CarouselContext.jsx +30 -0
  42. package/src/Carousel/CarouselItem/CarouselItem.jsx +66 -0
  43. package/src/Carousel/CarouselItem/index.js +3 -0
  44. package/src/Carousel/dictionary.js +16 -0
  45. package/src/Carousel/index.js +2 -0
  46. package/src/InputSupports/InputSupports.jsx +18 -3
  47. package/src/InputSupports/useInputSupports.js +2 -2
  48. package/src/Modal/Modal.jsx +3 -1
  49. package/src/Skeleton/Skeleton.jsx +1 -0
  50. package/src/StepTracker/StepTracker.jsx +21 -8
  51. package/src/TextInput/TextInput.jsx +1 -1
  52. package/src/index.js +2 -0
  53. package/src/utils/index.js +1 -0
  54. package/src/utils/props/clickProps.js +2 -2
  55. package/src/utils/props/handlerProps.js +64 -16
  56. package/src/utils/useScrollBlocking.js +57 -0
  57. package/src/utils/useScrollBlocking.native.js +2 -0
@@ -0,0 +1,59 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.CarouselProvider = void 0;
7
+ exports.useCarousel = useCarousel;
8
+
9
+ var _react = _interopRequireDefault(require("react"));
10
+
11
+ var _propTypes = _interopRequireDefault(require("prop-types"));
12
+
13
+ var _jsxRuntime = require("react/jsx-runtime");
14
+
15
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
16
+
17
+ const CarouselContext = /*#__PURE__*/_react.default.createContext();
18
+
19
+ const CarouselProvider = _ref => {
20
+ let {
21
+ children,
22
+ activeIndex,
23
+ totalItems,
24
+ width,
25
+ goTo
26
+ } = _ref;
27
+
28
+ const value = _react.default.useMemo(() => ({
29
+ activeIndex,
30
+ totalItems,
31
+ width,
32
+ goTo
33
+ }), [activeIndex, totalItems, width, goTo]);
34
+
35
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)(CarouselContext.Provider, {
36
+ value: value,
37
+ children: children
38
+ });
39
+ };
40
+
41
+ exports.CarouselProvider = CarouselProvider;
42
+
43
+ function useCarousel() {
44
+ const context = _react.default.useContext(CarouselContext);
45
+
46
+ if (context === undefined) {
47
+ throw new Error("'useCarousel' must be used within a 'CarouselProvider'");
48
+ }
49
+
50
+ return context;
51
+ }
52
+
53
+ CarouselProvider.propTypes = {
54
+ children: _propTypes.default.arrayOf(_propTypes.default.element).isRequired,
55
+ activeIndex: _propTypes.default.number.isRequired,
56
+ totalItems: _propTypes.default.number.isRequired,
57
+ width: _propTypes.default.number.isRequired,
58
+ goTo: _propTypes.default.func.isRequired
59
+ };
@@ -0,0 +1,92 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+
8
+ var _react = _interopRequireDefault(require("react"));
9
+
10
+ var _propTypes = _interopRequireDefault(require("prop-types"));
11
+
12
+ var _View = _interopRequireDefault(require("react-native-web/dist/cjs/exports/View"));
13
+
14
+ var _Platform = _interopRequireDefault(require("react-native-web/dist/cjs/exports/Platform"));
15
+
16
+ var _utils = require("../../utils");
17
+
18
+ var _CarouselContext = require("../CarouselContext");
19
+
20
+ var _jsxRuntime = require("react/jsx-runtime");
21
+
22
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
23
+
24
+ const [selectProps, selectedSystemPropTypes] = (0, _utils.selectSystemProps)([_utils.a11yProps, _utils.viewProps]);
25
+ /**
26
+ * `Carousel.Item` is used to wrap the content of an individual slide and is suppsoed to be the
27
+ * only top-level component passed to the `Carousel`
28
+ */
29
+
30
+ const CarouselItem = _ref => {
31
+ let {
32
+ children,
33
+ elementIndex,
34
+ tag = 'li',
35
+ hidden,
36
+ ...rest
37
+ } = _ref;
38
+ const {
39
+ width,
40
+ activeIndex
41
+ } = (0, _CarouselContext.useCarousel)();
42
+ const selectedProps = selectProps({ ...rest,
43
+ ...(0, _utils.getA11yPropsFromHtmlTag)(tag, rest.accessibilityRole)
44
+ });
45
+ const focusabilityProps = activeIndex === elementIndex ? {} : _utils.a11yProps.nonFocusableProps;
46
+ const style = {
47
+ width
48
+ };
49
+
50
+ if (hidden && _Platform.default.OS === 'web') {
51
+ // On web, visibility: hidden makes all children non-focusable. It doesn't exist on native.
52
+ style.visibility = 'hidden';
53
+ }
54
+
55
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)(_View.default, {
56
+ style: style,
57
+ ...selectedProps,
58
+ ...focusabilityProps,
59
+ children: children
60
+ });
61
+ };
62
+
63
+ CarouselItem.propTypes = { ...selectedSystemPropTypes,
64
+
65
+ /**
66
+ * Index of the current slide
67
+ * Don't pass this prop when using `Carousel.Item` as it is already being passed by `Carousel` top-level component
68
+ */
69
+ elementIndex: _propTypes.default.number,
70
+
71
+ /**
72
+ * Provide custom accessibilityLabelledBy for Carousel slide
73
+ */
74
+ accessibilityLabelledBy: _propTypes.default.string,
75
+
76
+ /**
77
+ * Content of the slide
78
+ */
79
+ children: _propTypes.default.oneOfType([_propTypes.default.arrayOf(_propTypes.default.node), _propTypes.default.node]).isRequired,
80
+
81
+ /**
82
+ * Sets the HTML tag of the outer container. By default `'li'` so that assistive technology sees
83
+ * the Carousel as a list of items.
84
+ *
85
+ * Carousel's innermost container defaults to `'ul'` which can be overridden. If the tag of either
86
+ * `Carousel` or `Carousel.Item` is overriden, the other should be too, to avoid producing invalid HTML.
87
+ */
88
+ tag: _propTypes.default.oneOf(_utils.layoutTags)
89
+ };
90
+ CarouselItem.displayName = 'Carousel.Item';
91
+ var _default = CarouselItem;
92
+ exports.default = _default;
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+
8
+ var _CarouselItem = _interopRequireDefault(require("./CarouselItem"));
9
+
10
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
11
+
12
+ var _default = _CarouselItem.default;
13
+ exports.default = _default;
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ // 'stepLabel' and 'stepTrackerLabel' are passed down to StepTracker
8
+ var _default = {
9
+ en: {
10
+ carouselLabel: '%{stepCount} items',
11
+ iconButtonLabel: 'Show %{itemLabel} %{targetStep} of %{stepCount}',
12
+ stepLabel: '%{itemLabel} %{stepNumber}',
13
+ stepTrackerLabel: '%{itemLabel} %{stepNumber} of %{stepCount}'
14
+ },
15
+ fr: {
16
+ // TODO: French translations here
17
+ carouselLabel: '(fr) %{stepCount} items',
18
+ iconButtonLabel: '(fr) Show %{itemLabel} %{targetStep} of %{stepCount}',
19
+ stepLabel: '(fr) %{itemLabel} %{stepNumber}',
20
+ stepTrackerLabel: '(fr) %{itemLabel} %{stepNumber} of %{stepCount}'
21
+ }
22
+ };
23
+ exports.default = _default;
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ var _exportNames = {
7
+ Carousel: true
8
+ };
9
+ Object.defineProperty(exports, "Carousel", {
10
+ enumerable: true,
11
+ get: function () {
12
+ return _Carousel.default;
13
+ }
14
+ });
15
+
16
+ var _CarouselContext = require("./CarouselContext");
17
+
18
+ Object.keys(_CarouselContext).forEach(function (key) {
19
+ if (key === "default" || key === "__esModule") return;
20
+ if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
21
+ if (key in exports && exports[key] === _CarouselContext[key]) return;
22
+ Object.defineProperty(exports, key, {
23
+ enumerable: true,
24
+ get: function () {
25
+ return _CarouselContext[key];
26
+ }
27
+ });
28
+ });
29
+
30
+ var _Carousel = _interopRequireDefault(require("./Carousel"));
31
+
32
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
@@ -36,7 +36,8 @@ const InputSupports = /*#__PURE__*/(0, _react.forwardRef)((_ref, ref) => {
36
36
  hintPosition = 'inline',
37
37
  feedback,
38
38
  tooltip,
39
- validation
39
+ validation,
40
+ nativeID
40
41
  } = _ref;
41
42
  const {
42
43
  space
@@ -50,7 +51,8 @@ const InputSupports = /*#__PURE__*/(0, _react.forwardRef)((_ref, ref) => {
50
51
  feedback,
51
52
  hint,
52
53
  label,
53
- validation
54
+ validation,
55
+ nativeID
54
56
  });
55
57
  return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_StackView.default, {
56
58
  space: space,
@@ -111,7 +113,12 @@ InputSupports.propTypes = {
111
113
  /**
112
114
  * Use to visually mark an input as valid or invalid.
113
115
  */
114
- validation: _propTypes.default.oneOf(['error', 'success'])
116
+ validation: _propTypes.default.oneOf(['error', 'success']),
117
+
118
+ /**
119
+ * ID for DOM element on web
120
+ */
121
+ nativeID: _propTypes.default.string
115
122
  };
116
123
  var _default = InputSupports;
117
124
  exports.default = _default;
@@ -16,7 +16,8 @@ const useInputSupports = _ref => {
16
16
  label,
17
17
  feedback,
18
18
  validation,
19
- hint
19
+ hint,
20
+ nativeID
20
21
  } = _ref;
21
22
  const hasValidationError = validation === 'error';
22
23
  const inputId = (0, _useUniqueId.default)('input');
@@ -31,7 +32,7 @@ const useInputSupports = _ref => {
31
32
  accessibilityInvalid: hasValidationError
32
33
  };
33
34
  return {
34
- inputId,
35
+ inputId: nativeID || inputId,
35
36
  hintId,
36
37
  feedbackId,
37
38
  a11yProps
@@ -29,6 +29,8 @@ var _IconButton = _interopRequireDefault(require("../IconButton"));
29
29
 
30
30
  var _dictionary = _interopRequireDefault(require("./dictionary"));
31
31
 
32
+ var _useScrollBlocking = _interopRequireDefault(require("../utils/useScrollBlocking"));
33
+
32
34
  var _jsxRuntime = require("react/jsx-runtime");
33
35
 
34
36
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
@@ -135,6 +137,7 @@ const Modal = /*#__PURE__*/(0, _react.forwardRef)((_ref5, ref) => {
135
137
  viewport,
136
138
  maxWidth
137
139
  });
140
+ const modalRef = (0, _useScrollBlocking.default)(isOpen);
138
141
  const {
139
142
  closeIcon: CloseIconComponent
140
143
  } = themeTokens;
@@ -165,6 +168,7 @@ const Modal = /*#__PURE__*/(0, _react.forwardRef)((_ref5, ref) => {
165
168
  ...selectProps(rest),
166
169
  children: /*#__PURE__*/(0, _jsxRuntime.jsxs)(_View.default, {
167
170
  style: [staticStyles.positioningContainer],
171
+ ref: modalRef,
168
172
  children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_View.default, {
169
173
  style: [staticStyles.sizingContainer, selectContainerStyles(themeTokens)],
170
174
  pointerEvents: "box-none" // don't capture backdrop press events
@@ -42,6 +42,7 @@ const selectSkeletonStyles = _ref => {
42
42
  return {
43
43
  backgroundColor: color,
44
44
  borderRadius: radius,
45
+ maxWidth: '100%',
45
46
  ...fadeAnimation
46
47
  };
47
48
  };
@@ -134,7 +134,10 @@ const StepTracker = /*#__PURE__*/(0, _react.forwardRef)((_ref4, ref) => {
134
134
  dictionary,
135
135
  copy
136
136
  });
137
- const stepTrackerLabel = getCopy('stepTrackerLabel').replace('%{stepNumber}', current < steps.length ? current + 1 : steps.length).replace('%{stepCount}', steps.length).replace('%{stepLabel}', current < steps.length ? steps[current] : steps[steps.length - 1]);
137
+ const stepTrackerLabel = showStepTrackerLabel ? getCopy('stepTrackerLabel').replace('%{stepNumber}', current < steps.length ? current + 1 : steps.length).replace('%{stepCount}', steps.length).replace('%{stepLabel}', current < steps.length ? steps[current] : steps[steps.length - 1]) : '';
138
+
139
+ const getStepLabel = index => themeTokens.showStepLabel ? getCopy('stepLabel').replace('%{stepNumber}', index + 1) : '';
140
+
138
141
  if (!steps.length) return null;
139
142
  const selectedProps = selectProps({
140
143
  accessibilityLabel: stepTrackerLabel,
@@ -160,7 +163,7 @@ const StepTracker = /*#__PURE__*/(0, _react.forwardRef)((_ref4, ref) => {
160
163
  return /*#__PURE__*/(0, _jsxRuntime.jsx)(_Step.default, {
161
164
  status: current,
162
165
  label: label,
163
- name: getCopy('stepLabel').replace('%{stepNumber}', index + 1),
166
+ name: getStepLabel(index),
164
167
  stepIndex: index,
165
168
  stepCount: steps.length,
166
169
  tokens: themeTokens
@@ -176,19 +179,19 @@ const StepTracker = /*#__PURE__*/(0, _react.forwardRef)((_ref4, ref) => {
176
179
  })
177
180
  });
178
181
  });
179
- StepTracker.displayName = 'StepTracker';
182
+ StepTracker.displayName = 'StepTracker'; // If a language dictionary entry is provided, it must contain every key
183
+
184
+ const dictionaryContentShape = _propTypes.default.shape({
185
+ stepLabel: _propTypes.default.string.isRequired,
186
+ stepTrackerLabel: _propTypes.default.string.isRequired
187
+ });
188
+
180
189
  StepTracker.propTypes = { ...selectedSystemPropTypes,
181
190
  current: _propTypes.default.number,
182
- copy: _propTypes.default.oneOf(['en', 'fr']),
191
+ copy: _propTypes.default.oneOfType([_propTypes.default.oneOf(['en', 'fr']), dictionaryContentShape]),
183
192
  dictionary: _propTypes.default.shape({
184
- en: _propTypes.default.shape({
185
- stepLabel: _propTypes.default.string,
186
- stepTrackerLabel: _propTypes.default.string
187
- }),
188
- fr: _propTypes.default.shape({
189
- stepLabel: _propTypes.default.string,
190
- stepTrackerLabel: _propTypes.default.string
191
- })
193
+ en: dictionaryContentShape,
194
+ fr: dictionaryContentShape
192
195
  }),
193
196
  steps: _propTypes.default.arrayOf(_propTypes.default.string),
194
197
  tokens: (0, _utils.getTokensPropType)('StepTracker'),
@@ -59,7 +59,9 @@ const TextInput = /*#__PURE__*/(0, _react.forwardRef)((_ref, ref) => {
59
59
  validation: supportsProps.validation
60
60
  }
61
61
  };
62
- return /*#__PURE__*/(0, _jsxRuntime.jsx)(_InputSupports.default, { ...supportsProps,
62
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)(_InputSupports.default, {
63
+ nativeID: selectedProps.nativeID,
64
+ ...supportsProps,
63
65
  children: _ref2 => {
64
66
  let {
65
67
  inputId,
package/lib/index.js CHANGED
@@ -20,6 +20,7 @@ var _exportNames = {
20
20
  Icon: true,
21
21
  IconButton: true,
22
22
  InputLabel: true,
23
+ InputSupports: true,
23
24
  List: true,
24
25
  ListItem: true,
25
26
  ListBase: true,
@@ -158,6 +159,12 @@ Object.defineProperty(exports, "InputLabel", {
158
159
  return _InputLabel.default;
159
160
  }
160
161
  });
162
+ Object.defineProperty(exports, "InputSupports", {
163
+ enumerable: true,
164
+ get: function () {
165
+ return _InputSupports.default;
166
+ }
167
+ });
161
168
  Object.defineProperty(exports, "List", {
162
169
  enumerable: true,
163
170
  get: function () {
@@ -385,6 +392,20 @@ Object.keys(_Button).forEach(function (key) {
385
392
 
386
393
  var _Card = _interopRequireWildcard(require("./Card"));
387
394
 
395
+ var _Carousel = require("./Carousel");
396
+
397
+ Object.keys(_Carousel).forEach(function (key) {
398
+ if (key === "default" || key === "__esModule") return;
399
+ if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
400
+ if (key in exports && exports[key] === _Carousel[key]) return;
401
+ Object.defineProperty(exports, key, {
402
+ enumerable: true,
403
+ get: function () {
404
+ return _Carousel[key];
405
+ }
406
+ });
407
+ });
408
+
388
409
  var _Checkbox = _interopRequireWildcard(require("./Checkbox"));
389
410
 
390
411
  Object.keys(_Checkbox).forEach(function (key) {
@@ -441,6 +462,8 @@ var _IconButton = _interopRequireDefault(require("./IconButton"));
441
462
 
442
463
  var _InputLabel = _interopRequireDefault(require("./InputLabel"));
443
464
 
465
+ var _InputSupports = _interopRequireDefault(require("./InputSupports"));
466
+
444
467
  var _Link = require("./Link");
445
468
 
446
469
  Object.keys(_Link).forEach(function (key) {
@@ -9,6 +9,7 @@ var _exportNames = {
9
9
  useHash: true,
10
10
  useSpacingScale: true,
11
11
  useResponsiveProp: true,
12
+ useScrollBlocking: true,
12
13
  useUniqueId: true,
13
14
  withLinkRouter: true,
14
15
  containUniqueFields: true
@@ -43,6 +44,12 @@ Object.defineProperty(exports, "useResponsiveProp", {
43
44
  return _useResponsiveProp.default;
44
45
  }
45
46
  });
47
+ Object.defineProperty(exports, "useScrollBlocking", {
48
+ enumerable: true,
49
+ get: function () {
50
+ return _useScrollBlocking.default;
51
+ }
52
+ });
46
53
  Object.defineProperty(exports, "useSpacingScale", {
47
54
  enumerable: true,
48
55
  get: function () {
@@ -168,6 +175,8 @@ Object.keys(_useResponsiveProp).forEach(function (key) {
168
175
  });
169
176
  });
170
177
 
178
+ var _useScrollBlocking = _interopRequireDefault(require("./useScrollBlocking"));
179
+
171
180
  var _useUniqueId = _interopRequireDefault(require("./useUniqueId"));
172
181
 
173
182
  var _withLinkRouter = _interopRequireDefault(require("./withLinkRouter"));
@@ -11,8 +11,8 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
11
11
 
12
12
  const clickHandlerMapping = {
13
13
  onClick: 'onPress',
14
- mouseDown: 'onPressIn',
15
- mouseUp: 'onPressOut'
14
+ onMouseDown: 'onPressIn',
15
+ onMouseUp: 'onPressOut'
16
16
  };
17
17
  var _default = {
18
18
  /**
@@ -3,10 +3,14 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.textInputHandlerProps = exports.focusHandlerProps = exports.default = void 0;
6
+ exports.textInputHandlerProps = exports.focusHandlerProps = void 0;
7
7
 
8
8
  var _propTypes = _interopRequireDefault(require("prop-types"));
9
9
 
10
+ var _Platform = _interopRequireDefault(require("react-native-web/dist/cjs/exports/Platform"));
11
+
12
+ var _getPropSelector = _interopRequireDefault(require("./getPropSelector"));
13
+
10
14
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
11
15
 
12
16
  const focusHandlerProps = {
@@ -20,19 +24,10 @@ const focusHandlerProps = {
20
24
  * onFocus handler
21
25
  */
22
26
  onFocus: _propTypes.default.func
23
- },
24
- select: _ref => {
25
- let {
26
- onBlur,
27
- onFocus
28
- } = _ref;
29
- return {
30
- onBlur,
31
- onFocus
32
- };
33
27
  }
34
28
  };
35
29
  exports.focusHandlerProps = focusHandlerProps;
30
+ focusHandlerProps.select = (0, _getPropSelector.default)(focusHandlerProps.types);
36
31
  const textInputHandlerProps = {
37
32
  types: {
38
33
  /**
@@ -53,26 +48,77 @@ const textInputHandlerProps = {
53
48
  /**
54
49
  * onSubmitEditing handler
55
50
  */
56
- onSubmitEditing: _propTypes.default.func
57
- },
58
- select: _ref2 => {
59
- let {
60
- onChange,
61
- onChangeText,
62
- onSubmit,
63
- onSubmitEditing
64
- } = _ref2;
65
- return {
66
- onChange,
67
- onChangeText,
68
- onSubmit,
69
- onSubmitEditing
70
- };
51
+ onSubmitEditing: _propTypes.default.func,
52
+
53
+ /**
54
+ * onContentSizeChange handler
55
+ */
56
+ onContentSizeChange: _propTypes.default.func,
57
+
58
+ /**
59
+ * onEndEditing handler
60
+ */
61
+ onEndEditing: _propTypes.default.func,
62
+
63
+ /**
64
+ * onScroll handler
65
+ */
66
+ onScroll: _propTypes.default.func,
67
+
68
+ /**
69
+ * onSelectionChange handler
70
+ */
71
+ onSelectionChange: _propTypes.default.func,
72
+
73
+ /**
74
+ * onKeyPress handler
75
+ */
76
+ onKeyPress: _propTypes.default.func,
77
+
78
+ /**
79
+ * onKeyUp handler (only supported on Web)
80
+ */
81
+ onKeyUp: _propTypes.default.func,
82
+
83
+ /**
84
+ * onKeyDown handler (only supported on Web)
85
+ */
86
+ onKeyDown: _propTypes.default.func
71
87
  }
72
88
  };
73
89
  exports.textInputHandlerProps = textInputHandlerProps;
74
- var _default = {
75
- focusHandlerProps,
76
- textInputHandlerProps
77
- };
78
- exports.default = _default;
90
+ const selectTextInputHandlers = (0, _getPropSelector.default)(textInputHandlerProps.types);
91
+
92
+ textInputHandlerProps.select = props => {
93
+ // Support for onKeyPress/onKeyUp/onKeyDown is inconsistent between React Native and React Native Web
94
+ const {
95
+ onKeyPress,
96
+ onKeyUp,
97
+ onKeyDown,
98
+ ...resolvedProps
99
+ } = selectTextInputHandlers(props);
100
+
101
+ if (onKeyPress || onKeyUp || onKeyDown) {
102
+ if (_Platform.default.OS !== 'web') {
103
+ // React Native only supports onKeyPress. Call any key handlers supplied in expected order.
104
+ resolvedProps.onKeyPress = event => {
105
+ if (typeof onKeyDown === 'function') onKeyDown(event);
106
+ if (typeof onKeyPress === 'function') onKeyPress(event);
107
+ if (typeof onKeyUp === 'function') onKeyUp(event);
108
+ };
109
+ } else {
110
+ // React Native Web supports onKeyUp the normal way.
111
+ if (onKeyUp) resolvedProps.onKeyUp = onKeyUp; // React Native Web doesn't support the `onKeyDown` prop name, but maps a supplied onKeyPress handler
112
+ // to the onKeyDown event and calls it with a keydown event. Make React Native Web call either or both.
113
+
114
+ if (onKeyPress || onKeyDown) {
115
+ resolvedProps.onKeyPress = event => {
116
+ if (typeof onKeyDown === 'function') onKeyDown(event);
117
+ if (typeof onKeyPress === 'function') onKeyPress(event);
118
+ };
119
+ }
120
+ }
121
+ }
122
+
123
+ return resolvedProps;
124
+ };
@@ -0,0 +1,66 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+
8
+ var _react = require("react");
9
+
10
+ const addScrollBlocking = (preventScrolling, stopPropagation, ref) => {
11
+ var _ref$current;
12
+
13
+ document.body.addEventListener('touchmove', preventScrolling, {
14
+ passive: false
15
+ });
16
+ (_ref$current = ref.current) === null || _ref$current === void 0 ? void 0 : _ref$current.addEventListener('touchmove', stopPropagation);
17
+ document.body.style.overflow = 'hidden';
18
+ };
19
+
20
+ const removeScrollBlocking = (preventScrolling, stopPropagation, ref) => {
21
+ var _ref$current2;
22
+
23
+ document.body.removeEventListener('touchmove', preventScrolling);
24
+ (_ref$current2 = ref.current) === null || _ref$current2 === void 0 ? void 0 : _ref$current2.removeEventListener('touchmove', stopPropagation);
25
+ document.body.style.overflow = 'inherit';
26
+ };
27
+ /**
28
+ * Disables scrolling when passed `true` or an array where all items are `true`.
29
+ *
30
+ * Returns an optional callback ref. Pass this to an element if it or its children
31
+ * should allow touch-based scrolling within that element's bounds.
32
+ *
33
+ * @param {boolean | boolean[]} conditionProps
34
+ * @returns
35
+ */
36
+
37
+
38
+ const useScrollBlocking = conditionProps => {
39
+ // useRef refs are null on first render and don't trigger a re-render when they get their
40
+ // element. Force re-run when ref mounts to ensure the stopPropagation listener is attached.
41
+ const ref = (0, _react.useRef)();
42
+ const [refIsMounted, setRefIsMounted] = (0, _react.useState)(false);
43
+ const callbackRef = (0, _react.useCallback)(element => {
44
+ ref.current = element;
45
+ setRefIsMounted(Boolean(element));
46
+ }, []);
47
+ const conditionsMet = Array.isArray(conditionProps) ? conditionProps.every(condition => condition) : Boolean(conditionProps);
48
+ const preventScrolling = (0, _react.useCallback)(event => event.preventDefault(), []);
49
+ const stopPropagation = (0, _react.useCallback)(event => event.stopPropagation(), []);
50
+ (0, _react.useEffect)(() => {
51
+ const cleanup = () => removeScrollBlocking(preventScrolling, stopPropagation, ref);
52
+
53
+ if (conditionsMet) {
54
+ addScrollBlocking(preventScrolling, stopPropagation, ref);
55
+ } else {
56
+ cleanup();
57
+ }
58
+
59
+ return cleanup; // preventScrolling and stopPropagation are stable callbacks with no deps, so this
60
+ // will re-run when conditionsMet or refIsMounted flip between true and false.
61
+ }, [preventScrolling, conditionsMet, stopPropagation, refIsMounted]);
62
+ return callbackRef;
63
+ };
64
+
65
+ var _default = useScrollBlocking;
66
+ exports.default = _default;
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+
8
+ // This is a no-op to emphasize that the original hook is web-only
9
+ var _default = () => {};
10
+
11
+ exports.default = _default;