@marigold/components 0.2.0 → 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 (195) hide show
  1. package/CHANGELOG.md +294 -0
  2. package/dist/ActionGroup/ActionGroup.d.ts +1 -2
  3. package/dist/ActionGroup/ActionGroup.stories.d.ts +5 -0
  4. package/dist/Alert/Alert.d.ts +10 -13
  5. package/dist/Alert/Alert.stories.d.ts +5 -0
  6. package/dist/Badge/Badge.d.ts +5 -0
  7. package/dist/Badge/Badge.stories.d.ts +5 -0
  8. package/dist/Box.d.ts +2 -0
  9. package/dist/Button/Button.d.ts +5 -0
  10. package/dist/Button/Button.stories.d.ts +5 -0
  11. package/dist/Card/Card.d.ts +5 -0
  12. package/dist/Card/Card.stories.d.ts +5 -0
  13. package/dist/Checkbox/Checkbox.d.ts +10 -5
  14. package/dist/Checkbox/Checkbox.stories.d.ts +5 -0
  15. package/dist/Checkbox/CheckboxIcons.d.ts +9 -9
  16. package/dist/Column/Column.stories.d.ts +5 -0
  17. package/dist/Columns/Columns.d.ts +2 -2
  18. package/dist/Columns/Columns.stories.d.ts +5 -0
  19. package/dist/Container/Container.stories.d.ts +5 -0
  20. package/dist/Dialog/Dialog.d.ts +5 -2
  21. package/dist/Dialog/Dialog.stories.d.ts +5 -0
  22. package/dist/Dialog/ModalDialog.d.ts +4 -1
  23. package/dist/Divider/Divider.d.ts +5 -0
  24. package/dist/Divider/Divider.stories.d.ts +5 -0
  25. package/dist/Field/Field.d.ts +2 -0
  26. package/dist/Field/Field.stories.d.ts +5 -0
  27. package/dist/Image/Image.d.ts +5 -0
  28. package/dist/Image/Image.stories.d.ts +5 -0
  29. package/dist/Inline/Inline.d.ts +7 -0
  30. package/dist/Inline/Inline.stories.d.ts +5 -0
  31. package/dist/Inline/index.d.ts +1 -0
  32. package/dist/Input/Input.d.ts +5 -0
  33. package/dist/Input/Input.stories.d.ts +5 -0
  34. package/dist/Label/Label.d.ts +12 -1
  35. package/dist/Label/Label.stories.d.ts +5 -0
  36. package/dist/Link/Link.d.ts +4 -1
  37. package/dist/Link/Link.stories.d.ts +5 -0
  38. package/dist/Menu/Menu.d.ts +3 -0
  39. package/dist/Menu/Menu.stories.d.ts +5 -0
  40. package/dist/MenuItem/MenuItem.d.ts +5 -0
  41. package/dist/MenuItem/MenuItem.stories.d.ts +5 -0
  42. package/dist/Message/Message.d.ts +5 -0
  43. package/dist/Message/Message.stories.d.ts +5 -0
  44. package/dist/Provider/MarigoldProvider.d.ts +11 -3
  45. package/dist/Provider/index.d.ts +1 -1
  46. package/dist/Radio/Radio.d.ts +6 -0
  47. package/dist/Radio/RadioIcons.d.ts +1 -0
  48. package/dist/Select/ListBox.d.ts +1 -0
  49. package/dist/Select/ListBoxSection.d.ts +1 -0
  50. package/dist/Select/Option.d.ts +1 -0
  51. package/dist/Select/Select.d.ts +15 -1
  52. package/dist/Select/Select.stories.d.ts +5 -0
  53. package/dist/Slider/Slider.d.ts +5 -0
  54. package/dist/Slider/Slider.stories.d.ts +5 -0
  55. package/dist/Stack/Stack.stories.d.ts +5 -0
  56. package/dist/Text/Text.d.ts +5 -0
  57. package/dist/Text/Text.stories.d.ts +5 -0
  58. package/dist/Textarea/Textarea.d.ts +5 -0
  59. package/dist/Textarea/Textarea.stories.d.ts +5 -0
  60. package/dist/ValidationMessage/ValidationMessage.d.ts +5 -0
  61. package/dist/ValidationMessage/ValidationMessage.stories.d.ts +5 -0
  62. package/dist/VisuallyHidden/VisuallyHidden.d.ts +1 -0
  63. package/dist/VisuallyHidden/VisuallyHidden.stories.d.ts +5 -0
  64. package/dist/VisuallyHidden/index.d.ts +1 -0
  65. package/dist/components.cjs.development.js +480 -496
  66. package/dist/components.cjs.development.js.map +1 -1
  67. package/dist/components.cjs.production.min.js +1 -1
  68. package/dist/components.cjs.production.min.js.map +1 -1
  69. package/dist/components.esm.js +415 -441
  70. package/dist/components.esm.js.map +1 -1
  71. package/dist/index.d.ts +2 -2
  72. package/dist/theme.d.ts +23 -48
  73. package/package.json +4 -1
  74. package/src/ActionGroup/ActionGroup.stories.tsx +47 -0
  75. package/src/ActionGroup/ActionGroup.test.tsx +36 -36
  76. package/src/ActionGroup/ActionGroup.tsx +17 -28
  77. package/src/Alert/Alert.stories.tsx +32 -0
  78. package/src/Alert/Alert.test.tsx +4 -1
  79. package/src/Alert/Alert.tsx +18 -3
  80. package/src/Badge/Badge.stories.tsx +38 -0
  81. package/src/Badge/Badge.test.tsx +5 -1
  82. package/src/Badge/Badge.tsx +13 -1
  83. package/src/Box.ts +2 -0
  84. package/src/Button/{Button.stories.mdx → Button.stories.tsx} +10 -17
  85. package/src/Button/Button.test.tsx +34 -11
  86. package/src/Button/Button.tsx +17 -3
  87. package/src/Card/{Card.stories.mdx → Card.stories.tsx} +9 -17
  88. package/src/Card/Card.test.tsx +8 -3
  89. package/src/Card/Card.tsx +13 -1
  90. package/src/Checkbox/Checkbox.stories.mdx +11 -0
  91. package/src/Checkbox/Checkbox.stories.tsx +78 -0
  92. package/src/Checkbox/Checkbox.test.tsx +77 -8
  93. package/src/Checkbox/Checkbox.tsx +70 -90
  94. package/src/Checkbox/CheckboxIcons.tsx +51 -41
  95. package/src/Column/Column.stories.tsx +33 -0
  96. package/src/Columns/Columns.stories.tsx +75 -0
  97. package/src/Columns/Columns.test.tsx +34 -23
  98. package/src/Columns/Columns.tsx +30 -30
  99. package/src/Container/Container.stories.tsx +14 -0
  100. package/src/Dialog/{Dialog.stories.mdx → Dialog.stories.tsx} +33 -18
  101. package/src/Dialog/Dialog.test.tsx +91 -20
  102. package/src/Dialog/Dialog.tsx +63 -17
  103. package/src/Dialog/ModalDialog.tsx +33 -4
  104. package/src/Divider/{Divider.stories.mdx → Divider.stories.tsx} +10 -17
  105. package/src/Divider/Divider.test.tsx +13 -5
  106. package/src/Divider/Divider.tsx +12 -0
  107. package/src/Field/{Field.stories.mdx → Field.stories.tsx} +33 -20
  108. package/src/Field/Field.test.tsx +55 -5
  109. package/src/Field/Field.tsx +10 -8
  110. package/src/Image/Image.stories.tsx +34 -0
  111. package/src/Image/Image.test.tsx +4 -1
  112. package/src/Image/Image.tsx +13 -1
  113. package/src/Inline/Inline.stories.tsx +39 -0
  114. package/src/Inline/Inline.test.tsx +99 -0
  115. package/src/Inline/Inline.tsx +38 -0
  116. package/src/Inline/index.ts +1 -0
  117. package/src/Input/{Input.stories.mdx → Input.stories.tsx} +10 -17
  118. package/src/Input/Input.test.tsx +7 -3
  119. package/src/Input/Input.tsx +13 -1
  120. package/src/Label/{Label.stories.mdx → Label.stories.tsx} +10 -21
  121. package/src/Label/Label.test.tsx +25 -4
  122. package/src/Label/Label.tsx +42 -9
  123. package/src/Link/Link.stories.tsx +35 -0
  124. package/src/Link/Link.test.tsx +6 -2
  125. package/src/Link/Link.tsx +10 -0
  126. package/src/Menu/{Menu.stories.mdx → Menu.stories.tsx} +13 -32
  127. package/src/Menu/Menu.test.tsx +7 -2
  128. package/src/Menu/Menu.tsx +10 -0
  129. package/src/MenuItem/MenuItem.stories.tsx +30 -0
  130. package/src/MenuItem/MenuItem.test.tsx +7 -2
  131. package/src/MenuItem/MenuItem.tsx +12 -0
  132. package/src/Message/Message.stories.tsx +30 -0
  133. package/src/Message/Message.test.tsx +4 -1
  134. package/src/Message/Message.tsx +17 -5
  135. package/src/Provider/MarigoldProvider.test.tsx +65 -55
  136. package/src/Provider/MarigoldProvider.tsx +37 -19
  137. package/src/Provider/index.ts +2 -1
  138. package/src/Radio/Radio.stories.mdx +11 -0
  139. package/src/Radio/Radio.test.tsx +36 -2
  140. package/src/Radio/Radio.tsx +13 -2
  141. package/src/Radio/RadioIcons.tsx +1 -1
  142. package/src/Select/ListBox.tsx +1 -0
  143. package/src/Select/{Select.stories.mdx → Select.stories.tsx} +23 -20
  144. package/src/Select/Select.test.tsx +39 -1
  145. package/src/Select/Select.tsx +24 -13
  146. package/src/Slider/Slider.stories.tsx +24 -0
  147. package/src/Slider/Slider.test.tsx +10 -6
  148. package/src/Slider/Slider.tsx +25 -13
  149. package/src/Stack/Stack.stories.tsx +57 -0
  150. package/src/Stack/Stack.test.tsx +16 -7
  151. package/src/Text/{Text.stories.mdx → Text.stories.tsx} +20 -19
  152. package/src/Text/Text.test.tsx +2 -2
  153. package/src/Text/Text.tsx +12 -0
  154. package/src/Textarea/{Textarea.stories.mdx → Textarea.stories.tsx} +14 -24
  155. package/src/Textarea/Textarea.test.tsx +7 -3
  156. package/src/Textarea/Textarea.tsx +13 -1
  157. package/src/ValidationMessage/{ValidationMessage.stories.mdx → ValidationMessage.stories.tsx} +8 -17
  158. package/src/ValidationMessage/ValidationMessage.test.tsx +7 -2
  159. package/src/ValidationMessage/ValidationMessage.tsx +12 -0
  160. package/src/VisuallyHidden/VisuallyHidden.stories.tsx +19 -0
  161. package/src/VisuallyHidden/VisuallyHidden.test.tsx +10 -0
  162. package/src/VisuallyHidden/VisuallyHidden.tsx +1 -0
  163. package/src/VisuallyHidden/index.ts +1 -0
  164. package/src/index.ts +2 -2
  165. package/src/theme.ts +49 -48
  166. package/dist/Box/Box.d.ts +0 -47
  167. package/dist/Box/index.d.ts +0 -1
  168. package/dist/Heading/Heading.d.ts +0 -7
  169. package/dist/Heading/index.d.ts +0 -1
  170. package/dist/Hidden/Hidden.d.ts +0 -5
  171. package/dist/Hidden/index.d.ts +0 -1
  172. package/src/ActionGroup/ActionGroup.stories.mdx +0 -62
  173. package/src/Alert/Alert.stories.mdx +0 -35
  174. package/src/Badge/Badge.stories.mdx +0 -57
  175. package/src/Box/Box.stories.mdx +0 -334
  176. package/src/Box/Box.test.tsx +0 -133
  177. package/src/Box/Box.tsx +0 -165
  178. package/src/Box/index.ts +0 -1
  179. package/src/Column/Column.stories.mdx +0 -49
  180. package/src/Columns/Columns.stories.mdx +0 -65
  181. package/src/Container/Container.stories.mdx +0 -19
  182. package/src/Heading/Heading.stories.mdx +0 -39
  183. package/src/Heading/Heading.test.tsx +0 -77
  184. package/src/Heading/Heading.tsx +0 -19
  185. package/src/Heading/index.ts +0 -1
  186. package/src/Hidden/Hidden.stories.mdx +0 -39
  187. package/src/Hidden/Hidden.test.tsx +0 -24
  188. package/src/Hidden/Hidden.tsx +0 -16
  189. package/src/Hidden/index.ts +0 -1
  190. package/src/Image/Image.stories.mdx +0 -36
  191. package/src/Link/Link.stories.mdx +0 -45
  192. package/src/MenuItem/MenuItem.stories.mdx +0 -37
  193. package/src/Message/Message.stories.mdx +0 -44
  194. package/src/Slider/Slider.stories.mdx +0 -31
  195. package/src/Stack/Stack.stories.mdx +0 -51
@@ -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,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
- default: {
9
- m: '2px',
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 id="test" title="checkbox" onChange={() => {}} checked />
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).toBeDefined();
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).toBeDefined();
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 { CheckboxChecked, CheckboxUnchecked } from './CheckboxIcons';
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
- // Checkbox Icon
16
+ // Theme Extension
12
17
  // ---------------
13
- type CheckboxIconProps = {
14
- variant?: string;
15
- checked?: boolean;
16
- disabled?: boolean;
17
- children?: never;
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
- variant?: string;
50
- error?: boolean;
51
- } & ComponentProps<'input'>;
26
+ type CheckboxInputProps = CheckboxIconProps &
27
+ ToggleProps &
28
+ ComponentProps<'input'>;
52
29
 
53
- const CheckboxInput: React.FC<CheckboxInputProps> = ({
54
- className,
55
- variant = 'default',
56
- error,
57
- ...props
58
- }) => (
59
- <Box display="inline-block" className={className}>
60
- <Box
61
- as="input"
62
- type="checkbox"
63
- css={{
64
- position: 'absolute',
65
- opacity: 0,
66
- zIndex: -1,
67
- width: 1,
68
- height: 1,
69
- overflow: 'hidden',
70
- }}
71
- {...props}
72
- />
73
- <CheckboxIcon
74
- checked={props.checked}
75
- variant={variant}
76
- disabled={props.disabled}
77
- error={error}
78
- />
79
- </Box>
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?: string;
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
- if (label) {
100
- return (
101
- <>
102
- <Label
103
- htmlFor={props.id}
104
- required={required}
105
- variant={props.disabled ? 'disabled' : 'inline'}
106
- >
107
- <Box as={CheckboxInput} pr="8px" error={error} {...props} />
108
- {label}
109
- </Label>
110
- {error && errorMessage && (
111
- <ValidationMessage>
112
- <Exclamation size={16} />
113
- {errorMessage}
114
- </ValidationMessage>
115
- )}
116
- </>
117
- );
118
- }
119
-
120
- return <CheckboxInput {...props} />;
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/icons';
2
+ import { conditional, State, SVG } from '@marigold/system';
3
3
 
4
4
  import { Box } from '../Box';
5
5
 
6
- export const CheckboxChecked = ({ disabled = false, ...props }) => (
7
- <SVG width="16" height="32" viewBox="0 0 16 32" fill="none" {...props}>
8
- <Box
9
- as="rect"
10
- x="0.5"
11
- y="8.5"
12
- width="15px"
13
- height="15px"
14
- rx="1.5"
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 CheckboxUnchecked = ({
16
+ export const CheckboxIcon: React.FC<CheckboxIconProps> = ({
17
+ variant = '',
18
+ checked = false,
28
19
  disabled = false,
29
20
  error = false,
30
- ...props
31
- }) => (
32
- <SVG width="16" height="32" viewBox="0 0 16 32" fill="none" {...props}>
33
- <Box
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
- </SVG>
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
+ );
@@ -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
+ );