@marigold/components 0.0.1 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/ActionGroup/ActionGroup.d.ts +9 -0
- package/dist/ActionGroup/index.d.ts +1 -0
- package/dist/Alert/Alert.d.ts +20 -2
- package/dist/Badge/Badge.d.ts +8 -0
- package/dist/Badge/index.d.ts +1 -0
- package/dist/Box/Box.d.ts +47 -0
- package/dist/Box/index.d.ts +1 -0
- package/dist/Button/Button.d.ts +4 -3
- package/dist/Card/Card.d.ts +9 -0
- package/dist/Card/index.d.ts +1 -0
- package/dist/Checkbox/Checkbox.d.ts +14 -2
- package/dist/Checkbox/CheckboxIcons.d.ts +9 -0
- package/dist/Column/Column.d.ts +8 -0
- package/dist/Column/index.d.ts +1 -0
- package/dist/Columns/Columns.d.ts +10 -0
- package/dist/Columns/index.d.ts +1 -0
- package/dist/Container/Container.d.ts +6 -0
- package/dist/Container/index.d.ts +1 -0
- package/dist/Dialog/Dialog.d.ts +14 -0
- package/dist/Dialog/ModalDialog.d.ts +5 -0
- package/dist/Dialog/index.d.ts +1 -0
- package/dist/Divider/Divider.d.ts +7 -0
- package/dist/Divider/index.d.ts +1 -0
- package/dist/Field/Field.d.ts +11 -0
- package/dist/Field/index.d.ts +1 -0
- package/dist/Heading/Heading.d.ts +7 -5
- package/dist/Hidden/Hidden.d.ts +5 -0
- package/dist/Hidden/index.d.ts +1 -0
- package/dist/Image/Image.d.ts +7 -0
- package/dist/Image/index.d.ts +1 -0
- package/dist/Input/Input.d.ts +6 -0
- package/dist/Input/index.d.ts +1 -0
- package/dist/Label/Label.d.ts +8 -5
- package/dist/Link/Link.d.ts +7 -3
- package/dist/Menu/Menu.d.ts +12 -0
- package/dist/Menu/index.d.ts +1 -0
- package/dist/MenuItem/MenuItem.d.ts +7 -0
- package/dist/MenuItem/index.d.ts +1 -0
- package/dist/Message/Message.d.ts +7 -0
- package/dist/Message/index.d.ts +1 -0
- package/dist/Provider/MarigoldProvider.d.ts +3 -0
- package/dist/Provider/index.d.ts +3 -0
- package/dist/Radio/Radio.d.ts +14 -2
- package/dist/Radio/RadioIcons.d.ts +9 -0
- package/dist/Select/ListBox.d.ts +8 -0
- package/dist/Select/ListBoxSection.d.ts +8 -0
- package/dist/Select/Option.d.ts +8 -0
- package/dist/Select/Popover.d.ts +9 -0
- package/dist/Select/Select.d.ts +13 -3
- package/dist/Slider/Slider.d.ts +6 -3
- package/dist/Stack/Stack.d.ts +7 -0
- package/dist/Stack/index.d.ts +1 -0
- package/dist/Text/Text.d.ts +12 -3
- package/dist/Textarea/Textarea.d.ts +11 -3
- package/dist/ValidationMessage/ValidationMessage.d.ts +6 -0
- package/dist/ValidationMessage/index.d.ts +1 -0
- package/dist/components.cjs.development.js +1308 -195
- 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 +1267 -185
- package/dist/components.esm.js.map +1 -1
- package/dist/index.d.ts +21 -4
- package/dist/theme.d.ts +24 -4
- package/package.json +24 -4
- package/src/ActionGroup/ActionGroup.stories.mdx +62 -0
- package/src/ActionGroup/ActionGroup.test.tsx +83 -0
- package/src/ActionGroup/ActionGroup.tsx +43 -0
- package/src/ActionGroup/index.ts +1 -0
- package/src/Alert/Alert.stories.mdx +30 -42
- package/src/Alert/Alert.test.tsx +37 -22
- package/src/Alert/Alert.tsx +31 -21
- package/src/Badge/Badge.stories.mdx +57 -0
- package/src/Badge/Badge.test.tsx +61 -0
- package/src/Badge/Badge.tsx +25 -0
- package/src/Badge/index.ts +1 -0
- package/src/Box/Box.stories.mdx +334 -0
- package/src/Box/Box.test.tsx +133 -0
- package/src/Box/Box.tsx +165 -0
- package/src/Box/index.ts +1 -0
- package/src/Button/Button.stories.mdx +58 -134
- package/src/Button/Button.test.tsx +65 -23
- package/src/Button/Button.tsx +48 -14
- package/src/Card/Card.stories.mdx +49 -0
- package/src/Card/Card.test.tsx +66 -0
- package/src/Card/Card.tsx +36 -0
- package/src/Card/index.ts +1 -0
- package/src/Checkbox/Checkbox.stories.mdx +79 -101
- package/src/Checkbox/Checkbox.test.tsx +73 -32
- package/src/Checkbox/Checkbox.tsx +114 -35
- package/src/Checkbox/CheckboxIcons.tsx +49 -0
- package/src/Column/Column.stories.mdx +49 -0
- package/src/Column/Column.test.tsx +32 -0
- package/src/Column/Column.tsx +27 -0
- package/src/Column/index.ts +1 -0
- package/src/Columns/Columns.stories.mdx +65 -0
- package/src/Columns/Columns.test.tsx +102 -0
- package/src/Columns/Columns.tsx +69 -0
- package/src/Columns/index.ts +1 -0
- package/src/Container/Container.stories.mdx +19 -0
- package/src/Container/Container.test.tsx +26 -0
- package/src/Container/Container.tsx +13 -0
- package/src/Container/index.ts +1 -0
- package/src/Dialog/Dialog.stories.mdx +73 -0
- package/src/Dialog/Dialog.test.tsx +87 -0
- package/src/Dialog/Dialog.tsx +84 -0
- package/src/Dialog/ModalDialog.tsx +47 -0
- package/src/Dialog/index.ts +1 -0
- package/src/Divider/Divider.stories.mdx +37 -0
- package/src/Divider/Divider.test.tsx +63 -0
- package/src/Divider/Divider.tsx +13 -0
- package/src/Divider/index.ts +1 -0
- package/src/Field/Field.stories.mdx +97 -0
- package/src/Field/Field.test.tsx +80 -0
- package/src/Field/Field.tsx +54 -0
- package/src/Field/index.ts +1 -0
- package/src/Heading/Heading.stories.mdx +36 -76
- package/src/Heading/Heading.test.tsx +31 -17
- package/src/Heading/Heading.tsx +15 -12
- package/src/Hidden/Hidden.stories.mdx +39 -0
- package/src/Hidden/Hidden.test.tsx +24 -0
- package/src/Hidden/Hidden.tsx +16 -0
- package/src/Hidden/index.ts +1 -0
- package/src/Image/Image.stories.mdx +36 -0
- package/src/Image/Image.test.tsx +70 -0
- package/src/Image/Image.tsx +13 -0
- package/src/Image/index.ts +1 -0
- package/src/Input/Input.stories.mdx +61 -0
- package/src/Input/Input.test.tsx +70 -0
- package/src/Input/Input.tsx +13 -0
- package/src/Input/index.ts +1 -0
- package/src/Label/Label.stories.mdx +50 -34
- package/src/Label/Label.test.tsx +45 -16
- package/src/Label/Label.tsx +26 -17
- package/src/Link/Link.stories.mdx +40 -31
- package/src/Link/Link.test.tsx +53 -28
- package/src/Link/Link.tsx +32 -14
- package/src/Menu/Menu.stories.mdx +81 -0
- package/src/Menu/Menu.test.tsx +79 -0
- package/src/Menu/Menu.tsx +41 -0
- package/src/Menu/index.ts +1 -0
- package/src/MenuItem/MenuItem.stories.mdx +37 -0
- package/src/MenuItem/MenuItem.test.tsx +63 -0
- package/src/MenuItem/MenuItem.tsx +23 -0
- package/src/MenuItem/index.ts +1 -0
- package/src/Message/Message.stories.mdx +44 -0
- package/src/Message/Message.test.tsx +87 -0
- package/src/Message/Message.tsx +43 -0
- package/src/Message/index.ts +1 -0
- package/src/Provider/MarigoldProvider.test.tsx +126 -0
- package/src/Provider/MarigoldProvider.tsx +29 -0
- package/src/Provider/index.ts +3 -0
- package/src/Radio/Radio.stories.mdx +80 -83
- package/src/Radio/Radio.test.tsx +63 -22
- package/src/Radio/Radio.tsx +110 -35
- package/src/Radio/RadioIcons.tsx +39 -0
- package/src/Select/ListBox.tsx +39 -0
- package/src/Select/ListBoxSection.tsx +40 -0
- package/src/Select/Option.tsx +48 -0
- package/src/Select/Popover.tsx +50 -0
- package/src/Select/Select.stories.mdx +72 -37
- package/src/Select/Select.test.tsx +271 -28
- package/src/Select/Select.tsx +158 -23
- package/src/Slider/Slider.stories.mdx +26 -54
- package/src/Slider/Slider.test.tsx +13 -13
- package/src/Slider/Slider.tsx +20 -18
- package/src/Stack/Stack.stories.mdx +51 -0
- package/src/Stack/Stack.test.tsx +129 -0
- package/src/Stack/Stack.tsx +39 -0
- package/src/Stack/index.ts +1 -0
- package/src/Text/Text.stories.mdx +53 -47
- package/src/Text/Text.test.tsx +55 -15
- package/src/Text/Text.tsx +44 -10
- package/src/Textarea/Textarea.stories.mdx +68 -21
- package/src/Textarea/Textarea.test.tsx +47 -16
- package/src/Textarea/Textarea.tsx +46 -14
- package/src/ValidationMessage/ValidationMessage.stories.mdx +36 -0
- package/src/ValidationMessage/ValidationMessage.test.tsx +63 -0
- package/src/ValidationMessage/ValidationMessage.tsx +28 -0
- package/src/ValidationMessage/index.ts +1 -0
- package/src/index.ts +22 -4
- package/src/theme.ts +24 -4
- package/dist/Svg/Svg.d.ts +0 -5
- package/dist/Svg/index.d.ts +0 -1
- package/dist/TextInput/TextInput.d.ts +0 -3
- package/dist/TextInput/index.d.ts +0 -1
- package/src/Svg/Svg.stories.mdx +0 -47
- package/src/Svg/Svg.test.tsx +0 -58
- package/src/Svg/Svg.tsx +0 -25
- package/src/Svg/index.ts +0 -1
- package/src/TextInput/TextInput.stories.mdx +0 -37
- package/src/TextInput/TextInput.test.tsx +0 -71
- package/src/TextInput/TextInput.tsx +0 -21
- package/src/TextInput/index.ts +0 -1
package/src/Radio/Radio.tsx
CHANGED
|
@@ -1,42 +1,117 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
2
|
+
import { ComponentProps } from '@marigold/types';
|
|
3
|
+
import { Exclamation } from '@marigold/icons';
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
import { Box } from '../Box';
|
|
6
|
+
import { Label } from '../Label';
|
|
7
|
+
import { ValidationMessage } from '../ValidationMessage';
|
|
6
8
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
+
import { RadioChecked, RadioUnchecked } from './RadioIcons';
|
|
10
|
+
|
|
11
|
+
// Radio Icon
|
|
12
|
+
// ---------------
|
|
13
|
+
type RadioIconProps = {
|
|
14
|
+
variant?: string;
|
|
15
|
+
checked?: boolean;
|
|
16
|
+
disabled?: boolean;
|
|
17
|
+
error?: boolean;
|
|
18
|
+
children?: never;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
const RadioIcon: React.FC<RadioIconProps> = ({
|
|
22
|
+
variant,
|
|
23
|
+
checked,
|
|
24
|
+
disabled,
|
|
25
|
+
error,
|
|
26
|
+
}) => {
|
|
27
|
+
if (checked) {
|
|
9
28
|
return (
|
|
10
|
-
<Box
|
|
11
|
-
<Box
|
|
12
|
-
as="input"
|
|
13
|
-
type="radio"
|
|
14
|
-
{...props}
|
|
15
|
-
css={{
|
|
16
|
-
position: 'absolute',
|
|
17
|
-
opacity: 0,
|
|
18
|
-
zIndex: -1,
|
|
19
|
-
width: 1,
|
|
20
|
-
height: 1,
|
|
21
|
-
overflow: 'hidden',
|
|
22
|
-
}}
|
|
23
|
-
/>
|
|
24
|
-
<Box
|
|
25
|
-
as={props.checked ? CircleChecked : CircleUnchecked}
|
|
26
|
-
aria-hidden="true"
|
|
27
|
-
themeSection="form"
|
|
28
|
-
variant={variant}
|
|
29
|
-
css={{
|
|
30
|
-
mr: 2,
|
|
31
|
-
verticalAlign: 'middle',
|
|
32
|
-
':hover': { cursor: 'pointer' },
|
|
33
|
-
'input:disabled ~ &': {
|
|
34
|
-
color: 'muted',
|
|
35
|
-
cursor: 'not-allowed',
|
|
36
|
-
},
|
|
37
|
-
}}
|
|
38
|
-
/>
|
|
39
|
-
</Box>
|
|
29
|
+
<Box as={RadioChecked} variant={`radio.${variant}`} disabled={disabled} />
|
|
40
30
|
);
|
|
41
31
|
}
|
|
32
|
+
return (
|
|
33
|
+
<Box
|
|
34
|
+
as={RadioUnchecked}
|
|
35
|
+
variant={`radio.${variant}`}
|
|
36
|
+
disabled={disabled}
|
|
37
|
+
error={error}
|
|
38
|
+
/>
|
|
39
|
+
);
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
// Radio Input
|
|
43
|
+
// ---------------
|
|
44
|
+
type RadioInputProps = {
|
|
45
|
+
variant?: string;
|
|
46
|
+
error?: boolean;
|
|
47
|
+
} & ComponentProps<'input'>;
|
|
48
|
+
|
|
49
|
+
const RadioInput: React.FC<RadioInputProps> = ({
|
|
50
|
+
className,
|
|
51
|
+
variant = 'default',
|
|
52
|
+
error,
|
|
53
|
+
...props
|
|
54
|
+
}) => (
|
|
55
|
+
<Box display="inline-block" className={className}>
|
|
56
|
+
<Box
|
|
57
|
+
as="input"
|
|
58
|
+
type="radio"
|
|
59
|
+
css={{
|
|
60
|
+
position: 'absolute',
|
|
61
|
+
opacity: 0,
|
|
62
|
+
zIndex: -1,
|
|
63
|
+
width: 1,
|
|
64
|
+
height: 1,
|
|
65
|
+
overflow: 'hidden',
|
|
66
|
+
}}
|
|
67
|
+
{...props}
|
|
68
|
+
/>
|
|
69
|
+
<RadioIcon
|
|
70
|
+
checked={props.checked}
|
|
71
|
+
variant={variant}
|
|
72
|
+
disabled={props.disabled}
|
|
73
|
+
error={error}
|
|
74
|
+
/>
|
|
75
|
+
</Box>
|
|
42
76
|
);
|
|
77
|
+
|
|
78
|
+
// Radio
|
|
79
|
+
// ---------------
|
|
80
|
+
export type RadioProps = {
|
|
81
|
+
id: string;
|
|
82
|
+
label?: string;
|
|
83
|
+
required?: boolean;
|
|
84
|
+
error?: boolean;
|
|
85
|
+
errorMessage?: string;
|
|
86
|
+
} & RadioInputProps;
|
|
87
|
+
|
|
88
|
+
export const Radio: React.FC<RadioProps> = ({
|
|
89
|
+
label,
|
|
90
|
+
required,
|
|
91
|
+
error,
|
|
92
|
+
errorMessage,
|
|
93
|
+
...props
|
|
94
|
+
}) => {
|
|
95
|
+
if (label) {
|
|
96
|
+
return (
|
|
97
|
+
<>
|
|
98
|
+
<Label
|
|
99
|
+
htmlFor={props.id}
|
|
100
|
+
required={required}
|
|
101
|
+
variant={props.disabled ? 'disabled' : 'inline'}
|
|
102
|
+
>
|
|
103
|
+
<Box as={RadioInput} pr="8px" error={error} {...props} />
|
|
104
|
+
{label}
|
|
105
|
+
</Label>
|
|
106
|
+
{error && errorMessage && (
|
|
107
|
+
<ValidationMessage>
|
|
108
|
+
<Exclamation size={16} />
|
|
109
|
+
{errorMessage}
|
|
110
|
+
</ValidationMessage>
|
|
111
|
+
)}
|
|
112
|
+
</>
|
|
113
|
+
);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
return <RadioInput {...props} />;
|
|
117
|
+
};
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { SVG } from '@marigold/icons';
|
|
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
|
+
);
|
|
@@ -0,0 +1,39 @@
|
|
|
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
|
+
css={{
|
|
24
|
+
listStyle: 'none',
|
|
25
|
+
}}
|
|
26
|
+
{...listBoxProps}
|
|
27
|
+
variant={error ? 'select.listbox.error' : 'select.listbox'}
|
|
28
|
+
ref={ref}
|
|
29
|
+
>
|
|
30
|
+
{[...state.collection].map(item =>
|
|
31
|
+
item.type === 'section' ? (
|
|
32
|
+
<ListBoxSection key={item.key} section={item} state={state} />
|
|
33
|
+
) : (
|
|
34
|
+
<Option key={item.key} item={item} state={state} />
|
|
35
|
+
)
|
|
36
|
+
)}
|
|
37
|
+
</Box>
|
|
38
|
+
);
|
|
39
|
+
};
|
|
@@ -0,0 +1,40 @@
|
|
|
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
|
+
};
|
|
@@ -0,0 +1,48 @@
|
|
|
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
|
+
};
|
|
@@ -0,0 +1,50 @@
|
|
|
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,43 +1,78 @@
|
|
|
1
|
-
import { Meta, Story
|
|
2
|
-
import {
|
|
1
|
+
import { ArgsTable, Canvas, Meta, Story } from '@storybook/addon-docs';
|
|
2
|
+
import { Select } from './Select';
|
|
3
|
+
import { Item } from '@marigold/components';
|
|
3
4
|
|
|
4
|
-
<Meta
|
|
5
|
+
<Meta
|
|
6
|
+
title="Components/Select"
|
|
7
|
+
argTypes={{
|
|
8
|
+
placeholder: {
|
|
9
|
+
control: {
|
|
10
|
+
type: 'text',
|
|
11
|
+
},
|
|
12
|
+
table: {
|
|
13
|
+
defaultValue: {
|
|
14
|
+
summary: 'Select an option',
|
|
15
|
+
},
|
|
16
|
+
},
|
|
17
|
+
},
|
|
18
|
+
disabled: {
|
|
19
|
+
control: {
|
|
20
|
+
type: 'boolean',
|
|
21
|
+
},
|
|
22
|
+
options: [true, false],
|
|
23
|
+
table: {
|
|
24
|
+
defaultValue: {
|
|
25
|
+
summary: false,
|
|
26
|
+
},
|
|
27
|
+
},
|
|
28
|
+
},
|
|
29
|
+
required: {
|
|
30
|
+
control: {
|
|
31
|
+
type: 'boolean',
|
|
32
|
+
},
|
|
33
|
+
options: [true, false],
|
|
34
|
+
table: {
|
|
35
|
+
defaultValue: {
|
|
36
|
+
summary: false,
|
|
37
|
+
},
|
|
38
|
+
},
|
|
39
|
+
},
|
|
40
|
+
error: {
|
|
41
|
+
control: {
|
|
42
|
+
type: 'boolean',
|
|
43
|
+
},
|
|
44
|
+
description: 'Error',
|
|
45
|
+
table: {
|
|
46
|
+
defaultValue: {
|
|
47
|
+
summary: false,
|
|
48
|
+
},
|
|
49
|
+
},
|
|
50
|
+
},
|
|
51
|
+
errorMessage: {
|
|
52
|
+
control: {
|
|
53
|
+
type: 'text',
|
|
54
|
+
},
|
|
55
|
+
description: 'Error Message',
|
|
56
|
+
},
|
|
57
|
+
width: {
|
|
58
|
+
control: 'number',
|
|
59
|
+
},
|
|
60
|
+
}}
|
|
61
|
+
/>
|
|
5
62
|
|
|
6
63
|
# Select
|
|
7
64
|
|
|
8
|
-
|
|
65
|
+
export const Template = args => (
|
|
66
|
+
<Select label="Favorite Color" htmlFor="id" {...args}>
|
|
67
|
+
{/* Storybook crashes with imported <Item> component
|
|
68
|
+
<Item>Red</Item>
|
|
69
|
+
<Item>Orange</Item>
|
|
70
|
+
<Item>Yellow</Item> */}
|
|
71
|
+
</Select>
|
|
72
|
+
);
|
|
9
73
|
|
|
10
|
-
|
|
74
|
+
<Canvas>
|
|
75
|
+
<Story name="Default">{Template.bind({})}</Story>
|
|
76
|
+
</Canvas>
|
|
11
77
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
```tsx
|
|
15
|
-
import { Select } from '@marigold/components';
|
|
16
|
-
```
|
|
17
|
-
|
|
18
|
-
## Usage
|
|
19
|
-
|
|
20
|
-
<Preview>
|
|
21
|
-
<Story name="Select">
|
|
22
|
-
<Label htmlFor="select">
|
|
23
|
-
Dropdown
|
|
24
|
-
<Select id="select">
|
|
25
|
-
<option selected>Choose here</option>
|
|
26
|
-
<option>Hi</option>
|
|
27
|
-
<option>Hey</option>
|
|
28
|
-
<option>Blubb</option>
|
|
29
|
-
</Select>
|
|
30
|
-
</Label>
|
|
31
|
-
</Story>
|
|
32
|
-
<Story name="Select disabled">
|
|
33
|
-
<Label htmlFor="select2">
|
|
34
|
-
Dropdown disabled
|
|
35
|
-
<Select disabled>
|
|
36
|
-
<option selected>Can't choose here</option>
|
|
37
|
-
<option>Hi</option>
|
|
38
|
-
<option>Hey</option>
|
|
39
|
-
<option>Blubb</option>
|
|
40
|
-
</Select>
|
|
41
|
-
</Label>
|
|
42
|
-
</Story>
|
|
43
|
-
</Preview>
|
|
78
|
+
<ArgsTable story="Default" />
|