@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.
- package/CHANGELOG.md +17 -0
- package/__fixtures__/testTheme.js +83 -11
- package/__tests__/Divider/Divider.test.jsx +26 -5
- package/__tests__/Feedback/Feedback.test.jsx +42 -0
- package/__tests__/Spacer/Spacer.test.jsx +63 -0
- package/__tests__/StackView/StackView.test.jsx +242 -0
- package/__tests__/StackView/StackWrap.test.jsx +47 -0
- package/__tests__/StackView/getStackedContent.test.jsx +295 -0
- package/__tests__/TextInput/TextInput.test.jsx +146 -0
- package/__tests__/utils/useUniqueId.test.js +31 -0
- package/lib/Box/Box.js +7 -2
- package/lib/Button/ButtonBase.js +6 -16
- package/lib/Button/ButtonGroup.js +13 -22
- package/lib/Divider/Divider.js +40 -2
- package/lib/Feedback/Feedback.js +110 -0
- package/lib/Feedback/index.js +2 -0
- package/lib/Icon/Icon.js +1 -1
- package/lib/InputLabel/InputLabel.js +86 -0
- package/lib/InputLabel/LabelContent.native.js +8 -0
- package/lib/InputLabel/LabelContent.web.js +17 -0
- package/lib/InputLabel/index.js +2 -0
- package/lib/Link/LinkBase.js +9 -3
- package/lib/Spacer/Spacer.js +98 -0
- package/lib/Spacer/index.js +2 -0
- package/lib/StackView/StackView.js +105 -0
- package/lib/StackView/StackWrap.js +32 -0
- package/lib/StackView/StackWrap.native.js +3 -0
- package/lib/StackView/StackWrapBox.js +85 -0
- package/lib/StackView/StackWrapGap.js +45 -0
- package/lib/StackView/common.js +30 -0
- package/lib/StackView/getStackedContent.js +111 -0
- package/lib/StackView/index.js +5 -0
- package/lib/TextInput/TextInput.js +337 -0
- package/lib/TextInput/index.js +2 -0
- package/lib/Typography/Typography.js +0 -4
- package/lib/index.js +6 -1
- package/lib/utils/input.js +3 -1
- package/lib/utils/propTypes.js +9 -1
- package/lib/utils/useUniqueId.js +12 -0
- package/package.json +2 -2
- package/release-context.json +4 -4
- package/src/Box/Box.jsx +4 -2
- package/src/Button/ButtonBase.jsx +6 -18
- package/src/Button/ButtonGroup.jsx +13 -17
- package/src/Divider/Divider.jsx +38 -3
- package/src/Feedback/Feedback.jsx +99 -0
- package/src/Feedback/index.js +3 -0
- package/src/Icon/Icon.jsx +2 -1
- package/src/InputLabel/InputLabel.jsx +99 -0
- package/src/InputLabel/LabelContent.native.jsx +6 -0
- package/src/InputLabel/LabelContent.web.jsx +13 -0
- package/src/InputLabel/index.js +3 -0
- package/src/Link/LinkBase.jsx +9 -3
- package/src/Spacer/Spacer.jsx +91 -0
- package/src/Spacer/index.js +3 -0
- package/src/StackView/StackView.jsx +103 -0
- package/src/StackView/StackWrap.jsx +33 -0
- package/src/StackView/StackWrap.native.jsx +4 -0
- package/src/StackView/StackWrapBox.jsx +82 -0
- package/src/StackView/StackWrapGap.jsx +39 -0
- package/src/StackView/common.jsx +28 -0
- package/src/StackView/getStackedContent.jsx +106 -0
- package/src/StackView/index.js +6 -0
- package/src/TextInput/TextInput.jsx +325 -0
- package/src/TextInput/index.js +3 -0
- package/src/Typography/Typography.jsx +0 -4
- package/src/index.js +6 -1
- package/src/utils/input.js +2 -1
- package/src/utils/propTypes.js +9 -0
- package/src/utils/useUniqueId.js +14 -0
- package/stories/A11yText/A11yText.stories.jsx +11 -5
- package/stories/ActivityIndicator/ActivityIndicator.stories.jsx +11 -2
- package/stories/Box/Box.stories.jsx +29 -2
- package/stories/Button/Button.stories.jsx +17 -21
- package/stories/Button/ButtonGroup.stories.jsx +2 -1
- package/stories/Button/ButtonLink.stories.jsx +6 -4
- package/stories/Card/Card.stories.jsx +13 -1
- package/stories/Divider/Divider.stories.jsx +26 -2
- package/stories/ExpandCollapse/ExpandCollapse.stories.jsx +74 -79
- package/stories/Feedback/Feedback.stories.jsx +97 -0
- package/stories/FlexGrid/01 FlexGrid.stories.jsx +20 -7
- package/stories/Icon/Icon.stories.jsx +11 -3
- package/stories/InputLabel/InputLabel.stories.jsx +37 -0
- package/stories/Link/ChevronLink.stories.jsx +20 -4
- package/stories/Link/Link.stories.jsx +24 -2
- package/stories/Link/TextButton.stories.jsx +24 -2
- package/stories/Pagination/Pagination.stories.jsx +28 -14
- package/stories/SideNav/SideNav.stories.jsx +17 -2
- package/stories/Spacer/Spacer.stories.jsx +33 -0
- package/stories/StackView/StackView.stories.jsx +65 -0
- package/stories/StackView/StackWrap.stories.jsx +52 -0
- package/stories/TextInput/TextInput.stories.jsx +103 -0
- package/stories/ToggleSwitch/ToggleSwitch.stories.jsx +16 -3
- package/stories/Typography/Typography.stories.jsx +12 -3
- package/stories/platform-supports.web.jsx +1 -1
- package/stories/supports.jsx +109 -13
|
@@ -1,14 +1,17 @@
|
|
|
1
|
+
/* eslint-disable react/no-multi-comp */
|
|
1
2
|
import React from 'react'
|
|
3
|
+
import PropTypes from 'prop-types'
|
|
2
4
|
import { SideNav } from '../../lib'
|
|
5
|
+
import { EachParentType, parentTypesParams } from '../supports'
|
|
3
6
|
|
|
4
7
|
export default {
|
|
5
8
|
title: 'Base/SideNav',
|
|
6
9
|
component: SideNav
|
|
7
10
|
}
|
|
8
11
|
|
|
9
|
-
const Template = (args) => (
|
|
12
|
+
const Template = ({ label = 'Level 1 - 1', ...args }) => (
|
|
10
13
|
<SideNav {...args}>
|
|
11
|
-
<SideNav.Item href="#level-1-1">
|
|
14
|
+
<SideNav.Item href="#level-1-1">{label}</SideNav.Item>
|
|
12
15
|
<SideNav.ItemsGroup label="Group 1">
|
|
13
16
|
<SideNav.Item href="#level-2-1">Level 2 - 1</SideNav.Item>
|
|
14
17
|
<SideNav.Item href="#level-2-2">Level 2 - 2</SideNav.Item>
|
|
@@ -20,8 +23,20 @@ const Template = (args) => (
|
|
|
20
23
|
</SideNav.ItemsGroup>
|
|
21
24
|
</SideNav>
|
|
22
25
|
)
|
|
26
|
+
Template.propTypes = {
|
|
27
|
+
...SideNav.propTypes,
|
|
28
|
+
label: PropTypes.string
|
|
29
|
+
}
|
|
23
30
|
|
|
24
31
|
export const Default = Template.bind({})
|
|
32
|
+
Default.storyName = 'SideNav'
|
|
25
33
|
|
|
26
34
|
export const NonAccordion = Template.bind({})
|
|
27
35
|
NonAccordion.args = { accordion: false }
|
|
36
|
+
|
|
37
|
+
export const ParentTypes = (args) => (
|
|
38
|
+
<EachParentType componentThemeName="SideNav" {...args}>
|
|
39
|
+
{({ label, variant }) => <Template {...args} variant={variant} label={label} />}
|
|
40
|
+
</EachParentType>
|
|
41
|
+
)
|
|
42
|
+
ParentTypes.parameters = parentTypesParams
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import React from 'react'
|
|
2
|
+
import { View } from 'react-native'
|
|
3
|
+
|
|
4
|
+
import { Spacer, Typography } from '../../lib'
|
|
5
|
+
import { Container } from '../supports'
|
|
6
|
+
|
|
7
|
+
export default {
|
|
8
|
+
title: 'Base/Spacer',
|
|
9
|
+
component: Spacer
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export const Default = (args) => <Spacer {...args} />
|
|
13
|
+
Default.storyName = 'Spacer'
|
|
14
|
+
|
|
15
|
+
export const InColumn = (args) => (
|
|
16
|
+
<>
|
|
17
|
+
<Container margin={0} offWhite>
|
|
18
|
+
<Typography>First item, before spacer.</Typography>
|
|
19
|
+
</Container>
|
|
20
|
+
<Spacer {...args} />
|
|
21
|
+
<Container margin={0} offWhite>
|
|
22
|
+
<Typography>Second item, after spacer.</Typography>
|
|
23
|
+
</Container>
|
|
24
|
+
</>
|
|
25
|
+
)
|
|
26
|
+
InColumn.args = { space: 2 }
|
|
27
|
+
|
|
28
|
+
export const InRow = (args) => (
|
|
29
|
+
<View style={{ flexDirection: 'row' }}>
|
|
30
|
+
<InColumn {...args} />
|
|
31
|
+
</View>
|
|
32
|
+
)
|
|
33
|
+
InRow.args = { space: 2 }
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/* eslint-disable react/no-multi-comp */
|
|
2
|
+
import React from 'react'
|
|
3
|
+
import PropTypes from 'prop-types'
|
|
4
|
+
import { View } from 'react-native'
|
|
5
|
+
|
|
6
|
+
import { StackView, Card, Typography, Button } from '../../lib'
|
|
7
|
+
|
|
8
|
+
export default {
|
|
9
|
+
title: 'Base/StackView',
|
|
10
|
+
component: StackView
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
const content = (
|
|
14
|
+
<>
|
|
15
|
+
<Card>
|
|
16
|
+
<Typography>First item.</Typography>
|
|
17
|
+
</Card>
|
|
18
|
+
<Card>
|
|
19
|
+
<Typography>Second item.</Typography>
|
|
20
|
+
<Typography>Has two lines.</Typography>
|
|
21
|
+
</Card>
|
|
22
|
+
<Card>
|
|
23
|
+
<Typography>Third item.</Typography>
|
|
24
|
+
<Typography>This one is longer.</Typography>
|
|
25
|
+
<Typography>It has three lines.</Typography>
|
|
26
|
+
</Card>
|
|
27
|
+
<Button onPress={() => {}}>Different item</Button>
|
|
28
|
+
</>
|
|
29
|
+
)
|
|
30
|
+
|
|
31
|
+
export const Default = (args) => <StackView {...args} />
|
|
32
|
+
Default.storyName = 'StackView'
|
|
33
|
+
Default.args = { children: content }
|
|
34
|
+
// By default the JSX object is shown as a huge human-unreadable JSON tree control; turn it off
|
|
35
|
+
Default.argTypes = { children: { control: { disable: true } } }
|
|
36
|
+
|
|
37
|
+
export const Tokens = ({ flexGrow, alignItems, justifyContent, ...args }) => (
|
|
38
|
+
<View
|
|
39
|
+
style={{
|
|
40
|
+
flexGrow,
|
|
41
|
+
flexDirection: args.direction,
|
|
42
|
+
alignItems,
|
|
43
|
+
justifyContent
|
|
44
|
+
}}
|
|
45
|
+
>
|
|
46
|
+
<StackView {...args}>{content}</StackView>
|
|
47
|
+
</View>
|
|
48
|
+
)
|
|
49
|
+
Tokens.args = { inherit: true, space: 4, direction: 'row' }
|
|
50
|
+
Tokens.parameters = {
|
|
51
|
+
docs: {
|
|
52
|
+
storyDescription:
|
|
53
|
+
"A set of common layout styles may be set using the `tokens` prop, and selected from a parent theme using `selectTokens('StackView', themeTokens)`."
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
Tokens.propTypes = {
|
|
57
|
+
flexGrow: PropTypes.number,
|
|
58
|
+
alignItems: PropTypes.string,
|
|
59
|
+
justifyContent: PropTypes.string
|
|
60
|
+
}
|
|
61
|
+
Tokens.argTypes = {
|
|
62
|
+
flexGrow: { type: 'number', defaultValue: 1 },
|
|
63
|
+
alignItems: { type: 'string', defaultValue: 'flex-end' },
|
|
64
|
+
justifyContent: { type: 'string', defaultValue: 'flex-end' }
|
|
65
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/* eslint-disable react/no-multi-comp */
|
|
2
|
+
import React from 'react'
|
|
3
|
+
import { StyleSheet, View } from 'react-native'
|
|
4
|
+
|
|
5
|
+
import { StackWrap, Button } from '../../lib'
|
|
6
|
+
|
|
7
|
+
export default {
|
|
8
|
+
title: 'Base/StackWrap',
|
|
9
|
+
component: StackWrap
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
// Mixed length labels
|
|
13
|
+
const labels = ['Button ', 'Longer label ', '#', 'Mid-length ']
|
|
14
|
+
|
|
15
|
+
const getLabels = (length) =>
|
|
16
|
+
Array(length)
|
|
17
|
+
.fill('')
|
|
18
|
+
.map((_, index) => `${labels[index % 4]}${index}`)
|
|
19
|
+
|
|
20
|
+
export const Default = (args) => <StackWrap {...args} />
|
|
21
|
+
Default.storyName = 'StackWrap'
|
|
22
|
+
Default.args = {
|
|
23
|
+
children: getLabels(15).map((label) => (
|
|
24
|
+
<Button onPress={() => {}} key={label}>
|
|
25
|
+
{label}
|
|
26
|
+
</Button>
|
|
27
|
+
)),
|
|
28
|
+
// Storybook does a bad job picking these up automatically due to the indirection; make them easy to edit
|
|
29
|
+
space: 1,
|
|
30
|
+
gap: 1,
|
|
31
|
+
tokens: {}
|
|
32
|
+
}
|
|
33
|
+
// By default the JSX object is shown as a huge human-unreadable JSON tree control; turn it off
|
|
34
|
+
Default.argTypes = { children: { control: { disable: true } } }
|
|
35
|
+
|
|
36
|
+
export const Column = (args) => (
|
|
37
|
+
<View style={styles.constrainedHeight}>
|
|
38
|
+
<StackWrap {...args} />
|
|
39
|
+
</View>
|
|
40
|
+
)
|
|
41
|
+
Column.args = {
|
|
42
|
+
...Default.args,
|
|
43
|
+
direction: 'column'
|
|
44
|
+
}
|
|
45
|
+
Column.argTypes = { ...Default.argTypes }
|
|
46
|
+
|
|
47
|
+
const styles = StyleSheet.create({
|
|
48
|
+
constrainedHeight: {
|
|
49
|
+
height: 350,
|
|
50
|
+
alignItems: 'flex-start'
|
|
51
|
+
}
|
|
52
|
+
})
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import React, { useEffect, useState } from 'react'
|
|
2
|
+
|
|
3
|
+
import { TextInput } from '../../lib'
|
|
4
|
+
import { Container } from '../supports'
|
|
5
|
+
|
|
6
|
+
export default {
|
|
7
|
+
title: 'Base/TextInput',
|
|
8
|
+
component: TextInput
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
/* eslint-disable react/no-multi-comp */
|
|
12
|
+
|
|
13
|
+
const Template = (args) => (
|
|
14
|
+
<Container>
|
|
15
|
+
<TextInput {...args} />
|
|
16
|
+
</Container>
|
|
17
|
+
)
|
|
18
|
+
|
|
19
|
+
export const Default = Template.bind({})
|
|
20
|
+
Default.args = {
|
|
21
|
+
label: 'Label'
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export const WithHint = () => {
|
|
25
|
+
return (
|
|
26
|
+
<>
|
|
27
|
+
<Container>
|
|
28
|
+
<TextInput label="Label" hint="An inline hint" tooltip="Tooltip content" />
|
|
29
|
+
</Container>
|
|
30
|
+
<Container>
|
|
31
|
+
<TextInput
|
|
32
|
+
label="Label"
|
|
33
|
+
hint="A usually much longer hint below"
|
|
34
|
+
hintPosition="below"
|
|
35
|
+
tooltip="Tooltip content"
|
|
36
|
+
/>
|
|
37
|
+
</Container>
|
|
38
|
+
</>
|
|
39
|
+
)
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export const WithFeedback = () => {
|
|
43
|
+
return (
|
|
44
|
+
<>
|
|
45
|
+
<Container>
|
|
46
|
+
<TextInput label="Instructional" feedback="An instructional feedback" />
|
|
47
|
+
</Container>
|
|
48
|
+
<Container>
|
|
49
|
+
<TextInput label="Success" validation="success" feedback="A detailed success message" />
|
|
50
|
+
</Container>
|
|
51
|
+
<Container>
|
|
52
|
+
<TextInput label="Error" validation="error" feedback="A detailed error message" />
|
|
53
|
+
</Container>
|
|
54
|
+
</>
|
|
55
|
+
)
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export const InactiveAndReadOnly = () => {
|
|
59
|
+
return (
|
|
60
|
+
<>
|
|
61
|
+
<Container>
|
|
62
|
+
<TextInput label="Inactive" inactive initialValue="can't touch this" />
|
|
63
|
+
</Container>
|
|
64
|
+
<Container>
|
|
65
|
+
<TextInput label="Read only" readOnly value="won't change" />
|
|
66
|
+
</Container>
|
|
67
|
+
</>
|
|
68
|
+
)
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export const Controlled = () => {
|
|
72
|
+
const [value, setValue] = useState('')
|
|
73
|
+
const [validation, setValidation] = useState()
|
|
74
|
+
|
|
75
|
+
useEffect(() => {
|
|
76
|
+
if (value !== undefined && value.length > 0)
|
|
77
|
+
setValidation(value.length < 6 ? 'success' : 'error')
|
|
78
|
+
}, [value])
|
|
79
|
+
|
|
80
|
+
const defaultFeedbackContent =
|
|
81
|
+
'Will show an error if longer than 6 characters and success otherwise'
|
|
82
|
+
|
|
83
|
+
const feedbackContent = {
|
|
84
|
+
error: 'The value must be shorter than 6 characters',
|
|
85
|
+
success: 'Yay! The value has less than 6 characters'
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
const feedback = validation === undefined ? defaultFeedbackContent : feedbackContent[validation]
|
|
89
|
+
|
|
90
|
+
return (
|
|
91
|
+
<>
|
|
92
|
+
<Container>
|
|
93
|
+
<TextInput
|
|
94
|
+
label="Controlled"
|
|
95
|
+
validation={validation}
|
|
96
|
+
feedback={feedback}
|
|
97
|
+
value={value}
|
|
98
|
+
onChange={setValue}
|
|
99
|
+
/>
|
|
100
|
+
</Container>
|
|
101
|
+
</>
|
|
102
|
+
)
|
|
103
|
+
}
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
/* eslint-disable react/no-multi-comp */
|
|
2
2
|
import React, { useState } from 'react'
|
|
3
3
|
import { View } from 'react-native'
|
|
4
|
-
import { ToggleSwitch
|
|
5
|
-
import { Container } from '../supports'
|
|
4
|
+
import { ToggleSwitch, Typography } from '../../lib'
|
|
5
|
+
import { Container, EachParentType, parentTypesParams } from '../supports'
|
|
6
6
|
|
|
7
|
-
export const
|
|
7
|
+
export const Default = (args) => <ToggleSwitch {...args} />
|
|
8
|
+
Default.storyName = 'ToggleSwitch'
|
|
8
9
|
|
|
9
10
|
export default {
|
|
10
11
|
title: 'Base/ToggleSwitch',
|
|
@@ -45,3 +46,15 @@ export const ToggleSwitchInactive = (args) => (
|
|
|
45
46
|
</Container>
|
|
46
47
|
</>
|
|
47
48
|
)
|
|
49
|
+
|
|
50
|
+
export const ParentTypes = (args) => (
|
|
51
|
+
<EachParentType componentThemeName="ToggleSwitch" {...args}>
|
|
52
|
+
{({ label, variant }) => (
|
|
53
|
+
<>
|
|
54
|
+
<Typography>{`${label} `}</Typography>
|
|
55
|
+
<ToggleSwitch {...args} variant={variant} />
|
|
56
|
+
</>
|
|
57
|
+
)}
|
|
58
|
+
</EachParentType>
|
|
59
|
+
)
|
|
60
|
+
ParentTypes.parameters = parentTypesParams
|
|
@@ -1,9 +1,11 @@
|
|
|
1
|
+
/* eslint-disable react/no-multi-comp */
|
|
1
2
|
import React from 'react'
|
|
2
3
|
|
|
3
|
-
import { useVariants, Container } from '../supports'
|
|
4
|
-
import { Typography
|
|
4
|
+
import { useVariants, Container, EachParentType, parentTypesParams } from '../supports'
|
|
5
|
+
import { Typography } from '../../lib'
|
|
5
6
|
|
|
6
|
-
export const
|
|
7
|
+
export const Default = (args) => <Typography {...args} />
|
|
8
|
+
Default.storyName = 'Typography'
|
|
7
9
|
|
|
8
10
|
const defaultChildren = 'The quick brown fox jumps over the lazy dog'
|
|
9
11
|
|
|
@@ -38,3 +40,10 @@ LongTextTypographyVariants.args = {
|
|
|
38
40
|
'and what the current screen size is of the window in which this component is being shown.'
|
|
39
41
|
]
|
|
40
42
|
}
|
|
43
|
+
|
|
44
|
+
export const ParentTypes = (args) => (
|
|
45
|
+
<EachParentType componentThemeName="Typography" {...args}>
|
|
46
|
+
{({ label, variant }) => <Typography {...args} variant={variant}>{`${label}. `}</Typography>}
|
|
47
|
+
</EachParentType>
|
|
48
|
+
)
|
|
49
|
+
ParentTypes.parameters = parentTypesParams
|
|
@@ -14,7 +14,7 @@ InlineBlockDiv.propTypes = { children: PropTypes.node }
|
|
|
14
14
|
|
|
15
15
|
const FloatDiv = ({ children }) => (
|
|
16
16
|
<div>
|
|
17
|
-
<div style={{ float: 'right' }}>{children}</div>
|
|
17
|
+
<div style={{ float: 'right', maxWidth: '85%', marginLeft: '10px' }}>{children}</div>
|
|
18
18
|
<Typography block>
|
|
19
19
|
Some lengthy text in a paragraph with a block above it containing the components to test,
|
|
20
20
|
where the block above it has the style "float: right" applied and no other styles, giving the
|
package/stories/supports.jsx
CHANGED
|
@@ -1,27 +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
|
|
10
|
-
|
|
9
|
+
const RowWrap = ({ children }) => <View style={styles.rowWrap}>{children}</View>
|
|
10
|
+
RowWrap.propTypes = { children: PropTypes.node }
|
|
11
11
|
|
|
12
|
-
const
|
|
13
|
-
|
|
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 }
|
|
14
34
|
|
|
15
35
|
// TODO: find a way to give Base stories a complete empty SpacingObject for easy editting
|
|
16
36
|
// while giving themed stories a simpler value.
|
|
17
37
|
export const spacingObjectArg = { xs: 1, lg: 3 }
|
|
18
38
|
|
|
19
39
|
export const parentTypes = {
|
|
20
|
-
|
|
21
|
-
|
|
40
|
+
RowWrap,
|
|
41
|
+
RowStretch,
|
|
42
|
+
ColumnWrap,
|
|
43
|
+
ColumnStretch,
|
|
22
44
|
...platformContainers
|
|
23
45
|
}
|
|
24
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
|
+
|
|
25
95
|
export const Placeholder = ({ margin = false, ...props }) => (
|
|
26
96
|
<View style={[styles.placeholder, margin && styles.margin]}>
|
|
27
97
|
<Typography {...props} />
|
|
@@ -36,17 +106,29 @@ export const Container = ({
|
|
|
36
106
|
padding = 8,
|
|
37
107
|
dark = false,
|
|
38
108
|
offWhite = false,
|
|
109
|
+
borderWidth,
|
|
110
|
+
style,
|
|
39
111
|
children
|
|
40
112
|
}) => (
|
|
41
|
-
<View
|
|
113
|
+
<View
|
|
114
|
+
style={[
|
|
115
|
+
{ margin, padding },
|
|
116
|
+
dark && styles.dark,
|
|
117
|
+
offWhite && styles.offWhite,
|
|
118
|
+
{ borderWidth },
|
|
119
|
+
style
|
|
120
|
+
]}
|
|
121
|
+
>
|
|
42
122
|
{children}
|
|
43
123
|
</View>
|
|
44
124
|
)
|
|
45
125
|
Container.propTypes = {
|
|
46
126
|
margin: PropTypes.number,
|
|
47
127
|
padding: PropTypes.number,
|
|
128
|
+
borderWidth: PropTypes.number,
|
|
48
129
|
dark: PropTypes.bool,
|
|
49
130
|
offWhite: PropTypes.bool,
|
|
131
|
+
style: PropTypes.object,
|
|
50
132
|
children: PropTypes.node
|
|
51
133
|
}
|
|
52
134
|
|
|
@@ -57,6 +139,8 @@ const getVariantLabel = (key, value) => `${key}${typeof value === 'string' ? `:
|
|
|
57
139
|
*/
|
|
58
140
|
export const useVariants = (componentName) => {
|
|
59
141
|
const theme = useTheme()
|
|
142
|
+
if (!componentName) return [['default', {}]]
|
|
143
|
+
|
|
60
144
|
const { appearances } = getComponentTheme(theme, componentName)
|
|
61
145
|
|
|
62
146
|
if (!appearances) {
|
|
@@ -76,14 +160,26 @@ export const useVariants = (componentName) => {
|
|
|
76
160
|
}
|
|
77
161
|
|
|
78
162
|
const styles = StyleSheet.create({
|
|
79
|
-
|
|
163
|
+
rowWrap: {
|
|
164
|
+
flexDirection: 'row',
|
|
165
|
+
alignItems: 'flex-start',
|
|
166
|
+
flexWrap: 'wrap',
|
|
167
|
+
flex: 1
|
|
168
|
+
},
|
|
169
|
+
rowStretch: {
|
|
80
170
|
flexDirection: 'row',
|
|
81
|
-
|
|
82
|
-
|
|
171
|
+
flexGrow: 1
|
|
172
|
+
},
|
|
173
|
+
columnStretch: {
|
|
174
|
+
// alignItems: 'stretch' and flexDirection: 'column' are the default
|
|
83
175
|
},
|
|
84
|
-
|
|
176
|
+
columnWrap: {
|
|
85
177
|
flexDirection: 'column',
|
|
86
|
-
alignItems: '
|
|
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
|
|
87
183
|
},
|
|
88
184
|
content: {
|
|
89
185
|
maxWidth: 200,
|