@telus-uds/components-base 0.0.2-prerelease.4 → 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 (96) hide show
  1. package/CHANGELOG.md +17 -0
  2. package/__fixtures__/testTheme.js +83 -11
  3. package/__tests__/Divider/Divider.test.jsx +26 -5
  4. package/__tests__/Feedback/Feedback.test.jsx +42 -0
  5. package/__tests__/Spacer/Spacer.test.jsx +63 -0
  6. package/__tests__/StackView/StackView.test.jsx +242 -0
  7. package/__tests__/StackView/StackWrap.test.jsx +47 -0
  8. package/__tests__/StackView/getStackedContent.test.jsx +295 -0
  9. package/__tests__/TextInput/TextInput.test.jsx +146 -0
  10. package/__tests__/utils/useUniqueId.test.js +31 -0
  11. package/lib/Box/Box.js +7 -2
  12. package/lib/Button/ButtonBase.js +6 -16
  13. package/lib/Button/ButtonGroup.js +13 -22
  14. package/lib/Divider/Divider.js +40 -2
  15. package/lib/Feedback/Feedback.js +110 -0
  16. package/lib/Feedback/index.js +2 -0
  17. package/lib/Icon/Icon.js +1 -1
  18. package/lib/InputLabel/InputLabel.js +86 -0
  19. package/lib/InputLabel/LabelContent.native.js +8 -0
  20. package/lib/InputLabel/LabelContent.web.js +17 -0
  21. package/lib/InputLabel/index.js +2 -0
  22. package/lib/Link/LinkBase.js +9 -3
  23. package/lib/Spacer/Spacer.js +98 -0
  24. package/lib/Spacer/index.js +2 -0
  25. package/lib/StackView/StackView.js +105 -0
  26. package/lib/StackView/StackWrap.js +32 -0
  27. package/lib/StackView/StackWrap.native.js +3 -0
  28. package/lib/StackView/StackWrapBox.js +85 -0
  29. package/lib/StackView/StackWrapGap.js +45 -0
  30. package/lib/StackView/common.js +30 -0
  31. package/lib/StackView/getStackedContent.js +111 -0
  32. package/lib/StackView/index.js +5 -0
  33. package/lib/TextInput/TextInput.js +337 -0
  34. package/lib/TextInput/index.js +2 -0
  35. package/lib/Typography/Typography.js +0 -4
  36. package/lib/index.js +6 -1
  37. package/lib/utils/input.js +3 -1
  38. package/lib/utils/propTypes.js +9 -1
  39. package/lib/utils/useUniqueId.js +12 -0
  40. package/package.json +2 -2
  41. package/release-context.json +4 -4
  42. package/src/Box/Box.jsx +4 -2
  43. package/src/Button/ButtonBase.jsx +6 -18
  44. package/src/Button/ButtonGroup.jsx +13 -17
  45. package/src/Divider/Divider.jsx +38 -3
  46. package/src/Feedback/Feedback.jsx +99 -0
  47. package/src/Feedback/index.js +3 -0
  48. package/src/Icon/Icon.jsx +2 -1
  49. package/src/InputLabel/InputLabel.jsx +99 -0
  50. package/src/InputLabel/LabelContent.native.jsx +6 -0
  51. package/src/InputLabel/LabelContent.web.jsx +13 -0
  52. package/src/InputLabel/index.js +3 -0
  53. package/src/Link/LinkBase.jsx +9 -3
  54. package/src/Spacer/Spacer.jsx +91 -0
  55. package/src/Spacer/index.js +3 -0
  56. package/src/StackView/StackView.jsx +103 -0
  57. package/src/StackView/StackWrap.jsx +33 -0
  58. package/src/StackView/StackWrap.native.jsx +4 -0
  59. package/src/StackView/StackWrapBox.jsx +82 -0
  60. package/src/StackView/StackWrapGap.jsx +39 -0
  61. package/src/StackView/common.jsx +28 -0
  62. package/src/StackView/getStackedContent.jsx +106 -0
  63. package/src/StackView/index.js +6 -0
  64. package/src/TextInput/TextInput.jsx +325 -0
  65. package/src/TextInput/index.js +3 -0
  66. package/src/Typography/Typography.jsx +0 -4
  67. package/src/index.js +6 -1
  68. package/src/utils/input.js +2 -1
  69. package/src/utils/propTypes.js +9 -0
  70. package/src/utils/useUniqueId.js +14 -0
  71. package/stories/A11yText/A11yText.stories.jsx +11 -5
  72. package/stories/ActivityIndicator/ActivityIndicator.stories.jsx +11 -2
  73. package/stories/Box/Box.stories.jsx +29 -2
  74. package/stories/Button/Button.stories.jsx +17 -21
  75. package/stories/Button/ButtonGroup.stories.jsx +2 -1
  76. package/stories/Button/ButtonLink.stories.jsx +6 -4
  77. package/stories/Card/Card.stories.jsx +13 -1
  78. package/stories/Divider/Divider.stories.jsx +26 -2
  79. package/stories/ExpandCollapse/ExpandCollapse.stories.jsx +74 -79
  80. package/stories/Feedback/Feedback.stories.jsx +97 -0
  81. package/stories/FlexGrid/01 FlexGrid.stories.jsx +20 -7
  82. package/stories/Icon/Icon.stories.jsx +11 -3
  83. package/stories/InputLabel/InputLabel.stories.jsx +37 -0
  84. package/stories/Link/ChevronLink.stories.jsx +20 -4
  85. package/stories/Link/Link.stories.jsx +24 -2
  86. package/stories/Link/TextButton.stories.jsx +24 -2
  87. package/stories/Pagination/Pagination.stories.jsx +28 -14
  88. package/stories/SideNav/SideNav.stories.jsx +17 -2
  89. package/stories/Spacer/Spacer.stories.jsx +33 -0
  90. package/stories/StackView/StackView.stories.jsx +65 -0
  91. package/stories/StackView/StackWrap.stories.jsx +52 -0
  92. package/stories/TextInput/TextInput.stories.jsx +103 -0
  93. package/stories/ToggleSwitch/ToggleSwitch.stories.jsx +16 -3
  94. package/stories/Typography/Typography.stories.jsx +12 -3
  95. package/stories/platform-supports.web.jsx +1 -1
  96. package/stories/supports.jsx +109 -13
package/CHANGELOG.md CHANGED
@@ -2,6 +2,23 @@
2
2
 
3
3
  All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
4
4
 
5
+ ### [0.0.2-prerelease.5](https://github.com/telus/universal-design-system/compare/@telus-uds/components-base/v0.0.2-prerelease.4...@telus-uds/components-base/v0.0.2-prerelease.5) (2021-10-27)
6
+
7
+ ### Features
8
+
9
+ - **allium-web:** Add `ExpandCollapseMiniControl` component ([#661](https://github.com/telus/universal-design-system/issues/661)) ([227407e](https://github.com/telus/universal-design-system/commit/227407ec6a48c0a170b8e39761ba33293f13eb3c)), closes [#605](https://github.com/telus/universal-design-system/issues/605) [#605](https://github.com/telus/universal-design-system/issues/605) [#605](https://github.com/telus/universal-design-system/issues/605) [#605](https://github.com/telus/universal-design-system/issues/605) [#605](https://github.com/telus/universal-design-system/issues/605)
10
+ - **allium:** add Allium `Card` ([#639](https://github.com/telus/universal-design-system/issues/639)) ([f88179c](https://github.com/telus/universal-design-system/commit/f88179c503dfe574bf7bac6bb36ce4726a9af338))
11
+ - **base, allium:** add reverse directions and switch Allium card to using `StackView` ([#676](https://github.com/telus/universal-design-system/issues/676)) ([819a15f](https://github.com/telus/universal-design-system/commit/819a15f059faa47d1bc4e96c6370e9694effc003))
12
+ - **base:** add StackView and Spacer ([#662](https://github.com/telus/universal-design-system/issues/662)) ([cc3965e](https://github.com/telus/universal-design-system/commit/cc3965e83c1ec2fa0f0dd006a03eeeeda5384940))
13
+ - **base:** add StackWrap component ([#666](https://github.com/telus/universal-design-system/issues/666)) ([f34fb60](https://github.com/telus/universal-design-system/commit/f34fb60d0a923b1e4b3105c21b4a762b630ab309))
14
+ - **base:** add TextInput component ([#649](https://github.com/telus/universal-design-system/issues/649)) ([245c073](https://github.com/telus/universal-design-system/commit/245c073ed3ba3a022f989d234fbf5cf972edec25))
15
+ - **base:** add the Feedback component ([#656](https://github.com/telus/universal-design-system/issues/656)) ([5d7a5b6](https://github.com/telus/universal-design-system/commit/5d7a5b69c870ce1077adfdb230fddd1aa120b373))
16
+
17
+ ### Bug Fixes
18
+
19
+ - **base:** control stretch from a row parent ([#668](https://github.com/telus/universal-design-system/issues/668)) ([fa13c37](https://github.com/telus/universal-design-system/commit/fa13c37b2bd6b4118dbeb39bc2cdf59d13d5b151))
20
+ - **base:** fix icon link width in block container ([#645](https://github.com/telus/universal-design-system/issues/645)) ([ff60d1d](https://github.com/telus/universal-design-system/commit/ff60d1d1d0a66b7735b902098c7ca22e442265e1))
21
+
5
22
  ### [0.0.2-prerelease.4](https://github.com/telus/universal-design-system/compare/@telus-uds/components-base/v0.0.2-prerelease.3...@telus-uds/components-base/v0.0.2-prerelease.4) (2021-10-13)
6
23
 
7
24
  ### Bug Fixes
@@ -2,7 +2,9 @@ const {
2
2
  buttonAppearances,
3
3
  linkAppearances,
4
4
  sideNavItemAppearances,
5
- toggleSwitchAppearances
5
+ toggleSwitchAppearances,
6
+ textInputAppearances,
7
+ feedbackAppearances
6
8
  } = require('@telus-uds/tools-theme')
7
9
  const { appearances: systemAppearances } = require('@telus-uds/system-constants')
8
10
 
@@ -137,12 +139,7 @@ module.exports = {
137
139
  paddingTop: 8,
138
140
  paddingBottom: 8,
139
141
 
140
- width: null,
141
-
142
- marginLeft: 0,
143
- marginRight: 0,
144
- marginTop: 0,
145
- marginBottom: 0
142
+ width: null
146
143
  },
147
144
  rules: [
148
145
  {
@@ -504,8 +501,6 @@ module.exports = {
504
501
  fontSize: 16,
505
502
  color: '#2c2e30',
506
503
  lineHeight: 1.5,
507
- marginTop: 8,
508
- marginBottom: 8,
509
504
  fontScaleCap: 64
510
505
  },
511
506
  rules: [
@@ -739,8 +734,6 @@ module.exports = {
739
734
  blockFontWeight: '400',
740
735
  blockFontSize: 16,
741
736
  blockLineHeight: 1.5,
742
- blockMarginTop: 8,
743
- blockMarginBottom: 8,
744
737
 
745
738
  outerBorderColor: transparent,
746
739
  outerBorderOutline: 'none',
@@ -849,6 +842,9 @@ module.exports = {
849
842
  ]
850
843
  },
851
844
  SideNavItemsGroup: {},
845
+ StackView: {
846
+ tokens: {}
847
+ },
852
848
  ToggleSwitch: {
853
849
  appearances: {
854
850
  focus: toggleSwitchAppearances.focus,
@@ -923,6 +919,82 @@ module.exports = {
923
919
  tokens: { opacity: 0.4 }
924
920
  }
925
921
  ]
922
+ },
923
+ TextInput: {
924
+ appearances: {
925
+ ...textInputAppearances
926
+ },
927
+ tokens: {
928
+ borderRadius: 4,
929
+ borderWidth: 1,
930
+ borderColor: '#00000044',
931
+ paddingTop: 6,
932
+ paddingBottom: 6,
933
+ paddingLeft: 6,
934
+ paddingRight: 6,
935
+ outerBorderWidth: 1,
936
+ outerBorderColor: transparent,
937
+ outerBorderRadius: 4
938
+ },
939
+ rules: [
940
+ {
941
+ if: { validation: 'success' },
942
+ tokens: {
943
+ outerBorderColor: '#99ff99'
944
+ }
945
+ },
946
+ {
947
+ if: { validation: 'error' },
948
+ tokens: {
949
+ outerBorderColor: '#990000'
950
+ }
951
+ },
952
+ {
953
+ if: { focus: true },
954
+ tokens: {
955
+ outerBorderColor: '#debc06'
956
+ }
957
+ },
958
+ {
959
+ if: { hover: true },
960
+ tokens: {
961
+ outerBorderColor: '#6666cc'
962
+ }
963
+ },
964
+ {
965
+ if: { inactive: true },
966
+ tokens: {
967
+ outerBorderColor: transparent,
968
+ backgroundColor: '#00000044'
969
+ }
970
+ }
971
+ ]
972
+ },
973
+ InputLabel: {
974
+ tokens: {
975
+ gap: 20,
976
+ hintFontSize: 12
977
+ }
978
+ },
979
+ Feedback: {
980
+ appearances: {
981
+ ...feedbackAppearances
982
+ },
983
+ tokens: {
984
+ borderColor: '#eee',
985
+ borderWidth: 1,
986
+ borderRadius: 3,
987
+ titleFontSize: 16,
988
+ contentFontSize: 14,
989
+ paddingTop: 12,
990
+ paddingBottom: 12,
991
+ paddingLeft: 12,
992
+ paddingRight: 12
993
+ },
994
+ rules: [
995
+ { if: { state: 'success' }, tokens: { color: 'green' } },
996
+ { if: { state: 'error' }, tokens: { color: 'red' } }
997
+ ]
926
998
  }
927
999
  }
928
1000
  }
@@ -41,17 +41,38 @@ describe('Divider', () => {
41
41
  expect(divider).not.toHaveStyle(verticalStyles)
42
42
  })
43
43
 
44
- it('renders a vertical line when vertical prop is passed', () => {
44
+ it('renders space above and below a horizontal line if space prop is passed', () => {
45
+ const expectedSize = 8 // from testTheme.js
46
+
45
47
  const { getByTestId } = render(
46
48
  <Theme>
47
49
  <Text>Before</Text>
48
- <Divider vertical testID={testID} />
50
+ <Divider testID={testID} space={2} />
49
51
  <Text>After</Text>
50
52
  </Theme>
51
53
  )
52
- const divider = getByTestId(testID)
53
- expect(divider).toHaveStyle(verticalStyles)
54
- expect(divider).not.toHaveStyle(horizontalStyles)
54
+ const before = getByTestId(`${testID}-Spacer-before`)
55
+ expect(before).toHaveStyle({ height: expectedSize })
56
+
57
+ const after = getByTestId(`${testID}-Spacer-after`)
58
+ expect(after).toHaveStyle({ height: expectedSize })
59
+ })
60
+
61
+ it('renders space left and right of a vertical line if space prop is passed', () => {
62
+ const expectedSize = 8 // from testTheme.js
63
+
64
+ const { getByTestId } = render(
65
+ <Theme>
66
+ <Text>Before</Text>
67
+ <Divider vertical testID={testID} space={2} />
68
+ <Text>After</Text>
69
+ </Theme>
70
+ )
71
+ const before = getByTestId(`${testID}-Spacer-before`)
72
+ expect(before).toHaveStyle({ width: expectedSize })
73
+
74
+ const after = getByTestId(`${testID}-Spacer-after`)
75
+ expect(after).toHaveStyle({ width: expectedSize })
55
76
  })
56
77
 
57
78
  it('renders the correct styles for a given variant', () => {
@@ -0,0 +1,42 @@
1
+ import React from 'react'
2
+ import { Text } from 'react-native'
3
+ import { render } from '@testing-library/react-native'
4
+
5
+ import Feedback from '../../src/Feedback'
6
+ import Theme from '../../__fixtures__/Theme'
7
+
8
+ describe('Feedback', () => {
9
+ it('renders title', () => {
10
+ const { queryByText } = render(<Feedback title="Test title" />, { wrapper: Theme })
11
+
12
+ expect(queryByText('Test title')).toBeTruthy()
13
+ })
14
+
15
+ it('renders content when passed a string', () => {
16
+ const { queryByText } = render(<Feedback>Test content</Feedback>, { wrapper: Theme })
17
+
18
+ expect(queryByText('Test content')).toBeTruthy()
19
+ })
20
+
21
+ it('renders content when passed a React element', () => {
22
+ const { queryByText } = render(
23
+ <Feedback>
24
+ <Text>Test content</Text>
25
+ </Feedback>,
26
+ { wrapper: Theme }
27
+ )
28
+
29
+ expect(queryByText('Test content')).toBeTruthy()
30
+ })
31
+
32
+ it("renders content with theme's style prop when passed a function", () => {
33
+ const { getByText } = render(
34
+ <Feedback>{({ textStyles }) => <Text style={textStyles}>Test content</Text>}</Feedback>,
35
+ {
36
+ wrapper: Theme
37
+ }
38
+ )
39
+
40
+ expect(getByText('Test content')).toHaveStyle({ fontSize: 14 })
41
+ })
42
+ })
@@ -0,0 +1,63 @@
1
+ import React from 'react'
2
+ import { render } from '@testing-library/react-native'
3
+
4
+ import { Spacer } from '../../src'
5
+ import Theme from '../../__fixtures__/Theme'
6
+
7
+ const testID = 'spacer'
8
+
9
+ describe('Spacer', () => {
10
+ it('has smallest size from spacing scale by default', () => {
11
+ const expectedSize = 4 // from __fixtures__/testTheme.js
12
+ const { getByTestId } = render(<Spacer testID={testID} />, { wrapper: Theme })
13
+ expect(getByTestId(testID)).toHaveStyle({
14
+ height: expectedSize
15
+ })
16
+ })
17
+
18
+ it('has size from spacing scale if space prop passed', () => {
19
+ const expectedSize = 8 // from __fixtures__/testTheme.js
20
+ const { getByTestId } = render(<Spacer space={2} testID={testID} />, { wrapper: Theme })
21
+ expect(getByTestId(testID)).toHaveStyle({
22
+ height: expectedSize
23
+ })
24
+ })
25
+
26
+ it('has no size if 0 passed in', () => {
27
+ const expectedSize = 0
28
+ const { getByTestId } = render(<Spacer space={0} testID={testID} />, { wrapper: Theme })
29
+ expect(getByTestId(testID)).toHaveStyle({
30
+ height: expectedSize
31
+ })
32
+ })
33
+ })
34
+
35
+ describe('Spacer (row)', () => {
36
+ it('has smallest size from spacing scale by default', () => {
37
+ const expectedSize = 4 // from __fixtures__/testTheme.js
38
+ const { getByTestId } = render(<Spacer testID={testID} direction="row" />, { wrapper: Theme })
39
+ expect(getByTestId(testID)).toHaveStyle({
40
+ width: expectedSize
41
+ })
42
+ })
43
+
44
+ it('has size from spacing scale if space prop passed', () => {
45
+ const expectedSize = 8 // from __fixtures__/testTheme.js
46
+ const { getByTestId } = render(<Spacer space={2} testID={testID} direction="row" />, {
47
+ wrapper: Theme
48
+ })
49
+ expect(getByTestId(testID)).toHaveStyle({
50
+ width: expectedSize
51
+ })
52
+ })
53
+
54
+ it('has no size if 0 passed in', () => {
55
+ const expectedSize = 0
56
+ const { getByTestId } = render(<Spacer space={0} testID={testID} direction="row" />, {
57
+ wrapper: Theme
58
+ })
59
+ expect(getByTestId(testID)).toHaveStyle({
60
+ width: expectedSize
61
+ })
62
+ })
63
+ })
@@ -0,0 +1,242 @@
1
+ import React from 'react'
2
+ import { View } from 'react-native'
3
+ import { render } from '@testing-library/react-native'
4
+
5
+ import { Spacer, StackView, Typography } from '../../src'
6
+ import Theme from '../../__fixtures__/Theme'
7
+ import testTheme from '../../__fixtures__/testTheme'
8
+
9
+ const getFirstAncestorAboveType = (element, ComponentType) => {
10
+ if (element.type === ComponentType) return element.parent
11
+ if (element.parent) return getFirstAncestorAboveType(element.parent, ComponentType)
12
+ return null
13
+ }
14
+
15
+ describe('StackView', () => {
16
+ it('renders separators and children as direct children of a flex column by default', () => {
17
+ const expectedStyle = { flexDirection: 'column' }
18
+
19
+ const { getByTestId } = render(
20
+ <StackView space={2}>
21
+ <Typography>A</Typography>
22
+ <Typography>B</Typography>
23
+ </StackView>,
24
+ { wrapper: Theme }
25
+ )
26
+ const parent = getFirstAncestorAboveType(getByTestId('Stack-Spacer-1'), Spacer)
27
+ expect(parent.type).toBe('View')
28
+ expect(parent).toHaveStyle(expectedStyle)
29
+ })
30
+
31
+ it('renders separators and children as direct children of a flex column if direction is "column-reverse"', () => {
32
+ const expectedStyle = { flexDirection: 'column-reverse' }
33
+
34
+ const { getByTestId } = render(
35
+ <StackView direction="column-reverse" space={2}>
36
+ <Typography>A</Typography>
37
+ <Typography>B</Typography>
38
+ </StackView>,
39
+ { wrapper: Theme }
40
+ )
41
+ const parent = getFirstAncestorAboveType(getByTestId('Stack-Spacer-1'), Spacer)
42
+ expect(parent.type).toBe('View')
43
+ expect(parent).toHaveStyle(expectedStyle)
44
+ })
45
+
46
+ it('renders separators and children as direct children of a flex row if direction is "row"', () => {
47
+ const expectedStyle = { flexDirection: 'row' }
48
+
49
+ const { getByTestId } = render(
50
+ <StackView direction="row" space={2}>
51
+ <Typography>A</Typography>
52
+ <Typography>B</Typography>
53
+ </StackView>,
54
+ { wrapper: Theme }
55
+ )
56
+ const parent = getFirstAncestorAboveType(getByTestId('Stack-Spacer-1'), Spacer)
57
+ expect(parent.type).toBe('View')
58
+ expect(parent).toHaveStyle(expectedStyle)
59
+ })
60
+
61
+ it('renders separators and children as direct children of a flex row if direction is "row-reverse"', () => {
62
+ const expectedStyle = { flexDirection: 'row-reverse' }
63
+
64
+ const { getByTestId } = render(
65
+ <StackView direction="row-reverse" space={2}>
66
+ <Typography>A</Typography>
67
+ <Typography>B</Typography>
68
+ </StackView>,
69
+ { wrapper: Theme }
70
+ )
71
+ const parent = getFirstAncestorAboveType(getByTestId('Stack-Spacer-1'), Spacer)
72
+ expect(parent.type).toBe('View')
73
+ expect(parent).toHaveStyle(expectedStyle)
74
+ })
75
+
76
+ it('renders separators and children as direct children of parent if "inherit" is set', () => {
77
+ // Some arbitrary custom style we apply to the parent
78
+ const expectedStyle = { color: '#012345', flexBasis: 12345 }
79
+
80
+ const { getByTestId } = render(
81
+ <View style={expectedStyle}>
82
+ <StackView inherit>
83
+ <Typography>A</Typography>
84
+ <Typography>B</Typography>
85
+ </StackView>
86
+ </View>,
87
+ { wrapper: Theme }
88
+ )
89
+ const parent = getFirstAncestorAboveType(getByTestId('Stack-Spacer-1'), Spacer)
90
+ // Expect an empty StackView fiber node with no styles of its own
91
+ expect(parent.type).toBe(StackView)
92
+ expect(parent).not.toHaveStyle({ flexDirection: 'column' })
93
+ expect(parent).not.toHaveStyle({ flexDirection: 'row' })
94
+
95
+ // Expect next parent to be a rendered View with styles
96
+ const renderedParent = getFirstAncestorAboveType(parent, StackView)
97
+ expect(renderedParent.type).toBe('View')
98
+ expect(renderedParent).toHaveStyle(expectedStyle)
99
+ })
100
+
101
+ it('renders horizontal dividers by default', () => {
102
+ const expectedSize = 4 // from __fixtures__/testTheme.js
103
+ const expectedStyle = { height: expectedSize }
104
+ const { color } = testTheme.components.Divider.tokens
105
+
106
+ const { getByTestId } = render(
107
+ <StackView divider>
108
+ <Typography>A</Typography>
109
+ <Typography>B</Typography>
110
+ <Typography>C</Typography>
111
+ </StackView>,
112
+ { wrapper: Theme }
113
+ )
114
+
115
+ expect(getByTestId('Stack-Divider-1')).toHaveStyle({ borderBottomColor: color })
116
+ expect(getByTestId('Stack-Divider-2')).toHaveStyle({ borderBottomColor: color })
117
+
118
+ expect(getByTestId('Stack-Divider-1')).not.toHaveStyle({ borderRightColor: color })
119
+ expect(getByTestId('Stack-Divider-2')).not.toHaveStyle({ borderRightColor: color })
120
+
121
+ expect(getByTestId('Stack-Divider-1-Spacer-before')).toHaveStyle(expectedStyle)
122
+ expect(getByTestId('Stack-Divider-1-Spacer-after')).toHaveStyle(expectedStyle)
123
+ expect(getByTestId('Stack-Divider-2-Spacer-before')).toHaveStyle(expectedStyle)
124
+ expect(getByTestId('Stack-Divider-2-Spacer-after')).toHaveStyle(expectedStyle)
125
+ })
126
+
127
+ it('renders horizontal dividers if direction is "column-reverse"', () => {
128
+ const expectedSize = 4 // from __fixtures__/testTheme.js
129
+ const expectedStyle = { height: expectedSize }
130
+ const { color } = testTheme.components.Divider.tokens
131
+
132
+ const { getByTestId } = render(
133
+ <StackView direction="column-reverse" divider>
134
+ <Typography>A</Typography>
135
+ <Typography>B</Typography>
136
+ <Typography>C</Typography>
137
+ </StackView>,
138
+ { wrapper: Theme }
139
+ )
140
+
141
+ expect(getByTestId('Stack-Divider-1')).toHaveStyle({ borderBottomColor: color })
142
+ expect(getByTestId('Stack-Divider-2')).toHaveStyle({ borderBottomColor: color })
143
+
144
+ expect(getByTestId('Stack-Divider-1')).not.toHaveStyle({ borderRightColor: color })
145
+ expect(getByTestId('Stack-Divider-2')).not.toHaveStyle({ borderRightColor: color })
146
+
147
+ expect(getByTestId('Stack-Divider-1-Spacer-before')).toHaveStyle(expectedStyle)
148
+ expect(getByTestId('Stack-Divider-1-Spacer-after')).toHaveStyle(expectedStyle)
149
+ expect(getByTestId('Stack-Divider-2-Spacer-before')).toHaveStyle(expectedStyle)
150
+ expect(getByTestId('Stack-Divider-2-Spacer-after')).toHaveStyle(expectedStyle)
151
+ })
152
+
153
+ it('renders vertical dividers if direction is "row"', () => {
154
+ const { color } = testTheme.components.Divider.tokens
155
+ const expectedSize = 4 // from __fixtures__/testTheme.js
156
+ const expectedStyle = { width: expectedSize }
157
+
158
+ const { getByTestId } = render(
159
+ <StackView divider direction="row">
160
+ <Typography>A</Typography>
161
+ <Typography>B</Typography>
162
+ <Typography>C</Typography>
163
+ </StackView>,
164
+ { wrapper: Theme }
165
+ )
166
+
167
+ expect(getByTestId('Stack-Divider-1')).not.toHaveStyle({ borderBottomColor: color })
168
+ expect(getByTestId('Stack-Divider-2')).not.toHaveStyle({ borderBottomColor: color })
169
+
170
+ expect(getByTestId('Stack-Divider-1')).toHaveStyle({ borderRightColor: color })
171
+ expect(getByTestId('Stack-Divider-2')).toHaveStyle({ borderRightColor: color })
172
+
173
+ expect(getByTestId('Stack-Divider-1-Spacer-before')).toHaveStyle(expectedStyle)
174
+ expect(getByTestId('Stack-Divider-1-Spacer-after')).toHaveStyle(expectedStyle)
175
+ expect(getByTestId('Stack-Divider-2-Spacer-before')).toHaveStyle(expectedStyle)
176
+ expect(getByTestId('Stack-Divider-2-Spacer-after')).toHaveStyle(expectedStyle)
177
+ })
178
+
179
+ it('renders vertical dividers if direction is "row-reverse"', () => {
180
+ const { color } = testTheme.components.Divider.tokens
181
+ const expectedSize = 4 // from __fixtures__/testTheme.js
182
+ const expectedStyle = { width: expectedSize }
183
+
184
+ const { getByTestId } = render(
185
+ <StackView divider direction="row-reverse">
186
+ <Typography>A</Typography>
187
+ <Typography>B</Typography>
188
+ <Typography>C</Typography>
189
+ </StackView>,
190
+ { wrapper: Theme }
191
+ )
192
+
193
+ expect(getByTestId('Stack-Divider-1')).not.toHaveStyle({ borderBottomColor: color })
194
+ expect(getByTestId('Stack-Divider-2')).not.toHaveStyle({ borderBottomColor: color })
195
+
196
+ expect(getByTestId('Stack-Divider-1')).toHaveStyle({ borderRightColor: color })
197
+ expect(getByTestId('Stack-Divider-2')).toHaveStyle({ borderRightColor: color })
198
+
199
+ expect(getByTestId('Stack-Divider-1-Spacer-before')).toHaveStyle(expectedStyle)
200
+ expect(getByTestId('Stack-Divider-1-Spacer-after')).toHaveStyle(expectedStyle)
201
+ expect(getByTestId('Stack-Divider-2-Spacer-before')).toHaveStyle(expectedStyle)
202
+ expect(getByTestId('Stack-Divider-2-Spacer-after')).toHaveStyle(expectedStyle)
203
+ })
204
+
205
+ it('renders row spacers if direction is "row"', () => {
206
+ const expectedSize = 8 // from __fixtures__/testTheme.js
207
+
208
+ const { getByTestId } = render(
209
+ <StackView direction="row" space={2}>
210
+ <Typography>A</Typography>
211
+ <Typography>B</Typography>
212
+ <Typography>C</Typography>
213
+ </StackView>,
214
+ { wrapper: Theme }
215
+ )
216
+
217
+ expect(getByTestId('Stack-Spacer-1')).not.toHaveStyle({ height: expectedSize })
218
+ expect(getByTestId('Stack-Spacer-2')).not.toHaveStyle({ height: expectedSize })
219
+
220
+ expect(getByTestId('Stack-Spacer-1')).toHaveStyle({ width: expectedSize })
221
+ expect(getByTestId('Stack-Spacer-2')).toHaveStyle({ width: expectedSize })
222
+ })
223
+
224
+ it('renders row spacers if direction is "row-reverse"', () => {
225
+ const expectedSize = 8 // from __fixtures__/testTheme.js
226
+
227
+ const { getByTestId } = render(
228
+ <StackView direction="row-reverse" space={2}>
229
+ <Typography>A</Typography>
230
+ <Typography>B</Typography>
231
+ <Typography>C</Typography>
232
+ </StackView>,
233
+ { wrapper: Theme }
234
+ )
235
+
236
+ expect(getByTestId('Stack-Spacer-1')).not.toHaveStyle({ height: expectedSize })
237
+ expect(getByTestId('Stack-Spacer-2')).not.toHaveStyle({ height: expectedSize })
238
+
239
+ expect(getByTestId('Stack-Spacer-1')).toHaveStyle({ width: expectedSize })
240
+ expect(getByTestId('Stack-Spacer-2')).toHaveStyle({ width: expectedSize })
241
+ })
242
+ })
@@ -0,0 +1,47 @@
1
+ import React from 'react'
2
+ import { render } from '@testing-library/react-native'
3
+
4
+ import { StackWrap, Typography } from '../../src'
5
+ import Theme from '../../__fixtures__/Theme'
6
+
7
+ describe('StackWrap', () => {
8
+ it('renders no spacers (because they would wrap badly)', () => {
9
+ const { queryAllByTestId } = render(
10
+ <StackWrap space={2}>
11
+ <Typography>A</Typography>
12
+ <Typography>B</Typography>
13
+ <Typography>C</Typography>
14
+ </StackWrap>,
15
+ { wrapper: Theme }
16
+ )
17
+ expect(queryAllByTestId(/Spacer/)).toHaveLength(0)
18
+ })
19
+
20
+ it('puts a `gap` between lines which may be different to `space` between items', () => {
21
+ // This test unavoidably hangs on some implementation details,
22
+ // which isn't ideal, but it does test something a user would see.
23
+ const expectedStyle = { paddingBottom: 8, paddingRight: 4 }
24
+
25
+ const { getByTestId } = render(
26
+ <StackWrap space={1} gap={2}>
27
+ <Typography>A</Typography>
28
+ <Typography>B</Typography>
29
+ </StackWrap>,
30
+ { wrapper: Theme }
31
+ )
32
+ expect(getByTestId('Stack-Box-1')).toHaveStyle(expectedStyle)
33
+ })
34
+
35
+ it('accepts accessibility props on the container responsible for wrapping content', () => {
36
+ const expectedStyle = { flexWrap: 'wrap' }
37
+
38
+ const { getByRole } = render(
39
+ <StackWrap accessibilityRole="radiogroup">
40
+ <Typography>A</Typography>
41
+ <Typography>B</Typography>
42
+ </StackWrap>,
43
+ { wrapper: Theme }
44
+ )
45
+ expect(getByRole('radiogroup')).toHaveStyle(expectedStyle)
46
+ })
47
+ })