@telus-uds/components-web 1.8.0 → 1.10.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 (188) hide show
  1. package/CHANGELOG.md +41 -2
  2. package/lib/Autocomplete/Autocomplete.js +393 -0
  3. package/lib/Autocomplete/Loading.js +51 -0
  4. package/lib/Autocomplete/Suggestions.js +81 -0
  5. package/lib/Autocomplete/constants.js +19 -0
  6. package/lib/Autocomplete/dictionary.js +19 -0
  7. package/lib/Autocomplete/index.js +13 -0
  8. package/lib/Breadcrumbs/Breadcrumbs.js +8 -3
  9. package/lib/Callout/Callout.js +3 -0
  10. package/lib/Card/Card.js +180 -0
  11. package/lib/Card/CardContent.js +110 -0
  12. package/lib/Card/CardFooter.js +98 -0
  13. package/lib/Card/index.js +13 -0
  14. package/lib/Countdown/Countdown.js +189 -0
  15. package/lib/Countdown/Segment.js +111 -0
  16. package/lib/Countdown/constants.js +14 -0
  17. package/lib/Countdown/dictionary.js +29 -0
  18. package/lib/Countdown/index.js +13 -0
  19. package/lib/Countdown/types.js +39 -0
  20. package/lib/Countdown/useCountdown.js +40 -0
  21. package/lib/Footnote/Footnote.js +67 -24
  22. package/lib/Modal/ModalContent.js +11 -4
  23. package/lib/OptimizeImage/OptimizeImage.js +127 -0
  24. package/lib/OptimizeImage/index.js +13 -0
  25. package/lib/OptimizeImage/utils/getFallbackUrl.js +18 -0
  26. package/lib/OptimizeImage/utils/getOptimizedUrl.js +32 -0
  27. package/lib/OptimizeImage/utils/hasWebpSupport.js +38 -0
  28. package/lib/OptimizeImage/utils/index.js +31 -0
  29. package/lib/OptimizeImage/utils/isSvgUrl.js +10 -0
  30. package/lib/QuantitySelector/QuantitySelector.js +253 -0
  31. package/lib/QuantitySelector/dictionary.js +33 -0
  32. package/lib/QuantitySelector/index.js +13 -0
  33. package/lib/QuantitySelector/styles.js +40 -0
  34. package/lib/StoryCard/StoryCard.js +244 -0
  35. package/lib/StoryCard/index.js +13 -0
  36. package/lib/TermsAndConditions/ExpandCollapse.js +141 -0
  37. package/lib/TermsAndConditions/TermsAndConditions.js +221 -0
  38. package/lib/TermsAndConditions/dictionary.js +19 -0
  39. package/lib/TermsAndConditions/index.js +15 -0
  40. package/lib/Testimonial/Testimonial.js +226 -0
  41. package/lib/Testimonial/index.js +13 -0
  42. package/lib/Toast/Toast.js +15 -8
  43. package/lib/Video/ControlBar/ControlBar.js +315 -0
  44. package/lib/Video/ControlBar/Controls/VideoButton/VideoButton.js +91 -0
  45. package/lib/Video/ControlBar/Controls/VideoMenu/VideoMenu.js +186 -0
  46. package/lib/Video/ControlBar/Controls/VideoProgressBar/VideoProgressBar.js +221 -0
  47. package/lib/Video/ControlBar/Controls/VolumeSlider/VolumeSlider.js +213 -0
  48. package/lib/Video/MiddleControlButton/MiddleControlButton.js +89 -0
  49. package/lib/Video/Video.js +1072 -0
  50. package/lib/Video/index.js +13 -0
  51. package/lib/Video/videoText.js +62 -0
  52. package/lib/WebVideo/WebVideo.js +170 -0
  53. package/lib/WebVideo/index.js +13 -0
  54. package/lib/baseExports.js +0 -6
  55. package/lib/index.js +91 -1
  56. package/lib/shared/VideoSplash/SplashButton/SplashButton.js +102 -0
  57. package/lib/shared/VideoSplash/SplashButtonWithDetails/SplashButtonWithDetails.js +234 -0
  58. package/lib/shared/VideoSplash/VideoSplash.js +86 -0
  59. package/lib/shared/VideoSplash/helpers.js +38 -0
  60. package/lib/utils/index.js +8 -0
  61. package/lib-module/Autocomplete/Autocomplete.js +369 -0
  62. package/lib-module/Autocomplete/Loading.js +38 -0
  63. package/lib-module/Autocomplete/Suggestions.js +64 -0
  64. package/lib-module/Autocomplete/constants.js +5 -0
  65. package/lib-module/Autocomplete/dictionary.js +12 -0
  66. package/lib-module/Autocomplete/index.js +2 -0
  67. package/lib-module/Breadcrumbs/Breadcrumbs.js +8 -3
  68. package/lib-module/Callout/Callout.js +3 -0
  69. package/lib-module/Card/Card.js +158 -0
  70. package/lib-module/Card/CardContent.js +92 -0
  71. package/lib-module/Card/CardFooter.js +80 -0
  72. package/lib-module/Card/index.js +2 -0
  73. package/lib-module/Countdown/Countdown.js +165 -0
  74. package/lib-module/Countdown/Segment.js +94 -0
  75. package/lib-module/Countdown/constants.js +4 -0
  76. package/lib-module/Countdown/dictionary.js +22 -0
  77. package/lib-module/Countdown/index.js +2 -0
  78. package/lib-module/Countdown/types.js +23 -0
  79. package/lib-module/Countdown/useCountdown.js +32 -0
  80. package/lib-module/Footnote/Footnote.js +65 -24
  81. package/lib-module/Modal/ModalContent.js +10 -4
  82. package/lib-module/OptimizeImage/OptimizeImage.js +106 -0
  83. package/lib-module/OptimizeImage/index.js +2 -0
  84. package/lib-module/OptimizeImage/utils/getFallbackUrl.js +8 -0
  85. package/lib-module/OptimizeImage/utils/getOptimizedUrl.js +22 -0
  86. package/lib-module/OptimizeImage/utils/hasWebpSupport.js +32 -0
  87. package/lib-module/OptimizeImage/utils/index.js +4 -0
  88. package/lib-module/OptimizeImage/utils/isSvgUrl.js +3 -0
  89. package/lib-module/QuantitySelector/QuantitySelector.js +232 -0
  90. package/lib-module/QuantitySelector/dictionary.js +26 -0
  91. package/lib-module/QuantitySelector/index.js +2 -0
  92. package/lib-module/QuantitySelector/styles.js +21 -0
  93. package/lib-module/StoryCard/StoryCard.js +220 -0
  94. package/lib-module/StoryCard/index.js +2 -0
  95. package/lib-module/TermsAndConditions/ExpandCollapse.js +120 -0
  96. package/lib-module/TermsAndConditions/TermsAndConditions.js +193 -0
  97. package/lib-module/TermsAndConditions/dictionary.js +12 -0
  98. package/lib-module/TermsAndConditions/index.js +1 -0
  99. package/lib-module/Testimonial/Testimonial.js +204 -0
  100. package/lib-module/Testimonial/index.js +2 -0
  101. package/lib-module/Toast/Toast.js +15 -8
  102. package/lib-module/Video/ControlBar/ControlBar.js +292 -0
  103. package/lib-module/Video/ControlBar/Controls/VideoButton/VideoButton.js +74 -0
  104. package/lib-module/Video/ControlBar/Controls/VideoMenu/VideoMenu.js +167 -0
  105. package/lib-module/Video/ControlBar/Controls/VideoProgressBar/VideoProgressBar.js +201 -0
  106. package/lib-module/Video/ControlBar/Controls/VolumeSlider/VolumeSlider.js +193 -0
  107. package/lib-module/Video/MiddleControlButton/MiddleControlButton.js +72 -0
  108. package/lib-module/Video/Video.js +1042 -0
  109. package/lib-module/Video/index.js +2 -0
  110. package/lib-module/Video/videoText.js +55 -0
  111. package/lib-module/WebVideo/WebVideo.js +144 -0
  112. package/lib-module/WebVideo/index.js +2 -0
  113. package/lib-module/baseExports.js +1 -1
  114. package/lib-module/index.js +10 -0
  115. package/lib-module/shared/VideoSplash/SplashButton/SplashButton.js +85 -0
  116. package/lib-module/shared/VideoSplash/SplashButtonWithDetails/SplashButtonWithDetails.js +216 -0
  117. package/lib-module/shared/VideoSplash/VideoSplash.js +65 -0
  118. package/lib-module/shared/VideoSplash/helpers.js +23 -0
  119. package/lib-module/utils/index.js +2 -1
  120. package/package.json +7 -5
  121. package/src/Autocomplete/Autocomplete.jsx +354 -0
  122. package/src/Autocomplete/Loading.jsx +18 -0
  123. package/src/Autocomplete/Suggestions.jsx +52 -0
  124. package/src/Autocomplete/constants.js +6 -0
  125. package/src/Autocomplete/dictionary.js +12 -0
  126. package/src/Autocomplete/index.js +3 -0
  127. package/src/Breadcrumbs/Breadcrumbs.jsx +4 -3
  128. package/src/Callout/Callout.jsx +1 -1
  129. package/src/Card/Card.jsx +170 -0
  130. package/src/Card/CardContent.jsx +88 -0
  131. package/src/Card/CardFooter.jsx +70 -0
  132. package/src/Card/index.js +3 -0
  133. package/src/Countdown/Countdown.jsx +144 -0
  134. package/src/Countdown/Segment.jsx +69 -0
  135. package/src/Countdown/constants.js +4 -0
  136. package/src/Countdown/dictionary.js +22 -0
  137. package/src/Countdown/index.js +3 -0
  138. package/src/Countdown/types.js +23 -0
  139. package/src/Countdown/useCountdown.js +34 -0
  140. package/src/Footnote/Footnote.jsx +73 -23
  141. package/src/Modal/ModalContent.jsx +8 -4
  142. package/src/OptimizeImage/OptimizeImage.jsx +131 -0
  143. package/src/OptimizeImage/index.js +3 -0
  144. package/src/OptimizeImage/utils/getFallbackUrl.js +9 -0
  145. package/src/OptimizeImage/utils/getOptimizedUrl.js +30 -0
  146. package/src/OptimizeImage/utils/hasWebpSupport.js +33 -0
  147. package/src/OptimizeImage/utils/index.js +5 -0
  148. package/src/OptimizeImage/utils/isSvgUrl.js +3 -0
  149. package/src/QuantitySelector/QuantitySelector.jsx +245 -0
  150. package/src/QuantitySelector/dictionary.js +27 -0
  151. package/src/QuantitySelector/index.js +3 -0
  152. package/src/QuantitySelector/styles.js +83 -0
  153. package/src/StoryCard/StoryCard.jsx +198 -0
  154. package/src/StoryCard/index.js +3 -0
  155. package/src/TermsAndConditions/ExpandCollapse.jsx +106 -0
  156. package/src/TermsAndConditions/TermsAndConditions.jsx +161 -0
  157. package/src/TermsAndConditions/dictionary.js +12 -0
  158. package/src/TermsAndConditions/index.js +1 -0
  159. package/src/Testimonial/Testimonial.jsx +169 -0
  160. package/src/Testimonial/index.js +3 -0
  161. package/src/Toast/Toast.jsx +12 -5
  162. package/src/Video/ControlBar/ControlBar.jsx +261 -0
  163. package/src/Video/ControlBar/Controls/VideoButton/VideoButton.jsx +61 -0
  164. package/src/Video/ControlBar/Controls/VideoMenu/VideoMenu.jsx +159 -0
  165. package/src/Video/ControlBar/Controls/VideoProgressBar/VideoProgressBar.jsx +185 -0
  166. package/src/Video/ControlBar/Controls/VolumeSlider/VolumeSlider.jsx +184 -0
  167. package/src/Video/MiddleControlButton/MiddleControlButton.jsx +64 -0
  168. package/src/Video/Video.jsx +988 -0
  169. package/src/Video/index.js +3 -0
  170. package/src/Video/videoText.js +58 -0
  171. package/src/WebVideo/WebVideo.jsx +131 -0
  172. package/src/WebVideo/index.js +3 -0
  173. package/src/baseExports.js +0 -1
  174. package/src/index.js +10 -0
  175. package/src/shared/VideoSplash/SplashButton/SplashButton.jsx +64 -0
  176. package/src/shared/VideoSplash/SplashButtonWithDetails/SplashButtonWithDetails.jsx +128 -0
  177. package/src/shared/VideoSplash/VideoSplash.jsx +50 -0
  178. package/src/shared/VideoSplash/helpers.js +27 -0
  179. package/src/utils/index.js +10 -1
  180. package/types/Autocomplete.d.ts +32 -0
  181. package/types/Card.d.ts +45 -0
  182. package/types/ControlBar.d.ts +59 -0
  183. package/types/MiddleControlButton.d.ts +15 -0
  184. package/types/Video.d.ts +39 -0
  185. package/types/VideoButton.d.ts +14 -0
  186. package/types/VideoMenu.d.ts +16 -0
  187. package/types/VideoProgressBar.d.ts +17 -0
  188. package/types/VolumeSlider.d.ts +20 -0
@@ -27,9 +27,15 @@ const StyledSubHeading = /*#__PURE__*/styled.div.withConfig({
27
27
  } = _ref2;
28
28
  return marginTop;
29
29
  });
30
+ const StyledTextButtonContainer = /*#__PURE__*/styled.div.withConfig({
31
+ displayName: "ModalContent__StyledTextButtonContainer",
32
+ componentId: "components-web__sc-k40cwb-3"
33
+ })({
34
+ display: 'flex'
35
+ });
30
36
  const StyledFooter = /*#__PURE__*/styled.footer.withConfig({
31
37
  displayName: "ModalContent__StyledFooter",
32
- componentId: "components-web__sc-k40cwb-3"
38
+ componentId: "components-web__sc-k40cwb-4"
33
39
  })(_ref3 => {
34
40
  let {
35
41
  hasBorder,
@@ -143,15 +149,15 @@ const ModalContent = _ref4 => {
143
149
  },
144
150
  onPress: onConfirm,
145
151
  children: confirmButtonText
146
- }), /*#__PURE__*/_jsx("div", {
147
- children: hasCancelButton && /*#__PURE__*/_jsx(CancelButton, {
152
+ }), hasCancelButton ? /*#__PURE__*/_jsx(StyledTextButtonContainer, {
153
+ children: /*#__PURE__*/_jsx(CancelButton, {
148
154
  tokens: {
149
155
  color: cancelButtonColor
150
156
  },
151
157
  onPress: onCancel,
152
158
  children: cancelButtonText
153
159
  })
154
- })]
160
+ }) : null]
155
161
  })]
156
162
  });
157
163
  };
@@ -0,0 +1,106 @@
1
+ import React, { useEffect, useState } from 'react';
2
+ import PropTypes from 'prop-types';
3
+ import { selectSystemProps } from '@telus-uds/components-base';
4
+ import ResponsiveImage from '../ResponsiveImage';
5
+ import { hasWebpSupport, getOptimizedUrl, getFallbackUrl } from './utils';
6
+ import { htmlAttrs } from '../utils';
7
+ import { jsx as _jsx } from "react/jsx-runtime";
8
+ const [selectProps, selectedSystemPropTypes] = selectSystemProps([htmlAttrs]);
9
+
10
+ const OptimizeImage = _ref => {
11
+ let {
12
+ contentfulAssetUrl,
13
+ alt,
14
+ quality = 80,
15
+ xs = 320,
16
+ sm = 576,
17
+ md = 768,
18
+ lg = 992,
19
+ xl = 1200,
20
+ sizeByHeight = false,
21
+ disableRetina = false,
22
+ ...rest
23
+ } = _ref;
24
+ const [imgUrls, setImgUrls] = useState(); // `useHeight` is a deprecated TDS prop, replaced by `sizeByHeight`
25
+
26
+ const dimension = sizeByHeight || rest.useHeight ? 'h' : 'w';
27
+ useEffect(() => {
28
+ // Currently not all browsers support webP
29
+ hasWebpSupport().then(supportsWebp => {
30
+ setImgUrls({
31
+ xsSrc: getOptimizedUrl(contentfulAssetUrl, dimension, xs, quality, disableRetina, supportsWebp),
32
+ smSrc: getOptimizedUrl(contentfulAssetUrl, dimension, sm, quality, disableRetina, supportsWebp),
33
+ mdSrc: getOptimizedUrl(contentfulAssetUrl, dimension, md, quality, disableRetina, supportsWebp),
34
+ lgSrc: getOptimizedUrl(contentfulAssetUrl, dimension, lg, quality, disableRetina, supportsWebp),
35
+ xlSrc: getOptimizedUrl(contentfulAssetUrl, dimension, xl, quality, disableRetina, supportsWebp),
36
+ fallbackSrc: getFallbackUrl(contentfulAssetUrl, xl, quality)
37
+ });
38
+ });
39
+ }, [contentfulAssetUrl, dimension, disableRetina, lg, md, quality, sm, xl, xs]);
40
+ if (!imgUrls) return null;
41
+ return /*#__PURE__*/_jsx(ResponsiveImage, { ...imgUrls,
42
+ alt: alt,
43
+ ...selectProps(rest)
44
+ });
45
+ };
46
+
47
+ OptimizeImage.propTypes = { ...selectedSystemPropTypes,
48
+
49
+ /**
50
+ * The source to load the image. Only contentful image urls are supported. See https://www.contentful.com/developers/docs/references/images-api/ for details.
51
+ */
52
+ contentfulAssetUrl: PropTypes.string.isRequired,
53
+
54
+ /**
55
+ * Alternative text to display if image cannot be loaded or a screen reader is used.
56
+ */
57
+ alt: PropTypes.string.isRequired,
58
+
59
+ /**
60
+ * Customize quality as a percentage between 1 and 100.
61
+ */
62
+ quality: PropTypes.number,
63
+
64
+ /**
65
+ * Customize width for xs screen size in px, this may affect the quality of the image.
66
+ */
67
+ xs: PropTypes.number,
68
+
69
+ /**
70
+ * Customize width for sm screen size in px, this may affect the quality of the image.
71
+ */
72
+ sm: PropTypes.number,
73
+
74
+ /**
75
+ * Customize width for md screen size in px, this may affect the quality of the image.
76
+ */
77
+ md: PropTypes.number,
78
+
79
+ /**
80
+ * Customize width for lg screen size in px, this may affect the quality of the image.
81
+ */
82
+ lg: PropTypes.number,
83
+
84
+ /**
85
+ * Customize width for xl screen size in px, this may affect the quality of the image.
86
+ */
87
+ xl: PropTypes.number,
88
+
89
+ /**
90
+ * Switches size dimension to height, default is false
91
+ */
92
+ sizeByHeight: PropTypes.bool,
93
+
94
+ /**
95
+ * Turns off retina display functionality
96
+ */
97
+ disableRetina: PropTypes.bool,
98
+
99
+ /**
100
+ * Loading strategy.
101
+ * @default 'eager'
102
+ * @see https://developer.mozilla.org/en-US/docs/Web/HTML/Element/img#attr-loading
103
+ */
104
+ loading: PropTypes.oneOf(['eager', 'lazy'])
105
+ };
106
+ export default OptimizeImage;
@@ -0,0 +1,2 @@
1
+ import OptimizeImage from './OptimizeImage';
2
+ export default OptimizeImage;
@@ -0,0 +1,8 @@
1
+ import isSvgUrl from './isSvgUrl';
2
+ export default function getFallbackUrl(url, width, quality) {
3
+ if (!isSvgUrl(url)) {
4
+ return `${url}?w=${width}&q=${quality}`;
5
+ }
6
+
7
+ return url;
8
+ }
@@ -0,0 +1,22 @@
1
+ import isSvgUrl from './isSvgUrl';
2
+ export default function getOptimizedUrl(url, dimension, size, quality, disableRetina, supportsWebp) {
3
+ if (!isSvgUrl(url)) {
4
+ let format = '';
5
+
6
+ if (supportsWebp) {
7
+ format = 'fm=webp';
8
+ } else if (url.match(/\.jpe?g$/i)) {
9
+ format = 'fm=jpg&fl=progressive';
10
+ }
11
+
12
+ let optimizedUrl = `${url}?${dimension}=${size}&q=${quality}&${format}`;
13
+
14
+ if (!disableRetina) {
15
+ optimizedUrl += `, ${url}?${dimension}=${size * 2}&q=${quality}&${format} 2x`;
16
+ }
17
+
18
+ return optimizedUrl;
19
+ }
20
+
21
+ return url;
22
+ }
@@ -0,0 +1,32 @@
1
+ let promise;
2
+ /**
3
+ * Taken directly from Google developers guide on how to detect browser support for WebP.
4
+ *
5
+ * @see https://developers.google.com/speed/webp/faq#in_your_own_javascript
6
+ * @return {Promise<boolean>}
7
+ */
8
+
9
+ export default function hasWebpSupport() {
10
+ // cache the result, so that this function runs only once
11
+ if (!promise) {
12
+ promise = new Promise(resolve => {
13
+ // basic support. other test forms exist for lossless, alpha, and animation types.
14
+ // check google guide if data strings are needed
15
+ const lossy = 'UklGRiIAAABXRUJQVlA4IBYAAAAwAQCdASoBAAEADsD+JaQAA3AAAAAA';
16
+ const img = document.createElement('img');
17
+
18
+ img.onload = function onLoad() {
19
+ const result = img.width > 0 && img.height > 0;
20
+ resolve(result);
21
+ };
22
+
23
+ img.onerror = function onError() {
24
+ resolve(false);
25
+ };
26
+
27
+ img.src = `data:image/webp;base64,${lossy}`;
28
+ });
29
+ }
30
+
31
+ return promise;
32
+ }
@@ -0,0 +1,4 @@
1
+ import getOptimizedUrl from './getOptimizedUrl';
2
+ import getFallbackUrl from './getFallbackUrl';
3
+ import hasWebpSupport from './hasWebpSupport';
4
+ export { getOptimizedUrl, getFallbackUrl, hasWebpSupport };
@@ -0,0 +1,3 @@
1
+ export default function isSvgUrl(url) {
2
+ return !!url.match(/\.svg$/i);
3
+ }
@@ -0,0 +1,232 @@
1
+ import React, { useState } from 'react';
2
+ import PropTypes from 'prop-types';
3
+ import { getThemeTokens, Box, TextInput, Spacer, Feedback, InputLabel, useInputValue, useCopy, useThemeTokens, useTheme } from '@telus-uds/components-base';
4
+ import IconButton from '../IconButton';
5
+ import { InputField, InputWrapper, LeftButtonWrapper, RightButtonWrapper } from './styles';
6
+ import defaultDictionary from './dictionary';
7
+ import { jsx as _jsx } from "react/jsx-runtime";
8
+ import { jsxs as _jsxs } from "react/jsx-runtime";
9
+ const {
10
+ isNaN
11
+ } = Number;
12
+
13
+ const isNumber = value => {
14
+ return typeof value === 'number' && !isNaN(value);
15
+ };
16
+
17
+ const QuantitySelector = _ref => {
18
+ let {
19
+ id,
20
+ minNumber,
21
+ maxNumber,
22
+ defaultValue,
23
+ label,
24
+ hint,
25
+ hintPosition,
26
+ tooltip,
27
+ onChange,
28
+ dictionary = defaultDictionary,
29
+ accessibilityLabel,
30
+ copy,
31
+ variant,
32
+ tokens,
33
+ testID
34
+ } = _ref;
35
+ const {
36
+ components: {
37
+ QuantitySelector: componentTheme
38
+ }
39
+ } = useTheme();
40
+ const {
41
+ leftIcon,
42
+ rightIcon,
43
+ padding
44
+ } = useThemeTokens('QuantitySelector', tokens, variant);
45
+ const [error, setError] = useState('');
46
+ const {
47
+ alternative
48
+ } = variant;
49
+ const getCopy = useCopy({
50
+ dictionary,
51
+ copy
52
+ });
53
+
54
+ const getValidatedNumber = numberToEvaluate => {
55
+ if (isNaN(numberToEvaluate)) return null;
56
+ if (isNumber(minNumber) && numberToEvaluate < minNumber) throw getCopy('errors').numberIsTooSmall(minNumber);
57
+ if (isNumber(maxNumber) && numberToEvaluate > maxNumber) throw getCopy('errors').numberIsTooBig(maxNumber);
58
+ return numberToEvaluate;
59
+ };
60
+
61
+ const initialValue = getValidatedNumber(defaultValue);
62
+ const {
63
+ currentValue: number,
64
+ setValue: setNumber
65
+ } = useInputValue({
66
+ value: undefined,
67
+ initialValue,
68
+ onChange
69
+ });
70
+ const isDecreaseEnabled = !isNumber(minNumber) || number > minNumber;
71
+ const isIncreaseEnabled = !isNumber(maxNumber) || number < maxNumber;
72
+ const inputValue = isNumber(number) ? number.toString() : '';
73
+
74
+ const updateNumber = (newNumber, originalInputEvent) => {
75
+ try {
76
+ const validatedNumber = getValidatedNumber(newNumber);
77
+ setNumber(validatedNumber, originalInputEvent);
78
+ setError('');
79
+ } catch (e) {
80
+ setError(e);
81
+ }
82
+ };
83
+
84
+ const inputChangeHandler = (textInputValue, event) => {
85
+ if (textInputValue === '') setNumber(null);
86
+ const numberFromTextInput = Number(textInputValue);
87
+
88
+ if (isNumber(numberFromTextInput)) {
89
+ updateNumber(numberFromTextInput, event);
90
+ } else {
91
+ setError(getCopy('errors').invalidCharacters);
92
+ }
93
+ };
94
+
95
+ const renderLabel = () => label ? /*#__PURE__*/_jsx(InputLabel, {
96
+ forId: id,
97
+ label: label,
98
+ hint: hint,
99
+ hintPosition: hintPosition,
100
+ tooltip: tooltip
101
+ }) : null;
102
+
103
+ const renderTextInput = () => /*#__PURE__*/_jsx(TextInput, {
104
+ nativeID: id,
105
+ value: inputValue,
106
+ tokens: textInputState => {
107
+ const {
108
+ inputBorderColor,
109
+ inputBackgroundColor
110
+ } = getThemeTokens(componentTheme, tokens, variant, textInputState);
111
+ return {
112
+ borderRadius: 0,
113
+ margin: 0,
114
+ padding: 0,
115
+ borderColor: inputBorderColor,
116
+ backgroundColor: inputBackgroundColor
117
+ };
118
+ },
119
+ onChange: inputChangeHandler // Using title as an accessibility workaround
120
+ // given that accessibilityLabel is not available
121
+ ,
122
+ keyboardType: "numeric",
123
+ accessibilityLabel: accessibilityLabel ?? getCopy('accessibility').a11yLabel,
124
+ accessibilityRole: "spinbutton",
125
+ accessibilityValueMax: maxNumber,
126
+ accessibilityValueMin: minNumber,
127
+ accessibilityValueNow: number
128
+ });
129
+
130
+ const getButtonTokens = isEnabled => buttonState => {
131
+ const disabled = !isEnabled;
132
+ const { ...buttonTokens
133
+ } = getThemeTokens(componentTheme, tokens, variant, { ...buttonState,
134
+ disabled
135
+ });
136
+ return { ...buttonTokens,
137
+ outerBorderGap: 0,
138
+ padding
139
+ };
140
+ };
141
+
142
+ const renderLeftButton = () => {
143
+ return /*#__PURE__*/_jsx(IconButton, {
144
+ icon: leftIcon,
145
+ tokens: getButtonTokens(isDecreaseEnabled),
146
+ onPress: event => updateNumber(number - 1, event),
147
+ onDoubleClick: event => updateNumber(number - 1, event),
148
+ accessibilityLabel: getCopy('accessibility').decreaseButton,
149
+ accessibilityDisabled: !isDecreaseEnabled
150
+ });
151
+ };
152
+
153
+ const renderRightButton = () => /*#__PURE__*/_jsx(IconButton, {
154
+ icon: rightIcon,
155
+ tokens: getButtonTokens(isIncreaseEnabled),
156
+ onPress: () => updateNumber(number + 1),
157
+ onDoubleClick: () => updateNumber(number + 1),
158
+ accessibilityLabel: getCopy('accessibility').increaseButton,
159
+ accessibilityDisabled: !isIncreaseEnabled
160
+ });
161
+
162
+ return /*#__PURE__*/_jsxs(Box, {
163
+ space: 2,
164
+ testID: testID,
165
+ children: [renderLabel(), /*#__PURE__*/_jsx(Spacer, {
166
+ space: 2
167
+ }), /*#__PURE__*/_jsxs(InputWrapper, {
168
+ children: [/*#__PURE__*/_jsx(InputField, {
169
+ className: `${alternative ? 'alternative' : ''}`,
170
+ children: renderTextInput()
171
+ }), /*#__PURE__*/_jsx(RightButtonWrapper, {
172
+ className: `${alternative ? 'alternative' : ''}`,
173
+ children: renderRightButton()
174
+ }), /*#__PURE__*/_jsx(LeftButtonWrapper, {
175
+ className: `${alternative ? 'alternative' : ''}`,
176
+ children: renderLeftButton()
177
+ })]
178
+ }), error ? /*#__PURE__*/_jsx(Box, {
179
+ vertical: 2,
180
+ children: /*#__PURE__*/_jsx(Feedback, {
181
+ validation: "error",
182
+ children: error
183
+ })
184
+ }) : null]
185
+ });
186
+ }; // If a language dictionary entry is provided, it must contain every key
187
+
188
+
189
+ const dictionaryContentShape = PropTypes.shape({
190
+ accessibility: PropTypes.shape({
191
+ a11yLabel: PropTypes.string.isRequired,
192
+ increaseButton: PropTypes.string.isRequired,
193
+ decreaseButton: PropTypes.string.isRequired
194
+ }).isRequired,
195
+ errors: PropTypes.shape({
196
+ numberIsTooSmall: PropTypes.func.isRequired,
197
+ numberIsTooBig: PropTypes.func.isRequired,
198
+ invalidCharacters: PropTypes.string.isRequired
199
+ }).isRequired
200
+ });
201
+ QuantitySelector.propTypes = {
202
+ id: PropTypes.string,
203
+ minNumber: PropTypes.number,
204
+ maxNumber: PropTypes.number,
205
+ onChange: PropTypes.func,
206
+ defaultValue: PropTypes.number,
207
+ label: PropTypes.string,
208
+ hint: PropTypes.string,
209
+ hintPosition: PropTypes.oneOf(['inline', 'below']),
210
+ tooltip: PropTypes.string,
211
+ accessibilityLabel: PropTypes.string,
212
+ dictionary: PropTypes.shape({
213
+ en: dictionaryContentShape,
214
+ fr: dictionaryContentShape
215
+ }),
216
+ copy: PropTypes.oneOfType([PropTypes.oneOf(['en', 'fr'])]),
217
+ variant: PropTypes.exact({
218
+ alternative: PropTypes.bool
219
+ }),
220
+ tokens: PropTypes.oneOf([PropTypes.object, PropTypes.func]),
221
+ testID: PropTypes.string
222
+ };
223
+ QuantitySelector.defaultProps = {
224
+ id: 'quantity-selector',
225
+ hintPosition: 'inline',
226
+ copy: 'en',
227
+ variant: {
228
+ alternative: false
229
+ },
230
+ testID: 'quantity-selector-testid'
231
+ };
232
+ export default QuantitySelector;
@@ -0,0 +1,26 @@
1
+ export default {
2
+ en: {
3
+ accessibility: {
4
+ a11yLabel: 'Quantity Selector control',
5
+ increaseButton: 'Increase quantity button',
6
+ decreaseButton: 'Decrease quantity button'
7
+ },
8
+ errors: {
9
+ numberIsTooSmall: minNumber => `Number must be equal or greater than ${minNumber}`,
10
+ numberIsTooBig: maxNumber => `Number must be equal or less than ${maxNumber}`,
11
+ invalidCharacters: 'This control does not allow alphabetical or symbol characters. Try using numbers only'
12
+ }
13
+ },
14
+ fr: {
15
+ accessibility: {
16
+ a11yLabel: 'Contrôleur de sélection de nombre',
17
+ increaseButton: `Bouton d'augmentation de quantité`,
18
+ decreaseButton: `Bouton de diminution de quantité`
19
+ },
20
+ errors: {
21
+ numberIsTooSmall: minNumber => `Le nombre doit être plus grand ou égal que ${minNumber}`,
22
+ numberIsTooBig: maxNumber => `Le nombre doit être plus petit ou égal que ${maxNumber}`,
23
+ invalidCharacters: `Ce champ ne supporte pas les caractères alphabétiques ni les symboles. Essayez d'utiliser des chiffres uniquement`
24
+ }
25
+ }
26
+ };
@@ -0,0 +1,2 @@
1
+ import QuantitySelector from './QuantitySelector';
2
+ export default QuantitySelector;
@@ -0,0 +1,21 @@
1
+ import styled from 'styled-components';
2
+ export const InputField = /*#__PURE__*/styled.div.withConfig({
3
+ displayName: "styles__InputField",
4
+ componentId: "components-web__sc-1lrz1xk-0"
5
+ })(["order:2;min-width:3.5rem;max-width:5 rem;height:28px;padding:0;width:64px;text-align:center;z-index:10;input{text-align:center;}&.alternative{input{height:40px;}}"]);
6
+ const ButtonWrapper = /*#__PURE__*/styled.div.withConfig({
7
+ displayName: "styles__ButtonWrapper",
8
+ componentId: "components-web__sc-1lrz1xk-1"
9
+ })(["&.alternative{div[role='button']{height:42px;> div{height:40px;> div{padding:12px 16px;}}}}"]);
10
+ export const LeftButtonWrapper = /*#__PURE__*/styled(ButtonWrapper).withConfig({
11
+ displayName: "styles__LeftButtonWrapper",
12
+ componentId: "components-web__sc-1lrz1xk-2"
13
+ })(["order:0;div[role='button']{border-radius:4px 0px 0px 4px !important;> div{border-right:none;border-radius:4px 0px 0px 4px !important;}}&.alternative{div[role='button']{border-radius:36px 0px 0px 36px !important;> div{border-radius:24px 0px 0px 24px !important;}}}"]);
14
+ export const RightButtonWrapper = /*#__PURE__*/styled(ButtonWrapper).withConfig({
15
+ displayName: "styles__RightButtonWrapper",
16
+ componentId: "components-web__sc-1lrz1xk-3"
17
+ })(["order:3;div[role='button']{border-radius:0px 4px 4px 0px !important;> div{border-left:none;border-radius:0px 4px 4px 0px !important;}}&.alternative{div[role='button']{border-radius:0px 36px 36px 0px !important;> div{border-radius:0px 36px 36px 0px !important;}}}"]);
18
+ export const InputWrapper = /*#__PURE__*/styled.div.withConfig({
19
+ displayName: "styles__InputWrapper",
20
+ componentId: "components-web__sc-1lrz1xk-4"
21
+ })(["textalign:start;display:flex;flexdirection:row;flexwrap:nowrap;justifycontent:center;"]);