@marigold/components 0.0.2 → 0.3.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 (224) hide show
  1. package/CHANGELOG.md +294 -0
  2. package/dist/ActionGroup/ActionGroup.d.ts +8 -0
  3. package/dist/ActionGroup/ActionGroup.stories.d.ts +5 -0
  4. package/dist/ActionGroup/index.d.ts +1 -0
  5. package/dist/Alert/Alert.d.ts +16 -3
  6. package/dist/Alert/Alert.stories.d.ts +5 -0
  7. package/dist/Badge/Badge.d.ts +11 -5
  8. package/dist/Badge/Badge.stories.d.ts +5 -0
  9. package/dist/Box.d.ts +2 -0
  10. package/dist/Button/Button.d.ts +9 -5
  11. package/dist/Button/Button.stories.d.ts +5 -0
  12. package/dist/Card/Card.d.ts +14 -0
  13. package/dist/Card/Card.stories.d.ts +5 -0
  14. package/dist/Card/index.d.ts +1 -0
  15. package/dist/Checkbox/Checkbox.d.ts +17 -5
  16. package/dist/Checkbox/Checkbox.stories.d.ts +5 -0
  17. package/dist/Checkbox/CheckboxIcons.d.ts +9 -0
  18. package/dist/Column/Column.d.ts +6 -4
  19. package/dist/Column/Column.stories.d.ts +5 -0
  20. package/dist/Columns/Columns.d.ts +10 -0
  21. package/dist/Columns/Columns.stories.d.ts +5 -0
  22. package/dist/Columns/index.d.ts +1 -0
  23. package/dist/Container/Container.d.ts +5 -4
  24. package/dist/Container/Container.stories.d.ts +5 -0
  25. package/dist/Dialog/Dialog.d.ts +17 -0
  26. package/dist/Dialog/Dialog.stories.d.ts +5 -0
  27. package/dist/Dialog/ModalDialog.d.ts +8 -0
  28. package/dist/Dialog/index.d.ts +1 -0
  29. package/dist/Divider/Divider.d.ts +10 -3
  30. package/dist/Divider/Divider.stories.d.ts +5 -0
  31. package/dist/Field/Field.d.ts +10 -5
  32. package/dist/Field/Field.stories.d.ts +5 -0
  33. package/dist/Image/Image.d.ts +11 -5
  34. package/dist/Image/Image.stories.d.ts +5 -0
  35. package/dist/Inline/Inline.d.ts +7 -0
  36. package/dist/Inline/Inline.stories.d.ts +5 -0
  37. package/dist/Inline/index.d.ts +1 -0
  38. package/dist/Input/Input.d.ts +10 -4
  39. package/dist/Input/Input.stories.d.ts +5 -0
  40. package/dist/Label/Label.d.ts +18 -5
  41. package/dist/Label/Label.stories.d.ts +5 -0
  42. package/dist/Link/Link.d.ts +10 -5
  43. package/dist/Link/Link.stories.d.ts +5 -0
  44. package/dist/Menu/Menu.d.ts +11 -4
  45. package/dist/Menu/Menu.stories.d.ts +5 -0
  46. package/dist/MenuItem/MenuItem.d.ts +11 -4
  47. package/dist/MenuItem/MenuItem.stories.d.ts +5 -0
  48. package/dist/Message/Message.d.ts +10 -4
  49. package/dist/Message/Message.stories.d.ts +5 -0
  50. package/dist/Provider/MarigoldProvider.d.ts +11 -0
  51. package/dist/Provider/index.d.ts +3 -0
  52. package/dist/Radio/Radio.d.ts +17 -4
  53. package/dist/Radio/RadioIcons.d.ts +10 -0
  54. package/dist/Select/ListBox.d.ts +9 -0
  55. package/dist/Select/ListBoxSection.d.ts +9 -0
  56. package/dist/Select/Option.d.ts +9 -0
  57. package/dist/Select/Popover.d.ts +9 -0
  58. package/dist/Select/Select.d.ts +27 -3
  59. package/dist/Select/Select.stories.d.ts +5 -0
  60. package/dist/Slider/Slider.d.ts +10 -4
  61. package/dist/Slider/Slider.stories.d.ts +5 -0
  62. package/dist/Stack/Stack.d.ts +7 -0
  63. package/dist/Stack/Stack.stories.d.ts +5 -0
  64. package/dist/Stack/index.d.ts +1 -0
  65. package/dist/Text/Text.d.ts +17 -7
  66. package/dist/Text/Text.stories.d.ts +5 -0
  67. package/dist/Textarea/Textarea.d.ts +15 -4
  68. package/dist/Textarea/Textarea.stories.d.ts +5 -0
  69. package/dist/ValidationMessage/ValidationMessage.d.ts +10 -4
  70. package/dist/ValidationMessage/ValidationMessage.stories.d.ts +5 -0
  71. package/dist/VisuallyHidden/VisuallyHidden.d.ts +1 -0
  72. package/dist/VisuallyHidden/VisuallyHidden.stories.d.ts +5 -0
  73. package/dist/VisuallyHidden/index.d.ts +1 -0
  74. package/dist/components.cjs.development.js +1276 -461
  75. package/dist/components.cjs.development.js.map +1 -1
  76. package/dist/components.cjs.production.min.js +1 -1
  77. package/dist/components.cjs.production.min.js.map +1 -1
  78. package/dist/components.esm.js +1229 -461
  79. package/dist/components.esm.js.map +1 -1
  80. package/dist/index.d.ts +10 -3
  81. package/dist/theme.d.ts +23 -28
  82. package/package.json +27 -4
  83. package/src/ActionGroup/ActionGroup.stories.tsx +47 -0
  84. package/src/ActionGroup/ActionGroup.test.tsx +83 -0
  85. package/src/ActionGroup/ActionGroup.tsx +32 -0
  86. package/src/ActionGroup/index.ts +1 -0
  87. package/src/Alert/Alert.stories.tsx +32 -0
  88. package/src/Alert/Alert.test.tsx +34 -23
  89. package/src/Alert/Alert.tsx +48 -24
  90. package/src/Badge/Badge.stories.tsx +38 -0
  91. package/src/Badge/Badge.test.tsx +14 -40
  92. package/src/Badge/Badge.tsx +31 -28
  93. package/src/Box.ts +2 -0
  94. package/src/Button/Button.stories.tsx +57 -0
  95. package/src/Button/Button.test.tsx +76 -13
  96. package/src/Button/Button.tsx +58 -23
  97. package/src/Card/Card.stories.tsx +41 -0
  98. package/src/Card/Card.test.tsx +71 -0
  99. package/src/Card/Card.tsx +48 -0
  100. package/src/Card/index.ts +1 -0
  101. package/src/Checkbox/Checkbox.stories.mdx +90 -112
  102. package/src/Checkbox/Checkbox.stories.tsx +78 -0
  103. package/src/Checkbox/Checkbox.test.tsx +139 -24
  104. package/src/Checkbox/Checkbox.tsx +95 -58
  105. package/src/Checkbox/CheckboxIcons.tsx +59 -0
  106. package/src/Column/Column.stories.tsx +33 -0
  107. package/src/Column/Column.test.tsx +15 -59
  108. package/src/Column/Column.tsx +21 -19
  109. package/src/Columns/Columns.stories.tsx +75 -0
  110. package/src/Columns/Columns.test.tsx +113 -0
  111. package/src/Columns/Columns.tsx +69 -0
  112. package/src/Columns/index.ts +1 -0
  113. package/src/Container/Container.stories.tsx +14 -0
  114. package/src/Container/Container.test.tsx +8 -49
  115. package/src/Container/Container.tsx +8 -19
  116. package/src/Dialog/Dialog.stories.tsx +88 -0
  117. package/src/Dialog/Dialog.test.tsx +158 -0
  118. package/src/Dialog/Dialog.tsx +130 -0
  119. package/src/Dialog/ModalDialog.tsx +76 -0
  120. package/src/Dialog/index.ts +1 -0
  121. package/src/Divider/Divider.stories.tsx +30 -0
  122. package/src/Divider/Divider.test.tsx +14 -6
  123. package/src/Divider/Divider.tsx +20 -13
  124. package/src/Field/Field.stories.tsx +110 -0
  125. package/src/Field/Field.test.tsx +75 -34
  126. package/src/Field/Field.tsx +50 -43
  127. package/src/Image/Image.stories.tsx +34 -0
  128. package/src/Image/Image.test.tsx +6 -3
  129. package/src/Image/Image.tsx +21 -15
  130. package/src/Inline/Inline.stories.tsx +39 -0
  131. package/src/Inline/Inline.test.tsx +99 -0
  132. package/src/Inline/Inline.tsx +38 -0
  133. package/src/Inline/index.ts +1 -0
  134. package/src/Input/Input.stories.tsx +54 -0
  135. package/src/Input/Input.test.tsx +9 -5
  136. package/src/Input/Input.tsx +21 -16
  137. package/src/Label/Label.stories.tsx +41 -0
  138. package/src/Label/Label.test.tsx +41 -6
  139. package/src/Label/Label.tsx +59 -18
  140. package/src/Link/Link.stories.tsx +35 -0
  141. package/src/Link/Link.test.tsx +52 -22
  142. package/src/Link/Link.tsx +40 -20
  143. package/src/Menu/Menu.stories.tsx +62 -0
  144. package/src/Menu/Menu.test.tsx +13 -7
  145. package/src/Menu/Menu.tsx +44 -38
  146. package/src/MenuItem/MenuItem.stories.tsx +30 -0
  147. package/src/MenuItem/MenuItem.test.tsx +23 -14
  148. package/src/MenuItem/MenuItem.tsx +29 -18
  149. package/src/Message/Message.stories.tsx +30 -0
  150. package/src/Message/Message.test.tsx +5 -2
  151. package/src/Message/Message.tsx +48 -40
  152. package/src/Provider/MarigoldProvider.test.tsx +136 -0
  153. package/src/Provider/MarigoldProvider.tsx +47 -0
  154. package/src/Provider/index.ts +4 -0
  155. package/src/Radio/Radio.stories.mdx +91 -94
  156. package/src/Radio/Radio.test.tsx +92 -16
  157. package/src/Radio/Radio.tsx +114 -50
  158. package/src/Radio/RadioIcons.tsx +39 -0
  159. package/src/Select/ListBox.tsx +40 -0
  160. package/src/Select/ListBoxSection.tsx +40 -0
  161. package/src/Select/Option.tsx +48 -0
  162. package/src/Select/Popover.tsx +50 -0
  163. package/src/Select/Select.stories.tsx +81 -0
  164. package/src/Select/Select.test.tsx +311 -43
  165. package/src/Select/Select.tsx +174 -28
  166. package/src/Slider/Slider.stories.tsx +24 -0
  167. package/src/Slider/Slider.test.tsx +11 -7
  168. package/src/Slider/Slider.tsx +30 -15
  169. package/src/Stack/Stack.stories.tsx +57 -0
  170. package/src/Stack/Stack.test.tsx +138 -0
  171. package/src/Stack/Stack.tsx +39 -0
  172. package/src/Stack/index.ts +1 -0
  173. package/src/Text/Text.stories.tsx +61 -0
  174. package/src/Text/Text.test.tsx +41 -36
  175. package/src/Text/Text.tsx +55 -29
  176. package/src/Textarea/Textarea.stories.tsx +64 -0
  177. package/src/Textarea/Textarea.test.tsx +41 -5
  178. package/src/Textarea/Textarea.tsx +57 -17
  179. package/src/ValidationMessage/ValidationMessage.stories.tsx +27 -0
  180. package/src/ValidationMessage/ValidationMessage.test.tsx +19 -14
  181. package/src/ValidationMessage/ValidationMessage.tsx +36 -21
  182. package/src/VisuallyHidden/VisuallyHidden.stories.tsx +19 -0
  183. package/src/VisuallyHidden/VisuallyHidden.test.tsx +10 -0
  184. package/src/VisuallyHidden/VisuallyHidden.tsx +1 -0
  185. package/src/VisuallyHidden/index.ts +1 -0
  186. package/src/index.ts +11 -3
  187. package/src/theme.ts +49 -28
  188. package/dist/Heading/Heading.d.ts +0 -5
  189. package/dist/Heading/index.d.ts +0 -1
  190. package/dist/Hidden/Hidden.d.ts +0 -6
  191. package/dist/Hidden/index.d.ts +0 -1
  192. package/dist/Svg/Svg.d.ts +0 -6
  193. package/dist/Svg/index.d.ts +0 -1
  194. package/src/Alert/Alert.stories.mdx +0 -49
  195. package/src/Badge/Badge.stories.mdx +0 -41
  196. package/src/Button/Button.stories.mdx +0 -155
  197. package/src/Column/Column.stories.mdx +0 -76
  198. package/src/Container/Container.stories.mdx +0 -42
  199. package/src/Divider/Divider.stories.mdx +0 -42
  200. package/src/Field/Field.stories.mdx +0 -57
  201. package/src/Heading/Heading.stories.mdx +0 -79
  202. package/src/Heading/Heading.test.tsx +0 -63
  203. package/src/Heading/Heading.tsx +0 -22
  204. package/src/Heading/index.ts +0 -1
  205. package/src/Hidden/Hidden.stories.mdx +0 -64
  206. package/src/Hidden/Hidden.test.tsx +0 -87
  207. package/src/Hidden/Hidden.tsx +0 -25
  208. package/src/Hidden/index.ts +0 -1
  209. package/src/Image/Image.stories.mdx +0 -40
  210. package/src/Input/Input.stories.mdx +0 -44
  211. package/src/Label/Label.stories.mdx +0 -34
  212. package/src/Link/Link.stories.mdx +0 -37
  213. package/src/Menu/Menu.stories.mdx +0 -47
  214. package/src/MenuItem/MenuItem.stories.mdx +0 -32
  215. package/src/Message/Message.stories.mdx +0 -43
  216. package/src/Select/Select.stories.mdx +0 -43
  217. package/src/Slider/Slider.stories.mdx +0 -57
  218. package/src/Svg/Svg.stories.mdx +0 -47
  219. package/src/Svg/Svg.test.tsx +0 -76
  220. package/src/Svg/Svg.tsx +0 -31
  221. package/src/Svg/index.ts +0 -1
  222. package/src/Text/Text.stories.mdx +0 -60
  223. package/src/Textarea/Textarea.stories.mdx +0 -34
  224. package/src/ValidationMessage/ValidationMessage.stories.mdx +0 -36
@@ -0,0 +1,71 @@
1
+ import React from 'react';
2
+ import { render, screen } from '@testing-library/react';
3
+ import { ThemeProvider } from '@marigold/system';
4
+
5
+ import { Card } from './Card';
6
+
7
+ const theme = {
8
+ space: {
9
+ none: 0,
10
+ small: 4,
11
+ medium: 8,
12
+ },
13
+ card: {
14
+ __default: {
15
+ p: 'medium',
16
+ },
17
+ custom: {
18
+ p: 'small',
19
+ },
20
+ },
21
+ };
22
+
23
+ test('supports default variant', () => {
24
+ render(
25
+ <ThemeProvider theme={theme}>
26
+ <Card>card</Card>
27
+ </ThemeProvider>
28
+ );
29
+ const card = screen.getByText(/card/);
30
+ expect(card).toHaveStyle(`padding: 8px`);
31
+ });
32
+
33
+ test('supports other variant than default', () => {
34
+ render(
35
+ <ThemeProvider theme={theme}>
36
+ <Card variant="custom">card</Card>
37
+ </ThemeProvider>
38
+ );
39
+ const card = screen.getByText(/card/);
40
+ expect(card).toHaveStyle(`padding: 4px`);
41
+ });
42
+
43
+ test('accepts title prop', () => {
44
+ render(
45
+ <ThemeProvider theme={theme}>
46
+ <Card title="title">content</Card>
47
+ </ThemeProvider>
48
+ );
49
+ const title = screen.getByText(/title/);
50
+ expect(title).toBeDefined();
51
+ });
52
+
53
+ test('accepts width prop', () => {
54
+ render(
55
+ <ThemeProvider theme={theme}>
56
+ <Card width="320px">content</Card>
57
+ </ThemeProvider>
58
+ );
59
+ const card = screen.getByText(/content/);
60
+ expect(card).toHaveStyle(`maxWidth: 320px`);
61
+ });
62
+
63
+ test('renders correct HTMl element', () => {
64
+ render(
65
+ <ThemeProvider theme={theme}>
66
+ <Card>card</Card>
67
+ </ThemeProvider>
68
+ );
69
+ const card = screen.getByText(/card/);
70
+ expect(card instanceof HTMLDivElement).toBeTruthy();
71
+ });
@@ -0,0 +1,48 @@
1
+ import React from 'react';
2
+ import { ResponsiveStyleValue } from '@marigold/system';
3
+ import { ComponentProps } from '@marigold/types';
4
+
5
+ import { Box } from '../Box';
6
+
7
+ // Theme Extension
8
+ // ---------------
9
+ export interface CardThemeExtension<Value> {
10
+ card?: {
11
+ [key: string]: Value;
12
+ };
13
+ }
14
+
15
+ // Props
16
+ // ---------------
17
+ export type CardProps = {
18
+ title?: string;
19
+ width?: ResponsiveStyleValue<string>;
20
+ variant?: string;
21
+ } & ComponentProps<'div'>;
22
+
23
+ // Component
24
+ // ---------------
25
+ export const Card: React.FC<CardProps> = ({
26
+ variant = '',
27
+ title,
28
+ width,
29
+ className,
30
+ children,
31
+ ...props
32
+ }) => {
33
+ return (
34
+ <Box
35
+ {...props}
36
+ variant={`card.${variant}`}
37
+ maxWidth={width}
38
+ className={className}
39
+ >
40
+ {title && (
41
+ <Box as="h2" variant="text.h2" pb="small">
42
+ {title}
43
+ </Box>
44
+ )}
45
+ {children}
46
+ </Box>
47
+ );
48
+ };
@@ -0,0 +1 @@
1
+ export * from './Card';
@@ -1,119 +1,97 @@
1
- import { Meta, Story, Preview } from '@storybook/addon-docs/blocks';
2
- import { Checkbox } from '@marigold/components';
1
+ import { ArgsTable, Canvas, Meta, Story } from '@storybook/addon-docs';
2
+ import { Checkbox } from './Checkbox';
3
3
  import { useState } from 'react';
4
- import { useStyles } from '@marigold/system';
5
4
 
6
- <Meta title="Components/Form/Checkbox" />
5
+ <Meta
6
+ title="Components/Checkbox"
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: 'Checkbox variant',
25
+ table: {
26
+ defaultValue: {
27
+ summary: 'default',
28
+ },
29
+ },
30
+ },
31
+ labelVariant: {
32
+ control: {
33
+ type: 'text',
34
+ },
35
+ description: 'Checkbox label variant',
36
+ table: {
37
+ defaultValue: {
38
+ summary: 'inline',
39
+ },
40
+ },
41
+ },
42
+ label: {
43
+ control: {
44
+ type: 'text',
45
+ },
46
+ description: 'Label',
47
+ },
48
+ required: {
49
+ control: {
50
+ type: 'boolean',
51
+ },
52
+ description: 'Require',
53
+ table: {
54
+ defaultValue: {
55
+ summary: false,
56
+ },
57
+ },
58
+ },
59
+ error: {
60
+ control: {
61
+ type: 'boolean',
62
+ },
63
+ description: 'Error',
64
+ table: {
65
+ defaultValue: {
66
+ summary: false,
67
+ },
68
+ },
69
+ },
70
+ errorMessage: {
71
+ control: {
72
+ type: 'text',
73
+ },
74
+ description: 'Error Message',
75
+ },
76
+ }}
77
+ />
7
78
 
8
79
  # Checkbox
9
80
 
10
- ## Description
81
+ export const Template = ({ onChange, checked, ...args }) => {
82
+ const [isChecked, setChecked] = useState(false);
83
+ return (
84
+ <Checkbox
85
+ onChange={() => setChecked(!isChecked)}
86
+ checked={isChecked}
87
+ label="Checkbox Label"
88
+ {...args}
89
+ />
90
+ );
91
+ };
11
92
 
12
- With the Checkbox component you can add a HTML `<input>` element with `type="checkbox"` to your form.
13
- 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 `checkbox`.
93
+ <Canvas>
94
+ <Story name="Default">{Template.bind({})}</Story>
95
+ </Canvas>
14
96
 
15
- ## Properties
16
-
17
- | Property | Type | Default |
18
- | :-------------------- | :-------- | :--------- |
19
- | `id` | `string` | |
20
- | `variant` (optional) | `string` | `checkbox` |
21
- | `label` (optional) | `string` | |
22
- | `required` (optional) | `boolean` | |
23
-
24
- ## Import
25
-
26
- ```tsx
27
- import { Checkbox } from '@marigold/components';
28
- ```
29
-
30
- ## Usage
31
-
32
- ### Checkbox standard labeled
33
-
34
- <Preview>
35
- <Story name="CheckboxOne">
36
- {() => {
37
- const [state, setState] = React.useState({
38
- bi: false,
39
- ca: false,
40
- bo: false,
41
- je: false,
42
- });
43
- const onChange = changeEvent => {
44
- setState({
45
- ...state,
46
- [changeEvent.target.name]: changeEvent.target.checked,
47
- });
48
- };
49
- return (
50
- <div>
51
- <Checkbox
52
- id="bi"
53
- name="bi"
54
- onChange={onChange}
55
- checked={state.bi}
56
- value="Bike"
57
- label="Bike"
58
- />
59
- <br />
60
- <Checkbox
61
- id="ca"
62
- name="ca"
63
- onChange={onChange}
64
- checked={state.ca}
65
- value="Car"
66
- label="Car"
67
- />
68
- <br />
69
- <Checkbox
70
- id="bo"
71
- name="bo"
72
- onChange={onChange}
73
- checked={state.bo}
74
- value="Boat"
75
- label="Boat"
76
- />
77
- <br />
78
- <Checkbox
79
- id="je"
80
- name="je"
81
- onChange={onChange}
82
- checked={state.je}
83
- value="Jet"
84
- label="Jet"
85
- />
86
- </div>
87
- );
88
- }}
89
- </Story>
90
- </Preview>
91
-
92
- ### Checkbox checked, disabled and custom styled
93
-
94
- <Preview>
95
- <Story name="CheckboxTwo">
96
- <div>
97
- <Checkbox id="checkbox" checked />
98
- <Checkbox id="checkbox" checked className={useStyles({ bg: 'red' })} />
99
- <Checkbox id="checkbox" disabled />
100
- <Checkbox id="checkbox" checked disabled />
101
- </div>
102
- </Story>
103
- </Preview>
104
-
105
- ### Checkbox with required label
106
-
107
- <Preview>
108
- <Story name="CheckboxThree">
109
- <div>
110
- <Checkbox
111
- checked
112
- id="required"
113
- value="required"
114
- required
115
- label="This label is required"
116
- />
117
- </div>
118
- </Story>
119
- </Preview>
97
+ <ArgsTable story="Default" />
@@ -0,0 +1,78 @@
1
+ import React, { useState } from 'react';
2
+ import type { Meta, ComponentStory } from '@storybook/react';
3
+
4
+ import { Checkbox } from './Checkbox';
5
+
6
+ export default {
7
+ title: 'Components/Checkbox',
8
+ parameters: {
9
+ actions: {
10
+ handles: ['click'],
11
+ },
12
+ },
13
+ argTypes: {
14
+ variant: {
15
+ control: {
16
+ type: 'text',
17
+ },
18
+ description: 'Checkbox variant',
19
+ defaultValue: '__default',
20
+ },
21
+ labelVariant: {
22
+ control: {
23
+ type: 'text',
24
+ },
25
+ description: 'Checkbox label variant',
26
+ defaultValue: 'inline',
27
+ },
28
+ label: {
29
+ control: {
30
+ type: 'text',
31
+ },
32
+ description: 'Label',
33
+ defaultValue: 'Checkbox Label',
34
+ },
35
+ required: {
36
+ control: {
37
+ type: 'boolean',
38
+ },
39
+ description: 'Required',
40
+ defaultValue: false,
41
+ },
42
+ disabled: {
43
+ control: {
44
+ type: 'boolean',
45
+ },
46
+ description: 'Disabled',
47
+ defaultValue: false,
48
+ },
49
+ error: {
50
+ control: {
51
+ type: 'boolean',
52
+ },
53
+ description: 'Error',
54
+ defaultValue: false,
55
+ },
56
+ errorMessage: {
57
+ control: {
58
+ type: 'text',
59
+ },
60
+ description: 'Error Message',
61
+ },
62
+ },
63
+ } as Meta;
64
+
65
+ export const Basic: ComponentStory<typeof Checkbox> = ({
66
+ onChange,
67
+ checked,
68
+ ...args
69
+ }) => {
70
+ const [isChecked, setChecked] = useState(false);
71
+ return (
72
+ <Checkbox
73
+ onChange={() => setChecked(!isChecked)}
74
+ checked={isChecked}
75
+ {...args}
76
+ />
77
+ );
78
+ };
@@ -1,51 +1,166 @@
1
1
  import React from 'react';
2
- import { render, screen, fireEvent } from '@testing-library/react';
3
- import { Checkbox } from '@marigold/components';
2
+ import { fireEvent, render, screen } from '@testing-library/react';
3
+ import { Checkbox } from './Checkbox';
4
+ import { ThemeProvider } from '@marigold/system';
5
+
6
+ const theme = {
7
+ space: {
8
+ none: 0,
9
+ small: 2,
10
+ },
11
+ colors: {
12
+ disabled: 'gray',
13
+ },
14
+ checkbox: {
15
+ __default: {
16
+ m: 'small',
17
+ },
18
+ },
19
+ label: {
20
+ inline: {
21
+ fontSize: '14px',
22
+ },
23
+ above: {
24
+ fontSize: '8px',
25
+ },
26
+ },
27
+ };
28
+
29
+ test('supports default labelVariant', () => {
30
+ render(
31
+ <ThemeProvider theme={theme}>
32
+ <Checkbox id="test" title="checkbox" label="label" />
33
+ </ThemeProvider>
34
+ );
35
+
36
+ const label = screen.getByText(/label/);
37
+ expect(label).toHaveStyle(`font-size: 14px`);
38
+ });
39
+
40
+ test('supports other labelVariant than default', () => {
41
+ render(
42
+ <ThemeProvider theme={theme}>
43
+ <Checkbox id="test" title="checkbox" label="label" labelVariant="above" />
44
+ </ThemeProvider>
45
+ );
46
+
47
+ const label = screen.getByText(/label/);
48
+ expect(label).toHaveStyle(`font-size: 8px`);
49
+ });
4
50
 
5
51
  test('supports label prop', () => {
6
52
  render(<Checkbox label="Test" id="test" title="checkbox" />);
7
- const checkbox = screen.getByText(/Test/);
8
53
 
9
- expect(checkbox).toBeDefined();
54
+ const checkboxLabel = screen.getByText(/Test/);
55
+ expect(checkboxLabel).toBeDefined();
10
56
  });
11
57
 
12
- test('supports required prop an renders required icon', () => {
58
+ test('supports required prop and renders required icon', () => {
13
59
  render(<Checkbox label="Test" id="test" required title="checkbox" />);
14
- const checkbox = screen.getByText(/Test/);
15
60
 
16
- expect(checkbox).toContainHTML('path d="M10.8');
61
+ const label = screen.getByText(/Test/);
62
+ expect(label.nextSibling).toContainHTML('path d="M10.8');
17
63
  });
18
64
 
19
65
  test('supports default type', () => {
20
- render(<Checkbox id="test" title="checkbox" />);
21
- const checkbox = screen.getByTitle(/checkbox/);
66
+ render(<Checkbox id="checkbox" title="checkbox" label="Test" />);
22
67
 
68
+ const checkbox = screen.getByTitle(/checkbox/);
23
69
  expect(checkbox.getAttribute('type')).toEqual('checkbox');
24
70
  });
25
71
 
26
72
  test('renders <input> element', () => {
27
- render(<Checkbox id="test" title="checkbox" />);
28
- const checkbox = screen.getByTitle(/checkbox/);
73
+ render(<Checkbox id="checkbox" title="checkbox" label="Test" />);
29
74
 
75
+ const checkbox = screen.getByTitle(/checkbox/);
30
76
  expect(checkbox instanceof HTMLInputElement).toBeTruthy();
31
77
  });
32
78
 
33
- test('renders <SVG> CircleUnchecked element', () => {
34
- render(<Checkbox id="checkbox" label="Test" />);
35
- const checkbox = screen.getByText(/Test/);
36
- expect(checkbox).toContainHTML('path d="M19.2917');
79
+ test('supports disabled prop', () => {
80
+ render(
81
+ <ThemeProvider theme={theme}>
82
+ <Checkbox id="test" title="checkbox" label="label" disabled />
83
+ </ThemeProvider>
84
+ );
85
+
86
+ const checkbox = screen.getByTitle(/checkbox/);
87
+ expect(checkbox).toHaveAttribute('disabled');
88
+ const label = screen.getByText(/label/);
89
+ expect(label).toHaveStyle(`color: gray`);
90
+ });
91
+
92
+ test('supports error and errorMessage prop', () => {
93
+ render(
94
+ <ThemeProvider theme={theme}>
95
+ <Checkbox
96
+ id="test"
97
+ title="checkbox"
98
+ label="test"
99
+ error
100
+ errorMessage="error"
101
+ />
102
+ </ThemeProvider>
103
+ );
104
+
105
+ const errorMessage = screen.getByText(/error/);
106
+ expect(errorMessage).toBeDefined();
37
107
  });
38
108
 
39
- test('renders <SVG> CircleChecked element', () => {
40
- render(<Checkbox id="checkbox" label="Test" checked onChange={() => {}} />);
41
- const checkbox = screen.getByText(/Test/);
42
- expect(checkbox).toContainHTML('path d="M19.2917');
109
+ test('supports checked checkbox', () => {
110
+ render(
111
+ <ThemeProvider theme={theme}>
112
+ <Checkbox
113
+ id="test"
114
+ title="checkbox"
115
+ label="Test"
116
+ onChange={() => {}}
117
+ checked
118
+ />
119
+ </ThemeProvider>
120
+ );
121
+
122
+ const checkbox = screen.getByTitle(/checkbox/);
123
+ expect(checkbox).toHaveAttribute('checked');
43
124
  });
44
125
 
45
- test('change state onClick', () => {
46
- render(<Checkbox id="checkbox" label="Test" />);
47
- const checkbox = screen.getByText(/Test/);
48
- expect(checkbox).toContainHTML('path d="M19.2917');
126
+ test('supports checked and disabled checkbox', () => {
127
+ render(
128
+ <ThemeProvider theme={theme}>
129
+ <Checkbox
130
+ id="test"
131
+ title="checkbox"
132
+ label="Test"
133
+ onChange={() => {}}
134
+ checked
135
+ disabled
136
+ />
137
+ </ThemeProvider>
138
+ );
139
+
140
+ const checkbox = screen.getByTitle(/checkbox/);
141
+ expect(checkbox).toHaveAttribute('checked');
142
+ expect(checkbox).toHaveAttribute('disabled');
143
+ });
144
+
145
+ test('correctly handles interaction', () => {
146
+ const click = jest.fn();
147
+ const change = jest.fn();
148
+
149
+ render(
150
+ <ThemeProvider theme={theme}>
151
+ <Checkbox
152
+ id="test"
153
+ title="checkbox"
154
+ label="Test"
155
+ onClick={click}
156
+ onChange={change}
157
+ />
158
+ </ThemeProvider>
159
+ );
160
+
161
+ const checkbox = screen.getByTitle(/checkbox/);
49
162
  fireEvent.click(checkbox);
50
- expect(checkbox).toContainHTML('path d="M19.2917');
163
+
164
+ expect(click).toHaveBeenCalledTimes(1);
165
+ expect(change).toHaveBeenCalledTimes(1);
51
166
  });