@telus-uds/components-base 1.1.0 → 1.2.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/.ultra.cache.json +1 -1
- package/CHANGELOG.md +8 -0
- package/__fixtures__/Accessible.js +4 -2
- package/__fixtures__/Accessible.native.js +5 -2
- package/__fixtures__/testTheme.js +9 -0
- package/__tests__/HorizontalScroll/HorizontalScroll.test.jsx +1 -0
- package/__tests__/ToggleSwitch/ToggleSwitch.test.jsx +10 -0
- package/__tests__/ToggleSwitch/ToggleSwitchGroup.test.jsx +192 -0
- package/component-docs.json +614 -796
- package/lib/Button/ButtonBase.js +20 -6
- package/lib/Card/PressableCardBase.js +9 -3
- package/lib/Checkbox/Checkbox.js +0 -2
- package/lib/IconButton/IconButton.js +8 -3
- package/lib/Link/LinkBase.js +10 -3
- package/lib/Pagination/PageButton.js +3 -1
- package/lib/Pagination/Pagination.js +16 -4
- package/lib/Pagination/SideButton.js +3 -1
- package/lib/Radio/Radio.js +0 -2
- package/lib/Tabs/Tabs.js +12 -4
- package/lib/Tabs/TabsItem.js +12 -6
- package/lib/ToggleSwitch/ToggleSwitch.js +99 -37
- package/lib/ToggleSwitch/ToggleSwitchGroup.js +230 -0
- package/lib/ToggleSwitch/index.js +14 -4
- package/lib/index.js +13 -8
- package/lib/utils/index.js +10 -1
- package/lib/utils/propTypes.js +26 -1
- package/lib/utils/withLinkRouter.js +98 -0
- package/package.json +2 -2
- package/release-context.json +4 -4
- package/src/Button/ButtonBase.jsx +11 -4
- package/src/Card/PressableCardBase.jsx +6 -4
- package/src/Checkbox/Checkbox.jsx +0 -2
- package/src/IconButton/IconButton.jsx +6 -4
- package/src/Link/LinkBase.jsx +6 -4
- package/src/Pagination/PageButton.jsx +3 -2
- package/src/Pagination/Pagination.jsx +29 -2
- package/src/Pagination/SideButton.jsx +2 -2
- package/src/Radio/Radio.jsx +0 -2
- package/src/Tabs/Tabs.jsx +49 -22
- package/src/Tabs/TabsItem.jsx +11 -7
- package/src/ToggleSwitch/ToggleSwitch.jsx +92 -34
- package/src/ToggleSwitch/ToggleSwitchGroup.jsx +203 -0
- package/src/ToggleSwitch/index.js +2 -1
- package/src/index.js +1 -1
- package/src/utils/index.js +1 -0
- package/src/utils/propTypes.js +30 -0
- package/src/utils/withLinkRouter.jsx +68 -0
- package/stories/TextInput/TextArea.stories.jsx +1 -0
- package/stories/ToggleSwitch/ToggleSwitch.stories.jsx +5 -1
- package/stories/ToggleSwitch/ToggleSwitchGroup.stories.jsx +81 -0
package/lib/Button/ButtonBase.js
CHANGED
|
@@ -7,6 +7,8 @@ exports.default = void 0;
|
|
|
7
7
|
|
|
8
8
|
var _react = _interopRequireWildcard(require("react"));
|
|
9
9
|
|
|
10
|
+
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
11
|
+
|
|
10
12
|
var _Pressable = _interopRequireDefault(require("react-native-web/dist/cjs/exports/Pressable"));
|
|
11
13
|
|
|
12
14
|
var _View = _interopRequireDefault(require("react-native-web/dist/cjs/exports/View"));
|
|
@@ -17,7 +19,7 @@ var _Platform = _interopRequireDefault(require("react-native-web/dist/cjs/export
|
|
|
17
19
|
|
|
18
20
|
var _utils = require("../ThemeProvider/utils");
|
|
19
21
|
|
|
20
|
-
var
|
|
22
|
+
var _propTypes2 = _interopRequireDefault(require("./propTypes"));
|
|
21
23
|
|
|
22
24
|
var _utils2 = require("../utils");
|
|
23
25
|
|
|
@@ -170,18 +172,23 @@ const selectWebOnlyStyles = (inactive, themeTokens, {
|
|
|
170
172
|
};
|
|
171
173
|
|
|
172
174
|
const ButtonBase = /*#__PURE__*/(0, _react.forwardRef)(({
|
|
175
|
+
id,
|
|
173
176
|
href,
|
|
174
177
|
hrefAttrs,
|
|
175
178
|
children,
|
|
176
|
-
onPress,
|
|
177
179
|
tokens = {},
|
|
178
180
|
disabled = false,
|
|
179
181
|
// alias for inactive
|
|
180
182
|
inactive = disabled,
|
|
181
183
|
selected = false,
|
|
182
184
|
dataSet,
|
|
183
|
-
...
|
|
185
|
+
...rawRest
|
|
184
186
|
}, ref) => {
|
|
187
|
+
const {
|
|
188
|
+
onPress,
|
|
189
|
+
...rest
|
|
190
|
+
} = _utils2.clickProps.toPressProps(rawRest);
|
|
191
|
+
|
|
185
192
|
const extraButtonState = {
|
|
186
193
|
inactive,
|
|
187
194
|
selected
|
|
@@ -217,6 +224,7 @@ const ButtonBase = /*#__PURE__*/(0, _react.forwardRef)(({
|
|
|
217
224
|
|
|
218
225
|
const stretchStyles = themeTokens.width ? staticStyles.stretch : staticStyles.align;
|
|
219
226
|
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_View.default, {
|
|
227
|
+
id: id,
|
|
220
228
|
style: [containerStyles, borderStyles, stretchStyles, staticStyles.row, _Platform.default.select({
|
|
221
229
|
web: {
|
|
222
230
|
maxWidth: '100%',
|
|
@@ -235,10 +243,15 @@ const ButtonBase = /*#__PURE__*/(0, _react.forwardRef)(({
|
|
|
235
243
|
});
|
|
236
244
|
});
|
|
237
245
|
ButtonBase.displayName = 'ButtonBase';
|
|
238
|
-
ButtonBase.propTypes = {
|
|
239
|
-
|
|
246
|
+
ButtonBase.propTypes = {
|
|
247
|
+
id: _propTypes.default.string,
|
|
248
|
+
..._utils2.a11yProps.types,
|
|
249
|
+
..._propTypes2.default,
|
|
240
250
|
..._utils2.linkProps.types
|
|
241
251
|
};
|
|
252
|
+
ButtonBase.defaultProps = {
|
|
253
|
+
id: undefined
|
|
254
|
+
};
|
|
242
255
|
|
|
243
256
|
const staticStyles = _StyleSheet.default.create({
|
|
244
257
|
row: {
|
|
@@ -265,5 +278,6 @@ const staticStyles = _StyleSheet.default.create({
|
|
|
265
278
|
}
|
|
266
279
|
});
|
|
267
280
|
|
|
268
|
-
var _default = ButtonBase;
|
|
281
|
+
var _default = (0, _utils2.withLinkRouter)(ButtonBase);
|
|
282
|
+
|
|
269
283
|
exports.default = _default;
|
|
@@ -52,10 +52,14 @@ const PressableCardBase = /*#__PURE__*/(0, _react.forwardRef)(({
|
|
|
52
52
|
inactive,
|
|
53
53
|
href,
|
|
54
54
|
hrefAttrs,
|
|
55
|
-
onPress,
|
|
56
55
|
accessibilityRole = href ? 'link' : undefined,
|
|
57
|
-
...
|
|
56
|
+
...rawRest
|
|
58
57
|
}, ref) => {
|
|
58
|
+
const {
|
|
59
|
+
onPress,
|
|
60
|
+
...rest
|
|
61
|
+
} = _utils.clickProps.toPressProps(rawRest);
|
|
62
|
+
|
|
59
63
|
const viewport = (0, _ViewportProvider.useViewport)();
|
|
60
64
|
|
|
61
65
|
const a11y = _propTypes2.a11yProps.select({ ...rest,
|
|
@@ -137,5 +141,7 @@ PressableCardBase.propTypes = {
|
|
|
137
141
|
variant: _utils.variantProp.propType,
|
|
138
142
|
..._propTypes2.a11yProps.types
|
|
139
143
|
};
|
|
140
|
-
|
|
144
|
+
|
|
145
|
+
var _default = (0, _utils.withLinkRouter)(PressableCardBase);
|
|
146
|
+
|
|
141
147
|
exports.default = _default;
|
package/lib/Checkbox/Checkbox.js
CHANGED
|
@@ -43,8 +43,6 @@ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "functio
|
|
|
43
43
|
|
|
44
44
|
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
45
45
|
|
|
46
|
-
// @todo move `LabelContent` outside of the `InputLabel` and fix
|
|
47
|
-
// the issue with the cursor not being pointer on Web
|
|
48
46
|
const selectInputStyles = ({
|
|
49
47
|
iconBackgroundColor,
|
|
50
48
|
inputBorderColor,
|
|
@@ -83,10 +83,14 @@ const IconButton = /*#__PURE__*/(0, _react.forwardRef)(({
|
|
|
83
83
|
icon: IconComponent,
|
|
84
84
|
href,
|
|
85
85
|
hrefAttrs,
|
|
86
|
-
onPress,
|
|
87
86
|
accessibilityRole = href ? 'link' : 'button',
|
|
88
|
-
...
|
|
87
|
+
...rawRest
|
|
89
88
|
}, ref) => {
|
|
89
|
+
const {
|
|
90
|
+
onPress,
|
|
91
|
+
...rest
|
|
92
|
+
} = _utils.clickProps.toPressProps(rawRest);
|
|
93
|
+
|
|
90
94
|
const a11y = _propTypes2.a11yProps.select({ ...rest,
|
|
91
95
|
accessibilityRole
|
|
92
96
|
});
|
|
@@ -136,5 +140,6 @@ const staticStyles = _StyleSheet.default.create({
|
|
|
136
140
|
}
|
|
137
141
|
});
|
|
138
142
|
|
|
139
|
-
var _default = IconButton;
|
|
143
|
+
var _default = (0, _utils.withLinkRouter)(IconButton);
|
|
144
|
+
|
|
140
145
|
exports.default = _default;
|
package/lib/Link/LinkBase.js
CHANGED
|
@@ -19,6 +19,8 @@ var _propTypes2 = require("../utils/propTypes");
|
|
|
19
19
|
|
|
20
20
|
var _pressability = require("../utils/pressability");
|
|
21
21
|
|
|
22
|
+
var _utils = require("../utils");
|
|
23
|
+
|
|
22
24
|
var _InlinePressable = _interopRequireDefault(require("./InlinePressable"));
|
|
23
25
|
|
|
24
26
|
var _ThemeProvider = require("../ThemeProvider");
|
|
@@ -120,7 +122,6 @@ const selectIconTokens = ({
|
|
|
120
122
|
|
|
121
123
|
const LinkBase = /*#__PURE__*/(0, _react.forwardRef)(({
|
|
122
124
|
href,
|
|
123
|
-
onPress,
|
|
124
125
|
icon,
|
|
125
126
|
iconPosition = icon ? 'left' : undefined,
|
|
126
127
|
iconProps,
|
|
@@ -129,8 +130,13 @@ const LinkBase = /*#__PURE__*/(0, _react.forwardRef)(({
|
|
|
129
130
|
children,
|
|
130
131
|
accessibilityRole = 'link',
|
|
131
132
|
dataSet,
|
|
132
|
-
...
|
|
133
|
+
...rawRest
|
|
133
134
|
}, ref) => {
|
|
135
|
+
const {
|
|
136
|
+
onPress,
|
|
137
|
+
...props
|
|
138
|
+
} = _propTypes2.clickProps.toPressProps(rawRest);
|
|
139
|
+
|
|
134
140
|
const {
|
|
135
141
|
hrefAttrs,
|
|
136
142
|
rest
|
|
@@ -231,5 +237,6 @@ const staticStyles = _StyleSheet.default.create({
|
|
|
231
237
|
}
|
|
232
238
|
});
|
|
233
239
|
|
|
234
|
-
var _default = LinkBase;
|
|
240
|
+
var _default = (0, _utils.withLinkRouter)(LinkBase);
|
|
241
|
+
|
|
235
242
|
exports.default = _default;
|
|
@@ -85,5 +85,7 @@ PageButton.propTypes = { ..._utils.linkProps.types,
|
|
|
85
85
|
variant: _utils.variantProp.propType,
|
|
86
86
|
tokens: (0, _utils.getTokensPropType)('PaginationPageButton')
|
|
87
87
|
};
|
|
88
|
-
|
|
88
|
+
|
|
89
|
+
var _default = (0, _utils.withLinkRouter)(PageButton);
|
|
90
|
+
|
|
89
91
|
exports.default = _default;
|
|
@@ -55,7 +55,9 @@ const Pagination = /*#__PURE__*/(0, _react.forwardRef)(({
|
|
|
55
55
|
variant,
|
|
56
56
|
tokens,
|
|
57
57
|
sideButtonVariant,
|
|
58
|
-
sideButtonTokens
|
|
58
|
+
sideButtonTokens,
|
|
59
|
+
LinkRouter,
|
|
60
|
+
linkRouterProps
|
|
59
61
|
}, ref) => {
|
|
60
62
|
const viewport = (0, _ViewportProvider.useViewport)();
|
|
61
63
|
const {
|
|
@@ -93,13 +95,21 @@ const Pagination = /*#__PURE__*/(0, _react.forwardRef)(({
|
|
|
93
95
|
direction: "previous",
|
|
94
96
|
copy: copy,
|
|
95
97
|
variant: sideButtonVariant,
|
|
96
|
-
tokens: sideButtonTokens
|
|
98
|
+
tokens: sideButtonTokens,
|
|
99
|
+
LinkRouter: LinkRouter,
|
|
100
|
+
linkRouterProps: linkRouterProps
|
|
97
101
|
}), ...items.map((child, itemIndex) => {
|
|
98
102
|
const buttonLabel = `${itemIndex + 1}`;
|
|
99
103
|
const itemProps = getItemProps(itemIndex);
|
|
104
|
+
const ItemLinkRouter = itemProps.LinkRouter ?? LinkRouter;
|
|
105
|
+
const itemLinkRouterProps = { ...linkRouterProps,
|
|
106
|
+
...itemProps.linkRouterProps
|
|
107
|
+
};
|
|
100
108
|
|
|
101
109
|
if (shouldRenderButton(itemIndex)) {
|
|
102
110
|
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_PageButton.default, { ...itemProps,
|
|
111
|
+
LinkRouter: ItemLinkRouter,
|
|
112
|
+
linkRouterProps: itemLinkRouterProps,
|
|
103
113
|
label: buttonLabel,
|
|
104
114
|
copy: copy,
|
|
105
115
|
isActive: isItemActive(itemIndex)
|
|
@@ -118,7 +128,9 @@ const Pagination = /*#__PURE__*/(0, _react.forwardRef)(({
|
|
|
118
128
|
direction: "next",
|
|
119
129
|
copy: copy,
|
|
120
130
|
variant: sideButtonVariant,
|
|
121
|
-
tokens: sideButtonTokens
|
|
131
|
+
tokens: sideButtonTokens,
|
|
132
|
+
LinkRouter: LinkRouter,
|
|
133
|
+
linkRouterProps: linkRouterProps
|
|
122
134
|
})];
|
|
123
135
|
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_View.default, {
|
|
124
136
|
style: staticStyles.container,
|
|
@@ -132,7 +144,7 @@ const Pagination = /*#__PURE__*/(0, _react.forwardRef)(({
|
|
|
132
144
|
});
|
|
133
145
|
_PageButton.default.displayName = 'PageButton';
|
|
134
146
|
Pagination.PageButton = _PageButton.default;
|
|
135
|
-
Pagination.propTypes = {
|
|
147
|
+
Pagination.propTypes = { ..._utils.withLinkRouter.propTypes,
|
|
136
148
|
children: (0, _utils.componentPropType)('PageButton'),
|
|
137
149
|
copy: _utils.copyPropTypes,
|
|
138
150
|
variant: _utils.variantProp.propType,
|
package/lib/Radio/Radio.js
CHANGED
|
@@ -37,8 +37,6 @@ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "functio
|
|
|
37
37
|
|
|
38
38
|
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
39
39
|
|
|
40
|
-
// @todo move `LabelContent` outside of the `InputLabel` and fix
|
|
41
|
-
// the issue with the cursor not being pointer on Web
|
|
42
40
|
const selectContainerStyles = ({
|
|
43
41
|
containerBackgroundColor,
|
|
44
42
|
containerBorderRadius,
|
package/lib/Tabs/Tabs.js
CHANGED
|
@@ -46,7 +46,9 @@ const Tabs = /*#__PURE__*/(0, _react.forwardRef)(({
|
|
|
46
46
|
value,
|
|
47
47
|
initialValue,
|
|
48
48
|
onChange,
|
|
49
|
-
items = []
|
|
49
|
+
items = [],
|
|
50
|
+
LinkRouter,
|
|
51
|
+
linkRouterProps
|
|
50
52
|
}, ref) => {
|
|
51
53
|
const {
|
|
52
54
|
space,
|
|
@@ -82,7 +84,9 @@ const Tabs = /*#__PURE__*/(0, _react.forwardRef)(({
|
|
|
82
84
|
href,
|
|
83
85
|
label,
|
|
84
86
|
id,
|
|
85
|
-
ref: itemRef
|
|
87
|
+
ref: itemRef,
|
|
88
|
+
LinkRouter: ItemLinkRouter = LinkRouter,
|
|
89
|
+
linkRouterProps: itemLinkRouterProps
|
|
86
90
|
}, index) => {
|
|
87
91
|
const itemId = id ?? label;
|
|
88
92
|
const isSelected = Boolean(currentValue && currentValue === itemId);
|
|
@@ -98,6 +102,10 @@ const Tabs = /*#__PURE__*/(0, _react.forwardRef)(({
|
|
|
98
102
|
selected: isSelected,
|
|
99
103
|
itemPositions: itemPositions,
|
|
100
104
|
index: index,
|
|
105
|
+
LinkRouter: ItemLinkRouter,
|
|
106
|
+
linkRouterProps: { ...linkRouterProps,
|
|
107
|
+
...itemLinkRouterProps
|
|
108
|
+
},
|
|
101
109
|
children: label
|
|
102
110
|
}, itemId);
|
|
103
111
|
})
|
|
@@ -105,8 +113,8 @@ const Tabs = /*#__PURE__*/(0, _react.forwardRef)(({
|
|
|
105
113
|
});
|
|
106
114
|
});
|
|
107
115
|
Tabs.displayName = 'Tabs';
|
|
108
|
-
Tabs.propTypes = {
|
|
109
|
-
items: _propTypes.default.arrayOf(_propTypes.default.shape({
|
|
116
|
+
Tabs.propTypes = { ..._utils.withLinkRouter.PropTypes,
|
|
117
|
+
items: _propTypes.default.arrayOf(_propTypes.default.shape({ ..._utils.withLinkRouter.PropTypes,
|
|
110
118
|
href: _propTypes.default.string,
|
|
111
119
|
label: _propTypes.default.string,
|
|
112
120
|
id: _propTypes.default.string,
|
package/lib/Tabs/TabsItem.js
CHANGED
|
@@ -99,7 +99,6 @@ const selectContainerStyles = ({
|
|
|
99
99
|
|
|
100
100
|
|
|
101
101
|
const TabsItem = /*#__PURE__*/(0, _react.forwardRef)(({
|
|
102
|
-
onPress,
|
|
103
102
|
href,
|
|
104
103
|
variant,
|
|
105
104
|
tokens,
|
|
@@ -114,8 +113,14 @@ const TabsItem = /*#__PURE__*/(0, _react.forwardRef)(({
|
|
|
114
113
|
} : {
|
|
115
114
|
selected
|
|
116
115
|
},
|
|
117
|
-
...
|
|
116
|
+
...rawRest
|
|
118
117
|
}, ref) => {
|
|
118
|
+
// Convert onClick etc to onPress etc if used in an integration
|
|
119
|
+
const {
|
|
120
|
+
onPress,
|
|
121
|
+
...rest
|
|
122
|
+
} = _utils.clickProps.toPressProps(rawRest);
|
|
123
|
+
|
|
119
124
|
const getTokens = (0, _ThemeProvider.useThemeTokensCallback)('TabsItem', tokens, variant);
|
|
120
125
|
|
|
121
126
|
const resolveTokens = pressableState => (0, _utils.resolvePressableTokens)(getTokens, pressableState, {
|
|
@@ -139,9 +144,9 @@ const TabsItem = /*#__PURE__*/(0, _react.forwardRef)(({
|
|
|
139
144
|
href
|
|
140
145
|
});
|
|
141
146
|
|
|
142
|
-
const handlePress = onPress || openHref ? () => {
|
|
143
|
-
if (onPress) onPress();
|
|
144
|
-
if (openHref) openHref();
|
|
147
|
+
const handlePress = onPress || openHref ? (...args) => {
|
|
148
|
+
if (onPress) onPress(...args);
|
|
149
|
+
if (openHref) openHref(...args);
|
|
145
150
|
} : undefined;
|
|
146
151
|
const a11y = {
|
|
147
152
|
accessibilityRole,
|
|
@@ -234,5 +239,6 @@ const staticStyles = _StyleSheet.default.create({
|
|
|
234
239
|
}
|
|
235
240
|
});
|
|
236
241
|
|
|
237
|
-
var _default = TabsItem;
|
|
242
|
+
var _default = (0, _utils.withLinkRouter)(TabsItem);
|
|
243
|
+
|
|
238
244
|
exports.default = _default;
|
|
@@ -11,18 +11,24 @@ var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
|
11
11
|
|
|
12
12
|
var _Platform = _interopRequireDefault(require("react-native-web/dist/cjs/exports/Platform"));
|
|
13
13
|
|
|
14
|
+
var _StyleSheet = _interopRequireDefault(require("react-native-web/dist/cjs/exports/StyleSheet"));
|
|
15
|
+
|
|
14
16
|
var _View = _interopRequireDefault(require("react-native-web/dist/cjs/exports/View"));
|
|
15
17
|
|
|
16
|
-
var
|
|
18
|
+
var _InputLabel = _interopRequireDefault(require("../InputLabel"));
|
|
17
19
|
|
|
18
20
|
var _ButtonBase = _interopRequireDefault(require("../Button/ButtonBase"));
|
|
19
21
|
|
|
22
|
+
var _StackView = _interopRequireDefault(require("../StackView"));
|
|
23
|
+
|
|
20
24
|
var _ThemeProvider = require("../ThemeProvider");
|
|
21
25
|
|
|
22
26
|
var _propTypes2 = require("../utils/propTypes");
|
|
23
27
|
|
|
24
28
|
var _input = require("../utils/input");
|
|
25
29
|
|
|
30
|
+
var _utils = require("../utils");
|
|
31
|
+
|
|
26
32
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
27
33
|
|
|
28
34
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
@@ -80,16 +86,41 @@ const selectSwitchStyles = ({
|
|
|
80
86
|
})
|
|
81
87
|
});
|
|
82
88
|
|
|
89
|
+
const selectLabelStyles = ({
|
|
90
|
+
labelMarginLeft
|
|
91
|
+
}) => ({
|
|
92
|
+
marginLeft: labelMarginLeft
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
const selectLabelTokens = ({
|
|
96
|
+
labelColor,
|
|
97
|
+
labelFontName,
|
|
98
|
+
labelFontSize,
|
|
99
|
+
labelFontWeight,
|
|
100
|
+
labelLineHeight
|
|
101
|
+
}) => ({
|
|
102
|
+
color: labelColor,
|
|
103
|
+
fontName: labelFontName,
|
|
104
|
+
fontWeight: labelFontWeight,
|
|
105
|
+
fontSize: labelFontSize,
|
|
106
|
+
lineHeight: labelLineHeight
|
|
107
|
+
});
|
|
108
|
+
|
|
83
109
|
const ToggleSwitch = /*#__PURE__*/(0, _react.forwardRef)(({
|
|
84
110
|
value,
|
|
85
111
|
initialValue,
|
|
86
112
|
onChange,
|
|
113
|
+
id,
|
|
114
|
+
label,
|
|
87
115
|
inactive,
|
|
88
116
|
tokens,
|
|
117
|
+
tooltip,
|
|
89
118
|
variant,
|
|
90
|
-
accessibilityRole = 'switch'
|
|
119
|
+
accessibilityRole = 'switch',
|
|
120
|
+
accessibilityLabel = label
|
|
91
121
|
}, ref) => {
|
|
92
122
|
const getTokens = (0, _ThemeProvider.useThemeTokensCallback)('ToggleSwitch', tokens, variant);
|
|
123
|
+
const themeTokens = getTokens();
|
|
93
124
|
const {
|
|
94
125
|
currentValue,
|
|
95
126
|
setValue
|
|
@@ -103,41 +134,57 @@ const ToggleSwitch = /*#__PURE__*/(0, _react.forwardRef)(({
|
|
|
103
134
|
|
|
104
135
|
const getButtonTokens = buttonState => selectButtonTokens(getTokens(buttonState));
|
|
105
136
|
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
+
const uniqueId = (0, _utils.useUniqueId)('toggleSwitch');
|
|
138
|
+
const inputId = id ?? uniqueId;
|
|
139
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_StackView.default, {
|
|
140
|
+
space: 2,
|
|
141
|
+
direction: "row",
|
|
142
|
+
children: [Boolean(label) && /*#__PURE__*/(0, _jsxRuntime.jsx)(_View.default, {
|
|
143
|
+
style: selectLabelStyles(themeTokens),
|
|
144
|
+
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_InputLabel.default, {
|
|
145
|
+
forId: inputId,
|
|
146
|
+
label: label,
|
|
147
|
+
tokens: selectLabelTokens(themeTokens),
|
|
148
|
+
tooltip: tooltip
|
|
149
|
+
})
|
|
150
|
+
}), /*#__PURE__*/(0, _jsxRuntime.jsx)(_ButtonBase.default, {
|
|
151
|
+
id: id,
|
|
152
|
+
ref: ref,
|
|
153
|
+
selected: currentValue,
|
|
154
|
+
inactive: inactive,
|
|
155
|
+
tokens: getButtonTokens,
|
|
156
|
+
accessibilityLabel: accessibilityLabel,
|
|
157
|
+
accessibilityRole: accessibilityRole,
|
|
158
|
+
accessibilityState: {
|
|
159
|
+
checked: currentValue
|
|
160
|
+
},
|
|
161
|
+
onPress: handlePress,
|
|
162
|
+
children: buttonState => {
|
|
163
|
+
const stateTokens = getTokens(buttonState);
|
|
164
|
+
const IconComponent = stateTokens.icon;
|
|
165
|
+
const switchStyles = selectSwitchStyles(stateTokens);
|
|
166
|
+
const trackStyles = selectTrackStyles(stateTokens);
|
|
167
|
+
const iconTokens = selectIconTokens(stateTokens); // If drag-slide support is needed, use a PanResponder and apply these to an Animated value.
|
|
168
|
+
// Use translate transforms for smoothest non-thread-blocking animations and to allow drag.
|
|
169
|
+
|
|
170
|
+
const slideStart = 0;
|
|
171
|
+
const slideEnd = stateTokens.width - stateTokens.switchSize - stateTokens.trackBorderWidth * 2;
|
|
172
|
+
const switchOffset = buttonState.selected ? slideEnd : slideStart;
|
|
173
|
+
const switchPositionStyle = {
|
|
174
|
+
transform: [{
|
|
175
|
+
translateX: switchOffset
|
|
176
|
+
}]
|
|
177
|
+
};
|
|
178
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_View.default, {
|
|
179
|
+
style: [staticStyles.track, trackStyles],
|
|
180
|
+
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_View.default, {
|
|
181
|
+
style: [staticStyles.switch, switchStyles, switchPositionStyle],
|
|
182
|
+
children: IconComponent && /*#__PURE__*/(0, _jsxRuntime.jsx)(IconComponent, { ...iconTokens
|
|
183
|
+
})
|
|
137
184
|
})
|
|
138
|
-
})
|
|
139
|
-
}
|
|
140
|
-
}
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
})]
|
|
141
188
|
});
|
|
142
189
|
});
|
|
143
190
|
ToggleSwitch.displayName = 'ToggleSwitch';
|
|
@@ -165,11 +212,26 @@ ToggleSwitch.propTypes = { ..._propTypes2.a11yProps.propTypes,
|
|
|
165
212
|
*/
|
|
166
213
|
onChange: _propTypes.default.func,
|
|
167
214
|
|
|
215
|
+
/**
|
|
216
|
+
* Input ID.
|
|
217
|
+
*/
|
|
218
|
+
id: _propTypes.default.string,
|
|
219
|
+
|
|
220
|
+
/**
|
|
221
|
+
* An optional label.
|
|
222
|
+
*/
|
|
223
|
+
label: _propTypes.default.string,
|
|
224
|
+
|
|
168
225
|
/**
|
|
169
226
|
* If passed, the switch does not respond to user input and may recieve different
|
|
170
227
|
* theme tokens if the theme supports inactive appearance.
|
|
171
228
|
*/
|
|
172
|
-
inactive: _propTypes.default.bool
|
|
229
|
+
inactive: _propTypes.default.bool,
|
|
230
|
+
|
|
231
|
+
/**
|
|
232
|
+
* Content of an optional Tooltip. If set, a tooltip button will be shown next to the label.
|
|
233
|
+
*/
|
|
234
|
+
tooltip: _propTypes.default.string
|
|
173
235
|
};
|
|
174
236
|
|
|
175
237
|
const staticStyles = _StyleSheet.default.create({
|