@telus-uds/components-base 0.0.2-prerelease.6 → 0.0.2-prerelease.7
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.
- package/.ultra.cache.json +1 -1
- package/CHANGELOG.md +20 -0
- package/__fixtures__/testTheme.js +424 -37
- package/__tests__/Button/ButtonBase.test.jsx +2 -31
- package/__tests__/Checkbox/Checkbox.test.jsx +94 -0
- package/__tests__/InputSupports/InputSupports.test.jsx +50 -0
- package/__tests__/List/List.test.jsx +60 -0
- package/__tests__/Radio/Radio.test.jsx +87 -0
- package/__tests__/Select/Select.test.jsx +93 -0
- package/__tests__/Skeleton/Skeleton.test.jsx +61 -0
- package/__tests__/Tags/Tags.test.jsx +328 -0
- package/__tests__/TextInput/TextArea.test.jsx +34 -0
- package/__tests__/TextInput/{TextInput.test.jsx → TextInputBase.test.jsx} +20 -46
- package/jest.config.js +3 -1
- package/lib/Button/Button.js +10 -3
- package/lib/Button/ButtonBase.js +73 -59
- package/lib/Button/ButtonGroup.js +11 -27
- package/lib/Button/ButtonLink.js +5 -0
- package/lib/Checkbox/Checkbox.js +308 -0
- package/lib/Checkbox/CheckboxInput.native.js +6 -0
- package/lib/Checkbox/CheckboxInput.web.js +57 -0
- package/lib/Checkbox/index.js +2 -0
- package/lib/Feedback/Feedback.js +20 -3
- package/lib/Icon/Icon.js +8 -5
- package/lib/Icon/IconText.js +72 -0
- package/lib/Icon/index.js +2 -1
- package/lib/InputSupports/InputSupports.js +90 -0
- package/lib/InputSupports/index.js +2 -0
- package/lib/InputSupports/propTypes.js +55 -0
- package/lib/Link/ChevronLink.js +23 -20
- package/lib/Link/InlinePressable.native.js +78 -0
- package/lib/Link/InlinePressable.web.js +32 -0
- package/lib/Link/Link.js +11 -10
- package/lib/Link/LinkBase.js +62 -123
- package/lib/Link/TextButton.js +20 -9
- package/lib/Link/index.js +2 -1
- package/lib/List/List.js +52 -0
- package/lib/List/ListItem.js +207 -0
- package/lib/List/index.js +2 -0
- package/lib/Pagination/PageButton.js +2 -25
- package/lib/Pagination/SideButton.js +27 -37
- package/lib/Radio/Radio.js +291 -0
- package/lib/Radio/RadioInput.native.js +6 -0
- package/lib/Radio/RadioInput.web.js +59 -0
- package/lib/Radio/index.js +2 -0
- package/lib/Select/Group.native.js +14 -0
- package/lib/Select/Group.web.js +18 -0
- package/lib/Select/Item.native.js +9 -0
- package/lib/Select/Item.web.js +15 -0
- package/lib/Select/Picker.native.js +87 -0
- package/lib/Select/Picker.web.js +63 -0
- package/lib/Select/Select.js +272 -0
- package/lib/Select/index.js +6 -0
- package/lib/Skeleton/Skeleton.js +119 -0
- package/lib/Skeleton/index.js +2 -0
- package/lib/Tags/Tags.js +217 -0
- package/lib/Tags/index.js +2 -0
- package/lib/TextInput/TextArea.js +82 -0
- package/lib/TextInput/TextInput.js +23 -304
- package/lib/TextInput/TextInputBase.js +229 -0
- package/lib/TextInput/index.js +2 -1
- package/lib/TextInput/propTypes.js +31 -0
- package/lib/ThemeProvider/useThemeTokens.js +54 -3
- package/lib/ToggleSwitch/ToggleSwitch.js +1 -1
- package/lib/Typography/Typography.js +4 -19
- package/lib/index.js +8 -1
- package/lib/utils/a11y/index.js +1 -0
- package/lib/utils/a11y/textSize.js +33 -0
- package/lib/utils/index.js +3 -0
- package/lib/utils/info/index.js +7 -0
- package/lib/utils/info/platform/index.js +11 -0
- package/lib/utils/info/platform/platform.android.js +1 -0
- package/lib/utils/info/platform/platform.ios.js +1 -0
- package/lib/utils/info/platform/platform.native.js +4 -0
- package/lib/utils/info/platform/platform.web.js +1 -0
- package/lib/utils/info/versions.js +5 -0
- package/lib/utils/pressability.js +92 -0
- package/lib/utils/propTypes.js +78 -17
- package/package.json +5 -4
- package/release-context.json +4 -4
- package/src/Button/Button.jsx +6 -3
- package/src/Button/ButtonBase.jsx +66 -57
- package/src/Button/ButtonGroup.jsx +9 -22
- package/src/Button/ButtonLink.jsx +11 -2
- package/src/Checkbox/Checkbox.jsx +275 -0
- package/src/Checkbox/CheckboxInput.native.jsx +6 -0
- package/src/Checkbox/CheckboxInput.web.jsx +55 -0
- package/src/Checkbox/index.js +3 -0
- package/src/Feedback/Feedback.jsx +13 -4
- package/src/Icon/Icon.jsx +9 -5
- package/src/Icon/IconText.jsx +63 -0
- package/src/Icon/index.js +2 -1
- package/src/InputSupports/InputSupports.jsx +86 -0
- package/src/InputSupports/index.js +3 -0
- package/src/InputSupports/propTypes.js +44 -0
- package/src/Link/ChevronLink.jsx +20 -17
- package/src/Link/InlinePressable.native.jsx +73 -0
- package/src/Link/InlinePressable.web.jsx +37 -0
- package/src/Link/Link.jsx +17 -13
- package/src/Link/LinkBase.jsx +57 -140
- package/src/Link/TextButton.jsx +25 -11
- package/src/Link/index.js +2 -1
- package/src/List/List.jsx +47 -0
- package/src/List/ListItem.jsx +187 -0
- package/src/List/index.js +3 -0
- package/src/Pagination/PageButton.jsx +2 -16
- package/src/Pagination/SideButton.jsx +23 -34
- package/src/Radio/Radio.jsx +270 -0
- package/src/Radio/RadioInput.native.jsx +6 -0
- package/src/Radio/RadioInput.web.jsx +57 -0
- package/src/Radio/index.js +3 -0
- package/src/Select/Group.native.jsx +14 -0
- package/src/Select/Group.web.jsx +15 -0
- package/src/Select/Item.native.jsx +10 -0
- package/src/Select/Item.web.jsx +11 -0
- package/src/Select/Picker.native.jsx +95 -0
- package/src/Select/Picker.web.jsx +67 -0
- package/src/Select/Select.jsx +265 -0
- package/src/Select/index.js +8 -0
- package/src/Skeleton/Skeleton.jsx +101 -0
- package/src/Skeleton/index.js +3 -0
- package/src/Tags/Tags.jsx +206 -0
- package/src/Tags/index.js +3 -0
- package/src/TextInput/TextArea.jsx +78 -0
- package/src/TextInput/TextInput.jsx +17 -284
- package/src/TextInput/TextInputBase.jsx +220 -0
- package/src/TextInput/index.js +2 -1
- package/src/TextInput/propTypes.js +29 -0
- package/src/ThemeProvider/useThemeTokens.js +54 -3
- package/src/ToggleSwitch/ToggleSwitch.jsx +1 -1
- package/src/Typography/Typography.jsx +4 -15
- package/src/index.js +8 -1
- package/src/utils/a11y/index.js +1 -0
- package/src/utils/a11y/textSize.js +30 -0
- package/src/utils/index.js +3 -0
- package/src/utils/info/index.js +8 -0
- package/src/utils/info/platform/index.js +11 -0
- package/src/utils/info/platform/platform.android.js +1 -0
- package/src/utils/info/platform/platform.ios.js +1 -0
- package/src/utils/info/platform/platform.native.js +4 -0
- package/src/utils/info/platform/platform.web.js +1 -0
- package/src/utils/info/versions.js +6 -0
- package/src/utils/pressability.js +92 -0
- package/src/utils/propTypes.js +97 -22
- package/stories/Button/Button.stories.jsx +5 -0
- package/stories/Checkbox/Checkbox.stories.jsx +71 -0
- package/stories/Feedback/Feedback.stories.jsx +5 -6
- package/stories/Link/Link.stories.jsx +15 -1
- package/stories/List/List.stories.jsx +117 -0
- package/stories/Radio/Radio.stories.jsx +113 -0
- package/stories/Select/Select.stories.jsx +55 -0
- package/stories/Skeleton/Skeleton.stories.jsx +36 -0
- package/stories/Tags/Tags.stories.jsx +69 -0
- package/stories/TextInput/TextArea.stories.jsx +100 -0
- package/stories/supports.jsx +1 -1
|
@@ -0,0 +1,272 @@
|
|
|
1
|
+
import React, { useState } from 'react';
|
|
2
|
+
import { View, Platform, StyleSheet } from 'react-native';
|
|
3
|
+
import PropTypes from 'prop-types';
|
|
4
|
+
import { applyTextStyles, useThemeTokens } from '../ThemeProvider';
|
|
5
|
+
import { componentPropType, getTokensPropType, useInputValue, variantProp } from '../utils';
|
|
6
|
+
import Picker from './Picker';
|
|
7
|
+
import InputSupports from '../InputSupports';
|
|
8
|
+
import inputSupportsProps from '../InputSupports/propTypes';
|
|
9
|
+
|
|
10
|
+
const selectInputStyles = ({
|
|
11
|
+
backgroundColor,
|
|
12
|
+
color,
|
|
13
|
+
borderWidth = 0,
|
|
14
|
+
borderColor,
|
|
15
|
+
borderRadius,
|
|
16
|
+
paddingTop,
|
|
17
|
+
paddingBottom,
|
|
18
|
+
paddingLeft = 0,
|
|
19
|
+
paddingRight,
|
|
20
|
+
fontName,
|
|
21
|
+
fontSize,
|
|
22
|
+
fontWeight,
|
|
23
|
+
lineHeight,
|
|
24
|
+
icon,
|
|
25
|
+
iconSize = 0,
|
|
26
|
+
validationIcon,
|
|
27
|
+
validationIconSize = 0,
|
|
28
|
+
height
|
|
29
|
+
}, inactive) => {
|
|
30
|
+
// Subtract border width from padding so overall input width/height doesn't
|
|
31
|
+
// jump around if the border width changes (avoiding NaN and negative padding)
|
|
32
|
+
const offsetBorder = value => typeof value === 'number' ? Math.max(0, value - borderWidth) : value;
|
|
33
|
+
|
|
34
|
+
const textStyles = applyTextStyles({
|
|
35
|
+
fontName,
|
|
36
|
+
fontSize,
|
|
37
|
+
lineHeight,
|
|
38
|
+
fontWeight
|
|
39
|
+
});
|
|
40
|
+
const webStyles = Platform.select({
|
|
41
|
+
web: {
|
|
42
|
+
appearance: 'none',
|
|
43
|
+
WebkitAppearance: 'none',
|
|
44
|
+
// since iOS Safari needs a prefix
|
|
45
|
+
outline: 'none',
|
|
46
|
+
cursor: inactive ? 'not-allowed' : undefined,
|
|
47
|
+
opacity: inactive ? 1 : undefined // override Chrome's default fadeout of a disabled select
|
|
48
|
+
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
let paddingWithIcons = paddingRight;
|
|
52
|
+
|
|
53
|
+
if (Platform.OS !== 'android') {
|
|
54
|
+
if (icon) {
|
|
55
|
+
paddingWithIcons += iconSize;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
if (validationIcon) {
|
|
59
|
+
paddingWithIcons += validationIconSize;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
return {
|
|
64
|
+
backgroundColor,
|
|
65
|
+
color,
|
|
66
|
+
borderWidth,
|
|
67
|
+
borderColor,
|
|
68
|
+
borderRadius,
|
|
69
|
+
paddingLeft: offsetBorder(paddingLeft),
|
|
70
|
+
paddingRight: offsetBorder(paddingWithIcons),
|
|
71
|
+
paddingTop: offsetBorder(paddingTop),
|
|
72
|
+
paddingBottom: offsetBorder(paddingBottom),
|
|
73
|
+
height,
|
|
74
|
+
...textStyles,
|
|
75
|
+
...webStyles
|
|
76
|
+
};
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
const selectOuterBorderStyles = ({
|
|
80
|
+
outerBackgroundColor,
|
|
81
|
+
outerBorderWidth = 0,
|
|
82
|
+
outerBorderColor,
|
|
83
|
+
outerBorderRadius = 0
|
|
84
|
+
}) => {
|
|
85
|
+
// Use negative margins so that the outer border doesn't expand the input's bounding box
|
|
86
|
+
const margin = -1 * outerBorderWidth; // Account for the border width since we style it as an outline
|
|
87
|
+
|
|
88
|
+
const borderRadius = outerBorderRadius + outerBorderWidth;
|
|
89
|
+
return {
|
|
90
|
+
background: outerBackgroundColor,
|
|
91
|
+
borderWidth: outerBorderWidth,
|
|
92
|
+
borderColor: outerBorderColor,
|
|
93
|
+
borderRadius,
|
|
94
|
+
marginTop: margin,
|
|
95
|
+
marginBottom: margin,
|
|
96
|
+
marginLeft: margin,
|
|
97
|
+
marginRight: margin
|
|
98
|
+
};
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
const selectIconTokens = ({
|
|
102
|
+
iconSize,
|
|
103
|
+
iconColor
|
|
104
|
+
}) => ({
|
|
105
|
+
size: iconSize,
|
|
106
|
+
color: iconColor
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
const selectIconContainerStyles = ({
|
|
110
|
+
paddingRight,
|
|
111
|
+
paddingBottom
|
|
112
|
+
}) => ({
|
|
113
|
+
paddingRight,
|
|
114
|
+
paddingBottom
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
const selectValidationIconTokens = ({
|
|
118
|
+
validationIconSize,
|
|
119
|
+
validationIconColor
|
|
120
|
+
}) => ({
|
|
121
|
+
size: validationIconSize,
|
|
122
|
+
color: validationIconColor
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
const selectValidationIconContainerStyles = ({
|
|
126
|
+
icon,
|
|
127
|
+
iconSize = 0,
|
|
128
|
+
paddingRight = 0,
|
|
129
|
+
paddingBottom
|
|
130
|
+
}) => ({
|
|
131
|
+
paddingRight: icon ? paddingRight + iconSize : paddingRight,
|
|
132
|
+
paddingBottom
|
|
133
|
+
});
|
|
134
|
+
/**
|
|
135
|
+
* A basic form single-choice select component. Use in forms or individually to receive user's input.
|
|
136
|
+
*
|
|
137
|
+
* ## Usage criteria
|
|
138
|
+
* - Include a `placeholder` to provide instructions such as "Please select..." as an unselectable option (recommended)
|
|
139
|
+
* - Use when options are between 7-15 (recommended)
|
|
140
|
+
* - For options are 6 and under, use `Radio` groups or `ButtonGroup`.
|
|
141
|
+
* - For options 15 and above, look for alternatives (e.g grouping into categories, or input field with auto-complete etc.)
|
|
142
|
+
*
|
|
143
|
+
* ## Controlled component
|
|
144
|
+
* If it is required that the state of the `Select` be controlled by the application or other external methods,
|
|
145
|
+
* `value` and `onChange` props must be passed to the `Select`.
|
|
146
|
+
* If the `Select` value should not be changed by user input, a `readOnly` prop must be provided.
|
|
147
|
+
*
|
|
148
|
+
* ## Uncontrolled component
|
|
149
|
+
* If it is not necessary to control the `Select` state, you can create one without a value prop.
|
|
150
|
+
* In this case its value can be accessed within the `onChange` callback. Use the `initialValue` prop to set the
|
|
151
|
+
* default value for an uncontrolled `Select`.
|
|
152
|
+
*
|
|
153
|
+
* ## Getting feedback for entered values
|
|
154
|
+
* Use the `feedback` prop to give the user feedback regarding their selection.
|
|
155
|
+
* You can affirm that the user's selection was correct, or highlight errors that must be corrected, using the `validation` prop.
|
|
156
|
+
* Keep feedback text as brief as possible, should be limited to text and links.
|
|
157
|
+
*
|
|
158
|
+
* ## Using a tooltip
|
|
159
|
+
* When a more in-depth explanation is needed to fill out a `Select` properly, the tooltip prop may be used.
|
|
160
|
+
*
|
|
161
|
+
* ## Grouping options
|
|
162
|
+
* `Select` supports option groups. Use a `Select.Group` component to render an `<optgroup>` element with its items.
|
|
163
|
+
* NOTE: this does not work on native platforms - the grouped items will be shown at the same level as the non-grouped items.
|
|
164
|
+
*
|
|
165
|
+
*/
|
|
166
|
+
|
|
167
|
+
|
|
168
|
+
const Select = ({
|
|
169
|
+
value,
|
|
170
|
+
initialValue,
|
|
171
|
+
onChange,
|
|
172
|
+
children,
|
|
173
|
+
inactive,
|
|
174
|
+
readOnly,
|
|
175
|
+
placeholder,
|
|
176
|
+
validation,
|
|
177
|
+
tokens,
|
|
178
|
+
variant,
|
|
179
|
+
testID,
|
|
180
|
+
...rest
|
|
181
|
+
}) => {
|
|
182
|
+
const {
|
|
183
|
+
currentValue,
|
|
184
|
+
setValue
|
|
185
|
+
} = useInputValue({
|
|
186
|
+
value,
|
|
187
|
+
initialValue,
|
|
188
|
+
onChange,
|
|
189
|
+
readOnly
|
|
190
|
+
});
|
|
191
|
+
const [isFocused, setIsFocused] = useState(false);
|
|
192
|
+
|
|
193
|
+
const handleFocus = () => setIsFocused(true);
|
|
194
|
+
|
|
195
|
+
const handleBlur = () => setIsFocused(false);
|
|
196
|
+
|
|
197
|
+
const [isHovered, setIsHovered] = useState(false);
|
|
198
|
+
|
|
199
|
+
const handleMouseOver = () => setIsHovered(true);
|
|
200
|
+
|
|
201
|
+
const handleMouseOut = () => setIsHovered(false);
|
|
202
|
+
|
|
203
|
+
const {
|
|
204
|
+
props: supportsProps
|
|
205
|
+
} = inputSupportsProps.select(rest);
|
|
206
|
+
const themeTokens = useThemeTokens('Select', tokens, variant, {
|
|
207
|
+
focus: isFocused,
|
|
208
|
+
hover: isHovered,
|
|
209
|
+
inactive,
|
|
210
|
+
validation
|
|
211
|
+
});
|
|
212
|
+
const {
|
|
213
|
+
icon: IconComponent,
|
|
214
|
+
validationIcon: ValidationIconComponent
|
|
215
|
+
} = themeTokens;
|
|
216
|
+
return /*#__PURE__*/React.createElement(InputSupports, supportsProps, ({
|
|
217
|
+
a11yProps,
|
|
218
|
+
inputId
|
|
219
|
+
}) => /*#__PURE__*/React.createElement(View, {
|
|
220
|
+
style: selectOuterBorderStyles(themeTokens)
|
|
221
|
+
}, /*#__PURE__*/React.createElement(Picker, Object.assign({
|
|
222
|
+
style: selectInputStyles(themeTokens, inactive),
|
|
223
|
+
onFocus: handleFocus,
|
|
224
|
+
onBlur: handleBlur,
|
|
225
|
+
onMouseOver: handleMouseOver,
|
|
226
|
+
onMouseOut: handleMouseOut,
|
|
227
|
+
onChange: setValue,
|
|
228
|
+
value: currentValue,
|
|
229
|
+
inactive: inactive,
|
|
230
|
+
placeholder: placeholder !== undefined ? {
|
|
231
|
+
label: placeholder,
|
|
232
|
+
value: ''
|
|
233
|
+
} : undefined
|
|
234
|
+
}, a11yProps, {
|
|
235
|
+
nativeID: inputId,
|
|
236
|
+
testID: testID
|
|
237
|
+
}), children), ValidationIconComponent && /*#__PURE__*/React.createElement(View, {
|
|
238
|
+
pointerEvents: "none",
|
|
239
|
+
style: [staticStyles.iconContainer, selectValidationIconContainerStyles(themeTokens)]
|
|
240
|
+
}, /*#__PURE__*/React.createElement(ValidationIconComponent, {
|
|
241
|
+
tokens: selectValidationIconTokens(themeTokens)
|
|
242
|
+
})), IconComponent && Platform.OS !== 'android' &&
|
|
243
|
+
/*#__PURE__*/
|
|
244
|
+
// we can't hide the default caret of a native picker on android
|
|
245
|
+
React.createElement(View, {
|
|
246
|
+
pointerEvents: "none",
|
|
247
|
+
style: [staticStyles.iconContainer, selectIconContainerStyles(themeTokens)]
|
|
248
|
+
}, /*#__PURE__*/React.createElement(IconComponent, {
|
|
249
|
+
tokens: selectIconTokens(themeTokens)
|
|
250
|
+
}))));
|
|
251
|
+
};
|
|
252
|
+
|
|
253
|
+
Select.propTypes = { ...inputSupportsProps.types,
|
|
254
|
+
initialValue: PropTypes.string,
|
|
255
|
+
value: PropTypes.string,
|
|
256
|
+
onChange: PropTypes.func,
|
|
257
|
+
children: componentPropType(['Item', 'Group']),
|
|
258
|
+
inactive: PropTypes.bool,
|
|
259
|
+
readOnly: PropTypes.bool,
|
|
260
|
+
placeholder: PropTypes.string,
|
|
261
|
+
tokens: getTokensPropType('Select'),
|
|
262
|
+
variant: variantProp.propType,
|
|
263
|
+
testID: PropTypes.string
|
|
264
|
+
};
|
|
265
|
+
export default Select;
|
|
266
|
+
const staticStyles = StyleSheet.create({
|
|
267
|
+
iconContainer: {
|
|
268
|
+
position: 'absolute',
|
|
269
|
+
right: 0,
|
|
270
|
+
bottom: 0
|
|
271
|
+
}
|
|
272
|
+
});
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import React, { useEffect, useRef } from 'react';
|
|
2
|
+
import { Animated, Platform } from 'react-native';
|
|
3
|
+
import propTypes from 'prop-types';
|
|
4
|
+
import StackView from '../StackView';
|
|
5
|
+
import { useThemeTokens } from '../ThemeProvider';
|
|
6
|
+
import { getTokensPropType, useSpacingScale, variantProp } from '../utils';
|
|
7
|
+
|
|
8
|
+
const selectSkeletonStyles = ({
|
|
9
|
+
color,
|
|
10
|
+
radius,
|
|
11
|
+
fadeAnimation
|
|
12
|
+
}) => ({
|
|
13
|
+
backgroundColor: color,
|
|
14
|
+
borderRadius: radius,
|
|
15
|
+
opacity: fadeAnimation
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
const selectLineStyles = ({
|
|
19
|
+
skeletonHeight,
|
|
20
|
+
lineWidth
|
|
21
|
+
}) => ({
|
|
22
|
+
width: lineWidth,
|
|
23
|
+
height: skeletonHeight
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
const selectShapeStyles = ({
|
|
27
|
+
skeletonHeight
|
|
28
|
+
}) => ({
|
|
29
|
+
height: skeletonHeight,
|
|
30
|
+
width: skeletonHeight
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
const selectSquareStyles = ({
|
|
34
|
+
radius
|
|
35
|
+
}) => ({
|
|
36
|
+
borderRadius: radius
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
const Skeleton = ({
|
|
40
|
+
tokens,
|
|
41
|
+
variant,
|
|
42
|
+
size,
|
|
43
|
+
characters,
|
|
44
|
+
lines,
|
|
45
|
+
shape = 'line'
|
|
46
|
+
}) => {
|
|
47
|
+
const themeTokens = useThemeTokens('Skeleton', tokens, variant);
|
|
48
|
+
const skeletonHeight = useSpacingScale(size || themeTokens.size);
|
|
49
|
+
const fadeAnimation = useRef(new Animated.Value(0)).current;
|
|
50
|
+
|
|
51
|
+
const getLineWidth = () => {
|
|
52
|
+
if (characters) {
|
|
53
|
+
return characters * themeTokens.baseWidth;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
return themeTokens.characters * themeTokens.baseWidth;
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
useEffect(() => {
|
|
60
|
+
const fade = Animated.sequence([Animated.timing(fadeAnimation, {
|
|
61
|
+
toValue: 1,
|
|
62
|
+
duration: 1000,
|
|
63
|
+
useNativeDriver: Platform.OS !== 'web'
|
|
64
|
+
}), Animated.timing(fadeAnimation, {
|
|
65
|
+
toValue: 0,
|
|
66
|
+
duration: 1000,
|
|
67
|
+
useNativeDriver: Platform.OS !== 'web'
|
|
68
|
+
})]);
|
|
69
|
+
Animated.loop(fade).start();
|
|
70
|
+
}, [fadeAnimation]);
|
|
71
|
+
|
|
72
|
+
const getStyledBasedOnShape = () => {
|
|
73
|
+
if (shape === 'circle') {
|
|
74
|
+
return selectShapeStyles({
|
|
75
|
+
skeletonHeight
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
if (shape === 'box') {
|
|
80
|
+
return [selectShapeStyles({
|
|
81
|
+
skeletonHeight
|
|
82
|
+
}), selectSquareStyles({
|
|
83
|
+
radius: themeTokens.squareRadius
|
|
84
|
+
})];
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
return selectLineStyles({
|
|
88
|
+
skeletonHeight,
|
|
89
|
+
lineWidth: getLineWidth()
|
|
90
|
+
});
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
const renderSkeleton = (index = 0) => /*#__PURE__*/React.createElement(Animated.View, {
|
|
94
|
+
testID: "skeleton",
|
|
95
|
+
key: `skeleton-${index + 1}`,
|
|
96
|
+
style: [selectSkeletonStyles({ ...themeTokens,
|
|
97
|
+
fadeAnimation
|
|
98
|
+
}), getStyledBasedOnShape()]
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
if (lines) {
|
|
102
|
+
const arrayOfSkeletons = [...Array(lines)];
|
|
103
|
+
return /*#__PURE__*/React.createElement(StackView, {
|
|
104
|
+
space: themeTokens.spaceBetweenLines
|
|
105
|
+
}, arrayOfSkeletons.map((_, index) => renderSkeleton(index)));
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
return renderSkeleton();
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
Skeleton.propTypes = {
|
|
112
|
+
tokens: getTokensPropType('Skeleton'),
|
|
113
|
+
variant: variantProp.propType,
|
|
114
|
+
size: propTypes.number,
|
|
115
|
+
characters: propTypes.number,
|
|
116
|
+
lines: propTypes.number,
|
|
117
|
+
shape: propTypes.oneOf(['line', 'circle', 'box'])
|
|
118
|
+
};
|
|
119
|
+
export default Skeleton;
|
package/lib/Tags/Tags.js
ADDED
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import PropTypes from 'prop-types';
|
|
3
|
+
import { Platform, Text, View } from 'react-native';
|
|
4
|
+
import ButtonBase from '../Button/ButtonBase';
|
|
5
|
+
import { StackWrap, getStackedContent } from '../StackView';
|
|
6
|
+
import { useViewport } from '../ViewportProvider';
|
|
7
|
+
import { useThemeTokens, useThemeTokensCallback } from '../ThemeProvider';
|
|
8
|
+
import { a11yProps, pressProps, variantProp, getTokensPropType, selectTokens } from '../utils/propTypes';
|
|
9
|
+
import { useMultipleInputValues } from '../utils/input';
|
|
10
|
+
import { getPressHandlersWithArgs } from '../utils/pressability';
|
|
11
|
+
|
|
12
|
+
const selectIconTextTokens = ({
|
|
13
|
+
icon,
|
|
14
|
+
iconPosition,
|
|
15
|
+
iconSpace,
|
|
16
|
+
iconSize,
|
|
17
|
+
iconColor,
|
|
18
|
+
iconBackground,
|
|
19
|
+
iconBorderRadius,
|
|
20
|
+
iconAlignSelf,
|
|
21
|
+
iconPadding,
|
|
22
|
+
iconTranslateX,
|
|
23
|
+
iconTranslateY
|
|
24
|
+
}) => ({
|
|
25
|
+
icon,
|
|
26
|
+
iconPosition,
|
|
27
|
+
iconSpace,
|
|
28
|
+
iconWrapperStyle: {
|
|
29
|
+
backgroundColor: iconBackground,
|
|
30
|
+
borderRadius: iconBorderRadius,
|
|
31
|
+
alignSelf: iconAlignSelf,
|
|
32
|
+
padding: iconPadding,
|
|
33
|
+
...Platform.select({
|
|
34
|
+
// TODO: https://github.com/telus/universal-design-system/issues/487
|
|
35
|
+
web: {
|
|
36
|
+
transition: 'color 200ms, background 200ms'
|
|
37
|
+
}
|
|
38
|
+
})
|
|
39
|
+
},
|
|
40
|
+
iconTokens: {
|
|
41
|
+
size: iconSize,
|
|
42
|
+
color: iconColor,
|
|
43
|
+
translateX: iconTranslateX,
|
|
44
|
+
translateY: iconTranslateY
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
const Tags = ({
|
|
49
|
+
variant,
|
|
50
|
+
tokens,
|
|
51
|
+
items = [],
|
|
52
|
+
values,
|
|
53
|
+
initialValues,
|
|
54
|
+
maxValues,
|
|
55
|
+
onChange,
|
|
56
|
+
readOnly = false,
|
|
57
|
+
inactive = false,
|
|
58
|
+
accessibilityRole = Platform.select({
|
|
59
|
+
web: 'group',
|
|
60
|
+
default: 'none'
|
|
61
|
+
}),
|
|
62
|
+
...rest
|
|
63
|
+
}) => {
|
|
64
|
+
const viewport = useViewport();
|
|
65
|
+
const themeTokens = useThemeTokens('Tags', tokens, variant, {
|
|
66
|
+
viewport
|
|
67
|
+
});
|
|
68
|
+
const stackTokens = selectTokens('StackView', themeTokens);
|
|
69
|
+
const {
|
|
70
|
+
direction,
|
|
71
|
+
space
|
|
72
|
+
} = themeTokens;
|
|
73
|
+
const getItemTokens = useThemeTokensCallback('TagsItem', tokens, variant);
|
|
74
|
+
|
|
75
|
+
const getButtonTokens = buttonState => selectTokens('Button', getItemTokens(buttonState));
|
|
76
|
+
|
|
77
|
+
const {
|
|
78
|
+
currentValues,
|
|
79
|
+
toggleOneValue
|
|
80
|
+
} = useMultipleInputValues({
|
|
81
|
+
initialValues,
|
|
82
|
+
values,
|
|
83
|
+
maxValues,
|
|
84
|
+
onChange,
|
|
85
|
+
readOnly
|
|
86
|
+
});
|
|
87
|
+
const a11y = a11yProps.select({
|
|
88
|
+
accessibilityRole,
|
|
89
|
+
...rest
|
|
90
|
+
});
|
|
91
|
+
const itemA11yRole = 'checkbox';
|
|
92
|
+
return /*#__PURE__*/React.createElement(StackWrap, Object.assign({}, a11y, {
|
|
93
|
+
space: space,
|
|
94
|
+
direction: direction,
|
|
95
|
+
tokens: stackTokens
|
|
96
|
+
}), items.map(({
|
|
97
|
+
label,
|
|
98
|
+
id = label,
|
|
99
|
+
accessibilityLabel
|
|
100
|
+
}, index) => {
|
|
101
|
+
const isSelected = currentValues.includes(id); // Pass an object of relevant component state as first argument for any passed-in press handlers
|
|
102
|
+
|
|
103
|
+
const pressHandlers = getPressHandlersWithArgs(rest, [{
|
|
104
|
+
id,
|
|
105
|
+
label,
|
|
106
|
+
currentValues
|
|
107
|
+
}]);
|
|
108
|
+
|
|
109
|
+
const handlePress = () => {
|
|
110
|
+
if (pressHandlers.onPress) pressHandlers.onPress();
|
|
111
|
+
toggleOneValue(id);
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
const itemA11y = {
|
|
115
|
+
accessibilityState: {
|
|
116
|
+
checked: isSelected
|
|
117
|
+
},
|
|
118
|
+
accessibilityRole: itemA11yRole,
|
|
119
|
+
accessibilityLabel,
|
|
120
|
+
...a11yProps.getPositionInSet(items.length, index)
|
|
121
|
+
};
|
|
122
|
+
return /*#__PURE__*/React.createElement(ButtonBase, Object.assign({
|
|
123
|
+
key: id
|
|
124
|
+
}, pressHandlers, {
|
|
125
|
+
onPress: handlePress,
|
|
126
|
+
tokens: getButtonTokens,
|
|
127
|
+
selected: isSelected,
|
|
128
|
+
inactive: inactive
|
|
129
|
+
}, itemA11y), ({
|
|
130
|
+
textStyles,
|
|
131
|
+
...buttonState
|
|
132
|
+
}) => {
|
|
133
|
+
// TODO: once Icon/IconButton designs are stable, see if this sort of styling around
|
|
134
|
+
// an icon should go in Icon itself, or possibly via an IconText token set. Related issues:
|
|
135
|
+
// - Icon: https://github.com/telus/universal-design-system/issues/327
|
|
136
|
+
// - IconButton: https://github.com/telus/universal-design-system/issues/281
|
|
137
|
+
// - Token sets: https://github.com/telus/universal-design-system/issues/782
|
|
138
|
+
const itemTokens = getItemTokens(buttonState);
|
|
139
|
+
const {
|
|
140
|
+
iconTokens,
|
|
141
|
+
iconPosition,
|
|
142
|
+
iconSpace,
|
|
143
|
+
iconWrapperStyle,
|
|
144
|
+
icon: IconComponent
|
|
145
|
+
} = selectIconTextTokens(itemTokens);
|
|
146
|
+
const iconContent = IconComponent ? /*#__PURE__*/React.createElement(View, {
|
|
147
|
+
style: iconWrapperStyle
|
|
148
|
+
}, /*#__PURE__*/React.createElement(IconComponent, {
|
|
149
|
+
tokens: iconTokens
|
|
150
|
+
})) : null;
|
|
151
|
+
const textContent = /*#__PURE__*/React.createElement(Text, {
|
|
152
|
+
style: textStyles
|
|
153
|
+
}, label);
|
|
154
|
+
return getStackedContent(iconPosition === 'left' ? [iconContent, textContent] : [textContent, iconContent], {
|
|
155
|
+
space: iconSpace,
|
|
156
|
+
direction: 'row'
|
|
157
|
+
});
|
|
158
|
+
});
|
|
159
|
+
}));
|
|
160
|
+
};
|
|
161
|
+
|
|
162
|
+
Tags.propTypes = { ...a11yProps.propTypes,
|
|
163
|
+
...pressProps.propTypes,
|
|
164
|
+
tokens: getTokensPropType('Tags'),
|
|
165
|
+
variant: variantProp.propType,
|
|
166
|
+
|
|
167
|
+
/**
|
|
168
|
+
* If provided, sets a maximum number of items a user may select at once.
|
|
169
|
+
*/
|
|
170
|
+
maxValues: PropTypes.number,
|
|
171
|
+
|
|
172
|
+
/**
|
|
173
|
+
* The options a user may select
|
|
174
|
+
*/
|
|
175
|
+
items: PropTypes.arrayOf(PropTypes.shape({
|
|
176
|
+
/**
|
|
177
|
+
* The text displayed to the user in the button, describing this option,
|
|
178
|
+
* passed to the button as its child.
|
|
179
|
+
*/
|
|
180
|
+
label: PropTypes.string.isRequired,
|
|
181
|
+
|
|
182
|
+
/**
|
|
183
|
+
* An optional accessibility label may be passed to ButtonGroup Buttons
|
|
184
|
+
* which is applied as normal for a React Native accessibilityLabel prop.
|
|
185
|
+
*/
|
|
186
|
+
accessibilityLabel: PropTypes.string,
|
|
187
|
+
|
|
188
|
+
/**
|
|
189
|
+
* An optional unique string may be provided to identify this option,
|
|
190
|
+
* which will be used in code and passed to any onChange function.
|
|
191
|
+
* If not provided, the label is used.
|
|
192
|
+
*/
|
|
193
|
+
id: PropTypes.string
|
|
194
|
+
})),
|
|
195
|
+
|
|
196
|
+
/**
|
|
197
|
+
* If provided, this function is called when the current selection is changed
|
|
198
|
+
* and is passed an array of the `id`s of all currently selected `items`.
|
|
199
|
+
*/
|
|
200
|
+
onChange: PropTypes.func,
|
|
201
|
+
|
|
202
|
+
/**
|
|
203
|
+
* If the selected item(s) in the button group are to be controlled externally by
|
|
204
|
+
* a parent component, pass an array of strings as well as an `onChange` handler.
|
|
205
|
+
* Passing an array for "values" makes the ButtonGroup a "controlled" component that
|
|
206
|
+
* expects its state to be handled via `onChange` and so doesn't handle it itself.
|
|
207
|
+
*/
|
|
208
|
+
values: PropTypes.arrayOf(PropTypes.string),
|
|
209
|
+
|
|
210
|
+
/**
|
|
211
|
+
* If `values` is not passed, making the ButtonGroup an "uncontrolled" component
|
|
212
|
+
* managing its own selected state, a default set of selections may be provided.
|
|
213
|
+
* Changing the `initialValues` does not change the user's selections.
|
|
214
|
+
*/
|
|
215
|
+
initialValues: PropTypes.arrayOf(PropTypes.string)
|
|
216
|
+
};
|
|
217
|
+
export default Tags;
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import React, { useState } from 'react';
|
|
2
|
+
import { Platform } from 'react-native';
|
|
3
|
+
import { getTokensPropType, variantProp } from '../utils';
|
|
4
|
+
import InputSupports from '../InputSupports';
|
|
5
|
+
import TextInputBase from './TextInputBase';
|
|
6
|
+
import { useThemeTokens } from '../ThemeProvider';
|
|
7
|
+
import inputSupportProps from '../InputSupports/propTypes';
|
|
8
|
+
import textInputPropTypes from './propTypes';
|
|
9
|
+
/**
|
|
10
|
+
* Use to collect long-form information such as product feedback or support queries.
|
|
11
|
+
* Due to React Native's implementation of `TextInput` it's not possible to access the current value by passing a ref.
|
|
12
|
+
* The `TextArea` height will automatically increase when new lines are added - this behavior can be limited within the theme.
|
|
13
|
+
*
|
|
14
|
+
* ## Controlled component
|
|
15
|
+
* If it is required that the state of the `TextArea` be controlled by the application or other external methods,
|
|
16
|
+
* `value` and `onChange` props must be passed to the `TextArea`.
|
|
17
|
+
* If the `TextArea` value should not be changed by user input, a `readOnly` prop must be provided.
|
|
18
|
+
*
|
|
19
|
+
* ## Uncontrolled component
|
|
20
|
+
* If it is not necessary to control the `TextArea` state, you can create one without a value prop.
|
|
21
|
+
* In this case its value can be accessed within the `onChange` callback.
|
|
22
|
+
*
|
|
23
|
+
* ## Getting feedback for entered values
|
|
24
|
+
* Use the `feedback` prop to give the user feedback regarding their input.
|
|
25
|
+
* You can affirm that the user's input was correct, or highlight errors that must be corrected, using the `validation` prop.
|
|
26
|
+
* Keep feedback text as brief as possible, should be limited to text and links.
|
|
27
|
+
*
|
|
28
|
+
* ## Supplying a hint
|
|
29
|
+
* Use the `hint` prop to succinctly clarify attributes of the expected input data, such as the expected format,
|
|
30
|
+
* or an indicator that the field is optional.
|
|
31
|
+
* It is a more usable and accessible option than the HTML `placeholder` attribute.
|
|
32
|
+
*/
|
|
33
|
+
|
|
34
|
+
function TextArea({
|
|
35
|
+
tokens,
|
|
36
|
+
variant = {},
|
|
37
|
+
...remainingProps
|
|
38
|
+
}) {
|
|
39
|
+
const themeTokens = useThemeTokens('TextArea', tokens, variant);
|
|
40
|
+
const [inputHeight, setInputHeight] = useState(); // adjust the text area's height as new lines are added to the content
|
|
41
|
+
|
|
42
|
+
const onHeightChange = ({
|
|
43
|
+
nativeEvent: {
|
|
44
|
+
contentSize: {
|
|
45
|
+
height
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}) => {
|
|
49
|
+
// on native this is happens out of the box
|
|
50
|
+
if (Platform.OS === 'web') {
|
|
51
|
+
setInputHeight(height);
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
const {
|
|
56
|
+
props: supportsProps,
|
|
57
|
+
rest
|
|
58
|
+
} = inputSupportProps.select(remainingProps);
|
|
59
|
+
const inputProps = { ...rest,
|
|
60
|
+
variant: { ...variant,
|
|
61
|
+
validation: supportsProps.validation
|
|
62
|
+
},
|
|
63
|
+
multiline: true,
|
|
64
|
+
onContentSizeChange: onHeightChange,
|
|
65
|
+
height: inputHeight,
|
|
66
|
+
tokens: themeTokens
|
|
67
|
+
};
|
|
68
|
+
return /*#__PURE__*/React.createElement(InputSupports, supportsProps, ({
|
|
69
|
+
a11yProps,
|
|
70
|
+
inputId
|
|
71
|
+
}) => /*#__PURE__*/React.createElement(TextInputBase, Object.assign({}, inputProps, a11yProps, {
|
|
72
|
+
nativeID: inputId
|
|
73
|
+
})));
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
TextArea.propTypes = { ...inputSupportProps.types,
|
|
77
|
+
...textInputPropTypes,
|
|
78
|
+
tokens: getTokensPropType('TextArea', 'TextInput'),
|
|
79
|
+
// TODO: support both TextArea and TextInput tokens
|
|
80
|
+
variant: variantProp.propType
|
|
81
|
+
};
|
|
82
|
+
export default TextArea;
|