@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.
- package/CHANGELOG.md +294 -0
- package/dist/ActionGroup/ActionGroup.d.ts +8 -0
- package/dist/ActionGroup/ActionGroup.stories.d.ts +5 -0
- package/dist/ActionGroup/index.d.ts +1 -0
- package/dist/Alert/Alert.d.ts +16 -3
- package/dist/Alert/Alert.stories.d.ts +5 -0
- package/dist/Badge/Badge.d.ts +11 -5
- package/dist/Badge/Badge.stories.d.ts +5 -0
- package/dist/Box.d.ts +2 -0
- package/dist/Button/Button.d.ts +9 -5
- package/dist/Button/Button.stories.d.ts +5 -0
- package/dist/Card/Card.d.ts +14 -0
- package/dist/Card/Card.stories.d.ts +5 -0
- package/dist/Card/index.d.ts +1 -0
- package/dist/Checkbox/Checkbox.d.ts +17 -5
- package/dist/Checkbox/Checkbox.stories.d.ts +5 -0
- package/dist/Checkbox/CheckboxIcons.d.ts +9 -0
- package/dist/Column/Column.d.ts +6 -4
- package/dist/Column/Column.stories.d.ts +5 -0
- package/dist/Columns/Columns.d.ts +10 -0
- package/dist/Columns/Columns.stories.d.ts +5 -0
- package/dist/Columns/index.d.ts +1 -0
- package/dist/Container/Container.d.ts +5 -4
- package/dist/Container/Container.stories.d.ts +5 -0
- package/dist/Dialog/Dialog.d.ts +17 -0
- package/dist/Dialog/Dialog.stories.d.ts +5 -0
- package/dist/Dialog/ModalDialog.d.ts +8 -0
- package/dist/Dialog/index.d.ts +1 -0
- package/dist/Divider/Divider.d.ts +10 -3
- package/dist/Divider/Divider.stories.d.ts +5 -0
- package/dist/Field/Field.d.ts +10 -5
- package/dist/Field/Field.stories.d.ts +5 -0
- package/dist/Image/Image.d.ts +11 -5
- package/dist/Image/Image.stories.d.ts +5 -0
- package/dist/Inline/Inline.d.ts +7 -0
- package/dist/Inline/Inline.stories.d.ts +5 -0
- package/dist/Inline/index.d.ts +1 -0
- package/dist/Input/Input.d.ts +10 -4
- package/dist/Input/Input.stories.d.ts +5 -0
- package/dist/Label/Label.d.ts +18 -5
- package/dist/Label/Label.stories.d.ts +5 -0
- package/dist/Link/Link.d.ts +10 -5
- package/dist/Link/Link.stories.d.ts +5 -0
- package/dist/Menu/Menu.d.ts +11 -4
- package/dist/Menu/Menu.stories.d.ts +5 -0
- package/dist/MenuItem/MenuItem.d.ts +11 -4
- package/dist/MenuItem/MenuItem.stories.d.ts +5 -0
- package/dist/Message/Message.d.ts +10 -4
- package/dist/Message/Message.stories.d.ts +5 -0
- package/dist/Provider/MarigoldProvider.d.ts +11 -0
- package/dist/Provider/index.d.ts +3 -0
- package/dist/Radio/Radio.d.ts +17 -4
- package/dist/Radio/RadioIcons.d.ts +10 -0
- package/dist/Select/ListBox.d.ts +9 -0
- package/dist/Select/ListBoxSection.d.ts +9 -0
- package/dist/Select/Option.d.ts +9 -0
- package/dist/Select/Popover.d.ts +9 -0
- package/dist/Select/Select.d.ts +27 -3
- package/dist/Select/Select.stories.d.ts +5 -0
- package/dist/Slider/Slider.d.ts +10 -4
- package/dist/Slider/Slider.stories.d.ts +5 -0
- package/dist/Stack/Stack.d.ts +7 -0
- package/dist/Stack/Stack.stories.d.ts +5 -0
- package/dist/Stack/index.d.ts +1 -0
- package/dist/Text/Text.d.ts +17 -7
- package/dist/Text/Text.stories.d.ts +5 -0
- package/dist/Textarea/Textarea.d.ts +15 -4
- package/dist/Textarea/Textarea.stories.d.ts +5 -0
- package/dist/ValidationMessage/ValidationMessage.d.ts +10 -4
- package/dist/ValidationMessage/ValidationMessage.stories.d.ts +5 -0
- package/dist/VisuallyHidden/VisuallyHidden.d.ts +1 -0
- package/dist/VisuallyHidden/VisuallyHidden.stories.d.ts +5 -0
- package/dist/VisuallyHidden/index.d.ts +1 -0
- package/dist/components.cjs.development.js +1276 -461
- 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 +1229 -461
- package/dist/components.esm.js.map +1 -1
- package/dist/index.d.ts +10 -3
- package/dist/theme.d.ts +23 -28
- package/package.json +27 -4
- package/src/ActionGroup/ActionGroup.stories.tsx +47 -0
- package/src/ActionGroup/ActionGroup.test.tsx +83 -0
- package/src/ActionGroup/ActionGroup.tsx +32 -0
- package/src/ActionGroup/index.ts +1 -0
- package/src/Alert/Alert.stories.tsx +32 -0
- package/src/Alert/Alert.test.tsx +34 -23
- package/src/Alert/Alert.tsx +48 -24
- package/src/Badge/Badge.stories.tsx +38 -0
- package/src/Badge/Badge.test.tsx +14 -40
- package/src/Badge/Badge.tsx +31 -28
- package/src/Box.ts +2 -0
- package/src/Button/Button.stories.tsx +57 -0
- package/src/Button/Button.test.tsx +76 -13
- package/src/Button/Button.tsx +58 -23
- package/src/Card/Card.stories.tsx +41 -0
- package/src/Card/Card.test.tsx +71 -0
- package/src/Card/Card.tsx +48 -0
- package/src/Card/index.ts +1 -0
- package/src/Checkbox/Checkbox.stories.mdx +90 -112
- package/src/Checkbox/Checkbox.stories.tsx +78 -0
- package/src/Checkbox/Checkbox.test.tsx +139 -24
- package/src/Checkbox/Checkbox.tsx +95 -58
- package/src/Checkbox/CheckboxIcons.tsx +59 -0
- package/src/Column/Column.stories.tsx +33 -0
- package/src/Column/Column.test.tsx +15 -59
- package/src/Column/Column.tsx +21 -19
- package/src/Columns/Columns.stories.tsx +75 -0
- package/src/Columns/Columns.test.tsx +113 -0
- package/src/Columns/Columns.tsx +69 -0
- package/src/Columns/index.ts +1 -0
- package/src/Container/Container.stories.tsx +14 -0
- package/src/Container/Container.test.tsx +8 -49
- package/src/Container/Container.tsx +8 -19
- package/src/Dialog/Dialog.stories.tsx +88 -0
- package/src/Dialog/Dialog.test.tsx +158 -0
- package/src/Dialog/Dialog.tsx +130 -0
- package/src/Dialog/ModalDialog.tsx +76 -0
- package/src/Dialog/index.ts +1 -0
- package/src/Divider/Divider.stories.tsx +30 -0
- package/src/Divider/Divider.test.tsx +14 -6
- package/src/Divider/Divider.tsx +20 -13
- package/src/Field/Field.stories.tsx +110 -0
- package/src/Field/Field.test.tsx +75 -34
- package/src/Field/Field.tsx +50 -43
- package/src/Image/Image.stories.tsx +34 -0
- package/src/Image/Image.test.tsx +6 -3
- package/src/Image/Image.tsx +21 -15
- package/src/Inline/Inline.stories.tsx +39 -0
- package/src/Inline/Inline.test.tsx +99 -0
- package/src/Inline/Inline.tsx +38 -0
- package/src/Inline/index.ts +1 -0
- package/src/Input/Input.stories.tsx +54 -0
- package/src/Input/Input.test.tsx +9 -5
- package/src/Input/Input.tsx +21 -16
- package/src/Label/Label.stories.tsx +41 -0
- package/src/Label/Label.test.tsx +41 -6
- package/src/Label/Label.tsx +59 -18
- package/src/Link/Link.stories.tsx +35 -0
- package/src/Link/Link.test.tsx +52 -22
- package/src/Link/Link.tsx +40 -20
- package/src/Menu/Menu.stories.tsx +62 -0
- package/src/Menu/Menu.test.tsx +13 -7
- package/src/Menu/Menu.tsx +44 -38
- package/src/MenuItem/MenuItem.stories.tsx +30 -0
- package/src/MenuItem/MenuItem.test.tsx +23 -14
- package/src/MenuItem/MenuItem.tsx +29 -18
- package/src/Message/Message.stories.tsx +30 -0
- package/src/Message/Message.test.tsx +5 -2
- package/src/Message/Message.tsx +48 -40
- package/src/Provider/MarigoldProvider.test.tsx +136 -0
- package/src/Provider/MarigoldProvider.tsx +47 -0
- package/src/Provider/index.ts +4 -0
- package/src/Radio/Radio.stories.mdx +91 -94
- package/src/Radio/Radio.test.tsx +92 -16
- package/src/Radio/Radio.tsx +114 -50
- package/src/Radio/RadioIcons.tsx +39 -0
- package/src/Select/ListBox.tsx +40 -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.tsx +81 -0
- package/src/Select/Select.test.tsx +311 -43
- package/src/Select/Select.tsx +174 -28
- package/src/Slider/Slider.stories.tsx +24 -0
- package/src/Slider/Slider.test.tsx +11 -7
- package/src/Slider/Slider.tsx +30 -15
- package/src/Stack/Stack.stories.tsx +57 -0
- package/src/Stack/Stack.test.tsx +138 -0
- package/src/Stack/Stack.tsx +39 -0
- package/src/Stack/index.ts +1 -0
- package/src/Text/Text.stories.tsx +61 -0
- package/src/Text/Text.test.tsx +41 -36
- package/src/Text/Text.tsx +55 -29
- package/src/Textarea/Textarea.stories.tsx +64 -0
- package/src/Textarea/Textarea.test.tsx +41 -5
- package/src/Textarea/Textarea.tsx +57 -17
- package/src/ValidationMessage/ValidationMessage.stories.tsx +27 -0
- package/src/ValidationMessage/ValidationMessage.test.tsx +19 -14
- package/src/ValidationMessage/ValidationMessage.tsx +36 -21
- package/src/VisuallyHidden/VisuallyHidden.stories.tsx +19 -0
- package/src/VisuallyHidden/VisuallyHidden.test.tsx +10 -0
- package/src/VisuallyHidden/VisuallyHidden.tsx +1 -0
- package/src/VisuallyHidden/index.ts +1 -0
- package/src/index.ts +11 -3
- package/src/theme.ts +49 -28
- package/dist/Heading/Heading.d.ts +0 -5
- package/dist/Heading/index.d.ts +0 -1
- package/dist/Hidden/Hidden.d.ts +0 -6
- package/dist/Hidden/index.d.ts +0 -1
- package/dist/Svg/Svg.d.ts +0 -6
- package/dist/Svg/index.d.ts +0 -1
- package/src/Alert/Alert.stories.mdx +0 -49
- package/src/Badge/Badge.stories.mdx +0 -41
- package/src/Button/Button.stories.mdx +0 -155
- package/src/Column/Column.stories.mdx +0 -76
- package/src/Container/Container.stories.mdx +0 -42
- package/src/Divider/Divider.stories.mdx +0 -42
- package/src/Field/Field.stories.mdx +0 -57
- package/src/Heading/Heading.stories.mdx +0 -79
- package/src/Heading/Heading.test.tsx +0 -63
- package/src/Heading/Heading.tsx +0 -22
- package/src/Heading/index.ts +0 -1
- package/src/Hidden/Hidden.stories.mdx +0 -64
- package/src/Hidden/Hidden.test.tsx +0 -87
- package/src/Hidden/Hidden.tsx +0 -25
- package/src/Hidden/index.ts +0 -1
- package/src/Image/Image.stories.mdx +0 -40
- package/src/Input/Input.stories.mdx +0 -44
- package/src/Label/Label.stories.mdx +0 -34
- package/src/Link/Link.stories.mdx +0 -37
- package/src/Menu/Menu.stories.mdx +0 -47
- package/src/MenuItem/MenuItem.stories.mdx +0 -32
- package/src/Message/Message.stories.mdx +0 -43
- package/src/Select/Select.stories.mdx +0 -43
- package/src/Slider/Slider.stories.mdx +0 -57
- package/src/Svg/Svg.stories.mdx +0 -47
- package/src/Svg/Svg.test.tsx +0 -76
- package/src/Svg/Svg.tsx +0 -31
- package/src/Svg/index.ts +0 -1
- package/src/Text/Text.stories.mdx +0 -60
- package/src/Textarea/Textarea.stories.mdx +0 -34
- 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
|
|
2
|
-
import { Checkbox } from '
|
|
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
|
|
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
|
-
|
|
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
|
-
|
|
13
|
-
|
|
93
|
+
<Canvas>
|
|
94
|
+
<Story name="Default">{Template.bind({})}</Story>
|
|
95
|
+
</Canvas>
|
|
14
96
|
|
|
15
|
-
|
|
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
|
|
3
|
-
import { Checkbox } from '
|
|
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
|
-
|
|
54
|
+
const checkboxLabel = screen.getByText(/Test/);
|
|
55
|
+
expect(checkboxLabel).toBeDefined();
|
|
10
56
|
});
|
|
11
57
|
|
|
12
|
-
test('supports required prop
|
|
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
|
-
|
|
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="
|
|
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="
|
|
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('
|
|
34
|
-
render(
|
|
35
|
-
|
|
36
|
-
|
|
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('
|
|
40
|
-
render(
|
|
41
|
-
|
|
42
|
-
|
|
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('
|
|
46
|
-
render(
|
|
47
|
-
|
|
48
|
-
|
|
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
|
-
|
|
163
|
+
|
|
164
|
+
expect(click).toHaveBeenCalledTimes(1);
|
|
165
|
+
expect(change).toHaveBeenCalledTimes(1);
|
|
51
166
|
});
|