@marigold/components 0.3.0 → 0.4.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 (232) hide show
  1. package/CHANGELOG.md +66 -161
  2. package/dist/index.d.ts +364 -32
  3. package/dist/index.js +1421 -5
  4. package/dist/index.mjs +1369 -0
  5. package/package.json +31 -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 -18
  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 -12
  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 -21
  72. package/dist/Radio/RadioIcons.d.ts +0 -10
  73. package/dist/Radio/index.d.ts +0 -1
  74. package/dist/Select/ListBox.d.ts +0 -9
  75. package/dist/Select/ListBoxSection.d.ts +0 -9
  76. package/dist/Select/Option.d.ts +0 -9
  77. package/dist/Select/Popover.d.ts +0 -9
  78. package/dist/Select/Select.d.ts +0 -27
  79. package/dist/Select/Select.stories.d.ts +0 -5
  80. package/dist/Select/index.d.ts +0 -1
  81. package/dist/Slider/Slider.d.ts +0 -11
  82. package/dist/Slider/Slider.stories.d.ts +0 -5
  83. package/dist/Slider/index.d.ts +0 -1
  84. package/dist/Stack/Stack.d.ts +0 -7
  85. package/dist/Stack/Stack.stories.d.ts +0 -5
  86. package/dist/Stack/index.d.ts +0 -1
  87. package/dist/Text/Text.d.ts +0 -17
  88. package/dist/Text/Text.stories.d.ts +0 -5
  89. package/dist/Text/index.d.ts +0 -1
  90. package/dist/Textarea/Textarea.d.ts +0 -16
  91. package/dist/Textarea/Textarea.stories.d.ts +0 -5
  92. package/dist/Textarea/index.d.ts +0 -1
  93. package/dist/ValidationMessage/ValidationMessage.d.ts +0 -11
  94. package/dist/ValidationMessage/ValidationMessage.stories.d.ts +0 -5
  95. package/dist/ValidationMessage/index.d.ts +0 -1
  96. package/dist/VisuallyHidden/VisuallyHidden.d.ts +0 -1
  97. package/dist/VisuallyHidden/VisuallyHidden.stories.d.ts +0 -5
  98. package/dist/VisuallyHidden/index.d.ts +0 -1
  99. package/dist/components.cjs.development.js +0 -1422
  100. package/dist/components.cjs.development.js.map +0 -1
  101. package/dist/components.cjs.production.min.js +0 -2
  102. package/dist/components.cjs.production.min.js.map +0 -1
  103. package/dist/components.esm.js +0 -1348
  104. package/dist/components.esm.js.map +0 -1
  105. package/dist/theme.d.ts +0 -23
  106. package/src/ActionGroup/ActionGroup.stories.tsx +0 -47
  107. package/src/ActionGroup/ActionGroup.test.tsx +0 -83
  108. package/src/ActionGroup/ActionGroup.tsx +0 -32
  109. package/src/ActionGroup/index.ts +0 -1
  110. package/src/Alert/Alert.stories.tsx +0 -32
  111. package/src/Alert/Alert.test.tsx +0 -82
  112. package/src/Alert/Alert.tsx +0 -52
  113. package/src/Alert/index.ts +0 -1
  114. package/src/Badge/Badge.stories.tsx +0 -38
  115. package/src/Badge/Badge.test.tsx +0 -65
  116. package/src/Badge/Badge.tsx +0 -37
  117. package/src/Badge/index.ts +0 -1
  118. package/src/Box.ts +0 -2
  119. package/src/Button/Button.stories.tsx +0 -57
  120. package/src/Button/Button.test.tsx +0 -149
  121. package/src/Button/Button.tsx +0 -64
  122. package/src/Button/index.ts +0 -1
  123. package/src/Card/Card.stories.tsx +0 -41
  124. package/src/Card/Card.test.tsx +0 -71
  125. package/src/Card/Card.tsx +0 -48
  126. package/src/Card/index.ts +0 -1
  127. package/src/Checkbox/Checkbox.stories.mdx +0 -97
  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 -71
  152. package/src/Divider/Divider.tsx +0 -25
  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 -42
  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.mdx +0 -97
  194. package/src/Radio/Radio.test.tsx +0 -119
  195. package/src/Radio/Radio.tsx +0 -128
  196. package/src/Radio/RadioIcons.tsx +0 -39
  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,119 +0,0 @@
1
- import React from 'react';
2
- import { render, screen } from '@testing-library/react';
3
- import { Radio } from './Radio';
4
- import { ThemeProvider } from '@marigold/system';
5
-
6
- const theme = {
7
- space: {
8
- none: 0,
9
- small: 2,
10
- },
11
- radio: {
12
- __default: {
13
- m: 'small',
14
- },
15
- },
16
- label: {
17
- above: {
18
- fontSize: '8px',
19
- },
20
- inline: {
21
- fontSize: '14px',
22
- },
23
- },
24
- };
25
-
26
- test('supports default labelVariant', () => {
27
- render(
28
- <ThemeProvider theme={theme}>
29
- <Radio id="test" title="checkbox" label="label" />
30
- </ThemeProvider>
31
- );
32
-
33
- const label = screen.getByText(/label/);
34
- expect(label).toHaveStyle(`font-size: 14px`);
35
- });
36
-
37
- test('supports other labelVariant than default', () => {
38
- render(
39
- <ThemeProvider theme={theme}>
40
- <Radio id="test" title="checkbox" label="label" labelVariant="above" />
41
- </ThemeProvider>
42
- );
43
-
44
- const label = screen.getByText(/label/);
45
- expect(label).toHaveStyle(`font-size: 8px`);
46
- });
47
-
48
- test('supports label prop', () => {
49
- render(<Radio label="Test" id="test" title="radio" />);
50
-
51
- const radioLabel = screen.getByText(/Test/);
52
- expect(radioLabel).toBeDefined();
53
- });
54
-
55
- test('supports required prop and renders required icon', () => {
56
- render(<Radio label="Test" id="test" required title="radio" />);
57
-
58
- const label = screen.getByText(/Test/);
59
- expect(label.nextSibling).toContainHTML('path d="M10.8');
60
- });
61
-
62
- test('supports default type', () => {
63
- render(<Radio id="radio" title="radio" />);
64
-
65
- const radio = screen.getByTitle(/radio/);
66
- expect(radio.getAttribute('type')).toEqual('radio');
67
- });
68
-
69
- test('renders <input> element', () => {
70
- render(<Radio id="radio" title="radio" />);
71
-
72
- const radio = screen.getByTitle(/radio/);
73
- expect(radio instanceof HTMLInputElement).toBeTruthy();
74
- });
75
-
76
- test('supports disabled prop', () => {
77
- render(
78
- <ThemeProvider theme={theme}>
79
- <Radio id="test" title="radio" label="label" disabled />
80
- </ThemeProvider>
81
- );
82
-
83
- const radio = screen.getByTitle(/radio/);
84
- expect(radio).toHaveAttribute('disabled');
85
- });
86
-
87
- test('supports error and errorMessage prop', () => {
88
- render(
89
- <ThemeProvider theme={theme}>
90
- <Radio id="test" title="radio" label="test" error errorMessage="error" />
91
- </ThemeProvider>
92
- );
93
-
94
- const errorMessage = screen.getByText(/error/);
95
- expect(errorMessage).toBeDefined();
96
- });
97
-
98
- test('supports checked radio', () => {
99
- render(
100
- <ThemeProvider theme={theme}>
101
- <Radio id="test" title="radio" onChange={() => {}} checked />
102
- </ThemeProvider>
103
- );
104
-
105
- const radio = screen.getByTitle(/radio/);
106
- expect(radio).toBeDefined();
107
- });
108
-
109
- test('supports checked and disabled radio', () => {
110
- render(
111
- <ThemeProvider theme={theme}>
112
- <Radio id="test" title="radio" onChange={() => {}} checked disabled />
113
- </ThemeProvider>
114
- );
115
-
116
- const radio = screen.getByTitle(/radio/);
117
- expect(radio).toBeDefined();
118
- expect(radio).toHaveAttribute('disabled');
119
- });
@@ -1,128 +0,0 @@
1
- import React from 'react';
2
- import { ComponentProps } from '@marigold/types';
3
- import { Exclamation } from '@marigold/icons';
4
-
5
- import { Box } from '../Box';
6
- import { Label } from '../Label';
7
- import { ValidationMessage } from '../ValidationMessage';
8
-
9
- import { RadioChecked, RadioUnchecked } from './RadioIcons';
10
-
11
- // Theme Extension
12
- // ---------------
13
- export interface RadioThemeExtension<Value> {
14
- radio?: {
15
- [key: string]: Value;
16
- };
17
- }
18
-
19
- // Radio Icon
20
- // ---------------
21
- type RadioIconProps = {
22
- variant?: string;
23
- checked?: boolean;
24
- disabled?: boolean;
25
- error?: boolean;
26
- children?: never;
27
- };
28
-
29
- const RadioIcon: React.FC<RadioIconProps> = ({
30
- variant,
31
- checked,
32
- disabled,
33
- error,
34
- }) => {
35
- if (checked) {
36
- return (
37
- <Box as={RadioChecked} variant={`radio.${variant}`} disabled={disabled} />
38
- );
39
- }
40
- return (
41
- <Box
42
- as={RadioUnchecked}
43
- variant={`radio.${variant}`}
44
- disabled={disabled}
45
- error={error}
46
- />
47
- );
48
- };
49
-
50
- // Radio Input
51
- // ---------------
52
- type RadioInputProps = {
53
- variant?: string;
54
- error?: boolean;
55
- } & ComponentProps<'input'>;
56
-
57
- const RadioInput: React.FC<RadioInputProps> = ({
58
- className,
59
- variant = '',
60
- error,
61
- ...props
62
- }) => (
63
- <Box display="inline-block" className={className}>
64
- <Box
65
- as="input"
66
- type="radio"
67
- css={{
68
- position: 'absolute',
69
- opacity: 0,
70
- zIndex: -1,
71
- width: 1,
72
- height: 1,
73
- overflow: 'hidden',
74
- }}
75
- {...props}
76
- />
77
- <RadioIcon
78
- checked={props.checked}
79
- variant={variant}
80
- disabled={props.disabled}
81
- error={error}
82
- />
83
- </Box>
84
- );
85
-
86
- // Radio
87
- // ---------------
88
- export type RadioProps = {
89
- id: string;
90
- label?: string;
91
- required?: boolean;
92
- labelVariant?: string;
93
- error?: boolean;
94
- errorMessage?: string;
95
- } & RadioInputProps;
96
-
97
- export const Radio: React.FC<RadioProps> = ({
98
- label,
99
- required,
100
- labelVariant = 'inline',
101
- error,
102
- errorMessage,
103
- ...props
104
- }) => {
105
- if (label) {
106
- return (
107
- <>
108
- <Label
109
- htmlFor={props.id}
110
- required={required}
111
- variant={labelVariant}
112
- color={props.disabled ? 'disabled' : 'text'}
113
- >
114
- <Box as={RadioInput} pr="8px" error={error} {...props} />
115
- {label}
116
- </Label>
117
- {error && errorMessage && (
118
- <ValidationMessage>
119
- <Exclamation size={16} />
120
- {errorMessage}
121
- </ValidationMessage>
122
- )}
123
- </>
124
- );
125
- }
126
-
127
- return <RadioInput {...props} />;
128
- };
@@ -1,39 +0,0 @@
1
- import React from 'react';
2
- import { SVG } from '@marigold/system';
3
-
4
- import { Box } from '../Box';
5
-
6
- export const RadioChecked = ({ disabled = false, ...props }) => (
7
- <SVG width="16" height="32" viewBox="0 0 16 32" fill="none" {...props}>
8
- <Box
9
- as="circle"
10
- cx="8"
11
- cy="16"
12
- r="7.5"
13
- variant={disabled ? 'radio.checked.disabled' : 'radio.checked'}
14
- />
15
- <Box as="circle" cx="8" cy="16" r="3" variant="radio.checked.circle" />
16
- </SVG>
17
- );
18
-
19
- export const RadioUnchecked = ({
20
- disabled = false,
21
- error = false,
22
- ...props
23
- }) => (
24
- <SVG width="16" height="32" viewBox="0 0 16 32" fill="none" {...props}>
25
- <Box
26
- as="circle"
27
- cx="8"
28
- cy="16"
29
- r="7.5"
30
- variant={
31
- disabled
32
- ? 'radio.unchecked.disabled'
33
- : error
34
- ? 'radio.unchecked.error'
35
- : 'radio.unchecked'
36
- }
37
- />
38
- </SVG>
39
- );
@@ -1 +0,0 @@
1
- export * from './Radio';
@@ -1,40 +0,0 @@
1
- import React, { useRef } from 'react';
2
- import { useListBox } from '@react-aria/listbox';
3
- import type { AriaListBoxOptions } from '@react-aria/listbox';
4
- import type { ListState } from '@react-stately/list';
5
-
6
- import { Box } from '../Box';
7
- import { Option } from './Option';
8
- import { ListBoxSection } from './ListBoxSection';
9
-
10
- interface ListBoxProps extends AriaListBoxOptions<unknown> {
11
- state: ListState<unknown>;
12
- error?: boolean;
13
- }
14
-
15
- export const ListBox = (props: ListBoxProps) => {
16
- const ref = useRef<HTMLUListElement>(null);
17
- const { state, error } = props;
18
- const { listBoxProps } = useListBox(props, state, ref);
19
-
20
- return (
21
- <Box
22
- as="ul"
23
- p="none"
24
- css={{
25
- listStyle: 'none',
26
- }}
27
- {...listBoxProps}
28
- variant={error ? 'select.listbox.error' : 'select.listbox'}
29
- ref={ref}
30
- >
31
- {[...state.collection].map(item =>
32
- item.type === 'section' ? (
33
- <ListBoxSection key={item.key} section={item} state={state} />
34
- ) : (
35
- <Option key={item.key} item={item} state={state} />
36
- )
37
- )}
38
- </Box>
39
- );
40
- };
@@ -1,40 +0,0 @@
1
- import React from 'react';
2
- import { useListBoxSection } from '@react-aria/listbox';
3
- import type { ListState } from '@react-stately/list';
4
- import type { Node } from '@react-types/shared';
5
-
6
- import { Box } from '../Box';
7
- import { Option } from './Option';
8
-
9
- interface SectionProps {
10
- section: Node<unknown>;
11
- state: ListState<unknown>;
12
- }
13
-
14
- export const ListBoxSection = ({ section, state }: SectionProps) => {
15
- const { itemProps, headingProps, groupProps } = useListBoxSection({
16
- heading: section.rendered,
17
- 'aria-label': section['aria-label'],
18
- });
19
-
20
- return (
21
- <Box
22
- as="li"
23
- {...itemProps}
24
- css={{
25
- cursor: 'not-allowed',
26
- }}
27
- >
28
- {section.rendered && (
29
- <Box as="span" {...headingProps} variant={'select.section'}>
30
- {section.rendered}
31
- </Box>
32
- )}
33
- <Box as="ul" {...groupProps}>
34
- {[...section.childNodes].map(node => (
35
- <Option key={node.key} item={node} state={state} />
36
- ))}
37
- </Box>
38
- </Box>
39
- );
40
- };
@@ -1,48 +0,0 @@
1
- import React, { useEffect, useRef, useState } from 'react';
2
- import type { ListState } from '@react-stately/list';
3
- import type { Node } from '@react-types/shared';
4
- import { useOption } from '@react-aria/listbox';
5
-
6
- import { Box } from '../Box';
7
-
8
- interface OptionProps {
9
- item: Node<unknown>;
10
- state: ListState<unknown>;
11
- }
12
-
13
- export const Option = ({ item, state }: OptionProps) => {
14
- const ref = useRef<HTMLLIElement>(null);
15
- const [disabled, setDisabled] = useState(false);
16
- const { optionProps, isSelected } = useOption(
17
- {
18
- key: item.key,
19
- },
20
- state,
21
- ref
22
- );
23
-
24
- useEffect(() => {
25
- for (const key of state.disabledKeys.values()) {
26
- if (key === item.key) {
27
- setDisabled(true);
28
- }
29
- }
30
- }, [state.disabledKeys, item.key]);
31
-
32
- return (
33
- <Box
34
- as="li"
35
- {...optionProps}
36
- ref={ref}
37
- variant={
38
- isSelected
39
- ? 'select.option.selected'
40
- : disabled
41
- ? 'select.option.disabled'
42
- : 'select.option'
43
- }
44
- >
45
- {item.rendered}
46
- </Box>
47
- );
48
- };
@@ -1,50 +0,0 @@
1
- import React, { forwardRef, RefObject } from 'react';
2
- import { FocusScope } from '@react-aria/focus';
3
- import {
4
- DismissButton,
5
- OverlayContainer,
6
- useModal,
7
- useOverlay,
8
- } from '@react-aria/overlays';
9
- import { mergeProps } from '@react-aria/utils';
10
-
11
- import { Box } from '../Box';
12
-
13
- interface PopoverProps {
14
- isOpen?: boolean;
15
- onClose?: () => void;
16
- ref?: React.Ref<HTMLDivElement>;
17
- className?: string;
18
- }
19
-
20
- export const Popover: React.FC<PopoverProps> = forwardRef(
21
- ({ children, className, isOpen, onClose, ...otherProps }, ref) => {
22
- // Handle events that should cause the popup to close,
23
- const { overlayProps } = useOverlay(
24
- {
25
- isOpen,
26
- onClose,
27
- shouldCloseOnBlur: true,
28
- isDismissable: true,
29
- },
30
- ref as RefObject<HTMLElement>
31
- );
32
- // Hide content outside the modal from screen readers.
33
- const { modalProps } = useModal();
34
-
35
- return (
36
- <OverlayContainer>
37
- <FocusScope restoreFocus>
38
- <Box
39
- {...mergeProps(overlayProps, otherProps, modalProps)}
40
- className={className}
41
- ref={ref}
42
- >
43
- {children}
44
- <DismissButton onDismiss={onClose} />
45
- </Box>
46
- </FocusScope>
47
- </OverlayContainer>
48
- );
49
- }
50
- );
@@ -1,81 +0,0 @@
1
- import React from 'react';
2
- import type { Meta, ComponentStory } from '@storybook/react';
3
- import { Select } from './Select';
4
- import { Item } from '@marigold/components';
5
-
6
- export default {
7
- title: 'Components/Select',
8
- argTypes: {
9
- label: {
10
- control: {
11
- type: 'text',
12
- },
13
- table: {
14
- defaultValue: {
15
- summary: 'Select label',
16
- },
17
- },
18
- defaultValue: 'Favorite Color',
19
- },
20
- placeholder: {
21
- control: {
22
- type: 'text',
23
- },
24
- table: {
25
- defaultValue: {
26
- summary: 'Select an option',
27
- },
28
- },
29
- },
30
- disabled: {
31
- control: {
32
- type: 'boolean',
33
- },
34
- options: [true, false],
35
- table: {
36
- defaultValue: {
37
- summary: false,
38
- },
39
- },
40
- },
41
- required: {
42
- control: {
43
- type: 'boolean',
44
- },
45
- options: [true, false],
46
- table: {
47
- defaultValue: {
48
- summary: false,
49
- },
50
- },
51
- },
52
- error: {
53
- control: {
54
- type: 'boolean',
55
- },
56
- description: 'Error',
57
- table: {
58
- defaultValue: {
59
- summary: false,
60
- },
61
- },
62
- },
63
- errorMessage: {
64
- control: {
65
- type: 'text',
66
- },
67
- description: 'Error Message',
68
- },
69
- width: {
70
- control: 'number',
71
- },
72
- },
73
- } as Meta;
74
-
75
- export const Basic: ComponentStory<typeof Select> = args => (
76
- <Select {...args}>
77
- <Item>Red</Item>
78
- <Item>Orange</Item>
79
- <Item>Yellow</Item>
80
- </Select>
81
- );