@marigold/components 0.2.0 → 0.3.3
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 +180 -0
- package/dist/ActionGroup/ActionGroup.d.ts +1 -2
- package/dist/ActionGroup/ActionGroup.stories.d.ts +5 -0
- package/dist/Alert/Alert.d.ts +7 -1
- package/dist/Alert/Alert.stories.d.ts +5 -0
- package/dist/Badge/Badge.d.ts +5 -0
- package/dist/Badge/Badge.stories.d.ts +5 -0
- package/dist/Box.d.ts +2 -0
- package/dist/Button/Button.d.ts +5 -0
- package/dist/Button/Button.stories.d.ts +5 -0
- package/dist/Card/Card.d.ts +5 -0
- package/dist/Card/Card.stories.d.ts +5 -0
- package/dist/Checkbox/Checkbox.d.ts +10 -5
- package/dist/Checkbox/Checkbox.stories.d.ts +5 -0
- package/dist/Checkbox/CheckboxIcons.d.ts +9 -9
- package/dist/Column/Column.stories.d.ts +5 -0
- package/dist/Columns/Columns.d.ts +2 -2
- package/dist/Columns/Columns.stories.d.ts +5 -0
- package/dist/Container/Container.stories.d.ts +5 -0
- package/dist/Dialog/Dialog.d.ts +5 -2
- package/dist/Dialog/Dialog.stories.d.ts +5 -0
- package/dist/Dialog/ModalDialog.d.ts +4 -1
- package/dist/Divider/Divider.d.ts +7 -3
- package/dist/Divider/Divider.stories.d.ts +5 -0
- package/dist/Field/Field.d.ts +2 -0
- package/dist/Field/Field.stories.d.ts +5 -0
- package/dist/Image/Image.d.ts +5 -0
- 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 +5 -0
- package/dist/Input/Input.stories.d.ts +5 -0
- package/dist/Label/Label.d.ts +12 -1
- package/dist/Label/Label.stories.d.ts +5 -0
- package/dist/Link/Link.d.ts +3 -0
- package/dist/Link/Link.stories.d.ts +5 -0
- package/dist/Menu/Menu.d.ts +3 -0
- package/dist/Menu/Menu.stories.d.ts +5 -0
- package/dist/MenuItem/MenuItem.d.ts +5 -0
- package/dist/MenuItem/MenuItem.stories.d.ts +5 -0
- package/dist/Message/Message.d.ts +5 -0
- package/dist/Message/Message.stories.d.ts +5 -0
- package/dist/Provider/MarigoldProvider.d.ts +11 -3
- package/dist/Provider/index.d.ts +1 -1
- package/dist/Radio/Radio.d.ts +9 -5
- package/dist/Radio/Radio.stories.d.ts +5 -0
- package/dist/Radio/RadioIcon.d.ts +9 -0
- package/dist/Select/ListBox.d.ts +1 -0
- package/dist/Select/ListBoxSection.d.ts +1 -0
- package/dist/Select/Option.d.ts +1 -0
- package/dist/Select/Select.d.ts +15 -1
- package/dist/Select/Select.stories.d.ts +5 -0
- package/dist/Slider/Slider.d.ts +5 -0
- package/dist/Slider/Slider.stories.d.ts +5 -0
- package/dist/Stack/Stack.stories.d.ts +5 -0
- package/dist/Text/Text.d.ts +5 -0
- package/dist/Text/Text.stories.d.ts +5 -0
- package/dist/Textarea/Textarea.d.ts +5 -0
- package/dist/Textarea/Textarea.stories.d.ts +5 -0
- package/dist/ValidationMessage/ValidationMessage.d.ts +5 -0
- 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 +536 -580
- 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 +481 -535
- package/dist/components.esm.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/theme.d.ts +23 -48
- package/package.json +8 -4
- package/src/ActionGroup/ActionGroup.stories.tsx +47 -0
- package/src/ActionGroup/ActionGroup.test.tsx +36 -36
- package/src/ActionGroup/ActionGroup.tsx +17 -28
- package/src/Alert/Alert.stories.tsx +32 -0
- package/src/Alert/Alert.test.tsx +4 -1
- package/src/Alert/Alert.tsx +18 -3
- package/src/Badge/Badge.stories.tsx +38 -0
- package/src/Badge/Badge.test.tsx +5 -1
- package/src/Badge/Badge.tsx +13 -1
- package/src/Box.ts +2 -0
- package/src/Button/{Button.stories.mdx → Button.stories.tsx} +10 -17
- package/src/Button/Button.test.tsx +34 -11
- package/src/Button/Button.tsx +17 -3
- package/src/Card/{Card.stories.mdx → Card.stories.tsx} +9 -17
- package/src/Card/Card.test.tsx +8 -3
- package/src/Card/Card.tsx +13 -1
- package/src/Checkbox/{Checkbox.stories.mdx → Checkbox.stories.tsx} +31 -39
- package/src/Checkbox/Checkbox.test.tsx +77 -8
- package/src/Checkbox/Checkbox.tsx +70 -90
- package/src/Checkbox/CheckboxIcons.tsx +51 -41
- package/src/Column/Column.stories.tsx +33 -0
- package/src/Column/Column.tsx +0 -0
- package/src/Columns/Columns.stories.tsx +75 -0
- package/src/Columns/Columns.test.tsx +34 -23
- package/src/Columns/Columns.tsx +30 -30
- package/src/Container/Container.stories.tsx +14 -0
- package/src/Container/Container.tsx +0 -0
- package/src/Dialog/{Dialog.stories.mdx → Dialog.stories.tsx} +33 -18
- package/src/Dialog/Dialog.test.tsx +91 -20
- package/src/Dialog/Dialog.tsx +63 -17
- package/src/Dialog/ModalDialog.tsx +33 -4
- package/src/Divider/Divider.stories.tsx +30 -0
- package/src/Divider/Divider.test.tsx +32 -23
- package/src/Divider/Divider.tsx +27 -7
- package/src/Field/{Field.stories.mdx → Field.stories.tsx} +33 -20
- package/src/Field/Field.test.tsx +55 -5
- package/src/Field/Field.tsx +10 -8
- package/src/Image/Image.stories.tsx +34 -0
- package/src/Image/Image.test.tsx +4 -1
- package/src/Image/Image.tsx +13 -1
- 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.mdx → Input.stories.tsx} +10 -17
- package/src/Input/Input.test.tsx +7 -3
- package/src/Input/Input.tsx +13 -1
- package/src/Label/{Label.stories.mdx → Label.stories.tsx} +10 -21
- package/src/Label/Label.test.tsx +25 -4
- package/src/Label/Label.tsx +42 -9
- package/src/Link/Link.stories.tsx +35 -0
- package/src/Link/Link.test.tsx +6 -2
- package/src/Link/Link.tsx +12 -1
- package/src/Menu/{Menu.stories.mdx → Menu.stories.tsx} +13 -32
- package/src/Menu/Menu.test.tsx +7 -2
- package/src/Menu/Menu.tsx +10 -0
- package/src/MenuItem/MenuItem.stories.tsx +30 -0
- package/src/MenuItem/MenuItem.test.tsx +7 -2
- package/src/MenuItem/MenuItem.tsx +12 -0
- package/src/Message/Message.stories.tsx +30 -0
- package/src/Message/Message.test.tsx +4 -1
- package/src/Message/Message.tsx +17 -5
- package/src/Provider/MarigoldProvider.test.tsx +65 -55
- package/src/Provider/MarigoldProvider.tsx +37 -19
- package/src/Provider/index.ts +2 -1
- package/src/Radio/{Radio.stories.mdx → Radio.stories.tsx} +31 -39
- package/src/Radio/Radio.test.tsx +78 -9
- package/src/Radio/Radio.tsx +58 -87
- package/src/Radio/RadioIcon.tsx +49 -0
- package/src/Select/ListBox.tsx +1 -0
- package/src/Select/{Select.stories.mdx → Select.stories.tsx} +23 -20
- package/src/Select/Select.test.tsx +39 -1
- package/src/Select/Select.tsx +24 -13
- package/src/Slider/Slider.stories.tsx +24 -0
- package/src/Slider/Slider.test.tsx +10 -6
- package/src/Slider/Slider.tsx +25 -13
- package/src/Stack/Stack.stories.tsx +57 -0
- package/src/Stack/Stack.test.tsx +16 -7
- package/src/Stack/Stack.tsx +0 -0
- package/src/Text/{Text.stories.mdx → Text.stories.tsx} +20 -19
- package/src/Text/Text.test.tsx +2 -2
- package/src/Text/Text.tsx +12 -0
- package/src/Textarea/{Textarea.stories.mdx → Textarea.stories.tsx} +14 -24
- package/src/Textarea/Textarea.test.tsx +7 -3
- package/src/Textarea/Textarea.tsx +13 -1
- package/src/ValidationMessage/{ValidationMessage.stories.mdx → ValidationMessage.stories.tsx} +8 -17
- package/src/ValidationMessage/ValidationMessage.test.tsx +7 -2
- package/src/ValidationMessage/ValidationMessage.tsx +12 -0
- 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 +2 -2
- package/src/theme.ts +49 -48
- package/dist/Box/Box.d.ts +0 -47
- package/dist/Box/index.d.ts +0 -1
- package/dist/Heading/Heading.d.ts +0 -7
- package/dist/Heading/index.d.ts +0 -1
- package/dist/Hidden/Hidden.d.ts +0 -5
- package/dist/Hidden/index.d.ts +0 -1
- package/dist/Radio/RadioIcons.d.ts +0 -9
- package/src/ActionGroup/ActionGroup.stories.mdx +0 -62
- package/src/Alert/Alert.stories.mdx +0 -35
- package/src/Badge/Badge.stories.mdx +0 -57
- package/src/Box/Box.stories.mdx +0 -334
- package/src/Box/Box.test.tsx +0 -133
- package/src/Box/Box.tsx +0 -165
- package/src/Box/index.ts +0 -1
- package/src/Column/Column.stories.mdx +0 -49
- package/src/Columns/Columns.stories.mdx +0 -65
- package/src/Container/Container.stories.mdx +0 -19
- package/src/Divider/Divider.stories.mdx +0 -37
- package/src/Heading/Heading.stories.mdx +0 -39
- package/src/Heading/Heading.test.tsx +0 -77
- package/src/Heading/Heading.tsx +0 -19
- package/src/Heading/index.ts +0 -1
- package/src/Hidden/Hidden.stories.mdx +0 -39
- package/src/Hidden/Hidden.test.tsx +0 -24
- package/src/Hidden/Hidden.tsx +0 -16
- package/src/Hidden/index.ts +0 -1
- package/src/Image/Image.stories.mdx +0 -36
- package/src/Link/Link.stories.mdx +0 -45
- package/src/MenuItem/MenuItem.stories.mdx +0 -37
- package/src/Message/Message.stories.mdx +0 -44
- package/src/Radio/RadioIcons.tsx +0 -39
- package/src/Slider/Slider.stories.mdx +0 -31
- package/src/Stack/Stack.stories.mdx +0 -51
|
@@ -1,60 +1,57 @@
|
|
|
1
|
-
import
|
|
1
|
+
import React, { useState } from 'react';
|
|
2
|
+
import type { Meta, ComponentStory } from '@storybook/react';
|
|
3
|
+
|
|
2
4
|
import { Checkbox } from './Checkbox';
|
|
3
|
-
import { useState } from 'react';
|
|
4
5
|
|
|
5
|
-
|
|
6
|
-
title
|
|
7
|
-
parameters
|
|
6
|
+
export default {
|
|
7
|
+
title: 'Components/Checkbox',
|
|
8
|
+
parameters: {
|
|
8
9
|
actions: {
|
|
9
10
|
handles: ['click'],
|
|
10
11
|
},
|
|
11
|
-
}
|
|
12
|
-
argTypes
|
|
13
|
-
|
|
12
|
+
},
|
|
13
|
+
argTypes: {
|
|
14
|
+
variant: {
|
|
14
15
|
control: {
|
|
15
16
|
type: 'text',
|
|
16
17
|
},
|
|
17
|
-
|
|
18
|
-
|
|
18
|
+
description: 'Checkbox variant',
|
|
19
|
+
defaultValue: '__default',
|
|
19
20
|
},
|
|
20
|
-
|
|
21
|
+
labelVariant: {
|
|
21
22
|
control: {
|
|
22
23
|
type: 'text',
|
|
23
24
|
},
|
|
24
|
-
description: 'Checkbox variant',
|
|
25
|
-
|
|
26
|
-
defaultValue: {
|
|
27
|
-
summary: 'default',
|
|
28
|
-
},
|
|
29
|
-
},
|
|
25
|
+
description: 'Checkbox label variant',
|
|
26
|
+
defaultValue: 'inline',
|
|
30
27
|
},
|
|
31
28
|
label: {
|
|
32
29
|
control: {
|
|
33
30
|
type: 'text',
|
|
34
31
|
},
|
|
35
32
|
description: 'Label',
|
|
33
|
+
defaultValue: 'Checkbox Label',
|
|
36
34
|
},
|
|
37
35
|
required: {
|
|
38
36
|
control: {
|
|
39
37
|
type: 'boolean',
|
|
40
38
|
},
|
|
41
|
-
description: '
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
39
|
+
description: 'Required',
|
|
40
|
+
defaultValue: false,
|
|
41
|
+
},
|
|
42
|
+
disabled: {
|
|
43
|
+
control: {
|
|
44
|
+
type: 'boolean',
|
|
46
45
|
},
|
|
46
|
+
description: 'Disabled',
|
|
47
|
+
defaultValue: false,
|
|
47
48
|
},
|
|
48
49
|
error: {
|
|
49
50
|
control: {
|
|
50
51
|
type: 'boolean',
|
|
51
52
|
},
|
|
52
53
|
description: 'Error',
|
|
53
|
-
|
|
54
|
-
defaultValue: {
|
|
55
|
-
summary: false,
|
|
56
|
-
},
|
|
57
|
-
},
|
|
54
|
+
defaultValue: false,
|
|
58
55
|
},
|
|
59
56
|
errorMessage: {
|
|
60
57
|
control: {
|
|
@@ -62,25 +59,20 @@ import { useState } from 'react';
|
|
|
62
59
|
},
|
|
63
60
|
description: 'Error Message',
|
|
64
61
|
},
|
|
65
|
-
}
|
|
66
|
-
|
|
62
|
+
},
|
|
63
|
+
} as Meta;
|
|
67
64
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
65
|
+
export const Basic: ComponentStory<typeof Checkbox> = ({
|
|
66
|
+
onChange,
|
|
67
|
+
checked,
|
|
68
|
+
...args
|
|
69
|
+
}) => {
|
|
71
70
|
const [isChecked, setChecked] = useState(false);
|
|
72
71
|
return (
|
|
73
72
|
<Checkbox
|
|
74
73
|
onChange={() => setChecked(!isChecked)}
|
|
75
74
|
checked={isChecked}
|
|
76
|
-
label="Checkbox Label"
|
|
77
75
|
{...args}
|
|
78
76
|
/>
|
|
79
77
|
);
|
|
80
78
|
};
|
|
81
|
-
|
|
82
|
-
<Canvas>
|
|
83
|
-
<Story name="Default">{Template.bind({})}</Story>
|
|
84
|
-
</Canvas>
|
|
85
|
-
|
|
86
|
-
<ArgsTable story="Default" />
|
|
@@ -1,16 +1,53 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import { render, screen } from '@testing-library/react';
|
|
2
|
+
import { fireEvent, render, screen } from '@testing-library/react';
|
|
3
3
|
import { Checkbox } from './Checkbox';
|
|
4
4
|
import { ThemeProvider } from '@marigold/system';
|
|
5
5
|
|
|
6
6
|
const theme = {
|
|
7
|
+
space: {
|
|
8
|
+
none: 0,
|
|
9
|
+
small: 2,
|
|
10
|
+
},
|
|
11
|
+
colors: {
|
|
12
|
+
disabled: 'gray',
|
|
13
|
+
},
|
|
7
14
|
checkbox: {
|
|
8
|
-
|
|
9
|
-
m: '
|
|
15
|
+
__default: {
|
|
16
|
+
m: 'small',
|
|
17
|
+
},
|
|
18
|
+
},
|
|
19
|
+
label: {
|
|
20
|
+
inline: {
|
|
21
|
+
fontSize: '14px',
|
|
22
|
+
},
|
|
23
|
+
above: {
|
|
24
|
+
fontSize: '8px',
|
|
10
25
|
},
|
|
11
26
|
},
|
|
12
27
|
};
|
|
13
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
|
+
});
|
|
50
|
+
|
|
14
51
|
test('supports label prop', () => {
|
|
15
52
|
render(<Checkbox label="Test" id="test" title="checkbox" />);
|
|
16
53
|
|
|
@@ -26,14 +63,14 @@ test('supports required prop and renders required icon', () => {
|
|
|
26
63
|
});
|
|
27
64
|
|
|
28
65
|
test('supports default type', () => {
|
|
29
|
-
render(<Checkbox id="checkbox" title="checkbox" />);
|
|
66
|
+
render(<Checkbox id="checkbox" title="checkbox" label="Test" />);
|
|
30
67
|
|
|
31
68
|
const checkbox = screen.getByTitle(/checkbox/);
|
|
32
69
|
expect(checkbox.getAttribute('type')).toEqual('checkbox');
|
|
33
70
|
});
|
|
34
71
|
|
|
35
72
|
test('renders <input> element', () => {
|
|
36
|
-
render(<Checkbox id="checkbox" title="checkbox" />);
|
|
73
|
+
render(<Checkbox id="checkbox" title="checkbox" label="Test" />);
|
|
37
74
|
|
|
38
75
|
const checkbox = screen.getByTitle(/checkbox/);
|
|
39
76
|
expect(checkbox instanceof HTMLInputElement).toBeTruthy();
|
|
@@ -48,6 +85,8 @@ test('supports disabled prop', () => {
|
|
|
48
85
|
|
|
49
86
|
const checkbox = screen.getByTitle(/checkbox/);
|
|
50
87
|
expect(checkbox).toHaveAttribute('disabled');
|
|
88
|
+
const label = screen.getByText(/label/);
|
|
89
|
+
expect(label).toHaveStyle(`color: gray`);
|
|
51
90
|
});
|
|
52
91
|
|
|
53
92
|
test('supports error and errorMessage prop', () => {
|
|
@@ -70,12 +109,18 @@ test('supports error and errorMessage prop', () => {
|
|
|
70
109
|
test('supports checked checkbox', () => {
|
|
71
110
|
render(
|
|
72
111
|
<ThemeProvider theme={theme}>
|
|
73
|
-
<Checkbox
|
|
112
|
+
<Checkbox
|
|
113
|
+
id="test"
|
|
114
|
+
title="checkbox"
|
|
115
|
+
label="Test"
|
|
116
|
+
onChange={() => {}}
|
|
117
|
+
checked
|
|
118
|
+
/>
|
|
74
119
|
</ThemeProvider>
|
|
75
120
|
);
|
|
76
121
|
|
|
77
122
|
const checkbox = screen.getByTitle(/checkbox/);
|
|
78
|
-
expect(checkbox).
|
|
123
|
+
expect(checkbox).toHaveAttribute('checked');
|
|
79
124
|
});
|
|
80
125
|
|
|
81
126
|
test('supports checked and disabled checkbox', () => {
|
|
@@ -84,6 +129,7 @@ test('supports checked and disabled checkbox', () => {
|
|
|
84
129
|
<Checkbox
|
|
85
130
|
id="test"
|
|
86
131
|
title="checkbox"
|
|
132
|
+
label="Test"
|
|
87
133
|
onChange={() => {}}
|
|
88
134
|
checked
|
|
89
135
|
disabled
|
|
@@ -92,6 +138,29 @@ test('supports checked and disabled checkbox', () => {
|
|
|
92
138
|
);
|
|
93
139
|
|
|
94
140
|
const checkbox = screen.getByTitle(/checkbox/);
|
|
95
|
-
expect(checkbox).
|
|
141
|
+
expect(checkbox).toHaveAttribute('checked');
|
|
96
142
|
expect(checkbox).toHaveAttribute('disabled');
|
|
97
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/);
|
|
162
|
+
fireEvent.click(checkbox);
|
|
163
|
+
|
|
164
|
+
expect(click).toHaveBeenCalledTimes(1);
|
|
165
|
+
expect(change).toHaveBeenCalledTimes(1);
|
|
166
|
+
});
|
|
@@ -1,90 +1,68 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
+
import { useFocusRing } from '@react-aria/focus';
|
|
3
|
+
import { VisuallyHidden } from '@react-aria/visually-hidden';
|
|
4
|
+
import { useCheckbox } from '@react-aria/checkbox';
|
|
5
|
+
import { useToggleState } from '@react-stately/toggle';
|
|
6
|
+
import { ToggleProps } from '@react-types/checkbox';
|
|
7
|
+
|
|
2
8
|
import { ComponentProps } from '@marigold/types';
|
|
3
9
|
import { Exclamation } from '@marigold/icons';
|
|
4
10
|
|
|
5
|
-
import {
|
|
6
|
-
|
|
11
|
+
import { CheckboxIcon, CheckboxIconProps } from './CheckboxIcons';
|
|
7
12
|
import { Box } from '../Box';
|
|
8
13
|
import { Label } from '../Label';
|
|
9
14
|
import { ValidationMessage } from '../ValidationMessage';
|
|
10
15
|
|
|
11
|
-
//
|
|
16
|
+
// Theme Extension
|
|
12
17
|
// ---------------
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
error?: boolean;
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
const CheckboxIcon: React.FC<CheckboxIconProps> = ({
|
|
22
|
-
variant,
|
|
23
|
-
checked,
|
|
24
|
-
disabled,
|
|
25
|
-
error,
|
|
26
|
-
}) => {
|
|
27
|
-
if (checked) {
|
|
28
|
-
return (
|
|
29
|
-
<Box
|
|
30
|
-
as={CheckboxChecked}
|
|
31
|
-
variant={`checkbox.${variant}`}
|
|
32
|
-
disabled={disabled}
|
|
33
|
-
/>
|
|
34
|
-
);
|
|
35
|
-
}
|
|
36
|
-
return (
|
|
37
|
-
<Box
|
|
38
|
-
as={CheckboxUnchecked}
|
|
39
|
-
variant={`checkbox.${variant}`}
|
|
40
|
-
disabled={disabled}
|
|
41
|
-
error={error}
|
|
42
|
-
/>
|
|
43
|
-
);
|
|
44
|
-
};
|
|
18
|
+
export interface CheckboxThemeExtension<Value> {
|
|
19
|
+
checkbox?: {
|
|
20
|
+
[key: string]: Value;
|
|
21
|
+
};
|
|
22
|
+
}
|
|
45
23
|
|
|
46
24
|
// Checkbox Input
|
|
47
25
|
// ---------------
|
|
48
|
-
type CheckboxInputProps =
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
} & ComponentProps<'input'>;
|
|
26
|
+
type CheckboxInputProps = CheckboxIconProps &
|
|
27
|
+
ToggleProps &
|
|
28
|
+
ComponentProps<'input'>;
|
|
52
29
|
|
|
53
|
-
const CheckboxInput: React.FC<CheckboxInputProps> = ({
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
<Box
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
30
|
+
const CheckboxInput: React.FC<CheckboxInputProps> = ({ error, ...props }) => {
|
|
31
|
+
const state = useToggleState(props);
|
|
32
|
+
const ref = React.useRef<HTMLInputElement>(null);
|
|
33
|
+
const { inputProps } = useCheckbox(props, state, ref);
|
|
34
|
+
const { focusProps } = useFocusRing();
|
|
35
|
+
|
|
36
|
+
return (
|
|
37
|
+
<Box pr="xsmall">
|
|
38
|
+
<VisuallyHidden>
|
|
39
|
+
<Box
|
|
40
|
+
as="input"
|
|
41
|
+
type="checkbox"
|
|
42
|
+
disabled={props.disabled}
|
|
43
|
+
{...inputProps}
|
|
44
|
+
{...focusProps}
|
|
45
|
+
ref={ref}
|
|
46
|
+
{...props}
|
|
47
|
+
/>
|
|
48
|
+
</VisuallyHidden>
|
|
49
|
+
<CheckboxIcon
|
|
50
|
+
checked={props.checked}
|
|
51
|
+
variant={props.variant}
|
|
52
|
+
disabled={props.disabled}
|
|
53
|
+
error={error}
|
|
54
|
+
/>
|
|
55
|
+
</Box>
|
|
56
|
+
);
|
|
57
|
+
};
|
|
81
58
|
|
|
82
59
|
// Checkbox
|
|
83
60
|
// ---------------
|
|
84
61
|
export type CheckboxProps = {
|
|
85
62
|
id: string;
|
|
86
|
-
label
|
|
63
|
+
label: string;
|
|
87
64
|
required?: boolean;
|
|
65
|
+
labelVariant?: string;
|
|
88
66
|
error?: boolean;
|
|
89
67
|
errorMessage?: string;
|
|
90
68
|
} & CheckboxInputProps;
|
|
@@ -92,30 +70,32 @@ export type CheckboxProps = {
|
|
|
92
70
|
export const Checkbox: React.FC<CheckboxProps> = ({
|
|
93
71
|
label,
|
|
94
72
|
required,
|
|
73
|
+
labelVariant = 'inline',
|
|
95
74
|
error,
|
|
96
75
|
errorMessage,
|
|
97
76
|
...props
|
|
98
77
|
}) => {
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
78
|
+
return (
|
|
79
|
+
<>
|
|
80
|
+
<Box
|
|
81
|
+
as={Label}
|
|
82
|
+
__baseCSS={{
|
|
83
|
+
':hover': { cursor: props.disabled ? 'not-allowed' : 'pointer' },
|
|
84
|
+
}}
|
|
85
|
+
htmlFor={props.id}
|
|
86
|
+
required={required}
|
|
87
|
+
variant={`label.${labelVariant}`}
|
|
88
|
+
color={props.disabled ? 'disabled' : 'text'}
|
|
89
|
+
>
|
|
90
|
+
<Box as={CheckboxInput} error={error} {...props} />
|
|
91
|
+
{label}
|
|
92
|
+
</Box>
|
|
93
|
+
{error && errorMessage && (
|
|
94
|
+
<ValidationMessage>
|
|
95
|
+
<Exclamation size={16} />
|
|
96
|
+
{errorMessage}
|
|
97
|
+
</ValidationMessage>
|
|
98
|
+
)}
|
|
99
|
+
</>
|
|
100
|
+
);
|
|
121
101
|
};
|
|
@@ -1,49 +1,59 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import { SVG } from '@marigold/
|
|
2
|
+
import { conditional, State, SVG } from '@marigold/system';
|
|
3
3
|
|
|
4
4
|
import { Box } from '../Box';
|
|
5
5
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
variant={disabled ? 'checkbox.checked.disabled' : 'checkbox.checked'}
|
|
16
|
-
/>
|
|
17
|
-
<Box
|
|
18
|
-
as="path"
|
|
19
|
-
fillRule="evenodd"
|
|
20
|
-
clipRule="evenodd"
|
|
21
|
-
d="M13.9571 12.8338L12.4085 11.2852L6.08699 17.6007L3.59887 15.1126L2.04163 16.6588L6.08682 20.704L13.9571 12.8338Z"
|
|
22
|
-
variant="checkbox.checked.icon"
|
|
23
|
-
/>
|
|
24
|
-
</SVG>
|
|
25
|
-
);
|
|
6
|
+
// Checkbox Icon
|
|
7
|
+
// ---------------
|
|
8
|
+
export type CheckboxIconProps = {
|
|
9
|
+
variant?: string;
|
|
10
|
+
checked?: boolean;
|
|
11
|
+
disabled?: boolean;
|
|
12
|
+
error?: boolean;
|
|
13
|
+
children?: never;
|
|
14
|
+
};
|
|
26
15
|
|
|
27
|
-
export const
|
|
16
|
+
export const CheckboxIcon: React.FC<CheckboxIconProps> = ({
|
|
17
|
+
variant = '',
|
|
18
|
+
checked = false,
|
|
28
19
|
disabled = false,
|
|
29
20
|
error = false,
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
as="rect"
|
|
35
|
-
x="0.5"
|
|
36
|
-
y="8.5"
|
|
37
|
-
width="15px"
|
|
38
|
-
height="15px"
|
|
39
|
-
rx="1.5"
|
|
40
|
-
variant={
|
|
41
|
-
disabled
|
|
42
|
-
? 'checkbox.unchecked.disabled'
|
|
43
|
-
: error
|
|
44
|
-
? 'checkbox.unchecked.error'
|
|
45
|
-
: 'checkbox.unchecked'
|
|
21
|
+
}) => {
|
|
22
|
+
const conditionalStates: State = disabled
|
|
23
|
+
? {
|
|
24
|
+
disabled: disabled,
|
|
46
25
|
}
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
26
|
+
: {
|
|
27
|
+
checked: checked,
|
|
28
|
+
error: error,
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
return (
|
|
32
|
+
<SVG
|
|
33
|
+
width="16"
|
|
34
|
+
height="32"
|
|
35
|
+
viewBox="0 0 16 32"
|
|
36
|
+
fill="none"
|
|
37
|
+
aria-hidden="true"
|
|
38
|
+
>
|
|
39
|
+
<Box
|
|
40
|
+
as="rect"
|
|
41
|
+
x="0.5"
|
|
42
|
+
y="8.5"
|
|
43
|
+
width="15px"
|
|
44
|
+
height="15px"
|
|
45
|
+
rx="1.5"
|
|
46
|
+
variant={conditional(`checkbox.${variant}`, conditionalStates)}
|
|
47
|
+
/>
|
|
48
|
+
{checked && (
|
|
49
|
+
<Box
|
|
50
|
+
__baseCSS={{ fill: 'gray00' }}
|
|
51
|
+
as="path"
|
|
52
|
+
fillRule="evenodd"
|
|
53
|
+
clipRule="evenodd"
|
|
54
|
+
d="M13.9571 12.8338L12.4085 11.2852L6.08699 17.6007L3.59887 15.1126L2.04163 16.6588L6.08682 20.704L13.9571 12.8338Z"
|
|
55
|
+
/>
|
|
56
|
+
)}
|
|
57
|
+
</SVG>
|
|
58
|
+
);
|
|
59
|
+
};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import type { Meta, ComponentStory } from '@storybook/react';
|
|
3
|
+
|
|
4
|
+
import { Column } from './Column';
|
|
5
|
+
import { Box } from '../Box';
|
|
6
|
+
|
|
7
|
+
export default {
|
|
8
|
+
title: 'Components/Column',
|
|
9
|
+
argTypes: {
|
|
10
|
+
width: {
|
|
11
|
+
control: {
|
|
12
|
+
type: 'range',
|
|
13
|
+
min: 0,
|
|
14
|
+
max: 12,
|
|
15
|
+
step: 1,
|
|
16
|
+
},
|
|
17
|
+
description: 'Absolute width in 12 grid',
|
|
18
|
+
table: {
|
|
19
|
+
defaultValue: {
|
|
20
|
+
summary: 12,
|
|
21
|
+
},
|
|
22
|
+
},
|
|
23
|
+
},
|
|
24
|
+
},
|
|
25
|
+
} as Meta;
|
|
26
|
+
|
|
27
|
+
export const Basic: ComponentStory<typeof Column> = args => (
|
|
28
|
+
<Column width={12} {...args}>
|
|
29
|
+
<Box p="small" border="1px solid gray" borderRadius="4px">
|
|
30
|
+
width=12
|
|
31
|
+
</Box>
|
|
32
|
+
</Column>
|
|
33
|
+
);
|
package/src/Column/Column.tsx
CHANGED
|
File without changes
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import type { Meta, ComponentStory } from '@storybook/react';
|
|
3
|
+
import { Column, Columns, Text } from '@marigold/components';
|
|
4
|
+
|
|
5
|
+
export default {
|
|
6
|
+
title: 'Components/Columns',
|
|
7
|
+
argTypes: {
|
|
8
|
+
space: {
|
|
9
|
+
control: {
|
|
10
|
+
type: 'select',
|
|
11
|
+
},
|
|
12
|
+
options: [
|
|
13
|
+
'none',
|
|
14
|
+
'xxsmall',
|
|
15
|
+
'xsmall',
|
|
16
|
+
'small',
|
|
17
|
+
'medium',
|
|
18
|
+
'large',
|
|
19
|
+
'xlarge',
|
|
20
|
+
'xxlarge',
|
|
21
|
+
],
|
|
22
|
+
description: 'Responsive Style Value',
|
|
23
|
+
table: {
|
|
24
|
+
defaultValue: {
|
|
25
|
+
summary: 'none',
|
|
26
|
+
},
|
|
27
|
+
},
|
|
28
|
+
},
|
|
29
|
+
horizontalAlign: {
|
|
30
|
+
control: {
|
|
31
|
+
type: 'select',
|
|
32
|
+
},
|
|
33
|
+
options: ['left', 'right', 'center'],
|
|
34
|
+
description: 'where to place',
|
|
35
|
+
table: {
|
|
36
|
+
defaultValue: {
|
|
37
|
+
summary: 'left',
|
|
38
|
+
},
|
|
39
|
+
},
|
|
40
|
+
},
|
|
41
|
+
verticalAlign: {
|
|
42
|
+
control: {
|
|
43
|
+
type: 'select',
|
|
44
|
+
},
|
|
45
|
+
options: ['top', 'bottom', 'center'],
|
|
46
|
+
description: 'where to place',
|
|
47
|
+
table: {
|
|
48
|
+
defaultValue: {
|
|
49
|
+
summary: 'top',
|
|
50
|
+
},
|
|
51
|
+
},
|
|
52
|
+
},
|
|
53
|
+
},
|
|
54
|
+
} as Meta;
|
|
55
|
+
|
|
56
|
+
export const Basic: ComponentStory<typeof Columns> = args => (
|
|
57
|
+
<Columns {...args}>
|
|
58
|
+
<Column width={6}>
|
|
59
|
+
<Text>First column</Text>
|
|
60
|
+
<Text>
|
|
61
|
+
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse
|
|
62
|
+
dignissim dapibus elit, vel egestas felis pharetra non. Cras malesuada,
|
|
63
|
+
massa nec ultricies efficitur.
|
|
64
|
+
</Text>
|
|
65
|
+
</Column>
|
|
66
|
+
<Column width={6}>
|
|
67
|
+
<Text>Second column</Text>
|
|
68
|
+
<Text>
|
|
69
|
+
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse
|
|
70
|
+
dignissim dapibus elit, vel egestas felis pharetra non. Cras malesuada,
|
|
71
|
+
massa nec ultricies efficitur.
|
|
72
|
+
</Text>
|
|
73
|
+
</Column>
|
|
74
|
+
</Columns>
|
|
75
|
+
);
|