@telus-uds/components-base 0.0.2-prerelease.6 → 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 -1
- package/CHANGELOG.md +20 -0
- package/__fixtures__/testTheme.js +424 -37
- package/__tests__/Button/ButtonBase.test.jsx +2 -31
- package/__tests__/Checkbox/Checkbox.test.jsx +94 -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__/Tags/Tags.test.jsx +328 -0
- package/__tests__/TextInput/TextArea.test.jsx +34 -0
- package/__tests__/TextInput/{TextInput.test.jsx → TextInputBase.test.jsx} +20 -46
- package/jest.config.js +3 -1
- package/lib/Button/Button.js +10 -3
- package/lib/Button/ButtonBase.js +73 -59
- package/lib/Button/ButtonGroup.js +11 -27
- 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/Feedback/Feedback.js +20 -3
- package/lib/Icon/Icon.js +8 -5
- package/lib/Icon/IconText.js +72 -0
- package/lib/Icon/index.js +2 -1
- 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 +23 -20
- 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 +62 -123
- 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 +2 -25
- package/lib/Pagination/SideButton.js +27 -37
- 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/Tags/Tags.js +217 -0
- package/lib/Tags/index.js +2 -0
- package/lib/TextInput/TextArea.js +82 -0
- package/lib/TextInput/TextInput.js +23 -304
- package/lib/TextInput/TextInputBase.js +229 -0
- package/lib/TextInput/index.js +2 -1
- package/lib/TextInput/propTypes.js +31 -0
- package/lib/ThemeProvider/useThemeTokens.js +54 -3
- package/lib/ToggleSwitch/ToggleSwitch.js +1 -1
- package/lib/Typography/Typography.js +4 -19
- package/lib/index.js +8 -1
- package/lib/utils/a11y/index.js +1 -0
- package/lib/utils/a11y/textSize.js +33 -0
- package/lib/utils/index.js +3 -0
- 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/pressability.js +92 -0
- package/lib/utils/propTypes.js +78 -17
- package/package.json +5 -4
- package/release-context.json +4 -4
- package/src/Button/Button.jsx +6 -3
- package/src/Button/ButtonBase.jsx +66 -57
- package/src/Button/ButtonGroup.jsx +9 -22
- 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/Feedback/Feedback.jsx +13 -4
- package/src/Icon/Icon.jsx +9 -5
- package/src/Icon/IconText.jsx +63 -0
- package/src/Icon/index.js +2 -1
- 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 +20 -17
- 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 +57 -140
- 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 +2 -16
- package/src/Pagination/SideButton.jsx +23 -34
- 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/Tags/Tags.jsx +206 -0
- package/src/Tags/index.js +3 -0
- package/src/TextInput/TextArea.jsx +78 -0
- package/src/TextInput/TextInput.jsx +17 -284
- package/src/TextInput/TextInputBase.jsx +220 -0
- package/src/TextInput/index.js +2 -1
- package/src/TextInput/propTypes.js +29 -0
- package/src/ThemeProvider/useThemeTokens.js +54 -3
- package/src/ToggleSwitch/ToggleSwitch.jsx +1 -1
- package/src/Typography/Typography.jsx +4 -15
- package/src/index.js +8 -1
- package/src/utils/a11y/index.js +1 -0
- package/src/utils/a11y/textSize.js +30 -0
- package/src/utils/index.js +3 -0
- 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/pressability.js +92 -0
- package/src/utils/propTypes.js +97 -22
- package/stories/Button/Button.stories.jsx +5 -0
- package/stories/Checkbox/Checkbox.stories.jsx +71 -0
- package/stories/Feedback/Feedback.stories.jsx +5 -6
- package/stories/Link/Link.stories.jsx +15 -1
- package/stories/List/List.stories.jsx +117 -0
- package/stories/Radio/Radio.stories.jsx +113 -0
- package/stories/Select/Select.stories.jsx +55 -0
- package/stories/Skeleton/Skeleton.stories.jsx +36 -0
- package/stories/Tags/Tags.stories.jsx +69 -0
- package/stories/TextInput/TextArea.stories.jsx +100 -0
- package/stories/supports.jsx +1 -1
package/lib/Link/LinkBase.js
CHANGED
|
@@ -1,14 +1,11 @@
|
|
|
1
|
-
import React
|
|
1
|
+
import React from 'react';
|
|
2
2
|
import PropTypes from 'prop-types';
|
|
3
|
-
import { Text, Platform, StyleSheet
|
|
3
|
+
import { Text, Platform, StyleSheet } from 'react-native';
|
|
4
4
|
import { a11yProps, hrefAttrsProp, variantProp, linkProps, getTokensPropType } from '../utils/propTypes';
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
}) => ({
|
|
10
|
-
color
|
|
11
|
-
});
|
|
5
|
+
import { resolvePressableTokens } from '../utils/pressability';
|
|
6
|
+
import InlinePressable from './InlinePressable';
|
|
7
|
+
import { applyTextStyles } from '../ThemeProvider';
|
|
8
|
+
import { IconText, iconComponentPropTypes } from '../Icon';
|
|
12
9
|
|
|
13
10
|
const selectOuterBorderStyles = ({
|
|
14
11
|
outerBorderColor,
|
|
@@ -32,11 +29,19 @@ Platform.OS === 'web' ? {
|
|
|
32
29
|
} : {};
|
|
33
30
|
|
|
34
31
|
const selectTextStyles = ({
|
|
32
|
+
color,
|
|
35
33
|
textLine,
|
|
36
34
|
textLineStyle
|
|
37
35
|
}) => ({
|
|
36
|
+
color,
|
|
38
37
|
textDecorationLine: textLine,
|
|
39
|
-
textDecorationStyle: textLineStyle
|
|
38
|
+
textDecorationStyle: textLineStyle,
|
|
39
|
+
...Platform.select({
|
|
40
|
+
web: {
|
|
41
|
+
// TODO: https://github.com/telus/universal-design-system/issues/487
|
|
42
|
+
transition: 'color 200ms'
|
|
43
|
+
}
|
|
44
|
+
})
|
|
40
45
|
});
|
|
41
46
|
|
|
42
47
|
const selectBlockStyles = ({
|
|
@@ -51,20 +56,16 @@ const selectBlockStyles = ({
|
|
|
51
56
|
fontName: blockFontName
|
|
52
57
|
});
|
|
53
58
|
|
|
54
|
-
const
|
|
59
|
+
const selectIconTokens = ({
|
|
60
|
+
color,
|
|
55
61
|
iconSize,
|
|
56
|
-
iconGapBefore,
|
|
57
|
-
iconGapAfter,
|
|
58
|
-
iconScale,
|
|
59
62
|
iconTranslateX,
|
|
60
63
|
iconTranslateY
|
|
61
64
|
}) => ({
|
|
62
|
-
|
|
65
|
+
color,
|
|
63
66
|
translateX: iconTranslateX,
|
|
64
67
|
translateY: iconTranslateY,
|
|
65
|
-
size: iconSize
|
|
66
|
-
gapBefore: iconGapBefore,
|
|
67
|
-
gapAfter: iconGapAfter
|
|
68
|
+
size: iconSize
|
|
68
69
|
});
|
|
69
70
|
/**
|
|
70
71
|
* Renders a pressable text link, with optional icon. This is rendered as a block element
|
|
@@ -95,35 +96,13 @@ const LinkBase = ({
|
|
|
95
96
|
onPress,
|
|
96
97
|
icon,
|
|
97
98
|
iconPosition = icon ? 'left' : undefined,
|
|
98
|
-
|
|
99
|
+
iconProps,
|
|
99
100
|
variant,
|
|
100
|
-
tokens,
|
|
101
|
+
tokens = {},
|
|
101
102
|
children,
|
|
102
103
|
accessibilityRole = 'link',
|
|
103
104
|
...props
|
|
104
105
|
}) => {
|
|
105
|
-
const handlePress = linkProps.handleHref({
|
|
106
|
-
href,
|
|
107
|
-
onPress
|
|
108
|
-
});
|
|
109
|
-
const [isFocused, setIsFocused] = useState(false);
|
|
110
|
-
|
|
111
|
-
const handleFocus = () => setIsFocused(true);
|
|
112
|
-
|
|
113
|
-
const handleBlur = () => setIsFocused(false);
|
|
114
|
-
|
|
115
|
-
const [isHovered, setIsHovered] = useState(false);
|
|
116
|
-
|
|
117
|
-
const handleHoverIn = () => setIsHovered(true);
|
|
118
|
-
|
|
119
|
-
const handleHoverOut = () => setIsHovered(false);
|
|
120
|
-
|
|
121
|
-
const [isPressed, setIsPressed] = useState(false);
|
|
122
|
-
|
|
123
|
-
const handlePressIn = () => setIsPressed(true);
|
|
124
|
-
|
|
125
|
-
const handlePressOut = () => setIsPressed(false);
|
|
126
|
-
|
|
127
106
|
const {
|
|
128
107
|
hrefAttrs,
|
|
129
108
|
rest
|
|
@@ -131,92 +110,49 @@ const LinkBase = ({
|
|
|
131
110
|
const linkPropSet = linkProps.select({
|
|
132
111
|
accessibilityRole,
|
|
133
112
|
href,
|
|
134
|
-
onPress:
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
onBlur: handleBlur,
|
|
139
|
-
onMouseEnter: handleHoverIn,
|
|
140
|
-
onMouseLeave: handleHoverOut,
|
|
113
|
+
onPress: linkProps.handleHref({
|
|
114
|
+
href,
|
|
115
|
+
onPress
|
|
116
|
+
}),
|
|
141
117
|
...hrefAttrsProp.spread(hrefAttrs),
|
|
142
118
|
...rest
|
|
143
119
|
});
|
|
144
|
-
const themeTokens = useThemeTokens('Link', tokens, variant, {
|
|
145
|
-
focus: isFocused,
|
|
146
|
-
hover: isHovered,
|
|
147
|
-
pressed: isPressed,
|
|
148
|
-
iconPosition
|
|
149
|
-
});
|
|
150
|
-
const IconComponent = icon || themeTokens.icon;
|
|
151
|
-
const hasIcon = !!IconComponent;
|
|
152
|
-
const textStyles = selectTextStyles(themeTokens);
|
|
153
|
-
const outerBorderStyles = selectOuterBorderStyles(themeTokens);
|
|
154
|
-
const contentStyles = selectContentStyles(themeTokens);
|
|
155
|
-
const blockStyles = selectBlockStyles(themeTokens);
|
|
156
|
-
const iconStyles = selectIconStyles(themeTokens); // TODO: re-apply support for inline links
|
|
157
|
-
|
|
158
|
-
const isNested = false; // On web, this makes focus rings wrap only the link, not the entire block
|
|
159
120
|
|
|
160
|
-
const
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
121
|
+
const resolveTokens = pressState => resolvePressableTokens(tokens, pressState, {
|
|
122
|
+
iconPosition
|
|
123
|
+
}); // On web, this makes focus rings wrap only the link, not the entire block
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
const blockLeftStyle = Platform.OS === 'web' && staticStyles.blockLeft;
|
|
127
|
+
return /*#__PURE__*/React.createElement(InlinePressable, Object.assign({}, linkPropSet, {
|
|
128
|
+
style: linkState => {
|
|
129
|
+
const themeTokens = resolveTokens(linkState);
|
|
130
|
+
const outerBorderStyles = selectOuterBorderStyles(themeTokens);
|
|
131
|
+
const hasIcon = Boolean(icon || themeTokens.icon);
|
|
132
|
+
return [outerBorderStyles, blockLeftStyle, hasIcon && staticStyles.rowContainer];
|
|
133
|
+
}
|
|
134
|
+
}), linkState => {
|
|
135
|
+
const themeTokens = resolveTokens(linkState);
|
|
136
|
+
const textStyles = selectTextStyles(themeTokens);
|
|
137
|
+
const iconTokens = selectIconTokens(themeTokens); // TODO: may need to apply some smarter text inheritance here if inline to avoid native
|
|
138
|
+
// issues like double-application of line heights breaking align-items: baseline
|
|
139
|
+
|
|
140
|
+
const blockTextStyles = selectBlockStyles(themeTokens);
|
|
141
|
+
const IconComponent = icon || themeTokens.icon;
|
|
166
142
|
const {
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
React.createElement(TouchableWithoutFeedback, {
|
|
176
|
-
onPressIn: onPressIn,
|
|
177
|
-
onPressOut: onPressOut,
|
|
178
|
-
onPress: _onPress
|
|
179
|
-
}, /*#__PURE__*/React.createElement(Text, Object.assign({}, textProps, {
|
|
180
|
-
style: [outerBorderStyles, blockLeftStyle, contentStyles, blockTextStyles, textStyles]
|
|
181
|
-
}), children))
|
|
182
|
-
);
|
|
183
|
-
} // Scale icon with text, but with a cap so text isn't squashed at large scales
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
const iconScale = Math.min(PixelRatio.getFontScale(), 2);
|
|
187
|
-
const iconTokens = {
|
|
188
|
-
size: iconStyles.size ? iconStyles.size * iconScale : undefined,
|
|
189
|
-
color: contentStyles.color ?? undefined,
|
|
190
|
-
scale: iconStyles.scale ?? undefined,
|
|
191
|
-
translateX: iconStyles.translateX ?? undefined,
|
|
192
|
-
translateY: iconStyles.translateY ?? undefined
|
|
193
|
-
};
|
|
194
|
-
const iconContent = /*#__PURE__*/React.createElement(IconComponent, {
|
|
195
|
-
tokens: iconTokens,
|
|
196
|
-
variant: iconVariant
|
|
197
|
-
});
|
|
198
|
-
const iconBlock = isNested ? // TODO: when reimplementing inline support, insert an appropriate space character
|
|
199
|
-
// based on the value of gapBefore and gapAfter on native (no inline margins/padding)
|
|
200
|
-
iconContent : /*#__PURE__*/React.createElement(View, {
|
|
201
|
-
style: [iconPosition === 'left' && {
|
|
202
|
-
marginRight: iconStyles.gapAfter * iconScale
|
|
203
|
-
}, iconPosition === 'right' && {
|
|
204
|
-
marginLeft: iconStyles.gapBefore * iconScale
|
|
205
|
-
}]
|
|
206
|
-
}, iconContent); // TODO: this doesn't work well when nested inline but does allow block-links to have icons align
|
|
207
|
-
// properly on Android which purely inline links can't do. Add an isNested case that is similar to
|
|
208
|
-
// https://github.com/telus/universal-design-system/pull/233
|
|
209
|
-
|
|
210
|
-
return /*#__PURE__*/React.createElement(Pressable, Object.assign({}, linkPropSet, {
|
|
211
|
-
style: [outerBorderStyles, blockLeftStyle, staticStyles.rowContainer]
|
|
212
|
-
}), iconPosition === 'left' && iconBlock, /*#__PURE__*/React.createElement(Text, {
|
|
213
|
-
style: [contentStyles, blockTextStyles, textStyles, Platform.select({
|
|
214
|
-
web: {
|
|
215
|
-
// TODO: https://github.com/telus/universal-design-system/issues/487
|
|
216
|
-
transition: 'color 200ms'
|
|
143
|
+
iconSpace
|
|
144
|
+
} = themeTokens;
|
|
145
|
+
return /*#__PURE__*/React.createElement(IconText, {
|
|
146
|
+
icon: IconComponent,
|
|
147
|
+
iconPosition: iconPosition,
|
|
148
|
+
space: iconSpace,
|
|
149
|
+
iconProps: { ...iconProps,
|
|
150
|
+
tokens: iconTokens
|
|
217
151
|
}
|
|
218
|
-
}
|
|
219
|
-
|
|
152
|
+
}, /*#__PURE__*/React.createElement(Text, {
|
|
153
|
+
style: [textStyles, blockTextStyles, staticStyles.baseline]
|
|
154
|
+
}, children));
|
|
155
|
+
});
|
|
220
156
|
};
|
|
221
157
|
|
|
222
158
|
LinkBase.propTypes = { ...a11yProps.types,
|
|
@@ -227,7 +163,7 @@ LinkBase.propTypes = { ...a11yProps.types,
|
|
|
227
163
|
/**
|
|
228
164
|
* Optional variant that may be passed down to the link's icon if there is one
|
|
229
165
|
*/
|
|
230
|
-
|
|
166
|
+
iconProps: PropTypes.exact(iconComponentPropTypes),
|
|
231
167
|
|
|
232
168
|
/**
|
|
233
169
|
* A function component for an SVG icon to render inside the link. Inherits size and color from
|
|
@@ -254,6 +190,9 @@ const staticStyles = StyleSheet.create({
|
|
|
254
190
|
flexDirection: 'row',
|
|
255
191
|
alignItems: 'center',
|
|
256
192
|
justifyContent: 'flex-start'
|
|
193
|
+
},
|
|
194
|
+
baseline: {
|
|
195
|
+
alignSelf: 'baseline'
|
|
257
196
|
}
|
|
258
197
|
});
|
|
259
198
|
export default LinkBase;
|
package/lib/Link/TextButton.js
CHANGED
|
@@ -1,25 +1,36 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import PropTypes from 'prop-types';
|
|
3
|
+
import { useThemeTokensCallback } from '../ThemeProvider';
|
|
3
4
|
import LinkBase from './LinkBase';
|
|
5
|
+
/**
|
|
6
|
+
* `TextButton` is a button that looks like a Link. It uses the same theming and variants as
|
|
7
|
+
* Link but has the accessibility role of a `Button`. It should be used for actions that
|
|
8
|
+
* take place on the current page, or for navigation within an app.
|
|
9
|
+
*/
|
|
4
10
|
|
|
5
11
|
const TextButton = ({
|
|
6
12
|
onPress,
|
|
7
13
|
children,
|
|
8
|
-
variant
|
|
14
|
+
variant,
|
|
15
|
+
tokens,
|
|
16
|
+
// TODO: this may need to use `link` role on Web in the case of being passed both `href` and
|
|
17
|
+
// `onPress` in an omniplatform app that uses React Navigation's useLinkProps for internal nav.
|
|
9
18
|
accessibilityRole = 'button',
|
|
10
19
|
...linkProps
|
|
11
|
-
}) =>
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
}
|
|
18
|
-
}
|
|
20
|
+
}) => {
|
|
21
|
+
const getTokens = useThemeTokensCallback('Link', tokens, variant);
|
|
22
|
+
return /*#__PURE__*/React.createElement(LinkBase, Object.assign({
|
|
23
|
+
onPress: onPress,
|
|
24
|
+
accessibilityRole: accessibilityRole,
|
|
25
|
+
tokens: getTokens
|
|
26
|
+
}, linkProps), children);
|
|
27
|
+
};
|
|
19
28
|
|
|
20
29
|
TextButton.propTypes = { ...LinkBase.propTypes,
|
|
21
30
|
onPress: PropTypes.func.isRequired
|
|
22
31
|
}; // Remove incompatible Link prop (if this build includes propTypes)
|
|
32
|
+
// TODO: test if this works with web navigation in omniplatform React Navigation
|
|
33
|
+
// https://github.com/telus/universal-design-system/issues/665
|
|
23
34
|
// eslint-disable-next-line react/forbid-foreign-prop-types
|
|
24
35
|
|
|
25
36
|
if (TextButton.propTypes?.href) delete TextButton.propTypes.href;
|
package/lib/Link/index.js
CHANGED
package/lib/List/List.js
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import React, { cloneElement, Children } from 'react';
|
|
2
|
+
import { View, Platform } from 'react-native';
|
|
3
|
+
import PropTypes from 'prop-types';
|
|
4
|
+
import { getTokensPropType, variantProp, componentPropType } from '../utils';
|
|
5
|
+
import { a11yProps } from '../utils/propTypes';
|
|
6
|
+
import ListItem from './ListItem';
|
|
7
|
+
/**
|
|
8
|
+
* A Unordered List component has a child a ListItem that
|
|
9
|
+
* allows icon, dividers and customized typography
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
const List = ({
|
|
13
|
+
children,
|
|
14
|
+
showDivider,
|
|
15
|
+
tokens,
|
|
16
|
+
variant,
|
|
17
|
+
...rest
|
|
18
|
+
}) => {
|
|
19
|
+
const accessibilityRole = Platform.select({
|
|
20
|
+
web: 'list',
|
|
21
|
+
default: 'none'
|
|
22
|
+
});
|
|
23
|
+
const a11y = a11yProps.select(rest);
|
|
24
|
+
const items = Children.map(children, (child, index) => {
|
|
25
|
+
if (child.type.name === ListItem.name) {
|
|
26
|
+
return /*#__PURE__*/cloneElement(child, {
|
|
27
|
+
showDivider,
|
|
28
|
+
isLastItem: index + 1 === Children.count(children),
|
|
29
|
+
tokens,
|
|
30
|
+
variant
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
return child;
|
|
35
|
+
});
|
|
36
|
+
return /*#__PURE__*/React.createElement(View, Object.assign({
|
|
37
|
+
accessibilityRole: accessibilityRole
|
|
38
|
+
}, a11y), items);
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
List.Item = ListItem;
|
|
42
|
+
List.propTypes = { ...a11yProps.types,
|
|
43
|
+
tokens: getTokensPropType('List'),
|
|
44
|
+
variant: variantProp.propType,
|
|
45
|
+
children: componentPropType('ListItem'),
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* In case it is not the last item allow display divider
|
|
49
|
+
*/
|
|
50
|
+
showDivider: PropTypes.bool
|
|
51
|
+
};
|
|
52
|
+
export default List;
|
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { View, Platform, Text, StyleSheet } from 'react-native';
|
|
3
|
+
import PropTypes from 'prop-types';
|
|
4
|
+
import { useThemeTokens, applyTextStyles } from '../ThemeProvider';
|
|
5
|
+
import { getTokensPropType, variantProp } from '../utils';
|
|
6
|
+
|
|
7
|
+
const selectBulletStyles = ({
|
|
8
|
+
itemBulletWidth,
|
|
9
|
+
itemBulletHeight,
|
|
10
|
+
itemBulletColor
|
|
11
|
+
}) => ({
|
|
12
|
+
width: itemBulletWidth,
|
|
13
|
+
height: itemBulletHeight,
|
|
14
|
+
borderRadius: itemBulletHeight / 2,
|
|
15
|
+
backgroundColor: itemBulletColor
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
const selectBulletContainerStyles = ({
|
|
19
|
+
itemBulletContainerWidth,
|
|
20
|
+
itemBulletContainerAlign
|
|
21
|
+
}) => ({
|
|
22
|
+
width: itemBulletContainerWidth,
|
|
23
|
+
alignItems: itemBulletContainerAlign,
|
|
24
|
+
justifyContent: itemBulletContainerAlign
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
const selectItemIconTokens = ({
|
|
28
|
+
itemIconSize,
|
|
29
|
+
itemIconColor
|
|
30
|
+
}) => ({
|
|
31
|
+
size: itemIconSize,
|
|
32
|
+
color: itemIconColor
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
const selectSideItemContainerStyles = ({
|
|
36
|
+
listGutter
|
|
37
|
+
}) => ({
|
|
38
|
+
marginRight: listGutter
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
const selectItemStyles = ({
|
|
42
|
+
itemFontWeight,
|
|
43
|
+
itemFontSize,
|
|
44
|
+
itemLineHeight,
|
|
45
|
+
itemFontName
|
|
46
|
+
}) => applyTextStyles({
|
|
47
|
+
fontWeight: itemFontWeight,
|
|
48
|
+
fontSize: itemFontSize,
|
|
49
|
+
lineHeight: itemLineHeight,
|
|
50
|
+
fontName: itemFontName
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
const selectItemBlockStyles = ({
|
|
54
|
+
interItemMargin
|
|
55
|
+
}) => ({
|
|
56
|
+
marginBottom: interItemMargin
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
const selectDividerStyles = ({
|
|
60
|
+
dividerColor,
|
|
61
|
+
dividerSize,
|
|
62
|
+
interItemMarginWithDivider
|
|
63
|
+
}) => ({
|
|
64
|
+
borderBottomWidth: dividerSize,
|
|
65
|
+
borderColor: dividerColor,
|
|
66
|
+
marginBottom: interItemMarginWithDivider,
|
|
67
|
+
paddingBottom: interItemMarginWithDivider
|
|
68
|
+
});
|
|
69
|
+
/**
|
|
70
|
+
* ListItem is responsible for rendering icon or a bullet as side item
|
|
71
|
+
*/
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
const ListItem = ({
|
|
75
|
+
tokens,
|
|
76
|
+
variant,
|
|
77
|
+
icon,
|
|
78
|
+
iconColor,
|
|
79
|
+
iconSize,
|
|
80
|
+
showDivider,
|
|
81
|
+
children,
|
|
82
|
+
isLastItem
|
|
83
|
+
}) => {
|
|
84
|
+
const themeTokens = useThemeTokens('List', tokens, variant);
|
|
85
|
+
const itemStyles = selectItemStyles(themeTokens);
|
|
86
|
+
const itemBlockStyles = selectItemBlockStyles(themeTokens);
|
|
87
|
+
const dividerStyles = selectDividerStyles(themeTokens);
|
|
88
|
+
const itemBulletContainerStyles = selectBulletContainerStyles(themeTokens);
|
|
89
|
+
const itemBulletStyles = selectBulletStyles(themeTokens);
|
|
90
|
+
const iconTokens = selectItemIconTokens(themeTokens);
|
|
91
|
+
const sideItemContainerStyles = selectSideItemContainerStyles(themeTokens);
|
|
92
|
+
const accessibilityRole = Platform.select({
|
|
93
|
+
web: 'listitem',
|
|
94
|
+
default: 'item'
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
const areChildrenStrings = () => {
|
|
98
|
+
if (Array.isArray(children)) {
|
|
99
|
+
return children.every(child => typeof child === 'string');
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
return typeof children === 'string';
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
const renderItem = () => {
|
|
106
|
+
if (areChildrenStrings()) {
|
|
107
|
+
return /*#__PURE__*/React.createElement(Text, {
|
|
108
|
+
style: itemStyles
|
|
109
|
+
}, children);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
return /*#__PURE__*/React.createElement(View, null, children);
|
|
113
|
+
};
|
|
114
|
+
/**
|
|
115
|
+
* Function responsible returning styling, in case the item is the last shouldn't
|
|
116
|
+
* add extra margin on the bottom, if "showDivider" is true it should add a divider
|
|
117
|
+
* and custom margin and padding, otherwise just adds a margin to the bottom
|
|
118
|
+
*/
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
const getContainerStyle = () => {
|
|
122
|
+
if (isLastItem) {
|
|
123
|
+
return undefined;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
if (showDivider) {
|
|
127
|
+
return dividerStyles;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
return itemBlockStyles;
|
|
131
|
+
};
|
|
132
|
+
/**
|
|
133
|
+
* Renders item bullet or Icon in case it's defined
|
|
134
|
+
* in case children are string the icon is centered otherwise
|
|
135
|
+
* it will align itself at start of the container
|
|
136
|
+
*/
|
|
137
|
+
|
|
138
|
+
|
|
139
|
+
const renderMarker = () => {
|
|
140
|
+
const IconComponent = icon || /*#__PURE__*/React.createElement(React.Fragment, null);
|
|
141
|
+
|
|
142
|
+
if (icon) {
|
|
143
|
+
return /*#__PURE__*/React.createElement(View, {
|
|
144
|
+
style: [sideItemContainerStyles, areChildrenStrings() ? staticStyles.centeredIcons : undefined]
|
|
145
|
+
}, /*#__PURE__*/React.createElement(IconComponent, {
|
|
146
|
+
tokens: { ...iconTokens,
|
|
147
|
+
size: iconSize || iconTokens.size,
|
|
148
|
+
color: iconColor || iconTokens.color
|
|
149
|
+
}
|
|
150
|
+
}));
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
return /*#__PURE__*/React.createElement(View, {
|
|
154
|
+
style: [sideItemContainerStyles, itemBulletContainerStyles]
|
|
155
|
+
}, /*#__PURE__*/React.createElement(View, {
|
|
156
|
+
style: itemBulletStyles,
|
|
157
|
+
testID: "unordered-item-bullet"
|
|
158
|
+
}));
|
|
159
|
+
};
|
|
160
|
+
|
|
161
|
+
return /*#__PURE__*/React.createElement(View, {
|
|
162
|
+
style: [staticStyles.itemContainer, getContainerStyle()],
|
|
163
|
+
accessibilityRole: accessibilityRole
|
|
164
|
+
}, renderMarker(), renderItem());
|
|
165
|
+
};
|
|
166
|
+
|
|
167
|
+
const staticStyles = StyleSheet.create({
|
|
168
|
+
itemContainer: {
|
|
169
|
+
flexDirection: 'row'
|
|
170
|
+
},
|
|
171
|
+
centeredIcons: {
|
|
172
|
+
justifyContent: 'center'
|
|
173
|
+
}
|
|
174
|
+
});
|
|
175
|
+
ListItem.propTypes = {
|
|
176
|
+
tokens: getTokensPropType('List'),
|
|
177
|
+
variant: variantProp.propType,
|
|
178
|
+
children: PropTypes.node.isRequired,
|
|
179
|
+
|
|
180
|
+
/**
|
|
181
|
+
* Renders side item icon
|
|
182
|
+
*/
|
|
183
|
+
icon: PropTypes.func,
|
|
184
|
+
|
|
185
|
+
/**
|
|
186
|
+
* Will set display icon color
|
|
187
|
+
*/
|
|
188
|
+
iconColor: PropTypes.string,
|
|
189
|
+
|
|
190
|
+
/**
|
|
191
|
+
* Allow the user define the icon size if not defined the theme's file
|
|
192
|
+
*/
|
|
193
|
+
iconSize: PropTypes.number,
|
|
194
|
+
|
|
195
|
+
/**
|
|
196
|
+
* @ignore
|
|
197
|
+
* Defined by parent if it's last item on the list
|
|
198
|
+
*/
|
|
199
|
+
isLastItem: PropTypes.bool,
|
|
200
|
+
|
|
201
|
+
/**
|
|
202
|
+
* @ignore
|
|
203
|
+
* In case it is not the last item allow display divider
|
|
204
|
+
*/
|
|
205
|
+
showDivider: PropTypes.bool
|
|
206
|
+
};
|
|
207
|
+
export default ListItem;
|
|
@@ -1,28 +1,11 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import { Text } from 'react-native';
|
|
3
2
|
import PropTypes from 'prop-types';
|
|
4
3
|
import ButtonBase from '../Button/ButtonBase';
|
|
5
|
-
import {
|
|
4
|
+
import { useThemeTokensCallback } from '../ThemeProvider';
|
|
6
5
|
import { a11yProps, copyPropTypes, getTokensPropType, hrefAttrsProp, linkProps, selectTokens, variantProp } from '../utils';
|
|
7
6
|
import useCopy from '../utils/useCopy';
|
|
8
7
|
import dictionary from './dictionary';
|
|
9
8
|
|
|
10
|
-
const selectTextStyles = ({
|
|
11
|
-
color,
|
|
12
|
-
fontName,
|
|
13
|
-
fontSize,
|
|
14
|
-
fontWeight,
|
|
15
|
-
lineHeight,
|
|
16
|
-
textLine
|
|
17
|
-
}) => applyTextStyles({
|
|
18
|
-
color,
|
|
19
|
-
fontName,
|
|
20
|
-
fontSize,
|
|
21
|
-
fontWeight,
|
|
22
|
-
lineHeight,
|
|
23
|
-
textDecorationLine: textLine
|
|
24
|
-
});
|
|
25
|
-
|
|
26
9
|
function PageButton({
|
|
27
10
|
label,
|
|
28
11
|
onPress,
|
|
@@ -41,8 +24,6 @@ function PageButton({
|
|
|
41
24
|
|
|
42
25
|
const getButtonTokens = buttonState => selectTokens('Button', getTokens(buttonState));
|
|
43
26
|
|
|
44
|
-
const getTextStyles = buttonState => selectTextStyles(getTokens(buttonState));
|
|
45
|
-
|
|
46
27
|
const activeProps = isActive ? {
|
|
47
28
|
selected: true,
|
|
48
29
|
...a11yProps.nonFocusableProps,
|
|
@@ -67,11 +48,7 @@ function PageButton({
|
|
|
67
48
|
};
|
|
68
49
|
return /*#__PURE__*/React.createElement(ButtonBase, Object.assign({}, buttonProps, {
|
|
69
50
|
tokens: getButtonTokens
|
|
70
|
-
}, activeProps),
|
|
71
|
-
return /*#__PURE__*/React.createElement(Text, {
|
|
72
|
-
style: getTextStyles(buttonState)
|
|
73
|
-
}, label);
|
|
74
|
-
});
|
|
51
|
+
}, activeProps), label);
|
|
75
52
|
}
|
|
76
53
|
|
|
77
54
|
PageButton.propTypes = {
|