@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
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { render, screen } from '@testing-library/react';
|
|
3
|
+
import { ThemeProvider } from '@marigold/system';
|
|
4
|
+
import { Message } from './Message';
|
|
5
|
+
|
|
6
|
+
const theme = {
|
|
7
|
+
messages: {
|
|
8
|
+
info: {
|
|
9
|
+
alignItems: 'center',
|
|
10
|
+
},
|
|
11
|
+
warning: {
|
|
12
|
+
alignItems: 'right',
|
|
13
|
+
},
|
|
14
|
+
error: {
|
|
15
|
+
alignItems: 'left',
|
|
16
|
+
},
|
|
17
|
+
},
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
test('supports default variant and themeSection', () => {
|
|
21
|
+
render(
|
|
22
|
+
<ThemeProvider theme={theme}>
|
|
23
|
+
<Message data-testid="messages" messageTitle="Default">
|
|
24
|
+
Default
|
|
25
|
+
</Message>
|
|
26
|
+
</ThemeProvider>
|
|
27
|
+
);
|
|
28
|
+
const message = screen.getByTestId(/messages/);
|
|
29
|
+
|
|
30
|
+
expect(message).toHaveStyle(`align-items: center`);
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
test('accepts other variant than default', () => {
|
|
34
|
+
render(
|
|
35
|
+
<ThemeProvider theme={theme}>
|
|
36
|
+
<Message data-testid="messages" messageTitle="info" variant="warning">
|
|
37
|
+
Danger
|
|
38
|
+
</Message>
|
|
39
|
+
</ThemeProvider>
|
|
40
|
+
);
|
|
41
|
+
const message = screen.getByTestId(/messages/);
|
|
42
|
+
|
|
43
|
+
expect(message).toHaveStyle(`align-items: right`);
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
test('accepts other third variant than default', () => {
|
|
47
|
+
render(
|
|
48
|
+
<ThemeProvider theme={theme}>
|
|
49
|
+
<Message data-testid="messages" messageTitle="error" variant="error">
|
|
50
|
+
error
|
|
51
|
+
</Message>
|
|
52
|
+
</ThemeProvider>
|
|
53
|
+
);
|
|
54
|
+
const message = screen.getByTestId(/messages/);
|
|
55
|
+
|
|
56
|
+
expect(message).toHaveStyle(`align-items: left`);
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
test('renders correct HTML element', () => {
|
|
60
|
+
render(
|
|
61
|
+
<ThemeProvider theme={theme}>
|
|
62
|
+
<Message data-testid="messages" messageTitle="messages">
|
|
63
|
+
Default
|
|
64
|
+
</Message>
|
|
65
|
+
</ThemeProvider>
|
|
66
|
+
);
|
|
67
|
+
const message = screen.getByTestId(/messages/);
|
|
68
|
+
|
|
69
|
+
expect(message instanceof HTMLDivElement).toBeTruthy();
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
test('accepts custom styles prop className', () => {
|
|
73
|
+
render(
|
|
74
|
+
<ThemeProvider theme={theme}>
|
|
75
|
+
<Message
|
|
76
|
+
className="custom-class-name"
|
|
77
|
+
data-testid="message"
|
|
78
|
+
messageTitle="message"
|
|
79
|
+
>
|
|
80
|
+
message
|
|
81
|
+
</Message>
|
|
82
|
+
</ThemeProvider>
|
|
83
|
+
);
|
|
84
|
+
const message = screen.getByTestId(/message/);
|
|
85
|
+
|
|
86
|
+
expect(message.className).toMatch('custom-class-name');
|
|
87
|
+
});
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { Exclamation, Info, Notification } from '@marigold/icons';
|
|
3
|
+
import { ComponentProps } from '@marigold/types';
|
|
4
|
+
import { Box } from '../Box';
|
|
5
|
+
import { Heading } from '../Heading';
|
|
6
|
+
|
|
7
|
+
export type MessageProps = {
|
|
8
|
+
messageTitle: string;
|
|
9
|
+
variant?: string;
|
|
10
|
+
} & ComponentProps<'div'>;
|
|
11
|
+
|
|
12
|
+
export const Message: React.FC<MessageProps> = ({
|
|
13
|
+
messageTitle,
|
|
14
|
+
variant = 'info',
|
|
15
|
+
className,
|
|
16
|
+
children,
|
|
17
|
+
...props
|
|
18
|
+
}) => {
|
|
19
|
+
var icon = <Info />;
|
|
20
|
+
if (variant === 'warning') {
|
|
21
|
+
icon = <Notification />;
|
|
22
|
+
}
|
|
23
|
+
if (variant === 'error') {
|
|
24
|
+
icon = <Exclamation />;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
return (
|
|
28
|
+
<Box
|
|
29
|
+
display="inline-block"
|
|
30
|
+
variant={`messages.${variant}`}
|
|
31
|
+
className={className}
|
|
32
|
+
{...props}
|
|
33
|
+
>
|
|
34
|
+
<Box display="flex" alignItems="center" variant="messages.title">
|
|
35
|
+
{icon}
|
|
36
|
+
<Heading as="h4" variant="h4">
|
|
37
|
+
{messageTitle}
|
|
38
|
+
</Heading>
|
|
39
|
+
</Box>
|
|
40
|
+
<Box css={{ color: 'black' }}>{children}</Box>
|
|
41
|
+
</Box>
|
|
42
|
+
);
|
|
43
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './Message';
|
|
@@ -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,89 +1,86 @@
|
|
|
1
|
-
import { Meta, Story
|
|
2
|
-
import {
|
|
1
|
+
import { ArgsTable, Canvas, Meta, Story } from '@storybook/addon-docs';
|
|
2
|
+
import { Radio } from './Radio';
|
|
3
3
|
import { useState } from 'react';
|
|
4
4
|
|
|
5
|
-
<Meta
|
|
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
|
+
/>
|
|
6
67
|
|
|
7
|
-
# Radio
|
|
68
|
+
# Radio
|
|
8
69
|
|
|
9
|
-
|
|
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
|
+
};
|
|
10
81
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
82
|
+
<Canvas>
|
|
83
|
+
<Story name="Default">{Template.bind({})}</Story>
|
|
84
|
+
</Canvas>
|
|
14
85
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
| Property | Type | Default |
|
|
18
|
-
| :-------- | :---------- | :-------- |
|
|
19
|
-
| `variant` | `string` | `'radio'` |
|
|
20
|
-
| `css` | `css props` | |
|
|
21
|
-
|
|
22
|
-
## Import
|
|
23
|
-
|
|
24
|
-
```tsx
|
|
25
|
-
import { Radio } from '@marigold/components';
|
|
26
|
-
```
|
|
27
|
-
|
|
28
|
-
## Usage
|
|
29
|
-
|
|
30
|
-
### Radio standard labeled
|
|
31
|
-
|
|
32
|
-
<Preview>
|
|
33
|
-
<Story name="RadioOne">
|
|
34
|
-
{() => {
|
|
35
|
-
const [state, setState] = React.useState('Mastercard');
|
|
36
|
-
const onChange = changeEvent => {
|
|
37
|
-
setState(changeEvent.currentTarget.value);
|
|
38
|
-
};
|
|
39
|
-
return (
|
|
40
|
-
<div>
|
|
41
|
-
<Label htmlFor="mc">
|
|
42
|
-
<Radio
|
|
43
|
-
id="mc"
|
|
44
|
-
name="payment"
|
|
45
|
-
onChange={onChange}
|
|
46
|
-
checked={state === 'Mastercard'}
|
|
47
|
-
value="Mastercard"
|
|
48
|
-
/>
|
|
49
|
-
Mastercard
|
|
50
|
-
</Label>
|
|
51
|
-
<br />
|
|
52
|
-
<Label htmlFor="vi">
|
|
53
|
-
<Radio
|
|
54
|
-
id="vi"
|
|
55
|
-
name="payment"
|
|
56
|
-
onChange={onChange}
|
|
57
|
-
checked={state === 'Visa'}
|
|
58
|
-
value="Visa"
|
|
59
|
-
/>
|
|
60
|
-
Visa
|
|
61
|
-
</Label>
|
|
62
|
-
<br />
|
|
63
|
-
<Label htmlFor="ae">
|
|
64
|
-
<Radio
|
|
65
|
-
id="ae"
|
|
66
|
-
name="payment"
|
|
67
|
-
onChange={onChange}
|
|
68
|
-
checked={state === 'AmericanExpress'}
|
|
69
|
-
value="AmericanExpress"
|
|
70
|
-
/>
|
|
71
|
-
American Express
|
|
72
|
-
</Label>
|
|
73
|
-
</div>
|
|
74
|
-
);
|
|
75
|
-
}}
|
|
76
|
-
</Story>
|
|
77
|
-
</Preview>
|
|
78
|
-
|
|
79
|
-
### Radio checked and disabled
|
|
80
|
-
|
|
81
|
-
<Preview>
|
|
82
|
-
<Story name="RadioTwo">
|
|
83
|
-
<div>
|
|
84
|
-
<Radio checked />
|
|
85
|
-
<Radio disabled />
|
|
86
|
-
<Radio checked disabled />
|
|
87
|
-
</div>
|
|
88
|
-
</Story>
|
|
89
|
-
</Preview>
|
|
86
|
+
<ArgsTable story="Default" />
|
package/src/Radio/Radio.test.tsx
CHANGED
|
@@ -1,44 +1,85 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { render, screen } from '@testing-library/react';
|
|
3
|
-
import {
|
|
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
|
+
};
|
|
13
|
+
|
|
14
|
+
test('supports label prop', () => {
|
|
15
|
+
render(<Radio label="Test" id="test" title="radio" />);
|
|
16
|
+
|
|
17
|
+
const radioLabel = screen.getByText(/Test/);
|
|
18
|
+
expect(radioLabel).toBeDefined();
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
test('supports required prop and renders required icon', () => {
|
|
22
|
+
render(<Radio label="Test" id="test" required title="radio" />);
|
|
23
|
+
|
|
24
|
+
const label = screen.getByText(/Test/);
|
|
25
|
+
expect(label.nextSibling).toContainHTML('path d="M10.8');
|
|
26
|
+
});
|
|
4
27
|
|
|
5
28
|
test('supports default type', () => {
|
|
6
|
-
render(<Radio title="radio" />);
|
|
7
|
-
const radio = screen.getByTitle(/radio/);
|
|
29
|
+
render(<Radio id="radio" title="radio" />);
|
|
8
30
|
|
|
31
|
+
const radio = screen.getByTitle(/radio/);
|
|
9
32
|
expect(radio.getAttribute('type')).toEqual('radio');
|
|
10
33
|
});
|
|
11
34
|
|
|
12
|
-
test('
|
|
13
|
-
render(<Radio
|
|
14
|
-
const radio = screen.getByTitle(/radio/);
|
|
35
|
+
test('renders <input> element', () => {
|
|
36
|
+
render(<Radio id="radio" title="radio" />);
|
|
15
37
|
|
|
16
|
-
|
|
38
|
+
const radio = screen.getByTitle(/radio/);
|
|
39
|
+
expect(radio instanceof HTMLInputElement).toBeTruthy();
|
|
17
40
|
});
|
|
18
41
|
|
|
19
|
-
test('
|
|
20
|
-
render(
|
|
42
|
+
test('supports disabled prop', () => {
|
|
43
|
+
render(
|
|
44
|
+
<ThemeProvider theme={theme}>
|
|
45
|
+
<Radio id="test" title="radio" label="label" disabled />
|
|
46
|
+
</ThemeProvider>
|
|
47
|
+
);
|
|
48
|
+
|
|
21
49
|
const radio = screen.getByTitle(/radio/);
|
|
50
|
+
expect(radio).toHaveAttribute('disabled');
|
|
51
|
+
});
|
|
22
52
|
|
|
23
|
-
|
|
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();
|
|
24
62
|
});
|
|
25
63
|
|
|
26
|
-
test('
|
|
64
|
+
test('supports checked radio', () => {
|
|
27
65
|
render(
|
|
28
|
-
<
|
|
29
|
-
<Radio id="radio" />
|
|
30
|
-
</
|
|
66
|
+
<ThemeProvider theme={theme}>
|
|
67
|
+
<Radio id="test" title="radio" onChange={() => {}} checked />
|
|
68
|
+
</ThemeProvider>
|
|
31
69
|
);
|
|
32
|
-
|
|
33
|
-
|
|
70
|
+
|
|
71
|
+
const radio = screen.getByTitle(/radio/);
|
|
72
|
+
expect(radio).toBeDefined();
|
|
34
73
|
});
|
|
35
74
|
|
|
36
|
-
test('
|
|
75
|
+
test('supports checked and disabled radio', () => {
|
|
37
76
|
render(
|
|
38
|
-
<
|
|
39
|
-
<Radio id="radio" checked />
|
|
40
|
-
</
|
|
77
|
+
<ThemeProvider theme={theme}>
|
|
78
|
+
<Radio id="test" title="radio" onChange={() => {}} checked disabled />
|
|
79
|
+
</ThemeProvider>
|
|
41
80
|
);
|
|
42
|
-
|
|
43
|
-
|
|
81
|
+
|
|
82
|
+
const radio = screen.getByTitle(/radio/);
|
|
83
|
+
expect(radio).toBeDefined();
|
|
84
|
+
expect(radio).toHaveAttribute('disabled');
|
|
44
85
|
});
|