@marigold/components 0.3.3 → 0.5.1

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 (232) hide show
  1. package/CHANGELOG.md +49 -0
  2. package/dist/index.d.ts +362 -32
  3. package/dist/index.js +1422 -5
  4. package/dist/index.mjs +1374 -0
  5. package/package.json +30 -11
  6. package/dist/ActionGroup/ActionGroup.d.ts +0 -8
  7. package/dist/ActionGroup/ActionGroup.stories.d.ts +0 -5
  8. package/dist/ActionGroup/index.d.ts +0 -1
  9. package/dist/Alert/Alert.d.ts +0 -27
  10. package/dist/Alert/Alert.stories.d.ts +0 -5
  11. package/dist/Alert/index.d.ts +0 -1
  12. package/dist/Badge/Badge.d.ts +0 -13
  13. package/dist/Badge/Badge.stories.d.ts +0 -5
  14. package/dist/Badge/index.d.ts +0 -1
  15. package/dist/Box.d.ts +0 -2
  16. package/dist/Button/Button.d.ts +0 -9
  17. package/dist/Button/Button.stories.d.ts +0 -5
  18. package/dist/Button/index.d.ts +0 -1
  19. package/dist/Card/Card.d.ts +0 -14
  20. package/dist/Card/Card.stories.d.ts +0 -5
  21. package/dist/Card/index.d.ts +0 -1
  22. package/dist/Checkbox/Checkbox.d.ts +0 -20
  23. package/dist/Checkbox/Checkbox.stories.d.ts +0 -5
  24. package/dist/Checkbox/CheckboxIcons.d.ts +0 -9
  25. package/dist/Checkbox/index.d.ts +0 -1
  26. package/dist/Column/Column.d.ts +0 -8
  27. package/dist/Column/Column.stories.d.ts +0 -5
  28. package/dist/Column/index.d.ts +0 -1
  29. package/dist/Columns/Columns.d.ts +0 -10
  30. package/dist/Columns/Columns.stories.d.ts +0 -5
  31. package/dist/Columns/index.d.ts +0 -1
  32. package/dist/Container/Container.d.ts +0 -6
  33. package/dist/Container/Container.stories.d.ts +0 -5
  34. package/dist/Container/index.d.ts +0 -1
  35. package/dist/Dialog/Dialog.d.ts +0 -17
  36. package/dist/Dialog/Dialog.stories.d.ts +0 -5
  37. package/dist/Dialog/ModalDialog.d.ts +0 -8
  38. package/dist/Dialog/index.d.ts +0 -1
  39. package/dist/Divider/Divider.d.ts +0 -11
  40. package/dist/Divider/Divider.stories.d.ts +0 -5
  41. package/dist/Divider/index.d.ts +0 -1
  42. package/dist/Field/Field.d.ts +0 -13
  43. package/dist/Field/Field.stories.d.ts +0 -5
  44. package/dist/Field/index.d.ts +0 -1
  45. package/dist/Image/Image.d.ts +0 -12
  46. package/dist/Image/Image.stories.d.ts +0 -5
  47. package/dist/Image/index.d.ts +0 -1
  48. package/dist/Inline/Inline.d.ts +0 -7
  49. package/dist/Inline/Inline.stories.d.ts +0 -5
  50. package/dist/Inline/index.d.ts +0 -1
  51. package/dist/Input/Input.d.ts +0 -11
  52. package/dist/Input/Input.stories.d.ts +0 -5
  53. package/dist/Input/index.d.ts +0 -1
  54. package/dist/Label/Label.d.ts +0 -19
  55. package/dist/Label/Label.stories.d.ts +0 -5
  56. package/dist/Label/index.d.ts +0 -1
  57. package/dist/Link/Link.d.ts +0 -10
  58. package/dist/Link/Link.stories.d.ts +0 -5
  59. package/dist/Link/index.d.ts +0 -1
  60. package/dist/Menu/Menu.d.ts +0 -15
  61. package/dist/Menu/Menu.stories.d.ts +0 -5
  62. package/dist/Menu/index.d.ts +0 -1
  63. package/dist/MenuItem/MenuItem.d.ts +0 -12
  64. package/dist/MenuItem/MenuItem.stories.d.ts +0 -5
  65. package/dist/MenuItem/index.d.ts +0 -1
  66. package/dist/Message/Message.d.ts +0 -12
  67. package/dist/Message/Message.stories.d.ts +0 -5
  68. package/dist/Message/index.d.ts +0 -1
  69. package/dist/Provider/MarigoldProvider.d.ts +0 -11
  70. package/dist/Provider/index.d.ts +0 -3
  71. package/dist/Radio/Radio.d.ts +0 -19
  72. package/dist/Radio/Radio.stories.d.ts +0 -5
  73. package/dist/Radio/RadioIcon.d.ts +0 -9
  74. package/dist/Radio/index.d.ts +0 -1
  75. package/dist/Select/ListBox.d.ts +0 -9
  76. package/dist/Select/ListBoxSection.d.ts +0 -9
  77. package/dist/Select/Option.d.ts +0 -9
  78. package/dist/Select/Popover.d.ts +0 -9
  79. package/dist/Select/Select.d.ts +0 -27
  80. package/dist/Select/Select.stories.d.ts +0 -5
  81. package/dist/Select/index.d.ts +0 -1
  82. package/dist/Slider/Slider.d.ts +0 -11
  83. package/dist/Slider/Slider.stories.d.ts +0 -5
  84. package/dist/Slider/index.d.ts +0 -1
  85. package/dist/Stack/Stack.d.ts +0 -7
  86. package/dist/Stack/Stack.stories.d.ts +0 -5
  87. package/dist/Stack/index.d.ts +0 -1
  88. package/dist/Text/Text.d.ts +0 -17
  89. package/dist/Text/Text.stories.d.ts +0 -5
  90. package/dist/Text/index.d.ts +0 -1
  91. package/dist/Textarea/Textarea.d.ts +0 -16
  92. package/dist/Textarea/Textarea.stories.d.ts +0 -5
  93. package/dist/Textarea/index.d.ts +0 -1
  94. package/dist/ValidationMessage/ValidationMessage.d.ts +0 -11
  95. package/dist/ValidationMessage/ValidationMessage.stories.d.ts +0 -5
  96. package/dist/ValidationMessage/index.d.ts +0 -1
  97. package/dist/VisuallyHidden/VisuallyHidden.d.ts +0 -1
  98. package/dist/VisuallyHidden/VisuallyHidden.stories.d.ts +0 -5
  99. package/dist/VisuallyHidden/index.d.ts +0 -1
  100. package/dist/components.cjs.development.js +0 -1394
  101. package/dist/components.cjs.development.js.map +0 -1
  102. package/dist/components.cjs.production.min.js +0 -2
  103. package/dist/components.cjs.production.min.js.map +0 -1
  104. package/dist/components.esm.js +0 -1320
  105. package/dist/components.esm.js.map +0 -1
  106. package/dist/theme.d.ts +0 -23
  107. package/src/ActionGroup/ActionGroup.stories.tsx +0 -47
  108. package/src/ActionGroup/ActionGroup.test.tsx +0 -83
  109. package/src/ActionGroup/ActionGroup.tsx +0 -32
  110. package/src/ActionGroup/index.ts +0 -1
  111. package/src/Alert/Alert.stories.tsx +0 -32
  112. package/src/Alert/Alert.test.tsx +0 -82
  113. package/src/Alert/Alert.tsx +0 -52
  114. package/src/Alert/index.ts +0 -1
  115. package/src/Badge/Badge.stories.tsx +0 -38
  116. package/src/Badge/Badge.test.tsx +0 -65
  117. package/src/Badge/Badge.tsx +0 -37
  118. package/src/Badge/index.ts +0 -1
  119. package/src/Box.ts +0 -2
  120. package/src/Button/Button.stories.tsx +0 -57
  121. package/src/Button/Button.test.tsx +0 -149
  122. package/src/Button/Button.tsx +0 -64
  123. package/src/Button/index.ts +0 -1
  124. package/src/Card/Card.stories.tsx +0 -41
  125. package/src/Card/Card.test.tsx +0 -71
  126. package/src/Card/Card.tsx +0 -48
  127. package/src/Card/index.ts +0 -1
  128. package/src/Checkbox/Checkbox.stories.tsx +0 -78
  129. package/src/Checkbox/Checkbox.test.tsx +0 -166
  130. package/src/Checkbox/Checkbox.tsx +0 -101
  131. package/src/Checkbox/CheckboxIcons.tsx +0 -59
  132. package/src/Checkbox/index.ts +0 -1
  133. package/src/Column/Column.stories.tsx +0 -33
  134. package/src/Column/Column.test.tsx +0 -32
  135. package/src/Column/Column.tsx +0 -27
  136. package/src/Column/index.ts +0 -1
  137. package/src/Columns/Columns.stories.tsx +0 -75
  138. package/src/Columns/Columns.test.tsx +0 -113
  139. package/src/Columns/Columns.tsx +0 -69
  140. package/src/Columns/index.ts +0 -1
  141. package/src/Container/Container.stories.tsx +0 -14
  142. package/src/Container/Container.test.tsx +0 -26
  143. package/src/Container/Container.tsx +0 -13
  144. package/src/Container/index.ts +0 -1
  145. package/src/Dialog/Dialog.stories.tsx +0 -88
  146. package/src/Dialog/Dialog.test.tsx +0 -158
  147. package/src/Dialog/Dialog.tsx +0 -130
  148. package/src/Dialog/ModalDialog.tsx +0 -76
  149. package/src/Dialog/index.ts +0 -1
  150. package/src/Divider/Divider.stories.tsx +0 -30
  151. package/src/Divider/Divider.test.tsx +0 -72
  152. package/src/Divider/Divider.tsx +0 -33
  153. package/src/Divider/index.ts +0 -1
  154. package/src/Field/Field.stories.tsx +0 -110
  155. package/src/Field/Field.test.tsx +0 -130
  156. package/src/Field/Field.tsx +0 -56
  157. package/src/Field/index.ts +0 -1
  158. package/src/Image/Image.stories.tsx +0 -34
  159. package/src/Image/Image.test.tsx +0 -73
  160. package/src/Image/Image.tsx +0 -25
  161. package/src/Image/index.ts +0 -1
  162. package/src/Inline/Inline.stories.tsx +0 -39
  163. package/src/Inline/Inline.test.tsx +0 -99
  164. package/src/Inline/Inline.tsx +0 -38
  165. package/src/Inline/index.ts +0 -1
  166. package/src/Input/Input.stories.tsx +0 -54
  167. package/src/Input/Input.test.tsx +0 -74
  168. package/src/Input/Input.tsx +0 -25
  169. package/src/Input/index.ts +0 -1
  170. package/src/Label/Label.stories.tsx +0 -41
  171. package/src/Label/Label.test.tsx +0 -109
  172. package/src/Label/Label.tsx +0 -64
  173. package/src/Label/index.ts +0 -1
  174. package/src/Link/Link.stories.tsx +0 -35
  175. package/src/Link/Link.test.tsx +0 -97
  176. package/src/Link/Link.tsx +0 -43
  177. package/src/Link/index.ts +0 -1
  178. package/src/Menu/Menu.stories.tsx +0 -62
  179. package/src/Menu/Menu.test.tsx +0 -84
  180. package/src/Menu/Menu.tsx +0 -51
  181. package/src/Menu/index.ts +0 -1
  182. package/src/MenuItem/MenuItem.stories.tsx +0 -30
  183. package/src/MenuItem/MenuItem.test.tsx +0 -68
  184. package/src/MenuItem/MenuItem.tsx +0 -35
  185. package/src/MenuItem/index.ts +0 -1
  186. package/src/Message/Message.stories.tsx +0 -30
  187. package/src/Message/Message.test.tsx +0 -90
  188. package/src/Message/Message.tsx +0 -55
  189. package/src/Message/index.ts +0 -1
  190. package/src/Provider/MarigoldProvider.test.tsx +0 -136
  191. package/src/Provider/MarigoldProvider.tsx +0 -47
  192. package/src/Provider/index.ts +0 -4
  193. package/src/Radio/Radio.stories.tsx +0 -78
  194. package/src/Radio/Radio.test.tsx +0 -154
  195. package/src/Radio/Radio.tsx +0 -88
  196. package/src/Radio/RadioIcon.tsx +0 -49
  197. package/src/Radio/index.ts +0 -1
  198. package/src/Select/ListBox.tsx +0 -40
  199. package/src/Select/ListBoxSection.tsx +0 -40
  200. package/src/Select/Option.tsx +0 -48
  201. package/src/Select/Popover.tsx +0 -50
  202. package/src/Select/Select.stories.tsx +0 -81
  203. package/src/Select/Select.test.tsx +0 -349
  204. package/src/Select/Select.tsx +0 -174
  205. package/src/Select/index.ts +0 -1
  206. package/src/Slider/Slider.stories.tsx +0 -24
  207. package/src/Slider/Slider.test.tsx +0 -63
  208. package/src/Slider/Slider.tsx +0 -35
  209. package/src/Slider/index.ts +0 -1
  210. package/src/Stack/Stack.stories.tsx +0 -57
  211. package/src/Stack/Stack.test.tsx +0 -138
  212. package/src/Stack/Stack.tsx +0 -39
  213. package/src/Stack/index.ts +0 -1
  214. package/src/Text/Text.stories.tsx +0 -61
  215. package/src/Text/Text.test.tsx +0 -99
  216. package/src/Text/Text.tsx +0 -60
  217. package/src/Text/index.ts +0 -1
  218. package/src/Textarea/Textarea.stories.tsx +0 -64
  219. package/src/Textarea/Textarea.test.tsx +0 -95
  220. package/src/Textarea/Textarea.tsx +0 -62
  221. package/src/Textarea/index.ts +0 -1
  222. package/src/ValidationMessage/ValidationMessage.stories.tsx +0 -27
  223. package/src/ValidationMessage/ValidationMessage.test.tsx +0 -68
  224. package/src/ValidationMessage/ValidationMessage.tsx +0 -40
  225. package/src/ValidationMessage/index.ts +0 -1
  226. package/src/VisuallyHidden/VisuallyHidden.stories.tsx +0 -19
  227. package/src/VisuallyHidden/VisuallyHidden.test.tsx +0 -10
  228. package/src/VisuallyHidden/VisuallyHidden.tsx +0 -1
  229. package/src/VisuallyHidden/index.ts +0 -1
  230. package/src/index.ts +0 -34
  231. package/src/theme.ts +0 -50
  232. package/tsconfig.build.json +0 -3
@@ -1,166 +0,0 @@
1
- import React from 'react';
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
- });
50
-
51
- test('supports label prop', () => {
52
- render(<Checkbox label="Test" id="test" title="checkbox" />);
53
-
54
- const checkboxLabel = screen.getByText(/Test/);
55
- expect(checkboxLabel).toBeDefined();
56
- });
57
-
58
- test('supports required prop and renders required icon', () => {
59
- render(<Checkbox label="Test" id="test" required title="checkbox" />);
60
-
61
- const label = screen.getByText(/Test/);
62
- expect(label.nextSibling).toContainHTML('path d="M10.8');
63
- });
64
-
65
- test('supports default type', () => {
66
- render(<Checkbox id="checkbox" title="checkbox" label="Test" />);
67
-
68
- const checkbox = screen.getByTitle(/checkbox/);
69
- expect(checkbox.getAttribute('type')).toEqual('checkbox');
70
- });
71
-
72
- test('renders <input> element', () => {
73
- render(<Checkbox id="checkbox" title="checkbox" label="Test" />);
74
-
75
- const checkbox = screen.getByTitle(/checkbox/);
76
- expect(checkbox instanceof HTMLInputElement).toBeTruthy();
77
- });
78
-
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();
107
- });
108
-
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');
124
- });
125
-
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/);
162
- fireEvent.click(checkbox);
163
-
164
- expect(click).toHaveBeenCalledTimes(1);
165
- expect(change).toHaveBeenCalledTimes(1);
166
- });
@@ -1,101 +0,0 @@
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
-
8
- import { ComponentProps } from '@marigold/types';
9
- import { Exclamation } from '@marigold/icons';
10
-
11
- import { CheckboxIcon, CheckboxIconProps } from './CheckboxIcons';
12
- import { Box } from '../Box';
13
- import { Label } from '../Label';
14
- import { ValidationMessage } from '../ValidationMessage';
15
-
16
- // Theme Extension
17
- // ---------------
18
- export interface CheckboxThemeExtension<Value> {
19
- checkbox?: {
20
- [key: string]: Value;
21
- };
22
- }
23
-
24
- // Checkbox Input
25
- // ---------------
26
- type CheckboxInputProps = CheckboxIconProps &
27
- ToggleProps &
28
- ComponentProps<'input'>;
29
-
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
- };
58
-
59
- // Checkbox
60
- // ---------------
61
- export type CheckboxProps = {
62
- id: string;
63
- label: string;
64
- required?: boolean;
65
- labelVariant?: string;
66
- error?: boolean;
67
- errorMessage?: string;
68
- } & CheckboxInputProps;
69
-
70
- export const Checkbox: React.FC<CheckboxProps> = ({
71
- label,
72
- required,
73
- labelVariant = 'inline',
74
- error,
75
- errorMessage,
76
- ...props
77
- }) => {
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
- );
101
- };
@@ -1,59 +0,0 @@
1
- import React from 'react';
2
- import { conditional, State, SVG } from '@marigold/system';
3
-
4
- import { Box } from '../Box';
5
-
6
- // Checkbox Icon
7
- // ---------------
8
- export type CheckboxIconProps = {
9
- variant?: string;
10
- checked?: boolean;
11
- disabled?: boolean;
12
- error?: boolean;
13
- children?: never;
14
- };
15
-
16
- export const CheckboxIcon: React.FC<CheckboxIconProps> = ({
17
- variant = '',
18
- checked = false,
19
- disabled = false,
20
- error = false,
21
- }) => {
22
- const conditionalStates: State = disabled
23
- ? {
24
- disabled: disabled,
25
- }
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
- };
@@ -1 +0,0 @@
1
- export * from './Checkbox';
@@ -1,33 +0,0 @@
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
- );
@@ -1,32 +0,0 @@
1
- import React from 'react';
2
- import { render, screen } from '@testing-library/react';
3
- import { Column } from './Column';
4
-
5
- test('supports width prop', () => {
6
- render(<Column width={6}>column</Column>);
7
- const column = screen.getByText('column');
8
-
9
- expect(column).toHaveStyle(`width: 50%`);
10
- });
11
-
12
- test('renders correct HTML element', () => {
13
- render(<Column>column</Column>);
14
- const column = screen.getByText('column');
15
-
16
- expect(column instanceof HTMLDivElement).toBeTruthy();
17
- });
18
-
19
- test('accepts custom styles prop className', () => {
20
- render(<Column className="custom-class-name">column</Column>);
21
- const column = screen.getByText('column');
22
-
23
- expect(column.className).toMatch('custom-class-name');
24
- });
25
-
26
- test('accepts responsive values', () => {
27
- render(<Column width={[12, 6]}>column</Column>);
28
- const column = screen.getByText('column');
29
-
30
- // Note: as of November 2021 jest-dom does not support media queries...
31
- expect(column).toHaveStyle('width: 100%');
32
- });
@@ -1,27 +0,0 @@
1
- import React from 'react';
2
- import { Box } from '../Box';
3
-
4
- type WidthValues = 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12;
5
-
6
- export type ColumnProps = {
7
- className?: string;
8
- width?: WidthValues | WidthValues[];
9
- };
10
-
11
- const transform = (width: WidthValues | WidthValues[]) => {
12
- if (Array.isArray(width)) {
13
- return width.map(v => `${(v / 12) * 100}%`);
14
- }
15
-
16
- return `${(width / 12) * 100}%`;
17
- };
18
-
19
- export const Column: React.FC<ColumnProps> = ({
20
- width = 12,
21
- children,
22
- ...props
23
- }) => (
24
- <Box {...props} width={transform(width)}>
25
- {children}
26
- </Box>
27
- );
@@ -1 +0,0 @@
1
- export * from './Column';
@@ -1,75 +0,0 @@
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
- );
@@ -1,113 +0,0 @@
1
- import React from 'react';
2
- import { render, screen } from '@testing-library/react';
3
- import { Column, Columns, MarigoldProvider } from '@marigold/components';
4
-
5
- const theme = {
6
- space: {
7
- none: 0,
8
- large: 24,
9
- },
10
- };
11
-
12
- test('supports default space prop', () => {
13
- render(
14
- <MarigoldProvider theme={theme}>
15
- <Columns data-testid="column">
16
- <Column>column</Column>
17
- </Columns>
18
- </MarigoldProvider>
19
- );
20
- const column = screen.getByTestId(/column/);
21
-
22
- expect(column).toHaveStyle(`margin: 0px`);
23
- });
24
-
25
- test('supports custom space prop', () => {
26
- render(
27
- <MarigoldProvider theme={theme}>
28
- <Columns space="large" data-testid="column">
29
- <Column>column</Column>
30
- </Columns>
31
- </MarigoldProvider>
32
- );
33
- const column = screen.getByTestId(/column/);
34
-
35
- expect(column).toHaveStyle(`margin: -12px`);
36
- });
37
-
38
- test('supports default horizontalAlign prop: left', () => {
39
- render(
40
- <Columns data-testid="column">
41
- <Column>column</Column>
42
- </Columns>
43
- );
44
- const column = screen.getByTestId(/column/);
45
-
46
- expect(column).toHaveStyle(`justify-content: flex-start`);
47
- });
48
-
49
- test('supports custom horizontalAlign prop: center', () => {
50
- render(
51
- <Columns horizontalAlign="center" data-testid="column">
52
- <Column>column</Column>
53
- </Columns>
54
- );
55
- const column = screen.getByTestId(/column/);
56
-
57
- expect(column).toHaveStyle(`justify-content: center`);
58
- });
59
-
60
- test('supports custom horizontalAlign prop: right', () => {
61
- render(
62
- <Columns horizontalAlign="right" data-testid="column">
63
- <Column>column</Column>
64
- </Columns>
65
- );
66
- const column = screen.getByTestId(/column/);
67
-
68
- expect(column).toHaveStyle(`justify-content: flex-end`);
69
- });
70
-
71
- test('supports default verticalAlign prop: top', () => {
72
- render(
73
- <Columns data-testid="column">
74
- <Column>column</Column>
75
- </Columns>
76
- );
77
- const column = screen.getByTestId(/column/);
78
-
79
- expect(column).toHaveStyle(`align-items: flex-start`);
80
- });
81
-
82
- test('supports custom verticalAlign prop: center', () => {
83
- render(
84
- <Columns verticalAlign="center" data-testid="column">
85
- <Column>column</Column>
86
- </Columns>
87
- );
88
- const column = screen.getByTestId(/column/);
89
-
90
- expect(column).toHaveStyle(`align-items: center`);
91
- });
92
-
93
- test('supports custom verticalAlign prop: bottom', () => {
94
- render(
95
- <Columns verticalAlign="bottom" data-testid="column">
96
- <Column>column</Column>
97
- </Columns>
98
- );
99
- const column = screen.getByTestId(/column/);
100
-
101
- expect(column).toHaveStyle(`align-items: flex-end`);
102
- });
103
-
104
- test('renders correct HTML element', () => {
105
- render(
106
- <Columns data-testid="column">
107
- <Column>column</Column>
108
- </Columns>
109
- );
110
- const column = screen.getByTestId(/column/);
111
-
112
- expect(column instanceof HTMLDivElement).toBeTruthy();
113
- });
@@ -1,69 +0,0 @@
1
- import React, { Children } from 'react';
2
- import { Box } from '../Box';
3
- import flattenChildren from 'react-keyed-flatten-children';
4
- import { ResponsiveStyleValue, useTheme } from '@marigold/system';
5
-
6
- type ColumnsProps = {
7
- className?: string;
8
- space?: ResponsiveStyleValue<string>;
9
- horizontalAlign?: 'left' | 'right' | 'center';
10
- verticalAlign?: 'top' | 'bottom' | 'center';
11
- };
12
-
13
- const useAlignment = (direction: string) => {
14
- switch (direction) {
15
- case 'right':
16
- return 'flex-end';
17
- case 'bottom':
18
- return 'flex-end';
19
- case 'center':
20
- return 'center';
21
- }
22
- return 'flex-start';
23
- };
24
-
25
- export const Columns: React.FC<ColumnsProps> = ({
26
- space = 'none',
27
- horizontalAlign = 'left',
28
- verticalAlign = 'top',
29
- className,
30
- children,
31
- ...props
32
- }) => {
33
- const justifyContent = useAlignment(horizontalAlign);
34
- const alignItems = useAlignment(verticalAlign);
35
-
36
- /**
37
- * transform space string to space value from theme
38
- */
39
- const { css } = useTheme();
40
- const spaceObject = css({ space }) as Object;
41
- const spaceValue = Object.values(spaceObject)[0];
42
-
43
- return (
44
- <Box p={space} display="flex" className={className}>
45
- <Box
46
- width={`calc(100% + ${spaceValue}px)`}
47
- m={`${-spaceValue / 2}px`}
48
- display="flex"
49
- flexWrap="wrap"
50
- alignItems={alignItems}
51
- justifyContent={justifyContent}
52
- {...props}
53
- >
54
- {Children.map(
55
- flattenChildren(children) as unknown as React.ReactElement,
56
- (child: React.ReactElement) => {
57
- return React.cloneElement(
58
- child,
59
- {},
60
- <Box css={{ p: `${spaceValue / 2}px` }}>
61
- {child.props.children}
62
- </Box>
63
- );
64
- }
65
- )}
66
- </Box>
67
- </Box>
68
- );
69
- };
@@ -1 +0,0 @@
1
- export * from './Columns';
@@ -1,14 +0,0 @@
1
- import React from 'react';
2
- import type { Meta, ComponentStory } from '@storybook/react';
3
- import { Container } from './Container';
4
- import { Text } from '../Text';
5
-
6
- export default {
7
- title: 'Components/Container',
8
- } as Meta;
9
-
10
- export const Basic: ComponentStory<typeof Container> = args => (
11
- <Container {...args}>
12
- <Text>Container with width=100%</Text>
13
- </Container>
14
- );