@marigold/components 0.0.1 → 0.2.0
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/dist/ActionGroup/ActionGroup.d.ts +9 -0
- package/dist/ActionGroup/index.d.ts +1 -0
- package/dist/Alert/Alert.d.ts +20 -2
- package/dist/Badge/Badge.d.ts +8 -0
- package/dist/Badge/index.d.ts +1 -0
- package/dist/Box/Box.d.ts +47 -0
- package/dist/Box/index.d.ts +1 -0
- package/dist/Button/Button.d.ts +4 -3
- package/dist/Card/Card.d.ts +9 -0
- package/dist/Card/index.d.ts +1 -0
- package/dist/Checkbox/Checkbox.d.ts +14 -2
- package/dist/Checkbox/CheckboxIcons.d.ts +9 -0
- package/dist/Column/Column.d.ts +8 -0
- package/dist/Column/index.d.ts +1 -0
- package/dist/Columns/Columns.d.ts +10 -0
- package/dist/Columns/index.d.ts +1 -0
- package/dist/Container/Container.d.ts +6 -0
- package/dist/Container/index.d.ts +1 -0
- package/dist/Dialog/Dialog.d.ts +14 -0
- package/dist/Dialog/ModalDialog.d.ts +5 -0
- package/dist/Dialog/index.d.ts +1 -0
- package/dist/Divider/Divider.d.ts +7 -0
- package/dist/Divider/index.d.ts +1 -0
- package/dist/Field/Field.d.ts +11 -0
- package/dist/Field/index.d.ts +1 -0
- package/dist/Heading/Heading.d.ts +7 -5
- package/dist/Hidden/Hidden.d.ts +5 -0
- package/dist/Hidden/index.d.ts +1 -0
- package/dist/Image/Image.d.ts +7 -0
- package/dist/Image/index.d.ts +1 -0
- package/dist/Input/Input.d.ts +6 -0
- package/dist/Input/index.d.ts +1 -0
- package/dist/Label/Label.d.ts +8 -5
- package/dist/Link/Link.d.ts +7 -3
- package/dist/Menu/Menu.d.ts +12 -0
- package/dist/Menu/index.d.ts +1 -0
- package/dist/MenuItem/MenuItem.d.ts +7 -0
- package/dist/MenuItem/index.d.ts +1 -0
- package/dist/Message/Message.d.ts +7 -0
- package/dist/Message/index.d.ts +1 -0
- package/dist/Provider/MarigoldProvider.d.ts +3 -0
- package/dist/Provider/index.d.ts +3 -0
- package/dist/Radio/Radio.d.ts +14 -2
- package/dist/Radio/RadioIcons.d.ts +9 -0
- package/dist/Select/ListBox.d.ts +8 -0
- package/dist/Select/ListBoxSection.d.ts +8 -0
- package/dist/Select/Option.d.ts +8 -0
- package/dist/Select/Popover.d.ts +9 -0
- package/dist/Select/Select.d.ts +13 -3
- package/dist/Slider/Slider.d.ts +6 -3
- package/dist/Stack/Stack.d.ts +7 -0
- package/dist/Stack/index.d.ts +1 -0
- package/dist/Text/Text.d.ts +12 -3
- package/dist/Textarea/Textarea.d.ts +11 -3
- package/dist/ValidationMessage/ValidationMessage.d.ts +6 -0
- package/dist/ValidationMessage/index.d.ts +1 -0
- package/dist/components.cjs.development.js +1308 -195
- 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 +1267 -185
- package/dist/components.esm.js.map +1 -1
- package/dist/index.d.ts +21 -4
- package/dist/theme.d.ts +24 -4
- package/package.json +24 -4
- package/src/ActionGroup/ActionGroup.stories.mdx +62 -0
- package/src/ActionGroup/ActionGroup.test.tsx +83 -0
- package/src/ActionGroup/ActionGroup.tsx +43 -0
- package/src/ActionGroup/index.ts +1 -0
- package/src/Alert/Alert.stories.mdx +30 -42
- package/src/Alert/Alert.test.tsx +37 -22
- package/src/Alert/Alert.tsx +31 -21
- package/src/Badge/Badge.stories.mdx +57 -0
- package/src/Badge/Badge.test.tsx +61 -0
- package/src/Badge/Badge.tsx +25 -0
- package/src/Badge/index.ts +1 -0
- package/src/Box/Box.stories.mdx +334 -0
- package/src/Box/Box.test.tsx +133 -0
- package/src/Box/Box.tsx +165 -0
- package/src/Box/index.ts +1 -0
- package/src/Button/Button.stories.mdx +58 -134
- package/src/Button/Button.test.tsx +65 -23
- package/src/Button/Button.tsx +48 -14
- package/src/Card/Card.stories.mdx +49 -0
- package/src/Card/Card.test.tsx +66 -0
- package/src/Card/Card.tsx +36 -0
- package/src/Card/index.ts +1 -0
- package/src/Checkbox/Checkbox.stories.mdx +79 -101
- package/src/Checkbox/Checkbox.test.tsx +73 -32
- package/src/Checkbox/Checkbox.tsx +114 -35
- package/src/Checkbox/CheckboxIcons.tsx +49 -0
- package/src/Column/Column.stories.mdx +49 -0
- package/src/Column/Column.test.tsx +32 -0
- package/src/Column/Column.tsx +27 -0
- package/src/Column/index.ts +1 -0
- package/src/Columns/Columns.stories.mdx +65 -0
- package/src/Columns/Columns.test.tsx +102 -0
- package/src/Columns/Columns.tsx +69 -0
- package/src/Columns/index.ts +1 -0
- package/src/Container/Container.stories.mdx +19 -0
- package/src/Container/Container.test.tsx +26 -0
- package/src/Container/Container.tsx +13 -0
- package/src/Container/index.ts +1 -0
- package/src/Dialog/Dialog.stories.mdx +73 -0
- package/src/Dialog/Dialog.test.tsx +87 -0
- package/src/Dialog/Dialog.tsx +84 -0
- package/src/Dialog/ModalDialog.tsx +47 -0
- package/src/Dialog/index.ts +1 -0
- package/src/Divider/Divider.stories.mdx +37 -0
- package/src/Divider/Divider.test.tsx +63 -0
- package/src/Divider/Divider.tsx +13 -0
- package/src/Divider/index.ts +1 -0
- package/src/Field/Field.stories.mdx +97 -0
- package/src/Field/Field.test.tsx +80 -0
- package/src/Field/Field.tsx +54 -0
- package/src/Field/index.ts +1 -0
- package/src/Heading/Heading.stories.mdx +36 -76
- package/src/Heading/Heading.test.tsx +31 -17
- package/src/Heading/Heading.tsx +15 -12
- package/src/Hidden/Hidden.stories.mdx +39 -0
- package/src/Hidden/Hidden.test.tsx +24 -0
- package/src/Hidden/Hidden.tsx +16 -0
- package/src/Hidden/index.ts +1 -0
- package/src/Image/Image.stories.mdx +36 -0
- package/src/Image/Image.test.tsx +70 -0
- package/src/Image/Image.tsx +13 -0
- package/src/Image/index.ts +1 -0
- package/src/Input/Input.stories.mdx +61 -0
- package/src/Input/Input.test.tsx +70 -0
- package/src/Input/Input.tsx +13 -0
- package/src/Input/index.ts +1 -0
- package/src/Label/Label.stories.mdx +50 -34
- package/src/Label/Label.test.tsx +45 -16
- package/src/Label/Label.tsx +26 -17
- package/src/Link/Link.stories.mdx +40 -31
- package/src/Link/Link.test.tsx +53 -28
- package/src/Link/Link.tsx +32 -14
- package/src/Menu/Menu.stories.mdx +81 -0
- package/src/Menu/Menu.test.tsx +79 -0
- package/src/Menu/Menu.tsx +41 -0
- package/src/Menu/index.ts +1 -0
- package/src/MenuItem/MenuItem.stories.mdx +37 -0
- package/src/MenuItem/MenuItem.test.tsx +63 -0
- package/src/MenuItem/MenuItem.tsx +23 -0
- package/src/MenuItem/index.ts +1 -0
- package/src/Message/Message.stories.mdx +44 -0
- package/src/Message/Message.test.tsx +87 -0
- package/src/Message/Message.tsx +43 -0
- package/src/Message/index.ts +1 -0
- package/src/Provider/MarigoldProvider.test.tsx +126 -0
- package/src/Provider/MarigoldProvider.tsx +29 -0
- package/src/Provider/index.ts +3 -0
- package/src/Radio/Radio.stories.mdx +80 -83
- package/src/Radio/Radio.test.tsx +63 -22
- package/src/Radio/Radio.tsx +110 -35
- package/src/Radio/RadioIcons.tsx +39 -0
- package/src/Select/ListBox.tsx +39 -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.mdx +72 -37
- package/src/Select/Select.test.tsx +271 -28
- package/src/Select/Select.tsx +158 -23
- package/src/Slider/Slider.stories.mdx +26 -54
- package/src/Slider/Slider.test.tsx +13 -13
- package/src/Slider/Slider.tsx +20 -18
- package/src/Stack/Stack.stories.mdx +51 -0
- package/src/Stack/Stack.test.tsx +129 -0
- package/src/Stack/Stack.tsx +39 -0
- package/src/Stack/index.ts +1 -0
- package/src/Text/Text.stories.mdx +53 -47
- package/src/Text/Text.test.tsx +55 -15
- package/src/Text/Text.tsx +44 -10
- package/src/Textarea/Textarea.stories.mdx +68 -21
- package/src/Textarea/Textarea.test.tsx +47 -16
- package/src/Textarea/Textarea.tsx +46 -14
- package/src/ValidationMessage/ValidationMessage.stories.mdx +36 -0
- package/src/ValidationMessage/ValidationMessage.test.tsx +63 -0
- package/src/ValidationMessage/ValidationMessage.tsx +28 -0
- package/src/ValidationMessage/index.ts +1 -0
- package/src/index.ts +22 -4
- package/src/theme.ts +24 -4
- package/dist/Svg/Svg.d.ts +0 -5
- package/dist/Svg/index.d.ts +0 -1
- package/dist/TextInput/TextInput.d.ts +0 -3
- package/dist/TextInput/index.d.ts +0 -1
- package/src/Svg/Svg.stories.mdx +0 -47
- package/src/Svg/Svg.test.tsx +0 -58
- package/src/Svg/Svg.tsx +0 -25
- package/src/Svg/index.ts +0 -1
- package/src/TextInput/TextInput.stories.mdx +0 -37
- package/src/TextInput/TextInput.test.tsx +0 -71
- package/src/TextInput/TextInput.tsx +0 -21
- package/src/TextInput/index.ts +0 -1
package/src/Slider/Slider.tsx
CHANGED
|
@@ -1,21 +1,23 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import {
|
|
2
|
+
import { useStyles } from '@marigold/system';
|
|
3
|
+
import { ComponentProps } from '@marigold/types';
|
|
3
4
|
|
|
4
|
-
type SliderProps = {
|
|
5
|
+
export type SliderProps = {
|
|
6
|
+
variant?: string;
|
|
7
|
+
} & ComponentProps<'input'>;
|
|
5
8
|
|
|
6
|
-
export const Slider
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
);
|
|
9
|
+
export const Slider: React.FC<SliderProps> = ({
|
|
10
|
+
variant = 'slider',
|
|
11
|
+
className,
|
|
12
|
+
...props
|
|
13
|
+
}) => {
|
|
14
|
+
const classNames = useStyles({
|
|
15
|
+
variant: `form.${variant}`,
|
|
16
|
+
css: {
|
|
17
|
+
verticalAlign: 'middle',
|
|
18
|
+
},
|
|
19
|
+
className,
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
return <input type="range" className={classNames} {...props} />;
|
|
23
|
+
};
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { ArgsTable, Canvas, Meta, Story } from '@storybook/addon-docs';
|
|
2
|
+
import { Heading } from '../Heading';
|
|
3
|
+
import { Stack } from './Stack';
|
|
4
|
+
import { Text } from '../Text';
|
|
5
|
+
|
|
6
|
+
<Meta
|
|
7
|
+
title="Components/Stack"
|
|
8
|
+
argTypes={{
|
|
9
|
+
space: {
|
|
10
|
+
control: {
|
|
11
|
+
type: 'text',
|
|
12
|
+
},
|
|
13
|
+
description: 'Responsive Style Value',
|
|
14
|
+
table: {
|
|
15
|
+
defaultValue: {
|
|
16
|
+
summary: '0',
|
|
17
|
+
},
|
|
18
|
+
},
|
|
19
|
+
},
|
|
20
|
+
align: {
|
|
21
|
+
control: {
|
|
22
|
+
type: 'select',
|
|
23
|
+
},
|
|
24
|
+
options: ['left', 'right', 'center'],
|
|
25
|
+
description: 'HTML element style',
|
|
26
|
+
table: {
|
|
27
|
+
defaultValue: {
|
|
28
|
+
summary: 'left',
|
|
29
|
+
},
|
|
30
|
+
},
|
|
31
|
+
},
|
|
32
|
+
}}
|
|
33
|
+
/>
|
|
34
|
+
|
|
35
|
+
# Stack
|
|
36
|
+
|
|
37
|
+
export const Template = args => (
|
|
38
|
+
<Stack {...args}>
|
|
39
|
+
<Heading>Heading</Heading>
|
|
40
|
+
<Text>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse
|
|
41
|
+
dignissim dapibus elit, vel egestas felis pharetra non. Cras
|
|
42
|
+
malesuada, massa nec ultricies efficitur, lectus ante consequat magna,
|
|
43
|
+
a porttitor massa ex ut quam.</Text>
|
|
44
|
+
</Stack>
|
|
45
|
+
);
|
|
46
|
+
|
|
47
|
+
<Canvas>
|
|
48
|
+
<Story name="Default">{Template.bind({})}</Story>
|
|
49
|
+
</Canvas>
|
|
50
|
+
|
|
51
|
+
<ArgsTable story="Default" />
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { render, screen } from '@testing-library/react';
|
|
3
|
+
import { ThemeProvider } from '@marigold/system';
|
|
4
|
+
|
|
5
|
+
import { Stack } from './Stack';
|
|
6
|
+
import { Text } from '../Text';
|
|
7
|
+
|
|
8
|
+
// Setup
|
|
9
|
+
// ---------------
|
|
10
|
+
const theme = {
|
|
11
|
+
space: {
|
|
12
|
+
none: 0,
|
|
13
|
+
small: 2,
|
|
14
|
+
medium: 4,
|
|
15
|
+
large: 8,
|
|
16
|
+
},
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
test('default space is "none"', () => {
|
|
20
|
+
render(
|
|
21
|
+
<ThemeProvider theme={theme}>
|
|
22
|
+
<Stack>
|
|
23
|
+
<Text>first</Text>
|
|
24
|
+
<Text>second</Text>
|
|
25
|
+
</Stack>
|
|
26
|
+
</ThemeProvider>
|
|
27
|
+
);
|
|
28
|
+
const first = screen.getByText(/first/);
|
|
29
|
+
const second = screen.getByText(/second/);
|
|
30
|
+
|
|
31
|
+
expect(first).toHaveStyle(`padding-top: 0px`);
|
|
32
|
+
expect(second).toHaveStyle(`padding-top: 0px`);
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
test('accepts and uses spacing from theme', () => {
|
|
36
|
+
render(
|
|
37
|
+
<ThemeProvider theme={theme}>
|
|
38
|
+
<Stack space="small">
|
|
39
|
+
<Text>first</Text>
|
|
40
|
+
<Text>second</Text>
|
|
41
|
+
</Stack>
|
|
42
|
+
</ThemeProvider>
|
|
43
|
+
);
|
|
44
|
+
const first = screen.getByText(/first/);
|
|
45
|
+
const second = screen.getByText(/second/);
|
|
46
|
+
|
|
47
|
+
expect(first.parentElement).toHaveStyle(`padding-top: 0px`);
|
|
48
|
+
expect(second.parentElement).toHaveStyle(`padding-top: 2px`);
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
test('aligns children left by default', () => {
|
|
52
|
+
render(
|
|
53
|
+
<Stack data-testid="stack">
|
|
54
|
+
<Text>first</Text>
|
|
55
|
+
</Stack>
|
|
56
|
+
);
|
|
57
|
+
const stack = screen.getByTestId('stack');
|
|
58
|
+
|
|
59
|
+
expect(stack).toHaveStyle(`align-items: flex-start`);
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
test('allows to aligns children to the center', () => {
|
|
63
|
+
render(
|
|
64
|
+
<Stack align="center" data-testid="stack">
|
|
65
|
+
<Text>first</Text>
|
|
66
|
+
</Stack>
|
|
67
|
+
);
|
|
68
|
+
const stack = screen.getByTestId('stack');
|
|
69
|
+
|
|
70
|
+
expect(stack).toHaveStyle(`align-items: center`);
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
test('allows to aligns children to the right', () => {
|
|
74
|
+
render(
|
|
75
|
+
<Stack align="right" data-testid="stack">
|
|
76
|
+
<Text>first</Text>
|
|
77
|
+
</Stack>
|
|
78
|
+
);
|
|
79
|
+
const stack = screen.getByTestId('stack');
|
|
80
|
+
|
|
81
|
+
expect(stack).toHaveStyle(`align-items: flex-end`);
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
test('supports nesting', () => {
|
|
85
|
+
render(
|
|
86
|
+
<ThemeProvider theme={theme}>
|
|
87
|
+
<Stack space="large">
|
|
88
|
+
<Stack space="small" data-testid="upperStack">
|
|
89
|
+
<Text>first</Text>
|
|
90
|
+
<Text>second</Text>
|
|
91
|
+
</Stack>
|
|
92
|
+
<Stack space="small" data-testid="lowerStack">
|
|
93
|
+
<Text>third</Text>
|
|
94
|
+
<Text>fourth</Text>
|
|
95
|
+
</Stack>
|
|
96
|
+
</Stack>
|
|
97
|
+
</ThemeProvider>
|
|
98
|
+
);
|
|
99
|
+
const first = screen.getByText(/first/);
|
|
100
|
+
const second = screen.getByText(/second/);
|
|
101
|
+
const upperStack = screen.getByTestId('upperStack');
|
|
102
|
+
|
|
103
|
+
const third = screen.getByText(/third/);
|
|
104
|
+
const fourth = screen.getByText(/fourth/);
|
|
105
|
+
const lowerStack = screen.getByTestId('lowerStack');
|
|
106
|
+
|
|
107
|
+
expect(upperStack.parentElement).toHaveStyle(`padding-top: 0px`);
|
|
108
|
+
expect(lowerStack.parentElement).toHaveStyle(`padding-top: 8px`);
|
|
109
|
+
|
|
110
|
+
expect(first.parentElement).toHaveStyle(`padding-top: 0px`);
|
|
111
|
+
expect(second.parentElement).toHaveStyle(`padding-top: 2px`);
|
|
112
|
+
|
|
113
|
+
expect(third.parentElement).toHaveStyle(`padding-top: 0px`);
|
|
114
|
+
expect(fourth.parentElement).toHaveStyle(`padding-top: 2px`);
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
test('renders as div per default', () => {
|
|
118
|
+
render(
|
|
119
|
+
<ThemeProvider theme={theme}>
|
|
120
|
+
<Stack data-testid="stack">
|
|
121
|
+
<Text>first</Text>
|
|
122
|
+
<Text>second</Text>
|
|
123
|
+
</Stack>
|
|
124
|
+
</ThemeProvider>
|
|
125
|
+
);
|
|
126
|
+
|
|
127
|
+
const stack = screen.getByTestId('stack');
|
|
128
|
+
expect(stack instanceof HTMLDivElement).toBeTruthy();
|
|
129
|
+
});
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import React, { Children } from 'react';
|
|
2
|
+
import flattenChildren from 'react-keyed-flatten-children';
|
|
3
|
+
|
|
4
|
+
import { ResponsiveStyleValue } from '@marigold/system';
|
|
5
|
+
|
|
6
|
+
import { Box } from '../Box';
|
|
7
|
+
|
|
8
|
+
export type StackProps = {
|
|
9
|
+
space?: ResponsiveStyleValue<string>;
|
|
10
|
+
align?: 'left' | 'right' | 'center';
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
const ALIGNMENT = {
|
|
14
|
+
left: 'flex-start',
|
|
15
|
+
center: 'center',
|
|
16
|
+
right: 'flex-end',
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
export const Stack: React.FC<StackProps> = ({
|
|
20
|
+
space = 'none',
|
|
21
|
+
align = 'left',
|
|
22
|
+
children,
|
|
23
|
+
...props
|
|
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 @@
|
|
|
1
|
+
export * from './Stack';
|
|
@@ -1,54 +1,60 @@
|
|
|
1
|
-
import { Meta, Story
|
|
1
|
+
import { ArgsTable, Canvas, Meta, Story } from '@storybook/addon-docs';
|
|
2
2
|
import { Text } from './Text';
|
|
3
3
|
|
|
4
|
-
<Meta
|
|
4
|
+
<Meta
|
|
5
|
+
title="Components/Text"
|
|
6
|
+
argTypes={{
|
|
7
|
+
as: {
|
|
8
|
+
control: {
|
|
9
|
+
type: 'select',
|
|
10
|
+
},
|
|
11
|
+
options: ['span', 'p'],
|
|
12
|
+
description: 'Set inline',
|
|
13
|
+
table: {
|
|
14
|
+
defaultValue: {
|
|
15
|
+
summary: 'span',
|
|
16
|
+
},
|
|
17
|
+
},
|
|
18
|
+
},
|
|
19
|
+
variant: {
|
|
20
|
+
control: {
|
|
21
|
+
type: 'select',
|
|
22
|
+
},
|
|
23
|
+
options: ['body', 'heading'],
|
|
24
|
+
description: 'Doesnt matter',
|
|
25
|
+
table: {
|
|
26
|
+
defaultValue: {
|
|
27
|
+
summary: 'body',
|
|
28
|
+
},
|
|
29
|
+
},
|
|
30
|
+
},
|
|
31
|
+
color: {
|
|
32
|
+
control: {
|
|
33
|
+
type: 'text',
|
|
34
|
+
},
|
|
35
|
+
description: 'Text color',
|
|
36
|
+
table: {
|
|
37
|
+
defaultValue: {
|
|
38
|
+
summary: 'inherit',
|
|
39
|
+
},
|
|
40
|
+
},
|
|
41
|
+
},
|
|
42
|
+
}}
|
|
43
|
+
/>
|
|
5
44
|
|
|
6
45
|
# Text
|
|
7
46
|
|
|
8
|
-
|
|
47
|
+
export const Template = args => (
|
|
48
|
+
<Text {...args}>
|
|
49
|
+
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse
|
|
50
|
+
dignissim dapibus elit, vel egestas felis pharetra non. Cras malesuada,
|
|
51
|
+
massa nec ultricies efficitur, lectus ante consequat magna, a porttitor
|
|
52
|
+
massa ex ut quam.
|
|
53
|
+
</Text>
|
|
54
|
+
);
|
|
9
55
|
|
|
10
|
-
|
|
11
|
-
|
|
56
|
+
<Canvas>
|
|
57
|
+
<Story name="Default">{Template.bind({})}</Story>
|
|
58
|
+
</Canvas>
|
|
12
59
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
| Property | Type | Default |
|
|
16
|
-
| :-------- | :---------------- | :------ |
|
|
17
|
-
| `variant` | `body`, `heading` | `body` |
|
|
18
|
-
|
|
19
|
-
## Import
|
|
20
|
-
|
|
21
|
-
```tsx
|
|
22
|
-
import { Text } from '@marigold/components';
|
|
23
|
-
```
|
|
24
|
-
|
|
25
|
-
## Usage
|
|
26
|
-
|
|
27
|
-
<Preview>
|
|
28
|
-
<Story name="body">
|
|
29
|
-
<Text css={{ color: 'text' }}>
|
|
30
|
-
SPAN: Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam
|
|
31
|
-
nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed
|
|
32
|
-
diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum.
|
|
33
|
-
Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor
|
|
34
|
-
sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed
|
|
35
|
-
diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam
|
|
36
|
-
erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea
|
|
37
|
-
rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum
|
|
38
|
-
dolor sit amet.
|
|
39
|
-
</Text>
|
|
40
|
-
</Story>
|
|
41
|
-
<Story name="heading">
|
|
42
|
-
<Text variant="heading" css={{ color: 'text' }}>
|
|
43
|
-
P: Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam
|
|
44
|
-
nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed
|
|
45
|
-
diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum.
|
|
46
|
-
Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor
|
|
47
|
-
sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed
|
|
48
|
-
diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam
|
|
49
|
-
erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea
|
|
50
|
-
rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum
|
|
51
|
-
dolor sit amet.
|
|
52
|
-
</Text>
|
|
53
|
-
</Story>
|
|
54
|
-
</Preview>
|
|
60
|
+
<ArgsTable story="Default" />
|
package/src/Text/Text.test.tsx
CHANGED
|
@@ -1,9 +1,16 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { render, screen } from '@testing-library/react';
|
|
3
|
-
import {
|
|
3
|
+
import { ThemeProvider } from '@marigold/system';
|
|
4
|
+
|
|
4
5
|
import { Text } from './Text';
|
|
5
6
|
|
|
6
7
|
const theme = {
|
|
8
|
+
colors: {
|
|
9
|
+
primary: 'hotpink',
|
|
10
|
+
black: '#000',
|
|
11
|
+
white: '#FFF',
|
|
12
|
+
blue: '#2980b9',
|
|
13
|
+
},
|
|
7
14
|
text: {
|
|
8
15
|
body: {
|
|
9
16
|
fontFamily: 'Oswald Regular',
|
|
@@ -14,46 +21,79 @@ const theme = {
|
|
|
14
21
|
},
|
|
15
22
|
};
|
|
16
23
|
|
|
17
|
-
test('
|
|
24
|
+
test('uses `text.body` as default variant', () => {
|
|
18
25
|
render(
|
|
19
|
-
<
|
|
26
|
+
<ThemeProvider theme={theme}>
|
|
20
27
|
<Text>text</Text>
|
|
21
|
-
</
|
|
28
|
+
</ThemeProvider>
|
|
22
29
|
);
|
|
23
30
|
const text = screen.getByText(/text/);
|
|
24
31
|
|
|
25
32
|
expect(text).toHaveStyle(`font-family: Oswald Regular`);
|
|
26
33
|
});
|
|
27
34
|
|
|
28
|
-
test('
|
|
35
|
+
test('allows to change variants via `variant` prop (with "text" prefix)', () => {
|
|
29
36
|
render(
|
|
30
|
-
<
|
|
37
|
+
<ThemeProvider theme={theme}>
|
|
31
38
|
<Text variant="heading">text</Text>
|
|
32
|
-
</
|
|
39
|
+
</ThemeProvider>
|
|
33
40
|
);
|
|
34
41
|
const text = screen.getByText(/text/);
|
|
35
42
|
|
|
36
43
|
expect(text).toHaveStyle(`font-family: Inter`);
|
|
37
44
|
});
|
|
38
45
|
|
|
39
|
-
test('renders <span> element by default', () => {
|
|
46
|
+
test('renders a <span> element by default', () => {
|
|
40
47
|
render(
|
|
41
|
-
<
|
|
48
|
+
<ThemeProvider theme={theme}>
|
|
42
49
|
<Text>text</Text>
|
|
43
|
-
</
|
|
50
|
+
</ThemeProvider>
|
|
44
51
|
);
|
|
45
52
|
const text = screen.getByText(/text/);
|
|
46
53
|
|
|
47
54
|
expect(text instanceof HTMLSpanElement).toBeTruthy();
|
|
48
55
|
});
|
|
49
56
|
|
|
50
|
-
test('
|
|
57
|
+
test('allows to control the rendered element via the `as` prop', () => {
|
|
51
58
|
render(
|
|
52
|
-
<
|
|
53
|
-
<Text
|
|
54
|
-
</
|
|
59
|
+
<ThemeProvider theme={theme}>
|
|
60
|
+
<Text as="p">text</Text>
|
|
61
|
+
</ThemeProvider>
|
|
55
62
|
);
|
|
56
63
|
const text = screen.getByText(/text/);
|
|
57
64
|
|
|
58
|
-
expect(text).
|
|
65
|
+
expect(text instanceof HTMLParagraphElement).toBeTruthy();
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
test.each([
|
|
69
|
+
[{ color: 'primary' }, 'color: hotpink'],
|
|
70
|
+
[{ color: 'blue' }, 'color: #2980b9'],
|
|
71
|
+
[{ align: 'center' }, 'text-align: center'],
|
|
72
|
+
[{ cursor: 'pointer' }, 'cursor: pointer'],
|
|
73
|
+
[{ outline: 'dashed red' }, 'outline: dashed red'],
|
|
74
|
+
[{ userSelect: 'none' }, 'user-select: none'],
|
|
75
|
+
])('test style prop %o', (...args) => {
|
|
76
|
+
const props = args.shift();
|
|
77
|
+
|
|
78
|
+
render(
|
|
79
|
+
<ThemeProvider theme={theme}>
|
|
80
|
+
<Text {...props}>This is the Text!</Text>
|
|
81
|
+
</ThemeProvider>
|
|
82
|
+
);
|
|
83
|
+
|
|
84
|
+
const box = screen.getByText('This is the Text!');
|
|
85
|
+
args.forEach((style: any) => {
|
|
86
|
+
expect(box).toHaveStyle(style);
|
|
87
|
+
});
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
test('forwards ref', () => {
|
|
91
|
+
const ref = React.createRef<HTMLButtonElement>();
|
|
92
|
+
render(
|
|
93
|
+
<Text as="button" ref={ref}>
|
|
94
|
+
button
|
|
95
|
+
</Text>
|
|
96
|
+
);
|
|
97
|
+
|
|
98
|
+
expect(ref.current instanceof HTMLButtonElement).toBeTruthy();
|
|
59
99
|
});
|
package/src/Text/Text.tsx
CHANGED
|
@@ -1,14 +1,48 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import {
|
|
1
|
+
import React, { forwardRef } from 'react';
|
|
2
|
+
import { ResponsiveStyleValue } from '@marigold/system';
|
|
3
|
+
import {
|
|
4
|
+
PolymorphicComponentWithRef,
|
|
5
|
+
PolymorphicPropsWithRef,
|
|
6
|
+
} from '@marigold/types';
|
|
3
7
|
|
|
4
|
-
|
|
8
|
+
import { Box, BoxOwnProps } from '../Box';
|
|
5
9
|
|
|
6
|
-
export
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
+
export type TextOwnProps = {
|
|
11
|
+
align?: ResponsiveStyleValue<string>;
|
|
12
|
+
color?: ResponsiveStyleValue<string>;
|
|
13
|
+
cursor?: ResponsiveStyleValue<string>;
|
|
14
|
+
outline?: ResponsiveStyleValue<string>;
|
|
15
|
+
userSelect?: ResponsiveStyleValue<string>;
|
|
16
|
+
} & BoxOwnProps;
|
|
17
|
+
|
|
18
|
+
export type TextProps = PolymorphicPropsWithRef<TextOwnProps, 'span'>;
|
|
19
|
+
|
|
20
|
+
export const Text: PolymorphicComponentWithRef<TextOwnProps, 'span'> =
|
|
21
|
+
forwardRef(
|
|
22
|
+
(
|
|
23
|
+
{
|
|
24
|
+
as = 'span',
|
|
25
|
+
variant = 'body',
|
|
26
|
+
children,
|
|
27
|
+
className,
|
|
28
|
+
align,
|
|
29
|
+
color,
|
|
30
|
+
cursor,
|
|
31
|
+
outline,
|
|
32
|
+
userSelect,
|
|
33
|
+
...props
|
|
34
|
+
},
|
|
35
|
+
ref
|
|
36
|
+
) => (
|
|
37
|
+
<Box
|
|
38
|
+
{...props}
|
|
39
|
+
as={as}
|
|
40
|
+
variant={`text.${variant}`}
|
|
41
|
+
css={{ textAlign: align, color, cursor, outline, userSelect }}
|
|
42
|
+
className={className}
|
|
43
|
+
ref={ref}
|
|
44
|
+
>
|
|
10
45
|
{children}
|
|
11
46
|
</Box>
|
|
12
|
-
)
|
|
13
|
-
|
|
14
|
-
);
|
|
47
|
+
)
|
|
48
|
+
);
|
|
@@ -1,27 +1,74 @@
|
|
|
1
|
-
import { Meta, Story
|
|
2
|
-
import { Textarea } from '
|
|
1
|
+
import { ArgsTable, Canvas, Meta, Story } from '@storybook/addon-docs';
|
|
2
|
+
import { Textarea } from '../Textarea';
|
|
3
3
|
|
|
4
|
-
<Meta
|
|
4
|
+
<Meta
|
|
5
|
+
title="Components/Textarea"
|
|
6
|
+
argTypes={{
|
|
7
|
+
variant: {
|
|
8
|
+
control: {
|
|
9
|
+
type: 'text',
|
|
10
|
+
},
|
|
11
|
+
table: {
|
|
12
|
+
defaultValue: {
|
|
13
|
+
summary: 'default',
|
|
14
|
+
},
|
|
15
|
+
},
|
|
16
|
+
},
|
|
17
|
+
label: {
|
|
18
|
+
control: {
|
|
19
|
+
type: 'text',
|
|
20
|
+
},
|
|
21
|
+
description: 'Text above',
|
|
22
|
+
},
|
|
23
|
+
htmlFor: {
|
|
24
|
+
control: {
|
|
25
|
+
type: 'text',
|
|
26
|
+
},
|
|
27
|
+
description: 'Bind to label',
|
|
28
|
+
table: {
|
|
29
|
+
defaultValue: {
|
|
30
|
+
summary: 'textarea',
|
|
31
|
+
},
|
|
32
|
+
},
|
|
33
|
+
},
|
|
34
|
+
error: {
|
|
35
|
+
control: {
|
|
36
|
+
type: 'boolean',
|
|
37
|
+
},
|
|
38
|
+
description: 'Error',
|
|
39
|
+
table: {
|
|
40
|
+
defaultValue: {
|
|
41
|
+
summary: false,
|
|
42
|
+
},
|
|
43
|
+
},
|
|
44
|
+
},
|
|
45
|
+
errorMessage: {
|
|
46
|
+
control: {
|
|
47
|
+
type: 'text',
|
|
48
|
+
},
|
|
49
|
+
description: 'Error Message',
|
|
50
|
+
},
|
|
51
|
+
required: {
|
|
52
|
+
control: {
|
|
53
|
+
type: 'boolean',
|
|
54
|
+
},
|
|
55
|
+
table: {
|
|
56
|
+
defaultValue: {
|
|
57
|
+
summary: false,
|
|
58
|
+
},
|
|
59
|
+
},
|
|
60
|
+
},
|
|
61
|
+
}}
|
|
62
|
+
/>
|
|
5
63
|
|
|
6
64
|
# Textarea
|
|
7
65
|
|
|
8
|
-
|
|
66
|
+
export const Template = args => (
|
|
67
|
+
<Textarea placeholder="Placeholder..." label="Textarea Label" {...args} />
|
|
68
|
+
);
|
|
9
69
|
|
|
10
|
-
|
|
70
|
+
<Canvas>
|
|
71
|
+
<Story name="Default">{Template.bind({})}</Story>
|
|
72
|
+
</Canvas>
|
|
11
73
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
```tsx
|
|
15
|
-
import { Textarea } from '@marigold/components';
|
|
16
|
-
```
|
|
17
|
-
|
|
18
|
-
## Usage
|
|
19
|
-
|
|
20
|
-
<Preview>
|
|
21
|
-
<Story name="Textarea">
|
|
22
|
-
<Textarea placeholder="Placeholder" />
|
|
23
|
-
</Story>
|
|
24
|
-
<Story name="Textarea disabled">
|
|
25
|
-
<Textarea placeholder="Placeholder disabled" disabled />
|
|
26
|
-
</Story>
|
|
27
|
-
</Preview>
|
|
74
|
+
<ArgsTable story="Default" />
|