@telus-uds/components-base 1.8.4 → 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 (51) hide show
  1. package/CHANGELOG.md +38 -2
  2. package/component-docs.json +344 -0
  3. package/lib/Card/Card.js +9 -4
  4. package/lib/Carousel/Carousel.js +619 -0
  5. package/lib/Carousel/CarouselContext.js +59 -0
  6. package/lib/Carousel/CarouselItem/CarouselItem.js +77 -0
  7. package/lib/Carousel/CarouselItem/index.js +13 -0
  8. package/lib/Carousel/index.js +32 -0
  9. package/lib/Checkbox/Checkbox.js +4 -2
  10. package/lib/ExpandCollapse/Panel.js +10 -1
  11. package/lib/Link/InlinePressable.js +5 -1
  12. package/lib/Link/LinkBase.js +5 -2
  13. package/lib/StepTracker/StepTracker.js +5 -2
  14. package/lib/TextInput/TextInput.js +0 -11
  15. package/lib/TextInput/TextInputBase.js +9 -0
  16. package/lib/TextInput/propTypes.js +3 -8
  17. package/lib/index.js +14 -0
  18. package/lib/utils/props/textInputProps.js +8 -1
  19. package/lib-module/Card/Card.js +5 -4
  20. package/lib-module/Carousel/Carousel.js +570 -0
  21. package/lib-module/Carousel/CarouselContext.js +43 -0
  22. package/lib-module/Carousel/CarouselItem/CarouselItem.js +60 -0
  23. package/lib-module/Carousel/CarouselItem/index.js +2 -0
  24. package/lib-module/Carousel/index.js +2 -0
  25. package/lib-module/Checkbox/Checkbox.js +4 -2
  26. package/lib-module/ExpandCollapse/Panel.js +9 -1
  27. package/lib-module/Link/InlinePressable.js +5 -1
  28. package/lib-module/Link/LinkBase.js +5 -2
  29. package/lib-module/StepTracker/StepTracker.js +5 -2
  30. package/lib-module/TextInput/TextInput.js +0 -8
  31. package/lib-module/TextInput/TextInputBase.js +10 -1
  32. package/lib-module/TextInput/propTypes.js +4 -8
  33. package/lib-module/index.js +1 -0
  34. package/lib-module/utils/props/textInputProps.js +8 -1
  35. package/package.json +3 -3
  36. package/src/Card/Card.jsx +6 -4
  37. package/src/Carousel/Carousel.jsx +586 -0
  38. package/src/Carousel/CarouselContext.jsx +30 -0
  39. package/src/Carousel/CarouselItem/CarouselItem.jsx +48 -0
  40. package/src/Carousel/CarouselItem/index.js +3 -0
  41. package/src/Carousel/index.js +2 -0
  42. package/src/Checkbox/Checkbox.jsx +3 -1
  43. package/src/ExpandCollapse/Panel.jsx +8 -1
  44. package/src/Link/InlinePressable.jsx +5 -2
  45. package/src/Link/LinkBase.jsx +4 -1
  46. package/src/StepTracker/StepTracker.jsx +12 -5
  47. package/src/TextInput/TextInput.jsx +1 -8
  48. package/src/TextInput/TextInputBase.jsx +11 -1
  49. package/src/TextInput/propTypes.js +3 -7
  50. package/src/index.js +1 -0
  51. package/src/utils/props/textInputProps.js +7 -1
@@ -0,0 +1,77 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+
8
+ var _react = _interopRequireDefault(require("react"));
9
+
10
+ var _propTypes = _interopRequireDefault(require("prop-types"));
11
+
12
+ var _View = _interopRequireDefault(require("react-native-web/dist/cjs/exports/View"));
13
+
14
+ var _Platform = _interopRequireDefault(require("react-native-web/dist/cjs/exports/Platform"));
15
+
16
+ var _utils = require("../../utils");
17
+
18
+ var _CarouselContext = require("../CarouselContext");
19
+
20
+ var _jsxRuntime = require("react/jsx-runtime");
21
+
22
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
23
+
24
+ const [selectProps, selectedSystemPropTypes] = (0, _utils.selectSystemProps)([_utils.a11yProps, _utils.viewProps]);
25
+ /**
26
+ * `Carousel.Item` is used to wrap the content of an individual slide and is suppsoed to be the
27
+ * only top-level component passed to the `Carousel`
28
+ */
29
+
30
+ const CarouselItem = _ref => {
31
+ let {
32
+ children,
33
+ elementIndex,
34
+ ...rest
35
+ } = _ref;
36
+ const {
37
+ width,
38
+ activeIndex,
39
+ totalItems
40
+ } = (0, _CarouselContext.useCarousel)();
41
+ const selectedProps = selectProps({ ...rest,
42
+ // `group` role crashes the app on Android so setting it to `none` for Android
43
+ accessibilityRole: _Platform.default.OS === 'android' ? 'none' : 'group',
44
+ accessibilityLabel: "Showing ".concat(elementIndex + 1, " of ").concat(totalItems)
45
+ });
46
+ const focusabilityProps = activeIndex === elementIndex ? {} : _utils.a11yProps.nonFocusableProps;
47
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)(_View.default, {
48
+ style: {
49
+ width
50
+ },
51
+ ...selectedProps,
52
+ ...focusabilityProps,
53
+ children: children
54
+ });
55
+ };
56
+
57
+ CarouselItem.propTypes = { ...selectedSystemPropTypes,
58
+
59
+ /**
60
+ * Index of the current slide
61
+ * Don't pass this prop when using `Carousel.Item` as it is already being passed by `Carousel` top-level component
62
+ */
63
+ elementIndex: _propTypes.default.number,
64
+
65
+ /**
66
+ * Provide custom accessibilityLabelledBy for Carousel slide
67
+ */
68
+ accessibilityLabelledBy: _propTypes.default.string,
69
+
70
+ /**
71
+ * Content of the slide
72
+ */
73
+ children: _propTypes.default.oneOfType([_propTypes.default.arrayOf(_propTypes.default.node), _propTypes.default.node]).isRequired
74
+ };
75
+ CarouselItem.displayName = 'Carousel.Item';
76
+ var _default = CarouselItem;
77
+ exports.default = _default;
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+
8
+ var _CarouselItem = _interopRequireDefault(require("./CarouselItem"));
9
+
10
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
11
+
12
+ var _default = _CarouselItem.default;
13
+ exports.default = _default;
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ var _exportNames = {
7
+ Carousel: true
8
+ };
9
+ Object.defineProperty(exports, "Carousel", {
10
+ enumerable: true,
11
+ get: function () {
12
+ return _Carousel.default;
13
+ }
14
+ });
15
+
16
+ var _CarouselContext = require("./CarouselContext");
17
+
18
+ Object.keys(_CarouselContext).forEach(function (key) {
19
+ if (key === "default" || key === "__esModule") return;
20
+ if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
21
+ if (key in exports && exports[key] === _CarouselContext[key]) return;
22
+ Object.defineProperty(exports, key, {
23
+ enumerable: true,
24
+ get: function () {
25
+ return _CarouselContext[key];
26
+ }
27
+ });
28
+ });
29
+
30
+ var _Carousel = _interopRequireDefault(require("./Carousel"));
31
+
32
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
@@ -265,8 +265,10 @@ const Checkbox = /*#__PURE__*/(0, _react.forwardRef)((_ref5, ref) => {
265
265
  isControlled: isControlled,
266
266
  name: name,
267
267
  value: value
268
- }), isChecked && IconComponent && /*#__PURE__*/(0, _jsxRuntime.jsx)(IconComponent, { ...iconTokens,
269
- testID: "Checkbox-Icon"
268
+ }), isChecked && IconComponent && /*#__PURE__*/(0, _jsxRuntime.jsx)(_View.default, {
269
+ testID: "Checkbox-Icon",
270
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)(IconComponent, { ...iconTokens
271
+ })
270
272
  })]
271
273
  })
272
274
  }), Boolean(label) && /*#__PURE__*/(0, _jsxRuntime.jsx)(_Text.default, {
@@ -15,6 +15,8 @@ var _View = _interopRequireDefault(require("react-native-web/dist/cjs/exports/Vi
15
15
 
16
16
  var _propTypes = _interopRequireDefault(require("prop-types"));
17
17
 
18
+ var _airbnbPropTypes = _interopRequireDefault(require("airbnb-prop-types"));
19
+
18
20
  var _Control = _interopRequireDefault(require("./Control"));
19
21
 
20
22
  var _ThemeProvider = require("../ThemeProvider");
@@ -70,6 +72,7 @@ const ExpandCollapsePanel = /*#__PURE__*/(0, _react.forwardRef)((_ref2, ref) =>
70
72
  children,
71
73
  tokens,
72
74
  variant,
75
+ controlRef,
73
76
  ...rest
74
77
  } = _ref2;
75
78
  const [containerHeight, setContainerHeight] = (0, _react.useState)(null);
@@ -112,6 +115,7 @@ const ExpandCollapsePanel = /*#__PURE__*/(0, _react.forwardRef)((_ref2, ref) =>
112
115
  isExpanded: isExpanded,
113
116
  tokens: controlTokens,
114
117
  onPress: handleControlPress,
118
+ ref: controlRef,
115
119
  children: control
116
120
  }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_Animated.default.View, {
117
121
  ref: animatedRef,
@@ -167,7 +171,12 @@ ExpandCollapsePanel.propTypes = { ...selectedSystemPropTypes,
167
171
  /**
168
172
  * Optional theme token overrides that may be passed to the ExpandCollapseControl element.
169
173
  */
170
- controlTokens: (0, _utils.getTokensPropType)('ExpandCollapseControl')
174
+ controlTokens: (0, _utils.getTokensPropType)('ExpandCollapseControl'),
175
+
176
+ /**
177
+ * An optional ref to be attached to the control
178
+ */
179
+ controlRef: _airbnbPropTypes.default.ref()
171
180
  };
172
181
  var _default = ExpandCollapsePanel;
173
182
  exports.default = _default;
@@ -37,11 +37,12 @@ const InlinePressable = /*#__PURE__*/(0, _react.forwardRef)((_ref, ref) => {
37
37
  let {
38
38
  children,
39
39
  style,
40
+ inline = false,
40
41
  ...props
41
42
  } = _ref;
42
43
  return /*#__PURE__*/(0, _jsxRuntime.jsx)(_Pressable.default, {
43
44
  ref: ref,
44
- style: pressState => [staticStyles.inline, typeof style === 'function' ? style(pressState) : style],
45
+ style: pressState => [staticStyles[inline ? 'inline' : 'inlineFlex'], typeof style === 'function' ? style(pressState) : style],
45
46
  ...props,
46
47
  children: pressState => typeof children === 'function' ? children(pressState) : children
47
48
  });
@@ -51,6 +52,9 @@ InlinePressable.displayName = 'InlinePressable';
51
52
  const staticStyles = _StyleSheet.default.create({
52
53
  inline: {
53
54
  // Stop Pressable defaulting to (block) flex
55
+ display: 'inline'
56
+ },
57
+ inlineFlex: {
54
58
  display: 'inline-flex'
55
59
  }
56
60
  });
@@ -186,17 +186,20 @@ const LinkBase = /*#__PURE__*/(0, _react.forwardRef)((_ref6, ref) => {
186
186
 
187
187
  const resolveLinkTokens = pressState => (0, _pressability.resolvePressableTokens)(tokens, pressState, {
188
188
  iconPosition
189
- }); // On web, this makes focus rings wrap only the link, not the entire block
189
+ });
190
190
 
191
+ const defaultThemeTokens = resolveLinkTokens({});
192
+ const hasIcon = Boolean(icon || defaultThemeTokens.icon); // On web, this makes focus rings wrap only the link, not the entire block
191
193
 
192
194
  const blockLeftStyle = _Platform.default.OS === 'web' && staticStyles.blockLeft;
193
195
  return /*#__PURE__*/(0, _jsxRuntime.jsx)(_InlinePressable.default, { ...selectedProps,
196
+ inline: hasIcon // assuming links without icons should be inline (even if they are long)
197
+ ,
194
198
  ref: ref,
195
199
  style: linkState => {
196
200
  const themeTokens = resolveLinkTokens(linkState);
197
201
  const outerBorderStyles = selectOuterBorderStyles(themeTokens);
198
202
  const decorationStyles = selectDecorationStyles(themeTokens);
199
- const hasIcon = Boolean(icon || themeTokens.icon);
200
203
  return [outerBorderStyles, blockLeftStyle, decorationStyles, hasIcon && staticStyles.rowContainer];
201
204
  },
202
205
  children: linkState => {
@@ -134,7 +134,10 @@ const StepTracker = /*#__PURE__*/(0, _react.forwardRef)((_ref4, ref) => {
134
134
  dictionary,
135
135
  copy
136
136
  });
137
- const stepTrackerLabel = getCopy('stepTrackerLabel').replace('%{stepNumber}', current < steps.length ? current + 1 : steps.length).replace('%{stepCount}', steps.length).replace('%{stepLabel}', current < steps.length ? steps[current] : steps[steps.length - 1]);
137
+ const stepTrackerLabel = showStepTrackerLabel ? getCopy('stepTrackerLabel').replace('%{stepNumber}', current < steps.length ? current + 1 : steps.length).replace('%{stepCount}', steps.length).replace('%{stepLabel}', current < steps.length ? steps[current] : steps[steps.length - 1]) : '';
138
+
139
+ const getStepLabel = index => themeTokens.showStepLabel ? getCopy('stepLabel').replace('%{stepNumber}', index + 1) : '';
140
+
138
141
  if (!steps.length) return null;
139
142
  const selectedProps = selectProps({
140
143
  accessibilityLabel: stepTrackerLabel,
@@ -160,7 +163,7 @@ const StepTracker = /*#__PURE__*/(0, _react.forwardRef)((_ref4, ref) => {
160
163
  return /*#__PURE__*/(0, _jsxRuntime.jsx)(_Step.default, {
161
164
  status: current,
162
165
  label: label,
163
- name: getCopy('stepLabel').replace('%{stepNumber}', index + 1),
166
+ name: getStepLabel(index),
164
167
  stepIndex: index,
165
168
  stepCount: steps.length,
166
169
  tokens: themeTokens
@@ -7,8 +7,6 @@ exports.default = void 0;
7
7
 
8
8
  var _react = _interopRequireWildcard(require("react"));
9
9
 
10
- var _Platform = _interopRequireDefault(require("react-native-web/dist/cjs/exports/Platform"));
11
-
12
10
  var _utils = require("../utils");
13
11
 
14
12
  var _InputSupports = _interopRequireDefault(require("../InputSupports"));
@@ -49,17 +47,8 @@ const TextInput = /*#__PURE__*/(0, _react.forwardRef)((_ref, ref) => {
49
47
  let {
50
48
  tokens,
51
49
  variant = {},
52
- pattern,
53
50
  ...rest
54
51
  } = _ref;
55
-
56
- _react.default.useEffect(() => {
57
- if (_Platform.default.OS === 'web' && pattern && ref.current) {
58
- // eslint-disable-next-line no-param-reassign
59
- ref.current.pattern = pattern;
60
- }
61
- }, [ref, pattern]);
62
-
63
52
  const {
64
53
  supportsProps,
65
54
  ...selectedProps
@@ -156,6 +156,7 @@ const TextInputBase = /*#__PURE__*/(0, _react.forwardRef)((_ref5, ref) => {
156
156
  onBlur,
157
157
  onMouseOver,
158
158
  onMouseOut,
159
+ pattern,
159
160
  tokens,
160
161
  variant = {},
161
162
  ...rest
@@ -194,6 +195,14 @@ const TextInputBase = /*#__PURE__*/(0, _react.forwardRef)((_ref5, ref) => {
194
195
  onChange,
195
196
  readOnly
196
197
  });
198
+ const element = ref === null || ref === void 0 ? void 0 : ref.current;
199
+ (0, _react.useEffect)(() => {
200
+ if (_Platform.default.OS === 'web' && pattern && element) {
201
+ // React Native Web doesn't support `pattern`, so we have to attach it via a ref,
202
+ // which a `pattern` user must provide anyway to call .checkValidity() on the element.
203
+ element.pattern = pattern;
204
+ }
205
+ }, [element, pattern]);
197
206
 
198
207
  const handleChangeText = event => {
199
208
  var _event$nativeEvent, _event$target;
@@ -7,10 +7,10 @@ exports.default = void 0;
7
7
 
8
8
  var _propTypes = _interopRequireDefault(require("prop-types"));
9
9
 
10
- var _Platform = _interopRequireDefault(require("react-native-web/dist/cjs/exports/Platform"));
11
-
12
10
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
13
11
 
12
+ // These are prop types specific to UDS TextInput; see also ../utils/props/textInputProps
13
+ // for generic React Native props and HTML input attrs that are passed through.
14
14
  const textInputPropTypes = {
15
15
  /**
16
16
  * If the input's state is to be controlled by a parent component, use this prop
@@ -38,12 +38,7 @@ const textInputPropTypes = {
38
38
  * Use to react upon input's value changes. Required when the `value` prop is set.
39
39
  * Will receive the input's value as an argument.
40
40
  */
41
- onChange: _propTypes.default.func,
42
- ..._Platform.default.select({
43
- web: {
44
- pattern: _propTypes.default.string
45
- }
46
- })
41
+ onChange: _propTypes.default.func
47
42
  };
48
43
  var _default = textInputPropTypes;
49
44
  exports.default = _default;
package/lib/index.js CHANGED
@@ -385,6 +385,20 @@ Object.keys(_Button).forEach(function (key) {
385
385
 
386
386
  var _Card = _interopRequireWildcard(require("./Card"));
387
387
 
388
+ var _Carousel = require("./Carousel");
389
+
390
+ Object.keys(_Carousel).forEach(function (key) {
391
+ if (key === "default" || key === "__esModule") return;
392
+ if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
393
+ if (key in exports && exports[key] === _Carousel[key]) return;
394
+ Object.defineProperty(exports, key, {
395
+ enumerable: true,
396
+ get: function () {
397
+ return _Carousel[key];
398
+ }
399
+ });
400
+ });
401
+
388
402
  var _Checkbox = _interopRequireWildcard(require("./Checkbox"));
389
403
 
390
404
  Object.keys(_Checkbox).forEach(function (key) {
@@ -147,7 +147,14 @@ const crossPlatform = { ...textProps,
147
147
  const webOnly = {
148
148
  disabled: _propTypes.default.bool,
149
149
  dir: _propTypes.default.oneOf(['auto', 'ltr', 'rtl']),
150
- lang: _propTypes.default.string
150
+ lang: _propTypes.default.string,
151
+
152
+ /**
153
+ * Sets the HTML input `pattern` attr. Not supported by React Native Web, but is supported by UDS.
154
+ * Must also pass in a ref and check validity by calling the HTML element's checkValidity method:
155
+ * https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement/checkValidity
156
+ */
157
+ pattern: _propTypes.default.string
151
158
  };
152
159
  /**
153
160
  * These props are supported in React Native but not React Native Web.
@@ -1,4 +1,4 @@
1
- import React from 'react';
1
+ import React, { forwardRef } from 'react';
2
2
  import PropTypes from 'prop-types';
3
3
  import { useThemeTokens } from '../ThemeProvider';
4
4
  import { getTokensPropType, variantProp } from '../utils';
@@ -56,7 +56,7 @@ const [selectProps, selectedSystemPropTypes] = selectSystemProps([a11yProps, vie
56
56
  * depending on what you are trying to achieve.
57
57
  */
58
58
 
59
- const Card = _ref => {
59
+ const Card = /*#__PURE__*/forwardRef((_ref, ref) => {
60
60
  let {
61
61
  children,
62
62
  tokens,
@@ -69,13 +69,14 @@ const Card = _ref => {
69
69
  viewport
70
70
  });
71
71
  return /*#__PURE__*/_jsx(CardBase, {
72
+ ref: ref,
72
73
  tokens: themeTokens,
73
74
  dataSet: dataSet,
74
75
  ...selectProps(rest),
75
76
  children: children
76
77
  });
77
- };
78
-
78
+ });
79
+ Card.displayName = 'Card';
79
80
  Card.propTypes = { ...selectedSystemPropTypes,
80
81
  children: PropTypes.node,
81
82
  tokens: getTokensPropType('Card'),