@telus-uds/components-base 0.0.2-prerelease.3 → 0.0.2-prerelease.7
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 -0
- package/CHANGELOG.md +55 -0
- package/__fixtures__/testTheme.js +528 -42
- package/__tests__/Button/ButtonBase.test.jsx +3 -32
- package/__tests__/Checkbox/Checkbox.test.jsx +94 -0
- package/__tests__/Divider/Divider.test.jsx +26 -5
- package/__tests__/Feedback/Feedback.test.jsx +42 -0
- package/__tests__/FlexGrid/Col.test.jsx +5 -0
- package/__tests__/InputSupports/InputSupports.test.jsx +50 -0
- package/__tests__/List/List.test.jsx +60 -0
- package/__tests__/Radio/Radio.test.jsx +87 -0
- package/__tests__/Select/Select.test.jsx +93 -0
- package/__tests__/Skeleton/Skeleton.test.jsx +61 -0
- package/__tests__/Spacer/Spacer.test.jsx +63 -0
- package/__tests__/StackView/StackView.test.jsx +216 -0
- package/__tests__/StackView/StackWrap.test.jsx +47 -0
- package/__tests__/StackView/getStackedContent.test.jsx +295 -0
- package/__tests__/Tags/Tags.test.jsx +328 -0
- package/__tests__/TextInput/TextArea.test.jsx +34 -0
- package/__tests__/TextInput/TextInputBase.test.jsx +120 -0
- package/__tests__/Tooltip/Tooltip.test.jsx +65 -0
- package/__tests__/Tooltip/getTooltipPosition.test.js +79 -0
- package/__tests__/utils/useCopy.test.js +31 -0
- package/__tests__/utils/useResponsiveProp.test.jsx +202 -0
- package/__tests__/utils/{spacing.test.jsx → useSpacingScale.test.jsx} +1 -1
- package/__tests__/utils/useUniqueId.test.js +31 -0
- package/jest.config.js +8 -2
- package/lib/Box/Box.js +7 -2
- package/lib/Button/Button.js +10 -3
- package/lib/Button/ButtonBase.js +79 -75
- package/lib/Button/ButtonGroup.js +24 -49
- package/lib/Button/ButtonLink.js +5 -0
- package/lib/Checkbox/Checkbox.js +308 -0
- package/lib/Checkbox/CheckboxInput.native.js +6 -0
- package/lib/Checkbox/CheckboxInput.web.js +57 -0
- package/lib/Checkbox/index.js +2 -0
- package/lib/Divider/Divider.js +40 -2
- package/lib/Feedback/Feedback.js +132 -0
- package/lib/Feedback/index.js +2 -0
- package/lib/Icon/Icon.js +9 -6
- package/lib/Icon/IconText.js +72 -0
- package/lib/Icon/index.js +2 -1
- package/lib/InputLabel/InputLabel.js +88 -0
- package/lib/InputLabel/LabelContent.native.js +8 -0
- package/lib/InputLabel/LabelContent.web.js +17 -0
- package/lib/InputLabel/index.js +2 -0
- package/lib/InputSupports/InputSupports.js +90 -0
- package/lib/InputSupports/index.js +2 -0
- package/lib/InputSupports/propTypes.js +55 -0
- package/lib/Link/ChevronLink.js +35 -10
- package/lib/Link/InlinePressable.native.js +78 -0
- package/lib/Link/InlinePressable.web.js +32 -0
- package/lib/Link/Link.js +11 -10
- package/lib/Link/LinkBase.js +69 -124
- package/lib/Link/TextButton.js +20 -9
- package/lib/Link/index.js +2 -1
- package/lib/List/List.js +52 -0
- package/lib/List/ListItem.js +207 -0
- package/lib/List/index.js +2 -0
- package/lib/Pagination/PageButton.js +3 -26
- package/lib/Pagination/SideButton.js +32 -42
- package/lib/Radio/Radio.js +291 -0
- package/lib/Radio/RadioInput.native.js +6 -0
- package/lib/Radio/RadioInput.web.js +59 -0
- package/lib/Radio/index.js +2 -0
- package/lib/Select/Group.native.js +14 -0
- package/lib/Select/Group.web.js +18 -0
- package/lib/Select/Item.native.js +9 -0
- package/lib/Select/Item.web.js +15 -0
- package/lib/Select/Picker.native.js +87 -0
- package/lib/Select/Picker.web.js +63 -0
- package/lib/Select/Select.js +272 -0
- package/lib/Select/index.js +6 -0
- package/lib/Skeleton/Skeleton.js +119 -0
- package/lib/Skeleton/index.js +2 -0
- package/lib/Spacer/Spacer.js +98 -0
- package/lib/Spacer/index.js +2 -0
- package/lib/StackView/StackView.js +107 -0
- package/lib/StackView/StackWrap.js +32 -0
- package/lib/StackView/StackWrap.native.js +3 -0
- package/lib/StackView/StackWrapBox.js +90 -0
- package/lib/StackView/StackWrapGap.js +50 -0
- package/lib/StackView/common.js +30 -0
- package/lib/StackView/getStackedContent.js +111 -0
- package/lib/StackView/index.js +5 -0
- package/lib/Tags/Tags.js +217 -0
- package/lib/Tags/index.js +2 -0
- package/lib/TextInput/TextArea.js +82 -0
- package/lib/TextInput/TextInput.js +54 -0
- package/lib/TextInput/TextInputBase.js +229 -0
- package/lib/TextInput/index.js +3 -0
- package/lib/TextInput/propTypes.js +31 -0
- package/lib/ThemeProvider/useThemeTokens.js +54 -3
- package/lib/ToggleSwitch/ToggleSwitch.js +1 -1
- package/lib/Tooltip/Backdrop.native.js +35 -0
- package/lib/Tooltip/Backdrop.web.js +52 -0
- package/lib/Tooltip/Tooltip.js +315 -0
- package/lib/Tooltip/dictionary.js +8 -0
- package/lib/Tooltip/getTooltipPosition.js +164 -0
- package/lib/Tooltip/index.js +2 -0
- package/lib/TooltipButton/TooltipButton.js +64 -0
- package/lib/TooltipButton/index.js +2 -0
- package/lib/Typography/Typography.js +4 -23
- package/lib/ViewportProvider/ViewportProvider.js +25 -0
- package/lib/ViewportProvider/index.js +2 -43
- package/lib/ViewportProvider/useViewport.js +3 -0
- package/lib/ViewportProvider/useViewportListener.js +43 -0
- package/lib/index.js +15 -1
- package/lib/utils/a11y/index.js +1 -0
- package/lib/utils/a11y/textSize.js +33 -0
- package/lib/utils/index.js +7 -1
- package/lib/utils/info/index.js +7 -0
- package/lib/utils/info/platform/index.js +11 -0
- package/lib/utils/info/platform/platform.android.js +1 -0
- package/lib/utils/info/platform/platform.ios.js +1 -0
- package/lib/utils/info/platform/platform.native.js +4 -0
- package/lib/utils/info/platform/platform.web.js +1 -0
- package/lib/utils/info/versions.js +5 -0
- package/lib/utils/input.js +3 -1
- package/lib/utils/pressability.js +92 -0
- package/lib/utils/propTypes.js +77 -8
- package/lib/utils/useCopy.js +16 -0
- package/lib/utils/useResponsiveProp.js +47 -0
- package/lib/utils/{spacing/useSpacingScale.js → useSpacingScale.js} +30 -9
- package/lib/utils/useUniqueId.js +12 -0
- package/package.json +7 -5
- package/release-context.json +4 -4
- package/src/Box/Box.jsx +4 -2
- package/src/Button/Button.jsx +6 -3
- package/src/Button/ButtonBase.jsx +72 -75
- package/src/Button/ButtonGroup.jsx +22 -39
- package/src/Button/ButtonLink.jsx +11 -2
- package/src/Checkbox/Checkbox.jsx +275 -0
- package/src/Checkbox/CheckboxInput.native.jsx +6 -0
- package/src/Checkbox/CheckboxInput.web.jsx +55 -0
- package/src/Checkbox/index.js +3 -0
- package/src/Divider/Divider.jsx +38 -3
- package/src/Feedback/Feedback.jsx +108 -0
- package/src/Feedback/index.js +3 -0
- package/src/Icon/Icon.jsx +11 -6
- package/src/Icon/IconText.jsx +63 -0
- package/src/Icon/index.js +2 -1
- package/src/InputLabel/InputLabel.jsx +99 -0
- package/src/InputLabel/LabelContent.native.jsx +6 -0
- package/src/InputLabel/LabelContent.web.jsx +13 -0
- package/src/InputLabel/index.js +3 -0
- package/src/InputSupports/InputSupports.jsx +86 -0
- package/src/InputSupports/index.js +3 -0
- package/src/InputSupports/propTypes.js +44 -0
- package/src/Link/ChevronLink.jsx +28 -7
- package/src/Link/InlinePressable.native.jsx +73 -0
- package/src/Link/InlinePressable.web.jsx +37 -0
- package/src/Link/Link.jsx +17 -13
- package/src/Link/LinkBase.jsx +62 -139
- package/src/Link/TextButton.jsx +25 -11
- package/src/Link/index.js +2 -1
- package/src/List/List.jsx +47 -0
- package/src/List/ListItem.jsx +187 -0
- package/src/List/index.js +3 -0
- package/src/Pagination/PageButton.jsx +3 -17
- package/src/Pagination/SideButton.jsx +27 -38
- package/src/Radio/Radio.jsx +270 -0
- package/src/Radio/RadioInput.native.jsx +6 -0
- package/src/Radio/RadioInput.web.jsx +57 -0
- package/src/Radio/index.js +3 -0
- package/src/Select/Group.native.jsx +14 -0
- package/src/Select/Group.web.jsx +15 -0
- package/src/Select/Item.native.jsx +10 -0
- package/src/Select/Item.web.jsx +11 -0
- package/src/Select/Picker.native.jsx +95 -0
- package/src/Select/Picker.web.jsx +67 -0
- package/src/Select/Select.jsx +265 -0
- package/src/Select/index.js +8 -0
- package/src/Skeleton/Skeleton.jsx +101 -0
- package/src/Skeleton/index.js +3 -0
- package/src/Spacer/Spacer.jsx +91 -0
- package/src/Spacer/index.js +3 -0
- package/src/StackView/StackView.jsx +104 -0
- package/src/StackView/StackWrap.jsx +33 -0
- package/src/StackView/StackWrap.native.jsx +4 -0
- package/src/StackView/StackWrapBox.jsx +93 -0
- package/src/StackView/StackWrapGap.jsx +49 -0
- package/src/StackView/common.jsx +28 -0
- package/src/StackView/getStackedContent.jsx +106 -0
- package/src/StackView/index.js +6 -0
- package/src/Tags/Tags.jsx +206 -0
- package/src/Tags/index.js +3 -0
- package/src/TextInput/TextArea.jsx +78 -0
- package/src/TextInput/TextInput.jsx +52 -0
- package/src/TextInput/TextInputBase.jsx +220 -0
- package/src/TextInput/index.js +4 -0
- package/src/TextInput/propTypes.js +29 -0
- package/src/ThemeProvider/useThemeTokens.js +54 -3
- package/src/ToggleSwitch/ToggleSwitch.jsx +1 -1
- package/src/Tooltip/Backdrop.native.jsx +33 -0
- package/src/Tooltip/Backdrop.web.jsx +60 -0
- package/src/Tooltip/Tooltip.jsx +294 -0
- package/src/Tooltip/dictionary.js +8 -0
- package/src/Tooltip/getTooltipPosition.js +161 -0
- package/src/Tooltip/index.js +3 -0
- package/src/TooltipButton/TooltipButton.jsx +53 -0
- package/src/TooltipButton/index.js +3 -0
- package/src/Typography/Typography.jsx +4 -19
- package/src/ViewportProvider/ViewportProvider.jsx +21 -0
- package/src/ViewportProvider/index.jsx +2 -41
- package/src/ViewportProvider/useViewport.js +5 -0
- package/src/ViewportProvider/useViewportListener.js +43 -0
- package/src/index.js +15 -1
- package/src/utils/a11y/index.js +1 -0
- package/src/utils/a11y/textSize.js +30 -0
- package/src/utils/index.js +8 -1
- package/src/utils/info/index.js +8 -0
- package/src/utils/info/platform/index.js +11 -0
- package/src/utils/info/platform/platform.android.js +1 -0
- package/src/utils/info/platform/platform.ios.js +1 -0
- package/src/utils/info/platform/platform.native.js +4 -0
- package/src/utils/info/platform/platform.web.js +1 -0
- package/src/utils/info/versions.js +6 -0
- package/src/utils/input.js +2 -1
- package/src/utils/pressability.js +92 -0
- package/src/utils/propTypes.js +97 -13
- package/src/utils/useCopy.js +13 -0
- package/src/utils/useResponsiveProp.js +50 -0
- package/src/utils/{spacing/useSpacingScale.js → useSpacingScale.js} +25 -10
- package/src/utils/useUniqueId.js +14 -0
- package/stories/A11yText/A11yText.stories.jsx +11 -5
- package/stories/ActivityIndicator/ActivityIndicator.stories.jsx +11 -2
- package/stories/Box/Box.stories.jsx +29 -2
- package/stories/Button/Button.stories.jsx +21 -20
- package/stories/Button/ButtonGroup.stories.jsx +2 -1
- package/stories/Button/ButtonLink.stories.jsx +6 -4
- package/stories/Card/Card.stories.jsx +13 -1
- package/stories/Checkbox/Checkbox.stories.jsx +71 -0
- package/stories/Divider/Divider.stories.jsx +26 -2
- package/stories/ExpandCollapse/ExpandCollapse.stories.jsx +74 -79
- package/stories/Feedback/Feedback.stories.jsx +96 -0
- package/stories/FlexGrid/01 FlexGrid.stories.jsx +20 -7
- package/stories/Icon/Icon.stories.jsx +11 -3
- package/stories/InputLabel/InputLabel.stories.jsx +42 -0
- package/stories/Link/ChevronLink.stories.jsx +20 -4
- package/stories/Link/Link.stories.jsx +39 -3
- package/stories/Link/TextButton.stories.jsx +24 -2
- package/stories/List/List.stories.jsx +117 -0
- package/stories/Pagination/Pagination.stories.jsx +28 -14
- package/stories/Radio/Radio.stories.jsx +113 -0
- package/stories/Select/Select.stories.jsx +55 -0
- package/stories/SideNav/SideNav.stories.jsx +17 -2
- package/stories/Skeleton/Skeleton.stories.jsx +36 -0
- package/stories/Spacer/Spacer.stories.jsx +38 -0
- package/stories/StackView/StackView.stories.jsx +75 -0
- package/stories/StackView/StackWrap.stories.jsx +64 -0
- package/stories/Tags/Tags.stories.jsx +69 -0
- package/stories/TextInput/TextArea.stories.jsx +100 -0
- package/stories/TextInput/TextInput.stories.jsx +103 -0
- package/stories/ToggleSwitch/ToggleSwitch.stories.jsx +16 -3
- package/stories/Tooltip/Tooltip.stories.jsx +81 -0
- package/stories/TooltipButton/TooltipButton.stories.jsx +11 -0
- package/stories/Typography/Typography.stories.jsx +12 -3
- package/stories/platform-supports.web.jsx +1 -1
- package/stories/supports.jsx +110 -14
- package/lib/Pagination/useCopy.js +0 -10
- package/lib/utils/spacing/index.js +0 -2
- package/lib/utils/spacing/utils.js +0 -32
- package/src/Pagination/useCopy.js +0 -7
- package/src/utils/spacing/index.js +0 -3
- package/src/utils/spacing/utils.js +0 -28
|
@@ -1,27 +1,16 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import PropTypes from 'prop-types';
|
|
3
|
-
import {
|
|
3
|
+
import { Platform } from 'react-native';
|
|
4
4
|
import ButtonBase from './ButtonBase';
|
|
5
|
+
import { StackWrap } from '../StackView';
|
|
5
6
|
import { useViewport } from '../ViewportProvider';
|
|
6
|
-
import { useThemeTokens } from '../ThemeProvider';
|
|
7
|
-
import { a11yProps, pressProps, variantProp, getTokensPropType } from '../utils/propTypes';
|
|
7
|
+
import { useThemeTokens, useThemeTokensCallback } from '../ThemeProvider';
|
|
8
|
+
import { a11yProps, pressProps, variantProp, getTokensPropType, selectTokens } from '../utils/propTypes';
|
|
8
9
|
import { useMultipleInputValues } from '../utils/input';
|
|
9
|
-
|
|
10
|
-
const selectContainerStyles = ({
|
|
11
|
-
direction
|
|
12
|
-
}) => ({
|
|
13
|
-
flexDirection: direction
|
|
14
|
-
});
|
|
15
|
-
|
|
16
|
-
const selectItemTokens = ({
|
|
17
|
-
gap
|
|
18
|
-
}, index) => ({
|
|
19
|
-
marginLeft: index && gap
|
|
20
|
-
});
|
|
10
|
+
import { getPressHandlersWithArgs } from '../utils/pressability';
|
|
21
11
|
|
|
22
12
|
const ButtonGroup = ({
|
|
23
13
|
variant,
|
|
24
|
-
buttonVariant = {},
|
|
25
14
|
tokens,
|
|
26
15
|
items = [],
|
|
27
16
|
values,
|
|
@@ -41,7 +30,12 @@ const ButtonGroup = ({
|
|
|
41
30
|
const themeTokens = useThemeTokens('ButtonGroup', tokens, variant, {
|
|
42
31
|
viewport
|
|
43
32
|
});
|
|
44
|
-
const
|
|
33
|
+
const stackTokens = selectTokens('StackView', themeTokens);
|
|
34
|
+
const {
|
|
35
|
+
direction,
|
|
36
|
+
space
|
|
37
|
+
} = themeTokens;
|
|
38
|
+
const getButtonTokens = useThemeTokensCallback('ButtonGroupItem', tokens, variant);
|
|
45
39
|
const {
|
|
46
40
|
currentValues,
|
|
47
41
|
toggleOneValue
|
|
@@ -57,26 +51,22 @@ const ButtonGroup = ({
|
|
|
57
51
|
...rest
|
|
58
52
|
});
|
|
59
53
|
const itemA11yRole = a11y.accessibilityRole === 'radioGroup' ? 'radio' : 'checkbox';
|
|
60
|
-
return /*#__PURE__*/React.createElement(
|
|
61
|
-
|
|
62
|
-
|
|
54
|
+
return /*#__PURE__*/React.createElement(StackWrap, Object.assign({}, a11y, {
|
|
55
|
+
space: space,
|
|
56
|
+
direction: direction,
|
|
57
|
+
tokens: stackTokens
|
|
58
|
+
}), items.map(({
|
|
63
59
|
label,
|
|
64
60
|
id = label,
|
|
65
61
|
accessibilityLabel
|
|
66
62
|
}, index) => {
|
|
67
|
-
const
|
|
68
|
-
const isSelected = currentValues.includes(id); // Allow handlers to be passed down for blur, hover, focus, pressIn, etc
|
|
63
|
+
const isSelected = currentValues.includes(id); // Pass an object of relevant component state as first argument for any passed-in press handlers
|
|
69
64
|
|
|
70
|
-
const pressHandlers =
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
label,
|
|
76
|
-
currentValues
|
|
77
|
-
}, ...args);
|
|
78
|
-
}
|
|
79
|
-
})));
|
|
65
|
+
const pressHandlers = getPressHandlersWithArgs(rest, [{
|
|
66
|
+
id,
|
|
67
|
+
label,
|
|
68
|
+
currentValues
|
|
69
|
+
}]);
|
|
80
70
|
|
|
81
71
|
const handlePress = () => {
|
|
82
72
|
if (pressHandlers.onPress) pressHandlers.onPress();
|
|
@@ -89,29 +79,15 @@ const ButtonGroup = ({
|
|
|
89
79
|
},
|
|
90
80
|
accessibilityRole: itemA11yRole,
|
|
91
81
|
accessibilityLabel,
|
|
92
|
-
...
|
|
93
|
-
web: {
|
|
94
|
-
// accessibilityPosInSet etc exists in React Native Web main branch
|
|
95
|
-
// but not in a release compatible with Expo etc; just use `aria-*`
|
|
96
|
-
'aria-setsize': items.length,
|
|
97
|
-
'aria-posinset': index + 1
|
|
98
|
-
},
|
|
99
|
-
default: {}
|
|
100
|
-
})
|
|
82
|
+
...a11yProps.getPositionInSet(items.length, index)
|
|
101
83
|
}; // Ensure button is direct child of group as MacOS voiceover only applies "X of Y" to
|
|
102
84
|
// "radio" if it's a direct child of "radiogroup", even if aria-posinset etc exists
|
|
103
|
-
// See also: TODO: make margin the responsibility of a parent
|
|
104
|
-
// https://github.com/telus/universal-design-system/issues/525
|
|
105
85
|
|
|
106
86
|
return /*#__PURE__*/React.createElement(ButtonBase, Object.assign({
|
|
107
87
|
key: id
|
|
108
88
|
}, pressHandlers, {
|
|
109
89
|
onPress: handlePress,
|
|
110
|
-
|
|
111
|
-
component: 'ButtonGroup',
|
|
112
|
-
...buttonVariant
|
|
113
|
-
},
|
|
114
|
-
tokens: itemTokens,
|
|
90
|
+
tokens: getButtonTokens,
|
|
115
91
|
selected: isSelected,
|
|
116
92
|
inactive: inactive
|
|
117
93
|
}, itemA11y), label);
|
|
@@ -122,7 +98,6 @@ ButtonGroup.propTypes = { ...a11yProps.propTypes,
|
|
|
122
98
|
...pressProps.propTypes,
|
|
123
99
|
tokens: getTokensPropType('ButtonGroup'),
|
|
124
100
|
variant: variantProp.propType,
|
|
125
|
-
buttonVariant: variantProp.propType,
|
|
126
101
|
|
|
127
102
|
/**
|
|
128
103
|
* The maximum number of items a user may select at once. Defaults to 1 and behaves
|
package/lib/Button/ButtonLink.js
CHANGED
|
@@ -2,6 +2,7 @@ import React from 'react';
|
|
|
2
2
|
import ButtonBase from './ButtonBase';
|
|
3
3
|
import buttonPropTypes from './propTypes';
|
|
4
4
|
import { a11yProps, hrefAttrsProp, linkProps } from '../utils/propTypes';
|
|
5
|
+
import { useThemeTokensCallback } from '../ThemeProvider';
|
|
5
6
|
/**
|
|
6
7
|
* `ButtonLink` is a component with the semantics and behaviour of a link, but with the visual appearance of a button.
|
|
7
8
|
* ButtonLink is a block-level component and should not be used inline.
|
|
@@ -9,14 +10,18 @@ import { a11yProps, hrefAttrsProp, linkProps } from '../utils/propTypes';
|
|
|
9
10
|
|
|
10
11
|
const ButtonLink = ({
|
|
11
12
|
accessibilityRole = 'link',
|
|
13
|
+
tokens,
|
|
14
|
+
variant,
|
|
12
15
|
...props
|
|
13
16
|
}) => {
|
|
14
17
|
const {
|
|
15
18
|
hrefAttrs,
|
|
16
19
|
rest
|
|
17
20
|
} = hrefAttrsProp.bundle(props);
|
|
21
|
+
const getTokens = useThemeTokensCallback('Button', tokens, variant);
|
|
18
22
|
return /*#__PURE__*/React.createElement(ButtonBase, Object.assign({
|
|
19
23
|
accessibilityRole: accessibilityRole,
|
|
24
|
+
tokens: getTokens,
|
|
20
25
|
hrefAttrs: hrefAttrs
|
|
21
26
|
}, rest));
|
|
22
27
|
};
|
|
@@ -0,0 +1,308 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import PropTypes from 'prop-types';
|
|
3
|
+
import { Pressable, StyleSheet, Text, View } from 'react-native';
|
|
4
|
+
import CheckboxInput from './CheckboxInput'; // @todo move `LabelContent` outside of the `InputLabel` and fix
|
|
5
|
+
// the issue with the cursor not being pointer on Web
|
|
6
|
+
|
|
7
|
+
import CheckboxLabel from '../InputLabel/LabelContent';
|
|
8
|
+
import Feedback from '../Feedback';
|
|
9
|
+
import StackView from '../StackView';
|
|
10
|
+
import { applyShadowToken, applyTextStyles, useThemeTokensCallback } from '../ThemeProvider';
|
|
11
|
+
import { getTokensPropType, useInputValue, variantProp } from '../utils';
|
|
12
|
+
import { a11yProps } from '../utils/propTypes';
|
|
13
|
+
import useUniqueId from '../utils/useUniqueId';
|
|
14
|
+
|
|
15
|
+
const selectInputStyles = ({
|
|
16
|
+
iconBackgroundColor,
|
|
17
|
+
inputBorderColor,
|
|
18
|
+
inputBorderRadius,
|
|
19
|
+
inputBorderWidth,
|
|
20
|
+
inputBackgroundColor,
|
|
21
|
+
inputHeight,
|
|
22
|
+
inputOutlineColor,
|
|
23
|
+
inputOutlineWidth,
|
|
24
|
+
inputShadow,
|
|
25
|
+
inputWidth
|
|
26
|
+
}, isChecked) => ({
|
|
27
|
+
borderColor: inputBorderColor,
|
|
28
|
+
borderWidth: inputBorderWidth,
|
|
29
|
+
borderRadius: inputBorderRadius,
|
|
30
|
+
backgroundColor: isChecked ? iconBackgroundColor : inputBackgroundColor,
|
|
31
|
+
outlineStyle: 'solid',
|
|
32
|
+
outlineColor: inputOutlineColor,
|
|
33
|
+
outlineWidth: inputOutlineWidth,
|
|
34
|
+
height: inputHeight,
|
|
35
|
+
width: inputWidth,
|
|
36
|
+
...applyShadowToken(inputShadow)
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
const selectLabelStyles = ({
|
|
40
|
+
labelColor,
|
|
41
|
+
labelFontName,
|
|
42
|
+
labelFontSize,
|
|
43
|
+
labelFontWeight,
|
|
44
|
+
labelMarginLeft,
|
|
45
|
+
labelLineHeight
|
|
46
|
+
}) => ({
|
|
47
|
+
marginLeft: labelMarginLeft,
|
|
48
|
+
...applyTextStyles({
|
|
49
|
+
color: labelColor,
|
|
50
|
+
fontName: labelFontName,
|
|
51
|
+
fontWeight: labelFontWeight,
|
|
52
|
+
fontSize: labelFontSize,
|
|
53
|
+
lineHeight: labelLineHeight
|
|
54
|
+
})
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
const selectContainerStyles = ({
|
|
58
|
+
containerMarginBottom
|
|
59
|
+
}) => ({
|
|
60
|
+
marginBottom: containerMarginBottom
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
const selectIconTokens = ({
|
|
64
|
+
iconColor,
|
|
65
|
+
iconSize
|
|
66
|
+
}) => ({
|
|
67
|
+
color: iconColor,
|
|
68
|
+
size: iconSize
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
const selectFeedbackTokens = ({
|
|
72
|
+
feedbackMarginBottom,
|
|
73
|
+
feedbackMarginTop,
|
|
74
|
+
feedbackPosition
|
|
75
|
+
}) => ({
|
|
76
|
+
feedbackPosition,
|
|
77
|
+
feedbackMarginBottom,
|
|
78
|
+
feedbackMarginTop
|
|
79
|
+
});
|
|
80
|
+
/**
|
|
81
|
+
* Basic Checkbox component.
|
|
82
|
+
*
|
|
83
|
+
* ## Component API
|
|
84
|
+
*
|
|
85
|
+
* Use `label` prop to provide a label for the checkbox.
|
|
86
|
+
* For a disabled `Checkbox` set the `inactive` prop to `true`.
|
|
87
|
+
*
|
|
88
|
+
* ### Controlled version
|
|
89
|
+
*
|
|
90
|
+
* If the checkbox is controlled from outside, it needs to receive `checked` and `onChange` props.
|
|
91
|
+
*
|
|
92
|
+
* ### Uncontrolled version
|
|
93
|
+
*
|
|
94
|
+
* In case of uncontrolled checkbox you can use `defaultChecked` prop to provide the initial value.
|
|
95
|
+
* Whenever the checkbox gets toggled, it calls the `onChange` callback with the new value (boolean).
|
|
96
|
+
*
|
|
97
|
+
* ### Using within forms
|
|
98
|
+
*
|
|
99
|
+
* You can pass `name` and `value` props if you need a particular checkbox to be a part of a group of
|
|
100
|
+
* checkboxes on a form.
|
|
101
|
+
*
|
|
102
|
+
* ### Validation and feedback
|
|
103
|
+
*
|
|
104
|
+
* You can use the `feedback` prop to provide a comment related to the checkbox element. If the comment
|
|
105
|
+
* is related to a validation error, the checkbox and the feedback can be styled accordingly by setting
|
|
106
|
+
* the `error` prop to `true` (can also be done without feedback).
|
|
107
|
+
*
|
|
108
|
+
* ## A11y guidelines
|
|
109
|
+
*
|
|
110
|
+
* Checkbox component accepts all the common accessibility props, but also sets some defaults, including
|
|
111
|
+
* accessibility role `'checkbox'` and accessibility state that depends on the other props (`checked`, `inactive`)
|
|
112
|
+
* or the internal state in case of uncontrolled checkbox.
|
|
113
|
+
*
|
|
114
|
+
*/
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
const Checkbox = ({
|
|
118
|
+
checked,
|
|
119
|
+
defaultChecked,
|
|
120
|
+
error = false,
|
|
121
|
+
feedback,
|
|
122
|
+
id,
|
|
123
|
+
inactive,
|
|
124
|
+
label,
|
|
125
|
+
name,
|
|
126
|
+
onChange,
|
|
127
|
+
tokens,
|
|
128
|
+
value,
|
|
129
|
+
variant,
|
|
130
|
+
...rest
|
|
131
|
+
}) => {
|
|
132
|
+
const {
|
|
133
|
+
currentValue: isChecked,
|
|
134
|
+
setValue: setIsChecked,
|
|
135
|
+
isControlled
|
|
136
|
+
} = useInputValue({
|
|
137
|
+
value: checked,
|
|
138
|
+
initialValue: defaultChecked,
|
|
139
|
+
onChange
|
|
140
|
+
}, 'useCheckboxValue');
|
|
141
|
+
const getTokens = useThemeTokensCallback('Checkbox', tokens, {
|
|
142
|
+
checked: isChecked,
|
|
143
|
+
inactive,
|
|
144
|
+
error,
|
|
145
|
+
...variant
|
|
146
|
+
});
|
|
147
|
+
const defaultTokens = getTokens();
|
|
148
|
+
const {
|
|
149
|
+
feedbackMarginBottom,
|
|
150
|
+
feedbackMarginTop,
|
|
151
|
+
feedbackPosition
|
|
152
|
+
} = selectFeedbackTokens(defaultTokens);
|
|
153
|
+
const styles = StyleSheet.create({
|
|
154
|
+
feedbackContainer: {
|
|
155
|
+
marginTop: feedbackMarginTop,
|
|
156
|
+
marginBottom: feedbackMarginBottom
|
|
157
|
+
}
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
const handleChange = () => {
|
|
161
|
+
if (!inactive) {
|
|
162
|
+
setIsChecked(!isChecked);
|
|
163
|
+
}
|
|
164
|
+
};
|
|
165
|
+
|
|
166
|
+
const accessibilityProps = a11yProps.select(rest);
|
|
167
|
+
const uniqueId = useUniqueId('checkbox');
|
|
168
|
+
const inputId = id ?? uniqueId; // @todo our current version of React Native Web doesn't include
|
|
169
|
+
// keyboard support on `Pressable` (which starts with 0.15.3), so
|
|
170
|
+
// the complete accessibility of the `Checkbox` component on Web
|
|
171
|
+
// (namely, change on key pressed) is pending RNW upgrade
|
|
172
|
+
// (see https://github.com/necolas/react-native-web/issues/1950)
|
|
173
|
+
|
|
174
|
+
return /*#__PURE__*/React.createElement(View, {
|
|
175
|
+
style: staticStyles.wrapper
|
|
176
|
+
}, /*#__PURE__*/React.createElement(StackView, {
|
|
177
|
+
direction: feedbackPosition === 'top' ? 'column-reverse' : 'column',
|
|
178
|
+
space: 0
|
|
179
|
+
}, /*#__PURE__*/React.createElement(Pressable, Object.assign({
|
|
180
|
+
disabled: inactive,
|
|
181
|
+
onPress: handleChange,
|
|
182
|
+
accessibilityRole: "checkbox",
|
|
183
|
+
accessibilityState: {
|
|
184
|
+
checked: isChecked,
|
|
185
|
+
disabled: inactive
|
|
186
|
+
}
|
|
187
|
+
}, accessibilityProps), ({
|
|
188
|
+
focused: focus,
|
|
189
|
+
hovered: hover,
|
|
190
|
+
pressed
|
|
191
|
+
}) => {
|
|
192
|
+
const {
|
|
193
|
+
icon: IconComponent,
|
|
194
|
+
...stateTokens
|
|
195
|
+
} = getTokens({
|
|
196
|
+
focus,
|
|
197
|
+
hover,
|
|
198
|
+
pressed
|
|
199
|
+
});
|
|
200
|
+
const iconTokens = selectIconTokens(stateTokens);
|
|
201
|
+
return /*#__PURE__*/React.createElement(View, {
|
|
202
|
+
style: [staticStyles.container, selectContainerStyles(stateTokens)]
|
|
203
|
+
}, /*#__PURE__*/React.createElement(View, {
|
|
204
|
+
style: StyleSheet.flatten([staticStyles.defaultInputStyles, selectInputStyles(stateTokens, isChecked)]),
|
|
205
|
+
testID: "Checkbox-Input"
|
|
206
|
+
}, /*#__PURE__*/React.createElement(CheckboxInput, {
|
|
207
|
+
checked: isChecked,
|
|
208
|
+
defaultChecked: defaultChecked,
|
|
209
|
+
disabled: inactive,
|
|
210
|
+
id: inputId,
|
|
211
|
+
isControlled: isControlled,
|
|
212
|
+
name: name,
|
|
213
|
+
value: value
|
|
214
|
+
}), isChecked && IconComponent && /*#__PURE__*/React.createElement(IconComponent, {
|
|
215
|
+
tokens: iconTokens,
|
|
216
|
+
testID: "Checkbox-Icon"
|
|
217
|
+
})), Boolean(label) && /*#__PURE__*/React.createElement(Text, {
|
|
218
|
+
style: selectLabelStyles(stateTokens)
|
|
219
|
+
}, /*#__PURE__*/React.createElement(CheckboxLabel, {
|
|
220
|
+
forId: inputId
|
|
221
|
+
}, label)));
|
|
222
|
+
}), Boolean(feedback) && /*#__PURE__*/React.createElement(View, {
|
|
223
|
+
style: styles.feedbackContainer
|
|
224
|
+
}, /*#__PURE__*/React.createElement(Feedback, {
|
|
225
|
+
title: feedback,
|
|
226
|
+
variant: {
|
|
227
|
+
icon: error === true
|
|
228
|
+
},
|
|
229
|
+
validation: error === true ? 'error' : undefined
|
|
230
|
+
}))));
|
|
231
|
+
};
|
|
232
|
+
|
|
233
|
+
Checkbox.propTypes = { ...a11yProps.propTypes,
|
|
234
|
+
|
|
235
|
+
/**
|
|
236
|
+
* Use `checked` for controlled Checkbox. For uncontrolled Checkbox, use the `defaultChecked` prop.
|
|
237
|
+
*/
|
|
238
|
+
checked: PropTypes.bool,
|
|
239
|
+
|
|
240
|
+
/**
|
|
241
|
+
* Use `defaultChecked` to provide the initial value for an uncontrolled Checkbox.
|
|
242
|
+
*/
|
|
243
|
+
defaultChecked: PropTypes.bool,
|
|
244
|
+
|
|
245
|
+
/**
|
|
246
|
+
* A detailed description of related validation error or additional instructions (depending on the `error` prop).
|
|
247
|
+
*/
|
|
248
|
+
feedback: PropTypes.string,
|
|
249
|
+
|
|
250
|
+
/**
|
|
251
|
+
* Checkbox ID.
|
|
252
|
+
*/
|
|
253
|
+
id: PropTypes.string,
|
|
254
|
+
|
|
255
|
+
/**
|
|
256
|
+
* Whether the corresponding input is disabled or active.
|
|
257
|
+
*/
|
|
258
|
+
inactive: PropTypes.bool,
|
|
259
|
+
|
|
260
|
+
/**
|
|
261
|
+
* The label.
|
|
262
|
+
*/
|
|
263
|
+
label: PropTypes.string,
|
|
264
|
+
|
|
265
|
+
/**
|
|
266
|
+
* Associate this checkbox with a group (set as the name attribute).
|
|
267
|
+
*/
|
|
268
|
+
name: PropTypes.string,
|
|
269
|
+
|
|
270
|
+
/**
|
|
271
|
+
* Whether the underlying input triggered a validation error or not.
|
|
272
|
+
*/
|
|
273
|
+
error: PropTypes.bool,
|
|
274
|
+
|
|
275
|
+
/**
|
|
276
|
+
* The value. Must be unique within the group.
|
|
277
|
+
*/
|
|
278
|
+
value: PropTypes.oneOfType([PropTypes.string, PropTypes.number, PropTypes.bool]),
|
|
279
|
+
|
|
280
|
+
/**
|
|
281
|
+
* Callback called when a controlled checkbox gets interacted with.
|
|
282
|
+
*/
|
|
283
|
+
onChange: PropTypes.func,
|
|
284
|
+
|
|
285
|
+
/**
|
|
286
|
+
* Checkbox tokens.
|
|
287
|
+
*/
|
|
288
|
+
tokens: getTokensPropType('Checkbox'),
|
|
289
|
+
|
|
290
|
+
/**
|
|
291
|
+
* Checkbox variant.
|
|
292
|
+
*/
|
|
293
|
+
variant: variantProp.propType
|
|
294
|
+
};
|
|
295
|
+
export default Checkbox;
|
|
296
|
+
const staticStyles = StyleSheet.create({
|
|
297
|
+
wrapper: {
|
|
298
|
+
backgroundColor: 'transparent'
|
|
299
|
+
},
|
|
300
|
+
container: {
|
|
301
|
+
flexDirection: 'row',
|
|
302
|
+
alignItems: 'center'
|
|
303
|
+
},
|
|
304
|
+
defaultInputStyles: {
|
|
305
|
+
alignItems: 'center',
|
|
306
|
+
justifyContent: 'center'
|
|
307
|
+
}
|
|
308
|
+
});
|
|
@@ -0,0 +1,57 @@
|
|
|
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
|
+
const CheckboxInput = /*#__PURE__*/forwardRef(({
|
|
8
|
+
checked,
|
|
9
|
+
defaultChecked,
|
|
10
|
+
disabled,
|
|
11
|
+
id,
|
|
12
|
+
isControlled,
|
|
13
|
+
name,
|
|
14
|
+
onChange,
|
|
15
|
+
value
|
|
16
|
+
}, ref) => {
|
|
17
|
+
const handleClick = event => {
|
|
18
|
+
// Cancel the click dispatched via the label tag, since it's already wrapped
|
|
19
|
+
// in <Pressable>
|
|
20
|
+
event.preventDefault();
|
|
21
|
+
event.stopPropagation();
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
return /*#__PURE__*/React.createElement("input", {
|
|
25
|
+
checked: isControlled ? checked : undefined,
|
|
26
|
+
defaultChecked: isControlled ? undefined : defaultChecked,
|
|
27
|
+
disabled: disabled,
|
|
28
|
+
hidden: true,
|
|
29
|
+
id: id,
|
|
30
|
+
name: name,
|
|
31
|
+
onChange: onChange,
|
|
32
|
+
onClick: handleClick,
|
|
33
|
+
ref: ref,
|
|
34
|
+
type: "checkbox",
|
|
35
|
+
value: value
|
|
36
|
+
});
|
|
37
|
+
});
|
|
38
|
+
CheckboxInput.displayName = 'CheckboxInput';
|
|
39
|
+
CheckboxInput.propTypes = {
|
|
40
|
+
checked: PropTypes.bool,
|
|
41
|
+
defaultChecked: PropTypes.bool,
|
|
42
|
+
disabled: PropTypes.bool,
|
|
43
|
+
id: PropTypes.string.isRequired,
|
|
44
|
+
isControlled: PropTypes.bool.isRequired,
|
|
45
|
+
name: PropTypes.string,
|
|
46
|
+
onChange: PropTypes.func,
|
|
47
|
+
value: PropTypes.string
|
|
48
|
+
};
|
|
49
|
+
CheckboxInput.defaultProps = {
|
|
50
|
+
checked: undefined,
|
|
51
|
+
defaultChecked: undefined,
|
|
52
|
+
disabled: false,
|
|
53
|
+
name: undefined,
|
|
54
|
+
onChange: () => {},
|
|
55
|
+
value: undefined
|
|
56
|
+
};
|
|
57
|
+
export default CheckboxInput;
|
package/lib/Divider/Divider.js
CHANGED
|
@@ -2,7 +2,13 @@ import React from 'react';
|
|
|
2
2
|
import PropTypes from 'prop-types';
|
|
3
3
|
import { View, StyleSheet, Platform } from 'react-native';
|
|
4
4
|
import { useThemeTokens } from '../ThemeProvider';
|
|
5
|
-
import
|
|
5
|
+
import Spacer from '../Spacer';
|
|
6
|
+
import { getTokensPropType, variantProp, spacingProps } from '../utils';
|
|
7
|
+
/**
|
|
8
|
+
* @typedef {import('../utils/propTypes.js').SpacingIndex} SpacingIndex
|
|
9
|
+
* @typedef {import('../utils/propTypes.js').SpacingObject} SpacingObject
|
|
10
|
+
*/
|
|
11
|
+
|
|
6
12
|
/**
|
|
7
13
|
* A basic divider component, horizontal by default. Color and thickness can be controlled by theme.
|
|
8
14
|
* Divider is based on the flexbox model and uses `alignSelf: flex` to span its flex parent.
|
|
@@ -15,6 +21,26 @@ import { getTokensPropType, variantProp } from '../utils/propTypes';
|
|
|
15
21
|
*
|
|
16
22
|
* In a flexbox row, vertical dividers will automatically size to their parent height.
|
|
17
23
|
*
|
|
24
|
+
* ## Space
|
|
25
|
+
*
|
|
26
|
+
* Use this to create **space either side of the divider**. For simple cases, pass a number referring to
|
|
27
|
+
* a position on the theme's spacing scale; for example, this will put a Spacer of the smallest supported
|
|
28
|
+
* size either side of the divider:
|
|
29
|
+
*
|
|
30
|
+
* ```jsx
|
|
31
|
+
* <Divider space={1} />
|
|
32
|
+
* ```
|
|
33
|
+
*
|
|
34
|
+
* `space` prop uses `useSpacingScale` and may accept a {@link SpacingObject} or a {@link SpacingIndex} number.
|
|
35
|
+
*
|
|
36
|
+
* To **reduce the length of a divider** as well as creating space between it and its neighbours, wrap it in
|
|
37
|
+
* a `Box` component. For example, this will have the second-smallest theme-supported spacing value between
|
|
38
|
+
* the dividing line and its neighbours, and will shorten the line at either end by the same amount:
|
|
39
|
+
*
|
|
40
|
+
* ```jsx
|
|
41
|
+
* <Box space={2}><Divider /></Box>
|
|
42
|
+
* ```
|
|
43
|
+
*
|
|
18
44
|
* ## Accessibility
|
|
19
45
|
*
|
|
20
46
|
* For accessibility purposes a divider component will be described with ARIA attributes, i.e. `role="separator"` and `aria-orientation="vertical/horizontal"`.
|
|
@@ -23,6 +49,7 @@ import { getTokensPropType, variantProp } from '../utils/propTypes';
|
|
|
23
49
|
const Divider = ({
|
|
24
50
|
variant,
|
|
25
51
|
vertical = false,
|
|
52
|
+
space,
|
|
26
53
|
tokens,
|
|
27
54
|
testID
|
|
28
55
|
}) => {
|
|
@@ -43,14 +70,25 @@ const Divider = ({
|
|
|
43
70
|
accessibilityRole: 'separator'
|
|
44
71
|
} : // There are no such equivalent attributes for native
|
|
45
72
|
{};
|
|
46
|
-
|
|
73
|
+
const divider = /*#__PURE__*/React.createElement(View, Object.assign({
|
|
47
74
|
style: [styles.divider, borderStyles],
|
|
48
75
|
testID: testID
|
|
49
76
|
}, a11y));
|
|
77
|
+
if (!space) return divider;
|
|
78
|
+
const spacerProps = {
|
|
79
|
+
space,
|
|
80
|
+
direction: vertical ? 'row' : 'column'
|
|
81
|
+
};
|
|
82
|
+
return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(Spacer, Object.assign({}, spacerProps, {
|
|
83
|
+
testID: testID ? `${testID}-Spacer-before` : undefined
|
|
84
|
+
})), divider, /*#__PURE__*/React.createElement(Spacer, Object.assign({}, spacerProps, {
|
|
85
|
+
testID: testID ? `${testID}-Spacer-after` : undefined
|
|
86
|
+
})));
|
|
50
87
|
};
|
|
51
88
|
|
|
52
89
|
Divider.propTypes = {
|
|
53
90
|
tokens: getTokensPropType('Divider'),
|
|
91
|
+
space: spacingProps.types.spacingValue,
|
|
54
92
|
variant: variantProp.propType,
|
|
55
93
|
|
|
56
94
|
/**
|