@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
@@ -3,6 +3,7 @@ import Animated from "react-native-web/dist/exports/Animated";
3
3
  import Platform from "react-native-web/dist/exports/Platform";
4
4
  import View from "react-native-web/dist/exports/View";
5
5
  import PropTypes from 'prop-types';
6
+ import ABBPropTypes from 'airbnb-prop-types';
6
7
  import ExpandCollapseControl from './Control';
7
8
  import { useThemeTokens } from '../ThemeProvider';
8
9
  import { a11yProps, getTokensPropType, selectSystemProps, useVerticalExpandAnimation, variantProp, viewProps } from '../utils';
@@ -49,6 +50,7 @@ const ExpandCollapsePanel = /*#__PURE__*/forwardRef((_ref2, ref) => {
49
50
  children,
50
51
  tokens,
51
52
  variant,
53
+ controlRef,
52
54
  ...rest
53
55
  } = _ref2;
54
56
  const [containerHeight, setContainerHeight] = useState(null);
@@ -91,6 +93,7 @@ const ExpandCollapsePanel = /*#__PURE__*/forwardRef((_ref2, ref) => {
91
93
  isExpanded: isExpanded,
92
94
  tokens: controlTokens,
93
95
  onPress: handleControlPress,
96
+ ref: controlRef,
94
97
  children: control
95
98
  }), /*#__PURE__*/_jsx(Animated.View, {
96
99
  ref: animatedRef,
@@ -146,6 +149,11 @@ ExpandCollapsePanel.propTypes = { ...selectedSystemPropTypes,
146
149
  /**
147
150
  * Optional theme token overrides that may be passed to the ExpandCollapseControl element.
148
151
  */
149
- controlTokens: getTokensPropType('ExpandCollapseControl')
152
+ controlTokens: getTokensPropType('ExpandCollapseControl'),
153
+
154
+ /**
155
+ * An optional ref to be attached to the control
156
+ */
157
+ controlRef: ABBPropTypes.ref()
150
158
  };
151
159
  export default ExpandCollapsePanel;
@@ -21,11 +21,12 @@ const InlinePressable = /*#__PURE__*/forwardRef((_ref, ref) => {
21
21
  let {
22
22
  children,
23
23
  style,
24
+ inline = false,
24
25
  ...props
25
26
  } = _ref;
26
27
  return /*#__PURE__*/_jsx(Pressable, {
27
28
  ref: ref,
28
- style: pressState => [staticStyles.inline, typeof style === 'function' ? style(pressState) : style],
29
+ style: pressState => [staticStyles[inline ? 'inline' : 'inlineFlex'], typeof style === 'function' ? style(pressState) : style],
29
30
  ...props,
30
31
  children: pressState => typeof children === 'function' ? children(pressState) : children
31
32
  });
@@ -34,6 +35,9 @@ InlinePressable.displayName = 'InlinePressable';
34
35
  const staticStyles = StyleSheet.create({
35
36
  inline: {
36
37
  // Stop Pressable defaulting to (block) flex
38
+ display: 'inline'
39
+ },
40
+ inlineFlex: {
37
41
  display: 'inline-flex'
38
42
  }
39
43
  });
@@ -158,17 +158,20 @@ const LinkBase = /*#__PURE__*/forwardRef((_ref6, ref) => {
158
158
 
159
159
  const resolveLinkTokens = pressState => resolvePressableTokens(tokens, pressState, {
160
160
  iconPosition
161
- }); // On web, this makes focus rings wrap only the link, not the entire block
161
+ });
162
162
 
163
+ const defaultThemeTokens = resolveLinkTokens({});
164
+ const hasIcon = Boolean(icon || defaultThemeTokens.icon); // On web, this makes focus rings wrap only the link, not the entire block
163
165
 
164
166
  const blockLeftStyle = Platform.OS === 'web' && staticStyles.blockLeft;
165
167
  return /*#__PURE__*/_jsx(InlinePressable, { ...selectedProps,
168
+ inline: hasIcon // assuming links without icons should be inline (even if they are long)
169
+ ,
166
170
  ref: ref,
167
171
  style: linkState => {
168
172
  const themeTokens = resolveLinkTokens(linkState);
169
173
  const outerBorderStyles = selectOuterBorderStyles(themeTokens);
170
174
  const decorationStyles = selectDecorationStyles(themeTokens);
171
- const hasIcon = Boolean(icon || themeTokens.icon);
172
175
  return [outerBorderStyles, blockLeftStyle, decorationStyles, hasIcon && staticStyles.rowContainer];
173
176
  },
174
177
  children: linkState => {
@@ -109,7 +109,10 @@ const StepTracker = /*#__PURE__*/forwardRef((_ref4, ref) => {
109
109
  dictionary,
110
110
  copy
111
111
  });
112
- 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]);
112
+ 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]) : '';
113
+
114
+ const getStepLabel = index => themeTokens.showStepLabel ? getCopy('stepLabel').replace('%{stepNumber}', index + 1) : '';
115
+
113
116
  if (!steps.length) return null;
114
117
  const selectedProps = selectProps({
115
118
  accessibilityLabel: stepTrackerLabel,
@@ -135,7 +138,7 @@ const StepTracker = /*#__PURE__*/forwardRef((_ref4, ref) => {
135
138
  return /*#__PURE__*/_jsx(Step, {
136
139
  status: current,
137
140
  label: label,
138
- name: getCopy('stepLabel').replace('%{stepNumber}', index + 1),
141
+ name: getStepLabel(index),
139
142
  stepIndex: index,
140
143
  stepCount: steps.length,
141
144
  tokens: themeTokens
@@ -1,5 +1,4 @@
1
1
  import React, { forwardRef } from 'react';
2
- import Platform from "react-native-web/dist/exports/Platform";
3
2
  import { a11yProps, focusHandlerProps, getTokensPropType, inputSupportsProps, selectSystemProps, textInputHandlerProps, textInputProps, variantProp, viewProps } from '../utils';
4
3
  import InputSupports from '../InputSupports';
5
4
  import TextInputBase from './TextInputBase';
@@ -29,15 +28,8 @@ const TextInput = /*#__PURE__*/forwardRef((_ref, ref) => {
29
28
  let {
30
29
  tokens,
31
30
  variant = {},
32
- pattern,
33
31
  ...rest
34
32
  } = _ref;
35
- React.useEffect(() => {
36
- if (Platform.OS === 'web' && pattern && ref.current) {
37
- // eslint-disable-next-line no-param-reassign
38
- ref.current.pattern = pattern;
39
- }
40
- }, [ref, pattern]);
41
33
  const {
42
34
  supportsProps,
43
35
  ...selectedProps
@@ -1,4 +1,4 @@
1
- import React, { forwardRef, useState } from 'react';
1
+ import React, { forwardRef, useEffect, useState } from 'react';
2
2
  import Platform from "react-native-web/dist/exports/Platform";
3
3
  import StyleSheet from "react-native-web/dist/exports/StyleSheet";
4
4
  import NativeTextInput from "react-native-web/dist/exports/TextInput";
@@ -133,6 +133,7 @@ const TextInputBase = /*#__PURE__*/forwardRef((_ref5, ref) => {
133
133
  onBlur,
134
134
  onMouseOver,
135
135
  onMouseOut,
136
+ pattern,
136
137
  tokens,
137
138
  variant = {},
138
139
  ...rest
@@ -171,6 +172,14 @@ const TextInputBase = /*#__PURE__*/forwardRef((_ref5, ref) => {
171
172
  onChange,
172
173
  readOnly
173
174
  });
175
+ const element = ref === null || ref === void 0 ? void 0 : ref.current;
176
+ useEffect(() => {
177
+ if (Platform.OS === 'web' && pattern && element) {
178
+ // React Native Web doesn't support `pattern`, so we have to attach it via a ref,
179
+ // which a `pattern` user must provide anyway to call .checkValidity() on the element.
180
+ element.pattern = pattern;
181
+ }
182
+ }, [element, pattern]);
174
183
 
175
184
  const handleChangeText = event => {
176
185
  var _event$nativeEvent, _event$target;
@@ -1,5 +1,6 @@
1
- import PropTypes from 'prop-types';
2
- import Platform from "react-native-web/dist/exports/Platform";
1
+ import PropTypes from 'prop-types'; // These are prop types specific to UDS TextInput; see also ../utils/props/textInputProps
2
+ // for generic React Native props and HTML input attrs that are passed through.
3
+
3
4
  const textInputPropTypes = {
4
5
  /**
5
6
  * If the input's state is to be controlled by a parent component, use this prop
@@ -27,11 +28,6 @@ const textInputPropTypes = {
27
28
  * Use to react upon input's value changes. Required when the `value` prop is set.
28
29
  * Will receive the input's value as an argument.
29
30
  */
30
- onChange: PropTypes.func,
31
- ...Platform.select({
32
- web: {
33
- pattern: PropTypes.string
34
- }
35
- })
31
+ onChange: PropTypes.func
36
32
  };
37
33
  export default textInputPropTypes;
@@ -3,6 +3,7 @@ export { default as ActivityIndicator } from './ActivityIndicator';
3
3
  export { default as Box } from './Box';
4
4
  export * from './Button';
5
5
  export { default as Card, PressableCardBase } from './Card';
6
+ export * from './Carousel';
6
7
  export { default as Checkbox } from './Checkbox';
7
8
  export * from './Checkbox';
8
9
  export { default as Divider } from './Divider';
@@ -135,7 +135,14 @@ const crossPlatform = { ...textProps,
135
135
  const webOnly = {
136
136
  disabled: PropTypes.bool,
137
137
  dir: PropTypes.oneOf(['auto', 'ltr', 'rtl']),
138
- lang: PropTypes.string
138
+ lang: PropTypes.string,
139
+
140
+ /**
141
+ * Sets the HTML input `pattern` attr. Not supported by React Native Web, but is supported by UDS.
142
+ * Must also pass in a ref and check validity by calling the HTML element's checkValidity method:
143
+ * https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement/checkValidity
144
+ */
145
+ pattern: PropTypes.string
139
146
  };
140
147
  /**
141
148
  * These props are supported in React Native but not React Native Web.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@telus-uds/components-base",
3
- "version": "1.8.4",
3
+ "version": "1.10.0",
4
4
  "description": "Base components",
5
5
  "keywords": [
6
6
  "base"
@@ -46,7 +46,7 @@
46
46
  "peerDependencies": {
47
47
  "react": "^17.0.2",
48
48
  "react-dom": "^17.0.2",
49
- "react-native": "*",
49
+ "react-native": "0.68.2",
50
50
  "react-native-web": "^0.17.0"
51
51
  },
52
52
  "devDependencies": {
@@ -66,7 +66,7 @@
66
66
  "dependencies": {
67
67
  "airbnb-prop-types": "^2.16.0",
68
68
  "@telus-uds/system-constants": "^1.0.4",
69
- "@telus-uds/system-theme-tokens": "^2.0.2",
69
+ "@telus-uds/system-theme-tokens": "^2.1.0",
70
70
  "lodash.debounce": "^4.0.8",
71
71
  "lodash.merge": "^4.6.2",
72
72
  "prop-types": "^15.7.2",
package/src/Card/Card.jsx CHANGED
@@ -1,4 +1,4 @@
1
- import React from 'react'
1
+ import React, { forwardRef } from 'react'
2
2
  import PropTypes from 'prop-types'
3
3
 
4
4
  import { useThemeTokens } from '../ThemeProvider'
@@ -57,16 +57,18 @@ const [selectProps, selectedSystemPropTypes] = selectSystemProps([a11yProps, vie
57
57
  * you automatically make inaccessible its children, which may or may not be appropriate
58
58
  * depending on what you are trying to achieve.
59
59
  */
60
- const Card = ({ children, tokens, variant, dataSet, ...rest }) => {
60
+ const Card = forwardRef(({ children, tokens, variant, dataSet, ...rest }, ref) => {
61
61
  const viewport = useViewport()
62
62
  const themeTokens = useThemeTokens('Card', tokens, variant, { viewport })
63
63
 
64
64
  return (
65
- <CardBase tokens={themeTokens} dataSet={dataSet} {...selectProps(rest)}>
65
+ <CardBase ref={ref} tokens={themeTokens} dataSet={dataSet} {...selectProps(rest)}>
66
66
  {children}
67
67
  </CardBase>
68
68
  )
69
- }
69
+ })
70
+
71
+ Card.displayName = 'Card'
70
72
 
71
73
  Card.propTypes = {
72
74
  ...selectedSystemPropTypes,