@telus-uds/components-base 1.18.1 → 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 (160) hide show
  1. package/CHANGELOG.md +22 -2
  2. package/component-docs.json +111 -16
  3. package/jest.config-android.js +17 -0
  4. package/jest.config-ios.js +18 -0
  5. package/jest.config-web.js +31 -0
  6. package/lib/ActivityIndicator/Spinner.js +7 -7
  7. package/lib/ActivityIndicator/Spinner.native.js +2 -2
  8. package/lib/BaseProvider/HydrationContext.js +1 -1
  9. package/lib/BaseProvider/TamaguiProvider.js +30 -0
  10. package/lib/Button/ButtonBase.js +8 -4
  11. package/lib/Button/ButtonDropdown.js +207 -0
  12. package/lib/Button/ButtonGroup.js +1 -1
  13. package/lib/Carousel/Carousel.js +31 -5
  14. package/lib/Carousel/CarouselContext.js +1 -1
  15. package/lib/Carousel/CarouselFirstFocus/CarouselFirstFocus.js +1 -1
  16. package/lib/Carousel/CarouselTabs/CarouselTabsPanel.js +1 -10
  17. package/lib/Carousel/CarouselThumbnail.js +2 -2
  18. package/lib/Checkbox/Checkbox.js +1 -1
  19. package/lib/Checkbox/CheckboxGroup.js +2 -2
  20. package/lib/Divider/Divider.js +2 -2
  21. package/lib/FlexGrid/Col/Col.js +1 -1
  22. package/lib/Icon/Icon.js +1 -1
  23. package/lib/MultiSelectFilter/ModalOverlay.js +136 -0
  24. package/lib/MultiSelectFilter/MultiSelectFilter.js +314 -0
  25. package/lib/MultiSelectFilter/dictionary.js +19 -0
  26. package/lib/MultiSelectFilter/index.js +13 -0
  27. package/lib/Pagination/PageButton.js +2 -2
  28. package/lib/Pagination/Pagination.js +3 -5
  29. package/lib/Pagination/SideButton.js +6 -4
  30. package/lib/Pagination/usePagination.js +2 -2
  31. package/lib/Progress/ProgressBar.js +3 -3
  32. package/lib/Progress/ProgressBarBackground.js +3 -3
  33. package/lib/QuickLinksFeature/QuickLinksFeature.js +91 -0
  34. package/lib/QuickLinksFeature/QuickLinksFeatureItem.js +157 -0
  35. package/lib/QuickLinksFeature/index.js +16 -0
  36. package/lib/Radio/Radio.js +2 -2
  37. package/lib/Radio/RadioGroup.js +2 -2
  38. package/lib/RadioCard/RadioCard.js +1 -1
  39. package/lib/RadioCard/RadioCardGroup.js +2 -2
  40. package/lib/Responsive/Responsive.js +58 -0
  41. package/lib/Responsive/index.js +13 -0
  42. package/lib/Search/Search.js +30 -63
  43. package/lib/Select/constants.js +15 -0
  44. package/lib/SideNav/SideNav.js +2 -2
  45. package/lib/Skeleton/Skeleton.js +1 -1
  46. package/lib/Skeleton/skeletonWebAnimation.js +1 -1
  47. package/lib/StackView/StackWrap.js +1 -3
  48. package/lib/StackView/getStackedContent.js +2 -2
  49. package/lib/Tabs/Tabs.js +2 -4
  50. package/lib/Tags/Tags.js +11 -5
  51. package/lib/TextInput/TextInputBase.js +53 -19
  52. package/lib/TextInput/dictionary.js +19 -0
  53. package/lib/ThemeProvider/utils/styles.js +3 -3
  54. package/lib/ThemeProvider/utils/theme-tokens.js +9 -7
  55. package/lib/Timeline/Timeline.js +1 -1
  56. package/lib/ToggleSwitch/ToggleSwitch.js +1 -1
  57. package/lib/ToggleSwitch/ToggleSwitchGroup.js +1 -1
  58. package/lib/Tooltip/Backdrop.js +10 -2
  59. package/lib/Tooltip/Tooltip.native.js +357 -0
  60. package/lib/Tooltip/shared.js +39 -0
  61. package/lib/Validator/Validator.js +271 -0
  62. package/lib/Validator/index.js +13 -0
  63. package/lib/index.js +9 -0
  64. package/lib/utils/BaseView/BaseView.js +64 -0
  65. package/lib/utils/BaseView/BaseView.native.js +16 -0
  66. package/lib/utils/BaseView/index.js +13 -0
  67. package/lib/utils/animation/useVerticalExpandAnimation.js +1 -1
  68. package/lib/utils/children.js +2 -2
  69. package/lib/utils/floating-ui/index.js +43 -0
  70. package/lib/utils/floating-ui/index.native.js +43 -0
  71. package/lib/utils/input.js +12 -6
  72. package/lib/utils/props/componentPropType.js +3 -3
  73. package/lib/utils/props/selectSystemProps.js +2 -2
  74. package/lib/utils/props/tokens.js +2 -2
  75. package/lib/utils/useOverlaidPosition.js +243 -0
  76. package/lib/utils/useSpacingScale.js +1 -3
  77. package/lib/utils/useUniqueId.js +1 -1
  78. package/lib-module/ActivityIndicator/Spinner.js +7 -7
  79. package/lib-module/ActivityIndicator/Spinner.native.js +2 -2
  80. package/lib-module/BaseProvider/HydrationContext.js +1 -1
  81. package/lib-module/BaseProvider/TamaguiProvider.js +22 -0
  82. package/lib-module/Button/ButtonBase.js +8 -4
  83. package/lib-module/Button/ButtonDropdown.js +181 -0
  84. package/lib-module/Button/ButtonGroup.js +1 -1
  85. package/lib-module/Carousel/Carousel.js +31 -5
  86. package/lib-module/Carousel/CarouselContext.js +1 -1
  87. package/lib-module/Carousel/CarouselFirstFocus/CarouselFirstFocus.js +1 -1
  88. package/lib-module/Carousel/CarouselTabs/CarouselTabsPanel.js +1 -10
  89. package/lib-module/Carousel/CarouselThumbnail.js +2 -2
  90. package/lib-module/Checkbox/Checkbox.js +1 -1
  91. package/lib-module/Checkbox/CheckboxGroup.js +2 -2
  92. package/lib-module/Divider/Divider.js +2 -2
  93. package/lib-module/FlexGrid/Col/Col.js +1 -1
  94. package/lib-module/Icon/Icon.js +1 -1
  95. package/lib-module/MultiSelectFilter/ModalOverlay.js +112 -0
  96. package/lib-module/MultiSelectFilter/MultiSelectFilter.js +286 -0
  97. package/lib-module/MultiSelectFilter/dictionary.js +12 -0
  98. package/lib-module/MultiSelectFilter/index.js +2 -0
  99. package/lib-module/Pagination/PageButton.js +2 -2
  100. package/lib-module/Pagination/Pagination.js +3 -5
  101. package/lib-module/Pagination/SideButton.js +6 -4
  102. package/lib-module/Pagination/usePagination.js +2 -2
  103. package/lib-module/Progress/ProgressBar.js +3 -3
  104. package/lib-module/Progress/ProgressBarBackground.js +3 -3
  105. package/lib-module/QuickLinksFeature/QuickLinksFeature.js +69 -0
  106. package/lib-module/QuickLinksFeature/QuickLinksFeatureItem.js +130 -0
  107. package/lib-module/QuickLinksFeature/index.js +4 -0
  108. package/lib-module/Radio/Radio.js +2 -2
  109. package/lib-module/Radio/RadioGroup.js +2 -2
  110. package/lib-module/RadioCard/RadioCard.js +1 -1
  111. package/lib-module/RadioCard/RadioCardGroup.js +2 -2
  112. package/lib-module/Responsive/Responsive.js +45 -0
  113. package/lib-module/Responsive/index.js +2 -0
  114. package/lib-module/Search/Search.js +30 -61
  115. package/lib-module/Select/constants.js +5 -0
  116. package/lib-module/SideNav/SideNav.js +2 -2
  117. package/lib-module/Skeleton/Skeleton.js +1 -1
  118. package/lib-module/Skeleton/skeletonWebAnimation.js +1 -1
  119. package/lib-module/StackView/StackWrap.js +1 -3
  120. package/lib-module/StackView/getStackedContent.js +2 -2
  121. package/lib-module/Tabs/Tabs.js +2 -4
  122. package/lib-module/Tags/Tags.js +11 -5
  123. package/lib-module/TextInput/TextInputBase.js +52 -19
  124. package/lib-module/TextInput/dictionary.js +12 -0
  125. package/lib-module/ThemeProvider/utils/styles.js +3 -3
  126. package/lib-module/ThemeProvider/utils/theme-tokens.js +9 -7
  127. package/lib-module/Timeline/Timeline.js +1 -1
  128. package/lib-module/ToggleSwitch/ToggleSwitch.js +1 -1
  129. package/lib-module/ToggleSwitch/ToggleSwitchGroup.js +1 -1
  130. package/lib-module/Tooltip/Backdrop.js +10 -2
  131. package/lib-module/Tooltip/Tooltip.native.js +326 -0
  132. package/lib-module/Tooltip/shared.js +27 -0
  133. package/lib-module/Validator/Validator.js +245 -0
  134. package/lib-module/Validator/index.js +2 -0
  135. package/lib-module/index.js +1 -0
  136. package/lib-module/utils/BaseView/BaseView.js +43 -0
  137. package/lib-module/utils/BaseView/BaseView.native.js +6 -0
  138. package/lib-module/utils/BaseView/index.js +2 -0
  139. package/lib-module/utils/animation/useVerticalExpandAnimation.js +1 -1
  140. package/lib-module/utils/children.js +2 -2
  141. package/lib-module/utils/floating-ui/index.js +1 -0
  142. package/lib-module/utils/floating-ui/index.native.js +1 -0
  143. package/lib-module/utils/input.js +12 -6
  144. package/lib-module/utils/props/componentPropType.js +3 -3
  145. package/lib-module/utils/props/selectSystemProps.js +2 -2
  146. package/lib-module/utils/props/tokens.js +2 -2
  147. package/lib-module/utils/useOverlaidPosition.js +232 -0
  148. package/lib-module/utils/useSpacingScale.js +1 -3
  149. package/lib-module/utils/useUniqueId.js +1 -1
  150. package/package.json +7 -4
  151. package/src/Button/ButtonBase.jsx +4 -2
  152. package/src/Carousel/Carousel.jsx +42 -10
  153. package/src/Carousel/CarouselTabs/CarouselTabsPanel.jsx +0 -10
  154. package/src/Pagination/SideButton.jsx +5 -5
  155. package/src/Responsive/Responsive.jsx +33 -0
  156. package/src/Responsive/index.js +3 -0
  157. package/src/Search/Search.jsx +17 -32
  158. package/src/Tags/Tags.jsx +46 -33
  159. package/src/TextInput/TextInputBase.jsx +46 -16
  160. package/src/index.js +1 -0
@@ -92,7 +92,7 @@ const ButtonGroup = /*#__PURE__*/(0, _react.forwardRef)((_ref, ref) => {
92
92
  const uniqueFields = ['id', 'label'];
93
93
 
94
94
  if (!(0, _utils.containUniqueFields)(items, uniqueFields)) {
95
- throw new Error("ButtonGroup items must have unique ".concat(uniqueFields.join(', ')));
95
+ throw new Error(`ButtonGroup items must have unique ${uniqueFields.join(', ')}`);
96
96
  } // Some web screenreaders e.g. MacOS Voiceover don't handle radiogroups properly unless radio is direct child of radiogroup
97
97
 
98
98
 
@@ -180,7 +180,7 @@ const Carousel = /*#__PURE__*/_react.default.forwardRef((_ref, ref) => {
180
180
  }) : /*#__PURE__*/(0, _jsxRuntime.jsx)(_CarouselStepTracker.default, {}),
181
181
  tag = 'ul',
182
182
  accessibilityRole,
183
- accessibilityLabel = title,
183
+ accessibilityLabel,
184
184
  accessibilityLiveRegion = 'polite',
185
185
  copy,
186
186
  ...rest
@@ -445,12 +445,39 @@ const Carousel = /*#__PURE__*/_react.default.forwardRef((_ref, ref) => {
445
445
  const getCopyWithPlaceholders = _react.default.useCallback(copyKey => {
446
446
  const copyText = getCopy(copyKey).replace(/%\{title\}/g, title).replace(/%\{itemLabel\}/g, itemLabel).replace(/%\{stepNumber\}/g, activeIndex + 1).replace(/%\{stepCount\}/g, childrenArray.length); // First word might be a lowercase placeholder: capitalize the first letter
447
447
 
448
- return "".concat(copyText[0].toUpperCase()).concat(copyText.slice(1));
448
+ return `${copyText[0].toUpperCase()}${copyText.slice(1)}`;
449
449
  }, [activeIndex, childrenArray.length, itemLabel, getCopy, title]);
450
450
 
451
451
  const activePanelNavigation = tabs && showPanelTabs ? /*#__PURE__*/(0, _jsxRuntime.jsx)(_CarouselTabsPanel.default, {
452
452
  items: tabs
453
453
  }) : panelNavigation;
454
+ const isFirstFocusContainer = Boolean(refocus && !skipLinkHref);
455
+
456
+ const containerRef = element => {
457
+ // Apply both firstFocusRef to the container
458
+ firstFocusRef.current = element; // Also apply forwarded ref if there is one (which could be a function ref)
459
+
460
+ if (ref) {
461
+ if (typeof ref === 'object') {
462
+ // eslint-disable-next-line no-param-reassign
463
+ ref.current = element;
464
+ } else if (typeof ref === 'function') {
465
+ ref(element);
466
+ }
467
+ }
468
+ }; // If container isn't used for focus, give it a label of title if none is passed in,
469
+ // otherwise read the current position on focus
470
+
471
+
472
+ const containerAccessibilityLabel = systemProps.accessibilityLabel ?? isFirstFocusContainer ? `${title ? `${title} ` : ''}${getCopyWithPlaceholders('stepTrackerLabel')}` : title;
473
+ const containerProps = {
474
+ accessibilityLabel: containerAccessibilityLabel,
475
+ // If used for focus, attach the ref and draw a focus box around the whole carousel
476
+ ...(isFirstFocusContainer && {
477
+ ref: containerRef,
478
+ focusable: true
479
+ })
480
+ };
454
481
  return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_CarouselContext.CarouselProvider, {
455
482
  activeIndex: activeIndex,
456
483
  goTo: goTo,
@@ -466,6 +493,7 @@ const Carousel = /*#__PURE__*/_react.default.forwardRef((_ref, ref) => {
466
493
  onLayout: onContainerLayout,
467
494
  ref: ref,
468
495
  ...systemProps,
496
+ ...containerProps,
469
497
  children: [showPreviousNextNavigation && /*#__PURE__*/(0, _jsxRuntime.jsx)(_View.default, {
470
498
  style: selectPreviousNextNavigationButtonStyles(previousNextNavigationButtonWidth, previousNextNavigationPosition, spaceBetweenSlideAndPreviousNextNavigation, isFirstSlide, isLastSlide, true),
471
499
  testID: "previous-button-container",
@@ -480,12 +508,10 @@ const Carousel = /*#__PURE__*/_react.default.forwardRef((_ref, ref) => {
480
508
  ref: firstFocusRef,
481
509
  href: skipLinkHref,
482
510
  children: getCopyWithPlaceholders('skipLink')
483
- }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_A11yText.default // Read the current slide position to screen readers on slide.
511
+ }), !isFirstFocusContainer && /*#__PURE__*/(0, _jsxRuntime.jsx)(_A11yText.default // Read the current slide position to screen readers on slide.
484
512
  // If it's set to refocus and doesn't have a SkipLink to focus to, focus this.
485
513
  , {
486
- ref: !skipLinkHref && refocus ? firstFocusRef : null,
487
514
  accessibilityLiveRegion: !skipLinkHref && refocus ? undefined : 'polite',
488
- focusable: !skipLinkHref && refocus,
489
515
  text: getCopyWithPlaceholders('stepTrackerLabel')
490
516
  }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_View.default, {
491
517
  style: selectContainerStyles(containerLayout.width),
@@ -54,7 +54,7 @@ function useCarousel() {
54
54
  const context = _react.default.useContext(CarouselContext);
55
55
 
56
56
  if (context === undefined) {
57
- throw new Error("'useCarousel' must be used within a 'CarouselProvider'");
57
+ throw new Error(`'useCarousel' must be used within a 'CarouselProvider'`);
58
58
  }
59
59
 
60
60
  return context;
@@ -40,7 +40,7 @@ const CarouselFirstFocus = /*#__PURE__*/(0, _react.forwardRef)((_ref, ref) => {
40
40
  } = (0, _CarouselContext.useCarousel)(); // TODO: integrate skip link description if behaving as skip link.
41
41
  // Consider moving this content to aria-live area while only the skip link is focused.
42
42
 
43
- const accessibilityLabel = "".concat(title, ", ").concat(getCopyWithPlaceholders('stepTrackerLabel'));
43
+ const accessibilityLabel = `${title}, ${getCopyWithPlaceholders('stepTrackerLabel')}`;
44
44
 
45
45
  const accessibilityRole = _Platform.default.select({
46
46
  web: 'link',
@@ -43,16 +43,7 @@ const CarouselTabsPanel = /*#__PURE__*/(0, _react.forwardRef)((_ref, ref) => {
43
43
  };
44
44
  const lastTabSelected = activeIndex === items.length - 1;
45
45
  return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
46
- children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_View.default, {
47
- focusable: true,
48
- accessible: true,
49
- onFocus: event => {
50
- // When user forward-tabs into this section, focus the next tab; if they backwards-tab
51
- // (shift-tab) back into the carousel content, don't interfere.
52
- const previousWebFocus = event.relatedTarget;
53
- if (previousWebFocus !== firstTabRef.current) nextFocusRef.current.focus();
54
- }
55
- }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_StackView.default, {
46
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_StackView.default, {
56
47
  direction: "row",
57
48
  space: 3,
58
49
  divider: {
@@ -38,7 +38,7 @@ const CarouselThumbnail = _ref => {
38
38
  goTo,
39
39
  themeTokens
40
40
  } = (0, _CarouselContext.useCarousel)();
41
- const thumbnailTitle = alt !== null && alt !== void 0 ? alt : getCopyWithPlaceholders('stepTrackerLabel').replace(/%\{itemLabel\}/g, itemLabel).replace(/%\{stepNumber\}/g, index).replace(/%\{stepCount\}/g, totalItems);
41
+ const thumbnailTitle = alt ?? getCopyWithPlaceholders('stepTrackerLabel').replace(/%\{itemLabel\}/g, itemLabel).replace(/%\{stepNumber\}/g, index).replace(/%\{stepCount\}/g, totalItems);
42
42
 
43
43
  const handlePress = () => goTo(index);
44
44
 
@@ -81,7 +81,7 @@ const CarouselThumbnail = _ref => {
81
81
  style: [styles.pressable, index === activeIndex && styles.selected],
82
82
  children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_Image.default, {
83
83
  accessibilityIgnoresInvertColors: true,
84
- accessibilityLabel: accessibilityLabel !== null && accessibilityLabel !== void 0 ? accessibilityLabel : alt,
84
+ accessibilityLabel: accessibilityLabel ?? alt,
85
85
  source: src,
86
86
  style: styles.image,
87
87
  title: thumbnailTitle
@@ -215,7 +215,7 @@ const Checkbox = /*#__PURE__*/(0, _react.forwardRef)((_ref5, ref) => {
215
215
  };
216
216
 
217
217
  const uniqueId = (0, _useUniqueId.default)('checkbox');
218
- const inputId = id !== null && id !== void 0 ? id : uniqueId;
218
+ const inputId = id ?? uniqueId;
219
219
  const {
220
220
  themeOptions
221
221
  } = (0, _ThemeProvider.useTheme)();
@@ -120,7 +120,7 @@ const CheckboxGroup = /*#__PURE__*/(0, _react.forwardRef)((_ref, ref) => {
120
120
  const uniqueFields = ['id', 'label'];
121
121
 
122
122
  if (!(0, _utils.containUniqueFields)(items, uniqueFields)) {
123
- throw new Error("CheckboxGroup items must have unique ".concat(uniqueFields.join(', ')));
123
+ throw new Error(`CheckboxGroup items must have unique ${uniqueFields.join(', ')}`);
124
124
  }
125
125
 
126
126
  const checkboxes = items.map((_ref2, index) => {
@@ -131,7 +131,7 @@ const CheckboxGroup = /*#__PURE__*/(0, _react.forwardRef)((_ref, ref) => {
131
131
  ref: itemRef,
132
132
  ...itemRest
133
133
  } = _ref2;
134
- const checkboxId = id || "Checkbox[".concat(index, "]");
134
+ const checkboxId = id || `Checkbox[${index}]`;
135
135
 
136
136
  const handleChange = (newCheckedState, event) => {
137
137
  if (typeof itemOnChange === 'function') itemOnChange(newCheckedState, event);
@@ -116,9 +116,9 @@ const Divider = /*#__PURE__*/(0, _react.forwardRef)((_ref, ref) => {
116
116
  };
117
117
  return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
118
118
  children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_Spacer.default, { ...spacerProps,
119
- testID: testID ? "".concat(testID, "-Spacer-before") : undefined
119
+ testID: testID ? `${testID}-Spacer-before` : undefined
120
120
  }), divider, /*#__PURE__*/(0, _jsxRuntime.jsx)(_Spacer.default, { ...spacerProps,
121
- testID: testID ? "".concat(testID, "-Spacer-after") : undefined
121
+ testID: testID ? `${testID}-Spacer-after` : undefined
122
122
  })]
123
123
  });
124
124
  });
@@ -69,7 +69,7 @@ const Col = /*#__PURE__*/(0, _react.forwardRef)((_ref, ref) => {
69
69
  const horizontalAlignLevel = getHorizontalAlignLevel();
70
70
 
71
71
  const toPercent = num => {
72
- return "".concat(num / 12 * 100, "%");
72
+ return `${num / 12 * 100}%`;
73
73
  };
74
74
 
75
75
  const calculateWidth = value => {
package/lib/Icon/Icon.js CHANGED
@@ -48,7 +48,7 @@ const Icon = /*#__PURE__*/(0, _react.forwardRef)((_ref, ref) => {
48
48
  // TODO: systematise animations.
49
49
  // https://github.com/telus/universal-design-system/issues/487
50
50
  transition: 'transform 200ms, color 200ms',
51
- transform: [themeTokens.scale ? "scale(".concat(themeTokens.scale, ")") : '', themeTokens.translateX ? "translateX(".concat(themeTokens.translateX, "px)") : '', themeTokens.translateY ? "translateY(".concat(themeTokens.translateY, "px)") : ''].filter(exists => exists).join(' ')
51
+ transform: [themeTokens.scale ? `scale(${themeTokens.scale})` : '', themeTokens.translateX ? `translateX(${themeTokens.translateX}px)` : '', themeTokens.translateY ? `translateY(${themeTokens.translateY}px)` : ''].filter(exists => exists).join(' ')
52
52
  },
53
53
  dataSet: dataSet,
54
54
  children: iconContent
@@ -0,0 +1,136 @@
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 _portal = require("@gorhom/portal");
17
+
18
+ var _utils = require("../utils");
19
+
20
+ var _ViewportProvider = require("../ViewportProvider");
21
+
22
+ var _ThemeProvider = require("../ThemeProvider");
23
+
24
+ var _dictionary = _interopRequireDefault(require("./dictionary"));
25
+
26
+ var _Card = _interopRequireDefault(require("../Card"));
27
+
28
+ var _IconButton = _interopRequireDefault(require("../IconButton"));
29
+
30
+ var _jsxRuntime = require("react/jsx-runtime");
31
+
32
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
33
+
34
+ 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); }
35
+
36
+ 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; }
37
+
38
+ const staticStyles = _StyleSheet.default.create({
39
+ positioner: {
40
+ flex: 1,
41
+ // Grow to maxWidth when possible, shrink when not possible
42
+ position: 'absolute',
43
+ height: 330,
44
+ paddingTop: 5,
45
+ zIndex: 10000 // Position on top of all the other overlays, including backdrops and modals
46
+
47
+ },
48
+ closeButtonContainer: {
49
+ position: 'absolute',
50
+ top: 0,
51
+ right: 0,
52
+ zIndex: 1
53
+ }
54
+ });
55
+
56
+ const selectCloseButtonContainerStyles = _ref => {
57
+ let {
58
+ paddingRight,
59
+ paddingTop
60
+ } = _ref;
61
+ return {
62
+ paddingRight,
63
+ paddingTop
64
+ };
65
+ };
66
+
67
+ const selectPaddingContainerStyles = _ref2 => {
68
+ let {
69
+ paddingTop,
70
+ paddingLeft,
71
+ paddingRight
72
+ } = _ref2;
73
+ return {
74
+ paddingBottom: 35,
75
+ paddingTop,
76
+ paddingLeft,
77
+ paddingRight
78
+ };
79
+ };
80
+
81
+ const ModalOverlay = /*#__PURE__*/(0, _react.forwardRef)((_ref3, ref) => {
82
+ let {
83
+ children,
84
+ tokens,
85
+ variant,
86
+ copy,
87
+ onClose
88
+ } = _ref3;
89
+ const viewport = (0, _ViewportProvider.useViewport)();
90
+ const themeTokens = (0, _ThemeProvider.useThemeTokens)('Modal', tokens, variant, {
91
+ viewport,
92
+ maxWidth: false
93
+ });
94
+ const {
95
+ closeIcon: CloseIconComponent,
96
+ maxWidth
97
+ } = themeTokens;
98
+ const getCopy = (0, _utils.useCopy)({
99
+ dictionary: _dictionary.default,
100
+ copy
101
+ });
102
+ const closeLabel = getCopy('closeButton');
103
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)(_jsxRuntime.Fragment, {
104
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_portal.Portal, {
105
+ ref: ref,
106
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_View.default, {
107
+ style: [{
108
+ minWidth: maxWidth
109
+ }, staticStyles.positioner],
110
+ children: /*#__PURE__*/(0, _jsxRuntime.jsxs)(_Card.default, {
111
+ tokens: selectPaddingContainerStyles(themeTokens),
112
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_View.default, {
113
+ style: [staticStyles.closeButtonContainer, selectCloseButtonContainerStyles(themeTokens)],
114
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_IconButton.default, {
115
+ onPress: onClose,
116
+ icon: CloseIconComponent,
117
+ accessibilityRole: "button",
118
+ accessibilityLabel: closeLabel,
119
+ tokens: (0, _utils.selectTokens)('IconButton', themeTokens, 'close')
120
+ })
121
+ }), children]
122
+ })
123
+ })
124
+ })
125
+ });
126
+ });
127
+ ModalOverlay.displayName = 'ModalOverlay';
128
+ ModalOverlay.propTypes = {
129
+ children: _propTypes.default.node.isRequired,
130
+ variant: _utils.variantProp.propType,
131
+ tokens: (0, _utils.getTokensPropType)('Modal'),
132
+ copy: _utils.copyPropTypes,
133
+ onClose: _propTypes.default.func
134
+ };
135
+ var _default = ModalOverlay;
136
+ exports.default = _default;
@@ -0,0 +1,314 @@
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 _ThemeProvider = require("../ThemeProvider");
13
+
14
+ var _utils = require("../utils");
15
+
16
+ var _dictionary = _interopRequireDefault(require("./dictionary"));
17
+
18
+ var _Box = _interopRequireDefault(require("../Box"));
19
+
20
+ var _Button = require("../Button");
21
+
22
+ var _Checkbox = require("../Checkbox");
23
+
24
+ var _Divider = _interopRequireDefault(require("../Divider"));
25
+
26
+ var _FlexGrid = _interopRequireDefault(require("../FlexGrid"));
27
+
28
+ var _Spacer = _interopRequireDefault(require("../Spacer"));
29
+
30
+ var _StackView = _interopRequireDefault(require("../StackView"));
31
+
32
+ var _Typography = _interopRequireDefault(require("../Typography"));
33
+
34
+ var _Link = require("../Link");
35
+
36
+ var _ModalOverlay = _interopRequireDefault(require("./ModalOverlay"));
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 {
47
+ Col,
48
+ Row
49
+ } = _FlexGrid.default;
50
+
51
+ const selectSubTitleTokens = _ref => {
52
+ let {
53
+ subtitleColor
54
+ } = _ref;
55
+ return {
56
+ color: subtitleColor
57
+ };
58
+ };
59
+
60
+ const selectDividerToknes = _ref2 => {
61
+ let {
62
+ dividerColor,
63
+ width,
64
+ decorative = true,
65
+ weight = 'thin'
66
+ } = _ref2;
67
+ return {
68
+ color: dividerColor,
69
+ width,
70
+ decorative,
71
+ weight
72
+ };
73
+ };
74
+
75
+ const MultiSelectFilter = /*#__PURE__*/(0, _react.forwardRef)((_ref3, ref) => {
76
+ let {
77
+ label,
78
+ subtitle,
79
+ id = label,
80
+ variant,
81
+ tokens,
82
+ items = [],
83
+ values,
84
+ initialValues,
85
+ maxValues,
86
+ onChange,
87
+ copy = 'en',
88
+ readOnly = false,
89
+ inactive = false,
90
+ rowLimit = 12,
91
+ ...rest
92
+ } = _ref3;
93
+ const {
94
+ currentValues,
95
+ setValues
96
+ } = (0, _utils.useMultipleInputValues)({
97
+ initialValues,
98
+ values,
99
+ maxValues,
100
+ onChange,
101
+ readOnly
102
+ });
103
+ const themeTokens = (0, _ThemeProvider.useThemeTokens)('ButtonDropdown', tokens, variant);
104
+ const getItemTokens = (0, _ThemeProvider.useThemeTokensCallback)('ButtonDropdown', tokens, variant);
105
+
106
+ const getButtonTokens = buttonState => (0, _utils.selectTokens)('Button', getItemTokens(buttonState));
107
+
108
+ const getCopy = (0, _utils.useCopy)({
109
+ dictionary: _dictionary.default,
110
+ copy
111
+ });
112
+ const [isOpen, setIsOpen] = (0, _react.useState)(false);
113
+ const [checkedIds, setCheckedIds] = (0, _react.useState)(currentValues ?? []);
114
+ const colSize = items.length > rowLimit ? 2 : 1;
115
+ const isSelected = currentValues.length > 0;
116
+ const uniqueFields = ['id', 'label'];
117
+
118
+ if (!(0, _utils.containUniqueFields)(items, uniqueFields)) {
119
+ throw new Error(`MultiSelectFilter items must have unique ${uniqueFields.join(', ')}`);
120
+ } // Pass an object of relevant component state as first argument for any passed-in press handlers
121
+
122
+
123
+ const pressHandlers = (0, _utils.getPressHandlersWithArgs)(rest, [{
124
+ id,
125
+ label,
126
+ currentValues
127
+ }]);
128
+
129
+ const handleChange = event => {
130
+ if (pressHandlers.onPress) pressHandlers === null || pressHandlers === void 0 ? void 0 : pressHandlers.onPress(event);
131
+ setIsOpen(!isOpen);
132
+ };
133
+
134
+ const onApply = e => {
135
+ setValues(e);
136
+ setIsOpen(false);
137
+ };
138
+
139
+ return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
140
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_Button.ButtonDropdown, {
141
+ ref: ref,
142
+ ...pressHandlers,
143
+ value: isOpen,
144
+ selected: isSelected,
145
+ label: label,
146
+ onChange: handleChange,
147
+ tokens: getButtonTokens,
148
+ inactive: inactive
149
+ }, id), isOpen && /*#__PURE__*/(0, _jsxRuntime.jsxs)(_ModalOverlay.default, {
150
+ variant: {
151
+ width: colSize > 1 ? 'size576' : 's'
152
+ },
153
+ onClose: () => setIsOpen(false),
154
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(Row, {
155
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_Typography.default, {
156
+ variant: {
157
+ size: 'h4'
158
+ },
159
+ children: getCopy('filterByLabel').replace(/%\{filterCategory\}/g, label.toLowerCase())
160
+ })
161
+ }), subtitle && /*#__PURE__*/(0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
162
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_Spacer.default, {
163
+ space: 5
164
+ }), /*#__PURE__*/(0, _jsxRuntime.jsx)(Row, {
165
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_Typography.default, {
166
+ variant: {
167
+ size: 'h5'
168
+ },
169
+ tokens: selectSubTitleTokens(themeTokens),
170
+ children: subtitle
171
+ })
172
+ })]
173
+ }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_Spacer.default, {
174
+ space: 4
175
+ }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_Box.default, {
176
+ scroll: true,
177
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)(Row, {
178
+ distribute: "between",
179
+ children: [...Array(colSize).keys()].map(i => /*#__PURE__*/(0, _jsxRuntime.jsxs)(Col, {
180
+ xs: 12 / colSize,
181
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_Checkbox.CheckboxGroup, {
182
+ items: items.slice(i * rowLimit, (i + 1) * rowLimit),
183
+ checkedIds: checkedIds,
184
+ onChange: e => setCheckedIds(e, i)
185
+ }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_Spacer.default, {
186
+ size: 4
187
+ })]
188
+ }, i))
189
+ })
190
+ }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_Divider.default, {
191
+ variant: selectDividerToknes({ ...themeTokens,
192
+ width: 'full'
193
+ }),
194
+ space: 4
195
+ }), /*#__PURE__*/(0, _jsxRuntime.jsx)(Row, {
196
+ children: /*#__PURE__*/(0, _jsxRuntime.jsxs)(_StackView.default, {
197
+ direction: "row",
198
+ space: 3,
199
+ tokens: {
200
+ alignItems: 'center'
201
+ },
202
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_Button.Button, {
203
+ onPress: () => onApply(checkedIds),
204
+ variant: {
205
+ size: 'small',
206
+ priority: 'high'
207
+ },
208
+ children: getCopy('applyButtonLabel')
209
+ }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_Box.default, {
210
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_Link.TextButton, {
211
+ onPress: () => setCheckedIds([]),
212
+ children: getCopy('clearButtonLabel')
213
+ })
214
+ })]
215
+ })
216
+ })]
217
+ })]
218
+ });
219
+ });
220
+ MultiSelectFilter.displayName = 'MultiSelectFilter';
221
+ MultiSelectFilter.propTypes = {
222
+ /**
223
+ * The text displayed to the user in a ButtonDropdown.
224
+ */
225
+ label: _propTypes.default.string.isRequired,
226
+
227
+ /**
228
+ * The text for the subtitle
229
+ */
230
+ subtitle: _propTypes.default.string,
231
+
232
+ /**
233
+ * An optional unique string may be provided to identify the ButtonDropdown.
234
+ * If not provided, the label is used.
235
+ */
236
+ id: _propTypes.default.string,
237
+
238
+ /**
239
+ * Sets the variant for ButtonDropdown element.
240
+ */
241
+ variant: _utils.variantProp.propType,
242
+
243
+ /**
244
+ * Sets the tokens for ButtonDropdown element.
245
+ */
246
+ tokens: (0, _utils.getTokensPropType)('ButtonDropdown'),
247
+
248
+ /**
249
+ * The options a user may select.
250
+ */
251
+ items: _propTypes.default.arrayOf(_propTypes.default.shape({
252
+ /**
253
+ * The text displayed to the user with a checkbox, describing this option.
254
+ */
255
+ label: _propTypes.default.string.isRequired,
256
+
257
+ /**
258
+ * An optional unique string may be provided to identify this option.
259
+ * If not provided, the label is used.
260
+ */
261
+ id: _propTypes.default.string
262
+ })),
263
+
264
+ /**
265
+ * If the selected item(s) in the checkbox group(s) are to be controlled externally by
266
+ * a parent component, pass an array of strings as well as an `onChange` handler.
267
+ * Passing an array for "values" makes the MultiSelectFilter a "controlled" component that
268
+ * expects its state to be handled via `onChange` and so doesn't handle it itself.
269
+ */
270
+ values: _propTypes.default.arrayOf(_propTypes.default.string),
271
+
272
+ /**
273
+ * If `values` is not passed, making the MultiSelectFilter an "uncontrolled" component
274
+ * managing its own selected state, a default set of selections may be provided.
275
+ * Changing the `initialValues` does not change the user's selections.
276
+ */
277
+ initialValues: _propTypes.default.arrayOf(_propTypes.default.string),
278
+
279
+ /**
280
+ * If provided, sets a maximum number of items a user may select at once.
281
+ */
282
+ maxValues: _propTypes.default.number,
283
+
284
+ /**
285
+ * If provided, this function is called when the current selection is changed
286
+ * and is passed an array of the `id`s of all currently selected `items`.
287
+ */
288
+ onChange: _propTypes.default.func,
289
+
290
+ /**
291
+ * Select English or French copy for the accessible label.
292
+ */
293
+ copy: _propTypes.default.oneOf(['en', 'fr']),
294
+
295
+ /**
296
+ * If true, the ButtonDropdown cannot be selected by the user and simply show their current state.
297
+ */
298
+ readOnly: _propTypes.default.string,
299
+
300
+ /**
301
+ * If true, the MultiSelectFilter cannot be interacted with, ButtonDropdown is
302
+ * set as `disabled` and if the theme supports `inactive` appearances rules, these
303
+ * are applied.
304
+ */
305
+ inactive: _propTypes.default.string,
306
+
307
+ /**
308
+ * Sets the maximum number of items in one column. If number of items are more
309
+ * than the `rowLimit`, they will be rendered in 2 columns.
310
+ */
311
+ rowLimit: _propTypes.default.number
312
+ };
313
+ var _default = MultiSelectFilter;
314
+ exports.default = _default;
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ var _default = {
8
+ en: {
9
+ filterByLabel: 'Filter by %{filterCategory}:',
10
+ applyButtonLabel: 'Apply',
11
+ clearButtonLabel: 'Clear'
12
+ },
13
+ fr: {
14
+ filterByLabel: 'Filtrer par %{filterCategory}:',
15
+ applyButtonLabel: 'Appliquer',
16
+ clearButtonLabel: 'Effacer'
17
+ }
18
+ };
19
+ exports.default = _default;