@telus-uds/components-base 1.8.3 → 1.9.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 +37 -2
- package/component-docs.json +17 -1
- package/lib/ActivityIndicator/Spinner.js +7 -7
- package/lib/ActivityIndicator/Spinner.native.js +2 -2
- package/lib/Button/ButtonBase.js +2 -2
- package/lib/Button/ButtonGroup.js +1 -1
- package/lib/Card/Card.js +9 -4
- package/lib/Checkbox/Checkbox.js +5 -3
- package/lib/Checkbox/CheckboxGroup.js +2 -2
- package/lib/Divider/Divider.js +2 -2
- package/lib/ExpandCollapse/Panel.js +12 -18
- package/lib/FlexGrid/Col/Col.js +1 -1
- package/lib/Icon/Icon.js +1 -1
- package/lib/Link/InlinePressable.js +5 -1
- package/lib/Link/LinkBase.js +5 -2
- package/lib/List/List.js +8 -2
- package/lib/Pagination/PageButton.js +2 -2
- package/lib/Pagination/Pagination.js +5 -3
- package/lib/Pagination/usePagination.js +2 -2
- package/lib/Progress/ProgressBar.js +3 -3
- package/lib/Progress/ProgressBarBackground.js +3 -3
- package/lib/Radio/Radio.js +2 -2
- package/lib/Radio/RadioGroup.js +2 -2
- package/lib/RadioCard/RadioCard.js +1 -1
- package/lib/RadioCard/RadioCardGroup.js +2 -2
- package/lib/Search/Search.js +1 -1
- package/lib/SideNav/SideNav.js +2 -2
- package/lib/Skeleton/Skeleton.js +1 -1
- package/lib/Skeleton/skeletonWebAnimation.js +1 -1
- package/lib/StackView/StackWrap.js +3 -1
- package/lib/StackView/getStackedContent.js +2 -2
- package/lib/Tabs/Tabs.js +28 -3
- package/lib/Tabs/TabsItem.js +5 -6
- package/lib/Tags/Tags.js +1 -1
- package/lib/TextInput/TextInput.js +0 -11
- package/lib/TextInput/TextInputBase.js +9 -0
- package/lib/TextInput/propTypes.js +3 -8
- package/lib/ThemeProvider/utils/styles.js +2 -2
- package/lib/ThemeProvider/utils/theme-tokens.js +7 -9
- package/lib/ToggleSwitch/ToggleSwitch.js +1 -1
- package/lib/ToggleSwitch/ToggleSwitchGroup.js +1 -1
- package/lib/Tooltip/Backdrop.js +2 -10
- package/lib/utils/animation/useVerticalExpandAnimation.js +40 -14
- package/lib/utils/children.js +2 -2
- package/lib/utils/input.js +6 -12
- package/lib/utils/props/componentPropType.js +3 -3
- package/lib/utils/props/selectSystemProps.js +2 -2
- package/lib/utils/props/textInputProps.js +8 -1
- package/lib/utils/props/tokens.js +2 -2
- package/lib/utils/useSpacingScale.js +3 -1
- package/lib/utils/useUniqueId.js +1 -1
- package/lib-module/A11yInfoProvider/index.js +63 -0
- package/lib-module/A11yText/index.js +56 -0
- package/lib-module/ActivityIndicator/Spinner.js +77 -0
- package/lib-module/ActivityIndicator/Spinner.native.js +144 -0
- package/lib-module/ActivityIndicator/index.js +41 -0
- package/lib-module/ActivityIndicator/shared.js +12 -0
- package/lib-module/BaseProvider/index.js +29 -0
- package/lib-module/Box/Box.js +244 -0
- package/lib-module/Box/index.js +2 -0
- package/lib-module/Button/Button.js +26 -0
- package/lib-module/Button/ButtonBase.js +271 -0
- package/lib-module/Button/ButtonGroup.js +247 -0
- package/lib-module/Button/ButtonLink.js +40 -0
- package/lib-module/Button/index.js +4 -0
- package/lib-module/Button/propTypes.js +36 -0
- package/lib-module/Card/Card.js +85 -0
- package/lib-module/Card/CardBase.js +66 -0
- package/lib-module/Card/PressableCardBase.js +114 -0
- package/lib-module/Card/index.js +4 -0
- package/lib-module/Checkbox/Checkbox.js +348 -0
- package/lib-module/Checkbox/CheckboxGroup.js +233 -0
- package/lib-module/Checkbox/CheckboxInput.js +60 -0
- package/lib-module/Checkbox/CheckboxInput.native.js +6 -0
- package/lib-module/Checkbox/index.js +3 -0
- package/lib-module/Divider/Divider.js +124 -0
- package/lib-module/Divider/index.js +2 -0
- package/lib-module/ExpandCollapse/Accordion.js +15 -0
- package/lib-module/ExpandCollapse/Control.js +136 -0
- package/lib-module/ExpandCollapse/ExpandCollapse.js +95 -0
- package/lib-module/ExpandCollapse/Panel.js +159 -0
- package/lib-module/ExpandCollapse/index.js +7 -0
- package/lib-module/Feedback/Feedback.js +157 -0
- package/lib-module/Feedback/index.js +2 -0
- package/lib-module/Fieldset/Fieldset.js +153 -0
- package/lib-module/Fieldset/FieldsetContainer.js +32 -0
- package/lib-module/Fieldset/FieldsetContainer.native.js +23 -0
- package/lib-module/Fieldset/Legend.js +24 -0
- package/lib-module/Fieldset/Legend.native.js +31 -0
- package/lib-module/Fieldset/cssReset.js +14 -0
- package/lib-module/Fieldset/index.js +2 -0
- package/lib-module/FlexGrid/Col/Col.js +276 -0
- package/lib-module/FlexGrid/Col/index.js +2 -0
- package/lib-module/FlexGrid/FlexGrid.js +148 -0
- package/lib-module/FlexGrid/Row/Row.js +184 -0
- package/lib-module/FlexGrid/Row/index.js +2 -0
- package/lib-module/FlexGrid/helpers/index.js +18 -0
- package/lib-module/FlexGrid/index.js +2 -0
- package/lib-module/FlexGrid/providers/GutterContext.js +3 -0
- package/lib-module/HorizontalScroll/HorizontalScroll.js +175 -0
- package/lib-module/HorizontalScroll/HorizontalScrollButton.js +81 -0
- package/lib-module/HorizontalScroll/ScrollViewEnd.js +48 -0
- package/lib-module/HorizontalScroll/ScrollViewEnd.native.js +27 -0
- package/lib-module/HorizontalScroll/dictionary.js +11 -0
- package/lib-module/HorizontalScroll/index.js +11 -0
- package/lib-module/HorizontalScroll/itemPositions.js +112 -0
- package/lib-module/Icon/Icon.js +62 -0
- package/lib-module/Icon/IconText.js +83 -0
- package/lib-module/Icon/index.js +4 -0
- package/lib-module/IconButton/IconButton.js +122 -0
- package/lib-module/IconButton/index.js +2 -0
- package/lib-module/InputLabel/InputLabel.js +148 -0
- package/lib-module/InputLabel/LabelContent.js +27 -0
- package/lib-module/InputLabel/LabelContent.native.js +19 -0
- package/lib-module/InputLabel/index.js +2 -0
- package/lib-module/InputSupports/InputSupports.js +96 -0
- package/lib-module/InputSupports/index.js +2 -0
- package/lib-module/InputSupports/useInputSupports.js +32 -0
- package/lib-module/Link/ChevronLink.js +52 -0
- package/lib-module/Link/InlinePressable.js +44 -0
- package/lib-module/Link/InlinePressable.native.js +89 -0
- package/lib-module/Link/Link.js +28 -0
- package/lib-module/Link/LinkBase.js +243 -0
- package/lib-module/Link/TextButton.js +35 -0
- package/lib-module/Link/index.js +5 -0
- package/lib-module/List/List.js +62 -0
- package/lib-module/List/ListItem.js +248 -0
- package/lib-module/List/index.js +5 -0
- package/lib-module/Modal/Modal.js +222 -0
- package/lib-module/Modal/dictionary.js +9 -0
- package/lib-module/Modal/index.js +2 -0
- package/lib-module/Notification/Notification.js +209 -0
- package/lib-module/Notification/dictionary.js +8 -0
- package/lib-module/Notification/index.js +2 -0
- package/lib-module/Pagination/PageButton.js +66 -0
- package/lib-module/Pagination/Pagination.js +153 -0
- package/lib-module/Pagination/SideButton.js +106 -0
- package/lib-module/Pagination/dictionary.js +18 -0
- package/lib-module/Pagination/index.js +2 -0
- package/lib-module/Pagination/usePagination.js +73 -0
- package/lib-module/Progress/Progress.js +89 -0
- package/lib-module/Progress/ProgressBar.js +138 -0
- package/lib-module/Progress/ProgressBarBackground.js +42 -0
- package/lib-module/Progress/index.js +4 -0
- package/lib-module/Radio/Radio.js +285 -0
- package/lib-module/Radio/RadioButton.js +138 -0
- package/lib-module/Radio/RadioGroup.js +243 -0
- package/lib-module/Radio/RadioInput.js +62 -0
- package/lib-module/Radio/RadioInput.native.js +6 -0
- package/lib-module/Radio/index.js +3 -0
- package/lib-module/RadioCard/RadioCard.js +219 -0
- package/lib-module/RadioCard/RadioCardGroup.js +250 -0
- package/lib-module/RadioCard/index.js +3 -0
- package/lib-module/Search/Search.js +261 -0
- package/lib-module/Search/dictionary.js +12 -0
- package/lib-module/Search/index.js +2 -0
- package/lib-module/Select/Group.js +21 -0
- package/lib-module/Select/Group.native.js +15 -0
- package/lib-module/Select/Item.js +20 -0
- package/lib-module/Select/Item.native.js +3 -0
- package/lib-module/Select/Picker.js +68 -0
- package/lib-module/Select/Picker.native.js +120 -0
- package/lib-module/Select/Select.js +337 -0
- package/lib-module/Select/index.js +6 -0
- package/lib-module/SideNav/Item.js +145 -0
- package/lib-module/SideNav/ItemContent.js +48 -0
- package/lib-module/SideNav/ItemsGroup.js +117 -0
- package/lib-module/SideNav/SideNav.js +136 -0
- package/lib-module/SideNav/index.js +1 -0
- package/lib-module/Skeleton/Skeleton.js +179 -0
- package/lib-module/Skeleton/index.js +2 -0
- package/lib-module/Skeleton/skeleton.constant.js +3 -0
- package/lib-module/Skeleton/skeletonWebAnimation.js +18 -0
- package/lib-module/Skeleton/useSkeletonNativeAnimation.js +24 -0
- package/lib-module/Spacer/Spacer.js +98 -0
- package/lib-module/Spacer/index.js +2 -0
- package/lib-module/StackView/StackView.js +125 -0
- package/lib-module/StackView/StackWrap.js +50 -0
- package/lib-module/StackView/StackWrap.native.js +3 -0
- package/lib-module/StackView/StackWrapBox.js +115 -0
- package/lib-module/StackView/StackWrapGap.js +59 -0
- package/lib-module/StackView/common.js +35 -0
- package/lib-module/StackView/getStackedContent.js +124 -0
- package/lib-module/StackView/index.js +5 -0
- package/lib-module/StepTracker/Step.js +248 -0
- package/lib-module/StepTracker/StepTracker.js +185 -0
- package/lib-module/StepTracker/dictionary.js +10 -0
- package/lib-module/StepTracker/index.js +2 -0
- package/lib-module/Tabs/Tabs.js +143 -0
- package/lib-module/Tabs/TabsItem.js +224 -0
- package/lib-module/Tabs/index.js +2 -0
- package/lib-module/Tags/Tags.js +251 -0
- package/lib-module/Tags/index.js +2 -0
- package/lib-module/TextInput/TextArea.js +94 -0
- package/lib-module/TextInput/TextInput.js +64 -0
- package/lib-module/TextInput/TextInputBase.js +254 -0
- package/lib-module/TextInput/index.js +3 -0
- package/lib-module/TextInput/propTypes.js +33 -0
- package/lib-module/ThemeProvider/ThemeProvider.js +36 -0
- package/lib-module/ThemeProvider/index.js +6 -0
- package/lib-module/ThemeProvider/useSetTheme.js +25 -0
- package/lib-module/ThemeProvider/useTheme.js +14 -0
- package/lib-module/ThemeProvider/useThemeTokens.js +110 -0
- package/lib-module/ThemeProvider/utils/index.js +2 -0
- package/lib-module/ThemeProvider/utils/styles.js +181 -0
- package/lib-module/ThemeProvider/utils/theme-tokens.js +163 -0
- package/lib-module/ToggleSwitch/ToggleSwitch.js +250 -0
- package/lib-module/ToggleSwitch/ToggleSwitchGroup.js +220 -0
- package/lib-module/ToggleSwitch/index.js +3 -0
- package/lib-module/Tooltip/Backdrop.js +45 -0
- package/lib-module/Tooltip/Backdrop.native.js +44 -0
- package/lib-module/Tooltip/Tooltip.js +348 -0
- package/lib-module/Tooltip/dictionary.js +8 -0
- package/lib-module/Tooltip/getTooltipPosition.js +175 -0
- package/lib-module/Tooltip/index.js +2 -0
- package/lib-module/TooltipButton/TooltipButton.js +78 -0
- package/lib-module/TooltipButton/index.js +2 -0
- package/lib-module/Typography/Typography.js +124 -0
- package/lib-module/Typography/index.js +2 -0
- package/lib-module/ViewportProvider/ViewportProvider.js +29 -0
- package/lib-module/ViewportProvider/index.js +3 -0
- package/lib-module/ViewportProvider/useViewport.js +3 -0
- package/lib-module/ViewportProvider/useViewportListener.js +46 -0
- package/lib-module/index.js +48 -0
- package/lib-module/utils/a11y/index.js +2 -0
- package/lib-module/utils/a11y/semantics.js +157 -0
- package/lib-module/utils/a11y/textSize.js +36 -0
- package/lib-module/utils/animation/index.js +2 -0
- package/lib-module/utils/animation/useVerticalExpandAnimation.js +88 -0
- package/lib-module/utils/children.js +119 -0
- package/lib-module/utils/containUniqueFields.js +26 -0
- package/lib-module/utils/index.js +16 -0
- package/lib-module/utils/info/index.js +7 -0
- package/lib-module/utils/info/platform/index.js +11 -0
- package/lib-module/utils/info/platform/platform.android.js +1 -0
- package/lib-module/utils/info/platform/platform.ios.js +1 -0
- package/lib-module/utils/info/platform/platform.js +1 -0
- package/lib-module/utils/info/platform/platform.native.js +4 -0
- package/lib-module/utils/info/versions.js +5 -0
- package/lib-module/utils/input.js +179 -0
- package/lib-module/utils/pressability.js +111 -0
- package/lib-module/utils/props/a11yProps.js +140 -0
- package/lib-module/utils/props/clickProps.js +26 -0
- package/lib-module/utils/props/componentPropType.js +63 -0
- package/lib-module/utils/props/copyPropTypes.js +2 -0
- package/lib-module/utils/props/getPropSelector.js +9 -0
- package/lib-module/utils/props/handlerProps.js +65 -0
- package/lib-module/utils/props/hrefAttrsProp.js +33 -0
- package/lib-module/utils/props/index.js +19 -0
- package/lib-module/utils/props/inputSupportsProps.js +62 -0
- package/lib-module/utils/props/linkProps.js +44 -0
- package/lib-module/utils/props/paddingProp.js +9 -0
- package/lib-module/utils/props/pressProps.js +42 -0
- package/lib-module/utils/props/rectProp.js +9 -0
- package/lib-module/utils/props/responsiveProps.js +30 -0
- package/lib-module/utils/props/selectSystemProps.js +24 -0
- package/lib-module/utils/props/spacingProps.js +56 -0
- package/lib-module/utils/props/textInputProps.js +201 -0
- package/lib-module/utils/props/textProps.js +59 -0
- package/lib-module/utils/props/tokens.js +133 -0
- package/lib-module/utils/props/variantProp.js +18 -0
- package/lib-module/utils/props/viewProps.js +22 -0
- package/lib-module/utils/ssr.js +38 -0
- package/lib-module/utils/useCopy.js +44 -0
- package/lib-module/utils/useHash.js +45 -0
- package/lib-module/utils/useHash.native.js +7 -0
- package/lib-module/utils/useResponsiveProp.js +47 -0
- package/lib-module/utils/useSpacingScale.js +125 -0
- package/lib-module/utils/useUniqueId.js +13 -0
- package/lib-module/utils/withLinkRouter.js +83 -0
- package/package.json +3 -3
- package/src/Card/Card.jsx +6 -4
- package/src/Checkbox/Checkbox.jsx +3 -1
- package/src/ExpandCollapse/Panel.jsx +10 -20
- package/src/Link/InlinePressable.jsx +5 -2
- package/src/Link/LinkBase.jsx +4 -1
- package/src/List/List.jsx +6 -2
- package/src/Tabs/Tabs.jsx +24 -2
- package/src/Tabs/TabsItem.jsx +6 -5
- package/src/TextInput/TextInput.jsx +1 -8
- package/src/TextInput/TextInputBase.jsx +11 -1
- package/src/TextInput/propTypes.js +3 -7
- package/src/utils/animation/useVerticalExpandAnimation.js +47 -13
- package/src/utils/props/textInputProps.js +7 -1
|
@@ -0,0 +1,233 @@
|
|
|
1
|
+
import React, { forwardRef } from 'react';
|
|
2
|
+
import PropTypes from 'prop-types';
|
|
3
|
+
import ABBPropTypes from 'airbnb-prop-types';
|
|
4
|
+
import { useViewport } from '../ViewportProvider';
|
|
5
|
+
import { useThemeTokens } from '../ThemeProvider';
|
|
6
|
+
import { a11yProps, containUniqueFields, focusHandlerProps, getTokensPropType, selectSystemProps, useMultipleInputValues, variantProp, viewProps } from '../utils';
|
|
7
|
+
import { getStackedContent } from '../StackView';
|
|
8
|
+
import Checkbox from './Checkbox';
|
|
9
|
+
import Fieldset from '../Fieldset';
|
|
10
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
11
|
+
const [selectProps, selectedSystemPropTypes] = selectSystemProps([a11yProps, viewProps]);
|
|
12
|
+
const [selectItemProps, selectedItemPropTypes] = selectSystemProps([a11yProps, focusHandlerProps, viewProps]);
|
|
13
|
+
/**
|
|
14
|
+
* A group of Checkboxs that behave as a fieldset. Use when users select any number of choices from options.
|
|
15
|
+
*
|
|
16
|
+
* ## Component API
|
|
17
|
+
*
|
|
18
|
+
* Use the `items` prop to pass an array of objects describing each Checkbox in the group:
|
|
19
|
+
*
|
|
20
|
+
* - `label`: main text passed to CheckboxGroup's `label` prop
|
|
21
|
+
* - `id`: identifier used to store which CheckboxGroup is selected (uses `label` if undefinded)
|
|
22
|
+
* - `onChange`: optional function called on selection, in addition to updating the group's selection state
|
|
23
|
+
*
|
|
24
|
+
* ### Controlled version
|
|
25
|
+
*
|
|
26
|
+
* If the selection state is controlled from outside, it needs to receive `checkedId` and `onChange` props.
|
|
27
|
+
*
|
|
28
|
+
* ### Uncontrolled version
|
|
29
|
+
*
|
|
30
|
+
* If the CheckboxGroup manages its own state, you can use `initialCheckedId` prop to provide the initial value.
|
|
31
|
+
* Whenever the radio card gets toggled, it calls the `onChange` callback with the new value (string).
|
|
32
|
+
*
|
|
33
|
+
* ### Use in forms
|
|
34
|
+
*
|
|
35
|
+
* For web forms, the `name` prop may be used to define the name of the group's `fieldset` and input elements.
|
|
36
|
+
*
|
|
37
|
+
* ### Validation
|
|
38
|
+
*
|
|
39
|
+
* Validation state may be set by passing 'error' or 'success' to the `validation` prop.
|
|
40
|
+
*
|
|
41
|
+
* ## A11y guidelines
|
|
42
|
+
*
|
|
43
|
+
* CheckboxGroup accepts all the common accessibility props, and controls the accessibility state
|
|
44
|
+
* of children like Checkbox and Feedback based on current state.
|
|
45
|
+
*
|
|
46
|
+
* @example
|
|
47
|
+
* ```jsx
|
|
48
|
+
* <CheckboxGroup
|
|
49
|
+
* initialCheckedId="check1"
|
|
50
|
+
* items={[
|
|
51
|
+
* { label: 'Checkbox 1', id: 'check1' },
|
|
52
|
+
* { label: 'Checkbox 2', id: 'check2' },
|
|
53
|
+
* { label: 'Checkbox 3', id: 'check3' }
|
|
54
|
+
* ]}
|
|
55
|
+
* legend="Checkboxes"
|
|
56
|
+
* hint="Choose from these options"
|
|
57
|
+
* />
|
|
58
|
+
* ```
|
|
59
|
+
*/
|
|
60
|
+
|
|
61
|
+
const CheckboxGroup = /*#__PURE__*/forwardRef((_ref, ref) => {
|
|
62
|
+
let {
|
|
63
|
+
tokens,
|
|
64
|
+
radioTokens,
|
|
65
|
+
variant,
|
|
66
|
+
items = [],
|
|
67
|
+
legend,
|
|
68
|
+
tooltip,
|
|
69
|
+
hint,
|
|
70
|
+
validation,
|
|
71
|
+
feedback,
|
|
72
|
+
initialCheckedIds,
|
|
73
|
+
checkedIds,
|
|
74
|
+
onChange,
|
|
75
|
+
readOnly,
|
|
76
|
+
name: inputGroupName,
|
|
77
|
+
inactive,
|
|
78
|
+
...rest
|
|
79
|
+
} = _ref;
|
|
80
|
+
const viewport = useViewport();
|
|
81
|
+
const {
|
|
82
|
+
space,
|
|
83
|
+
fieldSpace
|
|
84
|
+
} = useThemeTokens('CheckboxGroup', tokens, variant, {
|
|
85
|
+
viewport
|
|
86
|
+
});
|
|
87
|
+
const {
|
|
88
|
+
currentValues,
|
|
89
|
+
toggleOneValue
|
|
90
|
+
} = useMultipleInputValues({
|
|
91
|
+
values: checkedIds,
|
|
92
|
+
initialValues: initialCheckedIds,
|
|
93
|
+
onChange,
|
|
94
|
+
readOnly: readOnly || inactive
|
|
95
|
+
});
|
|
96
|
+
const uniqueFields = ['id', 'label'];
|
|
97
|
+
|
|
98
|
+
if (!containUniqueFields(items, uniqueFields)) {
|
|
99
|
+
throw new Error("CheckboxGroup items must have unique ".concat(uniqueFields.join(', ')));
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
const checkboxes = items.map((_ref2, index) => {
|
|
103
|
+
let {
|
|
104
|
+
label,
|
|
105
|
+
id,
|
|
106
|
+
onChange: itemOnChange,
|
|
107
|
+
ref: itemRef,
|
|
108
|
+
...itemRest
|
|
109
|
+
} = _ref2;
|
|
110
|
+
const checkboxId = id || "Checkbox[".concat(index, "]");
|
|
111
|
+
|
|
112
|
+
const handleChange = (newCheckedState, event) => {
|
|
113
|
+
if (typeof itemOnChange === 'function') itemOnChange(newCheckedState, event);
|
|
114
|
+
toggleOneValue(checkboxId, event);
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
return /*#__PURE__*/_jsx(Checkbox, {
|
|
118
|
+
ref: itemRef,
|
|
119
|
+
id: checkboxId,
|
|
120
|
+
checked: currentValues.includes(checkboxId),
|
|
121
|
+
onChange: handleChange,
|
|
122
|
+
inactive: inactive,
|
|
123
|
+
label: label,
|
|
124
|
+
name: inputGroupName,
|
|
125
|
+
tokens: radioTokens,
|
|
126
|
+
variant: variant,
|
|
127
|
+
...selectItemProps(itemRest)
|
|
128
|
+
}, checkboxId);
|
|
129
|
+
});
|
|
130
|
+
return /*#__PURE__*/_jsx(Fieldset, {
|
|
131
|
+
ref: ref,
|
|
132
|
+
name: inputGroupName,
|
|
133
|
+
legend: legend,
|
|
134
|
+
tooltip: tooltip,
|
|
135
|
+
hint: hint,
|
|
136
|
+
space: fieldSpace,
|
|
137
|
+
feedback: feedback,
|
|
138
|
+
inactive: inactive,
|
|
139
|
+
validation: validation,
|
|
140
|
+
...selectProps(rest),
|
|
141
|
+
children: getStackedContent(checkboxes, {
|
|
142
|
+
space,
|
|
143
|
+
direction: 'column'
|
|
144
|
+
})
|
|
145
|
+
});
|
|
146
|
+
});
|
|
147
|
+
CheckboxGroup.displayName = 'CheckboxGroup';
|
|
148
|
+
CheckboxGroup.propTypes = { ...selectedSystemPropTypes,
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* Optional theme token overrides for the outer CheckboxGroup component
|
|
152
|
+
*/
|
|
153
|
+
tokens: getTokensPropType('CheckboxGroup'),
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* Optional theme token overrides for each inner Checkbox component
|
|
157
|
+
*/
|
|
158
|
+
radioTokens: getTokensPropType('Checkbox'),
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* Theme variants, shared between both CheckboxGroup and Checkbox
|
|
162
|
+
*/
|
|
163
|
+
variant: variantProp.propType,
|
|
164
|
+
|
|
165
|
+
/**
|
|
166
|
+
* Array of objects containing specifics for each Checkbox to be rendered in the group.
|
|
167
|
+
*/
|
|
168
|
+
items: PropTypes.arrayOf(PropTypes.exact({ ...selectedItemPropTypes,
|
|
169
|
+
label: PropTypes.string,
|
|
170
|
+
id: PropTypes.string,
|
|
171
|
+
onChange: PropTypes.func,
|
|
172
|
+
ref: ABBPropTypes.ref()
|
|
173
|
+
})),
|
|
174
|
+
|
|
175
|
+
/**
|
|
176
|
+
* Main text used to describe this group, used in Fieldset's Legend element.
|
|
177
|
+
*/
|
|
178
|
+
legend: PropTypes.string,
|
|
179
|
+
|
|
180
|
+
/**
|
|
181
|
+
* Optional additional text giving more detail to help a user make a choice.
|
|
182
|
+
*/
|
|
183
|
+
hint: PropTypes.string,
|
|
184
|
+
|
|
185
|
+
/**
|
|
186
|
+
* Optional tooltip text content to include alongside the legend and hint.
|
|
187
|
+
*/
|
|
188
|
+
tooltip: PropTypes.string,
|
|
189
|
+
|
|
190
|
+
/**
|
|
191
|
+
* Current validation status of the group, passed to the feedback element if there is one.
|
|
192
|
+
*/
|
|
193
|
+
validation: PropTypes.oneOf(['error', 'success']),
|
|
194
|
+
|
|
195
|
+
/**
|
|
196
|
+
* If provided, a Feedback element is rendered containing this text.
|
|
197
|
+
*/
|
|
198
|
+
feedback: PropTypes.string,
|
|
199
|
+
|
|
200
|
+
/**
|
|
201
|
+
* If provided, the checkboxed with this ids are selected on first render.
|
|
202
|
+
*/
|
|
203
|
+
initialCheckedIds: PropTypes.arrayOf(PropTypes.string),
|
|
204
|
+
|
|
205
|
+
/**
|
|
206
|
+
* If not undefined, the checkboxes with these ids is selected, and the
|
|
207
|
+
* element's selection state will be controlled by its parent using the `onChange` function.
|
|
208
|
+
*/
|
|
209
|
+
checkedIds: PropTypes.arrayOf(PropTypes.string),
|
|
210
|
+
|
|
211
|
+
/**
|
|
212
|
+
* Function to call on change in selection state. Is required if the selection state is controlled
|
|
213
|
+
* by a parent using checkedId and the input is not readOnly.
|
|
214
|
+
*/
|
|
215
|
+
onChange: PropTypes.func,
|
|
216
|
+
|
|
217
|
+
/**
|
|
218
|
+
* If true, the checkboxes cannot be selected by the user and simply show their current state.
|
|
219
|
+
*/
|
|
220
|
+
readOnly: PropTypes.bool,
|
|
221
|
+
|
|
222
|
+
/**
|
|
223
|
+
* If true, the checkboxes cannot be interacted with, elements are set as `disabled` and if the
|
|
224
|
+
* theme supports `inactive` appearances rules, these are applied.
|
|
225
|
+
*/
|
|
226
|
+
inactive: PropTypes.bool,
|
|
227
|
+
|
|
228
|
+
/**
|
|
229
|
+
* On Web, this is passed to the `name` attribute of the fieldset and each checkbox input.
|
|
230
|
+
*/
|
|
231
|
+
name: PropTypes.string
|
|
232
|
+
};
|
|
233
|
+
export default CheckboxGroup;
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import React, { forwardRef } from 'react';
|
|
2
|
+
import PropTypes from 'prop-types';
|
|
3
|
+
/**
|
|
4
|
+
* On Web we need to include an actual input but hide it.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
8
|
+
const CheckboxInput = /*#__PURE__*/forwardRef((_ref, ref) => {
|
|
9
|
+
let {
|
|
10
|
+
checked,
|
|
11
|
+
defaultChecked,
|
|
12
|
+
disabled,
|
|
13
|
+
id,
|
|
14
|
+
isControlled,
|
|
15
|
+
name,
|
|
16
|
+
onChange,
|
|
17
|
+
value
|
|
18
|
+
} = _ref;
|
|
19
|
+
|
|
20
|
+
const handleClick = event => {
|
|
21
|
+
// Cancel the click dispatched via the label tag, since it's already wrapped
|
|
22
|
+
// in <Pressable>
|
|
23
|
+
event.preventDefault();
|
|
24
|
+
event.stopPropagation();
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
return /*#__PURE__*/_jsx("input", {
|
|
28
|
+
checked: isControlled ? checked : undefined,
|
|
29
|
+
defaultChecked: isControlled ? undefined : defaultChecked,
|
|
30
|
+
disabled: disabled,
|
|
31
|
+
hidden: true,
|
|
32
|
+
id: id,
|
|
33
|
+
name: name,
|
|
34
|
+
onChange: onChange,
|
|
35
|
+
onClick: handleClick,
|
|
36
|
+
ref: ref,
|
|
37
|
+
type: "checkbox",
|
|
38
|
+
value: value
|
|
39
|
+
});
|
|
40
|
+
});
|
|
41
|
+
CheckboxInput.displayName = 'CheckboxInput';
|
|
42
|
+
CheckboxInput.propTypes = {
|
|
43
|
+
checked: PropTypes.bool,
|
|
44
|
+
defaultChecked: PropTypes.bool,
|
|
45
|
+
disabled: PropTypes.bool,
|
|
46
|
+
id: PropTypes.string.isRequired,
|
|
47
|
+
isControlled: PropTypes.bool.isRequired,
|
|
48
|
+
name: PropTypes.string,
|
|
49
|
+
onChange: PropTypes.func,
|
|
50
|
+
value: PropTypes.string
|
|
51
|
+
};
|
|
52
|
+
CheckboxInput.defaultProps = {
|
|
53
|
+
checked: undefined,
|
|
54
|
+
defaultChecked: undefined,
|
|
55
|
+
disabled: false,
|
|
56
|
+
name: undefined,
|
|
57
|
+
onChange: () => {},
|
|
58
|
+
value: undefined
|
|
59
|
+
};
|
|
60
|
+
export default CheckboxInput;
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import React, { forwardRef } from 'react';
|
|
2
|
+
import PropTypes from 'prop-types';
|
|
3
|
+
import View from "react-native-web/dist/exports/View";
|
|
4
|
+
import StyleSheet from "react-native-web/dist/exports/StyleSheet";
|
|
5
|
+
import Platform from "react-native-web/dist/exports/Platform";
|
|
6
|
+
import { useThemeTokens } from '../ThemeProvider';
|
|
7
|
+
import Spacer from '../Spacer';
|
|
8
|
+
import { a11yProps, getTokensPropType, selectSystemProps, spacingProps, variantProp, viewProps } from '../utils';
|
|
9
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
10
|
+
import { Fragment as _Fragment } from "react/jsx-runtime";
|
|
11
|
+
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
12
|
+
const [selectProps, selectedSystemPropTypes] = selectSystemProps([a11yProps, viewProps]);
|
|
13
|
+
/**
|
|
14
|
+
* @typedef {import('../utils/props/spacingProps.js').SpacingIndex} SpacingIndex
|
|
15
|
+
* @typedef {import('../utils/props/spacingProps.js').SpacingObject} SpacingObject
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* A basic divider component, horizontal by default. Color and thickness can be controlled by theme.
|
|
20
|
+
* Divider is based on the flexbox model and uses `alignSelf: flex` to span its flex parent.
|
|
21
|
+
*
|
|
22
|
+
* ## Vertical
|
|
23
|
+
*
|
|
24
|
+
* Vertical dividers can be created by passing a `vertical` boolean prop.
|
|
25
|
+
* Note that for a vertical divider the parent flex element **must** have flex direction set to row.
|
|
26
|
+
* This is the default for web but not for React Native.
|
|
27
|
+
*
|
|
28
|
+
* In a flexbox row, vertical dividers will automatically size to their parent height.
|
|
29
|
+
*
|
|
30
|
+
* ## Space
|
|
31
|
+
*
|
|
32
|
+
* Use this to create **space either side of the divider**. For simple cases, pass a number referring to
|
|
33
|
+
* a position on the theme's spacing scale; for example, this will put a Spacer of the smallest supported
|
|
34
|
+
* size either side of the divider:
|
|
35
|
+
*
|
|
36
|
+
* ```jsx
|
|
37
|
+
* <Divider space={1} />
|
|
38
|
+
* ```
|
|
39
|
+
*
|
|
40
|
+
* `space` prop uses `useSpacingScale` and may accept a {@link SpacingObject} or a {@link SpacingIndex} number.
|
|
41
|
+
*
|
|
42
|
+
* To **reduce the length of a divider** as well as creating space between it and its neighbours, wrap it in
|
|
43
|
+
* a `Box` component. For example, this will have the second-smallest theme-supported spacing value between
|
|
44
|
+
* the dividing line and its neighbours, and will shorten the line at either end by the same amount:
|
|
45
|
+
*
|
|
46
|
+
* ```jsx
|
|
47
|
+
* <Box space={2}><Divider /></Box>
|
|
48
|
+
* ```
|
|
49
|
+
*
|
|
50
|
+
* ## Accessibility
|
|
51
|
+
*
|
|
52
|
+
* For accessibility purposes a divider component will be described with ARIA attributes, i.e. `role="separator"` and `aria-orientation="vertical/horizontal"`.
|
|
53
|
+
*/
|
|
54
|
+
|
|
55
|
+
const Divider = /*#__PURE__*/forwardRef((_ref, ref) => {
|
|
56
|
+
let {
|
|
57
|
+
variant,
|
|
58
|
+
vertical = false,
|
|
59
|
+
space,
|
|
60
|
+
tokens,
|
|
61
|
+
...rest
|
|
62
|
+
} = _ref;
|
|
63
|
+
const {
|
|
64
|
+
color,
|
|
65
|
+
width
|
|
66
|
+
} = useThemeTokens('Divider', tokens, variant);
|
|
67
|
+
const borderStyles = vertical ? {
|
|
68
|
+
borderRightColor: color,
|
|
69
|
+
borderRightWidth: width
|
|
70
|
+
} : {
|
|
71
|
+
borderBottomColor: color,
|
|
72
|
+
borderBottomWidth: width
|
|
73
|
+
};
|
|
74
|
+
const a11y = Platform.OS === 'web' ? // There are aria attributes for dividers on web
|
|
75
|
+
{
|
|
76
|
+
'aria-orientation': vertical ? 'vertical' : 'horizontal',
|
|
77
|
+
accessibilityRole: 'separator'
|
|
78
|
+
} : // There are no such equivalent attributes for native
|
|
79
|
+
{};
|
|
80
|
+
const {
|
|
81
|
+
testID,
|
|
82
|
+
...selectedProps
|
|
83
|
+
} = selectProps({ ...a11y,
|
|
84
|
+
...rest
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
const divider = /*#__PURE__*/_jsx(View, {
|
|
88
|
+
ref: ref,
|
|
89
|
+
style: [styles.divider, borderStyles],
|
|
90
|
+
testID: testID,
|
|
91
|
+
...selectedProps
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
if (!space) return divider;
|
|
95
|
+
const spacerProps = {
|
|
96
|
+
space,
|
|
97
|
+
direction: vertical ? 'row' : 'column'
|
|
98
|
+
};
|
|
99
|
+
return /*#__PURE__*/_jsxs(_Fragment, {
|
|
100
|
+
children: [/*#__PURE__*/_jsx(Spacer, { ...spacerProps,
|
|
101
|
+
testID: testID ? "".concat(testID, "-Spacer-before") : undefined
|
|
102
|
+
}), divider, /*#__PURE__*/_jsx(Spacer, { ...spacerProps,
|
|
103
|
+
testID: testID ? "".concat(testID, "-Spacer-after") : undefined
|
|
104
|
+
})]
|
|
105
|
+
});
|
|
106
|
+
});
|
|
107
|
+
Divider.displayName = 'Divider';
|
|
108
|
+
Divider.propTypes = { ...selectedSystemPropTypes,
|
|
109
|
+
tokens: getTokensPropType('Divider'),
|
|
110
|
+
space: spacingProps.types.spacingValue,
|
|
111
|
+
variant: variantProp.propType,
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* By default, the divider is a horizontal line the full width of its parent.
|
|
115
|
+
* With `vertical` prop and when inside a container with { flexDirection: row }, draws a full height vertical line.
|
|
116
|
+
*/
|
|
117
|
+
vertical: PropTypes.bool
|
|
118
|
+
};
|
|
119
|
+
const styles = StyleSheet.create({
|
|
120
|
+
divider: {
|
|
121
|
+
alignSelf: 'stretch'
|
|
122
|
+
}
|
|
123
|
+
});
|
|
124
|
+
export default Divider;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import React, { forwardRef } from 'react';
|
|
2
|
+
import ExpandCollapse from './ExpandCollapse';
|
|
3
|
+
/**
|
|
4
|
+
* 'Accordion' is a shorthand for an ExpandCollapse where only one item may be open at a time
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
8
|
+
const Accordion = /*#__PURE__*/forwardRef((props, ref) => /*#__PURE__*/_jsx(ExpandCollapse, {
|
|
9
|
+
ref: ref,
|
|
10
|
+
...props,
|
|
11
|
+
maxOpen: 1
|
|
12
|
+
}));
|
|
13
|
+
Accordion.displayName = 'Accordion';
|
|
14
|
+
Accordion.propTypes = ExpandCollapse.propTypes;
|
|
15
|
+
export default Accordion;
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
import React, { forwardRef } from 'react';
|
|
2
|
+
import Pressable from "react-native-web/dist/exports/Pressable";
|
|
3
|
+
import View from "react-native-web/dist/exports/View";
|
|
4
|
+
import PropTypes from 'prop-types';
|
|
5
|
+
import { useThemeTokensCallback, verticalAlignRow } from '../ThemeProvider';
|
|
6
|
+
import { a11yProps, getTokensPropType, selectSystemProps, variantProp, viewProps } from '../utils';
|
|
7
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
8
|
+
import { Fragment as _Fragment } from "react/jsx-runtime";
|
|
9
|
+
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
10
|
+
const [selectProps, selectedSystemPropTypes] = selectSystemProps([a11yProps, viewProps]);
|
|
11
|
+
|
|
12
|
+
function selectContainerStyles(_ref) {
|
|
13
|
+
let {
|
|
14
|
+
backgroundColor,
|
|
15
|
+
borderColor,
|
|
16
|
+
borderWidth,
|
|
17
|
+
borderStyle,
|
|
18
|
+
paddingLeft,
|
|
19
|
+
paddingRight,
|
|
20
|
+
paddingTop,
|
|
21
|
+
paddingBottom,
|
|
22
|
+
justifyContent,
|
|
23
|
+
verticalAlign,
|
|
24
|
+
iconPosition
|
|
25
|
+
} = _ref;
|
|
26
|
+
return {
|
|
27
|
+
backgroundColor,
|
|
28
|
+
borderTopColor: borderColor,
|
|
29
|
+
borderTopWidth: borderWidth,
|
|
30
|
+
borderTopStyle: borderStyle,
|
|
31
|
+
paddingLeft,
|
|
32
|
+
paddingRight,
|
|
33
|
+
paddingTop,
|
|
34
|
+
paddingBottom,
|
|
35
|
+
justifyContent,
|
|
36
|
+
...verticalAlignRow(verticalAlign, iconPosition === 'right')
|
|
37
|
+
};
|
|
38
|
+
} // TODO: use stack / spacer when available
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
function selectIconContainerStyles(_ref2) {
|
|
42
|
+
let {
|
|
43
|
+
iconGap,
|
|
44
|
+
iconPosition
|
|
45
|
+
} = _ref2;
|
|
46
|
+
const paddingSide = iconPosition === 'right' ? 'paddingLeft' : 'paddingRight';
|
|
47
|
+
return {
|
|
48
|
+
[paddingSide]: iconGap
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function selectIconTokens(tokens) {
|
|
53
|
+
return {
|
|
54
|
+
color: tokens.iconColor,
|
|
55
|
+
size: tokens.iconSize
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const ExpandCollapseControl = /*#__PURE__*/forwardRef((_ref3, ref) => {
|
|
60
|
+
let {
|
|
61
|
+
onPress,
|
|
62
|
+
isExpanded,
|
|
63
|
+
children,
|
|
64
|
+
tokens,
|
|
65
|
+
accessibilityRole = 'button',
|
|
66
|
+
variant,
|
|
67
|
+
...rest
|
|
68
|
+
} = _ref3;
|
|
69
|
+
const getTokens = useThemeTokensCallback('ExpandCollapseControl', tokens, variant);
|
|
70
|
+
const selectedProps = selectProps({ ...rest,
|
|
71
|
+
accessibilityRole
|
|
72
|
+
});
|
|
73
|
+
selectedProps.accessibilityState = { ...(selectedProps.accessibilityState || {}),
|
|
74
|
+
expanded: isExpanded
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
const getControlState = _ref4 => {
|
|
78
|
+
let {
|
|
79
|
+
pressed,
|
|
80
|
+
hovered,
|
|
81
|
+
focused
|
|
82
|
+
} = _ref4;
|
|
83
|
+
return {
|
|
84
|
+
pressed,
|
|
85
|
+
hover: hovered,
|
|
86
|
+
focus: focused,
|
|
87
|
+
expanded: isExpanded
|
|
88
|
+
};
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
const getControlTokens = pressableState => getTokens(getControlState(pressableState));
|
|
92
|
+
|
|
93
|
+
const getPressableStyle = pressableState => selectContainerStyles(getControlTokens(pressableState));
|
|
94
|
+
|
|
95
|
+
return /*#__PURE__*/_jsx(Pressable, {
|
|
96
|
+
ref: ref,
|
|
97
|
+
...selectedProps,
|
|
98
|
+
onPress: onPress,
|
|
99
|
+
style: getPressableStyle,
|
|
100
|
+
children: pressableState => {
|
|
101
|
+
const {
|
|
102
|
+
icon: IconComponent,
|
|
103
|
+
...themeTokens
|
|
104
|
+
} = getControlTokens(pressableState);
|
|
105
|
+
return /*#__PURE__*/_jsxs(_Fragment, {
|
|
106
|
+
children: [IconComponent && /*#__PURE__*/_jsx(View, {
|
|
107
|
+
style: selectIconContainerStyles(themeTokens),
|
|
108
|
+
children: /*#__PURE__*/_jsx(IconComponent, { ...selectIconTokens(themeTokens)
|
|
109
|
+
})
|
|
110
|
+
}), typeof children === 'function' ? children(getControlState(pressableState)) : children]
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
});
|
|
114
|
+
});
|
|
115
|
+
ExpandCollapseControl.displayName = 'ExpandCollapseControl';
|
|
116
|
+
ExpandCollapseControl.propTypes = { ...selectedSystemPropTypes,
|
|
117
|
+
tokens: getTokensPropType('ExpandCollapseControl'),
|
|
118
|
+
variant: variantProp.propType,
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* ExpandCollapseControl's children are the content within the button that opens or closes this panel. May
|
|
122
|
+
* accept a render function that recieves the control state: { pressed, hover, focus, expanded }
|
|
123
|
+
*/
|
|
124
|
+
children: PropTypes.oneOfType([PropTypes.node, PropTypes.func]),
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* Whether the linked ExpandCollapsePanel is opened or closed. Allows themes to set `expanded` styles.
|
|
128
|
+
*/
|
|
129
|
+
isExpanded: PropTypes.bool,
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* Function called when the ExpandCollapse is pressed.
|
|
133
|
+
*/
|
|
134
|
+
onPress: PropTypes.func.isRequired
|
|
135
|
+
};
|
|
136
|
+
export default ExpandCollapseControl;
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import React, { forwardRef } from 'react';
|
|
2
|
+
import View from "react-native-web/dist/exports/View";
|
|
3
|
+
import PropTypes from 'prop-types';
|
|
4
|
+
import { useThemeTokens } from '../ThemeProvider';
|
|
5
|
+
import { a11yProps, getTokensPropType, selectSystemProps, useMultipleInputValues, variantProp, viewProps } from '../utils';
|
|
6
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
7
|
+
const [selectProps, selectedSystemPropTypes] = selectSystemProps([a11yProps, viewProps]);
|
|
8
|
+
|
|
9
|
+
function selectBorderStyles(tokens) {
|
|
10
|
+
return {
|
|
11
|
+
borderBottomWidth: tokens.borderWidth,
|
|
12
|
+
borderBottomStyle: tokens.borderStyle,
|
|
13
|
+
borderBottomColor: tokens.borderColor
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Flexible base component for lists where some or all items are collapsible headers.
|
|
18
|
+
*
|
|
19
|
+
* Pass a render function as `children` which takes and passes `openIds` and `onToggle` props to
|
|
20
|
+
* <ExpandCollapse.Panel> children, and assign the panels explicit `panelId` props. The panels may be
|
|
21
|
+
* nested (they do not need to be direct children), and non-interactive items may be included too.
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
const ExpandCollapse = /*#__PURE__*/forwardRef((_ref, ref) => {
|
|
26
|
+
let {
|
|
27
|
+
children,
|
|
28
|
+
tokens,
|
|
29
|
+
variant,
|
|
30
|
+
maxOpen,
|
|
31
|
+
open,
|
|
32
|
+
initialOpen,
|
|
33
|
+
onChange,
|
|
34
|
+
...rest
|
|
35
|
+
} = _ref;
|
|
36
|
+
const {
|
|
37
|
+
currentValues: openIds,
|
|
38
|
+
toggleOneValue: onToggle,
|
|
39
|
+
resetValues,
|
|
40
|
+
setValues,
|
|
41
|
+
unsetValues
|
|
42
|
+
} = useMultipleInputValues({
|
|
43
|
+
maxValues: maxOpen,
|
|
44
|
+
values: open,
|
|
45
|
+
initialValues: initialOpen,
|
|
46
|
+
onChange
|
|
47
|
+
});
|
|
48
|
+
const themeTokens = useThemeTokens('ExpandCollapse', tokens, variant);
|
|
49
|
+
return /*#__PURE__*/_jsx(View, {
|
|
50
|
+
ref: ref,
|
|
51
|
+
style: selectBorderStyles(themeTokens),
|
|
52
|
+
...selectProps(rest),
|
|
53
|
+
children: typeof children === 'function' ? children({
|
|
54
|
+
openIds,
|
|
55
|
+
onToggle,
|
|
56
|
+
resetValues,
|
|
57
|
+
setValues,
|
|
58
|
+
unsetValues
|
|
59
|
+
}) : children
|
|
60
|
+
});
|
|
61
|
+
});
|
|
62
|
+
ExpandCollapse.displayName = 'ExpandCollapse';
|
|
63
|
+
ExpandCollapse.propTypes = { ...selectedSystemPropTypes,
|
|
64
|
+
variant: variantProp.propType,
|
|
65
|
+
tokens: getTokensPropType('ExpandCollapse'),
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* ExpandCollapse usually takes a render function to which it passes an object with properties
|
|
69
|
+
* { openIds, onToggle, resetValues, setValues, unsetValues }. openIds (array of ids) and
|
|
70
|
+
* onToggle (function) will usually be passed to `<ExpandCollapse.Panel>`
|
|
71
|
+
*/
|
|
72
|
+
children: PropTypes.oneOfType([PropTypes.func, PropTypes.node]).isRequired,
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* If set, enforces a specific maximum number of open items, closing already-open items when new
|
|
76
|
+
* items are opened. By default, any number of items may be open at once.
|
|
77
|
+
*/
|
|
78
|
+
maxOpen: PropTypes.number,
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* If passed, the item or items that are expanded will be controlled by a parent component
|
|
82
|
+
*/
|
|
83
|
+
open: PropTypes.arrayOf(PropTypes.string),
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Function called when which panels are currently open changes. Necessary if `open` is passed.
|
|
87
|
+
*/
|
|
88
|
+
onChange: PropTypes.func,
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Allows items with specified ids to be open by default on first load. Should not be used with `open`.
|
|
92
|
+
*/
|
|
93
|
+
initialOpen: PropTypes.arrayOf(PropTypes.string)
|
|
94
|
+
};
|
|
95
|
+
export default ExpandCollapse;
|