@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.
Files changed (112) hide show
  1. package/dist/ActionGroup/ActionGroup.d.ts +9 -0
  2. package/dist/ActionGroup/index.d.ts +1 -0
  3. package/dist/Alert/Alert.d.ts +16 -1
  4. package/dist/Box/Box.d.ts +2 -1
  5. package/dist/Button/Button.d.ts +4 -6
  6. package/dist/Card/Card.d.ts +9 -0
  7. package/dist/Card/index.d.ts +1 -0
  8. package/dist/Checkbox/Checkbox.d.ts +3 -0
  9. package/dist/Checkbox/CheckboxIcons.d.ts +9 -0
  10. package/dist/Column/Column.d.ts +3 -1
  11. package/dist/Dialog/Dialog.d.ts +8 -1
  12. package/dist/Dialog/ModalDialog.d.ts +5 -0
  13. package/dist/Field/Field.d.ts +4 -2
  14. package/dist/Label/Label.d.ts +2 -1
  15. package/dist/Provider/MarigoldProvider.d.ts +3 -0
  16. package/dist/Provider/index.d.ts +3 -0
  17. package/dist/Radio/Radio.d.ts +3 -0
  18. package/dist/Radio/RadioIcons.d.ts +9 -0
  19. package/dist/Select/ListBox.d.ts +8 -0
  20. package/dist/Select/ListBoxSection.d.ts +8 -0
  21. package/dist/Select/Option.d.ts +8 -0
  22. package/dist/Select/Popover.d.ts +9 -0
  23. package/dist/Select/Select.d.ts +11 -4
  24. package/dist/Stack/Stack.d.ts +1 -3
  25. package/dist/Textarea/Textarea.d.ts +2 -1
  26. package/dist/components.cjs.development.js +868 -357
  27. package/dist/components.cjs.development.js.map +1 -1
  28. package/dist/components.cjs.production.min.js +1 -1
  29. package/dist/components.cjs.production.min.js.map +1 -1
  30. package/dist/components.esm.js +837 -359
  31. package/dist/components.esm.js.map +1 -1
  32. package/dist/index.d.ts +4 -0
  33. package/package.json +18 -3
  34. package/src/ActionGroup/ActionGroup.stories.mdx +62 -0
  35. package/src/ActionGroup/ActionGroup.test.tsx +83 -0
  36. package/src/ActionGroup/ActionGroup.tsx +43 -0
  37. package/src/ActionGroup/index.ts +1 -0
  38. package/src/Alert/Alert.stories.mdx +28 -38
  39. package/src/Alert/Alert.test.tsx +1 -1
  40. package/src/Alert/Alert.tsx +11 -33
  41. package/src/Badge/Badge.stories.mdx +48 -34
  42. package/src/Badge/Badge.test.tsx +7 -15
  43. package/src/Badge/Badge.tsx +1 -2
  44. package/src/Box/Box.stories.mdx +322 -26
  45. package/src/Box/Box.tsx +58 -50
  46. package/src/Button/Button.stories.mdx +54 -166
  47. package/src/Button/Button.test.tsx +48 -8
  48. package/src/Button/Button.tsx +47 -18
  49. package/src/Card/Card.stories.mdx +49 -0
  50. package/src/Card/Card.test.tsx +66 -0
  51. package/src/Card/Card.tsx +36 -0
  52. package/src/Card/index.ts +1 -0
  53. package/src/Checkbox/Checkbox.stories.mdx +76 -71
  54. package/src/Checkbox/Checkbox.test.tsx +70 -24
  55. package/src/Checkbox/Checkbox.tsx +68 -49
  56. package/src/Checkbox/CheckboxIcons.tsx +49 -0
  57. package/src/Column/Column.stories.mdx +39 -64
  58. package/src/Column/Column.test.tsx +8 -0
  59. package/src/Column/Column.tsx +12 -2
  60. package/src/Columns/Columns.stories.mdx +58 -240
  61. package/src/Container/Container.stories.mdx +8 -25
  62. package/src/Dialog/Dialog.stories.mdx +65 -56
  63. package/src/Dialog/Dialog.test.tsx +64 -24
  64. package/src/Dialog/Dialog.tsx +64 -12
  65. package/src/Dialog/ModalDialog.tsx +47 -0
  66. package/src/Divider/Divider.stories.mdx +28 -34
  67. package/src/Field/Field.stories.mdx +88 -48
  68. package/src/Field/Field.test.tsx +31 -40
  69. package/src/Field/Field.tsx +26 -21
  70. package/src/Heading/Heading.stories.mdx +30 -82
  71. package/src/Hidden/Hidden.stories.mdx +29 -54
  72. package/src/Image/Image.stories.mdx +26 -30
  73. package/src/Input/Input.stories.mdx +52 -36
  74. package/src/Label/Label.stories.mdx +47 -29
  75. package/src/Label/Label.test.tsx +15 -1
  76. package/src/Label/Label.tsx +20 -7
  77. package/src/Link/Link.stories.mdx +36 -29
  78. package/src/Menu/Menu.stories.mdx +71 -39
  79. package/src/Menu/Menu.test.tsx +4 -4
  80. package/src/Menu/Menu.tsx +12 -14
  81. package/src/MenuItem/MenuItem.stories.mdx +32 -27
  82. package/src/MenuItem/MenuItem.test.tsx +15 -11
  83. package/src/MenuItem/MenuItem.tsx +7 -10
  84. package/src/Message/Message.stories.mdx +35 -35
  85. package/src/Message/Message.tsx +2 -10
  86. package/src/Provider/MarigoldProvider.test.tsx +126 -0
  87. package/src/Provider/MarigoldProvider.tsx +29 -0
  88. package/src/Provider/index.ts +3 -0
  89. package/src/Radio/Radio.stories.mdx +78 -92
  90. package/src/Radio/Radio.test.tsx +57 -15
  91. package/src/Radio/Radio.tsx +71 -51
  92. package/src/Radio/RadioIcons.tsx +39 -0
  93. package/src/Select/ListBox.tsx +39 -0
  94. package/src/Select/ListBoxSection.tsx +40 -0
  95. package/src/Select/Option.tsx +48 -0
  96. package/src/Select/Popover.tsx +50 -0
  97. package/src/Select/Select.stories.mdx +70 -36
  98. package/src/Select/Select.test.tsx +279 -35
  99. package/src/Select/Select.tsx +151 -18
  100. package/src/Slider/Slider.stories.mdx +22 -49
  101. package/src/Stack/Stack.stories.mdx +40 -94
  102. package/src/Stack/Stack.test.tsx +84 -65
  103. package/src/Stack/Stack.tsx +25 -41
  104. package/src/Text/Text.stories.mdx +52 -52
  105. package/src/Text/Text.tsx +13 -14
  106. package/src/Textarea/Textarea.stories.mdx +65 -56
  107. package/src/Textarea/Textarea.test.tsx +4 -5
  108. package/src/Textarea/Textarea.tsx +28 -37
  109. package/src/ValidationMessage/ValidationMessage.stories.mdx +26 -26
  110. package/src/ValidationMessage/ValidationMessage.test.tsx +4 -4
  111. package/src/ValidationMessage/ValidationMessage.tsx +11 -12
  112. 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
- menu: {
8
- menuItem: {
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 and themeSection', () => {
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" title="menuItem" />
55
+ <MenuItem title="menuItem" className="custom-class-name">
56
+ Item
57
+ </MenuItem>
54
58
  </ThemeProvider>
55
59
  );
56
- const menuItem = screen.getByTitle(/menuItem/);
60
+ const menuItem = screen.getByText(/Item/).parentElement;
57
61
 
58
- expect(menuItem.className).toMatch('custom-class-name');
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 = 'menuItem',
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
- <Link {...props} variant="menu" className={classNames}>
23
- {children}
24
- </Link>
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, Canvas } from '@storybook/addon-docs/blocks';
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 title="Components/Message" />
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
- ## Description
10
-
11
- Simple component to display a message with a title and icon based on a `div` element and styled with a theme.
12
-
13
- ## Properties
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="Message">
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" />
@@ -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 className={useStyles({ css: { color: 'black' } })}>{children}</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
+ };
@@ -0,0 +1,3 @@
1
+ export { useTheme, ThemeProvider } from '@marigold/system';
2
+ export * from './MarigoldProvider';
3
+ export { SSRProvider } from '@react-aria/ssr';
@@ -1,100 +1,86 @@
1
- import { Meta, Story, Canvas } from '@storybook/addon-docs/blocks';
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 title="Components/Radio" />
6
-
7
- # Radio Button
8
-
9
- ## Description
10
-
11
- With the Radio Button component you can add a HTML `<input>` element with `type="radio"` to your form.
12
- The element uses always the themeSection with the name: `form` in your given theme. The variant in your section can be added with the variant prop. The default variant is `radio`.
13
-
14
- ## Properties
15
-
16
- | Property | Type | Default |
17
- | :-------------------- | :-------- | :------ |
18
- | `id` | `string` | |
19
- | `variant` (optional) | `string` | `radio` |
20
- | `label` (optional) | `string` | |
21
- | `required` (optional) | `boolean` | |
22
-
23
- ## Import
24
-
25
- ```tsx
26
- import { Radio } from '@marigold/components';
27
- ```
28
-
29
- ## Usage
30
-
31
- ### Radio standard labeled
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
- <Canvas>
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
- ### Radio checked and disabled
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="RadioTwo">
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
- ### Radio with required label
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" />
@@ -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
- expect(radio).toBeDefined();
17
+ const radioLabel = screen.getByText(/Test/);
18
+ expect(radioLabel).toBeDefined();
10
19
  });
11
20
 
12
- test('supports required prop an renders required icon', () => {
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
- expect(radio).toContainHTML('path d="M10.8');
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('renders <SVG> CircleUnchecked element', () => {
34
- render(<Radio id="radio" label="Test" />);
35
- const radio = screen.getByText(/Test/);
36
- expect(radio).toContainHTML('path d="M5.62507');
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('renders <SVG> CircleChecked element', () => {
40
- render(<Radio id="radio" checked onChange={() => {}} label="Test" />);
41
- const radio = screen.getByText(/Test/);
42
- expect(radio).toContainHTML('path d="M12');
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
  });