@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.
Files changed (161) hide show
  1. package/CHANGELOG.md +36 -0
  2. package/__fixtures__/testTheme.js +264 -84
  3. package/__tests__/Box/Box.test.jsx +81 -58
  4. package/__tests__/Card/Card.test.jsx +63 -0
  5. package/__tests__/Divider/Divider.test.jsx +26 -5
  6. package/__tests__/Feedback/Feedback.test.jsx +42 -0
  7. package/__tests__/FlexGrid/Col.test.jsx +5 -0
  8. package/__tests__/Pagination/Pagination.test.jsx +160 -0
  9. package/__tests__/Spacer/Spacer.test.jsx +63 -0
  10. package/__tests__/StackView/StackView.test.jsx +242 -0
  11. package/__tests__/StackView/StackWrap.test.jsx +47 -0
  12. package/__tests__/StackView/getStackedContent.test.jsx +295 -0
  13. package/__tests__/TextInput/TextInput.test.jsx +146 -0
  14. package/__tests__/ThemeProvider/useThemeTokens.test.jsx +5 -3
  15. package/__tests__/utils/spacing.test.jsx +273 -0
  16. package/__tests__/utils/useUniqueId.test.js +31 -0
  17. package/babel.config.json +8 -0
  18. package/jest.config.js +7 -6
  19. package/lib/A11yInfoProvider/index.js +2 -2
  20. package/lib/A11yText/index.js +1 -3
  21. package/lib/ActivityIndicator/Spinner.web.js +3 -5
  22. package/lib/Box/Box.js +117 -82
  23. package/lib/Button/Button.js +1 -3
  24. package/lib/Button/ButtonBase.js +9 -21
  25. package/lib/Button/ButtonGroup.js +14 -25
  26. package/lib/Button/ButtonLink.js +1 -3
  27. package/lib/Card/Card.js +103 -0
  28. package/lib/Card/index.js +2 -0
  29. package/lib/Divider/Divider.js +40 -4
  30. package/lib/ExpandCollapse/Accordion.js +1 -3
  31. package/lib/ExpandCollapse/Control.js +3 -5
  32. package/lib/ExpandCollapse/Panel.js +2 -4
  33. package/lib/Feedback/Feedback.js +110 -0
  34. package/lib/Feedback/index.js +2 -0
  35. package/lib/FlexGrid/Col/Col.js +3 -5
  36. package/lib/FlexGrid/FlexGrid.js +1 -3
  37. package/lib/FlexGrid/Row/Row.js +1 -3
  38. package/lib/FlexGrid/providers/GutterContext.js +1 -1
  39. package/lib/Icon/Icon.js +1 -1
  40. package/lib/InputLabel/InputLabel.js +86 -0
  41. package/lib/InputLabel/LabelContent.native.js +8 -0
  42. package/lib/InputLabel/LabelContent.web.js +17 -0
  43. package/lib/InputLabel/index.js +2 -0
  44. package/lib/Link/ChevronLink.js +1 -3
  45. package/lib/Link/Link.js +1 -3
  46. package/lib/Link/LinkBase.js +11 -7
  47. package/lib/Link/TextButton.js +1 -3
  48. package/lib/Pagination/PageButton.js +85 -0
  49. package/lib/Pagination/Pagination.js +118 -0
  50. package/lib/Pagination/SideButton.js +108 -0
  51. package/lib/Pagination/dictionary.js +18 -0
  52. package/lib/Pagination/index.js +2 -0
  53. package/lib/Pagination/useCopy.js +10 -0
  54. package/lib/Pagination/usePagination.js +70 -0
  55. package/lib/SideNav/Item.js +4 -6
  56. package/lib/SideNav/ItemsGroup.js +11 -11
  57. package/lib/SideNav/SideNav.js +2 -4
  58. package/lib/Spacer/Spacer.js +98 -0
  59. package/lib/Spacer/index.js +2 -0
  60. package/lib/StackView/StackView.js +105 -0
  61. package/lib/StackView/StackWrap.js +32 -0
  62. package/lib/StackView/StackWrap.native.js +3 -0
  63. package/lib/StackView/StackWrapBox.js +85 -0
  64. package/lib/StackView/StackWrapGap.js +45 -0
  65. package/lib/StackView/common.js +30 -0
  66. package/lib/StackView/getStackedContent.js +111 -0
  67. package/lib/StackView/index.js +5 -0
  68. package/lib/TextInput/TextInput.js +337 -0
  69. package/lib/TextInput/index.js +2 -0
  70. package/lib/ThemeProvider/ThemeProvider.js +2 -2
  71. package/lib/ThemeProvider/useThemeTokens.js +34 -6
  72. package/lib/ThemeProvider/utils/theme-tokens.js +37 -9
  73. package/lib/ToggleSwitch/ToggleSwitch.js +17 -47
  74. package/lib/Typography/Typography.js +1 -7
  75. package/lib/ViewportProvider/index.js +1 -1
  76. package/lib/index.js +8 -1
  77. package/lib/utils/index.js +2 -1
  78. package/lib/utils/input.js +3 -1
  79. package/lib/utils/propTypes.js +103 -8
  80. package/lib/utils/spacing/index.js +2 -0
  81. package/lib/utils/spacing/useSpacingScale.js +102 -0
  82. package/lib/utils/spacing/utils.js +32 -0
  83. package/lib/utils/useUniqueId.js +12 -0
  84. package/package.json +6 -9
  85. package/release-context.json +4 -4
  86. package/src/Box/Box.jsx +117 -80
  87. package/src/Button/ButtonBase.jsx +8 -21
  88. package/src/Button/ButtonGroup.jsx +13 -17
  89. package/src/Card/Card.jsx +101 -0
  90. package/src/Card/index.js +3 -0
  91. package/src/Divider/Divider.jsx +38 -3
  92. package/src/ExpandCollapse/Control.jsx +2 -3
  93. package/src/Feedback/Feedback.jsx +99 -0
  94. package/src/Feedback/index.js +3 -0
  95. package/src/FlexGrid/Col/Col.jsx +4 -2
  96. package/src/Icon/Icon.jsx +2 -1
  97. package/src/InputLabel/InputLabel.jsx +99 -0
  98. package/src/InputLabel/LabelContent.native.jsx +6 -0
  99. package/src/InputLabel/LabelContent.web.jsx +13 -0
  100. package/src/InputLabel/index.js +3 -0
  101. package/src/Link/LinkBase.jsx +9 -3
  102. package/src/Pagination/PageButton.jsx +80 -0
  103. package/src/Pagination/Pagination.jsx +135 -0
  104. package/src/Pagination/SideButton.jsx +93 -0
  105. package/src/Pagination/dictionary.js +18 -0
  106. package/src/Pagination/index.js +3 -0
  107. package/src/Pagination/useCopy.js +7 -0
  108. package/src/Pagination/usePagination.js +69 -0
  109. package/src/SideNav/Item.jsx +3 -3
  110. package/src/SideNav/ItemsGroup.jsx +11 -13
  111. package/src/Spacer/Spacer.jsx +91 -0
  112. package/src/Spacer/index.js +3 -0
  113. package/src/StackView/StackView.jsx +103 -0
  114. package/src/StackView/StackWrap.jsx +33 -0
  115. package/src/StackView/StackWrap.native.jsx +4 -0
  116. package/src/StackView/StackWrapBox.jsx +82 -0
  117. package/src/StackView/StackWrapGap.jsx +39 -0
  118. package/src/StackView/common.jsx +28 -0
  119. package/src/StackView/getStackedContent.jsx +106 -0
  120. package/src/StackView/index.js +6 -0
  121. package/src/TextInput/TextInput.jsx +325 -0
  122. package/src/TextInput/index.js +3 -0
  123. package/src/ThemeProvider/useThemeTokens.js +34 -7
  124. package/src/ThemeProvider/utils/theme-tokens.js +37 -8
  125. package/src/ToggleSwitch/ToggleSwitch.jsx +23 -43
  126. package/src/Typography/Typography.jsx +0 -4
  127. package/src/index.js +8 -1
  128. package/src/utils/index.js +1 -0
  129. package/src/utils/input.js +2 -1
  130. package/src/utils/propTypes.js +105 -16
  131. package/src/utils/spacing/index.js +3 -0
  132. package/src/utils/spacing/useSpacingScale.js +93 -0
  133. package/src/utils/spacing/utils.js +28 -0
  134. package/src/utils/useUniqueId.js +14 -0
  135. package/stories/A11yText/A11yText.stories.jsx +11 -5
  136. package/stories/ActivityIndicator/ActivityIndicator.stories.jsx +11 -2
  137. package/stories/Box/Box.stories.jsx +46 -17
  138. package/stories/Button/Button.stories.jsx +17 -21
  139. package/stories/Button/ButtonGroup.stories.jsx +2 -1
  140. package/stories/Button/ButtonLink.stories.jsx +6 -4
  141. package/stories/Card/Card.stories.jsx +62 -0
  142. package/stories/Divider/Divider.stories.jsx +26 -2
  143. package/stories/ExpandCollapse/ExpandCollapse.stories.jsx +74 -79
  144. package/stories/Feedback/Feedback.stories.jsx +97 -0
  145. package/stories/FlexGrid/01 FlexGrid.stories.jsx +20 -7
  146. package/stories/Icon/Icon.stories.jsx +11 -3
  147. package/stories/InputLabel/InputLabel.stories.jsx +37 -0
  148. package/stories/Link/ChevronLink.stories.jsx +20 -4
  149. package/stories/Link/Link.stories.jsx +24 -3
  150. package/stories/Link/TextButton.stories.jsx +24 -3
  151. package/stories/Pagination/Pagination.stories.jsx +64 -0
  152. package/stories/SideNav/SideNav.stories.jsx +17 -2
  153. package/stories/Spacer/Spacer.stories.jsx +33 -0
  154. package/stories/StackView/StackView.stories.jsx +65 -0
  155. package/stories/StackView/StackWrap.stories.jsx +52 -0
  156. package/stories/TextInput/TextInput.stories.jsx +103 -0
  157. package/stories/ToggleSwitch/ToggleSwitch.stories.jsx +16 -3
  158. package/stories/Typography/Typography.stories.jsx +12 -3
  159. package/stories/platform-supports.web.jsx +1 -1
  160. package/stories/supports.jsx +113 -13
  161. package/babel.config.js +0 -3
@@ -1,23 +1,97 @@
1
1
  /* eslint-disable react/no-multi-comp */
2
2
  import React from 'react'
3
3
  import PropTypes from 'prop-types'
4
- import { View, StyleSheet } from 'react-native'
4
+ import { Platform, ScrollView, View, StyleSheet } from 'react-native'
5
5
  import { useTheme, getComponentTheme } from '../lib/ThemeProvider'
6
6
  import { Typography } from '../lib'
7
7
  import { containers as platformContainers } from './platform-supports'
8
8
 
9
- const FlexRow = ({ children }) => <View style={styles.row}>{children}</View>
10
- FlexRow.propTypes = { children: PropTypes.node }
9
+ const RowWrap = ({ children }) => <View style={styles.rowWrap}>{children}</View>
10
+ RowWrap.propTypes = { children: PropTypes.node }
11
11
 
12
- const FlexColumn = ({ children }) => <View style={styles.column}>{children}</View>
13
- FlexColumn.propTypes = { children: PropTypes.node }
12
+ const RowStretch = ({ children }) => (
13
+ <ScrollView horizontal contentContainerStyle={styles.rowStretch}>
14
+ {children}
15
+ </ScrollView>
16
+ )
17
+ RowStretch.propTypes = { children: PropTypes.node }
18
+
19
+ const ColumnWrap = ({ children }) => (
20
+ <ScrollView
21
+ horizontal
22
+ style={styles.columnWrapContainer}
23
+ contentContainerStyle={styles.columnWrap}
24
+ >
25
+ {children}
26
+ </ScrollView>
27
+ )
28
+ ColumnWrap.propTypes = { children: PropTypes.node }
29
+
30
+ const ColumnStretch = ({ children }) => (
31
+ <View containerStyle={styles.columnStretch}>{children}</View>
32
+ )
33
+ ColumnStretch.propTypes = { children: PropTypes.node }
34
+
35
+ // TODO: find a way to give Base stories a complete empty SpacingObject for easy editting
36
+ // while giving themed stories a simpler value.
37
+ export const spacingObjectArg = { xs: 1, lg: 3 }
14
38
 
15
39
  export const parentTypes = {
16
- FlexRow,
17
- FlexColumn,
40
+ RowWrap,
41
+ RowStretch,
42
+ ColumnWrap,
43
+ ColumnStretch,
18
44
  ...platformContainers
19
45
  }
20
46
 
47
+ /**
48
+ * React Native (and therefore also React Native Web) components are usually at some level based on
49
+ * `View` and have some default layout styles that are quite different to regular web defaults:
50
+ *
51
+ * - `display: flex` instead of `display: block`
52
+ * - `flexDirection: column` instead of `flexDirection: row` when flex
53
+ * - `position: relative`
54
+ *
55
+ * It's easy to fall into the trap of developing and testing something that works fine in a regular
56
+ * `View` but doesn't work as expected in other common layout containers. This is particularly true
57
+ * for UDS where internally we are devleoping entirely within React Native but many real-world use cases
58
+ * will mix UDS components with regular web HTML elements.
59
+ *
60
+ * The `EachParentType` support component and related `parentTypes` tooling are intended to make it easy
61
+ * to routinely test and demonstrate how UDS components behave in a wide range of parent types.
62
+ *
63
+ * To use it, pass as `children` a render function that takes the following and places them appropriately
64
+ * in a demonstration of your component (be careful to not wrap the component in a `View` or container as
65
+ * that will defeat the point of the exercise!):
66
+ *
67
+ * - `variant` - each theme variant will be rendered as siblings, pass this to the component's `variant` prop.
68
+ * - `label` - this will describe the parent type / variant combination and ideally should be somewhere easy to read
69
+ * inside the component to help users understand what they are looking at.
70
+ * - `index` - the index of the currently rendered component variant (`0` if the component has no variants).
71
+ */
72
+ export const EachParentType = ({ children, componentThemeName, ...args }) => {
73
+ const variants = useVariants(componentThemeName)
74
+ return Object.entries(parentTypes).map(([parentLabel, ParentType]) => (
75
+ <Container key={parentLabel} offWhite>
76
+ <ParentType>
77
+ {variants.map(([key, value, variantLabel], index) => {
78
+ const label = variantLabel ? `${parentLabel}: ${variantLabel}` : parentLabel
79
+ const variant = { ...args.variant, [key]: value }
80
+ return typeof children === 'function' ? children({ label, variant, index }) : children
81
+ })}
82
+ </ParentType>
83
+ </Container>
84
+ ))
85
+ }
86
+
87
+ const parentTypesList = `\`"${Object.keys(parentTypes).join('"`, `"')}"\``
88
+
89
+ export const parentTypesParams = {
90
+ docs: {
91
+ storyDescription: `This tests how this component's variants render in each of the following types of container: ${parentTypesList}.`
92
+ }
93
+ }
94
+
21
95
  export const Placeholder = ({ margin = false, ...props }) => (
22
96
  <View style={[styles.placeholder, margin && styles.margin]}>
23
97
  <Typography {...props} />
@@ -32,17 +106,29 @@ export const Container = ({
32
106
  padding = 8,
33
107
  dark = false,
34
108
  offWhite = false,
109
+ borderWidth,
110
+ style,
35
111
  children
36
112
  }) => (
37
- <View style={[{ margin, padding }, dark && styles.dark, offWhite && styles.offWhite]}>
113
+ <View
114
+ style={[
115
+ { margin, padding },
116
+ dark && styles.dark,
117
+ offWhite && styles.offWhite,
118
+ { borderWidth },
119
+ style
120
+ ]}
121
+ >
38
122
  {children}
39
123
  </View>
40
124
  )
41
125
  Container.propTypes = {
42
126
  margin: PropTypes.number,
43
127
  padding: PropTypes.number,
128
+ borderWidth: PropTypes.number,
44
129
  dark: PropTypes.bool,
45
130
  offWhite: PropTypes.bool,
131
+ style: PropTypes.object,
46
132
  children: PropTypes.node
47
133
  }
48
134
 
@@ -53,6 +139,8 @@ const getVariantLabel = (key, value) => `${key}${typeof value === 'string' ? `:
53
139
  */
54
140
  export const useVariants = (componentName) => {
55
141
  const theme = useTheme()
142
+ if (!componentName) return [['default', {}]]
143
+
56
144
  const { appearances } = getComponentTheme(theme, componentName)
57
145
 
58
146
  if (!appearances) {
@@ -72,14 +160,26 @@ export const useVariants = (componentName) => {
72
160
  }
73
161
 
74
162
  const styles = StyleSheet.create({
75
- row: {
163
+ rowWrap: {
76
164
  flexDirection: 'row',
77
- alignItems: 'center',
78
- flexWrap: 'wrap'
165
+ alignItems: 'flex-start',
166
+ flexWrap: 'wrap',
167
+ flex: 1
168
+ },
169
+ rowStretch: {
170
+ flexDirection: 'row',
171
+ flexGrow: 1
172
+ },
173
+ columnStretch: {
174
+ // alignItems: 'stretch' and flexDirection: 'column' are the default
79
175
  },
80
- column: {
176
+ columnWrap: {
81
177
  flexDirection: 'column',
82
- alignItems: 'center'
178
+ alignItems: 'flex-start',
179
+ flexWrap: 'wrap',
180
+ // Ensure the content columns wrap
181
+ ...Platform.select({ web: { maxHeight: 150 }, default: { height: 125, minWidth: '200%' } }),
182
+ flexGrow: 1
83
183
  },
84
184
  content: {
85
185
  maxWidth: 200,
package/babel.config.js DELETED
@@ -1,3 +0,0 @@
1
- module.exports = {
2
- plugins: ['@babel/plugin-transform-react-jsx']
3
- }