@telus-uds/components-base 1.71.0 → 1.73.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +37 -2
- package/lib/Box/Box.js +17 -6
- package/lib/ColourToggle/ColourBubble.js +135 -0
- package/lib/ColourToggle/ColourToggle.js +101 -0
- package/lib/ColourToggle/index.js +10 -0
- package/lib/FlexGrid/Col/Col.js +42 -19
- package/lib/FlexGrid/FlexGrid.js +40 -17
- package/lib/FlexGrid/Row/Row.js +45 -22
- package/lib/Listbox/ListboxGroup.js +7 -1
- package/lib/Modal/ModalContent.js +4 -6
- package/lib/MultiSelectFilter/MultiSelectFilter.js +1 -0
- package/lib/Notification/Notification.js +13 -5
- package/lib/OrderedList/Item.js +180 -0
- package/lib/OrderedList/ItemBase.js +54 -0
- package/lib/OrderedList/OrderedList.js +71 -0
- package/lib/OrderedList/OrderedListBase.js +47 -0
- package/lib/OrderedList/index.js +10 -0
- package/lib/Responsive/Responsive.js +24 -14
- package/lib/Responsive/ResponsiveProp.js +46 -0
- package/lib/Responsive/ResponsiveWithMediaQueryStyleSheet.js +72 -0
- package/lib/ThemeProvider/ThemeProvider.js +5 -2
- package/lib/ThemeProvider/index.js +9 -1
- package/lib/ThemeProvider/useResponsiveThemeTokens.js +89 -0
- package/lib/Typography/Typography.js +48 -22
- package/lib/index.js +16 -0
- package/lib/server.js +40 -0
- package/lib/utils/ssr-media-query/create-stylesheet/create-stylesheet-mobile.js +56 -0
- package/lib/utils/ssr-media-query/create-stylesheet/index.android.js +10 -0
- package/lib/utils/ssr-media-query/create-stylesheet/index.ios.js +10 -0
- package/lib/utils/ssr-media-query/create-stylesheet/index.js +44 -0
- package/lib/utils/ssr-media-query/utils/create-media-query-styles.js +39 -6
- package/lib-module/Box/Box.js +17 -6
- package/lib-module/ColourToggle/ColourBubble.js +125 -0
- package/lib-module/ColourToggle/ColourToggle.js +92 -0
- package/lib-module/ColourToggle/index.js +2 -0
- package/lib-module/FlexGrid/Col/Col.js +42 -19
- package/lib-module/FlexGrid/FlexGrid.js +40 -17
- package/lib-module/FlexGrid/Row/Row.js +45 -22
- package/lib-module/Listbox/ListboxGroup.js +7 -1
- package/lib-module/Modal/ModalContent.js +4 -6
- package/lib-module/MultiSelectFilter/MultiSelectFilter.js +1 -0
- package/lib-module/Notification/Notification.js +13 -5
- package/lib-module/OrderedList/Item.js +171 -0
- package/lib-module/OrderedList/ItemBase.js +43 -0
- package/lib-module/OrderedList/OrderedList.js +61 -0
- package/lib-module/OrderedList/OrderedListBase.js +36 -0
- package/lib-module/OrderedList/index.js +2 -0
- package/lib-module/Responsive/Responsive.js +24 -15
- package/lib-module/Responsive/ResponsiveProp.js +39 -0
- package/lib-module/Responsive/ResponsiveWithMediaQueryStyleSheet.js +64 -0
- package/lib-module/ThemeProvider/ThemeProvider.js +5 -2
- package/lib-module/ThemeProvider/index.js +1 -0
- package/lib-module/ThemeProvider/useResponsiveThemeTokens.js +81 -0
- package/lib-module/Typography/Typography.js +50 -24
- package/lib-module/index.js +2 -0
- package/lib-module/server.js +4 -0
- package/lib-module/utils/ssr-media-query/create-stylesheet/create-stylesheet-mobile.js +48 -0
- package/lib-module/utils/ssr-media-query/create-stylesheet/index.android.js +2 -0
- package/lib-module/utils/ssr-media-query/create-stylesheet/index.ios.js +2 -0
- package/lib-module/utils/ssr-media-query/create-stylesheet/index.js +36 -0
- package/lib-module/utils/ssr-media-query/utils/create-media-query-styles.js +36 -6
- package/package.json +13 -2
- package/src/Box/Box.jsx +35 -17
- package/src/ColourToggle/ColourBubble.jsx +111 -0
- package/src/ColourToggle/ColourToggle.jsx +83 -0
- package/src/ColourToggle/index.js +3 -0
- package/src/FlexGrid/Col/Col.jsx +42 -13
- package/src/FlexGrid/FlexGrid.jsx +40 -11
- package/src/FlexGrid/Row/Row.jsx +40 -16
- package/src/Listbox/ListboxGroup.jsx +9 -2
- package/src/Modal/ModalContent.jsx +4 -6
- package/src/MultiSelectFilter/MultiSelectFilter.jsx +2 -0
- package/src/Notification/Notification.jsx +15 -3
- package/src/OrderedList/Item.jsx +152 -0
- package/src/OrderedList/ItemBase.jsx +43 -0
- package/src/OrderedList/OrderedList.jsx +61 -0
- package/src/OrderedList/OrderedListBase.jsx +33 -0
- package/src/OrderedList/index.js +3 -0
- package/src/Responsive/Responsive.jsx +24 -11
- package/src/Responsive/ResponsiveProp.jsx +33 -0
- package/src/Responsive/ResponsiveWithMediaQueryStyleSheet.jsx +58 -0
- package/src/ThemeProvider/ThemeProvider.jsx +5 -2
- package/src/ThemeProvider/index.js +1 -0
- package/src/ThemeProvider/useResponsiveThemeTokens.js +85 -0
- package/src/Typography/Typography.jsx +72 -24
- package/src/index.js +2 -0
- package/src/server.js +4 -0
- package/src/utils/ssr-media-query/create-stylesheet/create-stylesheet-mobile.js +41 -0
- package/src/utils/ssr-media-query/create-stylesheet/index.android.js +3 -0
- package/src/utils/ssr-media-query/create-stylesheet/index.ios.js +3 -0
- package/src/utils/ssr-media-query/create-stylesheet/index.js +33 -0
- package/src/utils/ssr-media-query/utils/create-media-query-styles.js +21 -6
- package/types/Badge.d.ts +28 -0
- package/types/Box.d.ts +52 -0
- package/types/ChevronLink.d.ts +47 -0
- package/types/Common.d.ts +106 -0
- package/types/Divider.d.ts +19 -0
- package/types/ExpandCollapse.d.ts +65 -0
- package/types/HorizontalScrollButton.d.ts +16 -0
- package/types/Icon.d.ts +21 -0
- package/types/Link.d.ts +48 -0
- package/types/List.d.ts +48 -0
- package/types/Search.d.ts +38 -0
- package/types/Select.d.ts +57 -0
- package/types/Spacer.d.ts +5 -0
- package/types/StackView.d.ts +28 -0
- package/types/Tabs.d.ts +46 -0
- package/types/TextButton.d.ts +11 -0
- package/types/ToggleSwitch.d.ts +54 -0
- package/types/ToolTip.d.ts +40 -0
- package/types/Typography.d.ts +39 -0
- package/types/index.d.ts +62 -0
- package/lib/utils/ssr-media-query/create-stylesheet.js +0 -76
- package/lib-module/utils/ssr-media-query/create-stylesheet.js +0 -68
- package/src/utils/ssr-media-query/create-stylesheet.js +0 -61
package/src/FlexGrid/Col/Col.jsx
CHANGED
|
@@ -5,6 +5,8 @@ import { Platform } from 'react-native'
|
|
|
5
5
|
import GutterContext from '../providers/GutterContext'
|
|
6
6
|
import applyInheritance from '../helpers'
|
|
7
7
|
import { responsiveProps, BaseView, StyleSheet, createMediaQueryStyles } from '../../utils'
|
|
8
|
+
import { useViewport } from '../../ViewportProvider'
|
|
9
|
+
import { useTheme } from '../../ThemeProvider'
|
|
8
10
|
|
|
9
11
|
const Col = forwardRef(
|
|
10
12
|
(
|
|
@@ -27,6 +29,10 @@ const Col = forwardRef(
|
|
|
27
29
|
ref
|
|
28
30
|
) => {
|
|
29
31
|
const gutter = useContext(GutterContext)
|
|
32
|
+
const viewport = useViewport()
|
|
33
|
+
const {
|
|
34
|
+
themeOptions: { enableMediaQueryStyleSheet }
|
|
35
|
+
} = useTheme()
|
|
30
36
|
const hiddenLevels = applyInheritance([xs, sm, md, lg, xl])
|
|
31
37
|
|
|
32
38
|
const getHorizontalAlignLevel = () => {
|
|
@@ -104,7 +110,16 @@ const Col = forwardRef(
|
|
|
104
110
|
xl: offsetsWithIheritance[4]
|
|
105
111
|
}
|
|
106
112
|
|
|
107
|
-
const
|
|
113
|
+
const staticStyles = {
|
|
114
|
+
flexGrow: 1,
|
|
115
|
+
flexShrink: 0,
|
|
116
|
+
flexBasis: 'auto',
|
|
117
|
+
maxWidth: '100%',
|
|
118
|
+
paddingLeft: gutter ? 16 : 0,
|
|
119
|
+
paddingRight: gutter ? 16 : 0
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
const stylesByViewport = {
|
|
108
123
|
xs: {
|
|
109
124
|
display: hiddenLevels[0] === 0 ? 'none' : shown,
|
|
110
125
|
textAlign: horizontalAlignLevel[0],
|
|
@@ -135,21 +150,35 @@ const Col = forwardRef(
|
|
|
135
150
|
...calculateWidth(sizes.xl),
|
|
136
151
|
...calculateOffset(offsets.xl)
|
|
137
152
|
}
|
|
138
|
-
}
|
|
153
|
+
}
|
|
139
154
|
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
155
|
+
let colStyles
|
|
156
|
+
let mediaIds
|
|
157
|
+
|
|
158
|
+
if (enableMediaQueryStyleSheet) {
|
|
159
|
+
const mediaQueryStyles = createMediaQueryStyles(stylesByViewport)
|
|
160
|
+
const { ids, styles } = StyleSheet.create({
|
|
161
|
+
col: {
|
|
162
|
+
...staticStyles,
|
|
163
|
+
...mediaQueryStyles
|
|
164
|
+
}
|
|
165
|
+
})
|
|
166
|
+
colStyles = styles.col
|
|
167
|
+
mediaIds = ids.col
|
|
168
|
+
} else {
|
|
169
|
+
colStyles = {
|
|
170
|
+
...staticStyles,
|
|
171
|
+
...stylesByViewport[viewport]
|
|
149
172
|
}
|
|
150
|
-
}
|
|
173
|
+
}
|
|
174
|
+
|
|
151
175
|
return (
|
|
152
|
-
<BaseView
|
|
176
|
+
<BaseView
|
|
177
|
+
ref={ref}
|
|
178
|
+
{...viewProps}
|
|
179
|
+
style={colStyles}
|
|
180
|
+
dataSet={mediaIds && { media: mediaIds }}
|
|
181
|
+
>
|
|
153
182
|
{children}
|
|
154
183
|
</BaseView>
|
|
155
184
|
)
|
|
@@ -16,6 +16,8 @@ import Row from './Row'
|
|
|
16
16
|
import Col from './Col'
|
|
17
17
|
import GutterContext from './providers/GutterContext'
|
|
18
18
|
import applyInheritance from './helpers'
|
|
19
|
+
import { useTheme } from '../ThemeProvider'
|
|
20
|
+
import { useViewport } from '../ViewportProvider'
|
|
19
21
|
|
|
20
22
|
const [selectProps, selectedSystemPropTypes] = selectSystemProps([a11yProps, viewProps])
|
|
21
23
|
|
|
@@ -42,7 +44,15 @@ const FlexGrid = forwardRef(
|
|
|
42
44
|
ref
|
|
43
45
|
) => {
|
|
44
46
|
const reverseLevel = applyInheritance([xsReverse, smReverse, mdReverse, lgReverse, xlReverse])
|
|
45
|
-
const
|
|
47
|
+
const viewport = useViewport()
|
|
48
|
+
const {
|
|
49
|
+
themeOptions: { enableMediaQueryStyleSheet }
|
|
50
|
+
} = useTheme()
|
|
51
|
+
|
|
52
|
+
let flexgridStyles
|
|
53
|
+
let mediaIds
|
|
54
|
+
|
|
55
|
+
const stylesByViewport = {
|
|
46
56
|
xs: {
|
|
47
57
|
flexDirection: reverseLevel[0] ? 'column-reverse' : 'column'
|
|
48
58
|
},
|
|
@@ -62,17 +72,31 @@ const FlexGrid = forwardRef(
|
|
|
62
72
|
maxWidth: limitWidth && viewports.map.get('xl'),
|
|
63
73
|
flexDirection: reverseLevel[4] ? 'column-reverse' : 'column'
|
|
64
74
|
}
|
|
65
|
-
}
|
|
75
|
+
}
|
|
66
76
|
|
|
67
|
-
const
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
77
|
+
const staticStyles = {
|
|
78
|
+
flexWrap: 'wrap',
|
|
79
|
+
width: outsideGutter ? '100%' : 'auto',
|
|
80
|
+
marginVertical: 0,
|
|
81
|
+
marginHorizontal: outsideGutter ? 'auto' : -16
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
if (enableMediaQueryStyleSheet) {
|
|
85
|
+
const mediaQueryStyles = createMediaQueryStyles(stylesByViewport)
|
|
86
|
+
const { ids, styles } = StyleSheet.create({
|
|
87
|
+
flexgrid: {
|
|
88
|
+
...staticStyles,
|
|
89
|
+
...mediaQueryStyles
|
|
90
|
+
}
|
|
91
|
+
})
|
|
92
|
+
flexgridStyles = styles.flexgrid
|
|
93
|
+
mediaIds = ids.flexgrid
|
|
94
|
+
} else {
|
|
95
|
+
flexgridStyles = {
|
|
96
|
+
...staticStyles,
|
|
97
|
+
...stylesByViewport[viewport]
|
|
74
98
|
}
|
|
75
|
-
}
|
|
99
|
+
}
|
|
76
100
|
|
|
77
101
|
const props = {
|
|
78
102
|
accessibilityRole,
|
|
@@ -82,7 +106,12 @@ const FlexGrid = forwardRef(
|
|
|
82
106
|
|
|
83
107
|
return (
|
|
84
108
|
<GutterContext.Provider value={gutter}>
|
|
85
|
-
<BaseView
|
|
109
|
+
<BaseView
|
|
110
|
+
ref={ref}
|
|
111
|
+
{...props}
|
|
112
|
+
style={flexgridStyles}
|
|
113
|
+
dataSet={mediaIds && { media: mediaIds }}
|
|
114
|
+
>
|
|
86
115
|
{children}
|
|
87
116
|
</BaseView>
|
|
88
117
|
</GutterContext.Provider>
|
package/src/FlexGrid/Row/Row.jsx
CHANGED
|
@@ -3,6 +3,8 @@ import PropTypes from 'prop-types'
|
|
|
3
3
|
|
|
4
4
|
import applyInheritance from '../helpers'
|
|
5
5
|
import { BaseView, StyleSheet, createMediaQueryStyles } from '../../utils'
|
|
6
|
+
import { useTheme } from '../../ThemeProvider'
|
|
7
|
+
import { useViewport } from '../../ViewportProvider'
|
|
6
8
|
|
|
7
9
|
const horizontalAlignStyles = (horizontalAlign) => {
|
|
8
10
|
switch (horizontalAlign) {
|
|
@@ -66,8 +68,23 @@ const Row = forwardRef(
|
|
|
66
68
|
},
|
|
67
69
|
ref
|
|
68
70
|
) => {
|
|
71
|
+
const {
|
|
72
|
+
themeOptions: { enableMediaQueryStyleSheet }
|
|
73
|
+
} = useTheme()
|
|
74
|
+
const viewport = useViewport()
|
|
75
|
+
const staticStyles = {
|
|
76
|
+
width: '100%',
|
|
77
|
+
marginVertical: 0,
|
|
78
|
+
marginHorizontal: 'auto',
|
|
79
|
+
flexGrow: 0,
|
|
80
|
+
flexShrink: 1,
|
|
81
|
+
flexBasis: 'auto',
|
|
82
|
+
...horizontalAlignStyles(horizontalAlign),
|
|
83
|
+
...verticalAlignStyles(verticalAlign),
|
|
84
|
+
...distributeStyles(distribute)
|
|
85
|
+
}
|
|
69
86
|
const reverseLevel = applyInheritance([xsReverse, smReverse, mdReverse, lgReverse, xlReverse])
|
|
70
|
-
const
|
|
87
|
+
const stylesByViewport = {
|
|
71
88
|
xs: {
|
|
72
89
|
flexDirection: reverseLevel[0] ? 'row-reverse' : 'row',
|
|
73
90
|
flexWrap: reverseLevel[0] ? 'wrap-reverse' : 'wrap'
|
|
@@ -88,23 +105,30 @@ const Row = forwardRef(
|
|
|
88
105
|
flexDirection: reverseLevel[4] ? 'row-reverse' : 'row',
|
|
89
106
|
flexWrap: reverseLevel[4] ? 'wrap-reverse' : 'wrap'
|
|
90
107
|
}
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
let rowStyles
|
|
111
|
+
let mediaIds
|
|
112
|
+
|
|
113
|
+
if (enableMediaQueryStyleSheet) {
|
|
114
|
+
const mediaQueryStyles = createMediaQueryStyles(stylesByViewport)
|
|
115
|
+
const { ids, styles } = StyleSheet.create({
|
|
116
|
+
row: {
|
|
117
|
+
...staticStyles,
|
|
118
|
+
...mediaQueryStyles
|
|
119
|
+
}
|
|
120
|
+
})
|
|
121
|
+
rowStyles = styles.row
|
|
122
|
+
mediaIds = ids.row
|
|
123
|
+
} else {
|
|
124
|
+
rowStyles = {
|
|
125
|
+
...staticStyles,
|
|
126
|
+
...stylesByViewport[viewport]
|
|
104
127
|
}
|
|
105
|
-
}
|
|
128
|
+
}
|
|
129
|
+
|
|
106
130
|
return (
|
|
107
|
-
<BaseView ref={ref} {...rest} style={
|
|
131
|
+
<BaseView ref={ref} {...rest} style={rowStyles} dataSet={mediaIds && { media: mediaIds }}>
|
|
108
132
|
{children}
|
|
109
133
|
</BaseView>
|
|
110
134
|
)
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/* eslint-disable react-native-a11y/has-valid-accessibility-role */
|
|
2
2
|
import React, { forwardRef } from 'react'
|
|
3
3
|
import PropTypes from 'prop-types'
|
|
4
|
-
import { View, StyleSheet } from 'react-native'
|
|
4
|
+
import { View, StyleSheet, Platform } from 'react-native'
|
|
5
5
|
import { withLinkRouter } from '../utils'
|
|
6
6
|
import ExpandCollapse from '../ExpandCollapse'
|
|
7
7
|
import ListboxItem from './ListboxItem'
|
|
@@ -20,6 +20,13 @@ const styles = StyleSheet.create({
|
|
|
20
20
|
}
|
|
21
21
|
})
|
|
22
22
|
|
|
23
|
+
const getAccessibilityRole = () =>
|
|
24
|
+
Platform.select({
|
|
25
|
+
ios: 'listitem',
|
|
26
|
+
android: 'none',
|
|
27
|
+
web: 'listitem'
|
|
28
|
+
})
|
|
29
|
+
|
|
23
30
|
const ListboxGroup = forwardRef(
|
|
24
31
|
(
|
|
25
32
|
{
|
|
@@ -39,7 +46,7 @@ const ListboxGroup = forwardRef(
|
|
|
39
46
|
|
|
40
47
|
// TODO: implement keyboard navigation via refs for grouped items separately here
|
|
41
48
|
return (
|
|
42
|
-
<View id="test" style={styles.groupWrapper} accessibilityRole=
|
|
49
|
+
<View id="test" style={styles.groupWrapper} accessibilityRole={getAccessibilityRole()}>
|
|
43
50
|
<ExpandCollapse.Panel
|
|
44
51
|
panelId={id ?? label}
|
|
45
52
|
controlTokens={{
|
|
@@ -25,14 +25,15 @@ const ModalContent = ({
|
|
|
25
25
|
children,
|
|
26
26
|
onCancel
|
|
27
27
|
}) => {
|
|
28
|
+
const viewport = useViewport()
|
|
28
29
|
const { headingColor, cancelButtonColor, ...themeTokens } = useThemeTokens(
|
|
29
30
|
'Modal',
|
|
30
31
|
tokens,
|
|
31
|
-
variant
|
|
32
|
+
variant,
|
|
33
|
+
{ viewport }
|
|
32
34
|
)
|
|
33
35
|
const [scrollContainerHeight, setScrollContainerHeight] = useState(0)
|
|
34
36
|
const [scrollContentHeight, setScrollContentHeight] = useState(0)
|
|
35
|
-
const viewport = useViewport()
|
|
36
37
|
|
|
37
38
|
const handleContainerLayout = ({
|
|
38
39
|
nativeEvent: {
|
|
@@ -128,7 +129,7 @@ const ModalContent = ({
|
|
|
128
129
|
</Button>
|
|
129
130
|
)}
|
|
130
131
|
{hasCancelButton ? (
|
|
131
|
-
<View
|
|
132
|
+
<View>
|
|
132
133
|
<CancelButton tokens={{ color: cancelButtonColor }} onPress={onCancel}>
|
|
133
134
|
{cancelButtonText}
|
|
134
135
|
</CancelButton>
|
|
@@ -145,9 +146,6 @@ const styles = StyleSheet.create({
|
|
|
145
146
|
flex: 1,
|
|
146
147
|
flexDirection: 'column',
|
|
147
148
|
minHeight: Platform.OS === 'web' ? '100%' : 'auto'
|
|
148
|
-
},
|
|
149
|
-
styledTextButtonContainer: {
|
|
150
|
-
flex: 1
|
|
151
149
|
}
|
|
152
150
|
})
|
|
153
151
|
|
|
@@ -22,8 +22,20 @@ const [selectProps, selectedSystemPropTypes] = selectSystemProps([a11yProps, vie
|
|
|
22
22
|
|
|
23
23
|
const selectContainerStyles = (tokens) => ({ ...tokens })
|
|
24
24
|
|
|
25
|
-
const selectTextStyles = (tokens, themeOptions) =>
|
|
26
|
-
|
|
25
|
+
const selectTextStyles = (tokens, themeOptions, isDismissible) => {
|
|
26
|
+
const textTokens = selectTokens('Typography', tokens)
|
|
27
|
+
const styles = {
|
|
28
|
+
...textTokens,
|
|
29
|
+
themeOptions,
|
|
30
|
+
overflow: 'hidden'
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
if (!isDismissible) {
|
|
34
|
+
styles.flexShrink = 1
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
return applyTextStyles(styles)
|
|
38
|
+
}
|
|
27
39
|
|
|
28
40
|
const selectIconProps = ({ iconSize, iconColor }) => ({
|
|
29
41
|
size: iconSize,
|
|
@@ -113,7 +125,7 @@ const Notification = forwardRef(
|
|
|
113
125
|
return null
|
|
114
126
|
}
|
|
115
127
|
|
|
116
|
-
const textStyles = selectTextStyles(themeTokens, themeOptions)
|
|
128
|
+
const textStyles = selectTextStyles(themeTokens, themeOptions, dismissible)
|
|
117
129
|
|
|
118
130
|
const content = wrapStringsInText(
|
|
119
131
|
typeof children === 'function' ? children({ textStyles, variant }) : children,
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
import React, { forwardRef } from 'react'
|
|
2
|
+
import PropTypes from 'prop-types'
|
|
3
|
+
import { View, StyleSheet } from 'react-native'
|
|
4
|
+
|
|
5
|
+
import {
|
|
6
|
+
getTokensPropType,
|
|
7
|
+
htmlAttrs,
|
|
8
|
+
selectSystemProps,
|
|
9
|
+
variantProp,
|
|
10
|
+
viewProps,
|
|
11
|
+
wrapStringsInText
|
|
12
|
+
} from '../utils'
|
|
13
|
+
import { applyTextStyles, useTheme, useThemeTokens } from '../ThemeProvider'
|
|
14
|
+
import StackView from '../StackView'
|
|
15
|
+
import Typography from '../Typography'
|
|
16
|
+
import ItemBase from './ItemBase'
|
|
17
|
+
|
|
18
|
+
const [selectProps, selectedSystemPropTypes] = selectSystemProps([htmlAttrs, viewProps])
|
|
19
|
+
|
|
20
|
+
const selectItemTextStyles = (
|
|
21
|
+
{ itemFontHeight, itemFontSize, itemLineHeight, itemFontName, itemColor },
|
|
22
|
+
themeOptions
|
|
23
|
+
) =>
|
|
24
|
+
applyTextStyles({
|
|
25
|
+
fontWeight: itemFontHeight,
|
|
26
|
+
fontSize: itemFontSize,
|
|
27
|
+
fontName: itemFontName,
|
|
28
|
+
color: itemColor,
|
|
29
|
+
themeOptions,
|
|
30
|
+
lineHeight: itemLineHeight
|
|
31
|
+
})
|
|
32
|
+
|
|
33
|
+
const selectItemCounterStyles = ({
|
|
34
|
+
itemBulletContainerWidth,
|
|
35
|
+
itemBulletContainerAlign,
|
|
36
|
+
itemFontWeight,
|
|
37
|
+
itemFontSize,
|
|
38
|
+
itemFontName,
|
|
39
|
+
itemLineHeight,
|
|
40
|
+
themeOptions,
|
|
41
|
+
listGutter,
|
|
42
|
+
itemColor
|
|
43
|
+
}) => ({
|
|
44
|
+
color: itemColor,
|
|
45
|
+
width: itemBulletContainerWidth,
|
|
46
|
+
paddingRight: listGutter,
|
|
47
|
+
textAlign: itemBulletContainerAlign,
|
|
48
|
+
...applyTextStyles({
|
|
49
|
+
fontWeight: itemFontWeight,
|
|
50
|
+
fontSize: itemFontSize,
|
|
51
|
+
fontName: itemFontName,
|
|
52
|
+
themeOptions
|
|
53
|
+
}),
|
|
54
|
+
lineHeight: itemLineHeight * itemFontSize
|
|
55
|
+
})
|
|
56
|
+
|
|
57
|
+
const selectItemContentStyles = ({ interItemMargin, ...themeTokens }, isLastChild) => ({
|
|
58
|
+
...themeTokens,
|
|
59
|
+
marginBottom: !isLastChild ? interItemMargin : 0
|
|
60
|
+
})
|
|
61
|
+
|
|
62
|
+
const Item = forwardRef(
|
|
63
|
+
({ children, index, isLastChild, title, tokens, variant, ...rest }, ref) => {
|
|
64
|
+
const themeTokens = useThemeTokens('OrderedList', tokens, variant)
|
|
65
|
+
const headingTokens = title && {
|
|
66
|
+
lineHeight: themeTokens.itemLineHeight,
|
|
67
|
+
fontSize: themeTokens.itemFontSize,
|
|
68
|
+
color: themeTokens.itemColor,
|
|
69
|
+
fontName: themeTokens.headerFontName,
|
|
70
|
+
fontWeight: themeTokens.headerFontWeight
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
const { themeOptions } = useTheme()
|
|
74
|
+
const itemContent = wrapStringsInText(children, {
|
|
75
|
+
style: selectItemTextStyles(themeTokens, themeOptions)
|
|
76
|
+
})
|
|
77
|
+
const itemCounter = wrapStringsInText(`${index}.`, {
|
|
78
|
+
style: selectItemTextStyles(themeTokens, themeOptions)
|
|
79
|
+
})
|
|
80
|
+
|
|
81
|
+
return (
|
|
82
|
+
<ItemBase
|
|
83
|
+
ref={ref}
|
|
84
|
+
style={{ ...staticStyles.container, ...themeTokens }}
|
|
85
|
+
{...selectProps(rest)}
|
|
86
|
+
>
|
|
87
|
+
<View style={[staticStyles.itemCounter, selectItemCounterStyles(themeTokens)]}>
|
|
88
|
+
{itemCounter}
|
|
89
|
+
</View>
|
|
90
|
+
<View style={staticStyles.itemContent}>
|
|
91
|
+
{title ? (
|
|
92
|
+
<StackView tokens={{ flexShrink: 1 }} space={0}>
|
|
93
|
+
<Typography variant={{ size: 'h4' }} tokens={headingTokens}>
|
|
94
|
+
{title}
|
|
95
|
+
</Typography>
|
|
96
|
+
<View style={selectItemContentStyles(themeTokens, isLastChild)}>{itemContent}</View>
|
|
97
|
+
</StackView>
|
|
98
|
+
) : (
|
|
99
|
+
<View style={selectItemContentStyles(themeTokens, isLastChild)}>{itemContent}</View>
|
|
100
|
+
)}
|
|
101
|
+
</View>
|
|
102
|
+
</ItemBase>
|
|
103
|
+
)
|
|
104
|
+
}
|
|
105
|
+
)
|
|
106
|
+
|
|
107
|
+
Item.propTypes = {
|
|
108
|
+
...selectedSystemPropTypes,
|
|
109
|
+
/**
|
|
110
|
+
* Item content
|
|
111
|
+
*/
|
|
112
|
+
children: PropTypes.node.isRequired,
|
|
113
|
+
/**
|
|
114
|
+
* Item index
|
|
115
|
+
*/
|
|
116
|
+
index: PropTypes.number,
|
|
117
|
+
/**
|
|
118
|
+
* If true, the item is the last one on the list
|
|
119
|
+
*/
|
|
120
|
+
isLastChild: PropTypes.bool,
|
|
121
|
+
/**
|
|
122
|
+
* Defines the title of the `OrderedList.Item`
|
|
123
|
+
*/
|
|
124
|
+
title: PropTypes.string,
|
|
125
|
+
/**
|
|
126
|
+
* Item tokens
|
|
127
|
+
*/
|
|
128
|
+
tokens: getTokensPropType('List'),
|
|
129
|
+
/**
|
|
130
|
+
* Item variant
|
|
131
|
+
*/
|
|
132
|
+
variant: variantProp.propType
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
Item.displayName = 'OrderedListItem'
|
|
136
|
+
|
|
137
|
+
Item.defaultProps = { title: undefined, tokens: {} }
|
|
138
|
+
|
|
139
|
+
export default Item
|
|
140
|
+
|
|
141
|
+
const staticStyles = StyleSheet.create({
|
|
142
|
+
container: {
|
|
143
|
+
flexDirection: 'row'
|
|
144
|
+
},
|
|
145
|
+
itemCounter: {
|
|
146
|
+
flexWrap: 'wrap'
|
|
147
|
+
},
|
|
148
|
+
itemContent: {
|
|
149
|
+
flexDirection: 'column',
|
|
150
|
+
marginLeft: 8
|
|
151
|
+
}
|
|
152
|
+
})
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/* eslint-disable react-native-a11y/has-valid-accessibility-role */
|
|
2
|
+
import React, { forwardRef } from 'react'
|
|
3
|
+
import PropTypes from 'prop-types'
|
|
4
|
+
import { View, StyleSheet, Platform } from 'react-native'
|
|
5
|
+
|
|
6
|
+
const getAccessibilityRole = () =>
|
|
7
|
+
Platform.select({
|
|
8
|
+
ios: 'listitem',
|
|
9
|
+
android: 'none',
|
|
10
|
+
web: 'listitem'
|
|
11
|
+
})
|
|
12
|
+
|
|
13
|
+
const Item = forwardRef(({ children, style, ...rest }, ref) => (
|
|
14
|
+
<View
|
|
15
|
+
accessibilityRole={getAccessibilityRole()}
|
|
16
|
+
ref={ref}
|
|
17
|
+
style={[staticStyles.container, style]}
|
|
18
|
+
{...rest}
|
|
19
|
+
>
|
|
20
|
+
{children}
|
|
21
|
+
</View>
|
|
22
|
+
))
|
|
23
|
+
|
|
24
|
+
Item.propTypes = {
|
|
25
|
+
/**
|
|
26
|
+
* Item content
|
|
27
|
+
*/
|
|
28
|
+
children: PropTypes.node.isRequired,
|
|
29
|
+
/**
|
|
30
|
+
* Item custom styles
|
|
31
|
+
*/
|
|
32
|
+
style: PropTypes.object
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
Item.displayName = 'OrderedListItem'
|
|
36
|
+
|
|
37
|
+
export default Item
|
|
38
|
+
|
|
39
|
+
const staticStyles = StyleSheet.create({
|
|
40
|
+
container: {
|
|
41
|
+
display: 'flex'
|
|
42
|
+
}
|
|
43
|
+
})
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import React, { forwardRef, useMemo } from 'react'
|
|
2
|
+
import PropTypes from 'prop-types'
|
|
3
|
+
|
|
4
|
+
import { getTokensPropType, htmlAttrs, selectSystemProps, variantProp, viewProps } from '../utils'
|
|
5
|
+
import OrderedListBase from './OrderedListBase'
|
|
6
|
+
import Item from './Item'
|
|
7
|
+
|
|
8
|
+
const [selectProps, selectedSystemPropsTypes] = selectSystemProps([htmlAttrs, viewProps])
|
|
9
|
+
|
|
10
|
+
const getChildrenWithParentVariants = (variant, children, start) => {
|
|
11
|
+
if (variant)
|
|
12
|
+
return children.map((child, i) => {
|
|
13
|
+
const existingChildVariants = child.props?.variant ?? {}
|
|
14
|
+
return {
|
|
15
|
+
...child,
|
|
16
|
+
props: {
|
|
17
|
+
...child.props,
|
|
18
|
+
index: start + i,
|
|
19
|
+
isLastChild: i === children.length - 1,
|
|
20
|
+
variant: { ...existingChildVariants, ...variant }
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
})
|
|
24
|
+
|
|
25
|
+
return children
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const OrderedList = forwardRef(({ children, start, variant, ...rest }, ref) => {
|
|
29
|
+
const childrenWithParentVariants = useMemo(
|
|
30
|
+
() => getChildrenWithParentVariants(variant, children, start),
|
|
31
|
+
[children, variant, start]
|
|
32
|
+
)
|
|
33
|
+
|
|
34
|
+
return (
|
|
35
|
+
<OrderedListBase ref={ref} {...selectProps(rest)}>
|
|
36
|
+
{childrenWithParentVariants}
|
|
37
|
+
</OrderedListBase>
|
|
38
|
+
)
|
|
39
|
+
})
|
|
40
|
+
|
|
41
|
+
OrderedList.propTypes = {
|
|
42
|
+
...selectedSystemPropsTypes,
|
|
43
|
+
tokens: getTokensPropType('OrderedList'),
|
|
44
|
+
/**
|
|
45
|
+
* A list of ordered items wrapped in `OrderedList.Item`.
|
|
46
|
+
*/
|
|
47
|
+
children: PropTypes.node.isRequired,
|
|
48
|
+
/**
|
|
49
|
+
* The position to start the list with.
|
|
50
|
+
*/
|
|
51
|
+
start: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
|
|
52
|
+
variant: variantProp.propType
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
OrderedList.defaultProps = { start: 1, tokens: {}, variant: {} }
|
|
56
|
+
|
|
57
|
+
OrderedList.displayName = 'OrderedList'
|
|
58
|
+
|
|
59
|
+
OrderedList.Item = Item
|
|
60
|
+
|
|
61
|
+
export default OrderedList
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/* eslint-disable react-native-a11y/has-valid-accessibility-role */
|
|
2
|
+
import React, { forwardRef } from 'react'
|
|
3
|
+
import PropTypes from 'prop-types'
|
|
4
|
+
import { View, StyleSheet } from 'react-native'
|
|
5
|
+
|
|
6
|
+
import ItemBase from './ItemBase'
|
|
7
|
+
|
|
8
|
+
const OrderedListBase = forwardRef(({ children, ...rest }, ref) => (
|
|
9
|
+
<View accessibilityRole="list" ref={ref} style={staticStyles.container} {...rest}>
|
|
10
|
+
{children}
|
|
11
|
+
</View>
|
|
12
|
+
))
|
|
13
|
+
|
|
14
|
+
OrderedListBase.propTypes = {
|
|
15
|
+
/**
|
|
16
|
+
* A list of ordered items wrapped in `OrderedListBase.Item`.
|
|
17
|
+
*/
|
|
18
|
+
children: PropTypes.node.isRequired
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
OrderedListBase.displayName = 'OrderedList'
|
|
22
|
+
|
|
23
|
+
OrderedListBase.Item = ItemBase
|
|
24
|
+
|
|
25
|
+
export default OrderedListBase
|
|
26
|
+
|
|
27
|
+
const staticStyles = StyleSheet.create({
|
|
28
|
+
container: {
|
|
29
|
+
flexDirection: 'column',
|
|
30
|
+
margin: 0,
|
|
31
|
+
padding: 0
|
|
32
|
+
}
|
|
33
|
+
})
|