@marigold/components 0.1.0 → 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 +16 -1
- package/dist/Box/Box.d.ts +2 -1
- package/dist/Button/Button.d.ts +4 -6
- package/dist/Card/Card.d.ts +9 -0
- package/dist/Card/index.d.ts +1 -0
- package/dist/Checkbox/Checkbox.d.ts +3 -0
- package/dist/Checkbox/CheckboxIcons.d.ts +9 -0
- package/dist/Column/Column.d.ts +3 -1
- package/dist/Dialog/Dialog.d.ts +8 -1
- package/dist/Dialog/ModalDialog.d.ts +5 -0
- package/dist/Field/Field.d.ts +4 -2
- package/dist/Label/Label.d.ts +2 -1
- package/dist/Provider/MarigoldProvider.d.ts +3 -0
- package/dist/Provider/index.d.ts +3 -0
- package/dist/Radio/Radio.d.ts +3 -0
- 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 +11 -4
- package/dist/Stack/Stack.d.ts +1 -3
- package/dist/Textarea/Textarea.d.ts +2 -1
- package/dist/components.cjs.development.js +868 -357
- 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 +837 -359
- package/dist/components.esm.js.map +1 -1
- package/dist/index.d.ts +4 -0
- package/package.json +18 -3
- 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 +28 -38
- package/src/Alert/Alert.test.tsx +1 -1
- package/src/Alert/Alert.tsx +11 -33
- package/src/Badge/Badge.stories.mdx +48 -34
- package/src/Badge/Badge.test.tsx +7 -15
- package/src/Badge/Badge.tsx +1 -2
- package/src/Box/Box.stories.mdx +322 -26
- package/src/Box/Box.tsx +58 -50
- package/src/Button/Button.stories.mdx +54 -166
- package/src/Button/Button.test.tsx +48 -8
- package/src/Button/Button.tsx +47 -18
- 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 +76 -71
- package/src/Checkbox/Checkbox.test.tsx +70 -24
- package/src/Checkbox/Checkbox.tsx +68 -49
- package/src/Checkbox/CheckboxIcons.tsx +49 -0
- package/src/Column/Column.stories.mdx +39 -64
- package/src/Column/Column.test.tsx +8 -0
- package/src/Column/Column.tsx +12 -2
- package/src/Columns/Columns.stories.mdx +58 -240
- package/src/Container/Container.stories.mdx +8 -25
- package/src/Dialog/Dialog.stories.mdx +65 -56
- package/src/Dialog/Dialog.test.tsx +64 -24
- package/src/Dialog/Dialog.tsx +64 -12
- package/src/Dialog/ModalDialog.tsx +47 -0
- package/src/Divider/Divider.stories.mdx +28 -34
- package/src/Field/Field.stories.mdx +88 -48
- package/src/Field/Field.test.tsx +31 -40
- package/src/Field/Field.tsx +26 -21
- package/src/Heading/Heading.stories.mdx +30 -82
- package/src/Hidden/Hidden.stories.mdx +29 -54
- package/src/Image/Image.stories.mdx +26 -30
- package/src/Input/Input.stories.mdx +52 -36
- package/src/Label/Label.stories.mdx +47 -29
- package/src/Label/Label.test.tsx +15 -1
- package/src/Label/Label.tsx +20 -7
- package/src/Link/Link.stories.mdx +36 -29
- package/src/Menu/Menu.stories.mdx +71 -39
- package/src/Menu/Menu.test.tsx +4 -4
- package/src/Menu/Menu.tsx +12 -14
- package/src/MenuItem/MenuItem.stories.mdx +32 -27
- package/src/MenuItem/MenuItem.test.tsx +15 -11
- package/src/MenuItem/MenuItem.tsx +7 -10
- package/src/Message/Message.stories.mdx +35 -35
- package/src/Message/Message.tsx +2 -10
- 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 +78 -92
- package/src/Radio/Radio.test.tsx +57 -15
- package/src/Radio/Radio.tsx +71 -51
- 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 +70 -36
- package/src/Select/Select.test.tsx +279 -35
- package/src/Select/Select.tsx +151 -18
- package/src/Slider/Slider.stories.mdx +22 -49
- package/src/Stack/Stack.stories.mdx +40 -94
- package/src/Stack/Stack.test.tsx +84 -65
- package/src/Stack/Stack.tsx +25 -41
- package/src/Text/Text.stories.mdx +52 -52
- package/src/Text/Text.tsx +13 -14
- package/src/Textarea/Textarea.stories.mdx +65 -56
- package/src/Textarea/Textarea.test.tsx +4 -5
- package/src/Textarea/Textarea.tsx +28 -37
- package/src/ValidationMessage/ValidationMessage.stories.mdx +26 -26
- package/src/ValidationMessage/ValidationMessage.test.tsx +4 -4
- package/src/ValidationMessage/ValidationMessage.tsx +11 -12
- package/src/index.ts +5 -0
|
@@ -4,8 +4,8 @@ import { ThemeProvider } from '@marigold/system';
|
|
|
4
4
|
import { MenuItem } from './MenuItem';
|
|
5
5
|
|
|
6
6
|
const theme = {
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
menuItem: {
|
|
8
|
+
default: {
|
|
9
9
|
padding: '4px',
|
|
10
10
|
},
|
|
11
11
|
item: {
|
|
@@ -14,32 +14,34 @@ const theme = {
|
|
|
14
14
|
},
|
|
15
15
|
};
|
|
16
16
|
|
|
17
|
-
test('supports default variant
|
|
17
|
+
test('supports default variant', () => {
|
|
18
18
|
render(
|
|
19
19
|
<ThemeProvider theme={theme}>
|
|
20
|
-
<MenuItem title="menuItem"
|
|
20
|
+
<MenuItem title="menuItem">Item</MenuItem>
|
|
21
21
|
</ThemeProvider>
|
|
22
22
|
);
|
|
23
23
|
const menuItem = screen.getByTitle(/menuItem/);
|
|
24
24
|
|
|
25
|
-
expect(menuItem).toHaveStyle(`padding: 4px`);
|
|
25
|
+
expect(menuItem.parentElement).toHaveStyle(`padding: 4px`);
|
|
26
26
|
});
|
|
27
27
|
|
|
28
28
|
test('accepts other variant than default', () => {
|
|
29
29
|
render(
|
|
30
30
|
<ThemeProvider theme={theme}>
|
|
31
|
-
<MenuItem title="menuItem" variant="item"
|
|
31
|
+
<MenuItem title="menuItem" variant="item">
|
|
32
|
+
Item
|
|
33
|
+
</MenuItem>
|
|
32
34
|
</ThemeProvider>
|
|
33
35
|
);
|
|
34
36
|
const menuItem = screen.getByTitle(/menuItem/);
|
|
35
37
|
|
|
36
|
-
expect(menuItem).toHaveStyle(`padding: 8px`);
|
|
38
|
+
expect(menuItem.parentElement).toHaveStyle(`padding: 8px`);
|
|
37
39
|
});
|
|
38
40
|
|
|
39
41
|
test('renders correct HTML element', () => {
|
|
40
42
|
render(
|
|
41
43
|
<ThemeProvider theme={theme}>
|
|
42
|
-
<MenuItem title="menuItem"
|
|
44
|
+
<MenuItem title="menuItem">Item</MenuItem>
|
|
43
45
|
</ThemeProvider>
|
|
44
46
|
);
|
|
45
47
|
const menuItem = screen.getByTitle(/menuItem/);
|
|
@@ -50,10 +52,12 @@ test('renders correct HTML element', () => {
|
|
|
50
52
|
test('accepts custom styles prop className', () => {
|
|
51
53
|
render(
|
|
52
54
|
<ThemeProvider theme={theme}>
|
|
53
|
-
<MenuItem className="custom-class-name"
|
|
55
|
+
<MenuItem title="menuItem" className="custom-class-name">
|
|
56
|
+
Item
|
|
57
|
+
</MenuItem>
|
|
54
58
|
</ThemeProvider>
|
|
55
59
|
);
|
|
56
|
-
const menuItem = screen.
|
|
60
|
+
const menuItem = screen.getByText(/Item/).parentElement;
|
|
57
61
|
|
|
58
|
-
expect(menuItem
|
|
62
|
+
expect(menuItem).toHaveClass('custom-class-name');
|
|
59
63
|
});
|
|
@@ -1,26 +1,23 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import { useStyles } from '@marigold/system';
|
|
3
2
|
import { ComponentProps } from '@marigold/types';
|
|
4
3
|
import { Link } from '../Link';
|
|
4
|
+
import { Box } from '../Box';
|
|
5
5
|
|
|
6
6
|
export type MenuItemProps = {
|
|
7
7
|
variant?: string;
|
|
8
8
|
} & ComponentProps<typeof Link>;
|
|
9
9
|
|
|
10
10
|
export const MenuItem: React.FC<MenuItemProps> = ({
|
|
11
|
-
variant = '
|
|
11
|
+
variant = 'default',
|
|
12
12
|
className,
|
|
13
13
|
children,
|
|
14
14
|
...props
|
|
15
15
|
}) => {
|
|
16
|
-
const classNames = useStyles({
|
|
17
|
-
variant: `menu.${variant}`,
|
|
18
|
-
className,
|
|
19
|
-
});
|
|
20
|
-
|
|
21
16
|
return (
|
|
22
|
-
<
|
|
23
|
-
{
|
|
24
|
-
|
|
17
|
+
<Box variant={`menuItem.${variant}`} className={className}>
|
|
18
|
+
<Link variant="menuItemLink" {...props}>
|
|
19
|
+
{children}
|
|
20
|
+
</Link>
|
|
21
|
+
</Box>
|
|
25
22
|
);
|
|
26
23
|
};
|
|
@@ -1,44 +1,44 @@
|
|
|
1
|
-
import { Meta, Story
|
|
1
|
+
import { ArgsTable, Canvas, Meta, Story } from '@storybook/addon-docs';
|
|
2
2
|
import { Message } from './Message';
|
|
3
3
|
import { Text } from '../Text';
|
|
4
4
|
|
|
5
|
-
<Meta
|
|
5
|
+
<Meta
|
|
6
|
+
title="Components/Message"
|
|
7
|
+
argTypes={{
|
|
8
|
+
variant: {
|
|
9
|
+
control: {
|
|
10
|
+
type: 'select',
|
|
11
|
+
},
|
|
12
|
+
options: ['warning', 'error', 'info'],
|
|
13
|
+
description: 'Messaging in different colors and icons',
|
|
14
|
+
table: {
|
|
15
|
+
defaultValue: {
|
|
16
|
+
summary: 'info',
|
|
17
|
+
},
|
|
18
|
+
},
|
|
19
|
+
},
|
|
20
|
+
messageTitle: {
|
|
21
|
+
control: {
|
|
22
|
+
type: 'text',
|
|
23
|
+
},
|
|
24
|
+
description: 'Content',
|
|
25
|
+
type: {
|
|
26
|
+
required: true,
|
|
27
|
+
},
|
|
28
|
+
},
|
|
29
|
+
}}
|
|
30
|
+
/>
|
|
6
31
|
|
|
7
32
|
# Message
|
|
8
33
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
| Property | Type | Default |
|
|
16
|
-
| :------------------- | :------- | :------ |
|
|
17
|
-
| `messageTitle` | `string` | |
|
|
18
|
-
| `variant` (optional) | `string` | `info` |
|
|
19
|
-
|
|
20
|
-
## Import
|
|
21
|
-
|
|
22
|
-
```tsx
|
|
23
|
-
import { Message } from '@marigold/components';
|
|
24
|
-
```
|
|
25
|
-
|
|
26
|
-
## Usage
|
|
34
|
+
export const Template = args => (
|
|
35
|
+
<Message messageTitle="Danger Zone!" {...args}>
|
|
36
|
+
<Text>Hello, I am a simple message.</Text>
|
|
37
|
+
</Message>
|
|
38
|
+
);
|
|
27
39
|
|
|
28
40
|
<Canvas>
|
|
29
|
-
<Story name="
|
|
30
|
-
<Message variant="warning" messageTitle="Danger Zone!">
|
|
31
|
-
<Text>Hello, I am a simple warning message.</Text>
|
|
32
|
-
</Message>
|
|
33
|
-
<br />
|
|
34
|
-
<br />
|
|
35
|
-
<Message variant="error" messageTitle="Wrong here.">
|
|
36
|
-
<Text>Hello, I am a simple error message.</Text>
|
|
37
|
-
</Message>
|
|
38
|
-
<br />
|
|
39
|
-
<br />
|
|
40
|
-
<Message messageTitle="There is an update available.">
|
|
41
|
-
<Text>Hello, I am a simple info message.</Text>
|
|
42
|
-
</Message>
|
|
43
|
-
</Story>
|
|
41
|
+
<Story name="Default">{Template.bind({})}</Story>
|
|
44
42
|
</Canvas>
|
|
43
|
+
|
|
44
|
+
<ArgsTable story="Default" />
|
package/src/Message/Message.tsx
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { Exclamation, Info, Notification } from '@marigold/icons';
|
|
3
|
-
import { useStyles } from '@marigold/system';
|
|
4
3
|
import { ComponentProps } from '@marigold/types';
|
|
5
4
|
import { Box } from '../Box';
|
|
6
5
|
import { Heading } from '../Heading';
|
|
@@ -34,18 +33,11 @@ export const Message: React.FC<MessageProps> = ({
|
|
|
34
33
|
>
|
|
35
34
|
<Box display="flex" alignItems="center" variant="messages.title">
|
|
36
35
|
{icon}
|
|
37
|
-
<Heading
|
|
38
|
-
variant="h4"
|
|
39
|
-
className={useStyles({
|
|
40
|
-
css: {
|
|
41
|
-
display: 'inline',
|
|
42
|
-
},
|
|
43
|
-
})}
|
|
44
|
-
>
|
|
36
|
+
<Heading as="h4" variant="h4">
|
|
45
37
|
{messageTitle}
|
|
46
38
|
</Heading>
|
|
47
39
|
</Box>
|
|
48
|
-
<Box
|
|
40
|
+
<Box css={{ color: 'black' }}>{children}</Box>
|
|
49
41
|
</Box>
|
|
50
42
|
);
|
|
51
43
|
};
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { useTheme } from '@marigold/system';
|
|
3
|
+
import { render, screen } from '@testing-library/react';
|
|
4
|
+
import { useModal } from '@react-aria/overlays';
|
|
5
|
+
|
|
6
|
+
import { MarigoldProvider } from './MarigoldProvider';
|
|
7
|
+
|
|
8
|
+
// Setup
|
|
9
|
+
// ---------------
|
|
10
|
+
const theme = {
|
|
11
|
+
text: {
|
|
12
|
+
body: {
|
|
13
|
+
fontSize: 1,
|
|
14
|
+
color: 'black',
|
|
15
|
+
},
|
|
16
|
+
},
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
test('themes can be cascaded', () => {
|
|
20
|
+
const outerTheme = {
|
|
21
|
+
colors: {
|
|
22
|
+
primary: 'coral',
|
|
23
|
+
},
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
const innerTheme = {
|
|
27
|
+
colors: {
|
|
28
|
+
primary: 'gainsboro',
|
|
29
|
+
},
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
const Theme = ({ testId }: { testId: string }) => {
|
|
33
|
+
const { theme } = useTheme();
|
|
34
|
+
return <div data-testid={testId}>{JSON.stringify(theme, null, 2)}</div>;
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
render(
|
|
38
|
+
<MarigoldProvider theme={outerTheme}>
|
|
39
|
+
<>
|
|
40
|
+
<Theme testId="outer" />
|
|
41
|
+
<MarigoldProvider theme={innerTheme}>
|
|
42
|
+
<Theme testId="inner" />
|
|
43
|
+
</MarigoldProvider>
|
|
44
|
+
</>
|
|
45
|
+
</MarigoldProvider>
|
|
46
|
+
);
|
|
47
|
+
|
|
48
|
+
const outer = screen.getByTestId('outer');
|
|
49
|
+
const inner = screen.getByTestId('inner');
|
|
50
|
+
|
|
51
|
+
expect(outer.innerHTML).toMatchInlineSnapshot(`
|
|
52
|
+
"{
|
|
53
|
+
\\"colors\\": {
|
|
54
|
+
\\"primary\\": \\"coral\\"
|
|
55
|
+
}
|
|
56
|
+
}"
|
|
57
|
+
`);
|
|
58
|
+
expect(inner.innerHTML).toMatchInlineSnapshot(`
|
|
59
|
+
"{
|
|
60
|
+
\\"colors\\": {
|
|
61
|
+
\\"primary\\": \\"gainsboro\\"
|
|
62
|
+
}
|
|
63
|
+
}"
|
|
64
|
+
`);
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
// if theres no OverlayProvider you got an error with text: Modal is not contained within a provider
|
|
68
|
+
test('OverlayProvider is present and supports useModal hook', () => {
|
|
69
|
+
const ChildComponent: React.FC = ({ children }) => {
|
|
70
|
+
const { modalProps } = useModal();
|
|
71
|
+
return <div {...modalProps}>{children}</div>;
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
render(
|
|
75
|
+
<MarigoldProvider theme={theme}>
|
|
76
|
+
<ChildComponent>Test</ChildComponent>
|
|
77
|
+
</MarigoldProvider>
|
|
78
|
+
);
|
|
79
|
+
|
|
80
|
+
const childComp = screen.getByText('Test');
|
|
81
|
+
expect(childComp).toBeDefined();
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
// test('renders global styles for body and html based on root in theme', () => {
|
|
85
|
+
// const root = render(
|
|
86
|
+
// <MarigoldProvider
|
|
87
|
+
// theme={{
|
|
88
|
+
// fonts: {
|
|
89
|
+
// body: 'Inter',
|
|
90
|
+
// html: 'Roboto',
|
|
91
|
+
// },
|
|
92
|
+
// lineHeights: {
|
|
93
|
+
// body: 1.5,
|
|
94
|
+
// html: 1,
|
|
95
|
+
// },
|
|
96
|
+
// fontWeights: {
|
|
97
|
+
// body: 500,
|
|
98
|
+
// html: 700,
|
|
99
|
+
// },
|
|
100
|
+
// root: {
|
|
101
|
+
// body: {
|
|
102
|
+
// fontFamily: 'body',
|
|
103
|
+
// lineHeight: 'body',
|
|
104
|
+
// fontWeight: 'body',
|
|
105
|
+
// },
|
|
106
|
+
// html: {
|
|
107
|
+
// fontFamily: 'html',
|
|
108
|
+
// lineHeight: 'html',
|
|
109
|
+
// fontWeight: 'html',
|
|
110
|
+
// }
|
|
111
|
+
// },
|
|
112
|
+
// }}
|
|
113
|
+
// >
|
|
114
|
+
// <h1 title="h1">Hello</h1>
|
|
115
|
+
// </MarigoldProvider>
|
|
116
|
+
// );
|
|
117
|
+
|
|
118
|
+
// const html = window.getComputedStyle(root.baseElement.parentElement!);
|
|
119
|
+
// expect(html.fontFamily).toBe('Roboto');
|
|
120
|
+
// expect(html.fontWeight).toBe('700');
|
|
121
|
+
// expect(html.lineHeight).toBe('1');
|
|
122
|
+
// const body = window.getComputedStyle(root.baseElement);
|
|
123
|
+
// expect(body.fontFamily).toBe('Inter');
|
|
124
|
+
// expect(body.fontWeight).toBe('500');
|
|
125
|
+
// expect(body.lineHeight).toBe('1.5');
|
|
126
|
+
// });
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { OverlayProvider } from '@react-aria/overlays';
|
|
3
|
+
import { ThemeProvider, ThemeProviderProps } from '@marigold/system';
|
|
4
|
+
// import { Global } from '@emotion/react';
|
|
5
|
+
// import { css } from '@theme-ui/css';
|
|
6
|
+
|
|
7
|
+
// const GlobalStyles = () => {
|
|
8
|
+
// const theme = useTheme();
|
|
9
|
+
// const styles = css({
|
|
10
|
+
// body: { variant: 'root.body' },
|
|
11
|
+
// html: { variant: 'root.html' },
|
|
12
|
+
// })(theme);
|
|
13
|
+
|
|
14
|
+
// return <Global styles={styles} />;
|
|
15
|
+
// };
|
|
16
|
+
// a merge of the ThemeProvider and the react-aria OverlayProvider
|
|
17
|
+
export const MarigoldProvider: React.FC<ThemeProviderProps> = ({
|
|
18
|
+
theme,
|
|
19
|
+
children,
|
|
20
|
+
}) => {
|
|
21
|
+
return (
|
|
22
|
+
<ThemeProvider theme={theme}>
|
|
23
|
+
<OverlayProvider>
|
|
24
|
+
{/* <GlobalStyles /> */}
|
|
25
|
+
{children}
|
|
26
|
+
</OverlayProvider>
|
|
27
|
+
</ThemeProvider>
|
|
28
|
+
);
|
|
29
|
+
};
|
|
@@ -1,100 +1,86 @@
|
|
|
1
|
-
import { Meta, Story
|
|
2
|
-
import { useState } from 'react';
|
|
1
|
+
import { ArgsTable, Canvas, Meta, Story } from '@storybook/addon-docs';
|
|
3
2
|
import { Radio } from './Radio';
|
|
3
|
+
import { useState } from 'react';
|
|
4
4
|
|
|
5
|
-
<Meta
|
|
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
|
-
|
|
5
|
+
<Meta
|
|
6
|
+
title="Components/Radio"
|
|
7
|
+
parameters={{
|
|
8
|
+
actions: {
|
|
9
|
+
handles: ['click'],
|
|
10
|
+
},
|
|
11
|
+
}}
|
|
12
|
+
argTypes={{
|
|
13
|
+
id: {
|
|
14
|
+
control: {
|
|
15
|
+
type: 'text',
|
|
16
|
+
},
|
|
17
|
+
type: { required: true },
|
|
18
|
+
description: 'Unique ID',
|
|
19
|
+
},
|
|
20
|
+
variant: {
|
|
21
|
+
control: {
|
|
22
|
+
type: 'text',
|
|
23
|
+
},
|
|
24
|
+
description: 'Radio variant',
|
|
25
|
+
table: {
|
|
26
|
+
defaultValue: {
|
|
27
|
+
summary: 'default',
|
|
28
|
+
},
|
|
29
|
+
},
|
|
30
|
+
},
|
|
31
|
+
label: {
|
|
32
|
+
control: {
|
|
33
|
+
type: 'text',
|
|
34
|
+
},
|
|
35
|
+
description: 'Label',
|
|
36
|
+
},
|
|
37
|
+
required: {
|
|
38
|
+
control: {
|
|
39
|
+
type: 'boolean',
|
|
40
|
+
},
|
|
41
|
+
description: 'Require',
|
|
42
|
+
table: {
|
|
43
|
+
defaultValue: {
|
|
44
|
+
summary: false,
|
|
45
|
+
},
|
|
46
|
+
},
|
|
47
|
+
},
|
|
48
|
+
error: {
|
|
49
|
+
control: {
|
|
50
|
+
type: 'boolean',
|
|
51
|
+
},
|
|
52
|
+
description: 'Error',
|
|
53
|
+
table: {
|
|
54
|
+
defaultValue: {
|
|
55
|
+
summary: false,
|
|
56
|
+
},
|
|
57
|
+
},
|
|
58
|
+
},
|
|
59
|
+
errorMessage: {
|
|
60
|
+
control: {
|
|
61
|
+
type: 'text',
|
|
62
|
+
},
|
|
63
|
+
description: 'Error Message',
|
|
64
|
+
},
|
|
65
|
+
}}
|
|
66
|
+
/>
|
|
32
67
|
|
|
33
|
-
|
|
34
|
-
<Story name="RadioOne">
|
|
35
|
-
{() => {
|
|
36
|
-
const [state, setState] = React.useState('Mastercard');
|
|
37
|
-
const onChange = changeEvent => {
|
|
38
|
-
setState(changeEvent.currentTarget.value);
|
|
39
|
-
};
|
|
40
|
-
return (
|
|
41
|
-
<div>
|
|
42
|
-
<Radio
|
|
43
|
-
id="mc"
|
|
44
|
-
name="payment"
|
|
45
|
-
onChange={onChange}
|
|
46
|
-
checked={state === 'Mastercard'}
|
|
47
|
-
value="Mastercard"
|
|
48
|
-
label="Mastercard"
|
|
49
|
-
/>
|
|
50
|
-
<br />
|
|
51
|
-
<Radio
|
|
52
|
-
id="vi"
|
|
53
|
-
name="payment"
|
|
54
|
-
onChange={onChange}
|
|
55
|
-
checked={state === 'Visa'}
|
|
56
|
-
value="Visa"
|
|
57
|
-
label="Visa"
|
|
58
|
-
/>
|
|
59
|
-
<br />
|
|
60
|
-
<Radio
|
|
61
|
-
id="ae"
|
|
62
|
-
name="payment"
|
|
63
|
-
onChange={onChange}
|
|
64
|
-
checked={state === 'AmericanExpress'}
|
|
65
|
-
value="AmericanExpress"
|
|
66
|
-
label="AmericanExpress"
|
|
67
|
-
/>
|
|
68
|
-
</div>
|
|
69
|
-
);
|
|
70
|
-
}}
|
|
71
|
-
</Story>
|
|
72
|
-
</Canvas>
|
|
68
|
+
# Radio
|
|
73
69
|
|
|
74
|
-
|
|
70
|
+
export const Template = ({ onChange, checked, ...args }) => {
|
|
71
|
+
const [isChecked, setChecked] = useState(false);
|
|
72
|
+
return (
|
|
73
|
+
<Radio
|
|
74
|
+
onChange={() => setChecked(!isChecked)}
|
|
75
|
+
checked={isChecked}
|
|
76
|
+
label="Radio Label"
|
|
77
|
+
{...args}
|
|
78
|
+
/>
|
|
79
|
+
);
|
|
80
|
+
};
|
|
75
81
|
|
|
76
82
|
<Canvas>
|
|
77
|
-
<Story name="
|
|
78
|
-
<div>
|
|
79
|
-
<Radio id="radio" checked />
|
|
80
|
-
<Radio id="radio" disabled />
|
|
81
|
-
<Radio id="radio" checked disabled />
|
|
82
|
-
</div>
|
|
83
|
-
</Story>
|
|
83
|
+
<Story name="Default">{Template.bind({})}</Story>
|
|
84
84
|
</Canvas>
|
|
85
85
|
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
<Canvas>
|
|
89
|
-
<Story name="RadioThree">
|
|
90
|
-
<div>
|
|
91
|
-
<Radio
|
|
92
|
-
checked
|
|
93
|
-
id="required"
|
|
94
|
-
value="required"
|
|
95
|
-
required
|
|
96
|
-
label="This label is required"
|
|
97
|
-
/>
|
|
98
|
-
</div>
|
|
99
|
-
</Story>
|
|
100
|
-
</Canvas>
|
|
86
|
+
<ArgsTable story="Default" />
|
package/src/Radio/Radio.test.tsx
CHANGED
|
@@ -1,43 +1,85 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { render, screen } from '@testing-library/react';
|
|
3
3
|
import { Radio } from './Radio';
|
|
4
|
+
import { ThemeProvider } from '@marigold/system';
|
|
5
|
+
|
|
6
|
+
const theme = {
|
|
7
|
+
radio: {
|
|
8
|
+
default: {
|
|
9
|
+
m: '2px',
|
|
10
|
+
},
|
|
11
|
+
},
|
|
12
|
+
};
|
|
4
13
|
|
|
5
14
|
test('supports label prop', () => {
|
|
6
15
|
render(<Radio label="Test" id="test" title="radio" />);
|
|
7
|
-
const radio = screen.getByText(/Test/);
|
|
8
16
|
|
|
9
|
-
|
|
17
|
+
const radioLabel = screen.getByText(/Test/);
|
|
18
|
+
expect(radioLabel).toBeDefined();
|
|
10
19
|
});
|
|
11
20
|
|
|
12
|
-
test('supports required prop
|
|
21
|
+
test('supports required prop and renders required icon', () => {
|
|
13
22
|
render(<Radio label="Test" id="test" required title="radio" />);
|
|
14
|
-
const radio = screen.getByText(/Test/);
|
|
15
23
|
|
|
16
|
-
|
|
24
|
+
const label = screen.getByText(/Test/);
|
|
25
|
+
expect(label.nextSibling).toContainHTML('path d="M10.8');
|
|
17
26
|
});
|
|
18
27
|
|
|
19
28
|
test('supports default type', () => {
|
|
20
29
|
render(<Radio id="radio" title="radio" />);
|
|
21
|
-
const radio = screen.getByTitle(/radio/);
|
|
22
30
|
|
|
31
|
+
const radio = screen.getByTitle(/radio/);
|
|
23
32
|
expect(radio.getAttribute('type')).toEqual('radio');
|
|
24
33
|
});
|
|
25
34
|
|
|
26
35
|
test('renders <input> element', () => {
|
|
27
36
|
render(<Radio id="radio" title="radio" />);
|
|
28
|
-
const radio = screen.getByTitle(/radio/);
|
|
29
37
|
|
|
38
|
+
const radio = screen.getByTitle(/radio/);
|
|
30
39
|
expect(radio instanceof HTMLInputElement).toBeTruthy();
|
|
31
40
|
});
|
|
32
41
|
|
|
33
|
-
test('
|
|
34
|
-
render(
|
|
35
|
-
|
|
36
|
-
|
|
42
|
+
test('supports disabled prop', () => {
|
|
43
|
+
render(
|
|
44
|
+
<ThemeProvider theme={theme}>
|
|
45
|
+
<Radio id="test" title="radio" label="label" disabled />
|
|
46
|
+
</ThemeProvider>
|
|
47
|
+
);
|
|
48
|
+
|
|
49
|
+
const radio = screen.getByTitle(/radio/);
|
|
50
|
+
expect(radio).toHaveAttribute('disabled');
|
|
37
51
|
});
|
|
38
52
|
|
|
39
|
-
test('
|
|
40
|
-
render(
|
|
41
|
-
|
|
42
|
-
|
|
53
|
+
test('supports error and errorMessage prop', () => {
|
|
54
|
+
render(
|
|
55
|
+
<ThemeProvider theme={theme}>
|
|
56
|
+
<Radio id="test" title="radio" label="test" error errorMessage="error" />
|
|
57
|
+
</ThemeProvider>
|
|
58
|
+
);
|
|
59
|
+
|
|
60
|
+
const errorMessage = screen.getByText(/error/);
|
|
61
|
+
expect(errorMessage).toBeDefined();
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
test('supports checked radio', () => {
|
|
65
|
+
render(
|
|
66
|
+
<ThemeProvider theme={theme}>
|
|
67
|
+
<Radio id="test" title="radio" onChange={() => {}} checked />
|
|
68
|
+
</ThemeProvider>
|
|
69
|
+
);
|
|
70
|
+
|
|
71
|
+
const radio = screen.getByTitle(/radio/);
|
|
72
|
+
expect(radio).toBeDefined();
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
test('supports checked and disabled radio', () => {
|
|
76
|
+
render(
|
|
77
|
+
<ThemeProvider theme={theme}>
|
|
78
|
+
<Radio id="test" title="radio" onChange={() => {}} checked disabled />
|
|
79
|
+
</ThemeProvider>
|
|
80
|
+
);
|
|
81
|
+
|
|
82
|
+
const radio = screen.getByTitle(/radio/);
|
|
83
|
+
expect(radio).toBeDefined();
|
|
84
|
+
expect(radio).toHaveAttribute('disabled');
|
|
43
85
|
});
|