@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/Heading/Heading.tsx
CHANGED
|
@@ -1,16 +1,19 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import {
|
|
2
|
+
import { ComponentProps } from '@marigold/types';
|
|
3
|
+
import { Box } from '../Box';
|
|
3
4
|
|
|
4
|
-
type HeadingProps = {
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
export type HeadingProps = {
|
|
6
|
+
as?: 'h1' | 'h2' | 'h3' | 'h4' | 'h5' | 'h6';
|
|
7
|
+
variant?: string;
|
|
8
|
+
} & ComponentProps<'h1'>;
|
|
7
9
|
|
|
8
|
-
export const Heading
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
10
|
+
export const Heading: React.FC<HeadingProps> = ({
|
|
11
|
+
as = 'h2',
|
|
12
|
+
variant = 'h2',
|
|
13
|
+
children,
|
|
14
|
+
...props
|
|
15
|
+
}) => (
|
|
16
|
+
<Box {...props} as={as} variant={`text.${variant}`}>
|
|
17
|
+
{children}
|
|
18
|
+
</Box>
|
|
16
19
|
);
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { ArgsTable, Canvas, Meta, Story } from '@storybook/addon-docs';
|
|
2
|
+
import { Hidden } from './Hidden';
|
|
3
|
+
import { Text } from '../Text';
|
|
4
|
+
|
|
5
|
+
<Meta
|
|
6
|
+
title="Components/Hidden"
|
|
7
|
+
argTypes={{
|
|
8
|
+
show: {
|
|
9
|
+
control: {
|
|
10
|
+
type: 'boolean',
|
|
11
|
+
},
|
|
12
|
+
options: [true, false],
|
|
13
|
+
description: 'Show or hide',
|
|
14
|
+
table: {
|
|
15
|
+
defaultValue: {
|
|
16
|
+
summary: false,
|
|
17
|
+
},
|
|
18
|
+
},
|
|
19
|
+
},
|
|
20
|
+
}}
|
|
21
|
+
/>
|
|
22
|
+
|
|
23
|
+
# Hidden
|
|
24
|
+
|
|
25
|
+
export const Template = args => (
|
|
26
|
+
<div>
|
|
27
|
+
<Text>Change the "show" switch to "true"</Text>
|
|
28
|
+
<Hidden {...args}>
|
|
29
|
+
<br />
|
|
30
|
+
<Text>Hello here I am!</Text>
|
|
31
|
+
</Hidden>
|
|
32
|
+
</div>
|
|
33
|
+
);
|
|
34
|
+
|
|
35
|
+
<Canvas>
|
|
36
|
+
<Story name="Default">{Template.bind({})}</Story>
|
|
37
|
+
</Canvas>
|
|
38
|
+
|
|
39
|
+
<ArgsTable story="Default" />
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { render, screen } from '@testing-library/react';
|
|
3
|
+
import { Hidden } from './Hidden';
|
|
4
|
+
|
|
5
|
+
test('text is not visible, show prop = false', () => {
|
|
6
|
+
render(<Hidden>Default</Hidden>);
|
|
7
|
+
const hidden = screen.getByText('Default');
|
|
8
|
+
|
|
9
|
+
expect(hidden).not.toBeVisible();
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
test('support show prop = true', () => {
|
|
13
|
+
render(<Hidden show={true}>Default</Hidden>);
|
|
14
|
+
const hidden = screen.getByText('Default');
|
|
15
|
+
|
|
16
|
+
expect(hidden).toBeVisible();
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
test('renders correct HTML element', () => {
|
|
20
|
+
render(<Hidden>Default</Hidden>);
|
|
21
|
+
const hidden = screen.getByText('Default');
|
|
22
|
+
|
|
23
|
+
expect(hidden instanceof HTMLSpanElement).toBeTruthy();
|
|
24
|
+
});
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { Box } from '../Box';
|
|
3
|
+
|
|
4
|
+
export type HiddenProps = {
|
|
5
|
+
show?: boolean;
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
export const Hidden: React.FC<HiddenProps> = ({
|
|
9
|
+
show = false,
|
|
10
|
+
children,
|
|
11
|
+
...props
|
|
12
|
+
}) => (
|
|
13
|
+
<Box {...props} as="span" display={show ? 'display' : 'none'}>
|
|
14
|
+
{children}
|
|
15
|
+
</Box>
|
|
16
|
+
);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './Hidden';
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { ArgsTable, Canvas, Meta, Story } from '@storybook/addon-docs';
|
|
2
|
+
import { Image } from './Image';
|
|
3
|
+
import image1 from '../../../images/src/type_logo.png';
|
|
4
|
+
|
|
5
|
+
<Meta
|
|
6
|
+
title="Components/Image"
|
|
7
|
+
argTypes={{
|
|
8
|
+
variant: {
|
|
9
|
+
control: {
|
|
10
|
+
type: 'text',
|
|
11
|
+
},
|
|
12
|
+
description: 'there is only one variant',
|
|
13
|
+
table: {
|
|
14
|
+
defaultValue: {
|
|
15
|
+
summary: 'fullWidth',
|
|
16
|
+
},
|
|
17
|
+
},
|
|
18
|
+
},
|
|
19
|
+
alt: {
|
|
20
|
+
control: {
|
|
21
|
+
type: 'text',
|
|
22
|
+
},
|
|
23
|
+
description: 'Description text for screenreaders'
|
|
24
|
+
},
|
|
25
|
+
}}
|
|
26
|
+
/>
|
|
27
|
+
|
|
28
|
+
# Image
|
|
29
|
+
|
|
30
|
+
export const Template = args => <Image src={image1} alt="marigold_logo" />;
|
|
31
|
+
|
|
32
|
+
<Canvas>
|
|
33
|
+
<Story name="Default">{Template.bind({})}</Story>
|
|
34
|
+
</Canvas>
|
|
35
|
+
|
|
36
|
+
<ArgsTable story="Default" />
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { render, screen } from '@testing-library/react';
|
|
3
|
+
import { ThemeProvider } from '@marigold/system';
|
|
4
|
+
import { Image } from './Image';
|
|
5
|
+
|
|
6
|
+
const theme = {
|
|
7
|
+
images: {
|
|
8
|
+
fullWidth: {
|
|
9
|
+
alignItems: 'center',
|
|
10
|
+
},
|
|
11
|
+
logos: {
|
|
12
|
+
alignItems: 'right',
|
|
13
|
+
},
|
|
14
|
+
},
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
test('supports default variant and themeSection', () => {
|
|
18
|
+
render(
|
|
19
|
+
<ThemeProvider theme={theme}>
|
|
20
|
+
<Image title="images" />
|
|
21
|
+
</ThemeProvider>
|
|
22
|
+
);
|
|
23
|
+
const img = screen.getByTitle(/images/);
|
|
24
|
+
|
|
25
|
+
expect(img).toHaveStyle(`align-items: center`);
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
test('accepts other variant than default', () => {
|
|
29
|
+
render(
|
|
30
|
+
<ThemeProvider theme={theme}>
|
|
31
|
+
<Image title="logos" variant="logos" />
|
|
32
|
+
</ThemeProvider>
|
|
33
|
+
);
|
|
34
|
+
const img = screen.getByTitle(/logos/);
|
|
35
|
+
|
|
36
|
+
expect(img).toHaveStyle(`align-items: right`);
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
test('renders correct HTML element', () => {
|
|
40
|
+
render(
|
|
41
|
+
<ThemeProvider theme={theme}>
|
|
42
|
+
<Image title="default" />
|
|
43
|
+
</ThemeProvider>
|
|
44
|
+
);
|
|
45
|
+
const img = screen.getByTitle(/default/);
|
|
46
|
+
|
|
47
|
+
expect(img instanceof HTMLImageElement).toBeTruthy();
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
test('accept alt', () => {
|
|
51
|
+
render(
|
|
52
|
+
<ThemeProvider theme={theme}>
|
|
53
|
+
<Image alt="altText" title="default" />
|
|
54
|
+
</ThemeProvider>
|
|
55
|
+
);
|
|
56
|
+
const img = screen.getByTitle(/default/);
|
|
57
|
+
|
|
58
|
+
expect(img.getAttribute('alt')).toEqual('altText');
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
test('accepts custom styles prop className', () => {
|
|
62
|
+
render(
|
|
63
|
+
<ThemeProvider theme={theme}>
|
|
64
|
+
<Image className="custom-class-name" title="image" />
|
|
65
|
+
</ThemeProvider>
|
|
66
|
+
);
|
|
67
|
+
const image = screen.getByTitle(/image/);
|
|
68
|
+
|
|
69
|
+
expect(image.className).toMatch('custom-class-name');
|
|
70
|
+
});
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { ComponentProps } from '@marigold/types';
|
|
3
|
+
import { Box } from '../Box';
|
|
4
|
+
|
|
5
|
+
export type ImageProps = {
|
|
6
|
+
variant?: string;
|
|
7
|
+
children?: never;
|
|
8
|
+
} & ComponentProps<'img'>;
|
|
9
|
+
|
|
10
|
+
export const Image: React.FC<ImageProps> = ({
|
|
11
|
+
variant = 'fullWidth',
|
|
12
|
+
...props
|
|
13
|
+
}) => <Box {...props} as="img" variant={`images.${variant}`} />;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './Image';
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { ArgsTable, Canvas, Meta, Story } from '@storybook/addon-docs';
|
|
2
|
+
import { Input } from './Input';
|
|
3
|
+
import { Label } from '../Label';
|
|
4
|
+
|
|
5
|
+
<Meta
|
|
6
|
+
title="Components/Input"
|
|
7
|
+
argTypes={{
|
|
8
|
+
variant: {
|
|
9
|
+
control: {
|
|
10
|
+
type: 'text',
|
|
11
|
+
},
|
|
12
|
+
description: '?',
|
|
13
|
+
table: {
|
|
14
|
+
defaultValue: {
|
|
15
|
+
summary: 'default',
|
|
16
|
+
},
|
|
17
|
+
},
|
|
18
|
+
},
|
|
19
|
+
type: {
|
|
20
|
+
control: {
|
|
21
|
+
type: 'select',
|
|
22
|
+
},
|
|
23
|
+
options: [
|
|
24
|
+
'date',
|
|
25
|
+
'datetime-local',
|
|
26
|
+
'email',
|
|
27
|
+
'month',
|
|
28
|
+
'number',
|
|
29
|
+
'password',
|
|
30
|
+
'search',
|
|
31
|
+
'tel',
|
|
32
|
+
'text',
|
|
33
|
+
'time',
|
|
34
|
+
'time',
|
|
35
|
+
'url',
|
|
36
|
+
'week',
|
|
37
|
+
],
|
|
38
|
+
type: { required: true },
|
|
39
|
+
table: {
|
|
40
|
+
defaultValue: {
|
|
41
|
+
summary: 'text',
|
|
42
|
+
},
|
|
43
|
+
},
|
|
44
|
+
},
|
|
45
|
+
}}
|
|
46
|
+
/>
|
|
47
|
+
|
|
48
|
+
# Input
|
|
49
|
+
|
|
50
|
+
export const Template = args => (
|
|
51
|
+
<Label htmlFor="input">
|
|
52
|
+
Label
|
|
53
|
+
<Input id="input" placeholder="Placeholder..." {...args} />
|
|
54
|
+
</Label>
|
|
55
|
+
);
|
|
56
|
+
|
|
57
|
+
<Canvas>
|
|
58
|
+
<Story name="Default">{Template.bind({})}</Story>
|
|
59
|
+
</Canvas>
|
|
60
|
+
|
|
61
|
+
<ArgsTable story="Default" />
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { render, screen } from '@testing-library/react';
|
|
3
|
+
import { ThemeProvider } from '@marigold/system';
|
|
4
|
+
import { Input } from './Input';
|
|
5
|
+
|
|
6
|
+
const theme = {
|
|
7
|
+
input: {
|
|
8
|
+
default: {
|
|
9
|
+
fontFamily: 'Inter',
|
|
10
|
+
},
|
|
11
|
+
input2: {
|
|
12
|
+
fontFamily: 'Roboto',
|
|
13
|
+
},
|
|
14
|
+
},
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
test('supports default variant and themeSection', () => {
|
|
18
|
+
render(
|
|
19
|
+
<ThemeProvider theme={theme}>
|
|
20
|
+
<Input title="input" />
|
|
21
|
+
</ThemeProvider>
|
|
22
|
+
);
|
|
23
|
+
const input = screen.getByTitle('input');
|
|
24
|
+
|
|
25
|
+
expect(input).toHaveStyle(`font-family: Inter`);
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
test('accepts other variant than default', () => {
|
|
29
|
+
render(
|
|
30
|
+
<ThemeProvider theme={theme}>
|
|
31
|
+
<Input title="input" variant="input2" />
|
|
32
|
+
</ThemeProvider>
|
|
33
|
+
);
|
|
34
|
+
const input = screen.getByTitle('input');
|
|
35
|
+
|
|
36
|
+
expect(input).toHaveStyle(`font-family: Roboto`);
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
test('renders correct HTML element', () => {
|
|
40
|
+
render(
|
|
41
|
+
<ThemeProvider theme={theme}>
|
|
42
|
+
<Input title="input" />
|
|
43
|
+
</ThemeProvider>
|
|
44
|
+
);
|
|
45
|
+
const input = screen.getByTitle('input');
|
|
46
|
+
|
|
47
|
+
expect(input instanceof HTMLInputElement).toBeTruthy();
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
test('supports custom prop', () => {
|
|
51
|
+
render(
|
|
52
|
+
<ThemeProvider theme={theme}>
|
|
53
|
+
<Input title="input" placeholder="placeholder" />
|
|
54
|
+
</ThemeProvider>
|
|
55
|
+
);
|
|
56
|
+
const input = screen.getByTitle('input');
|
|
57
|
+
|
|
58
|
+
expect(input).toHaveAttribute('placeholder');
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
test('accepts custom styles prop className', () => {
|
|
62
|
+
render(
|
|
63
|
+
<ThemeProvider theme={theme}>
|
|
64
|
+
<Input className="custom-class-name" title="input" />
|
|
65
|
+
</ThemeProvider>
|
|
66
|
+
);
|
|
67
|
+
const input = screen.getByTitle(/input/);
|
|
68
|
+
|
|
69
|
+
expect(input.className).toMatch('custom-class-name');
|
|
70
|
+
});
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { ComponentProps } from '@marigold/types';
|
|
3
|
+
import { Box } from '../Box';
|
|
4
|
+
|
|
5
|
+
export type InputProps = {
|
|
6
|
+
variant?: string;
|
|
7
|
+
} & ComponentProps<'input'>;
|
|
8
|
+
|
|
9
|
+
export const Input: React.FC<InputProps> = ({
|
|
10
|
+
variant = 'default',
|
|
11
|
+
type = 'text',
|
|
12
|
+
...props
|
|
13
|
+
}) => <Box {...props} as="input" type={type} variant={`input.${variant}`} />;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './Input';
|
|
@@ -1,36 +1,52 @@
|
|
|
1
|
-
import { Meta, Story
|
|
1
|
+
import { ArgsTable, Canvas, Meta, Story } from '@storybook/addon-docs';
|
|
2
2
|
import { Label } from './Label';
|
|
3
3
|
|
|
4
|
-
<Meta
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
4
|
+
<Meta
|
|
5
|
+
title="Components/Label"
|
|
6
|
+
argTypes={{
|
|
7
|
+
variant: {
|
|
8
|
+
control: {
|
|
9
|
+
type: 'text',
|
|
10
|
+
},
|
|
11
|
+
description: '?',
|
|
12
|
+
table: {
|
|
13
|
+
defaultValue: {
|
|
14
|
+
summary: 'above',
|
|
15
|
+
},
|
|
16
|
+
},
|
|
17
|
+
},
|
|
18
|
+
htmlFor: {
|
|
19
|
+
control: {
|
|
20
|
+
type: 'text',
|
|
21
|
+
},
|
|
22
|
+
type: {
|
|
23
|
+
required: true,
|
|
24
|
+
},
|
|
25
|
+
},
|
|
26
|
+
required: {
|
|
27
|
+
control: {
|
|
28
|
+
type: 'boolean',
|
|
29
|
+
},
|
|
30
|
+
description: 'Adds required Icon to label',
|
|
31
|
+
table: {
|
|
32
|
+
defaultValue: {
|
|
33
|
+
summary: false,
|
|
34
|
+
},
|
|
35
|
+
},
|
|
36
|
+
},
|
|
37
|
+
}}
|
|
38
|
+
/>
|
|
39
|
+
|
|
40
|
+
# Label
|
|
41
|
+
|
|
42
|
+
export const Template = args => (
|
|
43
|
+
<Label htmlFor="input" {...args}>
|
|
44
|
+
Label
|
|
45
|
+
</Label>
|
|
46
|
+
);
|
|
47
|
+
|
|
48
|
+
<Canvas>
|
|
49
|
+
<Story name="Default">{Template.bind({})}</Story>
|
|
50
|
+
</Canvas>
|
|
51
|
+
|
|
52
|
+
<ArgsTable story="Default" />
|
package/src/Label/Label.test.tsx
CHANGED
|
@@ -1,59 +1,88 @@
|
|
|
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
|
import { Label } from './Label';
|
|
5
5
|
|
|
6
6
|
const theme = {
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
label: {
|
|
8
|
+
above: {
|
|
9
9
|
fontFamily: 'Inter Regular',
|
|
10
10
|
},
|
|
11
|
+
myLabel: {
|
|
12
|
+
fontFamily: 'Oswald Regular',
|
|
13
|
+
},
|
|
11
14
|
},
|
|
12
15
|
};
|
|
13
16
|
|
|
14
17
|
test('supports default variant and themeSection', () => {
|
|
15
18
|
render(
|
|
16
|
-
<
|
|
19
|
+
<ThemeProvider theme={theme}>
|
|
17
20
|
<Label htmlFor="labelId">label</Label>
|
|
18
|
-
</
|
|
21
|
+
</ThemeProvider>
|
|
19
22
|
);
|
|
20
23
|
const label = screen.getByText(/label/);
|
|
21
24
|
|
|
22
25
|
expect(label).toHaveStyle(`font-family: Inter Regular`);
|
|
23
26
|
});
|
|
24
27
|
|
|
28
|
+
test('supports other variant than default', () => {
|
|
29
|
+
render(
|
|
30
|
+
<ThemeProvider theme={theme}>
|
|
31
|
+
<Label htmlFor="labelId" variant="myLabel">
|
|
32
|
+
label
|
|
33
|
+
</Label>
|
|
34
|
+
</ThemeProvider>
|
|
35
|
+
);
|
|
36
|
+
const label = screen.getByText(/label/);
|
|
37
|
+
|
|
38
|
+
expect(label).toHaveStyle(`font-family: Oswald Regular`);
|
|
39
|
+
});
|
|
40
|
+
|
|
25
41
|
test('supports htmlFor prop', () => {
|
|
26
42
|
render(
|
|
27
|
-
<
|
|
43
|
+
<ThemeProvider theme={theme}>
|
|
28
44
|
<Label htmlFor="labelId">label</Label>
|
|
29
|
-
</
|
|
45
|
+
</ThemeProvider>
|
|
30
46
|
);
|
|
31
47
|
const label = screen.getByText(/label/);
|
|
32
48
|
|
|
33
49
|
expect(label).toHaveAttribute('for');
|
|
34
50
|
});
|
|
35
51
|
|
|
52
|
+
test('supports required prop', () => {
|
|
53
|
+
render(
|
|
54
|
+
<ThemeProvider theme={theme}>
|
|
55
|
+
<Label htmlFor="labelId" required>
|
|
56
|
+
label
|
|
57
|
+
</Label>
|
|
58
|
+
</ThemeProvider>
|
|
59
|
+
);
|
|
60
|
+
const label = screen.getByText(/label/);
|
|
61
|
+
const parent = label.parentElement;
|
|
62
|
+
|
|
63
|
+
expect(parent instanceof HTMLSpanElement).toBeTruthy();
|
|
64
|
+
});
|
|
65
|
+
|
|
36
66
|
test('renders <label> element', () => {
|
|
37
67
|
render(
|
|
38
|
-
<
|
|
68
|
+
<ThemeProvider theme={theme}>
|
|
39
69
|
<Label htmlFor="labelId">label</Label>
|
|
40
|
-
</
|
|
70
|
+
</ThemeProvider>
|
|
41
71
|
);
|
|
42
72
|
const label = screen.getByText(/label/);
|
|
43
73
|
|
|
44
74
|
expect(label instanceof HTMLLabelElement).toBeTruthy();
|
|
45
75
|
});
|
|
46
76
|
|
|
47
|
-
test('
|
|
77
|
+
test('accepts custom styles prop className', () => {
|
|
48
78
|
render(
|
|
49
|
-
<
|
|
50
|
-
<Label htmlFor="labelId"
|
|
79
|
+
<ThemeProvider theme={theme}>
|
|
80
|
+
<Label htmlFor="labelId" className="custom-class-name" title="label">
|
|
51
81
|
label
|
|
52
82
|
</Label>
|
|
53
|
-
</
|
|
83
|
+
</ThemeProvider>
|
|
54
84
|
);
|
|
55
|
-
const label = screen.
|
|
85
|
+
const label = screen.getByTitle(/label/);
|
|
56
86
|
|
|
57
|
-
expect(label).
|
|
58
|
-
expect(label).toHaveStyle(`font-family: Inter Regular`);
|
|
87
|
+
expect(label.className).toMatch('custom-class-name');
|
|
59
88
|
});
|
package/src/Label/Label.tsx
CHANGED
|
@@ -1,22 +1,31 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import {
|
|
2
|
+
import { ComponentProps } from '@marigold/types';
|
|
3
|
+
import { Required } from '@marigold/icons';
|
|
3
4
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
import { Box } from '../Box';
|
|
6
|
+
|
|
7
|
+
export type LabelProps = {
|
|
8
|
+
htmlFor?: string;
|
|
9
|
+
variant?: string;
|
|
10
|
+
required?: boolean;
|
|
11
|
+
} & ComponentProps<'label'>;
|
|
7
12
|
|
|
8
|
-
export const Label
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
>
|
|
13
|
+
export const Label: React.FC<LabelProps> = ({
|
|
14
|
+
variant = 'above',
|
|
15
|
+
required,
|
|
16
|
+
children,
|
|
17
|
+
...props
|
|
18
|
+
}) => {
|
|
19
|
+
return required ? (
|
|
20
|
+
<Box as="span" display="inline-flex" alignItems="center">
|
|
21
|
+
<Box {...props} as="label" variant={`label.${variant}`}>
|
|
18
22
|
{children}
|
|
19
23
|
</Box>
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
)
|
|
24
|
+
{required && <Box as={Required} size={16} css={{ color: 'red60' }} />}
|
|
25
|
+
</Box>
|
|
26
|
+
) : (
|
|
27
|
+
<Box {...props} as="label" variant={`label.${variant}`}>
|
|
28
|
+
{children}
|
|
29
|
+
</Box>
|
|
30
|
+
);
|
|
31
|
+
};
|