@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.
Files changed (115) hide show
  1. package/CHANGELOG.md +37 -2
  2. package/lib/Box/Box.js +17 -6
  3. package/lib/ColourToggle/ColourBubble.js +135 -0
  4. package/lib/ColourToggle/ColourToggle.js +101 -0
  5. package/lib/ColourToggle/index.js +10 -0
  6. package/lib/FlexGrid/Col/Col.js +42 -19
  7. package/lib/FlexGrid/FlexGrid.js +40 -17
  8. package/lib/FlexGrid/Row/Row.js +45 -22
  9. package/lib/Listbox/ListboxGroup.js +7 -1
  10. package/lib/Modal/ModalContent.js +4 -6
  11. package/lib/MultiSelectFilter/MultiSelectFilter.js +1 -0
  12. package/lib/Notification/Notification.js +13 -5
  13. package/lib/OrderedList/Item.js +180 -0
  14. package/lib/OrderedList/ItemBase.js +54 -0
  15. package/lib/OrderedList/OrderedList.js +71 -0
  16. package/lib/OrderedList/OrderedListBase.js +47 -0
  17. package/lib/OrderedList/index.js +10 -0
  18. package/lib/Responsive/Responsive.js +24 -14
  19. package/lib/Responsive/ResponsiveProp.js +46 -0
  20. package/lib/Responsive/ResponsiveWithMediaQueryStyleSheet.js +72 -0
  21. package/lib/ThemeProvider/ThemeProvider.js +5 -2
  22. package/lib/ThemeProvider/index.js +9 -1
  23. package/lib/ThemeProvider/useResponsiveThemeTokens.js +89 -0
  24. package/lib/Typography/Typography.js +48 -22
  25. package/lib/index.js +16 -0
  26. package/lib/server.js +40 -0
  27. package/lib/utils/ssr-media-query/create-stylesheet/create-stylesheet-mobile.js +56 -0
  28. package/lib/utils/ssr-media-query/create-stylesheet/index.android.js +10 -0
  29. package/lib/utils/ssr-media-query/create-stylesheet/index.ios.js +10 -0
  30. package/lib/utils/ssr-media-query/create-stylesheet/index.js +44 -0
  31. package/lib/utils/ssr-media-query/utils/create-media-query-styles.js +39 -6
  32. package/lib-module/Box/Box.js +17 -6
  33. package/lib-module/ColourToggle/ColourBubble.js +125 -0
  34. package/lib-module/ColourToggle/ColourToggle.js +92 -0
  35. package/lib-module/ColourToggle/index.js +2 -0
  36. package/lib-module/FlexGrid/Col/Col.js +42 -19
  37. package/lib-module/FlexGrid/FlexGrid.js +40 -17
  38. package/lib-module/FlexGrid/Row/Row.js +45 -22
  39. package/lib-module/Listbox/ListboxGroup.js +7 -1
  40. package/lib-module/Modal/ModalContent.js +4 -6
  41. package/lib-module/MultiSelectFilter/MultiSelectFilter.js +1 -0
  42. package/lib-module/Notification/Notification.js +13 -5
  43. package/lib-module/OrderedList/Item.js +171 -0
  44. package/lib-module/OrderedList/ItemBase.js +43 -0
  45. package/lib-module/OrderedList/OrderedList.js +61 -0
  46. package/lib-module/OrderedList/OrderedListBase.js +36 -0
  47. package/lib-module/OrderedList/index.js +2 -0
  48. package/lib-module/Responsive/Responsive.js +24 -15
  49. package/lib-module/Responsive/ResponsiveProp.js +39 -0
  50. package/lib-module/Responsive/ResponsiveWithMediaQueryStyleSheet.js +64 -0
  51. package/lib-module/ThemeProvider/ThemeProvider.js +5 -2
  52. package/lib-module/ThemeProvider/index.js +1 -0
  53. package/lib-module/ThemeProvider/useResponsiveThemeTokens.js +81 -0
  54. package/lib-module/Typography/Typography.js +50 -24
  55. package/lib-module/index.js +2 -0
  56. package/lib-module/server.js +4 -0
  57. package/lib-module/utils/ssr-media-query/create-stylesheet/create-stylesheet-mobile.js +48 -0
  58. package/lib-module/utils/ssr-media-query/create-stylesheet/index.android.js +2 -0
  59. package/lib-module/utils/ssr-media-query/create-stylesheet/index.ios.js +2 -0
  60. package/lib-module/utils/ssr-media-query/create-stylesheet/index.js +36 -0
  61. package/lib-module/utils/ssr-media-query/utils/create-media-query-styles.js +36 -6
  62. package/package.json +13 -2
  63. package/src/Box/Box.jsx +35 -17
  64. package/src/ColourToggle/ColourBubble.jsx +111 -0
  65. package/src/ColourToggle/ColourToggle.jsx +83 -0
  66. package/src/ColourToggle/index.js +3 -0
  67. package/src/FlexGrid/Col/Col.jsx +42 -13
  68. package/src/FlexGrid/FlexGrid.jsx +40 -11
  69. package/src/FlexGrid/Row/Row.jsx +40 -16
  70. package/src/Listbox/ListboxGroup.jsx +9 -2
  71. package/src/Modal/ModalContent.jsx +4 -6
  72. package/src/MultiSelectFilter/MultiSelectFilter.jsx +2 -0
  73. package/src/Notification/Notification.jsx +15 -3
  74. package/src/OrderedList/Item.jsx +152 -0
  75. package/src/OrderedList/ItemBase.jsx +43 -0
  76. package/src/OrderedList/OrderedList.jsx +61 -0
  77. package/src/OrderedList/OrderedListBase.jsx +33 -0
  78. package/src/OrderedList/index.js +3 -0
  79. package/src/Responsive/Responsive.jsx +24 -11
  80. package/src/Responsive/ResponsiveProp.jsx +33 -0
  81. package/src/Responsive/ResponsiveWithMediaQueryStyleSheet.jsx +58 -0
  82. package/src/ThemeProvider/ThemeProvider.jsx +5 -2
  83. package/src/ThemeProvider/index.js +1 -0
  84. package/src/ThemeProvider/useResponsiveThemeTokens.js +85 -0
  85. package/src/Typography/Typography.jsx +72 -24
  86. package/src/index.js +2 -0
  87. package/src/server.js +4 -0
  88. package/src/utils/ssr-media-query/create-stylesheet/create-stylesheet-mobile.js +41 -0
  89. package/src/utils/ssr-media-query/create-stylesheet/index.android.js +3 -0
  90. package/src/utils/ssr-media-query/create-stylesheet/index.ios.js +3 -0
  91. package/src/utils/ssr-media-query/create-stylesheet/index.js +33 -0
  92. package/src/utils/ssr-media-query/utils/create-media-query-styles.js +21 -6
  93. package/types/Badge.d.ts +28 -0
  94. package/types/Box.d.ts +52 -0
  95. package/types/ChevronLink.d.ts +47 -0
  96. package/types/Common.d.ts +106 -0
  97. package/types/Divider.d.ts +19 -0
  98. package/types/ExpandCollapse.d.ts +65 -0
  99. package/types/HorizontalScrollButton.d.ts +16 -0
  100. package/types/Icon.d.ts +21 -0
  101. package/types/Link.d.ts +48 -0
  102. package/types/List.d.ts +48 -0
  103. package/types/Search.d.ts +38 -0
  104. package/types/Select.d.ts +57 -0
  105. package/types/Spacer.d.ts +5 -0
  106. package/types/StackView.d.ts +28 -0
  107. package/types/Tabs.d.ts +46 -0
  108. package/types/TextButton.d.ts +11 -0
  109. package/types/ToggleSwitch.d.ts +54 -0
  110. package/types/ToolTip.d.ts +40 -0
  111. package/types/Typography.d.ts +39 -0
  112. package/types/index.d.ts +62 -0
  113. package/lib/utils/ssr-media-query/create-stylesheet.js +0 -76
  114. package/lib-module/utils/ssr-media-query/create-stylesheet.js +0 -68
  115. package/src/utils/ssr-media-query/create-stylesheet.js +0 -61
@@ -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 mediaQueryStyles = createMediaQueryStyles({
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
- const { ids, styles } = StyleSheet.create({
141
- col: {
142
- flexGrow: 1,
143
- flexShrink: 0,
144
- flexBasis: 'auto',
145
- maxWidth: '100%',
146
- paddingLeft: gutter ? 16 : 0,
147
- paddingRight: gutter ? 16 : 0,
148
- ...mediaQueryStyles
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 ref={ref} {...viewProps} style={[styles.col]} dataSet={{ media: ids.col }}>
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 mediaQueryStyles = createMediaQueryStyles({
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 { ids, styles } = StyleSheet.create({
68
- flexgrid: {
69
- flexWrap: 'wrap',
70
- width: outsideGutter ? '100%' : 'auto',
71
- marginVertical: 0,
72
- marginHorizontal: outsideGutter ? 'auto' : -16,
73
- ...mediaQueryStyles
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 ref={ref} {...props} style={[styles.flexgrid]} dataSet={{ media: ids.flexgrid }}>
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>
@@ -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 mediaQueryStyles = createMediaQueryStyles({
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
- const { ids, styles } = StyleSheet.create({
93
- row: {
94
- width: '100%',
95
- marginVertical: 0,
96
- marginHorizontal: 'auto',
97
- flexGrow: 0,
98
- flexShrink: 1,
99
- flexBasis: 'auto',
100
- ...horizontalAlignStyles(horizontalAlign),
101
- ...verticalAlignStyles(verticalAlign),
102
- ...distributeStyles(distribute),
103
- ...mediaQueryStyles
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={[styles.row]} dataSet={{ media: ids.row }}>
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="listitem">
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 style={styles.styledTextButtonContainer}>
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
 
@@ -89,6 +89,8 @@ const MultiSelectFilter = ({
89
89
  return colSize === 2 && setMaxWidth(true)
90
90
  }, [colSize])
91
91
 
92
+ useEffect(() => setCheckedIds(currentValues ?? []), [currentValues])
93
+
92
94
  const {
93
95
  headerFontColor,
94
96
  headerFontSize,
@@ -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
- applyTextStyles({ ...selectTokens('Typography', tokens), themeOptions })
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
+ })
@@ -0,0 +1,3 @@
1
+ import OrderedList from './OrderedList'
2
+
3
+ export default OrderedList