@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,5 +1,7 @@
1
+ /* eslint-disable react/no-multi-comp */
1
2
  import React from 'react'
2
3
  import { ActivityIndicator } from '../../lib'
4
+ import { EachParentType, parentTypesParams } from '../supports'
3
5
 
4
6
  export default {
5
7
  title: 'Base/ActivityIndicator',
@@ -9,5 +11,12 @@ export default {
9
11
  }
10
12
  }
11
13
 
12
- export const Story = (args) => <ActivityIndicator {...args} />
13
- Story.storyName = 'ActivityIndicator'
14
+ export const Default = (args) => <ActivityIndicator {...args} />
15
+ Default.storyName = 'ActivityIndicator'
16
+
17
+ export const ParentTypes = (args) => (
18
+ <EachParentType {...args}>
19
+ {({ label }) => <ActivityIndicator {...args} label={label} />}
20
+ </EachParentType>
21
+ )
22
+ ParentTypes.parameters = parentTypesParams
@@ -2,21 +2,26 @@
2
2
  import React from 'react'
3
3
 
4
4
  import { View, StyleSheet } from 'react-native'
5
- import { Box } from '../../lib'
6
- import { Placeholder } from '../supports'
5
+ import { Box, Typography } from '../../lib'
6
+ import {
7
+ spacingObjectArg,
8
+ Container,
9
+ Placeholder,
10
+ EachParentType,
11
+ parentTypesParams
12
+ } from '../supports'
7
13
 
8
14
  export default {
9
15
  title: 'Base/Box',
10
- component: Box,
11
- parameters: {
12
- padded: false
13
- }
16
+ component: Box
14
17
  }
15
18
 
16
19
  const Template = (args) => (
17
- <Box {...args}>
18
- <Placeholder>Box</Placeholder>
19
- </Box>
20
+ <Container margin={0} padding={0} borderWidth={1} offWhite>
21
+ <Box {...args}>
22
+ <Placeholder>Box</Placeholder>
23
+ </Box>
24
+ </Container>
20
25
  )
21
26
 
22
27
  const ScrollTemplate = (args) => (
@@ -68,39 +73,49 @@ const ScrollTemplate = (args) => (
68
73
  </View>
69
74
  )
70
75
 
71
- const spacings = { xs: 2, sm: 4, md: 6, lg: 8, xl: 10 }
72
-
73
76
  const styles = StyleSheet.create({
74
77
  fixedHeight: { height: 200, overflow: 'hidden' }
75
78
  })
79
+
80
+ export const Default = (args) => <Box {...args} />
81
+ Default.storyName = 'Box'
82
+ Default.args = { children: <Typography>Box</Typography> }
83
+ // By default the JSX object is shown as a huge human-unreadable JSON tree control; turn it off
84
+ Default.argTypes = { children: { control: { disable: true } } }
85
+
76
86
  export const Top = Template.bind({})
77
87
  Top.args = {
78
- top: spacings
88
+ top: spacingObjectArg
79
89
  }
80
90
 
81
91
  export const Bottom = Template.bind({})
82
92
  Bottom.args = {
83
- bottom: spacings
93
+ bottom: spacingObjectArg
84
94
  }
85
95
 
86
96
  export const Left = Template.bind({})
87
97
  Left.args = {
88
- left: spacings
98
+ left: spacingObjectArg
89
99
  }
90
100
 
91
101
  export const Right = Template.bind({})
92
102
  Right.args = {
93
- right: spacings
103
+ right: spacingObjectArg
94
104
  }
95
105
 
96
106
  export const Horizontal = Template.bind({})
97
107
  Horizontal.args = {
98
- horizontal: spacings
108
+ horizontal: spacingObjectArg
99
109
  }
100
110
 
101
111
  export const Vertical = Template.bind({})
102
112
  Vertical.args = {
103
- vertical: spacings
113
+ vertical: spacingObjectArg
114
+ }
115
+
116
+ export const AllSides = Template.bind({})
117
+ AllSides.args = {
118
+ space: spacingObjectArg
104
119
  }
105
120
 
106
121
  export const Scroll = ScrollTemplate.bind({})
@@ -112,3 +127,17 @@ export const NoScroll = ScrollTemplate.bind({})
112
127
  NoScroll.args = {
113
128
  scroll: false
114
129
  }
130
+
131
+ export const ParentTypes = (args) => (
132
+ <EachParentType componentThemeName="Box" {...args}>
133
+ {({ label, variant }) => (
134
+ <Container key={label} margin={0} padding={0} borderWidth={1} dark>
135
+ <Box {...args} variant={variant}>
136
+ <Placeholder>{label}</Placeholder>
137
+ </Box>
138
+ </Container>
139
+ )}
140
+ </EachParentType>
141
+ )
142
+ ParentTypes.args = { space: 2 }
143
+ ParentTypes.parameters = parentTypesParams
@@ -1,9 +1,11 @@
1
+ /* eslint-disable react/no-multi-comp */
1
2
  import React from 'react'
2
- import { Button as ButtonComponent, useTheme } from '../../lib'
3
- import { Container, useVariants, parentTypes } from '../supports'
3
+ import { Button, useTheme } from '../../lib'
4
+ import { Container, useVariants, EachParentType, parentTypesParams } from '../supports'
4
5
  import { getComponentTheme } from '../../lib/ThemeProvider/utils'
5
6
 
6
- export const Button = ButtonComponent
7
+ export const Default = (args) => <Button {...args} />
8
+ Default.storyName = 'Button'
7
9
 
8
10
  const defaultLabel = "I'm a button"
9
11
 
@@ -14,7 +16,8 @@ export default {
14
16
  // eslint-disable-next-line no-console
15
17
  onPress: () => console.log('Button pressed'),
16
18
  children: defaultLabel,
17
- variant: {} // @TODO work out why this isn't coming from jsdoc
19
+ variant: {}, // @TODO work out why this isn't coming from jsdoc
20
+ tokens: {}
18
21
  }
19
22
  }
20
23
 
@@ -52,20 +55,13 @@ LongLabelButtonVariants.args = {
52
55
  children: 'This button has a label that is much longer than is considered advisable'
53
56
  }
54
57
 
55
- export const ButtonParentTypes = (args) => {
56
- const variants = useVariants('Button')
57
- return Object.entries(parentTypes).map(([parentLabel, ParentType]) => (
58
- <Container borderWidth={1} key={parentLabel} offWhite>
59
- <ParentType>
60
- {variants.map(([key, value, variantLabel]) => {
61
- const label = `${parentLabel}: ${variantLabel}`
62
- return (
63
- <Button {...args} key={label} variant={{ [key]: value }}>
64
- {label}
65
- </Button>
66
- )
67
- })}
68
- </ParentType>
69
- </Container>
70
- ))
71
- }
58
+ export const ParentTypes = (args) => (
59
+ <EachParentType componentThemeName="Button" {...args}>
60
+ {({ label, variant }) => (
61
+ <Button {...args} key={label} variant={variant}>
62
+ {label}
63
+ </Button>
64
+ )}
65
+ </EachParentType>
66
+ )
67
+ ParentTypes.parameters = parentTypesParams
@@ -59,7 +59,8 @@ const ControlledTemplate = ({ values, ...args }) => {
59
59
 
60
60
  ControlledTemplate.propTypes = ButtonGroup.propTypes
61
61
 
62
- export const ButtonGroupMaxOne = UncontrolledTemplate.bind({})
62
+ export const Default = UncontrolledTemplate.bind({})
63
+ Default.storyName = 'ButtonGroup'
63
64
 
64
65
  export const ButtonGroupMaxThree = UncontrolledTemplate.bind({})
65
66
  ButtonGroupMaxThree.args = { maxValues: 3 }
@@ -6,7 +6,7 @@ export default {
6
6
  title: 'Base/ButtonLink',
7
7
  component: ButtonLink,
8
8
  args: {
9
- label: "I'm a button link",
9
+ children: "I'm a button link",
10
10
  href: 'https://telus.com',
11
11
  target: '_blank',
12
12
  rel: 'nofollow'
@@ -18,11 +18,13 @@ const Template = (args) => {
18
18
  return variants.map(([key, value, label]) => (
19
19
  <Container key={`${key}:${value}`} dark={key === 'inverse'}>
20
20
  <ButtonLink {...args} href="https://telus.com" variant={{ [key]: value }}>
21
- {args.label || `Button ${label}`}
21
+ {args.label || `ButtonLink ${label}`}
22
22
  </ButtonLink>
23
23
  </Container>
24
24
  ))
25
25
  }
26
26
 
27
- export const ButtonLinkStory = Template.bind({})
28
- ButtonLinkStory.storyName = 'ButtonLink'
27
+ export const Default = (args) => <ButtonLink {...args} />
28
+ Default.storyName = 'ButtonLink'
29
+
30
+ export const Variants = Template.bind({})
@@ -0,0 +1,62 @@
1
+ /* eslint-disable react/no-multi-comp */
2
+ import React from 'react'
3
+ import { StyleSheet, Text, View } from 'react-native'
4
+
5
+ import { Card } from '../../lib'
6
+ import { Container, useVariants, EachParentType, parentTypesParams } from '../supports'
7
+
8
+ export default {
9
+ title: 'Base/Card',
10
+ component: Card
11
+ }
12
+
13
+ const styles = StyleSheet.create({
14
+ cardContent: {
15
+ padding: 4,
16
+ borderWidth: 1,
17
+ borderColor: '#C12335',
18
+ borderStyle: 'dashed',
19
+ backgroundColor: '#FFF6F8'
20
+ }
21
+ })
22
+
23
+ export const Default = (args) => (
24
+ <Card {...args}>
25
+ <View style={styles.cardContent}>
26
+ <Text>This is a card</Text>
27
+ </View>
28
+ </Card>
29
+ )
30
+ Default.storyName = 'Card'
31
+ Default.argTypes = {
32
+ children: { table: { disable: true } }
33
+ }
34
+
35
+ export const CardVariants = (args) => {
36
+ const variants = useVariants('Card')
37
+ const cardVariants = variants.map(([key, value, label]) => (
38
+ <Container key={`${key}:${value}`} padding={16}>
39
+ <Card {...args} variant={{ [key]: value }}>
40
+ <View style={styles.cardContent}>
41
+ <Text>
42
+ Card with
43
+ {` ${label}`}
44
+ </Text>
45
+ </View>
46
+ </Card>
47
+ </Container>
48
+ ))
49
+
50
+ return cardVariants
51
+ }
52
+
53
+ export const ParentTypes = (args) => (
54
+ <EachParentType componentThemeName="Card" {...args}>
55
+ {({ label, variant }) => (
56
+ <Card {...args} variant={variant}>
57
+ <Text>{label}</Text>
58
+ </Card>
59
+ )}
60
+ </EachParentType>
61
+ )
62
+ ParentTypes.parameters = parentTypesParams
@@ -1,12 +1,17 @@
1
+ /* eslint-disable react/no-multi-comp */
1
2
  import React from 'react'
2
3
  import { View, StyleSheet } from 'react-native'
3
4
  import { Divider, Typography } from '../../lib'
5
+ import { EachParentType, parentTypesParams } from '../supports'
4
6
 
5
7
  export default {
6
8
  title: 'Base/Divider',
7
9
  component: Divider
8
10
  }
9
11
 
12
+ export const Default = (args) => <Divider {...args} />
13
+ Default.storyName = 'Divider'
14
+
10
15
  const Template = ({ vertical, ...rest }) => (
11
16
  <View style={vertical ? styles.row : styles.column}>
12
17
  <View style={vertical ? styles.contentRow : styles.contentColumn}>
@@ -24,8 +29,27 @@ const Template = ({ vertical, ...rest }) => (
24
29
 
25
30
  Template.propTypes = Divider.propTypes
26
31
 
27
- export const Story = Template.bind({})
28
- Story.storyName = 'Divider'
32
+ export const Horizontal = Template.bind({})
33
+
34
+ export const Vertical = Template.bind({})
35
+ Vertical.args = { vertical: true }
36
+
37
+ export const ParentTypes = (args) => (
38
+ <EachParentType componentThemeName="Divider" {...args}>
39
+ {({ label, variant, index }) =>
40
+ label.match(/Row/) ? (
41
+ <Typography>{index ? '' : 'Skipping Row examples; see Vertical story. '}</Typography>
42
+ ) : (
43
+ <>
44
+ <Typography>{`"${label}" is below this moderately lengthy text appearing before the Divider.`}</Typography>
45
+ <Divider {...args} variant={variant} />
46
+ <Typography>{`"${label}" is above.`}</Typography>
47
+ </>
48
+ )
49
+ }
50
+ </EachParentType>
51
+ )
52
+ ParentTypes.parameters = parentTypesParams
29
53
 
30
54
  const styles = StyleSheet.create({
31
55
  row: {
@@ -1,14 +1,8 @@
1
1
  /* eslint-disable react/no-multi-comp */
2
2
  import React from 'react'
3
3
  import PropTypes from 'prop-types'
4
- import {
5
- Accordion as AccordionComponent,
6
- ButtonGroup,
7
- Divider,
8
- ExpandCollapse,
9
- Typography
10
- } from '../../lib'
11
- import { Container } from '../supports'
4
+ import { Accordion, ButtonGroup, ExpandCollapse, StackView, Typography } from '../../lib'
5
+ import { Container, EachParentType, parentTypesParams } from '../supports'
12
6
  import { useMultipleInputValues } from '../../lib/utils'
13
7
 
14
8
  export default {
@@ -27,48 +21,42 @@ SimpleText.propTypes = {
27
21
  children: PropTypes.node
28
22
  }
29
23
 
30
- const getTemplate = (ExpandComponent = ExpandCollapse) => {
31
- const Template = (args) => (
32
- <ExpandComponent {...args}>
33
- {(expandProps) => (
34
- <>
35
- <Divider />
36
- <ExpandCollapse.Panel
37
- {...expandProps}
38
- panelId="first"
39
- control={<SimpleText bold>First panel</SimpleText>}
40
- >
41
- <SimpleText>Some content within the first panel</SimpleText>
42
- </ExpandCollapse.Panel>
43
- <Divider />
44
- <ExpandCollapse.Panel
45
- {...expandProps}
46
- panelId="second"
47
- control={<SimpleText bold>Second panel</SimpleText>}
48
- >
49
- <SimpleText>Some content within the second panel</SimpleText>
50
- </ExpandCollapse.Panel>
51
- <Divider />
52
- <Container>
53
- <SimpleText>Non-interactive item</SimpleText>
54
- </Container>
55
- <Divider />
56
- <ExpandCollapse.Panel
57
- {...expandProps}
58
- panelId="third"
59
- control={<SimpleText bold>Last panel</SimpleText>}
60
- >
61
- <SimpleText>Some content within the last panel</SimpleText>
62
- </ExpandCollapse.Panel>
63
- </>
64
- )}
65
- </ExpandComponent>
66
- )
67
- return Template
68
- }
24
+ const exampleRenderFunction = (expandProps, label = 'Non-interactive item') => (
25
+ <StackView divider space={2}>
26
+ <ExpandCollapse.Panel
27
+ {...expandProps}
28
+ panelId="first"
29
+ control={<SimpleText bold>First panel</SimpleText>}
30
+ >
31
+ <SimpleText>Some content within the first panel</SimpleText>
32
+ </ExpandCollapse.Panel>
33
+ <ExpandCollapse.Panel
34
+ {...expandProps}
35
+ panelId="second"
36
+ control={<SimpleText bold>Second panel</SimpleText>}
37
+ >
38
+ <SimpleText>Some content within the second panel</SimpleText>
39
+ </ExpandCollapse.Panel>
40
+ <Container>
41
+ <SimpleText>{label}</SimpleText>
42
+ </Container>
43
+ <ExpandCollapse.Panel
44
+ {...expandProps}
45
+ panelId="third"
46
+ control={<SimpleText bold>Last panel</SimpleText>}
47
+ >
48
+ <SimpleText>Some content within the last panel</SimpleText>
49
+ </ExpandCollapse.Panel>
50
+ </StackView>
51
+ )
69
52
 
70
- export const Default = getTemplate()
71
- export const Accordion = getTemplate(AccordionComponent)
53
+ export const Default = (args) => <ExpandCollapse {...args} />
54
+ Default.storyName = 'ExpandCollapse'
55
+ Default.args = { children: exampleRenderFunction }
56
+
57
+ export const AccordionStory = (args) => <Accordion {...args} />
58
+ AccordionStory.storyName = 'Accordion'
59
+ AccordionStory.args = { children: exampleRenderFunction }
72
60
 
73
61
  // This is an edge case but TDS's ExpandCollapse only worked in this externally-controlled
74
62
  // way, so supporting it cleanly will make transition easier at low cost. Button group
@@ -79,39 +67,46 @@ export const Controlled = ({ maxOpen = null, ...args }) => {
79
67
  })
80
68
  const itemNames = ['one', 'two', 'three', 'four']
81
69
  return (
82
- <>
83
- <Container>
84
- <ButtonGroup
85
- items={itemNames.map((item) => ({
86
- label: item
87
- }))}
88
- maxValues={null}
89
- values={currentValues}
90
- onChange={setValues}
91
- />
92
- </Container>
93
- <Container>
94
- <ExpandCollapse {...args} open={currentValues} onChange={setValues} maxValues={maxOpen}>
95
- {(expandProps) =>
96
- itemNames.map((itemName) => (
97
- <>
98
- <Divider />
99
- <ExpandCollapse.Panel
100
- {...expandProps}
101
- panelId={itemName}
102
- control={<SimpleText bold>{itemName}</SimpleText>}
103
- >
104
- <SimpleText>{`Some content within panel number ${itemName}`}</SimpleText>
105
- </ExpandCollapse.Panel>
106
- </>
107
- ))
108
- }
109
- </ExpandCollapse>
110
- </Container>
111
- </>
70
+ <StackView space={6}>
71
+ <ButtonGroup
72
+ items={itemNames.map((item) => ({
73
+ label: item
74
+ }))}
75
+ maxValues={null}
76
+ values={currentValues}
77
+ onChange={setValues}
78
+ />
79
+ <ExpandCollapse {...args} open={currentValues} onChange={setValues} maxValues={maxOpen}>
80
+ {(expandProps) => (
81
+ <StackView divider>
82
+ {itemNames.map((itemName) => (
83
+ <ExpandCollapse.Panel
84
+ {...expandProps}
85
+ key={itemName}
86
+ panelId={itemName}
87
+ control={<SimpleText bold>{itemName}</SimpleText>}
88
+ >
89
+ <SimpleText>{`Some content within panel number ${itemName}`}</SimpleText>
90
+ </ExpandCollapse.Panel>
91
+ ))}
92
+ </StackView>
93
+ )}
94
+ </ExpandCollapse>
95
+ </StackView>
112
96
  )
113
97
  }
114
98
  Controlled.propTypes = {
115
99
  maxOpen: PropTypes.number
116
100
  }
117
101
  Controlled.args = {}
102
+
103
+ export const ParentTypes = (args) => (
104
+ <EachParentType componentThemeName="ExpandCollapse" {...args}>
105
+ {({ label, variant }) => (
106
+ <ExpandCollapse {...args} variant={variant}>
107
+ {(expandProps) => exampleRenderFunction(expandProps, label)}
108
+ </ExpandCollapse>
109
+ )}
110
+ </EachParentType>
111
+ )
112
+ ParentTypes.parameters = parentTypesParams
@@ -0,0 +1,97 @@
1
+ import React, { useEffect, useState } from 'react'
2
+ import { Text } from 'react-native'
3
+
4
+ import { Feedback, Typography } from '../../lib'
5
+ import { Container } from '../supports'
6
+ import TextInput from '../../lib/TextInput'
7
+
8
+ export default {
9
+ title: 'Base/Feedback',
10
+ component: Feedback
11
+ }
12
+
13
+ /* eslint-disable react/no-multi-comp */
14
+
15
+ const Template = (args) => (
16
+ <Container>
17
+ <Feedback {...args} />
18
+ </Container>
19
+ )
20
+
21
+ export const Default = Template.bind({})
22
+ Default.args = { title: 'Title', children: 'String content' }
23
+ Default.storyName = 'Feedback'
24
+
25
+ export const RenderFunctionAndChildren = () => (
26
+ <>
27
+ <Container>
28
+ <Feedback title="Render function">
29
+ {({ textStyles }) => <Text style={textStyles}>Content from function</Text>}
30
+ </Feedback>
31
+ </Container>
32
+ <Container>
33
+ <Feedback title="Children">
34
+ <Typography>Content from children</Typography>
35
+ </Feedback>
36
+ </Container>
37
+ </>
38
+ )
39
+
40
+ export const Variants = () => (
41
+ <>
42
+ <Container>
43
+ <Feedback variant={{ state: 'success' }} title="Success">
44
+ {({ textStyles }) => <Text style={textStyles}>Content from function</Text>}
45
+ </Feedback>
46
+ </Container>
47
+ <Container>
48
+ <Feedback variant={{ state: 'success', icon: true }} title="Success with icon">
49
+ {({ textStyles }) => <Text style={textStyles}>Content from function</Text>}
50
+ </Feedback>
51
+ </Container>
52
+ <Container>
53
+ <Feedback variant={{ state: 'error' }} title="Error">
54
+ {({ textStyles }) => <Text style={textStyles}>Content from function</Text>}
55
+ </Feedback>
56
+ </Container>
57
+ <Container>
58
+ <Feedback variant={{ state: 'error', icon: true }} title="Error with icon">
59
+ {({ textStyles }) => <Text style={textStyles}>Content from function</Text>}
60
+ </Feedback>
61
+ </Container>
62
+ </>
63
+ )
64
+
65
+ export const WithinInput = () => {
66
+ const [value, setValue] = useState('')
67
+ const [validation, setValidation] = useState()
68
+
69
+ useEffect(() => {
70
+ if (value !== undefined && value.length > 0)
71
+ setValidation(value.length < 6 ? 'success' : 'error')
72
+ }, [value])
73
+
74
+ const defaultFeedbackContent =
75
+ 'Will show an error if longer than 6 characters and success otherwise'
76
+
77
+ const feedbackContent = {
78
+ error: 'The value must be shorter than 6 characters',
79
+ success: 'Yay! The value has less than 6 characters'
80
+ }
81
+
82
+ const feedback = validation === undefined ? defaultFeedbackContent : feedbackContent[validation]
83
+
84
+ return (
85
+ <>
86
+ <Container>
87
+ <TextInput
88
+ label="Controlled"
89
+ validation={validation}
90
+ feedback={feedback}
91
+ value={value}
92
+ onChange={setValue}
93
+ />
94
+ </Container>
95
+ </>
96
+ )
97
+ }
@@ -1,7 +1,8 @@
1
+ /* eslint-disable react/no-multi-comp */
1
2
  import React from 'react'
2
3
 
3
4
  import { FlexGrid } from '../../lib'
4
- import { Placeholder } from '../supports'
5
+ import { Placeholder, EachParentType, parentTypesParams } from '../supports'
5
6
 
6
7
  const { Row, Col } = FlexGrid
7
8
 
@@ -10,11 +11,11 @@ export default {
10
11
  component: FlexGrid
11
12
  }
12
13
 
13
- const Template = (args) => (
14
- <FlexGrid {...args}>
14
+ const getContent = (label = '1/6') => (
15
+ <>
15
16
  <Row>
16
17
  <Col>
17
- <Placeholder margin>1/6</Placeholder>
18
+ <Placeholder margin>{label}</Placeholder>
18
19
  </Col>
19
20
  <Col>
20
21
  <Placeholder margin>2/6</Placeholder>
@@ -34,8 +35,20 @@ const Template = (args) => (
34
35
  <Placeholder margin>6/6</Placeholder>
35
36
  </Col>
36
37
  </Row>
37
- </FlexGrid>
38
+ </>
38
39
  )
39
40
 
40
- export const Example = Template.bind({})
41
- Example.storyName = 'FlexGrid'
41
+ export const Default = (args) => <FlexGrid {...args} />
42
+ Default.storyName = 'FlexGrid'
43
+ Default.args = { children: getContent() }
44
+
45
+ export const ParentTypes = (args) => (
46
+ <EachParentType {...args}>
47
+ {({ label, variant }) => (
48
+ <FlexGrid {...args} variant={variant}>
49
+ {getContent(label)}
50
+ </FlexGrid>
51
+ )}
52
+ </EachParentType>
53
+ )
54
+ ParentTypes.parameters = parentTypesParams