@marigold/components 0.1.0 → 0.3.2
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 +180 -0
- package/dist/ActionGroup/ActionGroup.d.ts +8 -0
- package/dist/ActionGroup/ActionGroup.stories.d.ts +5 -0
- package/dist/ActionGroup/index.d.ts +1 -0
- package/dist/Alert/Alert.d.ts +22 -1
- package/dist/Alert/Alert.stories.d.ts +5 -0
- package/dist/Badge/Badge.d.ts +5 -0
- package/dist/Badge/Badge.stories.d.ts +5 -0
- package/dist/Box.d.ts +2 -0
- package/dist/Button/Button.d.ts +9 -6
- package/dist/Button/Button.stories.d.ts +5 -0
- package/dist/Card/Card.d.ts +14 -0
- package/dist/Card/Card.stories.d.ts +5 -0
- package/dist/Card/index.d.ts +1 -0
- package/dist/Checkbox/Checkbox.d.ts +12 -4
- package/dist/Checkbox/Checkbox.stories.d.ts +5 -0
- package/dist/Checkbox/CheckboxIcons.d.ts +9 -0
- package/dist/Column/Column.d.ts +3 -1
- package/dist/Column/Column.stories.d.ts +5 -0
- package/dist/Columns/Columns.d.ts +2 -2
- package/dist/Columns/Columns.stories.d.ts +5 -0
- package/dist/Container/Container.stories.d.ts +5 -0
- package/dist/Dialog/Dialog.d.ts +12 -2
- package/dist/Dialog/Dialog.stories.d.ts +5 -0
- package/dist/Dialog/ModalDialog.d.ts +8 -0
- package/dist/Divider/Divider.d.ts +7 -3
- package/dist/Divider/Divider.stories.d.ts +5 -0
- package/dist/Field/Field.d.ts +5 -1
- package/dist/Field/Field.stories.d.ts +5 -0
- package/dist/Image/Image.d.ts +5 -0
- package/dist/Image/Image.stories.d.ts +5 -0
- package/dist/Inline/Inline.d.ts +7 -0
- package/dist/Inline/Inline.stories.d.ts +5 -0
- package/dist/Inline/index.d.ts +1 -0
- package/dist/Input/Input.d.ts +5 -0
- package/dist/Input/Input.stories.d.ts +5 -0
- package/dist/Label/Label.d.ts +14 -2
- package/dist/Label/Label.stories.d.ts +5 -0
- package/dist/Link/Link.d.ts +3 -0
- package/dist/Link/Link.stories.d.ts +5 -0
- package/dist/Menu/Menu.d.ts +3 -0
- package/dist/Menu/Menu.stories.d.ts +5 -0
- package/dist/MenuItem/MenuItem.d.ts +5 -0
- package/dist/MenuItem/MenuItem.stories.d.ts +5 -0
- package/dist/Message/Message.d.ts +5 -0
- package/dist/Message/Message.stories.d.ts +5 -0
- package/dist/Provider/MarigoldProvider.d.ts +11 -0
- package/dist/Provider/index.d.ts +3 -0
- package/dist/Radio/Radio.d.ts +11 -4
- package/dist/Radio/Radio.stories.d.ts +5 -0
- package/dist/Radio/RadioIcon.d.ts +9 -0
- package/dist/Select/ListBox.d.ts +9 -0
- package/dist/Select/ListBoxSection.d.ts +9 -0
- package/dist/Select/Option.d.ts +9 -0
- package/dist/Select/Popover.d.ts +9 -0
- package/dist/Select/Select.d.ts +25 -4
- package/dist/Select/Select.stories.d.ts +5 -0
- package/dist/Slider/Slider.d.ts +5 -0
- package/dist/Slider/Slider.stories.d.ts +5 -0
- package/dist/Stack/Stack.d.ts +1 -3
- package/dist/Stack/Stack.stories.d.ts +5 -0
- package/dist/Text/Text.d.ts +5 -0
- package/dist/Text/Text.stories.d.ts +5 -0
- package/dist/Textarea/Textarea.d.ts +7 -1
- package/dist/Textarea/Textarea.stories.d.ts +5 -0
- package/dist/ValidationMessage/ValidationMessage.d.ts +5 -0
- package/dist/ValidationMessage/ValidationMessage.stories.d.ts +5 -0
- package/dist/VisuallyHidden/VisuallyHidden.d.ts +1 -0
- package/dist/VisuallyHidden/VisuallyHidden.stories.d.ts +5 -0
- package/dist/VisuallyHidden/index.d.ts +1 -0
- package/dist/components.cjs.development.js +1068 -601
- package/dist/components.cjs.development.js.map +1 -1
- package/dist/components.cjs.production.min.js +1 -1
- package/dist/components.cjs.production.min.js.map +1 -1
- package/dist/components.esm.js +1003 -579
- package/dist/components.esm.js.map +1 -1
- package/dist/index.d.ts +6 -2
- package/dist/theme.d.ts +23 -48
- package/package.json +22 -3
- package/src/ActionGroup/ActionGroup.stories.tsx +47 -0
- package/src/ActionGroup/ActionGroup.test.tsx +83 -0
- package/src/ActionGroup/ActionGroup.tsx +32 -0
- package/src/ActionGroup/index.ts +1 -0
- package/src/Alert/Alert.stories.tsx +32 -0
- package/src/Alert/Alert.test.tsx +5 -2
- package/src/Alert/Alert.tsx +27 -34
- package/src/Badge/Badge.stories.tsx +38 -0
- package/src/Badge/Badge.test.tsx +12 -16
- package/src/Badge/Badge.tsx +14 -3
- package/src/Box.ts +2 -0
- package/src/Button/Button.stories.tsx +57 -0
- package/src/Button/Button.test.tsx +76 -13
- package/src/Button/Button.tsx +61 -18
- package/src/Card/Card.stories.tsx +41 -0
- package/src/Card/Card.test.tsx +71 -0
- package/src/Card/Card.tsx +48 -0
- package/src/Card/index.ts +1 -0
- package/src/Checkbox/Checkbox.stories.tsx +78 -0
- package/src/Checkbox/Checkbox.test.tsx +138 -23
- package/src/Checkbox/Checkbox.tsx +67 -68
- package/src/Checkbox/CheckboxIcons.tsx +59 -0
- package/src/Column/Column.stories.tsx +33 -0
- package/src/Column/Column.test.tsx +8 -0
- package/src/Column/Column.tsx +12 -2
- package/src/Columns/Columns.stories.tsx +75 -0
- package/src/Columns/Columns.test.tsx +34 -23
- package/src/Columns/Columns.tsx +30 -30
- package/src/Container/Container.stories.tsx +14 -0
- package/src/Dialog/Dialog.stories.tsx +88 -0
- package/src/Dialog/Dialog.test.tsx +129 -18
- package/src/Dialog/Dialog.tsx +113 -15
- package/src/Dialog/ModalDialog.tsx +76 -0
- package/src/Divider/Divider.stories.tsx +30 -0
- package/src/Divider/Divider.test.tsx +32 -23
- package/src/Divider/Divider.tsx +27 -7
- package/src/Field/Field.stories.tsx +110 -0
- package/src/Field/Field.test.tsx +74 -33
- package/src/Field/Field.tsx +27 -20
- package/src/Image/Image.stories.tsx +34 -0
- package/src/Image/Image.test.tsx +4 -1
- package/src/Image/Image.tsx +13 -1
- package/src/Inline/Inline.stories.tsx +39 -0
- package/src/Inline/Inline.test.tsx +99 -0
- package/src/Inline/Inline.tsx +38 -0
- package/src/Inline/index.ts +1 -0
- package/src/Input/Input.stories.tsx +54 -0
- package/src/Input/Input.test.tsx +7 -3
- package/src/Input/Input.tsx +13 -1
- package/src/Label/Label.stories.tsx +41 -0
- package/src/Label/Label.test.tsx +40 -5
- package/src/Label/Label.tsx +54 -8
- package/src/Link/Link.stories.tsx +35 -0
- package/src/Link/Link.test.tsx +6 -2
- package/src/Link/Link.tsx +12 -1
- package/src/Menu/Menu.stories.tsx +62 -0
- package/src/Menu/Menu.test.tsx +11 -6
- package/src/Menu/Menu.tsx +22 -14
- package/src/MenuItem/MenuItem.stories.tsx +30 -0
- package/src/MenuItem/MenuItem.test.tsx +22 -13
- package/src/MenuItem/MenuItem.tsx +19 -10
- package/src/Message/Message.stories.tsx +30 -0
- package/src/Message/Message.test.tsx +4 -1
- package/src/Message/Message.tsx +18 -14
- package/src/Provider/MarigoldProvider.test.tsx +136 -0
- package/src/Provider/MarigoldProvider.tsx +47 -0
- package/src/Provider/index.ts +4 -0
- package/src/Radio/Radio.stories.tsx +78 -0
- package/src/Radio/Radio.test.tsx +129 -18
- package/src/Radio/Radio.tsx +62 -71
- package/src/Radio/RadioIcon.tsx +49 -0
- package/src/Select/ListBox.tsx +40 -0
- package/src/Select/ListBoxSection.tsx +40 -0
- package/src/Select/Option.tsx +48 -0
- package/src/Select/Popover.tsx +50 -0
- package/src/Select/Select.stories.tsx +81 -0
- package/src/Select/Select.test.tsx +317 -35
- package/src/Select/Select.tsx +162 -18
- package/src/Slider/Slider.stories.tsx +24 -0
- package/src/Slider/Slider.test.tsx +10 -6
- package/src/Slider/Slider.tsx +25 -13
- package/src/Stack/Stack.stories.tsx +57 -0
- package/src/Stack/Stack.test.tsx +93 -65
- package/src/Stack/Stack.tsx +25 -41
- package/src/Text/Text.stories.tsx +61 -0
- package/src/Text/Text.test.tsx +2 -2
- package/src/Text/Text.tsx +25 -14
- package/src/Textarea/Textarea.stories.tsx +64 -0
- package/src/Textarea/Textarea.test.tsx +11 -8
- package/src/Textarea/Textarea.tsx +41 -38
- package/src/ValidationMessage/ValidationMessage.stories.tsx +27 -0
- package/src/ValidationMessage/ValidationMessage.test.tsx +9 -4
- package/src/ValidationMessage/ValidationMessage.tsx +23 -12
- package/src/VisuallyHidden/VisuallyHidden.stories.tsx +19 -0
- package/src/VisuallyHidden/VisuallyHidden.test.tsx +10 -0
- package/src/VisuallyHidden/VisuallyHidden.tsx +1 -0
- package/src/VisuallyHidden/index.ts +1 -0
- package/src/index.ts +7 -2
- package/src/theme.ts +49 -48
- package/dist/Box/Box.d.ts +0 -46
- package/dist/Box/index.d.ts +0 -1
- package/dist/Heading/Heading.d.ts +0 -7
- package/dist/Heading/index.d.ts +0 -1
- package/dist/Hidden/Hidden.d.ts +0 -5
- package/dist/Hidden/index.d.ts +0 -1
- package/src/Alert/Alert.stories.mdx +0 -45
- package/src/Badge/Badge.stories.mdx +0 -43
- package/src/Box/Box.stories.mdx +0 -38
- package/src/Box/Box.test.tsx +0 -133
- package/src/Box/Box.tsx +0 -157
- package/src/Box/index.ts +0 -1
- package/src/Button/Button.stories.mdx +0 -176
- package/src/Checkbox/Checkbox.stories.mdx +0 -81
- package/src/Column/Column.stories.mdx +0 -74
- package/src/Columns/Columns.stories.mdx +0 -247
- package/src/Container/Container.stories.mdx +0 -36
- package/src/Dialog/Dialog.stories.mdx +0 -64
- package/src/Divider/Divider.stories.mdx +0 -43
- package/src/Field/Field.stories.mdx +0 -57
- package/src/Heading/Heading.stories.mdx +0 -91
- package/src/Heading/Heading.test.tsx +0 -77
- package/src/Heading/Heading.tsx +0 -19
- package/src/Heading/index.ts +0 -1
- package/src/Hidden/Hidden.stories.mdx +0 -64
- package/src/Hidden/Hidden.test.tsx +0 -24
- package/src/Hidden/Hidden.tsx +0 -16
- package/src/Hidden/index.ts +0 -1
- package/src/Image/Image.stories.mdx +0 -40
- package/src/Input/Input.stories.mdx +0 -45
- package/src/Label/Label.stories.mdx +0 -34
- package/src/Link/Link.stories.mdx +0 -38
- package/src/Menu/Menu.stories.mdx +0 -49
- package/src/MenuItem/MenuItem.stories.mdx +0 -32
- package/src/Message/Message.stories.mdx +0 -44
- package/src/Radio/Radio.stories.mdx +0 -100
- package/src/Select/Select.stories.mdx +0 -44
- package/src/Slider/Slider.stories.mdx +0 -58
- package/src/Stack/Stack.stories.mdx +0 -105
- package/src/Text/Text.stories.mdx +0 -60
- package/src/Textarea/Textarea.stories.mdx +0 -65
- package/src/ValidationMessage/ValidationMessage.stories.mdx +0 -36
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import type { Meta, ComponentStory } from '@storybook/react';
|
|
3
|
+
import { Stack } from './Stack';
|
|
4
|
+
import { Text } from '../Text';
|
|
5
|
+
|
|
6
|
+
export default {
|
|
7
|
+
title: 'Components/Stack',
|
|
8
|
+
argTypes: {
|
|
9
|
+
space: {
|
|
10
|
+
control: {
|
|
11
|
+
type: 'select',
|
|
12
|
+
},
|
|
13
|
+
options: [
|
|
14
|
+
'none',
|
|
15
|
+
'xxsmall',
|
|
16
|
+
'xsmall',
|
|
17
|
+
'small',
|
|
18
|
+
'medium',
|
|
19
|
+
'large',
|
|
20
|
+
'xlarge',
|
|
21
|
+
'xxlarge',
|
|
22
|
+
],
|
|
23
|
+
description: 'Responsive Style Value',
|
|
24
|
+
table: {
|
|
25
|
+
defaultValue: {
|
|
26
|
+
summary: 'none',
|
|
27
|
+
},
|
|
28
|
+
},
|
|
29
|
+
},
|
|
30
|
+
align: {
|
|
31
|
+
control: {
|
|
32
|
+
type: 'select',
|
|
33
|
+
},
|
|
34
|
+
options: ['left', 'right', 'center'],
|
|
35
|
+
description: 'HTML element style',
|
|
36
|
+
table: {
|
|
37
|
+
defaultValue: {
|
|
38
|
+
summary: 'left',
|
|
39
|
+
},
|
|
40
|
+
},
|
|
41
|
+
},
|
|
42
|
+
},
|
|
43
|
+
} as Meta;
|
|
44
|
+
|
|
45
|
+
export const Basic: ComponentStory<typeof Stack> = args => (
|
|
46
|
+
<Stack {...args}>
|
|
47
|
+
<Text as="h2" variant="headline2">
|
|
48
|
+
Heading
|
|
49
|
+
</Text>
|
|
50
|
+
<Text>
|
|
51
|
+
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse
|
|
52
|
+
dignissim dapibus elit, vel egestas felis pharetra non. Cras malesuada,
|
|
53
|
+
massa nec ultricies efficitur, lectus ante consequat magna, a porttitor
|
|
54
|
+
massa ex ut quam.
|
|
55
|
+
</Text>
|
|
56
|
+
</Stack>
|
|
57
|
+
);
|
package/src/Stack/Stack.test.tsx
CHANGED
|
@@ -1,110 +1,138 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { render, screen } from '@testing-library/react';
|
|
3
|
+
import { ThemeProvider } from '@marigold/system';
|
|
4
|
+
|
|
3
5
|
import { Stack } from './Stack';
|
|
4
6
|
import { Text } from '../Text';
|
|
5
7
|
|
|
6
|
-
|
|
8
|
+
// Setup
|
|
9
|
+
// ---------------
|
|
10
|
+
const theme = {
|
|
11
|
+
space: {
|
|
12
|
+
none: 0,
|
|
13
|
+
small: 2,
|
|
14
|
+
medium: 4,
|
|
15
|
+
large: 8,
|
|
16
|
+
},
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
const getTopPadding = (element: HTMLElement) =>
|
|
20
|
+
getComputedStyle(element).getPropertyValue('padding-top');
|
|
21
|
+
|
|
22
|
+
test('default space is "none"', () => {
|
|
7
23
|
render(
|
|
8
|
-
<
|
|
9
|
-
<
|
|
10
|
-
|
|
24
|
+
<ThemeProvider theme={theme}>
|
|
25
|
+
<Stack>
|
|
26
|
+
<Text>first</Text>
|
|
27
|
+
<Text>second</Text>
|
|
28
|
+
<Text>third</Text>
|
|
29
|
+
</Stack>
|
|
30
|
+
</ThemeProvider>
|
|
11
31
|
);
|
|
12
|
-
const
|
|
32
|
+
const first = screen.getByText(/first/).parentElement!;
|
|
33
|
+
const second = screen.getByText(/second/).parentElement!;
|
|
34
|
+
const third = screen.getByText(/third/).parentElement!;
|
|
13
35
|
|
|
14
|
-
expect(
|
|
36
|
+
expect(getTopPadding(first)).toEqual('');
|
|
37
|
+
expect(second).toHaveStyle(`padding-top: 0px`);
|
|
38
|
+
expect(third).toHaveStyle(`padding-top: 0px`);
|
|
15
39
|
});
|
|
16
40
|
|
|
17
|
-
test('
|
|
41
|
+
test('accepts and uses spacing from theme', () => {
|
|
18
42
|
render(
|
|
19
|
-
<
|
|
20
|
-
<
|
|
21
|
-
|
|
43
|
+
<ThemeProvider theme={theme}>
|
|
44
|
+
<Stack space="small">
|
|
45
|
+
<Text>first</Text>
|
|
46
|
+
<Text>second</Text>
|
|
47
|
+
<Text>third</Text>
|
|
48
|
+
</Stack>
|
|
49
|
+
</ThemeProvider>
|
|
22
50
|
);
|
|
23
|
-
const
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
test('supports default prop align: left', () => {
|
|
29
|
-
render(<Stack title="stack">stack</Stack>);
|
|
30
|
-
const stack = screen.getByText(/stack/);
|
|
51
|
+
const first = screen.getByText(/first/);
|
|
52
|
+
const second = screen.getByText(/second/);
|
|
53
|
+
const third = screen.getByText(/third/);
|
|
31
54
|
|
|
32
|
-
expect(
|
|
55
|
+
expect(getTopPadding(first)).toEqual('');
|
|
56
|
+
expect(second.parentElement).toHaveStyle(`padding-top: 2px`);
|
|
57
|
+
expect(third.parentElement).toHaveStyle(`padding-top: 2px`);
|
|
33
58
|
});
|
|
34
59
|
|
|
35
|
-
test('
|
|
60
|
+
test('aligns children left by default', () => {
|
|
36
61
|
render(
|
|
37
|
-
<Stack
|
|
38
|
-
|
|
62
|
+
<Stack data-testid="stack">
|
|
63
|
+
<Text>first</Text>
|
|
39
64
|
</Stack>
|
|
40
65
|
);
|
|
41
|
-
const stack = screen.
|
|
66
|
+
const stack = screen.getByTestId('stack');
|
|
42
67
|
|
|
43
|
-
expect(stack).toHaveStyle(`align-items:
|
|
68
|
+
expect(stack).toHaveStyle(`align-items: flex-start`);
|
|
44
69
|
});
|
|
45
70
|
|
|
46
|
-
test('
|
|
71
|
+
test('allows to aligns children to the center', () => {
|
|
47
72
|
render(
|
|
48
|
-
<Stack align="
|
|
49
|
-
|
|
73
|
+
<Stack align="center" data-testid="stack">
|
|
74
|
+
<Text>first</Text>
|
|
50
75
|
</Stack>
|
|
51
76
|
);
|
|
52
|
-
const stack = screen.
|
|
77
|
+
const stack = screen.getByTestId('stack');
|
|
53
78
|
|
|
54
|
-
expect(stack).toHaveStyle(`align-items:
|
|
79
|
+
expect(stack).toHaveStyle(`align-items: center`);
|
|
55
80
|
});
|
|
56
81
|
|
|
57
|
-
test('
|
|
82
|
+
test('allows to aligns children to the right', () => {
|
|
58
83
|
render(
|
|
59
|
-
<Stack
|
|
60
|
-
<Text>
|
|
61
|
-
<Text>secondStackText</Text>
|
|
84
|
+
<Stack align="right" data-testid="stack">
|
|
85
|
+
<Text>first</Text>
|
|
62
86
|
</Stack>
|
|
63
87
|
);
|
|
64
|
-
const stack = screen.
|
|
65
|
-
const stackText = screen.getByText(/stackText/);
|
|
66
|
-
const secondStackText = screen.getByText(/secondStackText/);
|
|
88
|
+
const stack = screen.getByTestId('stack');
|
|
67
89
|
|
|
68
|
-
expect(stack).
|
|
69
|
-
expect(stackText).toBeDefined();
|
|
70
|
-
expect(secondStackText).toBeDefined();
|
|
90
|
+
expect(stack).toHaveStyle(`align-items: flex-end`);
|
|
71
91
|
});
|
|
72
92
|
|
|
73
|
-
test('supports
|
|
93
|
+
test('supports nesting', () => {
|
|
74
94
|
render(
|
|
75
|
-
<
|
|
76
|
-
<Stack
|
|
77
|
-
<
|
|
95
|
+
<ThemeProvider theme={theme}>
|
|
96
|
+
<Stack space="large">
|
|
97
|
+
<Stack space="small" data-testid="upperStack">
|
|
98
|
+
<Text>first</Text>
|
|
99
|
+
<Text>second</Text>
|
|
100
|
+
</Stack>
|
|
101
|
+
<Stack space="small" data-testid="lowerStack">
|
|
102
|
+
<Text>third</Text>
|
|
103
|
+
<Text>fourth</Text>
|
|
104
|
+
</Stack>
|
|
78
105
|
</Stack>
|
|
79
|
-
</
|
|
106
|
+
</ThemeProvider>
|
|
80
107
|
);
|
|
81
|
-
const
|
|
82
|
-
const
|
|
83
|
-
const
|
|
108
|
+
const first = screen.getByText(/first/);
|
|
109
|
+
const second = screen.getByText(/second/);
|
|
110
|
+
const upperStack = screen.getByTestId('upperStack');
|
|
84
111
|
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
});
|
|
112
|
+
const third = screen.getByText(/third/);
|
|
113
|
+
const fourth = screen.getByText(/fourth/);
|
|
114
|
+
const lowerStack = screen.getByTestId('lowerStack');
|
|
89
115
|
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
<Stack title="stack">
|
|
93
|
-
<Text>sdf</Text>
|
|
94
|
-
</Stack>
|
|
95
|
-
);
|
|
96
|
-
const stack = screen.getByTitle(/stack/);
|
|
116
|
+
expect(getTopPadding(upperStack.parentElement!)).toEqual('');
|
|
117
|
+
expect(lowerStack.parentElement).toHaveStyle(`padding-top: 8px`);
|
|
97
118
|
|
|
98
|
-
expect(
|
|
119
|
+
expect(getTopPadding(first.parentElement!)).toEqual('');
|
|
120
|
+
expect(second.parentElement).toHaveStyle(`padding-top: 2px`);
|
|
121
|
+
|
|
122
|
+
expect(getTopPadding(third.parentElement!)).toEqual('');
|
|
123
|
+
expect(fourth.parentElement).toHaveStyle(`padding-top: 2px`);
|
|
99
124
|
});
|
|
100
125
|
|
|
101
|
-
test('
|
|
126
|
+
test('renders as div per default', () => {
|
|
102
127
|
render(
|
|
103
|
-
<
|
|
104
|
-
<
|
|
105
|
-
|
|
128
|
+
<ThemeProvider theme={theme}>
|
|
129
|
+
<Stack data-testid="stack">
|
|
130
|
+
<Text>first</Text>
|
|
131
|
+
<Text>second</Text>
|
|
132
|
+
</Stack>
|
|
133
|
+
</ThemeProvider>
|
|
106
134
|
);
|
|
107
|
-
const stack = screen.getByTitle(/stack/);
|
|
108
135
|
|
|
109
|
-
|
|
136
|
+
const stack = screen.getByTestId('stack');
|
|
137
|
+
expect(stack instanceof HTMLDivElement).toBeTruthy();
|
|
110
138
|
});
|
package/src/Stack/Stack.tsx
CHANGED
|
@@ -1,55 +1,39 @@
|
|
|
1
1
|
import React, { Children } from 'react';
|
|
2
|
+
import flattenChildren from 'react-keyed-flatten-children';
|
|
3
|
+
|
|
2
4
|
import { ResponsiveStyleValue } from '@marigold/system';
|
|
5
|
+
|
|
3
6
|
import { Box } from '../Box';
|
|
4
|
-
import flattenChildren from 'react-keyed-flatten-children';
|
|
5
7
|
|
|
6
8
|
export type StackProps = {
|
|
7
|
-
|
|
8
|
-
space?: ResponsiveStyleValue<number | string>;
|
|
9
|
+
space?: ResponsiveStyleValue<string>;
|
|
9
10
|
align?: 'left' | 'right' | 'center';
|
|
10
|
-
title?: string; // For Testing
|
|
11
11
|
};
|
|
12
12
|
|
|
13
|
-
const
|
|
14
|
-
left:
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
alignItems: 'flex-start',
|
|
18
|
-
},
|
|
19
|
-
center: {
|
|
20
|
-
display: 'flex',
|
|
21
|
-
flexDirection: 'column',
|
|
22
|
-
alignItems: 'center',
|
|
23
|
-
},
|
|
24
|
-
right: {
|
|
25
|
-
display: 'flex',
|
|
26
|
-
flexDirection: 'column',
|
|
27
|
-
alignItems: 'flex-end',
|
|
28
|
-
},
|
|
13
|
+
const ALIGNMENT = {
|
|
14
|
+
left: 'flex-start',
|
|
15
|
+
center: 'center',
|
|
16
|
+
right: 'flex-end',
|
|
29
17
|
};
|
|
30
18
|
|
|
31
19
|
export const Stack: React.FC<StackProps> = ({
|
|
32
|
-
space =
|
|
20
|
+
space = 'none',
|
|
33
21
|
align = 'left',
|
|
34
22
|
children,
|
|
35
23
|
...props
|
|
36
|
-
}) =>
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
))}
|
|
53
|
-
</Box>
|
|
54
|
-
);
|
|
55
|
-
};
|
|
24
|
+
}) => (
|
|
25
|
+
<Box
|
|
26
|
+
{...props}
|
|
27
|
+
display="flex"
|
|
28
|
+
flexDirection="column"
|
|
29
|
+
alignItems={ALIGNMENT[align]}
|
|
30
|
+
css={{ '> * + *': { pt: space } }}
|
|
31
|
+
>
|
|
32
|
+
{Children.map(
|
|
33
|
+
flattenChildren(children) as unknown as React.ReactElement,
|
|
34
|
+
(child: React.ReactElement) => (
|
|
35
|
+
<Box>{React.cloneElement(child, {}, child.props.children)}</Box>
|
|
36
|
+
)
|
|
37
|
+
)}
|
|
38
|
+
</Box>
|
|
39
|
+
);
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import type { Meta, ComponentStory } from '@storybook/react';
|
|
3
|
+
import { Text } from './Text';
|
|
4
|
+
|
|
5
|
+
export default {
|
|
6
|
+
title: 'Components/Text',
|
|
7
|
+
argTypes: {
|
|
8
|
+
as: {
|
|
9
|
+
control: {
|
|
10
|
+
type: 'select',
|
|
11
|
+
},
|
|
12
|
+
options: ['span', 'p', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6'],
|
|
13
|
+
description: 'Set HTML element',
|
|
14
|
+
table: {
|
|
15
|
+
defaultValue: {
|
|
16
|
+
summary: 'span',
|
|
17
|
+
},
|
|
18
|
+
},
|
|
19
|
+
},
|
|
20
|
+
variant: {
|
|
21
|
+
control: {
|
|
22
|
+
type: 'select',
|
|
23
|
+
},
|
|
24
|
+
options: [
|
|
25
|
+
'body',
|
|
26
|
+
'headline1',
|
|
27
|
+
'headline2',
|
|
28
|
+
'headline3',
|
|
29
|
+
'headline4',
|
|
30
|
+
'headline5',
|
|
31
|
+
'headline6',
|
|
32
|
+
],
|
|
33
|
+
description: 'CHoose between body and different headlines',
|
|
34
|
+
table: {
|
|
35
|
+
defaultValue: {
|
|
36
|
+
summary: 'body',
|
|
37
|
+
},
|
|
38
|
+
},
|
|
39
|
+
},
|
|
40
|
+
color: {
|
|
41
|
+
control: {
|
|
42
|
+
type: 'text',
|
|
43
|
+
},
|
|
44
|
+
description: 'Text color',
|
|
45
|
+
table: {
|
|
46
|
+
defaultValue: {
|
|
47
|
+
summary: 'inherit',
|
|
48
|
+
},
|
|
49
|
+
},
|
|
50
|
+
},
|
|
51
|
+
},
|
|
52
|
+
} as Meta;
|
|
53
|
+
|
|
54
|
+
export const Basic: ComponentStory<typeof Text> = args => (
|
|
55
|
+
<Text {...args}>
|
|
56
|
+
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse
|
|
57
|
+
dignissim dapibus elit, vel egestas felis pharetra non. Cras malesuada,
|
|
58
|
+
massa nec ultricies efficitur, lectus ante consequat magna, a porttitor
|
|
59
|
+
massa ex ut quam.
|
|
60
|
+
</Text>
|
|
61
|
+
);
|
package/src/Text/Text.test.tsx
CHANGED
|
@@ -15,7 +15,7 @@ const theme = {
|
|
|
15
15
|
body: {
|
|
16
16
|
fontFamily: 'Oswald Regular',
|
|
17
17
|
},
|
|
18
|
-
|
|
18
|
+
headline1: {
|
|
19
19
|
fontFamily: 'Inter',
|
|
20
20
|
},
|
|
21
21
|
},
|
|
@@ -35,7 +35,7 @@ test('uses `text.body` as default variant', () => {
|
|
|
35
35
|
test('allows to change variants via `variant` prop (with "text" prefix)', () => {
|
|
36
36
|
render(
|
|
37
37
|
<ThemeProvider theme={theme}>
|
|
38
|
-
<Text variant="
|
|
38
|
+
<Text variant="headline1">text</Text>
|
|
39
39
|
</ThemeProvider>
|
|
40
40
|
);
|
|
41
41
|
const text = screen.getByText(/text/);
|
package/src/Text/Text.tsx
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React, { forwardRef } from 'react';
|
|
2
|
-
import { ResponsiveStyleValue
|
|
2
|
+
import { ResponsiveStyleValue } from '@marigold/system';
|
|
3
3
|
import {
|
|
4
4
|
PolymorphicComponentWithRef,
|
|
5
5
|
PolymorphicPropsWithRef,
|
|
@@ -7,6 +7,16 @@ import {
|
|
|
7
7
|
|
|
8
8
|
import { Box, BoxOwnProps } from '../Box';
|
|
9
9
|
|
|
10
|
+
// Theme Extension
|
|
11
|
+
// ---------------
|
|
12
|
+
export interface TextThemeExtension<Value> {
|
|
13
|
+
text?: {
|
|
14
|
+
[key: string]: Value;
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
// Props
|
|
19
|
+
// ---------------
|
|
10
20
|
export type TextOwnProps = {
|
|
11
21
|
align?: ResponsiveStyleValue<string>;
|
|
12
22
|
color?: ResponsiveStyleValue<string>;
|
|
@@ -17,6 +27,8 @@ export type TextOwnProps = {
|
|
|
17
27
|
|
|
18
28
|
export type TextProps = PolymorphicPropsWithRef<TextOwnProps, 'span'>;
|
|
19
29
|
|
|
30
|
+
// Component
|
|
31
|
+
// ---------------
|
|
20
32
|
export const Text: PolymorphicComponentWithRef<TextOwnProps, 'span'> =
|
|
21
33
|
forwardRef(
|
|
22
34
|
(
|
|
@@ -33,17 +45,16 @@ export const Text: PolymorphicComponentWithRef<TextOwnProps, 'span'> =
|
|
|
33
45
|
...props
|
|
34
46
|
},
|
|
35
47
|
ref
|
|
36
|
-
) =>
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
}
|
|
48
|
+
) => (
|
|
49
|
+
<Box
|
|
50
|
+
{...props}
|
|
51
|
+
as={as}
|
|
52
|
+
variant={`text.${variant}`}
|
|
53
|
+
css={{ textAlign: align, color, cursor, outline, userSelect }}
|
|
54
|
+
className={className}
|
|
55
|
+
ref={ref}
|
|
56
|
+
>
|
|
57
|
+
{children}
|
|
58
|
+
</Box>
|
|
59
|
+
)
|
|
49
60
|
);
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import type { Meta, ComponentStory } from '@storybook/react';
|
|
3
|
+
import { Textarea } from '.';
|
|
4
|
+
|
|
5
|
+
export default {
|
|
6
|
+
title: 'Components/Textarea',
|
|
7
|
+
argTypes: {
|
|
8
|
+
variant: {
|
|
9
|
+
control: {
|
|
10
|
+
type: 'text',
|
|
11
|
+
},
|
|
12
|
+
table: {
|
|
13
|
+
defaultValue: {
|
|
14
|
+
summary: '__default',
|
|
15
|
+
},
|
|
16
|
+
},
|
|
17
|
+
},
|
|
18
|
+
label: {
|
|
19
|
+
control: {
|
|
20
|
+
type: 'text',
|
|
21
|
+
},
|
|
22
|
+
description: 'Label text',
|
|
23
|
+
defaultValue: 'Textarea Label',
|
|
24
|
+
},
|
|
25
|
+
htmlFor: {
|
|
26
|
+
control: {
|
|
27
|
+
type: 'text',
|
|
28
|
+
},
|
|
29
|
+
description: 'Bind to label',
|
|
30
|
+
defaultValue: 'textareaId',
|
|
31
|
+
},
|
|
32
|
+
error: {
|
|
33
|
+
control: {
|
|
34
|
+
type: 'boolean',
|
|
35
|
+
},
|
|
36
|
+
description: 'Error',
|
|
37
|
+
table: {
|
|
38
|
+
defaultValue: {
|
|
39
|
+
summary: false,
|
|
40
|
+
},
|
|
41
|
+
},
|
|
42
|
+
},
|
|
43
|
+
errorMessage: {
|
|
44
|
+
control: {
|
|
45
|
+
type: 'text',
|
|
46
|
+
},
|
|
47
|
+
description: 'Error Message',
|
|
48
|
+
},
|
|
49
|
+
required: {
|
|
50
|
+
control: {
|
|
51
|
+
type: 'boolean',
|
|
52
|
+
},
|
|
53
|
+
table: {
|
|
54
|
+
defaultValue: {
|
|
55
|
+
summary: false,
|
|
56
|
+
},
|
|
57
|
+
},
|
|
58
|
+
},
|
|
59
|
+
},
|
|
60
|
+
} as Meta;
|
|
61
|
+
|
|
62
|
+
export const Basic: ComponentStory<typeof Textarea> = args => (
|
|
63
|
+
<Textarea placeholder="Placeholder..." {...args} />
|
|
64
|
+
);
|
|
@@ -4,12 +4,16 @@ import { ThemeProvider } from '@marigold/system';
|
|
|
4
4
|
import { Textarea } from '../Textarea';
|
|
5
5
|
|
|
6
6
|
const theme = {
|
|
7
|
+
fonts: {
|
|
8
|
+
body: 'Inter Regular',
|
|
9
|
+
fancy: 'Roboto',
|
|
10
|
+
},
|
|
7
11
|
textarea: {
|
|
8
|
-
|
|
9
|
-
fontFamily: '
|
|
12
|
+
__default: {
|
|
13
|
+
fontFamily: 'body',
|
|
10
14
|
},
|
|
11
15
|
textarea2: {
|
|
12
|
-
fontFamily: '
|
|
16
|
+
fontFamily: 'fancy',
|
|
13
17
|
},
|
|
14
18
|
},
|
|
15
19
|
};
|
|
@@ -58,14 +62,13 @@ test('supports label prop', () => {
|
|
|
58
62
|
expect(textarea instanceof HTMLLabelElement).toBeTruthy();
|
|
59
63
|
});
|
|
60
64
|
|
|
61
|
-
test('supports errorMessage prop', () => {
|
|
65
|
+
test('supports error and errorMessage prop', () => {
|
|
62
66
|
render(
|
|
63
67
|
<ThemeProvider theme={theme}>
|
|
64
|
-
<Textarea errorMessage="error" title="textarea" />
|
|
68
|
+
<Textarea error errorMessage="error" label="label" title="textarea" />
|
|
65
69
|
</ThemeProvider>
|
|
66
70
|
);
|
|
67
71
|
const textarea = screen.getByText(/error/);
|
|
68
|
-
|
|
69
72
|
expect(textarea).toBeDefined();
|
|
70
73
|
});
|
|
71
74
|
|
|
@@ -75,9 +78,9 @@ test('supports required prop', () => {
|
|
|
75
78
|
<Textarea label="test" htmlFor="myId" required title="textarea" />
|
|
76
79
|
</ThemeProvider>
|
|
77
80
|
);
|
|
78
|
-
const
|
|
81
|
+
const label = screen.getByText(/test/);
|
|
79
82
|
|
|
80
|
-
expect(
|
|
83
|
+
expect(label.nextSibling instanceof SVGElement).toBeTruthy();
|
|
81
84
|
});
|
|
82
85
|
|
|
83
86
|
test('accepts custom styles prop className', () => {
|