@telus-uds/components-base 1.4.0 → 1.6.1

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 (110) hide show
  1. package/.turbo/turbo-build.log +8 -8
  2. package/.turbo/turbo-lint.log +13 -0
  3. package/CHANGELOG.json +140 -1
  4. package/CHANGELOG.md +42 -2
  5. package/__tests__/FlexGrid/Row.test.jsx +100 -25
  6. package/__tests__/utils/containUniqueFields.test.js +25 -0
  7. package/component-docs.json +94 -16
  8. package/generate-component-docs.js +20 -7
  9. package/lib/Button/ButtonBase.js +1 -1
  10. package/lib/Button/ButtonGroup.js +20 -12
  11. package/lib/Card/PressableCardBase.js +1 -1
  12. package/lib/Checkbox/Checkbox.js +27 -16
  13. package/lib/Checkbox/CheckboxGroup.js +19 -5
  14. package/lib/ExpandCollapse/Panel.js +10 -10
  15. package/lib/FlexGrid/Col/Col.js +13 -3
  16. package/lib/FlexGrid/Row/Row.js +8 -2
  17. package/lib/HorizontalScroll/HorizontalScroll.js +0 -1
  18. package/lib/HorizontalScroll/HorizontalScrollButton.js +23 -49
  19. package/lib/InputLabel/InputLabel.js +27 -25
  20. package/lib/Link/LinkBase.js +19 -6
  21. package/lib/Link/TextButton.js +1 -10
  22. package/lib/Modal/Modal.js +18 -18
  23. package/lib/Radio/Radio.js +23 -12
  24. package/lib/Radio/RadioGroup.js +12 -3
  25. package/lib/RadioCard/RadioCard.js +1 -1
  26. package/lib/RadioCard/RadioCardGroup.js +11 -2
  27. package/lib/Select/Select.js +2 -3
  28. package/lib/Tags/Tags.js +23 -17
  29. package/lib/TextInput/TextArea.js +2 -2
  30. package/lib/TextInput/TextInput.js +12 -2
  31. package/lib/TextInput/TextInputBase.js +1 -1
  32. package/lib/TextInput/propTypes.js +8 -1
  33. package/lib/ToggleSwitch/ToggleSwitch.js +5 -2
  34. package/lib/ToggleSwitch/ToggleSwitchGroup.js +20 -12
  35. package/lib/utils/containUniqueFields.js +34 -0
  36. package/lib/utils/index.js +10 -1
  37. package/lib/utils/props/handlerProps.js +72 -0
  38. package/lib/utils/props/index.js +14 -0
  39. package/lib/utils/props/inputSupportsProps.js +3 -5
  40. package/lib/utils/props/linkProps.js +3 -7
  41. package/lib-module/Button/ButtonBase.js +2 -2
  42. package/lib-module/Button/ButtonGroup.js +15 -6
  43. package/lib-module/Card/PressableCardBase.js +2 -2
  44. package/lib-module/Checkbox/Checkbox.js +28 -17
  45. package/lib-module/Checkbox/CheckboxGroup.js +20 -7
  46. package/lib-module/ExpandCollapse/Panel.js +10 -10
  47. package/lib-module/FlexGrid/Col/Col.js +13 -3
  48. package/lib-module/FlexGrid/Row/Row.js +8 -2
  49. package/lib-module/HorizontalScroll/HorizontalScroll.js +0 -1
  50. package/lib-module/HorizontalScroll/HorizontalScrollButton.js +24 -49
  51. package/lib-module/InputLabel/InputLabel.js +28 -25
  52. package/lib-module/Link/LinkBase.js +19 -6
  53. package/lib-module/Link/TextButton.js +1 -10
  54. package/lib-module/Modal/Modal.js +19 -19
  55. package/lib-module/Radio/Radio.js +24 -13
  56. package/lib-module/Radio/RadioGroup.js +13 -4
  57. package/lib-module/RadioCard/RadioCard.js +2 -2
  58. package/lib-module/RadioCard/RadioCardGroup.js +12 -3
  59. package/lib-module/Select/Select.js +2 -3
  60. package/lib-module/Tags/Tags.js +18 -11
  61. package/lib-module/TextInput/TextArea.js +3 -3
  62. package/lib-module/TextInput/TextInput.js +11 -3
  63. package/lib-module/TextInput/TextInputBase.js +2 -2
  64. package/lib-module/TextInput/propTypes.js +7 -1
  65. package/lib-module/ToggleSwitch/ToggleSwitch.js +6 -3
  66. package/lib-module/ToggleSwitch/ToggleSwitchGroup.js +15 -6
  67. package/lib-module/utils/containUniqueFields.js +26 -0
  68. package/lib-module/utils/index.js +2 -1
  69. package/lib-module/utils/props/handlerProps.js +59 -0
  70. package/lib-module/utils/props/index.js +1 -0
  71. package/lib-module/utils/props/inputSupportsProps.js +3 -5
  72. package/lib-module/utils/props/linkProps.js +3 -7
  73. package/package.json +5 -5
  74. package/src/Button/ButtonBase.jsx +8 -2
  75. package/src/Button/ButtonGroup.jsx +51 -34
  76. package/src/Card/PressableCardBase.jsx +6 -1
  77. package/src/Checkbox/Checkbox.jsx +35 -23
  78. package/src/Checkbox/CheckboxGroup.jsx +52 -22
  79. package/src/ExpandCollapse/Panel.jsx +9 -9
  80. package/src/FlexGrid/Col/Col.jsx +11 -2
  81. package/src/FlexGrid/Row/Row.jsx +8 -2
  82. package/src/HorizontalScroll/HorizontalScroll.jsx +1 -1
  83. package/src/HorizontalScroll/HorizontalScrollButton.jsx +21 -58
  84. package/src/InputLabel/InputLabel.jsx +36 -27
  85. package/src/Link/LinkBase.jsx +20 -4
  86. package/src/Link/TextButton.jsx +1 -19
  87. package/src/Modal/Modal.jsx +30 -26
  88. package/src/Radio/Radio.jsx +26 -14
  89. package/src/Radio/RadioGroup.jsx +39 -21
  90. package/src/RadioCard/RadioCard.jsx +6 -1
  91. package/src/RadioCard/RadioCardGroup.jsx +17 -1
  92. package/src/Select/Select.jsx +2 -2
  93. package/src/Tags/Tags.jsx +23 -9
  94. package/src/TextInput/TextArea.jsx +5 -1
  95. package/src/TextInput/TextInput.jsx +13 -3
  96. package/src/TextInput/TextInputBase.jsx +6 -1
  97. package/src/TextInput/propTypes.js +7 -1
  98. package/src/ToggleSwitch/ToggleSwitch.jsx +11 -2
  99. package/src/ToggleSwitch/ToggleSwitchGroup.jsx +19 -6
  100. package/src/utils/containUniqueFields.js +32 -0
  101. package/src/utils/index.js +1 -0
  102. package/src/utils/props/handlerProps.js +47 -0
  103. package/src/utils/props/index.js +1 -0
  104. package/src/utils/props/inputSupportsProps.js +3 -4
  105. package/src/utils/props/linkProps.js +3 -6
  106. package/stories/InputLabel/InputLabel.stories.jsx +25 -28
  107. package/stories/Modal/Modal.stories.jsx +25 -0
  108. package/stories/Search/Search.stories.jsx +4 -1
  109. package/stories/TextInput/TextInput.stories.jsx +40 -2
  110. package/__tests__/Link/LinkBase.test.jsx +0 -22
@@ -22,16 +22,13 @@ export default {
22
22
  */
23
23
  select: getPropSelector(linkPropTypes),
24
24
  /**
25
- * Turn hrefs into press handlers on Native and throw if not given `onPress` or `href`.
25
+ * Turn hrefs into press handlers that open links on Native.
26
26
  *
27
27
  * @param {({ onPress?: () => void, href?: string })}
28
- * @returns {(() => void)|undefined} Returns a press handler, or undefined on web if href
29
- * string is provided. Expects calling component to use href string on web (e.g. in `<a>`).
28
+ * @returns {(() => void)|undefined} Returns a press handler, or undefined on web if no press
29
+ * handler is provided (expects calling component to render as `<a href={href}>` on web).
30
30
  */
31
31
  handleHref: ({ onPress, href }) => {
32
- if (!href && !onPress) {
33
- throw new Error('handleHref requires either href or onPress')
34
- }
35
32
  return Platform.select({
36
33
  web: onPress,
37
34
  default: (...args) => {
@@ -8,35 +8,32 @@ export default {
8
8
  component: InputLabel
9
9
  }
10
10
 
11
- export const Default = () => <InputLabel label="Test label" />
11
+ export const Default = (args) => <InputLabel {...args} />
12
+ Default.args = { label: 'Test label' }
12
13
 
13
- export const HintInline = () => (
14
- <InputLabel label="Test label" hint="Short hint" hintPosition="inline" />
15
- )
14
+ export const HintInline = (args) => <InputLabel {...args} />
15
+ HintInline.args = { label: 'Test label', hint: 'Short hint', hintPosition: 'inline' }
16
16
 
17
- export const HintAndTooltip = () => (
18
- <InputLabel
19
- label="Test label"
20
- hint="Short hint"
21
- hintPosition="inline"
22
- tooltip="This is the tooltip's content"
23
- />
24
- )
17
+ export const HintAndTooltip = (args) => <InputLabel {...args} />
18
+ HintAndTooltip.args = {
19
+ label: 'Test label',
20
+ hint: 'Short hint',
21
+ hintPosition: 'inline',
22
+ tooltip: "This is the tooltip's content"
23
+ }
25
24
 
26
- export const HintInlineLong = () => (
27
- <InputLabel
28
- label="Test label"
29
- hint="A rather long hint that won't actually fit"
30
- hintPosition="inline"
31
- tooltip="This is the tooltip's content"
32
- />
33
- )
25
+ export const HintInlineLong = (args) => <InputLabel {...args} />
26
+ HintInlineLong.args = {
27
+ label: 'Test label',
28
+ hint: "A rather long hint that won't actually fit",
29
+ hintPosition: 'inline',
30
+ tooltip: "This is the tooltip's content"
31
+ }
34
32
 
35
- export const HintBelow = () => (
36
- <InputLabel
37
- label="Test label"
38
- hint="A rather long hint that won't actually fit"
39
- hintPosition="below"
40
- tooltip="This is the tooltip's content"
41
- />
42
- )
33
+ export const HintBelow = (args) => <InputLabel {...args} />
34
+ HintBelow.args = {
35
+ label: 'Test label',
36
+ hint: "A rather long hint that won't actually fit",
37
+ hintPosition: 'below',
38
+ tooltip: "This is the tooltip's content"
39
+ }
@@ -10,6 +10,8 @@ export default {
10
10
  export const Default = (args) => {
11
11
  const [isOpen, setIsOpen] = useState(false)
12
12
  const [isMaxWidthOpen, setIsMaxWidthOpen] = useState(false)
13
+ const [isCustomCloseOpen, setIsCustomCloseOpen] = useState(false)
14
+ const [isNoCloseOpen, setIsNoCloseOpen] = useState(false)
13
15
 
14
16
  return (
15
17
  <>
@@ -23,6 +25,29 @@ export const Default = (args) => {
23
25
  <Typography variant={{ size: 'h2' }}>Test heading</Typography>
24
26
  <Typography>Test content</Typography>
25
27
  </Modal>
28
+ <Spacer space={3} />
29
+ <Button onPress={() => setIsCustomCloseOpen(true)}>Open custom close button modal</Button>
30
+ <Modal
31
+ {...args}
32
+ isOpen={isCustomCloseOpen}
33
+ onClose={() => setIsCustomCloseOpen(false)}
34
+ closeButton={<Button onPress={() => setIsCustomCloseOpen(false)}>Close</Button>}
35
+ >
36
+ <Typography variant={{ size: 'h2' }}>Test heading</Typography>
37
+ <Typography>Test content</Typography>
38
+ </Modal>
39
+ <Spacer space={3} />
40
+ <Button onPress={() => setIsNoCloseOpen(true)}>Open modal without close button</Button>
41
+ <Modal
42
+ {...args}
43
+ isOpen={isNoCloseOpen}
44
+ onClose={() => setIsNoCloseOpen(false)}
45
+ closeButton={null}
46
+ >
47
+ <Typography variant={{ size: 'h2' }}>Test heading</Typography>
48
+ <Typography>A custom close button is added in the modal content.</Typography>
49
+ <Button onPress={() => setIsNoCloseOpen(false)}>Close</Button>
50
+ </Modal>
26
51
  </>
27
52
  )
28
53
  }
@@ -4,7 +4,10 @@ import { Search } from '../../src'
4
4
 
5
5
  export default {
6
6
  title: 'Search',
7
- component: Search
7
+ component: Search,
8
+ argTypes: {
9
+ onSubmit: { action: 'submitted' }
10
+ }
8
11
  }
9
12
 
10
13
  const Template = (args) => <Search {...args} />
@@ -1,6 +1,7 @@
1
- import React, { useEffect, useState } from 'react'
1
+ import React, { useEffect, useState, useRef } from 'react'
2
+ import { Platform } from 'react-native'
2
3
 
3
- import { TextInput } from '../../src'
4
+ import { TextInput, Typography } from '../../src'
4
5
  import { Container } from '../supports'
5
6
 
6
7
  export default {
@@ -101,3 +102,40 @@ export const Controlled = () => {
101
102
  </>
102
103
  )
103
104
  }
105
+
106
+ export const WithPattern = (args) => {
107
+ const [value, setValue] = useState('')
108
+ const inputRef = useRef(null)
109
+ const isEmpty = value === ''
110
+ const isSuccess = !isEmpty && inputRef.current.checkValidity()
111
+ // eslint-disable-next-line no-nested-ternary
112
+ const validation = isEmpty ? undefined : isSuccess ? 'success' : 'error'
113
+ const { pattern } = args
114
+ // eslint-disable-next-line no-nested-ternary
115
+ const feedback = isEmpty
116
+ ? `Enter value matching pattern: ${pattern}`
117
+ : isSuccess
118
+ ? `Success! Value matches pattern: ${pattern}`
119
+ : `Error! Value must match pattern: ${pattern}`
120
+ if (Platform.OS !== 'web') {
121
+ return <Typography>Pattern prop is only supported on web</Typography>
122
+ }
123
+ return (
124
+ <>
125
+ <Container>
126
+ <TextInput
127
+ {...args}
128
+ ref={inputRef}
129
+ label="Pattern"
130
+ validation={validation}
131
+ feedback={feedback}
132
+ value={value}
133
+ onChange={setValue}
134
+ />
135
+ </Container>
136
+ </>
137
+ )
138
+ }
139
+ WithPattern.args = {
140
+ pattern: '[1-9]{2}'
141
+ }
@@ -1,22 +0,0 @@
1
- /* eslint-disable no-console */
2
- import React from 'react'
3
- import { render } from '@testing-library/react-native'
4
-
5
- import Theme from '../../__fixtures__/Theme'
6
- import LinkBase from '../../src/Link/LinkBase'
7
-
8
- beforeEach(() => jest.clearAllMocks())
9
-
10
- describe('LinkBase', () => {
11
- it('throws if neither href nor onPress are provided', async () => {
12
- jest.spyOn(console, 'error').mockImplementation()
13
- expect(() =>
14
- render(
15
- <Theme>
16
- <LinkBase>click me</LinkBase>
17
- </Theme>
18
- )
19
- ).toThrow()
20
- expect(console.error).toHaveBeenCalledTimes(1)
21
- })
22
- })