@telus-uds/components-base 0.0.2-prerelease.1 → 0.0.2-prerelease.5
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 +36 -0
- package/__fixtures__/testTheme.js +264 -84
- package/__tests__/Box/Box.test.jsx +81 -58
- package/__tests__/Card/Card.test.jsx +63 -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__/Pagination/Pagination.test.jsx +160 -0
- package/__tests__/Spacer/Spacer.test.jsx +63 -0
- package/__tests__/StackView/StackView.test.jsx +242 -0
- package/__tests__/StackView/StackWrap.test.jsx +47 -0
- package/__tests__/StackView/getStackedContent.test.jsx +295 -0
- package/__tests__/TextInput/TextInput.test.jsx +146 -0
- package/__tests__/ThemeProvider/useThemeTokens.test.jsx +5 -3
- package/__tests__/utils/spacing.test.jsx +273 -0
- package/__tests__/utils/useUniqueId.test.js +31 -0
- package/babel.config.json +8 -0
- package/jest.config.js +7 -6
- package/lib/A11yInfoProvider/index.js +2 -2
- package/lib/A11yText/index.js +1 -3
- package/lib/ActivityIndicator/Spinner.web.js +3 -5
- package/lib/Box/Box.js +117 -82
- package/lib/Button/Button.js +1 -3
- package/lib/Button/ButtonBase.js +9 -21
- package/lib/Button/ButtonGroup.js +14 -25
- package/lib/Button/ButtonLink.js +1 -3
- package/lib/Card/Card.js +103 -0
- package/lib/Card/index.js +2 -0
- package/lib/Divider/Divider.js +40 -4
- package/lib/ExpandCollapse/Accordion.js +1 -3
- package/lib/ExpandCollapse/Control.js +3 -5
- package/lib/ExpandCollapse/Panel.js +2 -4
- package/lib/Feedback/Feedback.js +110 -0
- package/lib/Feedback/index.js +2 -0
- package/lib/FlexGrid/Col/Col.js +3 -5
- package/lib/FlexGrid/FlexGrid.js +1 -3
- package/lib/FlexGrid/Row/Row.js +1 -3
- package/lib/FlexGrid/providers/GutterContext.js +1 -1
- package/lib/Icon/Icon.js +1 -1
- package/lib/InputLabel/InputLabel.js +86 -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/Link/ChevronLink.js +1 -3
- package/lib/Link/Link.js +1 -3
- package/lib/Link/LinkBase.js +11 -7
- package/lib/Link/TextButton.js +1 -3
- package/lib/Pagination/PageButton.js +85 -0
- package/lib/Pagination/Pagination.js +118 -0
- package/lib/Pagination/SideButton.js +108 -0
- package/lib/Pagination/dictionary.js +18 -0
- package/lib/Pagination/index.js +2 -0
- package/lib/Pagination/useCopy.js +10 -0
- package/lib/Pagination/usePagination.js +70 -0
- package/lib/SideNav/Item.js +4 -6
- package/lib/SideNav/ItemsGroup.js +11 -11
- package/lib/SideNav/SideNav.js +2 -4
- package/lib/Spacer/Spacer.js +98 -0
- package/lib/Spacer/index.js +2 -0
- package/lib/StackView/StackView.js +105 -0
- package/lib/StackView/StackWrap.js +32 -0
- package/lib/StackView/StackWrap.native.js +3 -0
- package/lib/StackView/StackWrapBox.js +85 -0
- package/lib/StackView/StackWrapGap.js +45 -0
- package/lib/StackView/common.js +30 -0
- package/lib/StackView/getStackedContent.js +111 -0
- package/lib/StackView/index.js +5 -0
- package/lib/TextInput/TextInput.js +337 -0
- package/lib/TextInput/index.js +2 -0
- package/lib/ThemeProvider/ThemeProvider.js +2 -2
- package/lib/ThemeProvider/useThemeTokens.js +34 -6
- package/lib/ThemeProvider/utils/theme-tokens.js +37 -9
- package/lib/ToggleSwitch/ToggleSwitch.js +17 -47
- package/lib/Typography/Typography.js +1 -7
- package/lib/ViewportProvider/index.js +1 -1
- package/lib/index.js +8 -1
- package/lib/utils/index.js +2 -1
- package/lib/utils/input.js +3 -1
- package/lib/utils/propTypes.js +103 -8
- package/lib/utils/spacing/index.js +2 -0
- package/lib/utils/spacing/useSpacingScale.js +102 -0
- package/lib/utils/spacing/utils.js +32 -0
- package/lib/utils/useUniqueId.js +12 -0
- package/package.json +6 -9
- package/release-context.json +4 -4
- package/src/Box/Box.jsx +117 -80
- package/src/Button/ButtonBase.jsx +8 -21
- package/src/Button/ButtonGroup.jsx +13 -17
- package/src/Card/Card.jsx +101 -0
- package/src/Card/index.js +3 -0
- package/src/Divider/Divider.jsx +38 -3
- package/src/ExpandCollapse/Control.jsx +2 -3
- package/src/Feedback/Feedback.jsx +99 -0
- package/src/Feedback/index.js +3 -0
- package/src/FlexGrid/Col/Col.jsx +4 -2
- package/src/Icon/Icon.jsx +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/Link/LinkBase.jsx +9 -3
- package/src/Pagination/PageButton.jsx +80 -0
- package/src/Pagination/Pagination.jsx +135 -0
- package/src/Pagination/SideButton.jsx +93 -0
- package/src/Pagination/dictionary.js +18 -0
- package/src/Pagination/index.js +3 -0
- package/src/Pagination/useCopy.js +7 -0
- package/src/Pagination/usePagination.js +69 -0
- package/src/SideNav/Item.jsx +3 -3
- package/src/SideNav/ItemsGroup.jsx +11 -13
- package/src/Spacer/Spacer.jsx +91 -0
- package/src/Spacer/index.js +3 -0
- package/src/StackView/StackView.jsx +103 -0
- package/src/StackView/StackWrap.jsx +33 -0
- package/src/StackView/StackWrap.native.jsx +4 -0
- package/src/StackView/StackWrapBox.jsx +82 -0
- package/src/StackView/StackWrapGap.jsx +39 -0
- package/src/StackView/common.jsx +28 -0
- package/src/StackView/getStackedContent.jsx +106 -0
- package/src/StackView/index.js +6 -0
- package/src/TextInput/TextInput.jsx +325 -0
- package/src/TextInput/index.js +3 -0
- package/src/ThemeProvider/useThemeTokens.js +34 -7
- package/src/ThemeProvider/utils/theme-tokens.js +37 -8
- package/src/ToggleSwitch/ToggleSwitch.jsx +23 -43
- package/src/Typography/Typography.jsx +0 -4
- package/src/index.js +8 -1
- package/src/utils/index.js +1 -0
- package/src/utils/input.js +2 -1
- package/src/utils/propTypes.js +105 -16
- package/src/utils/spacing/index.js +3 -0
- package/src/utils/spacing/useSpacingScale.js +93 -0
- package/src/utils/spacing/utils.js +28 -0
- 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 +46 -17
- package/stories/Button/Button.stories.jsx +17 -21
- package/stories/Button/ButtonGroup.stories.jsx +2 -1
- package/stories/Button/ButtonLink.stories.jsx +6 -4
- package/stories/Card/Card.stories.jsx +62 -0
- package/stories/Divider/Divider.stories.jsx +26 -2
- package/stories/ExpandCollapse/ExpandCollapse.stories.jsx +74 -79
- package/stories/Feedback/Feedback.stories.jsx +97 -0
- package/stories/FlexGrid/01 FlexGrid.stories.jsx +20 -7
- package/stories/Icon/Icon.stories.jsx +11 -3
- package/stories/InputLabel/InputLabel.stories.jsx +37 -0
- package/stories/Link/ChevronLink.stories.jsx +20 -4
- package/stories/Link/Link.stories.jsx +24 -3
- package/stories/Link/TextButton.stories.jsx +24 -3
- package/stories/Pagination/Pagination.stories.jsx +64 -0
- package/stories/SideNav/SideNav.stories.jsx +17 -2
- package/stories/Spacer/Spacer.stories.jsx +33 -0
- package/stories/StackView/StackView.stories.jsx +65 -0
- package/stories/StackView/StackWrap.stories.jsx +52 -0
- package/stories/TextInput/TextInput.stories.jsx +103 -0
- package/stories/ToggleSwitch/ToggleSwitch.stories.jsx +16 -3
- package/stories/Typography/Typography.stories.jsx +12 -3
- package/stories/platform-supports.web.jsx +1 -1
- package/stories/supports.jsx +113 -13
- package/babel.config.js +0 -3
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import React from 'react'
|
|
2
|
+
import { Text } from 'react-native'
|
|
3
|
+
import PropTypes from 'prop-types'
|
|
4
|
+
|
|
5
|
+
import ButtonBase from '../Button/ButtonBase'
|
|
6
|
+
import { applyTextStyles, useThemeTokensCallback } from '../ThemeProvider'
|
|
7
|
+
import {
|
|
8
|
+
a11yProps,
|
|
9
|
+
copyPropTypes,
|
|
10
|
+
getTokensPropType,
|
|
11
|
+
hrefAttrsProp,
|
|
12
|
+
linkProps,
|
|
13
|
+
selectTokens,
|
|
14
|
+
variantProp
|
|
15
|
+
} from '../utils'
|
|
16
|
+
|
|
17
|
+
import useCopy from './useCopy'
|
|
18
|
+
import dictionary from './dictionary'
|
|
19
|
+
|
|
20
|
+
const selectTextStyles = ({ color, fontName, fontSize, fontWeight, lineHeight, textLine }) =>
|
|
21
|
+
applyTextStyles({
|
|
22
|
+
color,
|
|
23
|
+
fontName,
|
|
24
|
+
fontSize,
|
|
25
|
+
fontWeight,
|
|
26
|
+
lineHeight,
|
|
27
|
+
textDecorationLine: textLine
|
|
28
|
+
})
|
|
29
|
+
|
|
30
|
+
function PageButton({ label, onPress, href, isActive, copy, variant, tokens, ...props }) {
|
|
31
|
+
const getTokens = useThemeTokensCallback('PaginationPageButton', tokens, variant)
|
|
32
|
+
|
|
33
|
+
const getCopy = useCopy({ dictionary, copy })
|
|
34
|
+
|
|
35
|
+
const getButtonTokens = (buttonState) => selectTokens('Button', getTokens(buttonState))
|
|
36
|
+
const getTextStyles = (buttonState) => selectTextStyles(getTokens(buttonState))
|
|
37
|
+
|
|
38
|
+
const activeProps = isActive
|
|
39
|
+
? {
|
|
40
|
+
selected: true,
|
|
41
|
+
...a11yProps.nonFocusableProps,
|
|
42
|
+
// a brute fix for the focus state being stuck on an active item since it becomes non-focusable
|
|
43
|
+
// (see https://github.com/telus/universal-design-system/pull/577#issuecomment-931344107)
|
|
44
|
+
key: 'active-item'
|
|
45
|
+
}
|
|
46
|
+
: {}
|
|
47
|
+
|
|
48
|
+
const accessibilityRole = href !== undefined ? 'link' : 'button'
|
|
49
|
+
const activeLabel = isActive ? ` ${getCopy('currentLabel')}` : ''
|
|
50
|
+
const accessibilityLabel = `${getCopy('goToLabel')} ${label}${activeLabel}`
|
|
51
|
+
|
|
52
|
+
const { hrefAttrs, rest } = hrefAttrsProp.bundle(props)
|
|
53
|
+
const buttonProps = {
|
|
54
|
+
accessibilityRole,
|
|
55
|
+
accessibilityLabel,
|
|
56
|
+
onPress,
|
|
57
|
+
href,
|
|
58
|
+
hrefAttrs,
|
|
59
|
+
...rest
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
return (
|
|
63
|
+
<ButtonBase {...buttonProps} tokens={getButtonTokens} {...activeProps}>
|
|
64
|
+
{(buttonState) => {
|
|
65
|
+
return <Text style={getTextStyles(buttonState)}>{label}</Text>
|
|
66
|
+
}}
|
|
67
|
+
</ButtonBase>
|
|
68
|
+
)
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
PageButton.propTypes = {
|
|
72
|
+
label: PropTypes.string,
|
|
73
|
+
isActive: PropTypes.bool,
|
|
74
|
+
copy: copyPropTypes,
|
|
75
|
+
variant: variantProp.propType,
|
|
76
|
+
tokens: getTokensPropType('PaginationPageButton'),
|
|
77
|
+
...linkProps.types
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export default PageButton
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
import React from 'react'
|
|
2
|
+
import { View, Text, StyleSheet } from 'react-native'
|
|
3
|
+
|
|
4
|
+
import { componentPropType, copyPropTypes, getTokensPropType, variantProp } from '../utils'
|
|
5
|
+
import { applyTextStyles, useThemeTokens } from '../ThemeProvider'
|
|
6
|
+
import { useViewport } from '../ViewportProvider'
|
|
7
|
+
import Box from '../Box'
|
|
8
|
+
|
|
9
|
+
import usePagination from './usePagination'
|
|
10
|
+
import PageButton from './PageButton'
|
|
11
|
+
import SideButton from './SideButton'
|
|
12
|
+
|
|
13
|
+
const selectTextStyles = ({ color, fontName, fontSize, fontWeight, lineHeight }) =>
|
|
14
|
+
applyTextStyles({
|
|
15
|
+
color,
|
|
16
|
+
fontName,
|
|
17
|
+
fontSize,
|
|
18
|
+
fontWeight,
|
|
19
|
+
lineHeight
|
|
20
|
+
})
|
|
21
|
+
|
|
22
|
+
function Pagination({
|
|
23
|
+
children,
|
|
24
|
+
copy = 'en',
|
|
25
|
+
variant,
|
|
26
|
+
tokens,
|
|
27
|
+
sideButtonVariant,
|
|
28
|
+
sideButtonTokens
|
|
29
|
+
}) {
|
|
30
|
+
const viewport = useViewport()
|
|
31
|
+
const { truncateAbove, gap, ...themeTokens } = useThemeTokens('Pagination', tokens, variant, {
|
|
32
|
+
viewport
|
|
33
|
+
})
|
|
34
|
+
|
|
35
|
+
const items = React.Children.toArray(children)
|
|
36
|
+
|
|
37
|
+
const {
|
|
38
|
+
isItemActive,
|
|
39
|
+
getItemProps,
|
|
40
|
+
showPrevious,
|
|
41
|
+
showNext,
|
|
42
|
+
nextItemProps,
|
|
43
|
+
previousItemProps,
|
|
44
|
+
shouldRenderButton,
|
|
45
|
+
shouldRenderEllipsis
|
|
46
|
+
} = usePagination({
|
|
47
|
+
items,
|
|
48
|
+
truncateAbove
|
|
49
|
+
})
|
|
50
|
+
|
|
51
|
+
const ellipsisTextStyles = selectTextStyles(themeTokens)
|
|
52
|
+
|
|
53
|
+
if (items.length === 0) {
|
|
54
|
+
return null
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// TODO: replace with a spacing component when https://github.com/telus/universal-design-system/pull/531 is implemented
|
|
58
|
+
// concatenate all items to easily wrap them in identical spacing components
|
|
59
|
+
const buttons = [
|
|
60
|
+
showPrevious && (
|
|
61
|
+
<SideButton
|
|
62
|
+
{...previousItemProps}
|
|
63
|
+
direction="previous"
|
|
64
|
+
copy={copy}
|
|
65
|
+
variant={sideButtonVariant}
|
|
66
|
+
tokens={sideButtonTokens}
|
|
67
|
+
/>
|
|
68
|
+
),
|
|
69
|
+
...items.map((child, itemIndex) => {
|
|
70
|
+
const buttonLabel = `${itemIndex + 1}`
|
|
71
|
+
const itemProps = getItemProps(itemIndex)
|
|
72
|
+
|
|
73
|
+
if (shouldRenderButton(itemIndex)) {
|
|
74
|
+
return (
|
|
75
|
+
<PageButton
|
|
76
|
+
{...itemProps}
|
|
77
|
+
label={buttonLabel}
|
|
78
|
+
copy={copy}
|
|
79
|
+
isActive={isItemActive(itemIndex)}
|
|
80
|
+
/>
|
|
81
|
+
)
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
if (shouldRenderEllipsis(itemIndex)) {
|
|
85
|
+
return <Text style={ellipsisTextStyles}>...</Text>
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
return null
|
|
89
|
+
}),
|
|
90
|
+
showNext && (
|
|
91
|
+
<SideButton
|
|
92
|
+
{...nextItemProps}
|
|
93
|
+
direction="next"
|
|
94
|
+
copy={copy}
|
|
95
|
+
variant={sideButtonVariant}
|
|
96
|
+
tokens={sideButtonTokens}
|
|
97
|
+
/>
|
|
98
|
+
)
|
|
99
|
+
]
|
|
100
|
+
|
|
101
|
+
return (
|
|
102
|
+
<View style={staticStyles.container}>
|
|
103
|
+
{buttons
|
|
104
|
+
// keep the keys in-line with the page numbers regardless of which buttons are actually rendered
|
|
105
|
+
.map((element, index) => [element, `page-${index + 1}`])
|
|
106
|
+
.filter(([element]) => element !== null)
|
|
107
|
+
.map(([element, key]) => (
|
|
108
|
+
<Box right={gap} key={key}>
|
|
109
|
+
{element}
|
|
110
|
+
</Box>
|
|
111
|
+
))}
|
|
112
|
+
</View>
|
|
113
|
+
)
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
Pagination.PageButton = PageButton
|
|
117
|
+
|
|
118
|
+
Pagination.propTypes = {
|
|
119
|
+
children: componentPropType('PageButton'),
|
|
120
|
+
copy: copyPropTypes,
|
|
121
|
+
variant: variantProp.propType,
|
|
122
|
+
tokens: getTokensPropType('Pagination'),
|
|
123
|
+
sideButtonVariant: variantProp.propType,
|
|
124
|
+
sideButtonTokens: getTokensPropType('PaginationSideButton')
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
const staticStyles = StyleSheet.create({
|
|
128
|
+
container: {
|
|
129
|
+
flexDirection: 'row',
|
|
130
|
+
flexWrap: 'wrap',
|
|
131
|
+
alignItems: 'center'
|
|
132
|
+
}
|
|
133
|
+
})
|
|
134
|
+
|
|
135
|
+
export default Pagination
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import React from 'react'
|
|
2
|
+
import { StyleSheet, View, Text, PixelRatio } from 'react-native'
|
|
3
|
+
|
|
4
|
+
import PropTypes from 'prop-types'
|
|
5
|
+
|
|
6
|
+
import ButtonBase from '../Button/ButtonBase'
|
|
7
|
+
import { applyTextStyles, useThemeTokensCallback } from '../ThemeProvider'
|
|
8
|
+
import { useViewport } from '../ViewportProvider'
|
|
9
|
+
import { copyPropTypes, hrefAttrsProp, linkProps, selectTokens } from '../utils'
|
|
10
|
+
|
|
11
|
+
import dictionary from './dictionary'
|
|
12
|
+
import useCopy from './useCopy'
|
|
13
|
+
|
|
14
|
+
const selectTextStyles = ({ color, fontName, fontSize, fontWeight, lineHeight }) =>
|
|
15
|
+
applyTextStyles({
|
|
16
|
+
color,
|
|
17
|
+
fontName,
|
|
18
|
+
fontSize,
|
|
19
|
+
fontWeight,
|
|
20
|
+
lineHeight
|
|
21
|
+
})
|
|
22
|
+
|
|
23
|
+
const selectIconTokens = ({ color, iconSize, iconTranslateX }) => {
|
|
24
|
+
// Scale icon with text, but with a cap so text isn't squashed at large scales
|
|
25
|
+
const iconScale = Math.min(PixelRatio.getFontScale(), 2)
|
|
26
|
+
|
|
27
|
+
return {
|
|
28
|
+
color,
|
|
29
|
+
size: iconSize * iconScale,
|
|
30
|
+
translateX: iconTranslateX
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function SideButton({ direction = 'previous', onPress, href, copy, variant, tokens, ...props }) {
|
|
35
|
+
const viewport = useViewport()
|
|
36
|
+
const buttonVariant = { direction, viewport, ...variant }
|
|
37
|
+
const getTokens = useThemeTokensCallback('PaginationSideButton', tokens, buttonVariant)
|
|
38
|
+
|
|
39
|
+
const getCopy = useCopy({ dictionary, copy })
|
|
40
|
+
|
|
41
|
+
const { icon: IconComponent } = getTokens(tokens, buttonVariant)
|
|
42
|
+
|
|
43
|
+
const getButtonTokens = (buttonState) => selectTokens('Button', getTokens(buttonState))
|
|
44
|
+
const getIconTokens = (buttonState) => selectIconTokens(getTokens(buttonState))
|
|
45
|
+
const getTextStyles = (buttonState) => selectTextStyles(getTokens(buttonState))
|
|
46
|
+
|
|
47
|
+
const label = direction === 'previous' ? getCopy('previousText') : getCopy('nextText')
|
|
48
|
+
const showLabel = viewport !== 'sm' && viewport !== 'xs'
|
|
49
|
+
|
|
50
|
+
const accessibilityLabel =
|
|
51
|
+
direction === 'previous' ? getCopy('previousLabel') : getCopy('nextLabel')
|
|
52
|
+
const accessibilityRole = href !== undefined ? 'link' : 'button'
|
|
53
|
+
|
|
54
|
+
const { hrefAttrs, rest } = hrefAttrsProp.bundle(props)
|
|
55
|
+
const buttonProps = {
|
|
56
|
+
accessibilityRole,
|
|
57
|
+
accessibilityLabel,
|
|
58
|
+
onPress,
|
|
59
|
+
href,
|
|
60
|
+
hrefAttrs,
|
|
61
|
+
...rest
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
return (
|
|
65
|
+
<ButtonBase {...buttonProps} tokens={getButtonTokens}>
|
|
66
|
+
{(buttonState) => (
|
|
67
|
+
<View style={staticStyles.contentContainer}>
|
|
68
|
+
{direction === 'previous' && IconComponent && (
|
|
69
|
+
<IconComponent tokens={getIconTokens(buttonState)} />
|
|
70
|
+
)}
|
|
71
|
+
{showLabel && <Text style={getTextStyles(buttonState)}>{label}</Text>}
|
|
72
|
+
{direction === 'next' && IconComponent && (
|
|
73
|
+
<IconComponent tokens={getIconTokens(buttonState)} />
|
|
74
|
+
)}
|
|
75
|
+
</View>
|
|
76
|
+
)}
|
|
77
|
+
</ButtonBase>
|
|
78
|
+
)
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
SideButton.propTypes = {
|
|
82
|
+
direction: PropTypes.oneOf(['previous', 'next']),
|
|
83
|
+
copy: copyPropTypes,
|
|
84
|
+
...linkProps.types
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
export default SideButton
|
|
88
|
+
|
|
89
|
+
const staticStyles = StyleSheet.create({
|
|
90
|
+
contentContainer: {
|
|
91
|
+
flexDirection: 'row'
|
|
92
|
+
}
|
|
93
|
+
})
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export default {
|
|
2
|
+
en: {
|
|
3
|
+
goToLabel: 'Go to page number',
|
|
4
|
+
currentLabel: '(current)',
|
|
5
|
+
previousLabel: 'Go to previous page',
|
|
6
|
+
previousText: 'Previous',
|
|
7
|
+
nextLabel: 'Go to next page',
|
|
8
|
+
nextText: 'Next'
|
|
9
|
+
},
|
|
10
|
+
fr: {
|
|
11
|
+
goToLabel: 'Aller au page n°',
|
|
12
|
+
currentLabel: '(page actuelle)',
|
|
13
|
+
previousLabel: 'Aller au page précédent',
|
|
14
|
+
previousText: 'Précédent',
|
|
15
|
+
nextLabel: 'Aller au prochain page',
|
|
16
|
+
nextText: 'Suivant'
|
|
17
|
+
}
|
|
18
|
+
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Handles configurable truncating of pagination items.
|
|
3
|
+
*
|
|
4
|
+
* @param {object} props
|
|
5
|
+
* @param {React.Element[]} items
|
|
6
|
+
* @param {number} truncateAbove
|
|
7
|
+
*/
|
|
8
|
+
function usePagination({ items, truncateAbove }) {
|
|
9
|
+
const activeItemIndex = Math.max(
|
|
10
|
+
items.findIndex((item) => item.props.isActive),
|
|
11
|
+
0 // default to the first item if none is marked as active
|
|
12
|
+
)
|
|
13
|
+
|
|
14
|
+
const getItemProps = (index) => {
|
|
15
|
+
const { onPress, href, hrefAttrs, variant, tokens } = items[index]?.props ?? {}
|
|
16
|
+
return { onPress, href, hrefAttrs, variant, tokens }
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const windowSize = truncateAbove > 4 ? 3 : 1
|
|
20
|
+
const truncateEnabled = items.length > truncateAbove
|
|
21
|
+
|
|
22
|
+
const truncateWindowStart = windowSize
|
|
23
|
+
const truncateWindowEnd = items.length - 1 - windowSize
|
|
24
|
+
|
|
25
|
+
// basically how many items next to the currently active one do we want to render
|
|
26
|
+
const activeWindowStart = activeItemIndex - (windowSize - 1) / 2
|
|
27
|
+
const activeWindowEnd = activeItemIndex + (windowSize - 1) / 2
|
|
28
|
+
|
|
29
|
+
const isFirstActive = activeItemIndex === 0
|
|
30
|
+
const isLastActive = activeItemIndex === items.length - 1
|
|
31
|
+
|
|
32
|
+
// start truncating when the active item is within the truncate window
|
|
33
|
+
const isLeftTruncated = truncateEnabled && activeItemIndex >= truncateWindowStart
|
|
34
|
+
const isRightTruncated = truncateEnabled && activeItemIndex <= truncateWindowEnd
|
|
35
|
+
|
|
36
|
+
function shouldRenderEllipsis(itemIndex) {
|
|
37
|
+
const isNextToFirst = itemIndex === 1
|
|
38
|
+
const isNextToLast = itemIndex === items.length - 2
|
|
39
|
+
|
|
40
|
+
return (isLeftTruncated && isNextToFirst) || (isRightTruncated && isNextToLast)
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function shouldRenderButton(itemIndex) {
|
|
44
|
+
const isFirst = itemIndex === 0
|
|
45
|
+
const isLast = itemIndex === items.length - 1
|
|
46
|
+
const isInActiveWindow = itemIndex >= activeWindowStart && itemIndex <= activeWindowEnd
|
|
47
|
+
|
|
48
|
+
return (
|
|
49
|
+
isFirst ||
|
|
50
|
+
isLast ||
|
|
51
|
+
isInActiveWindow ||
|
|
52
|
+
(!isLeftTruncated && itemIndex <= truncateWindowStart) ||
|
|
53
|
+
(!isRightTruncated && itemIndex >= truncateWindowEnd)
|
|
54
|
+
)
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
return {
|
|
58
|
+
showPrevious: !isFirstActive,
|
|
59
|
+
showNext: !isLastActive,
|
|
60
|
+
shouldRenderButton,
|
|
61
|
+
shouldRenderEllipsis,
|
|
62
|
+
isItemActive: (itemIndex) => itemIndex === activeItemIndex,
|
|
63
|
+
getItemProps,
|
|
64
|
+
nextItemProps: getItemProps(activeItemIndex + 1),
|
|
65
|
+
previousItemProps: getItemProps(activeItemIndex - 1)
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export default usePagination
|
package/src/SideNav/Item.jsx
CHANGED
|
@@ -62,14 +62,14 @@ const Item = ({
|
|
|
62
62
|
...rest
|
|
63
63
|
})
|
|
64
64
|
|
|
65
|
-
const getTokens = useThemeTokensCallback('SideNavItem')
|
|
65
|
+
const getTokens = useThemeTokensCallback('SideNavItem', tokens, variant)
|
|
66
66
|
const getAppearanceState = ({ hovered }) => ({
|
|
67
67
|
hover: hovered,
|
|
68
68
|
active: isActive,
|
|
69
69
|
expanded: isExpanded
|
|
70
70
|
})
|
|
71
71
|
const getPressableStyle = (pressableState) =>
|
|
72
|
-
selectItemStyles(getTokens(
|
|
72
|
+
selectItemStyles(getTokens(getAppearanceState(pressableState)))
|
|
73
73
|
|
|
74
74
|
return (
|
|
75
75
|
<Pressable
|
|
@@ -79,7 +79,7 @@ const Item = ({
|
|
|
79
79
|
testID={testID}
|
|
80
80
|
>
|
|
81
81
|
{(pressableState) => {
|
|
82
|
-
const themeTokens = getTokens(
|
|
82
|
+
const themeTokens = getTokens(getAppearanceState(pressableState))
|
|
83
83
|
return <ItemContent tokens={themeTokens}>{children}</ItemContent>
|
|
84
84
|
}}
|
|
85
85
|
</Pressable>
|
|
@@ -28,25 +28,23 @@ const ItemsGroup = ({
|
|
|
28
28
|
onToggle
|
|
29
29
|
}) => {
|
|
30
30
|
// A SideNav control uses the same style and theme as SideNavItem, with a 'parent' variant,
|
|
31
|
-
// plus control-specific tokens from the SideNavItemsGroup theme.
|
|
31
|
+
// plus control-specific tokens from the SideNavItemsGroup theme (e.g. open/close icon, etc).
|
|
32
32
|
const getAppearance = (appearance) => ({ ...variant, ...appearance, active: isActive })
|
|
33
33
|
const getItemAppearance = (appearance) => ({ ...getAppearance(appearance), type: 'parent' })
|
|
34
34
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
const panelTokensGetterProp = (appearance) =>
|
|
39
|
-
selectTokens('ExpandCollapsePanel', getGroupTokens(tokens, getAppearance(appearance)))
|
|
35
|
+
const getGroupTokens = useThemeTokensCallback('SideNavItemsGroup', tokens, variant)
|
|
36
|
+
const getPanelTokens = (appearance) =>
|
|
37
|
+
selectTokens('ExpandCollapsePanel', getGroupTokens(getAppearance(appearance)))
|
|
40
38
|
|
|
41
|
-
const getItemTokens = useThemeTokensCallback('SideNavItem')
|
|
42
|
-
const
|
|
39
|
+
const getItemTokens = useThemeTokensCallback('SideNavItem', itemTokens, variant)
|
|
40
|
+
const getControlTokens = (appearance) =>
|
|
43
41
|
selectTokens('ExpandCollapseControl', {
|
|
44
|
-
...getItemTokens(
|
|
45
|
-
...getGroupTokens(
|
|
42
|
+
...getItemTokens(getItemAppearance(appearance)), // main style from SideNavItem
|
|
43
|
+
...getGroupTokens(getAppearance(appearance)) // control-specific tokens like icon etc
|
|
46
44
|
})
|
|
47
45
|
|
|
48
46
|
const controlContent = (controlState) => {
|
|
49
|
-
const currentItemTokens = getItemTokens(
|
|
47
|
+
const currentItemTokens = getItemTokens(getItemAppearance(controlState))
|
|
50
48
|
return <ItemContent tokens={currentItemTokens}>{label}</ItemContent>
|
|
51
49
|
}
|
|
52
50
|
|
|
@@ -55,8 +53,8 @@ const ItemsGroup = ({
|
|
|
55
53
|
openIds={openGroups}
|
|
56
54
|
panelId={groupId}
|
|
57
55
|
onToggle={onToggle}
|
|
58
|
-
tokens={
|
|
59
|
-
controlTokens={
|
|
56
|
+
tokens={getPanelTokens}
|
|
57
|
+
controlTokens={getControlTokens}
|
|
60
58
|
control={controlContent}
|
|
61
59
|
accessibilityState={{ active: isActive }} // ExpandCollapse.Panel handles expanded state
|
|
62
60
|
>
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import React from 'react'
|
|
2
|
+
import PropTypes from 'prop-types'
|
|
3
|
+
import { StyleSheet, View } from 'react-native'
|
|
4
|
+
|
|
5
|
+
import { useSpacingScale, spacingProps } from '../utils'
|
|
6
|
+
/**
|
|
7
|
+
* @typedef {import('../utils/propTypes.js').SpacingValue} SpacingValue
|
|
8
|
+
* @typedef {import('../utils/propTypes.js').SpacingObject} SpacingObject
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
const selectSizeStyle = (size, direction) => ({
|
|
12
|
+
// Only apply space in one direction at a time, else large spacers will increase the
|
|
13
|
+
// 'across' size of the parent and mess up siblings with styles like `alignItems: stretch`.
|
|
14
|
+
[direction === 'row' ? 'width' : 'height']: size
|
|
15
|
+
})
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* An empty element used to create a gap between components that is sized according to the theme spacing scale,
|
|
19
|
+
* passing its `space` prop ({@link SpacingValue}) to `useSpacingScale`.
|
|
20
|
+
*
|
|
21
|
+
* ## Simple spacing
|
|
22
|
+
*
|
|
23
|
+
* For most simple uses, pass a number to Spacer's `space` prop referring to an index in the theme's
|
|
24
|
+
* spacing scale. For example, for a spacer of the theme's smallest non-zero spacing size:
|
|
25
|
+
*
|
|
26
|
+
* ```jsx
|
|
27
|
+
* <Spacer space={1} />
|
|
28
|
+
* ```
|
|
29
|
+
*
|
|
30
|
+
* ## Responsive spacing
|
|
31
|
+
*
|
|
32
|
+
* Different spacing scale sizes may be chosen for different viewports by passing `space` a {@link SpacingObject}
|
|
33
|
+
* using keys for the viewports at and above which certain spacing indexes should apply.
|
|
34
|
+
*
|
|
35
|
+
* This can be useful when a Spacer is inside a layout with a shape that changes between viewports.
|
|
36
|
+
*
|
|
37
|
+
* For example, a spacer might need no width below 'md' viewport because the items it separates will be on separate lines,
|
|
38
|
+
* but may need a visible size above that viewport, and a wider size at the highest viewport:
|
|
39
|
+
*
|
|
40
|
+
* ```jsx
|
|
41
|
+
* <Spacer space={{ xs: 0, md: 2, xl: 3 }} />
|
|
42
|
+
* ```
|
|
43
|
+
*
|
|
44
|
+
* Note that themes may also define viewport-specific behaviour for indexes on the spacing scale. These viewport
|
|
45
|
+
* props should only be used where necessary to achieve a certain responsive layoutm and shouldn't be used to replace
|
|
46
|
+
* or deviate from responsive spacing behaviour in a theme that is intended to apply universally.
|
|
47
|
+
*
|
|
48
|
+
* ## More options
|
|
49
|
+
*
|
|
50
|
+
* See `useSpacingScale` hook for more options that may be used with the `space` prop.
|
|
51
|
+
*
|
|
52
|
+
* ## Accessibility
|
|
53
|
+
*
|
|
54
|
+
* Spacer has no content and is ignored by tools such as screen readers. Use `Divider` for
|
|
55
|
+
* separations between elements that may be treated as semantically meaningful on web.
|
|
56
|
+
*/
|
|
57
|
+
const Spacer = ({ space = 1, direction = 'column', testID }) => {
|
|
58
|
+
const size = useSpacingScale(space)
|
|
59
|
+
const sizeStyle = selectSizeStyle(size, direction)
|
|
60
|
+
return <View testID={testID} style={[staticStyles.stretch, sizeStyle]} />
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
Spacer.propTypes = {
|
|
64
|
+
/**
|
|
65
|
+
* The size of the spacer according to the theme's spacing scale.
|
|
66
|
+
* Either a number corresponding to a position on the theme's spacing scale (1 is smallest, 2 is second smallest, etc),
|
|
67
|
+
* or, a SpacingObject with viewport keys and options (see `useSpacingScale` for details).
|
|
68
|
+
*/
|
|
69
|
+
space: spacingProps.types.spacingValue,
|
|
70
|
+
/**
|
|
71
|
+
* The spacer applies space in only one direction, which is controlled by the `direction` prop:
|
|
72
|
+
*
|
|
73
|
+
* - `'column'` (default) applies space vertically; has a fixed height and not width.
|
|
74
|
+
* - `'row'` applies space horizontally; has a fixed width and not height.
|
|
75
|
+
*/
|
|
76
|
+
direction: PropTypes.oneOf(['column', 'row']),
|
|
77
|
+
/**
|
|
78
|
+
* @ignore
|
|
79
|
+
* In tests, the only way to select Spacers is with testID prop and getByTestId, since they have no content,
|
|
80
|
+
* no accessibility role, and there is no equivalent of nextSibling in React Native Testing Library.
|
|
81
|
+
*/
|
|
82
|
+
testID: PropTypes.string
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
const staticStyles = StyleSheet.create({
|
|
86
|
+
stretch: {
|
|
87
|
+
alignSelf: 'stretch'
|
|
88
|
+
}
|
|
89
|
+
})
|
|
90
|
+
|
|
91
|
+
export default Spacer
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import React from 'react'
|
|
2
|
+
import PropTypes from 'prop-types'
|
|
3
|
+
import { View } from 'react-native'
|
|
4
|
+
|
|
5
|
+
import Divider from '../Divider'
|
|
6
|
+
import { spacingProps, a11yProps } from '../utils'
|
|
7
|
+
import { useThemeTokens } from '../ThemeProvider'
|
|
8
|
+
import getStackedContent from './getStackedContent'
|
|
9
|
+
import { staticStyles, selectFlexStyles } from './common'
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* StackView evenly spaces its children, by default placing `Spacer` components between them.
|
|
13
|
+
*
|
|
14
|
+
* ## Spacing
|
|
15
|
+
*
|
|
16
|
+
* StackView takes the same spacing props as `Spacer` and passes them directly to the layout components
|
|
17
|
+
* it uses for spacing.
|
|
18
|
+
*
|
|
19
|
+
* ## Direction
|
|
20
|
+
*
|
|
21
|
+
* Use `direction` to control how the children are stacked:
|
|
22
|
+
*
|
|
23
|
+
* - `'column'` (default) stacks and spaces the children vertically.
|
|
24
|
+
* - `'row'` stacks and spaces the children horizontally.
|
|
25
|
+
* - `'column-reverse'` acts the same as `'column'`, but reverses the direction.
|
|
26
|
+
* - `'row-reverse'` acts the same as `'row'`, but reverses the direction.
|
|
27
|
+
*
|
|
28
|
+
* ## Theming, alignment and justification
|
|
29
|
+
*
|
|
30
|
+
* `StackView` is a pure layout component and has no theme styles beyond a small set of layout styles
|
|
31
|
+
* (`alignItems`, `justifyContent`, `flexGrow`) which may be set using the `tokens` prop.
|
|
32
|
+
*
|
|
33
|
+
* All other styling such as borders, background colours, padding etc should be applied by wrapping
|
|
34
|
+
* the `StackView` in other components. For example, a `StackView` may be the child of a `Card`.
|
|
35
|
+
*
|
|
36
|
+
* ## Separator options
|
|
37
|
+
*
|
|
38
|
+
* By default, StackView inserts a `<Spacer>` component between each rendered child.
|
|
39
|
+
*
|
|
40
|
+
* With the `divider` prop, it instead renders a `Divider` instead of a `Spacer`. The gap between
|
|
41
|
+
* items will be double what it would be without this prop plus the width of the divider.
|
|
42
|
+
*
|
|
43
|
+
* ## Accessibility
|
|
44
|
+
*
|
|
45
|
+
* `StackView` may take any React Native accessibility props and applies them to the outer `View`.
|
|
46
|
+
* It applies no accessibility props of its own, unless `divider` prop is passed (`Divider` has a
|
|
47
|
+
* semantic role but only on web, not within native apps).
|
|
48
|
+
*/
|
|
49
|
+
const StackView = ({
|
|
50
|
+
space = 1,
|
|
51
|
+
divider,
|
|
52
|
+
direction = 'column',
|
|
53
|
+
inherit,
|
|
54
|
+
children,
|
|
55
|
+
variant,
|
|
56
|
+
tokens,
|
|
57
|
+
...rest
|
|
58
|
+
}) => {
|
|
59
|
+
const a11y = a11yProps.select({ ...rest })
|
|
60
|
+
const content = getStackedContent(children, { direction, divider, space })
|
|
61
|
+
const themeTokens = useThemeTokens('StackView', tokens, variant)
|
|
62
|
+
const flexStyles = selectFlexStyles(themeTokens)
|
|
63
|
+
|
|
64
|
+
return inherit ? (
|
|
65
|
+
content
|
|
66
|
+
) : (
|
|
67
|
+
<View {...a11y} style={[flexStyles, staticStyles[direction]]}>
|
|
68
|
+
{content}
|
|
69
|
+
</View>
|
|
70
|
+
)
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
StackView.propTypes = {
|
|
74
|
+
...a11yProps.propTypes,
|
|
75
|
+
/**
|
|
76
|
+
* Sets the `flexDirection` of the container and, if `divider` is used, gives the Divider the appropriate direction.
|
|
77
|
+
*/
|
|
78
|
+
direction: PropTypes.oneOf(['column', 'row', 'column-reverse', 'row-reverse']),
|
|
79
|
+
/**
|
|
80
|
+
* If true, renders a UDS `Divider` component between each item. If an object is passed,
|
|
81
|
+
* this object is passes as props to each Divider.
|
|
82
|
+
*/
|
|
83
|
+
divider: PropTypes.oneOfType([PropTypes.bool, PropTypes.shape(Divider.propTypes)]),
|
|
84
|
+
/**
|
|
85
|
+
* If true, does not render any container and returns an array of spaced children, inheriting
|
|
86
|
+
* flex styles from the StackView's parent. That parent must have a `flexDirection` style corresponding
|
|
87
|
+
* to the StackView's `direction` prop for `divider` prop to behave correctly.
|
|
88
|
+
*/
|
|
89
|
+
inherit: PropTypes.bool,
|
|
90
|
+
/**
|
|
91
|
+
* The size of the spacer according to the theme's spacing scale.
|
|
92
|
+
* Either a number corresponding to a position on the theme's spacing scale (1 is smallest, 2 is second smallest, etc),
|
|
93
|
+
* or, a SpacingObject with viewport keys and options (see `useSpacingScale` for details).
|
|
94
|
+
*/
|
|
95
|
+
space: spacingProps.types.spacingValue,
|
|
96
|
+
/**
|
|
97
|
+
* A StackView may take any children, but will have no effect if it is only passed one child or is passed children
|
|
98
|
+
* wrapped in a component. If necessary, children may be wrapped in one React Fragment.
|
|
99
|
+
*/
|
|
100
|
+
children: PropTypes.node
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
export default StackView
|