@telus-uds/components-base 1.64.0 → 1.65.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.
- package/CHANGELOG.md +12 -2
- package/lib/Checkbox/CheckboxButton.js +200 -0
- package/lib/CheckboxCard/CheckboxCard.js +225 -0
- package/lib/CheckboxCard/index.js +13 -0
- package/lib/StackView/StackView.js +4 -1
- package/lib/Tabs/Tabs.js +15 -0
- package/lib/index.js +9 -0
- package/lib-module/Checkbox/CheckboxButton.js +174 -0
- package/lib-module/CheckboxCard/CheckboxCard.js +200 -0
- package/lib-module/CheckboxCard/index.js +2 -0
- package/lib-module/StackView/StackView.js +4 -1
- package/lib-module/Tabs/Tabs.js +14 -0
- package/lib-module/index.js +1 -0
- package/package.json +2 -2
- package/src/Checkbox/CheckboxButton.jsx +180 -0
- package/src/CheckboxCard/CheckboxCard.jsx +190 -0
- package/src/CheckboxCard/index.js +3 -0
- package/src/StackView/StackView.jsx +2 -1
- package/src/Tabs/Tabs.jsx +14 -1
- package/src/index.js +1 -0
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
import React, { forwardRef } from 'react'
|
|
2
|
+
import PropTypes from 'prop-types'
|
|
3
|
+
import { StyleSheet, Text, View } from 'react-native'
|
|
4
|
+
|
|
5
|
+
import { applyTextStyles, useTheme, useThemeTokensCallback } from '../ThemeProvider'
|
|
6
|
+
import {
|
|
7
|
+
a11yProps,
|
|
8
|
+
focusHandlerProps,
|
|
9
|
+
getTokensPropType,
|
|
10
|
+
selectSystemProps,
|
|
11
|
+
selectTokens,
|
|
12
|
+
useInputValue,
|
|
13
|
+
useUniqueId,
|
|
14
|
+
variantProp,
|
|
15
|
+
viewProps
|
|
16
|
+
} from '../utils'
|
|
17
|
+
import { PressableCardBase, selectPressableCardTokens } from '../Card'
|
|
18
|
+
import StackView from '../StackView'
|
|
19
|
+
import CheckboxButton, { selectCheckboxTokens } from '../Checkbox/CheckboxButton'
|
|
20
|
+
|
|
21
|
+
const [selectProps, selectedSystemPropTypes] = selectSystemProps([
|
|
22
|
+
a11yProps,
|
|
23
|
+
focusHandlerProps,
|
|
24
|
+
viewProps
|
|
25
|
+
])
|
|
26
|
+
|
|
27
|
+
const CheckboxCard = forwardRef(
|
|
28
|
+
(
|
|
29
|
+
{
|
|
30
|
+
tokens,
|
|
31
|
+
variant,
|
|
32
|
+
title,
|
|
33
|
+
children,
|
|
34
|
+
inactive,
|
|
35
|
+
defaultChecked,
|
|
36
|
+
checked,
|
|
37
|
+
name: inputName,
|
|
38
|
+
value,
|
|
39
|
+
id,
|
|
40
|
+
iconId,
|
|
41
|
+
onChange,
|
|
42
|
+
...rest
|
|
43
|
+
},
|
|
44
|
+
ref
|
|
45
|
+
) => {
|
|
46
|
+
const {
|
|
47
|
+
currentValue: isChecked,
|
|
48
|
+
setValue: setIsChecked,
|
|
49
|
+
isControlled
|
|
50
|
+
} = useInputValue({
|
|
51
|
+
value: checked,
|
|
52
|
+
initialValue: defaultChecked,
|
|
53
|
+
onChange
|
|
54
|
+
})
|
|
55
|
+
|
|
56
|
+
const handleChange = (event) => {
|
|
57
|
+
if (!inactive) {
|
|
58
|
+
setIsChecked(!isChecked, event)
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
const uniqueId = useUniqueId('CheckboxCard')
|
|
62
|
+
const inputId = id ?? uniqueId
|
|
63
|
+
|
|
64
|
+
const uniqueIconId = useUniqueId('CheckboxIcon')
|
|
65
|
+
const iconCheckboxId = iconId ?? uniqueIconId
|
|
66
|
+
|
|
67
|
+
const getTokens = useThemeTokensCallback('CheckboxCard', tokens, variant)
|
|
68
|
+
const getCardTokens = (cardState) => selectPressableCardTokens(getTokens(cardState))
|
|
69
|
+
const { themeOptions } = useTheme()
|
|
70
|
+
|
|
71
|
+
const selectedProps = selectProps({
|
|
72
|
+
accessibilityRole: 'checkbox',
|
|
73
|
+
accessibilityState: { checked: isChecked, disabled: inactive },
|
|
74
|
+
...rest
|
|
75
|
+
})
|
|
76
|
+
|
|
77
|
+
return (
|
|
78
|
+
<PressableCardBase
|
|
79
|
+
ref={ref}
|
|
80
|
+
inactive={inactive}
|
|
81
|
+
checked={isChecked}
|
|
82
|
+
tokens={getCardTokens}
|
|
83
|
+
onPress={handleChange}
|
|
84
|
+
{...selectedProps}
|
|
85
|
+
>
|
|
86
|
+
{(cardState) => {
|
|
87
|
+
const { checkboxSpace, contentSpace, ...themeTokens } = getTokens(cardState)
|
|
88
|
+
const checkboxTokens = selectCheckboxTokens(themeTokens, 'checkbox')
|
|
89
|
+
const titleTokens = selectTokens('Typography', themeTokens)
|
|
90
|
+
const textStyle = applyTextStyles({ ...titleTokens, themeOptions })
|
|
91
|
+
return (
|
|
92
|
+
<StackView direction="row" space={checkboxSpace}>
|
|
93
|
+
<View style={[staticStyles.alignWithText, { height: textStyle.lineHeight }]}>
|
|
94
|
+
<CheckboxButton
|
|
95
|
+
tokens={checkboxTokens}
|
|
96
|
+
isControlled={isControlled}
|
|
97
|
+
isChecked={isChecked}
|
|
98
|
+
inactive={inactive}
|
|
99
|
+
defaultChecked={defaultChecked}
|
|
100
|
+
inputId={inputId}
|
|
101
|
+
iconId={iconCheckboxId}
|
|
102
|
+
handleChange={handleChange}
|
|
103
|
+
name={inputName}
|
|
104
|
+
value={value}
|
|
105
|
+
/>
|
|
106
|
+
</View>
|
|
107
|
+
<StackView direction="column" space={contentSpace} tokens={{ flexShrink: 1 }}>
|
|
108
|
+
{title ? <Text style={textStyle}>{title}</Text> : null}
|
|
109
|
+
{typeof children === 'function' ? children(cardState, textStyle) : children}
|
|
110
|
+
</StackView>
|
|
111
|
+
</StackView>
|
|
112
|
+
)
|
|
113
|
+
}}
|
|
114
|
+
</PressableCardBase>
|
|
115
|
+
)
|
|
116
|
+
}
|
|
117
|
+
)
|
|
118
|
+
CheckboxCard.displayName = 'CheckboxCard'
|
|
119
|
+
|
|
120
|
+
CheckboxCard.propTypes = {
|
|
121
|
+
...selectedSystemPropTypes,
|
|
122
|
+
/**
|
|
123
|
+
* Content to be displayed at the top of the card alongside the checkbox
|
|
124
|
+
*/
|
|
125
|
+
title: PropTypes.string,
|
|
126
|
+
/**
|
|
127
|
+
* Additional content to be displayed below the checkbox.
|
|
128
|
+
*/
|
|
129
|
+
children: PropTypes.oneOfType([PropTypes.node, PropTypes.func]),
|
|
130
|
+
/**
|
|
131
|
+
* Use `checked` for controlled checkbox. For uncontrolled checkbox, use the `defaultChecked` prop.
|
|
132
|
+
*/
|
|
133
|
+
checked: PropTypes.bool,
|
|
134
|
+
/**
|
|
135
|
+
* Use `defaultChecked` to provide the initial value for an uncontrolled checkbox.
|
|
136
|
+
*/
|
|
137
|
+
defaultChecked: PropTypes.bool,
|
|
138
|
+
/**
|
|
139
|
+
* An optional checkboxdescription.
|
|
140
|
+
*/
|
|
141
|
+
description: PropTypes.string,
|
|
142
|
+
/**
|
|
143
|
+
* Checkbox card ID.
|
|
144
|
+
*/
|
|
145
|
+
id: PropTypes.string,
|
|
146
|
+
/**
|
|
147
|
+
* Checkbox icon ID.
|
|
148
|
+
*/
|
|
149
|
+
iconId: PropTypes.string,
|
|
150
|
+
/**
|
|
151
|
+
* Whether the corresponding input is disabled or active.
|
|
152
|
+
*/
|
|
153
|
+
inactive: PropTypes.bool,
|
|
154
|
+
/**
|
|
155
|
+
* The label.
|
|
156
|
+
*/
|
|
157
|
+
label: PropTypes.string,
|
|
158
|
+
/**
|
|
159
|
+
* Associate this checkbox card with a group (set as the name attribute).
|
|
160
|
+
*/
|
|
161
|
+
name: PropTypes.string,
|
|
162
|
+
/**
|
|
163
|
+
* Whether the underlying input triggered a validation error or not.
|
|
164
|
+
*/
|
|
165
|
+
error: PropTypes.bool,
|
|
166
|
+
/**
|
|
167
|
+
* The value. Must be unique within the group.
|
|
168
|
+
*/
|
|
169
|
+
value: PropTypes.oneOfType([PropTypes.string, PropTypes.number, PropTypes.bool]),
|
|
170
|
+
/**
|
|
171
|
+
* Callback called when a controlled checkbox card gets interacted with.
|
|
172
|
+
*/
|
|
173
|
+
onChange: PropTypes.func,
|
|
174
|
+
/**
|
|
175
|
+
* checkbox card tokens.
|
|
176
|
+
*/
|
|
177
|
+
tokens: getTokensPropType('CheckboxCard'),
|
|
178
|
+
/**
|
|
179
|
+
* checkbox variant.
|
|
180
|
+
*/
|
|
181
|
+
variant: variantProp.propType
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
export default CheckboxCard
|
|
185
|
+
|
|
186
|
+
const staticStyles = StyleSheet.create({
|
|
187
|
+
alignWithText: {
|
|
188
|
+
justifyContent: 'center'
|
|
189
|
+
}
|
|
190
|
+
})
|
|
@@ -89,9 +89,10 @@ const StackView = forwardRef(
|
|
|
89
89
|
const content = getStackedContent(children, { direction, divider, space })
|
|
90
90
|
const themeTokens = useThemeTokens('StackView', tokens, variant, { viewport })
|
|
91
91
|
const flexStyles = selectFlexStyles(themeTokens)
|
|
92
|
+
const size = { width: themeTokens.width }
|
|
92
93
|
|
|
93
94
|
return (
|
|
94
|
-
<View ref={ref} {...selectedProps} style={[flexStyles, staticStyles[direction]]}>
|
|
95
|
+
<View ref={ref} {...selectedProps} style={[flexStyles, staticStyles[direction], size]}>
|
|
95
96
|
{content}
|
|
96
97
|
</View>
|
|
97
98
|
)
|
package/src/Tabs/Tabs.jsx
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import React, { forwardRef, useCallback } from 'react'
|
|
2
|
+
import { Platform } from 'react-native'
|
|
2
3
|
import PropTypes from 'prop-types'
|
|
3
4
|
import ABBPropTypes from 'airbnb-prop-types'
|
|
4
5
|
import { useThemeTokens } from '../ThemeProvider'
|
|
@@ -42,6 +43,17 @@ const getDefaultTabItemAccessibilityRole = (parentRole) => {
|
|
|
42
43
|
}
|
|
43
44
|
}
|
|
44
45
|
|
|
46
|
+
const getStackViewTokens = (variant) => {
|
|
47
|
+
const equalWidth = variant?.equalWidth
|
|
48
|
+
return Platform.select({
|
|
49
|
+
web: {
|
|
50
|
+
justifyContent: equalWidth ? 'space-evenly' : 'flex-start',
|
|
51
|
+
width: equalWidth ? '100%' : 'auto'
|
|
52
|
+
},
|
|
53
|
+
default: {}
|
|
54
|
+
})
|
|
55
|
+
}
|
|
56
|
+
|
|
45
57
|
/**
|
|
46
58
|
* Tabs renders a horizontally-scrolling menu of selectable buttons which may link
|
|
47
59
|
* to a page or control what content is displayed on this page.
|
|
@@ -88,6 +100,7 @@ const Tabs = forwardRef(
|
|
|
88
100
|
const parentAccessibilityRole = restProps.accessibilityRole ?? 'tablist'
|
|
89
101
|
const defaultTabItemAccessibiltyRole =
|
|
90
102
|
getDefaultTabItemAccessibilityRole(parentAccessibilityRole)
|
|
103
|
+
const stackViewTokens = getStackViewTokens(variant)
|
|
91
104
|
|
|
92
105
|
return (
|
|
93
106
|
<HorizontalScroll
|
|
@@ -99,7 +112,7 @@ const Tabs = forwardRef(
|
|
|
99
112
|
accessibilityRole={parentAccessibilityRole}
|
|
100
113
|
{...restProps}
|
|
101
114
|
>
|
|
102
|
-
<StackView space={space} direction="row">
|
|
115
|
+
<StackView space={space} direction="row" tokens={stackViewTokens}>
|
|
103
116
|
{items.map(
|
|
104
117
|
(
|
|
105
118
|
{
|
package/src/index.js
CHANGED
|
@@ -8,6 +8,7 @@ export * from './Carousel'
|
|
|
8
8
|
export { default as Listbox } from './Listbox'
|
|
9
9
|
export { default as Checkbox } from './Checkbox'
|
|
10
10
|
export * from './Checkbox'
|
|
11
|
+
export { default as CheckboxCard } from './CheckboxCard'
|
|
11
12
|
export { default as Divider } from './Divider'
|
|
12
13
|
export { default as ExpandCollapse, Accordion } from './ExpandCollapse'
|
|
13
14
|
export { default as Feedback } from './Feedback'
|