@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.
Files changed (194) 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 +20 -2
  4. package/dist/Badge/Badge.d.ts +8 -0
  5. package/dist/Badge/index.d.ts +1 -0
  6. package/dist/Box/Box.d.ts +47 -0
  7. package/dist/Box/index.d.ts +1 -0
  8. package/dist/Button/Button.d.ts +4 -3
  9. package/dist/Card/Card.d.ts +9 -0
  10. package/dist/Card/index.d.ts +1 -0
  11. package/dist/Checkbox/Checkbox.d.ts +14 -2
  12. package/dist/Checkbox/CheckboxIcons.d.ts +9 -0
  13. package/dist/Column/Column.d.ts +8 -0
  14. package/dist/Column/index.d.ts +1 -0
  15. package/dist/Columns/Columns.d.ts +10 -0
  16. package/dist/Columns/index.d.ts +1 -0
  17. package/dist/Container/Container.d.ts +6 -0
  18. package/dist/Container/index.d.ts +1 -0
  19. package/dist/Dialog/Dialog.d.ts +14 -0
  20. package/dist/Dialog/ModalDialog.d.ts +5 -0
  21. package/dist/Dialog/index.d.ts +1 -0
  22. package/dist/Divider/Divider.d.ts +7 -0
  23. package/dist/Divider/index.d.ts +1 -0
  24. package/dist/Field/Field.d.ts +11 -0
  25. package/dist/Field/index.d.ts +1 -0
  26. package/dist/Heading/Heading.d.ts +7 -5
  27. package/dist/Hidden/Hidden.d.ts +5 -0
  28. package/dist/Hidden/index.d.ts +1 -0
  29. package/dist/Image/Image.d.ts +7 -0
  30. package/dist/Image/index.d.ts +1 -0
  31. package/dist/Input/Input.d.ts +6 -0
  32. package/dist/Input/index.d.ts +1 -0
  33. package/dist/Label/Label.d.ts +8 -5
  34. package/dist/Link/Link.d.ts +7 -3
  35. package/dist/Menu/Menu.d.ts +12 -0
  36. package/dist/Menu/index.d.ts +1 -0
  37. package/dist/MenuItem/MenuItem.d.ts +7 -0
  38. package/dist/MenuItem/index.d.ts +1 -0
  39. package/dist/Message/Message.d.ts +7 -0
  40. package/dist/Message/index.d.ts +1 -0
  41. package/dist/Provider/MarigoldProvider.d.ts +3 -0
  42. package/dist/Provider/index.d.ts +3 -0
  43. package/dist/Radio/Radio.d.ts +14 -2
  44. package/dist/Radio/RadioIcons.d.ts +9 -0
  45. package/dist/Select/ListBox.d.ts +8 -0
  46. package/dist/Select/ListBoxSection.d.ts +8 -0
  47. package/dist/Select/Option.d.ts +8 -0
  48. package/dist/Select/Popover.d.ts +9 -0
  49. package/dist/Select/Select.d.ts +13 -3
  50. package/dist/Slider/Slider.d.ts +6 -3
  51. package/dist/Stack/Stack.d.ts +7 -0
  52. package/dist/Stack/index.d.ts +1 -0
  53. package/dist/Text/Text.d.ts +12 -3
  54. package/dist/Textarea/Textarea.d.ts +11 -3
  55. package/dist/ValidationMessage/ValidationMessage.d.ts +6 -0
  56. package/dist/ValidationMessage/index.d.ts +1 -0
  57. package/dist/components.cjs.development.js +1308 -195
  58. package/dist/components.cjs.development.js.map +1 -1
  59. package/dist/components.cjs.production.min.js +1 -1
  60. package/dist/components.cjs.production.min.js.map +1 -1
  61. package/dist/components.esm.js +1267 -185
  62. package/dist/components.esm.js.map +1 -1
  63. package/dist/index.d.ts +21 -4
  64. package/dist/theme.d.ts +24 -4
  65. package/package.json +24 -4
  66. package/src/ActionGroup/ActionGroup.stories.mdx +62 -0
  67. package/src/ActionGroup/ActionGroup.test.tsx +83 -0
  68. package/src/ActionGroup/ActionGroup.tsx +43 -0
  69. package/src/ActionGroup/index.ts +1 -0
  70. package/src/Alert/Alert.stories.mdx +30 -42
  71. package/src/Alert/Alert.test.tsx +37 -22
  72. package/src/Alert/Alert.tsx +31 -21
  73. package/src/Badge/Badge.stories.mdx +57 -0
  74. package/src/Badge/Badge.test.tsx +61 -0
  75. package/src/Badge/Badge.tsx +25 -0
  76. package/src/Badge/index.ts +1 -0
  77. package/src/Box/Box.stories.mdx +334 -0
  78. package/src/Box/Box.test.tsx +133 -0
  79. package/src/Box/Box.tsx +165 -0
  80. package/src/Box/index.ts +1 -0
  81. package/src/Button/Button.stories.mdx +58 -134
  82. package/src/Button/Button.test.tsx +65 -23
  83. package/src/Button/Button.tsx +48 -14
  84. package/src/Card/Card.stories.mdx +49 -0
  85. package/src/Card/Card.test.tsx +66 -0
  86. package/src/Card/Card.tsx +36 -0
  87. package/src/Card/index.ts +1 -0
  88. package/src/Checkbox/Checkbox.stories.mdx +79 -101
  89. package/src/Checkbox/Checkbox.test.tsx +73 -32
  90. package/src/Checkbox/Checkbox.tsx +114 -35
  91. package/src/Checkbox/CheckboxIcons.tsx +49 -0
  92. package/src/Column/Column.stories.mdx +49 -0
  93. package/src/Column/Column.test.tsx +32 -0
  94. package/src/Column/Column.tsx +27 -0
  95. package/src/Column/index.ts +1 -0
  96. package/src/Columns/Columns.stories.mdx +65 -0
  97. package/src/Columns/Columns.test.tsx +102 -0
  98. package/src/Columns/Columns.tsx +69 -0
  99. package/src/Columns/index.ts +1 -0
  100. package/src/Container/Container.stories.mdx +19 -0
  101. package/src/Container/Container.test.tsx +26 -0
  102. package/src/Container/Container.tsx +13 -0
  103. package/src/Container/index.ts +1 -0
  104. package/src/Dialog/Dialog.stories.mdx +73 -0
  105. package/src/Dialog/Dialog.test.tsx +87 -0
  106. package/src/Dialog/Dialog.tsx +84 -0
  107. package/src/Dialog/ModalDialog.tsx +47 -0
  108. package/src/Dialog/index.ts +1 -0
  109. package/src/Divider/Divider.stories.mdx +37 -0
  110. package/src/Divider/Divider.test.tsx +63 -0
  111. package/src/Divider/Divider.tsx +13 -0
  112. package/src/Divider/index.ts +1 -0
  113. package/src/Field/Field.stories.mdx +97 -0
  114. package/src/Field/Field.test.tsx +80 -0
  115. package/src/Field/Field.tsx +54 -0
  116. package/src/Field/index.ts +1 -0
  117. package/src/Heading/Heading.stories.mdx +36 -76
  118. package/src/Heading/Heading.test.tsx +31 -17
  119. package/src/Heading/Heading.tsx +15 -12
  120. package/src/Hidden/Hidden.stories.mdx +39 -0
  121. package/src/Hidden/Hidden.test.tsx +24 -0
  122. package/src/Hidden/Hidden.tsx +16 -0
  123. package/src/Hidden/index.ts +1 -0
  124. package/src/Image/Image.stories.mdx +36 -0
  125. package/src/Image/Image.test.tsx +70 -0
  126. package/src/Image/Image.tsx +13 -0
  127. package/src/Image/index.ts +1 -0
  128. package/src/Input/Input.stories.mdx +61 -0
  129. package/src/Input/Input.test.tsx +70 -0
  130. package/src/Input/Input.tsx +13 -0
  131. package/src/Input/index.ts +1 -0
  132. package/src/Label/Label.stories.mdx +50 -34
  133. package/src/Label/Label.test.tsx +45 -16
  134. package/src/Label/Label.tsx +26 -17
  135. package/src/Link/Link.stories.mdx +40 -31
  136. package/src/Link/Link.test.tsx +53 -28
  137. package/src/Link/Link.tsx +32 -14
  138. package/src/Menu/Menu.stories.mdx +81 -0
  139. package/src/Menu/Menu.test.tsx +79 -0
  140. package/src/Menu/Menu.tsx +41 -0
  141. package/src/Menu/index.ts +1 -0
  142. package/src/MenuItem/MenuItem.stories.mdx +37 -0
  143. package/src/MenuItem/MenuItem.test.tsx +63 -0
  144. package/src/MenuItem/MenuItem.tsx +23 -0
  145. package/src/MenuItem/index.ts +1 -0
  146. package/src/Message/Message.stories.mdx +44 -0
  147. package/src/Message/Message.test.tsx +87 -0
  148. package/src/Message/Message.tsx +43 -0
  149. package/src/Message/index.ts +1 -0
  150. package/src/Provider/MarigoldProvider.test.tsx +126 -0
  151. package/src/Provider/MarigoldProvider.tsx +29 -0
  152. package/src/Provider/index.ts +3 -0
  153. package/src/Radio/Radio.stories.mdx +80 -83
  154. package/src/Radio/Radio.test.tsx +63 -22
  155. package/src/Radio/Radio.tsx +110 -35
  156. package/src/Radio/RadioIcons.tsx +39 -0
  157. package/src/Select/ListBox.tsx +39 -0
  158. package/src/Select/ListBoxSection.tsx +40 -0
  159. package/src/Select/Option.tsx +48 -0
  160. package/src/Select/Popover.tsx +50 -0
  161. package/src/Select/Select.stories.mdx +72 -37
  162. package/src/Select/Select.test.tsx +271 -28
  163. package/src/Select/Select.tsx +158 -23
  164. package/src/Slider/Slider.stories.mdx +26 -54
  165. package/src/Slider/Slider.test.tsx +13 -13
  166. package/src/Slider/Slider.tsx +20 -18
  167. package/src/Stack/Stack.stories.mdx +51 -0
  168. package/src/Stack/Stack.test.tsx +129 -0
  169. package/src/Stack/Stack.tsx +39 -0
  170. package/src/Stack/index.ts +1 -0
  171. package/src/Text/Text.stories.mdx +53 -47
  172. package/src/Text/Text.test.tsx +55 -15
  173. package/src/Text/Text.tsx +44 -10
  174. package/src/Textarea/Textarea.stories.mdx +68 -21
  175. package/src/Textarea/Textarea.test.tsx +47 -16
  176. package/src/Textarea/Textarea.tsx +46 -14
  177. package/src/ValidationMessage/ValidationMessage.stories.mdx +36 -0
  178. package/src/ValidationMessage/ValidationMessage.test.tsx +63 -0
  179. package/src/ValidationMessage/ValidationMessage.tsx +28 -0
  180. package/src/ValidationMessage/index.ts +1 -0
  181. package/src/index.ts +22 -4
  182. package/src/theme.ts +24 -4
  183. package/dist/Svg/Svg.d.ts +0 -5
  184. package/dist/Svg/index.d.ts +0 -1
  185. package/dist/TextInput/TextInput.d.ts +0 -3
  186. package/dist/TextInput/index.d.ts +0 -1
  187. package/src/Svg/Svg.stories.mdx +0 -47
  188. package/src/Svg/Svg.test.tsx +0 -58
  189. package/src/Svg/Svg.tsx +0 -25
  190. package/src/Svg/index.ts +0 -1
  191. package/src/TextInput/TextInput.stories.mdx +0 -37
  192. package/src/TextInput/TextInput.test.tsx +0 -71
  193. package/src/TextInput/TextInput.tsx +0 -21
  194. 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
+ };
@@ -0,0 +1,3 @@
1
+ export { useTheme, ThemeProvider } from '@marigold/system';
2
+ export * from './MarigoldProvider';
3
+ export { SSRProvider } from '@react-aria/ssr';
@@ -1,89 +1,86 @@
1
- import { Meta, Story, Preview } from '@storybook/addon-docs/blocks';
2
- import { Label, Radio } from '@marigold/components';
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 title="Components/Form/Radio" />
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 Button
68
+ # Radio
8
69
 
9
- ## Description
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
- 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
- Specific css style prop can also be added.
82
+ <Canvas>
83
+ <Story name="Default">{Template.bind({})}</Story>
84
+ </Canvas>
14
85
 
15
- ## Properties
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" />
@@ -1,44 +1,85 @@
1
1
  import React from 'react';
2
2
  import { render, screen } from '@testing-library/react';
3
- import { Label, Radio } from '@marigold/components';
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('variant styles cannot be overridden with CSS prop', () => {
13
- render(<Radio title="radio" css={{ color: 'blue' }} />);
14
- const radio = screen.getByTitle(/radio/);
35
+ test('renders <input> element', () => {
36
+ render(<Radio id="radio" title="radio" />);
15
37
 
16
- expect(radio).not.toHaveStyle('color: blue');
38
+ const radio = screen.getByTitle(/radio/);
39
+ expect(radio instanceof HTMLInputElement).toBeTruthy();
17
40
  });
18
41
 
19
- test('renders <input> element', () => {
20
- render(<Radio title="radio" />);
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
- expect(radio instanceof HTMLInputElement).toBeTruthy();
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('renders <SVG> CircleUnchecked element', () => {
64
+ test('supports checked radio', () => {
27
65
  render(
28
- <Label htmlFor="radio">
29
- <Radio id="radio" /> Test
30
- </Label>
66
+ <ThemeProvider theme={theme}>
67
+ <Radio id="test" title="radio" onChange={() => {}} checked />
68
+ </ThemeProvider>
31
69
  );
32
- const radio = screen.getByText(/Test/);
33
- expect(radio).toContainHTML('path d="M5.62507');
70
+
71
+ const radio = screen.getByTitle(/radio/);
72
+ expect(radio).toBeDefined();
34
73
  });
35
74
 
36
- test('renders <SVG> CircleChecked element', () => {
75
+ test('supports checked and disabled radio', () => {
37
76
  render(
38
- <Label htmlFor="radio">
39
- <Radio id="radio" checked /> Test
40
- </Label>
77
+ <ThemeProvider theme={theme}>
78
+ <Radio id="test" title="radio" onChange={() => {}} checked disabled />
79
+ </ThemeProvider>
41
80
  );
42
- const radio = screen.getByText(/Test/);
43
- expect(radio).toContainHTML('path d="M12');
81
+
82
+ const radio = screen.getByTitle(/radio/);
83
+ expect(radio).toBeDefined();
84
+ expect(radio).toHaveAttribute('disabled');
44
85
  });