@telus-uds/components-base 1.19.0 → 1.19.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 (134) hide show
  1. package/CHANGELOG.md +2 -2
  2. package/lib/ActivityIndicator/Spinner.js +7 -7
  3. package/lib/ActivityIndicator/Spinner.native.js +2 -2
  4. package/lib/BaseProvider/HydrationContext.js +1 -1
  5. package/lib/BaseProvider/TamaguiProvider.js +30 -0
  6. package/lib/Button/ButtonBase.js +2 -2
  7. package/lib/Button/ButtonDropdown.js +207 -0
  8. package/lib/Button/ButtonGroup.js +1 -1
  9. package/lib/Carousel/Carousel.js +2 -4
  10. package/lib/Carousel/CarouselContext.js +1 -1
  11. package/lib/Carousel/CarouselFirstFocus/CarouselFirstFocus.js +1 -1
  12. package/lib/Carousel/CarouselThumbnail.js +2 -2
  13. package/lib/Checkbox/Checkbox.js +1 -1
  14. package/lib/Checkbox/CheckboxGroup.js +2 -2
  15. package/lib/Divider/Divider.js +2 -2
  16. package/lib/FlexGrid/Col/Col.js +1 -1
  17. package/lib/Icon/Icon.js +1 -1
  18. package/lib/MultiSelectFilter/ModalOverlay.js +136 -0
  19. package/lib/MultiSelectFilter/MultiSelectFilter.js +314 -0
  20. package/lib/MultiSelectFilter/dictionary.js +19 -0
  21. package/lib/MultiSelectFilter/index.js +13 -0
  22. package/lib/Pagination/PageButton.js +2 -2
  23. package/lib/Pagination/Pagination.js +3 -5
  24. package/lib/Pagination/usePagination.js +2 -2
  25. package/lib/Progress/ProgressBar.js +3 -3
  26. package/lib/Progress/ProgressBarBackground.js +3 -3
  27. package/lib/QuickLinksFeature/QuickLinksFeature.js +91 -0
  28. package/lib/QuickLinksFeature/QuickLinksFeatureItem.js +157 -0
  29. package/lib/QuickLinksFeature/index.js +16 -0
  30. package/lib/Radio/Radio.js +2 -2
  31. package/lib/Radio/RadioGroup.js +2 -2
  32. package/lib/RadioCard/RadioCard.js +1 -1
  33. package/lib/RadioCard/RadioCardGroup.js +2 -2
  34. package/lib/Search/Search.js +1 -1
  35. package/lib/Select/constants.js +15 -0
  36. package/lib/SideNav/SideNav.js +2 -2
  37. package/lib/Skeleton/Skeleton.js +1 -1
  38. package/lib/Skeleton/skeletonWebAnimation.js +1 -1
  39. package/lib/StackView/StackWrap.js +1 -3
  40. package/lib/StackView/getStackedContent.js +2 -2
  41. package/lib/Tabs/Tabs.js +2 -4
  42. package/lib/Tags/Tags.js +1 -1
  43. package/lib/TextInput/dictionary.js +19 -0
  44. package/lib/ThemeProvider/utils/styles.js +3 -3
  45. package/lib/ThemeProvider/utils/theme-tokens.js +9 -7
  46. package/lib/Timeline/Timeline.js +1 -1
  47. package/lib/ToggleSwitch/ToggleSwitch.js +1 -1
  48. package/lib/ToggleSwitch/ToggleSwitchGroup.js +1 -1
  49. package/lib/Tooltip/Backdrop.js +10 -2
  50. package/lib/Tooltip/Tooltip.native.js +357 -0
  51. package/lib/Tooltip/shared.js +39 -0
  52. package/lib/Validator/Validator.js +271 -0
  53. package/lib/Validator/index.js +13 -0
  54. package/lib/utils/BaseView/BaseView.js +64 -0
  55. package/lib/utils/BaseView/BaseView.native.js +16 -0
  56. package/lib/utils/BaseView/index.js +13 -0
  57. package/lib/utils/animation/useVerticalExpandAnimation.js +1 -1
  58. package/lib/utils/children.js +2 -2
  59. package/lib/utils/floating-ui/index.js +43 -0
  60. package/lib/utils/floating-ui/index.native.js +43 -0
  61. package/lib/utils/input.js +12 -6
  62. package/lib/utils/props/componentPropType.js +3 -3
  63. package/lib/utils/props/selectSystemProps.js +2 -2
  64. package/lib/utils/props/tokens.js +2 -2
  65. package/lib/utils/useOverlaidPosition.js +243 -0
  66. package/lib/utils/useSpacingScale.js +1 -3
  67. package/lib/utils/useUniqueId.js +1 -1
  68. package/lib-module/ActivityIndicator/Spinner.js +7 -7
  69. package/lib-module/ActivityIndicator/Spinner.native.js +2 -2
  70. package/lib-module/BaseProvider/HydrationContext.js +1 -1
  71. package/lib-module/BaseProvider/TamaguiProvider.js +22 -0
  72. package/lib-module/Button/ButtonBase.js +2 -2
  73. package/lib-module/Button/ButtonDropdown.js +181 -0
  74. package/lib-module/Button/ButtonGroup.js +1 -1
  75. package/lib-module/Carousel/Carousel.js +2 -4
  76. package/lib-module/Carousel/CarouselContext.js +1 -1
  77. package/lib-module/Carousel/CarouselFirstFocus/CarouselFirstFocus.js +1 -1
  78. package/lib-module/Carousel/CarouselThumbnail.js +2 -2
  79. package/lib-module/Checkbox/Checkbox.js +1 -1
  80. package/lib-module/Checkbox/CheckboxGroup.js +2 -2
  81. package/lib-module/Divider/Divider.js +2 -2
  82. package/lib-module/FlexGrid/Col/Col.js +1 -1
  83. package/lib-module/Icon/Icon.js +1 -1
  84. package/lib-module/MultiSelectFilter/ModalOverlay.js +112 -0
  85. package/lib-module/MultiSelectFilter/MultiSelectFilter.js +286 -0
  86. package/lib-module/MultiSelectFilter/dictionary.js +12 -0
  87. package/lib-module/MultiSelectFilter/index.js +2 -0
  88. package/lib-module/Pagination/PageButton.js +2 -2
  89. package/lib-module/Pagination/Pagination.js +3 -5
  90. package/lib-module/Pagination/usePagination.js +2 -2
  91. package/lib-module/Progress/ProgressBar.js +3 -3
  92. package/lib-module/Progress/ProgressBarBackground.js +3 -3
  93. package/lib-module/QuickLinksFeature/QuickLinksFeature.js +69 -0
  94. package/lib-module/QuickLinksFeature/QuickLinksFeatureItem.js +130 -0
  95. package/lib-module/QuickLinksFeature/index.js +4 -0
  96. package/lib-module/Radio/Radio.js +2 -2
  97. package/lib-module/Radio/RadioGroup.js +2 -2
  98. package/lib-module/RadioCard/RadioCard.js +1 -1
  99. package/lib-module/RadioCard/RadioCardGroup.js +2 -2
  100. package/lib-module/Search/Search.js +1 -1
  101. package/lib-module/Select/constants.js +5 -0
  102. package/lib-module/SideNav/SideNav.js +2 -2
  103. package/lib-module/Skeleton/Skeleton.js +1 -1
  104. package/lib-module/Skeleton/skeletonWebAnimation.js +1 -1
  105. package/lib-module/StackView/StackWrap.js +1 -3
  106. package/lib-module/StackView/getStackedContent.js +2 -2
  107. package/lib-module/Tabs/Tabs.js +2 -4
  108. package/lib-module/Tags/Tags.js +1 -1
  109. package/lib-module/TextInput/dictionary.js +12 -0
  110. package/lib-module/ThemeProvider/utils/styles.js +3 -3
  111. package/lib-module/ThemeProvider/utils/theme-tokens.js +9 -7
  112. package/lib-module/Timeline/Timeline.js +1 -1
  113. package/lib-module/ToggleSwitch/ToggleSwitch.js +1 -1
  114. package/lib-module/ToggleSwitch/ToggleSwitchGroup.js +1 -1
  115. package/lib-module/Tooltip/Backdrop.js +10 -2
  116. package/lib-module/Tooltip/Tooltip.native.js +326 -0
  117. package/lib-module/Tooltip/shared.js +27 -0
  118. package/lib-module/Validator/Validator.js +245 -0
  119. package/lib-module/Validator/index.js +2 -0
  120. package/lib-module/utils/BaseView/BaseView.js +43 -0
  121. package/lib-module/utils/BaseView/BaseView.native.js +6 -0
  122. package/lib-module/utils/BaseView/index.js +2 -0
  123. package/lib-module/utils/animation/useVerticalExpandAnimation.js +1 -1
  124. package/lib-module/utils/children.js +2 -2
  125. package/lib-module/utils/floating-ui/index.js +1 -0
  126. package/lib-module/utils/floating-ui/index.native.js +1 -0
  127. package/lib-module/utils/input.js +12 -6
  128. package/lib-module/utils/props/componentPropType.js +3 -3
  129. package/lib-module/utils/props/selectSystemProps.js +2 -2
  130. package/lib-module/utils/props/tokens.js +2 -2
  131. package/lib-module/utils/useOverlaidPosition.js +232 -0
  132. package/lib-module/utils/useSpacingScale.js +1 -3
  133. package/lib-module/utils/useUniqueId.js +1 -1
  134. package/package.json +2 -2
@@ -0,0 +1,357 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+
8
+ var _react = _interopRequireWildcard(require("react"));
9
+
10
+ var _Dimensions = _interopRequireDefault(require("react-native-web/dist/cjs/exports/Dimensions"));
11
+
12
+ var _Platform = _interopRequireDefault(require("react-native-web/dist/cjs/exports/Platform"));
13
+
14
+ var _Pressable = _interopRequireDefault(require("react-native-web/dist/cjs/exports/Pressable"));
15
+
16
+ var _StyleSheet = _interopRequireDefault(require("react-native-web/dist/cjs/exports/StyleSheet"));
17
+
18
+ var _Text = _interopRequireDefault(require("react-native-web/dist/cjs/exports/Text"));
19
+
20
+ var _View = _interopRequireDefault(require("react-native-web/dist/cjs/exports/View"));
21
+
22
+ var _shared = _interopRequireDefault(require("./shared"));
23
+
24
+ var _ThemeProvider = require("../ThemeProvider");
25
+
26
+ var _utils = require("../utils");
27
+
28
+ var _Backdrop = _interopRequireDefault(require("./Backdrop"));
29
+
30
+ var _getTooltipPosition = _interopRequireDefault(require("./getTooltipPosition"));
31
+
32
+ var _TooltipButton = _interopRequireDefault(require("../TooltipButton"));
33
+
34
+ var _useCopy = _interopRequireDefault(require("../utils/useCopy"));
35
+
36
+ var _dictionary = _interopRequireDefault(require("./dictionary"));
37
+
38
+ var _jsxRuntime = require("react/jsx-runtime");
39
+
40
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
41
+
42
+ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
43
+
44
+ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
45
+
46
+ const [selectProps, selectedSystemPropTypes] = (0, _utils.selectSystemProps)([_utils.a11yProps, _utils.viewProps]);
47
+
48
+ const selectTooltipStyles = _ref => {
49
+ let {
50
+ backgroundColor,
51
+ paddingTop,
52
+ paddingBottom,
53
+ paddingLeft,
54
+ paddingRight,
55
+ borderRadius
56
+ } = _ref;
57
+ return {
58
+ backgroundColor,
59
+ paddingTop,
60
+ paddingBottom,
61
+ paddingLeft,
62
+ paddingRight,
63
+ borderRadius
64
+ };
65
+ };
66
+
67
+ const selectTooltipShadowStyles = _ref2 => {
68
+ let {
69
+ shadow,
70
+ borderRadius
71
+ } = _ref2;
72
+ return {
73
+ borderRadius,
74
+ ...(0, _ThemeProvider.applyShadowToken)(shadow)
75
+ };
76
+ };
77
+
78
+ const selectTooltipPositionStyles = _ref3 => {
79
+ let {
80
+ top,
81
+ left,
82
+ width
83
+ } = _ref3;
84
+ return {
85
+ top,
86
+ left,
87
+ width
88
+ };
89
+ };
90
+
91
+ const selectArrowStyles = (_ref4, _ref5) => {
92
+ let {
93
+ backgroundColor,
94
+ arrowWidth,
95
+ arrowBorderRadius,
96
+ shadow
97
+ } = _ref4;
98
+ let {
99
+ position,
100
+ width: tooltipWidth,
101
+ height: tooltipHeight
102
+ } = _ref5;
103
+ // the arrow width is actually a diagonal of the rectangle that we'll use as a tip
104
+ const rectangleSide = Math.sqrt(arrowWidth * arrowWidth / 2); // position the arrow at the side and center of the tooltip - this happens before rotation
105
+ // so we use the rectangle size as basis
106
+
107
+ const verticalOffset = -1 * rectangleSide / 2;
108
+ const horizontalOffset = rectangleSide / 2; // percentage-based absolute positioning doesn't act well on native, so we have to
109
+ // calculate the pixel values
110
+
111
+ const directionalStyles = {
112
+ above: {
113
+ bottom: verticalOffset,
114
+ left: tooltipWidth / 2 - horizontalOffset,
115
+ transform: [{
116
+ rotateZ: '45deg'
117
+ }]
118
+ },
119
+ below: {
120
+ top: verticalOffset,
121
+ left: tooltipWidth / 2 - horizontalOffset,
122
+ transform: [{
123
+ rotateZ: '-135deg'
124
+ }]
125
+ },
126
+ left: {
127
+ right: verticalOffset,
128
+ top: tooltipHeight / 2 - horizontalOffset,
129
+ transform: [{
130
+ rotateZ: '-45deg'
131
+ }]
132
+ },
133
+ right: {
134
+ left: verticalOffset,
135
+ top: tooltipHeight / 2 - horizontalOffset,
136
+ transform: [{
137
+ rotateZ: '135deg'
138
+ }]
139
+ }
140
+ };
141
+ return {
142
+ backgroundColor,
143
+ width: rectangleSide,
144
+ height: rectangleSide,
145
+ borderBottomRightRadius: arrowBorderRadius,
146
+ // this corner will be the arrow tip after rotation
147
+ ...(0, _ThemeProvider.applyShadowToken)(shadow),
148
+ ...directionalStyles[position]
149
+ };
150
+ };
151
+
152
+ const selectTextStyles = tokens => (0, _ThemeProvider.applyTextStyles)((0, _utils.selectTokens)('Typography', tokens));
153
+
154
+ const defaultControl = (pressableState, variant) => /*#__PURE__*/(0, _jsxRuntime.jsx)(_TooltipButton.default, {
155
+ pressableState: pressableState,
156
+ variant: variant
157
+ });
158
+ /**
159
+ * Tooltip provides a descriptive and detailed explanation or instructions. It can be used next to an input label
160
+ * to help a user fill it in, or as a standalone component.
161
+ *
162
+ * By default the TooltipButton component will be used as a control for triggering the tooltip, but you may attach
163
+ * a tooltip to any other component. A render function can be used to adjust the control's styling on state changes (hover, focus, etc.).
164
+ *
165
+ * ### Positioning
166
+ * By default a Tooltip will be automatically positioned in a way that ensures it fits within the viewport.
167
+ * You may suggest a position with a prop - it will be used, unless the tooltip would end up outside the viewport.
168
+ *
169
+ * ### Usage criteria
170
+ * - You may use one when the information is useful only to a small percentage of users (ie. tech savvy people wouldn't need this info).
171
+ * - Tooltips may also be useful when vertical space is an issue.
172
+ */
173
+
174
+
175
+ const Tooltip = /*#__PURE__*/(0, _react.forwardRef)((_ref6, ref) => {
176
+ let {
177
+ children,
178
+ content,
179
+ position = 'auto',
180
+ copy = 'en',
181
+ tokens,
182
+ variant,
183
+ ...rest
184
+ } = _ref6;
185
+ const [isOpen, setIsOpen] = (0, _react.useState)(false);
186
+ const controlRef = (0, _react.useRef)();
187
+ const [controlLayout, setControlLayout] = (0, _react.useState)(null);
188
+ const [tooltipDimensions, setTooltipDimensions] = (0, _react.useState)(null);
189
+ const [windowDimensions, setWindowDimensions] = (0, _react.useState)(_Dimensions.default.get('window'));
190
+ const [tooltipPosition, setTooltipPosition] = (0, _react.useState)(null);
191
+ const getCopy = (0, _useCopy.default)({
192
+ dictionary: _dictionary.default,
193
+ copy
194
+ });
195
+ const themeTokens = (0, _ThemeProvider.useThemeTokens)('Tooltip', tokens, variant);
196
+ const {
197
+ arrowWidth,
198
+ arrowOffset
199
+ } = themeTokens;
200
+ (0, _react.useEffect)(() => {
201
+ const subscription = _Dimensions.default.addEventListener('change', _ref7 => {
202
+ let {
203
+ window
204
+ } = _ref7;
205
+ setWindowDimensions(window);
206
+ });
207
+
208
+ return () => subscription === null || subscription === void 0 ? void 0 : subscription.remove();
209
+ });
210
+
211
+ const toggleIsOpen = () => setIsOpen(!isOpen);
212
+
213
+ const close = () => setIsOpen(false);
214
+
215
+ const getPressableState = _ref8 => {
216
+ let {
217
+ pressed,
218
+ hovered,
219
+ focused
220
+ } = _ref8;
221
+ return {
222
+ pressed,
223
+ hover: hovered,
224
+ focus: focused
225
+ };
226
+ };
227
+
228
+ const onTooltipLayout = _ref9 => {
229
+ let {
230
+ nativeEvent: {
231
+ layout: {
232
+ width,
233
+ height
234
+ }
235
+ }
236
+ } = _ref9;
237
+
238
+ if (tooltipDimensions === null || tooltipDimensions.width !== width || tooltipDimensions.height !== height) {
239
+ setTooltipDimensions({
240
+ width: _Platform.default.select({
241
+ web: width + 0.3,
242
+ // avoids often unnecessary line breaks due to subpixel rendering of fonts
243
+ native: width
244
+ }),
245
+ height
246
+ });
247
+ }
248
+ };
249
+
250
+ (0, _react.useEffect)(() => {
251
+ if (isOpen) {
252
+ controlRef.current.measureInWindow((x, y, width, height) => {
253
+ setControlLayout({
254
+ x,
255
+ y,
256
+ width,
257
+ height
258
+ });
259
+ });
260
+ } else {
261
+ setControlLayout(null);
262
+ setTooltipDimensions(null);
263
+ setTooltipPosition(null);
264
+ }
265
+ }, [isOpen]);
266
+ (0, _react.useEffect)(() => {
267
+ setIsOpen(false);
268
+ }, [windowDimensions]);
269
+ (0, _react.useEffect)(() => {
270
+ if (tooltipPosition !== null && !(tooltipPosition !== null && tooltipPosition !== void 0 && tooltipPosition.isNormalized) || !isOpen || controlLayout === null || tooltipDimensions == null) {
271
+ return;
272
+ }
273
+
274
+ const updatedPosition = (0, _getTooltipPosition.default)(position, {
275
+ controlLayout,
276
+ tooltipDimensions,
277
+ windowDimensions,
278
+ arrowWidth,
279
+ arrowOffset
280
+ }); // avoid ending up in an infinite normalization loop
281
+
282
+ if (tooltipPosition !== null && tooltipPosition !== void 0 && tooltipPosition.isNormalized && updatedPosition.isNormalized) {
283
+ return;
284
+ }
285
+
286
+ setTooltipPosition(updatedPosition);
287
+ }, [isOpen, position, tooltipDimensions, controlLayout, windowDimensions, arrowWidth, arrowOffset, tooltipPosition]);
288
+ const control = children !== undefined ? children : defaultControl;
289
+ const pressableStyles = control === defaultControl ? _Platform.default.select({
290
+ web: {
291
+ outline: 'none'
292
+ }
293
+ }) : undefined;
294
+ const pressableHitSlop = control === defaultControl ? {
295
+ top: 10,
296
+ bottom: 10,
297
+ left: 10,
298
+ right: 10
299
+ } : undefined;
300
+ return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_View.default, {
301
+ style: staticStyles.container,
302
+ ...selectProps(rest),
303
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_Pressable.default, {
304
+ onPress: toggleIsOpen,
305
+ ref: controlRef,
306
+ onBlur: close,
307
+ style: pressableStyles,
308
+ hitSlop: pressableHitSlop,
309
+ accessibilityLabel: getCopy('a11yText'),
310
+ accessibilityRole: "button",
311
+ children: typeof control === 'function' ? pressableState => control(getPressableState(pressableState), variant) : control
312
+ }), isOpen && /*#__PURE__*/(0, _jsxRuntime.jsx)(_Backdrop.default, {
313
+ onPress: close,
314
+ children: /*#__PURE__*/(0, _jsxRuntime.jsxs)(_View.default, {
315
+ ref: ref,
316
+ style: [staticStyles.tooltip, selectTooltipShadowStyles(themeTokens), // applied separately so that it doesn't cover the arrow
317
+ tooltipPosition && selectTooltipPositionStyles(tooltipPosition), (tooltipPosition === null || (tooltipPosition === null || tooltipPosition === void 0 ? void 0 : tooltipPosition.isNormalized)) && staticStyles.tooltipHidden // visually hide the tooltip until we have a final measurement
318
+ ],
319
+ onLayout: onTooltipLayout,
320
+ accessibilityRole: "alert",
321
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_View.default, {
322
+ style: [staticStyles.arrow, tooltipPosition && selectArrowStyles(themeTokens, tooltipPosition)]
323
+ }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_View.default, {
324
+ style: selectTooltipStyles(themeTokens),
325
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_Text.default, {
326
+ style: selectTextStyles(themeTokens),
327
+ children: content
328
+ })
329
+ })]
330
+ })
331
+ })]
332
+ });
333
+ });
334
+ Tooltip.displayName = 'NativeTooltip';
335
+ Tooltip.propTypes = { ...selectedSystemPropTypes,
336
+ ..._shared.default
337
+ };
338
+ var _default = Tooltip;
339
+ exports.default = _default;
340
+
341
+ const staticStyles = _StyleSheet.default.create({
342
+ container: {
343
+ alignItems: 'flex-start'
344
+ },
345
+ tooltip: {
346
+ position: 'absolute',
347
+ maxWidth: 240,
348
+ top: 0,
349
+ left: 0
350
+ },
351
+ tooltipHidden: {
352
+ opacity: 0
353
+ },
354
+ arrow: {
355
+ position: 'absolute'
356
+ }
357
+ });
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+
8
+ var _propTypes = _interopRequireDefault(require("prop-types"));
9
+
10
+ var _utils = require("../utils");
11
+
12
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
13
+
14
+ const propTypes = {
15
+ /**
16
+ * Used to render the control (i.e. tooltip trigger). If a render function is used it will receive the
17
+ * pressable state and tooltip variant as an argument.
18
+ */
19
+ children: _propTypes.default.oneOfType([_propTypes.default.func, _propTypes.default.node]),
20
+
21
+ /**
22
+ * The message. Can be raw text or text components.
23
+ */
24
+ content: _propTypes.default.oneOfType([_propTypes.default.string, _propTypes.default.node]),
25
+
26
+ /**
27
+ * Select English or French copy for the accessible label.
28
+ */
29
+ copy: _propTypes.default.oneOf(['en', 'fr']),
30
+
31
+ /**
32
+ * Use to place the tooltip in a specific location (only if it fits within viewport).
33
+ */
34
+ position: _propTypes.default.oneOf(['auto', 'above', 'right', 'below', 'left']),
35
+ tokens: (0, _utils.getTokensPropType)('Tooltip'),
36
+ variant: _utils.variantProp.propType
37
+ };
38
+ var _default = propTypes;
39
+ exports.default = _default;
@@ -0,0 +1,271 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+
8
+ var _react = _interopRequireWildcard(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 _StyleSheet = _interopRequireDefault(require("react-native-web/dist/cjs/exports/StyleSheet"));
15
+
16
+ var _Platform = _interopRequireDefault(require("react-native-web/dist/cjs/exports/Platform"));
17
+
18
+ var _utils = require("../utils");
19
+
20
+ var _TextInput = require("../TextInput");
21
+
22
+ var _StackView = _interopRequireDefault(require("../StackView"));
23
+
24
+ var _InputSupports = _interopRequireDefault(require("../InputSupports"));
25
+
26
+ var _ThemeProvider = require("../ThemeProvider");
27
+
28
+ var _jsxRuntime = require("react/jsx-runtime");
29
+
30
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
31
+
32
+ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
33
+
34
+ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
35
+
36
+ const [selectProps, selectedSystemPropTypes] = (0, _utils.selectSystemProps)([_utils.inputSupportsProps]);
37
+
38
+ const selectCodeTextInputTokens = _ref => {
39
+ let {
40
+ outerBorderColor,
41
+ outerBackgroundColor
42
+ } = _ref;
43
+ return {
44
+ outerBorderColor,
45
+ outerBackgroundColor,
46
+ icon: null
47
+ };
48
+ };
49
+
50
+ const Validator = /*#__PURE__*/(0, _react.forwardRef)((_ref2, ref) => {
51
+ let {
52
+ value = '',
53
+ inactive,
54
+ onChange,
55
+ tokens = {},
56
+ variant = {},
57
+ ...rest
58
+ } = _ref2;
59
+ const defaultRef = (0, _react.useRef)();
60
+ const codeRef = ref ?? defaultRef;
61
+ const {
62
+ supportsProps
63
+ } = selectProps(rest);
64
+ const strValidation = supportsProps.validation;
65
+ const [individualCodes, setIndividualCodes] = (0, _react.useState)({});
66
+ const [text, setText] = (0, _react.useState)(value);
67
+ const validatorsLength = 6;
68
+ const prefix = 'code';
69
+ const sufixValidation = 'Validation';
70
+ const [isHover, setIsHover] = (0, _react.useState)(false);
71
+
72
+ const handleMouseOver = () => {
73
+ setIsHover(true);
74
+ };
75
+
76
+ const handleMouseOut = () => {
77
+ setIsHover(false);
78
+ };
79
+
80
+ const themeTokens = (0, _ThemeProvider.useThemeTokens)('TextInput', tokens, variant, {
81
+ hover: isHover
82
+ });
83
+ const [codeReferences, singleCodes] = (0, _react.useMemo)(() => {
84
+ const codes = [];
85
+ const valueCodes = {};
86
+
87
+ for (let i = 0; validatorsLength && i < validatorsLength; i += 1) {
88
+ codes[prefix + i] = /*#__PURE__*/(0, _react.createRef)();
89
+ valueCodes[prefix + i] = '';
90
+ valueCodes[prefix + i + sufixValidation] = '';
91
+ }
92
+
93
+ return [codes, valueCodes];
94
+ }, []);
95
+
96
+ const handleSingleCodes = (codeId, val, validation) => {
97
+ singleCodes[codeId] = val;
98
+ singleCodes[codeId + sufixValidation] = validation;
99
+ /* eslint-disable no-unused-expressions */
100
+
101
+ setIndividualCodes({ ...individualCodes,
102
+ [codeId]: val
103
+ });
104
+ };
105
+
106
+ const handleChangeCode = () => {
107
+ let code = '';
108
+
109
+ for (let i = 0; i < validatorsLength; i += 1) code += singleCodes[prefix + i];
110
+
111
+ if (typeof onChange === 'function') onChange(code, singleCodes);
112
+ };
113
+
114
+ const handleChangeCodeValues = (event, codeId, nextIndex) => {
115
+ var _codeReferences$codeI, _event$nativeEvent, _event$target, _codeElement$value, _codeElement$value2;
116
+
117
+ const codeElement = (_codeReferences$codeI = codeReferences[codeId]) === null || _codeReferences$codeI === void 0 ? void 0 : _codeReferences$codeI.current;
118
+ const val = ((_event$nativeEvent = event.nativeEvent) === null || _event$nativeEvent === void 0 ? void 0 : _event$nativeEvent.value) || ((_event$target = event.target) === null || _event$target === void 0 ? void 0 : _event$target.value);
119
+
120
+ if (Number(val).toString() === 'NaN') {
121
+ codeElement.value = singleCodes[codeId] ?? '';
122
+ return;
123
+ }
124
+
125
+ if ((codeElement === null || codeElement === void 0 ? void 0 : (_codeElement$value = codeElement.value) === null || _codeElement$value === void 0 ? void 0 : _codeElement$value.length) > 1) {
126
+ const oldValue = singleCodes[codeId];
127
+ const newValue = codeElement.value.replace(oldValue, '');
128
+ codeElement.value = newValue;
129
+ handleSingleCodes(codeId, codeElement.value, 'success');
130
+ }
131
+
132
+ handleSingleCodes(codeId, (codeElement === null || codeElement === void 0 ? void 0 : codeElement.value) ?? singleCodes[codeId], 'success');
133
+ handleChangeCode();
134
+
135
+ if (nextIndex === validatorsLength) {
136
+ codeElement.blur();
137
+ return;
138
+ }
139
+
140
+ if ((codeElement === null || codeElement === void 0 ? void 0 : (_codeElement$value2 = codeElement.value) === null || _codeElement$value2 === void 0 ? void 0 : _codeElement$value2.length) > 0) codeReferences[prefix + nextIndex].current.focus();
141
+ };
142
+
143
+ const handleKeyPress = (event, currentIndex, previousIndex) => {
144
+ if (!(event.keyCode === 8 || event.code === 'Backspace')) return;
145
+
146
+ if (currentIndex > 0) {
147
+ codeReferences[prefix + currentIndex].current.value = '';
148
+ codeReferences[prefix + previousIndex].current.focus();
149
+ }
150
+
151
+ handleSingleCodes(prefix + currentIndex, '', '');
152
+ handleChangeCode();
153
+ };
154
+
155
+ const getCodeComponents = () => {
156
+ const components = [];
157
+
158
+ for (let i = 0; validatorsLength && i < validatorsLength; i += 1) {
159
+ const codeId = prefix + i;
160
+ const codeInputProps = {
161
+ nativeID: codeId,
162
+ keyboardType: 'numeric',
163
+ ref: codeReferences[codeId] ?? null,
164
+ validation: strValidation || singleCodes[codeId + sufixValidation],
165
+ tokens: selectCodeTextInputTokens(themeTokens),
166
+ onFocus: () => {
167
+ var _codeReferences$codeI2, _codeReferences$codeI3;
168
+
169
+ return ((_codeReferences$codeI2 = codeReferences[codeId]) === null || _codeReferences$codeI2 === void 0 ? void 0 : (_codeReferences$codeI3 = _codeReferences$codeI2.current) === null || _codeReferences$codeI3 === void 0 ? void 0 : _codeReferences$codeI3.select()) ?? null;
170
+ },
171
+ onKeyPress: event => handleKeyPress(event, i, i - 1),
172
+ onMouseOver: handleMouseOver,
173
+ onMouseOut: handleMouseOut,
174
+ inactive
175
+ };
176
+ codeInputProps.validation || delete codeInputProps.validation;
177
+ components.push( /*#__PURE__*/(0, _jsxRuntime.jsx)(_View.default, {
178
+ style: staticStyles.codeInputWidth,
179
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_TextInput.TextInput, { ...codeInputProps
180
+ })
181
+ }, codeId));
182
+ }
183
+
184
+ return components;
185
+ };
186
+
187
+ (0, _react.useEffect)(() => {
188
+ /* eslint-disable no-unused-expressions */
189
+ if (Number(value).toString() !== 'NaN') setText(value);
190
+ }, [value]);
191
+ /* eslint-disable react-hooks/exhaustive-deps */
192
+
193
+ (0, _react.useEffect)(() => {
194
+ for (let i = 0; i < validatorsLength; i += 1) {
195
+ codeReferences[prefix + i].current.value = text[i] ?? '';
196
+ handleSingleCodes(prefix + i, text[i] ?? '', text[i] ? 'success' : '');
197
+ }
198
+ }, [text]);
199
+ /* eslint-disable react-hooks/exhaustive-deps */
200
+
201
+ (0, _react.useEffect)(() => {
202
+ const handlePasteCode = event => {
203
+ setText('');
204
+ const clipBoardText = event.clipboardData.getData('text');
205
+ if (Number(clipBoardText).toString() !== 'NaN') setText(clipBoardText);
206
+ };
207
+
208
+ const handleCopy = event => {
209
+ let clipBoardText = '';
210
+
211
+ for (let i = 0; i < validatorsLength; i += 1) singleCodes[prefix + i] && (clipBoardText += singleCodes[prefix + i]);
212
+
213
+ event.clipboardData.setData('text/plain', clipBoardText);
214
+ event.preventDefault();
215
+ };
216
+
217
+ if (_Platform.default.OS === 'web') {
218
+ for (let i = 0; i < validatorsLength; i += 1) {
219
+ codeReferences[prefix + i].current.addEventListener('paste', handlePasteCode);
220
+ codeReferences[prefix + i].current.addEventListener('copy', handleCopy);
221
+ codeReferences[prefix + i].current.addEventListener('input', event => handleChangeCodeValues(event, prefix + i, i + 1));
222
+ }
223
+ }
224
+
225
+ return () => {
226
+ if (_Platform.default.oldValue === 'web') {
227
+ for (let i = 0; i < validatorsLength; i += 1) {
228
+ var _codeReferences, _codeReferences$curre, _codeReferences2, _codeReferences2$curr, _codeReferences3, _codeReferences3$curr;
229
+
230
+ (_codeReferences = codeReferences[prefix + i]) === null || _codeReferences === void 0 ? void 0 : (_codeReferences$curre = _codeReferences.current) === null || _codeReferences$curre === void 0 ? void 0 : _codeReferences$curre.removeEventListener('paste', handlePasteCode);
231
+ (_codeReferences2 = codeReferences[prefix + i]) === null || _codeReferences2 === void 0 ? void 0 : (_codeReferences2$curr = _codeReferences2.current) === null || _codeReferences2$curr === void 0 ? void 0 : _codeReferences2$curr.removeEventListener('copy', handleCopy);
232
+ (_codeReferences3 = codeReferences[prefix + i]) === null || _codeReferences3 === void 0 ? void 0 : (_codeReferences3$curr = _codeReferences3.current) === null || _codeReferences3$curr === void 0 ? void 0 : _codeReferences3$curr.removeEventListener('input', event => handleChangeCodeValues(event, prefix + i, i + 1));
233
+ }
234
+ }
235
+ };
236
+ }, []);
237
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)(_InputSupports.default, { ...supportsProps,
238
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_StackView.default, {
239
+ space: 2,
240
+ direction: "row",
241
+ ref: codeRef,
242
+ children: getCodeComponents()
243
+ })
244
+ });
245
+ });
246
+ Validator.displayName = 'Validator';
247
+ Validator.propTypes = { ...selectedSystemPropTypes,
248
+
249
+ /**
250
+ * The value is a 6-digit code, may be only numeric characters, non numeric character aren't renderize
251
+ */
252
+ value: _propTypes.default.string,
253
+
254
+ /**
255
+ * If true, the component is inactive and non editable.
256
+ */
257
+ inactive: _propTypes.default.bool,
258
+
259
+ /**
260
+ * Use to react upon input's value changes. Required when the `value` prop is set. Will receive the input's value as an argument.
261
+ */
262
+ onChange: _propTypes.default.func
263
+ };
264
+ var _default = Validator;
265
+ exports.default = _default;
266
+
267
+ const staticStyles = _StyleSheet.default.create({
268
+ codeInputWidth: {
269
+ width: 43
270
+ }
271
+ });
@@ -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 _Validator = _interopRequireDefault(require("./Validator"));
9
+
10
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
11
+
12
+ var _default = _Validator.default;
13
+ exports.default = _default;