@telus-uds/components-base 1.64.0 → 1.66.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 +22 -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/TextInput/TextInputBase.js +102 -19
- package/lib/TextInput/propTypes.js +5 -0
- package/lib/index.js +9 -0
- package/lib/utils/props/textInputProps.js +1 -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/TextInput/TextInputBase.js +101 -19
- package/lib-module/TextInput/propTypes.js +5 -0
- package/lib-module/index.js +1 -0
- package/lib-module/utils/props/textInputProps.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/TextInput/TextInputBase.jsx +67 -12
- package/src/TextInput/propTypes.js +4 -0
- package/src/index.js +1 -0
- package/src/utils/props/textInputProps.js +1 -0
|
@@ -23,6 +23,8 @@ var _StackView = _interopRequireDefault(require("../StackView"));
|
|
|
23
23
|
|
|
24
24
|
var _IconButton = _interopRequireDefault(require("../IconButton"));
|
|
25
25
|
|
|
26
|
+
var _Icon = _interopRequireDefault(require("../Icon"));
|
|
27
|
+
|
|
26
28
|
var _utils = require("../utils");
|
|
27
29
|
|
|
28
30
|
var _dictionary = _interopRequireDefault(require("./dictionary"));
|
|
@@ -37,7 +39,7 @@ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj &&
|
|
|
37
39
|
|
|
38
40
|
const [selectProps, selectedSystemPropTypes] = (0, _utils.selectSystemProps)([_utils.a11yProps, _utils.textInputHandlerProps, _utils.textInputProps, _utils.viewProps]);
|
|
39
41
|
|
|
40
|
-
const selectInputStyles = (_ref, themeOptions, inactive) => {
|
|
42
|
+
const selectInputStyles = (_ref, themeOptions, inactive, type) => {
|
|
41
43
|
let {
|
|
42
44
|
backgroundColor,
|
|
43
45
|
color,
|
|
@@ -98,7 +100,7 @@ const selectInputStyles = (_ref, themeOptions, inactive) => {
|
|
|
98
100
|
borderWidth,
|
|
99
101
|
borderColor,
|
|
100
102
|
borderRadius,
|
|
101
|
-
paddingLeft: offsetBorder(paddingLeft),
|
|
103
|
+
paddingLeft: type === 'card' ? offsetBorder(paddingLeft + 34) : offsetBorder(paddingLeft),
|
|
102
104
|
paddingRight: icon ? offsetBorder(paddingWithIcon) : offsetBorder(paddingRight),
|
|
103
105
|
paddingTop: offsetBorder(paddingTop),
|
|
104
106
|
paddingBottom: offsetBorder(paddingBottom),
|
|
@@ -152,16 +154,64 @@ const selectIconContainerStyles = (_ref4, buttonCount) => {
|
|
|
152
154
|
};
|
|
153
155
|
};
|
|
154
156
|
|
|
155
|
-
const
|
|
157
|
+
const selectLeftIconContainerStyles = _ref5 => {
|
|
156
158
|
let {
|
|
157
|
-
|
|
159
|
+
leftIconPaddingBottom
|
|
158
160
|
} = _ref5;
|
|
161
|
+
return {
|
|
162
|
+
// not tokenizing paddingLeft as it remains same across brands for now
|
|
163
|
+
paddingLeft: 10,
|
|
164
|
+
paddingBottom: leftIconPaddingBottom
|
|
165
|
+
};
|
|
166
|
+
};
|
|
167
|
+
|
|
168
|
+
const selectButtonsContainerStyle = _ref6 => {
|
|
169
|
+
let {
|
|
170
|
+
buttonsPaddingRight
|
|
171
|
+
} = _ref6;
|
|
159
172
|
return {
|
|
160
173
|
paddingRight: buttonsPaddingRight
|
|
161
174
|
};
|
|
162
175
|
};
|
|
163
176
|
|
|
164
|
-
const
|
|
177
|
+
const getIcon = function () {
|
|
178
|
+
let cardNumber = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
|
|
179
|
+
let {
|
|
180
|
+
defaultCreditIcon,
|
|
181
|
+
amexIcon,
|
|
182
|
+
visaIcon,
|
|
183
|
+
masterCardIcon
|
|
184
|
+
} = arguments.length > 1 ? arguments[1] : undefined;
|
|
185
|
+
const cardType = {
|
|
186
|
+
1: {
|
|
187
|
+
icon: visaIcon,
|
|
188
|
+
testID: 'visa'
|
|
189
|
+
},
|
|
190
|
+
2: {
|
|
191
|
+
icon: amexIcon,
|
|
192
|
+
testID: 'amex'
|
|
193
|
+
},
|
|
194
|
+
4: {
|
|
195
|
+
icon: masterCardIcon,
|
|
196
|
+
testID: 'mastercard'
|
|
197
|
+
}
|
|
198
|
+
};
|
|
199
|
+
const firstDigit = cardNumber ? cardNumber[0] : '';
|
|
200
|
+
const defaultIcon = {
|
|
201
|
+
icon: defaultCreditIcon,
|
|
202
|
+
testID: 'default'
|
|
203
|
+
};
|
|
204
|
+
const selectedIcon = cardNumber.length > 4 ? cardType[firstDigit] || defaultIcon : defaultIcon;
|
|
205
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_Icon.default, {
|
|
206
|
+
icon: selectedIcon.icon,
|
|
207
|
+
variant: {
|
|
208
|
+
size: 'large'
|
|
209
|
+
},
|
|
210
|
+
testID: selectedIcon.testID
|
|
211
|
+
});
|
|
212
|
+
};
|
|
213
|
+
|
|
214
|
+
const TextInputBase = /*#__PURE__*/(0, _react.forwardRef)((_ref7, ref) => {
|
|
165
215
|
let {
|
|
166
216
|
buttons = [],
|
|
167
217
|
copy = 'en',
|
|
@@ -180,8 +230,9 @@ const TextInputBase = /*#__PURE__*/(0, _react.forwardRef)((_ref6, ref) => {
|
|
|
180
230
|
tokens,
|
|
181
231
|
value,
|
|
182
232
|
variant = {},
|
|
233
|
+
type,
|
|
183
234
|
...rest
|
|
184
|
-
} =
|
|
235
|
+
} = _ref7;
|
|
185
236
|
const [isFocused, setIsFocused] = (0, _react.useState)(false);
|
|
186
237
|
const [showPassword, setShowPassword] = (0, _react.useState)(false);
|
|
187
238
|
|
|
@@ -222,6 +273,12 @@ const TextInputBase = /*#__PURE__*/(0, _react.forwardRef)((_ref6, ref) => {
|
|
|
222
273
|
onChange,
|
|
223
274
|
readOnly
|
|
224
275
|
});
|
|
276
|
+
const {
|
|
277
|
+
password,
|
|
278
|
+
numeric
|
|
279
|
+
} = variant;
|
|
280
|
+
const isNumeric = numeric || type === 'card' || type === 'number';
|
|
281
|
+
const isPassword = password || type === 'password';
|
|
225
282
|
const element = inputRef === null || inputRef === void 0 ? void 0 : inputRef.current;
|
|
226
283
|
(0, _react.useEffect)(() => {
|
|
227
284
|
if (_Platform.default.OS === 'web' && pattern && element) {
|
|
@@ -234,11 +291,16 @@ const TextInputBase = /*#__PURE__*/(0, _react.forwardRef)((_ref6, ref) => {
|
|
|
234
291
|
const handleChangeText = event => {
|
|
235
292
|
var _event$nativeEvent, _event$target;
|
|
236
293
|
|
|
237
|
-
const {
|
|
238
|
-
numeric
|
|
239
|
-
} = variant;
|
|
240
294
|
const text = ((_event$nativeEvent = event.nativeEvent) === null || _event$nativeEvent === void 0 ? void 0 : _event$nativeEvent.text) || ((_event$target = event.target) === null || _event$target === void 0 ? void 0 : _event$target.value);
|
|
241
|
-
|
|
295
|
+
let filteredText = isNumeric ? text === null || text === void 0 ? void 0 : text.replace(/[^\d]/g, '') : text;
|
|
296
|
+
|
|
297
|
+
if (type === 'card' && filteredText) {
|
|
298
|
+
const formattedValue = filteredText.replace(/[^a-zA-Z0-9]/g, '');
|
|
299
|
+
const regex = new RegExp(`([a-zA-Z0-9]{4})(?=[a-zA-Z0-9])`, 'g'); // Add a space every 4 digits starting from the 5th position
|
|
300
|
+
|
|
301
|
+
filteredText = formattedValue.replace(regex, '$1 ').trim();
|
|
302
|
+
}
|
|
303
|
+
|
|
242
304
|
setValue(filteredText, event);
|
|
243
305
|
if (typeof onChangeText === 'function') onChangeText(filteredText, event);
|
|
244
306
|
};
|
|
@@ -267,7 +329,11 @@ const TextInputBase = /*#__PURE__*/(0, _react.forwardRef)((_ref6, ref) => {
|
|
|
267
329
|
clearButtonIcon: ClearButtonIcon,
|
|
268
330
|
icon: IconComponent,
|
|
269
331
|
passwordShowButtonIcon,
|
|
270
|
-
passwordHideButtonIcon
|
|
332
|
+
passwordHideButtonIcon,
|
|
333
|
+
defaultCreditIcon,
|
|
334
|
+
amexIcon,
|
|
335
|
+
visaIcon,
|
|
336
|
+
masterCardIcon
|
|
271
337
|
} = themeTokens;
|
|
272
338
|
const buttonsGapSize = (0, _utils.useSpacingScale)(buttonsGap);
|
|
273
339
|
const getCopy = (0, _utils.useCopy)({
|
|
@@ -287,7 +353,7 @@ const TextInputBase = /*#__PURE__*/(0, _react.forwardRef)((_ref6, ref) => {
|
|
|
287
353
|
}, "clear"));
|
|
288
354
|
}
|
|
289
355
|
|
|
290
|
-
if (
|
|
356
|
+
if (isPassword) {
|
|
291
357
|
textInputButtons === null || textInputButtons === void 0 ? void 0 : textInputButtons.unshift( /*#__PURE__*/(0, _jsxRuntime.jsx)(_IconButton.default, {
|
|
292
358
|
accessibilityLabel: !showPassword ? getCopy('hidePasswordAccessibilityLabel') : getCopy('showPasswordAccessibilityLabel'),
|
|
293
359
|
icon: !showPassword ? passwordShowButtonIcon : passwordHideButtonIcon,
|
|
@@ -313,6 +379,7 @@ const TextInputBase = /*#__PURE__*/(0, _react.forwardRef)((_ref6, ref) => {
|
|
|
313
379
|
onMouseOut: handleMouseOut,
|
|
314
380
|
onChange: handleChangeText,
|
|
315
381
|
defaultValue: initialValue,
|
|
382
|
+
maxLength: type === 'card' ? 19 : undefined,
|
|
316
383
|
value: isControlled ? currentValue : undefined
|
|
317
384
|
};
|
|
318
385
|
const {
|
|
@@ -320,20 +387,29 @@ const TextInputBase = /*#__PURE__*/(0, _react.forwardRef)((_ref6, ref) => {
|
|
|
320
387
|
} = (0, _ThemeProvider.useTheme)();
|
|
321
388
|
const nativeInputStyle = selectInputStyles({ ...themeTokens,
|
|
322
389
|
height
|
|
323
|
-
}, themeOptions, inactive);
|
|
390
|
+
}, themeOptions, inactive, type);
|
|
324
391
|
return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_View.default, {
|
|
325
392
|
style: selectOuterBorderStyles(themeTokens),
|
|
326
|
-
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(
|
|
393
|
+
children: [type === 'card' && /*#__PURE__*/(0, _jsxRuntime.jsx)(_View.default, {
|
|
394
|
+
pointerEvents: "none",
|
|
395
|
+
style: [staticStyles.leftIconContainer, selectLeftIconContainerStyles(themeTokens)],
|
|
396
|
+
children: getIcon(currentValue, {
|
|
397
|
+
defaultCreditIcon,
|
|
398
|
+
amexIcon,
|
|
399
|
+
visaIcon,
|
|
400
|
+
masterCardIcon
|
|
401
|
+
})
|
|
402
|
+
}), /*#__PURE__*/(0, _jsxRuntime.jsx)(_TextInput.default, {
|
|
327
403
|
ref: inputRef,
|
|
328
|
-
keyboardType:
|
|
329
|
-
inputMode:
|
|
404
|
+
keyboardType: isNumeric && 'numeric',
|
|
405
|
+
inputMode: isNumeric && 'numeric',
|
|
330
406
|
style: nativeInputStyle,
|
|
331
|
-
secureTextEntry:
|
|
407
|
+
secureTextEntry: isPassword && !showPassword,
|
|
332
408
|
...inputProps
|
|
333
409
|
}), IconComponent && /*#__PURE__*/(0, _jsxRuntime.jsx)(_View.default, {
|
|
334
410
|
pointerEvents: "none" // avoid hijacking input press events
|
|
335
411
|
,
|
|
336
|
-
style: [staticStyles.
|
|
412
|
+
style: [staticStyles.rightIconContainer, selectIconContainerStyles({ ...themeTokens,
|
|
337
413
|
buttonsGapSize
|
|
338
414
|
}, buttons === null || buttons === void 0 ? void 0 : buttons.length)],
|
|
339
415
|
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(IconComponent, { ...selectIconTokens(themeTokens)
|
|
@@ -359,6 +435,7 @@ TextInputBase.propTypes = { ...selectedSystemPropTypes,
|
|
|
359
435
|
copy: _propTypes.default.oneOfType([_propTypes.default.oneOf(['en', 'fr']), _propTypes.default.shape({
|
|
360
436
|
clearButtonAccessibilityLabel: _propTypes.default.string
|
|
361
437
|
})]),
|
|
438
|
+
type: _propTypes.default.oneOfType([_propTypes.default.oneOf(['password', 'card', 'number'])]),
|
|
362
439
|
height: _propTypes.default.number,
|
|
363
440
|
inactive: _propTypes.default.bool,
|
|
364
441
|
initialValue: _propTypes.default.string,
|
|
@@ -387,9 +464,15 @@ const staticStyles = _StyleSheet.default.create({
|
|
|
387
464
|
bottom: 0,
|
|
388
465
|
justifyContent: 'center'
|
|
389
466
|
},
|
|
390
|
-
|
|
467
|
+
rightIconContainer: {
|
|
391
468
|
position: 'absolute',
|
|
392
469
|
right: 0,
|
|
393
470
|
bottom: 0
|
|
471
|
+
},
|
|
472
|
+
leftIconContainer: {
|
|
473
|
+
position: 'absolute',
|
|
474
|
+
left: 0,
|
|
475
|
+
bottom: 0,
|
|
476
|
+
zIndex: 1
|
|
394
477
|
}
|
|
395
478
|
});
|
|
@@ -18,6 +18,11 @@ const textInputPropTypes = {
|
|
|
18
18
|
*/
|
|
19
19
|
value: _propTypes.default.string,
|
|
20
20
|
|
|
21
|
+
/**
|
|
22
|
+
* Use this to set the type of the input. Defaults to `text`.
|
|
23
|
+
*/
|
|
24
|
+
type: _propTypes.default.string,
|
|
25
|
+
|
|
21
26
|
/**
|
|
22
27
|
* Use this to set the initial value of an uncontrolled input.
|
|
23
28
|
* Updating `initialValue` will **not** update the actual value.
|
package/lib/index.js
CHANGED
|
@@ -12,6 +12,7 @@ var _exportNames = {
|
|
|
12
12
|
PressableCardBase: true,
|
|
13
13
|
Listbox: true,
|
|
14
14
|
Checkbox: true,
|
|
15
|
+
CheckboxCard: true,
|
|
15
16
|
Divider: true,
|
|
16
17
|
ExpandCollapse: true,
|
|
17
18
|
Accordion: true,
|
|
@@ -123,6 +124,12 @@ Object.defineProperty(exports, "Checkbox", {
|
|
|
123
124
|
return _Checkbox.default;
|
|
124
125
|
}
|
|
125
126
|
});
|
|
127
|
+
Object.defineProperty(exports, "CheckboxCard", {
|
|
128
|
+
enumerable: true,
|
|
129
|
+
get: function () {
|
|
130
|
+
return _CheckboxCard.default;
|
|
131
|
+
}
|
|
132
|
+
});
|
|
126
133
|
Object.defineProperty(exports, "Divider", {
|
|
127
134
|
enumerable: true,
|
|
128
135
|
get: function () {
|
|
@@ -508,6 +515,8 @@ Object.keys(_Checkbox).forEach(function (key) {
|
|
|
508
515
|
});
|
|
509
516
|
});
|
|
510
517
|
|
|
518
|
+
var _CheckboxCard = _interopRequireDefault(require("./CheckboxCard"));
|
|
519
|
+
|
|
511
520
|
var _Divider = _interopRequireDefault(require("./Divider"));
|
|
512
521
|
|
|
513
522
|
var _ExpandCollapse = _interopRequireWildcard(require("./ExpandCollapse"));
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
import React, { forwardRef } from 'react';
|
|
2
|
+
import PropTypes from 'prop-types';
|
|
3
|
+
import Platform from "react-native-web/dist/exports/Platform";
|
|
4
|
+
import StyleSheet from "react-native-web/dist/exports/StyleSheet";
|
|
5
|
+
import View from "react-native-web/dist/exports/View";
|
|
6
|
+
import CheckboxInput from './CheckboxInput';
|
|
7
|
+
import { applyShadowToken, useThemeTokens } from '../ThemeProvider';
|
|
8
|
+
import { a11yProps, getTokensSetPropType, selectSystemProps, selectTokens, viewProps } from '../utils';
|
|
9
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
10
|
+
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
11
|
+
const [selectProps, selectedSystemPropTypes] = selectSystemProps([a11yProps, viewProps]);
|
|
12
|
+
|
|
13
|
+
const selectInputStyles = (_ref, isChecked) => {
|
|
14
|
+
let {
|
|
15
|
+
iconBackgroundColor,
|
|
16
|
+
inputBorderColor,
|
|
17
|
+
inputBorderRadius,
|
|
18
|
+
inputBorderWidth,
|
|
19
|
+
inputBackgroundColor,
|
|
20
|
+
inputHeight,
|
|
21
|
+
inputOutlineColor,
|
|
22
|
+
inputOutlineWidth,
|
|
23
|
+
inputOutlineOffset,
|
|
24
|
+
inputShadow,
|
|
25
|
+
inputWidth
|
|
26
|
+
} = _ref;
|
|
27
|
+
return {
|
|
28
|
+
borderColor: inputBorderColor,
|
|
29
|
+
borderWidth: inputBorderWidth,
|
|
30
|
+
borderRadius: inputBorderRadius,
|
|
31
|
+
backgroundColor: isChecked ? iconBackgroundColor : inputBackgroundColor,
|
|
32
|
+
height: inputHeight,
|
|
33
|
+
width: inputWidth,
|
|
34
|
+
...applyShadowToken(inputShadow),
|
|
35
|
+
...Platform.select({
|
|
36
|
+
web: {
|
|
37
|
+
outlineStyle: 'solid',
|
|
38
|
+
outlineColor: inputOutlineColor,
|
|
39
|
+
outlineWidth: inputOutlineWidth,
|
|
40
|
+
outlineOffset: inputOutlineOffset
|
|
41
|
+
}
|
|
42
|
+
})
|
|
43
|
+
};
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
const selectIconTokens = _ref2 => {
|
|
47
|
+
let {
|
|
48
|
+
icon,
|
|
49
|
+
iconColor,
|
|
50
|
+
iconSize
|
|
51
|
+
} = _ref2;
|
|
52
|
+
return {
|
|
53
|
+
icon,
|
|
54
|
+
color: iconColor,
|
|
55
|
+
size: iconSize
|
|
56
|
+
};
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
const tokenKeys = ['checkedBackgroundColor', 'checkedSize', 'inputBackgroundColor', 'inputBorderColor', 'inputBorderWidth', 'inputOutlineColor', 'inputOutlineWidth', 'inputSize', 'outerBorderColor', 'outerBorderWidth', 'outerBorderGap', 'inputSize'];
|
|
60
|
+
export const selectCheckboxTokens = (themeTokens, prefix) => selectTokens(tokenKeys, themeTokens, prefix);
|
|
61
|
+
/**
|
|
62
|
+
* The visual toggle of a checkbox input. Is not interactive on its own, should be used inside
|
|
63
|
+
* an interactive parent that passes down props when interacted with. Used in CheckboxCard
|
|
64
|
+
*/
|
|
65
|
+
|
|
66
|
+
const CheckboxButton = /*#__PURE__*/forwardRef((_ref3, ref) => {
|
|
67
|
+
let {
|
|
68
|
+
isChecked,
|
|
69
|
+
tokens,
|
|
70
|
+
inactive,
|
|
71
|
+
defaultChecked,
|
|
72
|
+
inputId,
|
|
73
|
+
iconId,
|
|
74
|
+
isControlled,
|
|
75
|
+
handleChange,
|
|
76
|
+
name: inputName,
|
|
77
|
+
value,
|
|
78
|
+
...rest
|
|
79
|
+
} = _ref3;
|
|
80
|
+
const {
|
|
81
|
+
icon: IconComponent,
|
|
82
|
+
...stateTokens
|
|
83
|
+
} = useThemeTokens('Checkbox', {}, {
|
|
84
|
+
checked: isChecked
|
|
85
|
+
});
|
|
86
|
+
const iconTokens = selectIconTokens(stateTokens);
|
|
87
|
+
return /*#__PURE__*/_jsx(View, { ...selectProps(rest),
|
|
88
|
+
children: /*#__PURE__*/_jsxs(View, {
|
|
89
|
+
style: [staticStyles.defaultInputStyles, selectInputStyles(stateTokens, isChecked)],
|
|
90
|
+
testID: inputId,
|
|
91
|
+
children: [/*#__PURE__*/_jsx(CheckboxInput, {
|
|
92
|
+
ref: ref,
|
|
93
|
+
checked: isChecked,
|
|
94
|
+
defaultChecked: defaultChecked,
|
|
95
|
+
disabled: inactive,
|
|
96
|
+
id: inputId,
|
|
97
|
+
isControlled: isControlled,
|
|
98
|
+
onChange: handleChange,
|
|
99
|
+
name: inputName,
|
|
100
|
+
value: value
|
|
101
|
+
}), isChecked && IconComponent && /*#__PURE__*/_jsx(View, {
|
|
102
|
+
testID: iconId,
|
|
103
|
+
children: /*#__PURE__*/_jsx(IconComponent, { ...iconTokens
|
|
104
|
+
})
|
|
105
|
+
})]
|
|
106
|
+
})
|
|
107
|
+
});
|
|
108
|
+
});
|
|
109
|
+
CheckboxButton.displayName = 'CheckboxButton';
|
|
110
|
+
CheckboxButton.propTypes = { ...selectedSystemPropTypes,
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* Use `checked` for controlled Checkbox. For uncontrolled Checkbox, use the `defaultChecked` prop.
|
|
114
|
+
*/
|
|
115
|
+
isChecked: PropTypes.bool,
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* Checkbox tokens.
|
|
119
|
+
*/
|
|
120
|
+
tokens: getTokensSetPropType(tokenKeys, {
|
|
121
|
+
allowFunction: true
|
|
122
|
+
}),
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* Whether the corresponding input is disabled or active.
|
|
126
|
+
*/
|
|
127
|
+
inactive: PropTypes.bool,
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* Use `defaultChecked` to provide the initial value for an uncontrolled Checkbox.
|
|
131
|
+
*/
|
|
132
|
+
defaultChecked: PropTypes.bool,
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* Checkbox input ID.
|
|
136
|
+
*/
|
|
137
|
+
inputId: PropTypes.string,
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* Checkbox icon ID.
|
|
141
|
+
*/
|
|
142
|
+
iconId: PropTypes.string,
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* Can control the checkbox on the card.
|
|
146
|
+
*/
|
|
147
|
+
isControlled: PropTypes.bool,
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* Callback called when a controlled checkbox gets interacted with.
|
|
151
|
+
*/
|
|
152
|
+
handleChange: PropTypes.func,
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* Associate this checkbox with a group (set as the name attribute).
|
|
156
|
+
*/
|
|
157
|
+
name: PropTypes.string,
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* The value of the checkbox: true or false
|
|
161
|
+
*/
|
|
162
|
+
value: PropTypes.bool
|
|
163
|
+
};
|
|
164
|
+
export default CheckboxButton;
|
|
165
|
+
const staticStyles = StyleSheet.create({
|
|
166
|
+
container: {
|
|
167
|
+
flexDirection: 'row',
|
|
168
|
+
alignItems: 'center'
|
|
169
|
+
},
|
|
170
|
+
defaultInputStyles: {
|
|
171
|
+
alignItems: 'center',
|
|
172
|
+
justifyContent: 'center'
|
|
173
|
+
}
|
|
174
|
+
});
|
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
import React, { forwardRef } from 'react';
|
|
2
|
+
import PropTypes from 'prop-types';
|
|
3
|
+
import StyleSheet from "react-native-web/dist/exports/StyleSheet";
|
|
4
|
+
import Text from "react-native-web/dist/exports/Text";
|
|
5
|
+
import View from "react-native-web/dist/exports/View";
|
|
6
|
+
import { applyTextStyles, useTheme, useThemeTokensCallback } from '../ThemeProvider';
|
|
7
|
+
import { a11yProps, focusHandlerProps, getTokensPropType, selectSystemProps, selectTokens, useInputValue, useUniqueId, variantProp, viewProps } from '../utils';
|
|
8
|
+
import { PressableCardBase, selectPressableCardTokens } from '../Card';
|
|
9
|
+
import StackView from '../StackView';
|
|
10
|
+
import CheckboxButton, { selectCheckboxTokens } from '../Checkbox/CheckboxButton';
|
|
11
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
12
|
+
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
13
|
+
const [selectProps, selectedSystemPropTypes] = selectSystemProps([a11yProps, focusHandlerProps, viewProps]);
|
|
14
|
+
const CheckboxCard = /*#__PURE__*/forwardRef((_ref, ref) => {
|
|
15
|
+
let {
|
|
16
|
+
tokens,
|
|
17
|
+
variant,
|
|
18
|
+
title,
|
|
19
|
+
children,
|
|
20
|
+
inactive,
|
|
21
|
+
defaultChecked,
|
|
22
|
+
checked,
|
|
23
|
+
name: inputName,
|
|
24
|
+
value,
|
|
25
|
+
id,
|
|
26
|
+
iconId,
|
|
27
|
+
onChange,
|
|
28
|
+
...rest
|
|
29
|
+
} = _ref;
|
|
30
|
+
const {
|
|
31
|
+
currentValue: isChecked,
|
|
32
|
+
setValue: setIsChecked,
|
|
33
|
+
isControlled
|
|
34
|
+
} = useInputValue({
|
|
35
|
+
value: checked,
|
|
36
|
+
initialValue: defaultChecked,
|
|
37
|
+
onChange
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
const handleChange = event => {
|
|
41
|
+
if (!inactive) {
|
|
42
|
+
setIsChecked(!isChecked, event);
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
const uniqueId = useUniqueId('CheckboxCard');
|
|
47
|
+
const inputId = id ?? uniqueId;
|
|
48
|
+
const uniqueIconId = useUniqueId('CheckboxIcon');
|
|
49
|
+
const iconCheckboxId = iconId ?? uniqueIconId;
|
|
50
|
+
const getTokens = useThemeTokensCallback('CheckboxCard', tokens, variant);
|
|
51
|
+
|
|
52
|
+
const getCardTokens = cardState => selectPressableCardTokens(getTokens(cardState));
|
|
53
|
+
|
|
54
|
+
const {
|
|
55
|
+
themeOptions
|
|
56
|
+
} = useTheme();
|
|
57
|
+
const selectedProps = selectProps({
|
|
58
|
+
accessibilityRole: 'checkbox',
|
|
59
|
+
accessibilityState: {
|
|
60
|
+
checked: isChecked,
|
|
61
|
+
disabled: inactive
|
|
62
|
+
},
|
|
63
|
+
...rest
|
|
64
|
+
});
|
|
65
|
+
return /*#__PURE__*/_jsx(PressableCardBase, {
|
|
66
|
+
ref: ref,
|
|
67
|
+
inactive: inactive,
|
|
68
|
+
checked: isChecked,
|
|
69
|
+
tokens: getCardTokens,
|
|
70
|
+
onPress: handleChange,
|
|
71
|
+
...selectedProps,
|
|
72
|
+
children: cardState => {
|
|
73
|
+
const {
|
|
74
|
+
checkboxSpace,
|
|
75
|
+
contentSpace,
|
|
76
|
+
...themeTokens
|
|
77
|
+
} = getTokens(cardState);
|
|
78
|
+
const checkboxTokens = selectCheckboxTokens(themeTokens, 'checkbox');
|
|
79
|
+
const titleTokens = selectTokens('Typography', themeTokens);
|
|
80
|
+
const textStyle = applyTextStyles({ ...titleTokens,
|
|
81
|
+
themeOptions
|
|
82
|
+
});
|
|
83
|
+
return /*#__PURE__*/_jsxs(StackView, {
|
|
84
|
+
direction: "row",
|
|
85
|
+
space: checkboxSpace,
|
|
86
|
+
children: [/*#__PURE__*/_jsx(View, {
|
|
87
|
+
style: [staticStyles.alignWithText, {
|
|
88
|
+
height: textStyle.lineHeight
|
|
89
|
+
}],
|
|
90
|
+
children: /*#__PURE__*/_jsx(CheckboxButton, {
|
|
91
|
+
tokens: checkboxTokens,
|
|
92
|
+
isControlled: isControlled,
|
|
93
|
+
isChecked: isChecked,
|
|
94
|
+
inactive: inactive,
|
|
95
|
+
defaultChecked: defaultChecked,
|
|
96
|
+
inputId: inputId,
|
|
97
|
+
iconId: iconCheckboxId,
|
|
98
|
+
handleChange: handleChange,
|
|
99
|
+
name: inputName,
|
|
100
|
+
value: value
|
|
101
|
+
})
|
|
102
|
+
}), /*#__PURE__*/_jsxs(StackView, {
|
|
103
|
+
direction: "column",
|
|
104
|
+
space: contentSpace,
|
|
105
|
+
tokens: {
|
|
106
|
+
flexShrink: 1
|
|
107
|
+
},
|
|
108
|
+
children: [title ? /*#__PURE__*/_jsx(Text, {
|
|
109
|
+
style: textStyle,
|
|
110
|
+
children: title
|
|
111
|
+
}) : null, typeof children === 'function' ? children(cardState, textStyle) : children]
|
|
112
|
+
})]
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
});
|
|
116
|
+
});
|
|
117
|
+
CheckboxCard.displayName = 'CheckboxCard';
|
|
118
|
+
CheckboxCard.propTypes = { ...selectedSystemPropTypes,
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* Content to be displayed at the top of the card alongside the checkbox
|
|
122
|
+
*/
|
|
123
|
+
title: PropTypes.string,
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* Additional content to be displayed below the checkbox.
|
|
127
|
+
*/
|
|
128
|
+
children: PropTypes.oneOfType([PropTypes.node, PropTypes.func]),
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* Use `checked` for controlled checkbox. For uncontrolled checkbox, use the `defaultChecked` prop.
|
|
132
|
+
*/
|
|
133
|
+
checked: PropTypes.bool,
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* Use `defaultChecked` to provide the initial value for an uncontrolled checkbox.
|
|
137
|
+
*/
|
|
138
|
+
defaultChecked: PropTypes.bool,
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* An optional checkboxdescription.
|
|
142
|
+
*/
|
|
143
|
+
description: PropTypes.string,
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
* Checkbox card ID.
|
|
147
|
+
*/
|
|
148
|
+
id: PropTypes.string,
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* Checkbox icon ID.
|
|
152
|
+
*/
|
|
153
|
+
iconId: PropTypes.string,
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* Whether the corresponding input is disabled or active.
|
|
157
|
+
*/
|
|
158
|
+
inactive: PropTypes.bool,
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* The label.
|
|
162
|
+
*/
|
|
163
|
+
label: PropTypes.string,
|
|
164
|
+
|
|
165
|
+
/**
|
|
166
|
+
* Associate this checkbox card with a group (set as the name attribute).
|
|
167
|
+
*/
|
|
168
|
+
name: PropTypes.string,
|
|
169
|
+
|
|
170
|
+
/**
|
|
171
|
+
* Whether the underlying input triggered a validation error or not.
|
|
172
|
+
*/
|
|
173
|
+
error: PropTypes.bool,
|
|
174
|
+
|
|
175
|
+
/**
|
|
176
|
+
* The value. Must be unique within the group.
|
|
177
|
+
*/
|
|
178
|
+
value: PropTypes.oneOfType([PropTypes.string, PropTypes.number, PropTypes.bool]),
|
|
179
|
+
|
|
180
|
+
/**
|
|
181
|
+
* Callback called when a controlled checkbox card gets interacted with.
|
|
182
|
+
*/
|
|
183
|
+
onChange: PropTypes.func,
|
|
184
|
+
|
|
185
|
+
/**
|
|
186
|
+
* checkbox card tokens.
|
|
187
|
+
*/
|
|
188
|
+
tokens: getTokensPropType('CheckboxCard'),
|
|
189
|
+
|
|
190
|
+
/**
|
|
191
|
+
* checkbox variant.
|
|
192
|
+
*/
|
|
193
|
+
variant: variantProp.propType
|
|
194
|
+
};
|
|
195
|
+
export default CheckboxCard;
|
|
196
|
+
const staticStyles = StyleSheet.create({
|
|
197
|
+
alignWithText: {
|
|
198
|
+
justifyContent: 'center'
|
|
199
|
+
}
|
|
200
|
+
});
|
|
@@ -80,10 +80,13 @@ const StackView = /*#__PURE__*/forwardRef((_ref, ref) => {
|
|
|
80
80
|
viewport
|
|
81
81
|
});
|
|
82
82
|
const flexStyles = selectFlexStyles(themeTokens);
|
|
83
|
+
const size = {
|
|
84
|
+
width: themeTokens.width
|
|
85
|
+
};
|
|
83
86
|
return /*#__PURE__*/_jsx(View, {
|
|
84
87
|
ref: ref,
|
|
85
88
|
...selectedProps,
|
|
86
|
-
style: [flexStyles, staticStyles[direction]],
|
|
89
|
+
style: [flexStyles, staticStyles[direction], size],
|
|
87
90
|
children: content
|
|
88
91
|
});
|
|
89
92
|
});
|