@telus-uds/components-base 0.0.2-prerelease.4 → 0.0.2-prerelease.5
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/CHANGELOG.md +17 -0
- package/__fixtures__/testTheme.js +83 -11
- package/__tests__/Divider/Divider.test.jsx +26 -5
- package/__tests__/Feedback/Feedback.test.jsx +42 -0
- package/__tests__/Spacer/Spacer.test.jsx +63 -0
- package/__tests__/StackView/StackView.test.jsx +242 -0
- package/__tests__/StackView/StackWrap.test.jsx +47 -0
- package/__tests__/StackView/getStackedContent.test.jsx +295 -0
- package/__tests__/TextInput/TextInput.test.jsx +146 -0
- package/__tests__/utils/useUniqueId.test.js +31 -0
- package/lib/Box/Box.js +7 -2
- package/lib/Button/ButtonBase.js +6 -16
- package/lib/Button/ButtonGroup.js +13 -22
- package/lib/Divider/Divider.js +40 -2
- package/lib/Feedback/Feedback.js +110 -0
- package/lib/Feedback/index.js +2 -0
- package/lib/Icon/Icon.js +1 -1
- package/lib/InputLabel/InputLabel.js +86 -0
- package/lib/InputLabel/LabelContent.native.js +8 -0
- package/lib/InputLabel/LabelContent.web.js +17 -0
- package/lib/InputLabel/index.js +2 -0
- package/lib/Link/LinkBase.js +9 -3
- package/lib/Spacer/Spacer.js +98 -0
- package/lib/Spacer/index.js +2 -0
- package/lib/StackView/StackView.js +105 -0
- package/lib/StackView/StackWrap.js +32 -0
- package/lib/StackView/StackWrap.native.js +3 -0
- package/lib/StackView/StackWrapBox.js +85 -0
- package/lib/StackView/StackWrapGap.js +45 -0
- package/lib/StackView/common.js +30 -0
- package/lib/StackView/getStackedContent.js +111 -0
- package/lib/StackView/index.js +5 -0
- package/lib/TextInput/TextInput.js +337 -0
- package/lib/TextInput/index.js +2 -0
- package/lib/Typography/Typography.js +0 -4
- package/lib/index.js +6 -1
- package/lib/utils/input.js +3 -1
- package/lib/utils/propTypes.js +9 -1
- package/lib/utils/useUniqueId.js +12 -0
- package/package.json +2 -2
- package/release-context.json +4 -4
- package/src/Box/Box.jsx +4 -2
- package/src/Button/ButtonBase.jsx +6 -18
- package/src/Button/ButtonGroup.jsx +13 -17
- package/src/Divider/Divider.jsx +38 -3
- package/src/Feedback/Feedback.jsx +99 -0
- package/src/Feedback/index.js +3 -0
- package/src/Icon/Icon.jsx +2 -1
- package/src/InputLabel/InputLabel.jsx +99 -0
- package/src/InputLabel/LabelContent.native.jsx +6 -0
- package/src/InputLabel/LabelContent.web.jsx +13 -0
- package/src/InputLabel/index.js +3 -0
- package/src/Link/LinkBase.jsx +9 -3
- package/src/Spacer/Spacer.jsx +91 -0
- package/src/Spacer/index.js +3 -0
- package/src/StackView/StackView.jsx +103 -0
- package/src/StackView/StackWrap.jsx +33 -0
- package/src/StackView/StackWrap.native.jsx +4 -0
- package/src/StackView/StackWrapBox.jsx +82 -0
- package/src/StackView/StackWrapGap.jsx +39 -0
- package/src/StackView/common.jsx +28 -0
- package/src/StackView/getStackedContent.jsx +106 -0
- package/src/StackView/index.js +6 -0
- package/src/TextInput/TextInput.jsx +325 -0
- package/src/TextInput/index.js +3 -0
- package/src/Typography/Typography.jsx +0 -4
- package/src/index.js +6 -1
- package/src/utils/input.js +2 -1
- package/src/utils/propTypes.js +9 -0
- package/src/utils/useUniqueId.js +14 -0
- package/stories/A11yText/A11yText.stories.jsx +11 -5
- package/stories/ActivityIndicator/ActivityIndicator.stories.jsx +11 -2
- package/stories/Box/Box.stories.jsx +29 -2
- package/stories/Button/Button.stories.jsx +17 -21
- package/stories/Button/ButtonGroup.stories.jsx +2 -1
- package/stories/Button/ButtonLink.stories.jsx +6 -4
- package/stories/Card/Card.stories.jsx +13 -1
- package/stories/Divider/Divider.stories.jsx +26 -2
- package/stories/ExpandCollapse/ExpandCollapse.stories.jsx +74 -79
- package/stories/Feedback/Feedback.stories.jsx +97 -0
- package/stories/FlexGrid/01 FlexGrid.stories.jsx +20 -7
- package/stories/Icon/Icon.stories.jsx +11 -3
- package/stories/InputLabel/InputLabel.stories.jsx +37 -0
- package/stories/Link/ChevronLink.stories.jsx +20 -4
- package/stories/Link/Link.stories.jsx +24 -2
- package/stories/Link/TextButton.stories.jsx +24 -2
- package/stories/Pagination/Pagination.stories.jsx +28 -14
- package/stories/SideNav/SideNav.stories.jsx +17 -2
- package/stories/Spacer/Spacer.stories.jsx +33 -0
- package/stories/StackView/StackView.stories.jsx +65 -0
- package/stories/StackView/StackWrap.stories.jsx +52 -0
- package/stories/TextInput/TextInput.stories.jsx +103 -0
- package/stories/ToggleSwitch/ToggleSwitch.stories.jsx +16 -3
- package/stories/Typography/Typography.stories.jsx +12 -3
- package/stories/platform-supports.web.jsx +1 -1
- package/stories/supports.jsx +109 -13
|
@@ -0,0 +1,325 @@
|
|
|
1
|
+
import React, { useState } from 'react'
|
|
2
|
+
import { View, TextInput as NativeTextInput, Platform, StyleSheet } from 'react-native'
|
|
3
|
+
|
|
4
|
+
import PropTypes from 'prop-types'
|
|
5
|
+
import { useThemeTokens, applyTextStyles } from '../ThemeProvider'
|
|
6
|
+
import { getTokensPropType, useInputValue, variantProp } from '../utils'
|
|
7
|
+
import InputLabel from '../InputLabel'
|
|
8
|
+
import Feedback from '../Feedback'
|
|
9
|
+
import Box from '../Box'
|
|
10
|
+
import useUniqueId from '../utils/useUniqueId'
|
|
11
|
+
|
|
12
|
+
const selectInputStyles = (
|
|
13
|
+
{
|
|
14
|
+
backgroundColor,
|
|
15
|
+
color,
|
|
16
|
+
borderWidth,
|
|
17
|
+
borderColor,
|
|
18
|
+
borderRadius,
|
|
19
|
+
paddingTop,
|
|
20
|
+
paddingBottom,
|
|
21
|
+
paddingLeft,
|
|
22
|
+
paddingRight = 0,
|
|
23
|
+
fontName,
|
|
24
|
+
fontSize,
|
|
25
|
+
fontWeight,
|
|
26
|
+
lineHeight,
|
|
27
|
+
icon,
|
|
28
|
+
iconSize = 0
|
|
29
|
+
},
|
|
30
|
+
inactive
|
|
31
|
+
) => {
|
|
32
|
+
// Subtract border width from padding so overall input width/height doesn't
|
|
33
|
+
// jump around if the border width changes (avoiding NaN and negative padding)
|
|
34
|
+
const offsetBorder = (value) =>
|
|
35
|
+
typeof value === 'number' && typeof borderWidth === 'number'
|
|
36
|
+
? Math.max(0, value - borderWidth)
|
|
37
|
+
: value
|
|
38
|
+
|
|
39
|
+
const textStyles = applyTextStyles({ fontName, fontSize, lineHeight, fontWeight })
|
|
40
|
+
const webStyles = Platform.select({
|
|
41
|
+
web: {
|
|
42
|
+
outline: 'none',
|
|
43
|
+
cursor: inactive ? 'not-allowed' : undefined
|
|
44
|
+
}
|
|
45
|
+
})
|
|
46
|
+
|
|
47
|
+
const paddingWithIcon = iconSize + paddingRight
|
|
48
|
+
|
|
49
|
+
return {
|
|
50
|
+
backgroundColor,
|
|
51
|
+
color,
|
|
52
|
+
borderWidth,
|
|
53
|
+
borderColor,
|
|
54
|
+
borderRadius,
|
|
55
|
+
paddingLeft: offsetBorder(paddingLeft),
|
|
56
|
+
paddingRight: icon ? offsetBorder(paddingWithIcon) : offsetBorder(paddingRight),
|
|
57
|
+
paddingTop: offsetBorder(paddingTop),
|
|
58
|
+
paddingBottom: offsetBorder(paddingBottom),
|
|
59
|
+
...textStyles,
|
|
60
|
+
...webStyles
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const selectOuterBorderStyles = ({
|
|
65
|
+
outerBackgroundColor,
|
|
66
|
+
outerBorderWidth = 0,
|
|
67
|
+
outerBorderColor,
|
|
68
|
+
outerBorderRadius = 0
|
|
69
|
+
}) => {
|
|
70
|
+
// Use negative margins so that the outer border doesn't expand the input's bounding box
|
|
71
|
+
const margin = -1 * outerBorderWidth
|
|
72
|
+
|
|
73
|
+
// Account for the border width since we style it as an outline
|
|
74
|
+
const borderRadius = outerBorderRadius + outerBorderWidth
|
|
75
|
+
|
|
76
|
+
return {
|
|
77
|
+
background: outerBackgroundColor,
|
|
78
|
+
borderWidth: outerBorderWidth,
|
|
79
|
+
borderColor: outerBorderColor,
|
|
80
|
+
borderRadius,
|
|
81
|
+
marginTop: margin,
|
|
82
|
+
marginBottom: margin,
|
|
83
|
+
marginLeft: margin,
|
|
84
|
+
marginRight: margin
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
const selectIconTokens = ({ iconSize, iconColor }) => ({
|
|
89
|
+
size: iconSize,
|
|
90
|
+
color: iconColor
|
|
91
|
+
})
|
|
92
|
+
|
|
93
|
+
const joinDefined = (array) => array.filter((item) => item !== undefined).join(' ')
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* A basic text input component. Use in forms or individually to receive user's input.
|
|
97
|
+
* Due to React Native's implementation of `TextInput` it's not possible to access the current value by passing a ref.
|
|
98
|
+
*
|
|
99
|
+
* ## Controlled component
|
|
100
|
+
* If it is required that the state of the `TextInput` be controlled by the application or other external methods,
|
|
101
|
+
* `value` and `onChange` props must be passed to the `TextInput`.
|
|
102
|
+
* If the `TextInput` value should not be changed by user input, a `readOnly` prop must be provided.
|
|
103
|
+
*
|
|
104
|
+
* ## Uncontrolled component
|
|
105
|
+
* If it is not necessary to control the `TextInput` state, you can create one without a value prop.
|
|
106
|
+
* In this case its value can be accessed within the `onChange` callback.
|
|
107
|
+
*
|
|
108
|
+
* NOTE: In order to support more advanced usages all additional props will be passed down to the React Native's
|
|
109
|
+
* `TextInput` component. See <a href="https://reactnative.dev/docs/textinput" target="_blank">React Native documentation</a> for
|
|
110
|
+
* supported props and <a href="https://reactnative.dev/docs/textinput" target="_blank">React Native Web documentation</a> for
|
|
111
|
+
* their implementation on the web.
|
|
112
|
+
*/
|
|
113
|
+
function TextInput({
|
|
114
|
+
value,
|
|
115
|
+
initialValue,
|
|
116
|
+
label,
|
|
117
|
+
hint,
|
|
118
|
+
hintPosition = 'inline',
|
|
119
|
+
feedback,
|
|
120
|
+
tooltip,
|
|
121
|
+
validation,
|
|
122
|
+
inactive,
|
|
123
|
+
readOnly,
|
|
124
|
+
onChange,
|
|
125
|
+
onChangeText,
|
|
126
|
+
onFocus,
|
|
127
|
+
onBlur,
|
|
128
|
+
onMouseOver,
|
|
129
|
+
onMouseOut,
|
|
130
|
+
tokens,
|
|
131
|
+
variant = {},
|
|
132
|
+
...remainingProps
|
|
133
|
+
}) {
|
|
134
|
+
const inputId = useUniqueId('text-input')
|
|
135
|
+
const hintId = useUniqueId('text-input-hint')
|
|
136
|
+
const feedbackId = useUniqueId('text-input-feedback')
|
|
137
|
+
|
|
138
|
+
const [isFocused, setIsFocused] = useState(false)
|
|
139
|
+
const handleFocus = (event) => {
|
|
140
|
+
setIsFocused(true)
|
|
141
|
+
if (typeof onFocus === 'function') onFocus(event)
|
|
142
|
+
}
|
|
143
|
+
const handleBlur = (event) => {
|
|
144
|
+
setIsFocused(false)
|
|
145
|
+
if (typeof onBlur === 'function') onBlur(event)
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
const [isHovered, setIsHovered] = useState(false)
|
|
149
|
+
const handleMouseOver = (event) => {
|
|
150
|
+
setIsHovered(true)
|
|
151
|
+
if (typeof onMouseOver === 'function') onMouseOver(event)
|
|
152
|
+
}
|
|
153
|
+
const handleMouseOut = (event) => {
|
|
154
|
+
setIsHovered(false)
|
|
155
|
+
if (typeof onMouseOut === 'function') onMouseOut(event)
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
const { currentValue, setValue, isControlled } = useInputValue({
|
|
159
|
+
value,
|
|
160
|
+
initialValue,
|
|
161
|
+
onChange,
|
|
162
|
+
readOnly
|
|
163
|
+
})
|
|
164
|
+
|
|
165
|
+
const handleChangeText = (text) => {
|
|
166
|
+
setValue(text)
|
|
167
|
+
if (typeof onChangeText === 'function') onChangeText(text)
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
const states = { focus: isFocused, hover: isHovered, inactive }
|
|
171
|
+
|
|
172
|
+
const themeTokens = useThemeTokens('TextInput', tokens, { ...variant, validation }, states)
|
|
173
|
+
|
|
174
|
+
const { icon: IconComponent } = themeTokens
|
|
175
|
+
|
|
176
|
+
const hasValidationError = validation === 'error'
|
|
177
|
+
|
|
178
|
+
const inputProps = {
|
|
179
|
+
...remainingProps,
|
|
180
|
+
editable: !inactive,
|
|
181
|
+
onFocus: handleFocus,
|
|
182
|
+
onBlur: handleBlur,
|
|
183
|
+
onMouseOver: handleMouseOver,
|
|
184
|
+
onMouseOut: handleMouseOut,
|
|
185
|
+
onChangeText: handleChangeText,
|
|
186
|
+
accessibilityLabel: label,
|
|
187
|
+
accessibilityHint: joinDefined([!hasValidationError && feedback, hint]), // native only -> replaced with describedBy on web
|
|
188
|
+
accessibilityDescribedBy: joinDefined([
|
|
189
|
+
!hasValidationError && feedback && feedbackId, // feedback receives a11yRole=alert, so there's no need to include it here
|
|
190
|
+
hint && hintId
|
|
191
|
+
]), // introduced in RNW 0.15.0
|
|
192
|
+
accessibilityInvalid: hasValidationError, // introduced in RNW 0.15.0
|
|
193
|
+
nativeID: inputId,
|
|
194
|
+
defaultValue: initialValue,
|
|
195
|
+
// currentValue is being updated even if the input is not controlled, passing it down to the
|
|
196
|
+
// Input could lead to changing its state from uncontrolled to controlled
|
|
197
|
+
value: isControlled ? currentValue : undefined
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
// TODO: use Stack instead of the Boxes
|
|
201
|
+
|
|
202
|
+
const feedbackVariant = {}
|
|
203
|
+
|
|
204
|
+
if (hasValidationError) {
|
|
205
|
+
feedbackVariant.state = 'error'
|
|
206
|
+
} else if (validation === 'success') {
|
|
207
|
+
feedbackVariant.state = 'success'
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
return (
|
|
211
|
+
<View>
|
|
212
|
+
{label && (
|
|
213
|
+
<Box bottom={1}>
|
|
214
|
+
<InputLabel
|
|
215
|
+
label={label}
|
|
216
|
+
hint={hint}
|
|
217
|
+
hintPosition={hintPosition}
|
|
218
|
+
hintId={hintId}
|
|
219
|
+
tooltip={tooltip}
|
|
220
|
+
forId={inputId}
|
|
221
|
+
/>
|
|
222
|
+
</Box>
|
|
223
|
+
)}
|
|
224
|
+
<View style={selectOuterBorderStyles(themeTokens)}>
|
|
225
|
+
<NativeTextInput style={selectInputStyles(themeTokens, inactive)} {...inputProps} />
|
|
226
|
+
{IconComponent && (
|
|
227
|
+
<View
|
|
228
|
+
pointerEvents="none" // avoid hijacking input press events
|
|
229
|
+
style={[staticStyles.iconContainer, selectIconContainerStyles(themeTokens)]}
|
|
230
|
+
>
|
|
231
|
+
<IconComponent tokens={selectIconTokens(themeTokens)} />
|
|
232
|
+
</View>
|
|
233
|
+
)}
|
|
234
|
+
</View>
|
|
235
|
+
{feedback && (
|
|
236
|
+
<Box top={1}>
|
|
237
|
+
<Feedback
|
|
238
|
+
title={feedback}
|
|
239
|
+
variant={feedbackVariant}
|
|
240
|
+
accessibilityRole={hasValidationError ? 'alert' : undefined}
|
|
241
|
+
/>
|
|
242
|
+
</Box>
|
|
243
|
+
)}
|
|
244
|
+
</View>
|
|
245
|
+
)
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
const selectIconContainerStyles = ({ paddingRight }) => ({
|
|
249
|
+
paddingRight
|
|
250
|
+
})
|
|
251
|
+
|
|
252
|
+
TextInput.propTypes = {
|
|
253
|
+
/**
|
|
254
|
+
* The input label.
|
|
255
|
+
*/
|
|
256
|
+
label: PropTypes.string,
|
|
257
|
+
/**
|
|
258
|
+
* If the `TextInput's` state is to be controlled by a parent component, use this prop
|
|
259
|
+
* together with the `onChange` to pass down and update the lifted state.
|
|
260
|
+
*/
|
|
261
|
+
value: PropTypes.string,
|
|
262
|
+
/**
|
|
263
|
+
* Use this to set the initial value of an uncontrolled `TextInput`.
|
|
264
|
+
* Updating `initialValue` will **not** update the actual value.
|
|
265
|
+
*/
|
|
266
|
+
initialValue: PropTypes.string,
|
|
267
|
+
/**
|
|
268
|
+
* A short description of the expected input.
|
|
269
|
+
*/
|
|
270
|
+
hint: PropTypes.string,
|
|
271
|
+
/**
|
|
272
|
+
* Position of the hint relative to label.
|
|
273
|
+
*/
|
|
274
|
+
hintPosition: PropTypes.oneOf(['inline', 'below']),
|
|
275
|
+
/**
|
|
276
|
+
* A detailed description of validation error/success or additional instructions.
|
|
277
|
+
* Visual variant is determined based on the `validation` prop.
|
|
278
|
+
*/
|
|
279
|
+
feedback: PropTypes.string,
|
|
280
|
+
/**
|
|
281
|
+
* Content of an optional `Tooltip`. If set, a tooltip button will be shown next to the label.
|
|
282
|
+
*/
|
|
283
|
+
tooltip: PropTypes.string,
|
|
284
|
+
/**
|
|
285
|
+
* Use to visually mark an input as valid or invalid.
|
|
286
|
+
*/
|
|
287
|
+
validation: PropTypes.oneOf(['error', 'success']),
|
|
288
|
+
/**
|
|
289
|
+
* Disables all user interactions with the input.
|
|
290
|
+
*/
|
|
291
|
+
inactive: PropTypes.bool,
|
|
292
|
+
/**
|
|
293
|
+
* Makes it impossible to change the input's value.
|
|
294
|
+
*/
|
|
295
|
+
readOnly: PropTypes.bool,
|
|
296
|
+
/**
|
|
297
|
+
* Use to react upon input's value changes. Required when the `value` prop is set.
|
|
298
|
+
* Will receive the input's value as an argument.
|
|
299
|
+
*/
|
|
300
|
+
onChange: PropTypes.func,
|
|
301
|
+
/** @ignore */
|
|
302
|
+
onChangeText: PropTypes.func,
|
|
303
|
+
/** @ignore */
|
|
304
|
+
onFocus: PropTypes.func,
|
|
305
|
+
/** @ignore */
|
|
306
|
+
onBlur: PropTypes.func,
|
|
307
|
+
/** @ignore */
|
|
308
|
+
onMouseOver: PropTypes.func,
|
|
309
|
+
/** @ignore */
|
|
310
|
+
onMouseOut: PropTypes.func,
|
|
311
|
+
tokens: getTokensPropType('TextInput'),
|
|
312
|
+
variant: variantProp.propType
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
export default TextInput
|
|
316
|
+
|
|
317
|
+
const staticStyles = StyleSheet.create({
|
|
318
|
+
iconContainer: {
|
|
319
|
+
position: 'absolute',
|
|
320
|
+
right: 0,
|
|
321
|
+
top: 0,
|
|
322
|
+
bottom: 0,
|
|
323
|
+
justifyContent: 'center'
|
|
324
|
+
}
|
|
325
|
+
})
|
|
@@ -33,8 +33,6 @@ const selectTextStyles = ({
|
|
|
33
33
|
color,
|
|
34
34
|
lineHeight,
|
|
35
35
|
fontName,
|
|
36
|
-
marginTop,
|
|
37
|
-
marginBottom,
|
|
38
36
|
textAlign,
|
|
39
37
|
textTransform
|
|
40
38
|
}) =>
|
|
@@ -44,8 +42,6 @@ const selectTextStyles = ({
|
|
|
44
42
|
color,
|
|
45
43
|
lineHeight,
|
|
46
44
|
fontName,
|
|
47
|
-
marginTop,
|
|
48
|
-
marginBottom,
|
|
49
45
|
textAlign,
|
|
50
46
|
textTransform
|
|
51
47
|
})
|
package/src/index.js
CHANGED
|
@@ -4,18 +4,23 @@ export * from './Button'
|
|
|
4
4
|
export { default as Card } from './Card'
|
|
5
5
|
export { default as Divider } from './Divider'
|
|
6
6
|
export { default as ExpandCollapse, Accordion } from './ExpandCollapse'
|
|
7
|
+
export { default as Feedback } from './Feedback'
|
|
7
8
|
export { default as FlexGrid } from './FlexGrid'
|
|
8
9
|
export { default as Icon } from './Icon'
|
|
9
10
|
export * from './Icon'
|
|
10
11
|
export * from './Link'
|
|
11
12
|
export { default as Pagination } from './Pagination'
|
|
12
13
|
export { default as SideNav } from './SideNav'
|
|
14
|
+
export { default as Spacer } from './Spacer'
|
|
15
|
+
export { default as StackView } from './StackView'
|
|
16
|
+
export * from './StackView'
|
|
17
|
+
export { default as TextInput } from './TextInput'
|
|
13
18
|
export { default as ToggleSwitch } from './ToggleSwitch'
|
|
14
19
|
export { default as Typography } from './Typography'
|
|
15
20
|
|
|
16
21
|
export { default as A11yInfoProvider, useA11yInfo } from './A11yInfoProvider'
|
|
17
22
|
export { default as BaseProvider } from './BaseProvider'
|
|
18
23
|
export { default as ViewportProvider, useViewport } from './ViewportProvider'
|
|
19
|
-
export { default as ThemeProvider, useTheme, useSetTheme } from './ThemeProvider'
|
|
24
|
+
export { default as ThemeProvider, useTheme, useSetTheme, useThemeTokens } from './ThemeProvider'
|
|
20
25
|
|
|
21
26
|
export * from './utils'
|
package/src/utils/input.js
CHANGED
|
@@ -55,6 +55,7 @@ Consumers of this hook must be one of:
|
|
|
55
55
|
* currentValue: any
|
|
56
56
|
* setValue: (value: any) => void
|
|
57
57
|
* resetValue: () => void
|
|
58
|
+
* isControlled: bool
|
|
58
59
|
* }}
|
|
59
60
|
*/
|
|
60
61
|
|
|
@@ -81,7 +82,7 @@ export const useInputValue = (props = {}, hookName = 'useInputValue') => {
|
|
|
81
82
|
)
|
|
82
83
|
const resetValue = useCallback(() => setValue(initializedValue), [initializedValue, setValue])
|
|
83
84
|
|
|
84
|
-
return { currentValue, setValue, resetValue }
|
|
85
|
+
return { currentValue, setValue, resetValue, isControlled }
|
|
85
86
|
}
|
|
86
87
|
|
|
87
88
|
/**
|
package/src/utils/propTypes.js
CHANGED
|
@@ -427,3 +427,12 @@ export const componentPropType = (passedName, checkDisplayName = false) => {
|
|
|
427
427
|
}
|
|
428
428
|
|
|
429
429
|
export const copyPropTypes = PropTypes.oneOf(['en', 'fr'])
|
|
430
|
+
|
|
431
|
+
export const paddingProp = {
|
|
432
|
+
propType: PropTypes.shape({
|
|
433
|
+
paddingBottom: PropTypes.number,
|
|
434
|
+
paddingLeft: PropTypes.number,
|
|
435
|
+
paddingRight: PropTypes.number,
|
|
436
|
+
paddingTop: PropTypes.number
|
|
437
|
+
})
|
|
438
|
+
}
|
|
@@ -4,6 +4,7 @@ import { StyleSheet, Text, View } from 'react-native'
|
|
|
4
4
|
|
|
5
5
|
import A11yText from '../../lib/A11yText'
|
|
6
6
|
import { Button, Typography } from '../../lib'
|
|
7
|
+
import { EachParentType, parentTypesParams } from '../supports'
|
|
7
8
|
|
|
8
9
|
const defaultArgs = {
|
|
9
10
|
text: 'This text is for screen readers,',
|
|
@@ -31,6 +32,10 @@ const Template = (args) => (
|
|
|
31
32
|
</>
|
|
32
33
|
)
|
|
33
34
|
|
|
35
|
+
export const Default = (args) => <A11yText {...args} />
|
|
36
|
+
Default.storyName = 'A11yText'
|
|
37
|
+
Default.args = defaultArgs
|
|
38
|
+
|
|
34
39
|
export const A11yTextInText = Template.bind({})
|
|
35
40
|
A11yTextInText.args = defaultArgs
|
|
36
41
|
|
|
@@ -50,12 +55,13 @@ export const A11yTextInButton = (args) => (
|
|
|
50
55
|
)
|
|
51
56
|
A11yTextInButton.args = defaultArgs
|
|
52
57
|
|
|
53
|
-
export const
|
|
54
|
-
<
|
|
55
|
-
<Template {...args} />
|
|
56
|
-
</
|
|
58
|
+
export const ParentTypes = (args) => (
|
|
59
|
+
<EachParentType {...args}>
|
|
60
|
+
{({ label }) => <Template {...args} key={label} text={label} />}
|
|
61
|
+
</EachParentType>
|
|
57
62
|
)
|
|
58
|
-
|
|
63
|
+
ParentTypes.args = defaultArgs
|
|
64
|
+
ParentTypes.parameters = parentTypesParams
|
|
59
65
|
|
|
60
66
|
const styles = StyleSheet.create({
|
|
61
67
|
// Use borders so any hairline gaps created by A11yText are visible
|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
+
/* eslint-disable react/no-multi-comp */
|
|
1
2
|
import React from 'react'
|
|
2
3
|
import { ActivityIndicator } from '../../lib'
|
|
4
|
+
import { EachParentType, parentTypesParams } from '../supports'
|
|
3
5
|
|
|
4
6
|
export default {
|
|
5
7
|
title: 'Base/ActivityIndicator',
|
|
@@ -9,5 +11,12 @@ export default {
|
|
|
9
11
|
}
|
|
10
12
|
}
|
|
11
13
|
|
|
12
|
-
export const
|
|
13
|
-
|
|
14
|
+
export const Default = (args) => <ActivityIndicator {...args} />
|
|
15
|
+
Default.storyName = 'ActivityIndicator'
|
|
16
|
+
|
|
17
|
+
export const ParentTypes = (args) => (
|
|
18
|
+
<EachParentType {...args}>
|
|
19
|
+
{({ label }) => <ActivityIndicator {...args} label={label} />}
|
|
20
|
+
</EachParentType>
|
|
21
|
+
)
|
|
22
|
+
ParentTypes.parameters = parentTypesParams
|
|
@@ -2,8 +2,14 @@
|
|
|
2
2
|
import React from 'react'
|
|
3
3
|
|
|
4
4
|
import { View, StyleSheet } from 'react-native'
|
|
5
|
-
import { Box } from '../../lib'
|
|
6
|
-
import {
|
|
5
|
+
import { Box, Typography } from '../../lib'
|
|
6
|
+
import {
|
|
7
|
+
spacingObjectArg,
|
|
8
|
+
Container,
|
|
9
|
+
Placeholder,
|
|
10
|
+
EachParentType,
|
|
11
|
+
parentTypesParams
|
|
12
|
+
} from '../supports'
|
|
7
13
|
|
|
8
14
|
export default {
|
|
9
15
|
title: 'Base/Box',
|
|
@@ -70,6 +76,13 @@ const ScrollTemplate = (args) => (
|
|
|
70
76
|
const styles = StyleSheet.create({
|
|
71
77
|
fixedHeight: { height: 200, overflow: 'hidden' }
|
|
72
78
|
})
|
|
79
|
+
|
|
80
|
+
export const Default = (args) => <Box {...args} />
|
|
81
|
+
Default.storyName = 'Box'
|
|
82
|
+
Default.args = { children: <Typography>Box</Typography> }
|
|
83
|
+
// By default the JSX object is shown as a huge human-unreadable JSON tree control; turn it off
|
|
84
|
+
Default.argTypes = { children: { control: { disable: true } } }
|
|
85
|
+
|
|
73
86
|
export const Top = Template.bind({})
|
|
74
87
|
Top.args = {
|
|
75
88
|
top: spacingObjectArg
|
|
@@ -114,3 +127,17 @@ export const NoScroll = ScrollTemplate.bind({})
|
|
|
114
127
|
NoScroll.args = {
|
|
115
128
|
scroll: false
|
|
116
129
|
}
|
|
130
|
+
|
|
131
|
+
export const ParentTypes = (args) => (
|
|
132
|
+
<EachParentType componentThemeName="Box" {...args}>
|
|
133
|
+
{({ label, variant }) => (
|
|
134
|
+
<Container key={label} margin={0} padding={0} borderWidth={1} dark>
|
|
135
|
+
<Box {...args} variant={variant}>
|
|
136
|
+
<Placeholder>{label}</Placeholder>
|
|
137
|
+
</Box>
|
|
138
|
+
</Container>
|
|
139
|
+
)}
|
|
140
|
+
</EachParentType>
|
|
141
|
+
)
|
|
142
|
+
ParentTypes.args = { space: 2 }
|
|
143
|
+
ParentTypes.parameters = parentTypesParams
|
|
@@ -1,9 +1,11 @@
|
|
|
1
|
+
/* eslint-disable react/no-multi-comp */
|
|
1
2
|
import React from 'react'
|
|
2
|
-
import { Button
|
|
3
|
-
import { Container, useVariants,
|
|
3
|
+
import { Button, useTheme } from '../../lib'
|
|
4
|
+
import { Container, useVariants, EachParentType, parentTypesParams } from '../supports'
|
|
4
5
|
import { getComponentTheme } from '../../lib/ThemeProvider/utils'
|
|
5
6
|
|
|
6
|
-
export const
|
|
7
|
+
export const Default = (args) => <Button {...args} />
|
|
8
|
+
Default.storyName = 'Button'
|
|
7
9
|
|
|
8
10
|
const defaultLabel = "I'm a button"
|
|
9
11
|
|
|
@@ -14,7 +16,8 @@ export default {
|
|
|
14
16
|
// eslint-disable-next-line no-console
|
|
15
17
|
onPress: () => console.log('Button pressed'),
|
|
16
18
|
children: defaultLabel,
|
|
17
|
-
variant: {} // @TODO work out why this isn't coming from jsdoc
|
|
19
|
+
variant: {}, // @TODO work out why this isn't coming from jsdoc
|
|
20
|
+
tokens: {}
|
|
18
21
|
}
|
|
19
22
|
}
|
|
20
23
|
|
|
@@ -52,20 +55,13 @@ LongLabelButtonVariants.args = {
|
|
|
52
55
|
children: 'This button has a label that is much longer than is considered advisable'
|
|
53
56
|
}
|
|
54
57
|
|
|
55
|
-
export const
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
</Button>
|
|
66
|
-
)
|
|
67
|
-
})}
|
|
68
|
-
</ParentType>
|
|
69
|
-
</Container>
|
|
70
|
-
))
|
|
71
|
-
}
|
|
58
|
+
export const ParentTypes = (args) => (
|
|
59
|
+
<EachParentType componentThemeName="Button" {...args}>
|
|
60
|
+
{({ label, variant }) => (
|
|
61
|
+
<Button {...args} key={label} variant={variant}>
|
|
62
|
+
{label}
|
|
63
|
+
</Button>
|
|
64
|
+
)}
|
|
65
|
+
</EachParentType>
|
|
66
|
+
)
|
|
67
|
+
ParentTypes.parameters = parentTypesParams
|
|
@@ -59,7 +59,8 @@ const ControlledTemplate = ({ values, ...args }) => {
|
|
|
59
59
|
|
|
60
60
|
ControlledTemplate.propTypes = ButtonGroup.propTypes
|
|
61
61
|
|
|
62
|
-
export const
|
|
62
|
+
export const Default = UncontrolledTemplate.bind({})
|
|
63
|
+
Default.storyName = 'ButtonGroup'
|
|
63
64
|
|
|
64
65
|
export const ButtonGroupMaxThree = UncontrolledTemplate.bind({})
|
|
65
66
|
ButtonGroupMaxThree.args = { maxValues: 3 }
|
|
@@ -6,7 +6,7 @@ export default {
|
|
|
6
6
|
title: 'Base/ButtonLink',
|
|
7
7
|
component: ButtonLink,
|
|
8
8
|
args: {
|
|
9
|
-
|
|
9
|
+
children: "I'm a button link",
|
|
10
10
|
href: 'https://telus.com',
|
|
11
11
|
target: '_blank',
|
|
12
12
|
rel: 'nofollow'
|
|
@@ -18,11 +18,13 @@ const Template = (args) => {
|
|
|
18
18
|
return variants.map(([key, value, label]) => (
|
|
19
19
|
<Container key={`${key}:${value}`} dark={key === 'inverse'}>
|
|
20
20
|
<ButtonLink {...args} href="https://telus.com" variant={{ [key]: value }}>
|
|
21
|
-
{args.label || `
|
|
21
|
+
{args.label || `ButtonLink ${label}`}
|
|
22
22
|
</ButtonLink>
|
|
23
23
|
</Container>
|
|
24
24
|
))
|
|
25
25
|
}
|
|
26
26
|
|
|
27
|
-
export const
|
|
28
|
-
|
|
27
|
+
export const Default = (args) => <ButtonLink {...args} />
|
|
28
|
+
Default.storyName = 'ButtonLink'
|
|
29
|
+
|
|
30
|
+
export const Variants = Template.bind({})
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
+
/* eslint-disable react/no-multi-comp */
|
|
1
2
|
import React from 'react'
|
|
2
3
|
import { StyleSheet, Text, View } from 'react-native'
|
|
3
4
|
|
|
4
5
|
import { Card } from '../../lib'
|
|
5
|
-
import { Container, useVariants } from '../supports'
|
|
6
|
+
import { Container, useVariants, EachParentType, parentTypesParams } from '../supports'
|
|
6
7
|
|
|
7
8
|
export default {
|
|
8
9
|
title: 'Base/Card',
|
|
@@ -48,3 +49,14 @@ export const CardVariants = (args) => {
|
|
|
48
49
|
|
|
49
50
|
return cardVariants
|
|
50
51
|
}
|
|
52
|
+
|
|
53
|
+
export const ParentTypes = (args) => (
|
|
54
|
+
<EachParentType componentThemeName="Card" {...args}>
|
|
55
|
+
{({ label, variant }) => (
|
|
56
|
+
<Card {...args} variant={variant}>
|
|
57
|
+
<Text>{label}</Text>
|
|
58
|
+
</Card>
|
|
59
|
+
)}
|
|
60
|
+
</EachParentType>
|
|
61
|
+
)
|
|
62
|
+
ParentTypes.parameters = parentTypesParams
|