@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.
- package/CHANGELOG.md +66 -161
- package/dist/index.d.ts +364 -32
- package/dist/index.js +1421 -5
- package/dist/index.mjs +1369 -0
- package/package.json +31 -11
- package/dist/ActionGroup/ActionGroup.d.ts +0 -8
- package/dist/ActionGroup/ActionGroup.stories.d.ts +0 -5
- package/dist/ActionGroup/index.d.ts +0 -1
- package/dist/Alert/Alert.d.ts +0 -18
- package/dist/Alert/Alert.stories.d.ts +0 -5
- package/dist/Alert/index.d.ts +0 -1
- package/dist/Badge/Badge.d.ts +0 -13
- package/dist/Badge/Badge.stories.d.ts +0 -5
- package/dist/Badge/index.d.ts +0 -1
- package/dist/Box.d.ts +0 -2
- package/dist/Button/Button.d.ts +0 -9
- package/dist/Button/Button.stories.d.ts +0 -5
- package/dist/Button/index.d.ts +0 -1
- package/dist/Card/Card.d.ts +0 -14
- package/dist/Card/Card.stories.d.ts +0 -5
- package/dist/Card/index.d.ts +0 -1
- package/dist/Checkbox/Checkbox.d.ts +0 -20
- package/dist/Checkbox/Checkbox.stories.d.ts +0 -5
- package/dist/Checkbox/CheckboxIcons.d.ts +0 -9
- package/dist/Checkbox/index.d.ts +0 -1
- package/dist/Column/Column.d.ts +0 -8
- package/dist/Column/Column.stories.d.ts +0 -5
- package/dist/Column/index.d.ts +0 -1
- package/dist/Columns/Columns.d.ts +0 -10
- package/dist/Columns/Columns.stories.d.ts +0 -5
- package/dist/Columns/index.d.ts +0 -1
- package/dist/Container/Container.d.ts +0 -6
- package/dist/Container/Container.stories.d.ts +0 -5
- package/dist/Container/index.d.ts +0 -1
- package/dist/Dialog/Dialog.d.ts +0 -17
- package/dist/Dialog/Dialog.stories.d.ts +0 -5
- package/dist/Dialog/ModalDialog.d.ts +0 -8
- package/dist/Dialog/index.d.ts +0 -1
- package/dist/Divider/Divider.d.ts +0 -12
- package/dist/Divider/Divider.stories.d.ts +0 -5
- package/dist/Divider/index.d.ts +0 -1
- package/dist/Field/Field.d.ts +0 -13
- package/dist/Field/Field.stories.d.ts +0 -5
- package/dist/Field/index.d.ts +0 -1
- package/dist/Image/Image.d.ts +0 -12
- package/dist/Image/Image.stories.d.ts +0 -5
- package/dist/Image/index.d.ts +0 -1
- package/dist/Inline/Inline.d.ts +0 -7
- package/dist/Inline/Inline.stories.d.ts +0 -5
- package/dist/Inline/index.d.ts +0 -1
- package/dist/Input/Input.d.ts +0 -11
- package/dist/Input/Input.stories.d.ts +0 -5
- package/dist/Input/index.d.ts +0 -1
- package/dist/Label/Label.d.ts +0 -19
- package/dist/Label/Label.stories.d.ts +0 -5
- package/dist/Label/index.d.ts +0 -1
- package/dist/Link/Link.d.ts +0 -10
- package/dist/Link/Link.stories.d.ts +0 -5
- package/dist/Link/index.d.ts +0 -1
- package/dist/Menu/Menu.d.ts +0 -15
- package/dist/Menu/Menu.stories.d.ts +0 -5
- package/dist/Menu/index.d.ts +0 -1
- package/dist/MenuItem/MenuItem.d.ts +0 -12
- package/dist/MenuItem/MenuItem.stories.d.ts +0 -5
- package/dist/MenuItem/index.d.ts +0 -1
- package/dist/Message/Message.d.ts +0 -12
- package/dist/Message/Message.stories.d.ts +0 -5
- package/dist/Message/index.d.ts +0 -1
- package/dist/Provider/MarigoldProvider.d.ts +0 -11
- package/dist/Provider/index.d.ts +0 -3
- package/dist/Radio/Radio.d.ts +0 -21
- package/dist/Radio/RadioIcons.d.ts +0 -10
- package/dist/Radio/index.d.ts +0 -1
- package/dist/Select/ListBox.d.ts +0 -9
- package/dist/Select/ListBoxSection.d.ts +0 -9
- package/dist/Select/Option.d.ts +0 -9
- package/dist/Select/Popover.d.ts +0 -9
- package/dist/Select/Select.d.ts +0 -27
- package/dist/Select/Select.stories.d.ts +0 -5
- package/dist/Select/index.d.ts +0 -1
- package/dist/Slider/Slider.d.ts +0 -11
- package/dist/Slider/Slider.stories.d.ts +0 -5
- package/dist/Slider/index.d.ts +0 -1
- package/dist/Stack/Stack.d.ts +0 -7
- package/dist/Stack/Stack.stories.d.ts +0 -5
- package/dist/Stack/index.d.ts +0 -1
- package/dist/Text/Text.d.ts +0 -17
- package/dist/Text/Text.stories.d.ts +0 -5
- package/dist/Text/index.d.ts +0 -1
- package/dist/Textarea/Textarea.d.ts +0 -16
- package/dist/Textarea/Textarea.stories.d.ts +0 -5
- package/dist/Textarea/index.d.ts +0 -1
- package/dist/ValidationMessage/ValidationMessage.d.ts +0 -11
- package/dist/ValidationMessage/ValidationMessage.stories.d.ts +0 -5
- package/dist/ValidationMessage/index.d.ts +0 -1
- package/dist/VisuallyHidden/VisuallyHidden.d.ts +0 -1
- package/dist/VisuallyHidden/VisuallyHidden.stories.d.ts +0 -5
- package/dist/VisuallyHidden/index.d.ts +0 -1
- package/dist/components.cjs.development.js +0 -1422
- package/dist/components.cjs.development.js.map +0 -1
- package/dist/components.cjs.production.min.js +0 -2
- package/dist/components.cjs.production.min.js.map +0 -1
- package/dist/components.esm.js +0 -1348
- package/dist/components.esm.js.map +0 -1
- package/dist/theme.d.ts +0 -23
- package/src/ActionGroup/ActionGroup.stories.tsx +0 -47
- package/src/ActionGroup/ActionGroup.test.tsx +0 -83
- package/src/ActionGroup/ActionGroup.tsx +0 -32
- package/src/ActionGroup/index.ts +0 -1
- package/src/Alert/Alert.stories.tsx +0 -32
- package/src/Alert/Alert.test.tsx +0 -82
- package/src/Alert/Alert.tsx +0 -52
- package/src/Alert/index.ts +0 -1
- package/src/Badge/Badge.stories.tsx +0 -38
- package/src/Badge/Badge.test.tsx +0 -65
- package/src/Badge/Badge.tsx +0 -37
- package/src/Badge/index.ts +0 -1
- package/src/Box.ts +0 -2
- package/src/Button/Button.stories.tsx +0 -57
- package/src/Button/Button.test.tsx +0 -149
- package/src/Button/Button.tsx +0 -64
- package/src/Button/index.ts +0 -1
- package/src/Card/Card.stories.tsx +0 -41
- package/src/Card/Card.test.tsx +0 -71
- package/src/Card/Card.tsx +0 -48
- package/src/Card/index.ts +0 -1
- package/src/Checkbox/Checkbox.stories.mdx +0 -97
- package/src/Checkbox/Checkbox.stories.tsx +0 -78
- package/src/Checkbox/Checkbox.test.tsx +0 -166
- package/src/Checkbox/Checkbox.tsx +0 -101
- package/src/Checkbox/CheckboxIcons.tsx +0 -59
- package/src/Checkbox/index.ts +0 -1
- package/src/Column/Column.stories.tsx +0 -33
- package/src/Column/Column.test.tsx +0 -32
- package/src/Column/Column.tsx +0 -27
- package/src/Column/index.ts +0 -1
- package/src/Columns/Columns.stories.tsx +0 -75
- package/src/Columns/Columns.test.tsx +0 -113
- package/src/Columns/Columns.tsx +0 -69
- package/src/Columns/index.ts +0 -1
- package/src/Container/Container.stories.tsx +0 -14
- package/src/Container/Container.test.tsx +0 -26
- package/src/Container/Container.tsx +0 -13
- package/src/Container/index.ts +0 -1
- package/src/Dialog/Dialog.stories.tsx +0 -88
- package/src/Dialog/Dialog.test.tsx +0 -158
- package/src/Dialog/Dialog.tsx +0 -130
- package/src/Dialog/ModalDialog.tsx +0 -76
- package/src/Dialog/index.ts +0 -1
- package/src/Divider/Divider.stories.tsx +0 -30
- package/src/Divider/Divider.test.tsx +0 -71
- package/src/Divider/Divider.tsx +0 -25
- package/src/Divider/index.ts +0 -1
- package/src/Field/Field.stories.tsx +0 -110
- package/src/Field/Field.test.tsx +0 -130
- package/src/Field/Field.tsx +0 -56
- package/src/Field/index.ts +0 -1
- package/src/Image/Image.stories.tsx +0 -34
- package/src/Image/Image.test.tsx +0 -73
- package/src/Image/Image.tsx +0 -25
- package/src/Image/index.ts +0 -1
- package/src/Inline/Inline.stories.tsx +0 -39
- package/src/Inline/Inline.test.tsx +0 -99
- package/src/Inline/Inline.tsx +0 -38
- package/src/Inline/index.ts +0 -1
- package/src/Input/Input.stories.tsx +0 -54
- package/src/Input/Input.test.tsx +0 -74
- package/src/Input/Input.tsx +0 -25
- package/src/Input/index.ts +0 -1
- package/src/Label/Label.stories.tsx +0 -41
- package/src/Label/Label.test.tsx +0 -109
- package/src/Label/Label.tsx +0 -64
- package/src/Label/index.ts +0 -1
- package/src/Link/Link.stories.tsx +0 -35
- package/src/Link/Link.test.tsx +0 -97
- package/src/Link/Link.tsx +0 -42
- package/src/Link/index.ts +0 -1
- package/src/Menu/Menu.stories.tsx +0 -62
- package/src/Menu/Menu.test.tsx +0 -84
- package/src/Menu/Menu.tsx +0 -51
- package/src/Menu/index.ts +0 -1
- package/src/MenuItem/MenuItem.stories.tsx +0 -30
- package/src/MenuItem/MenuItem.test.tsx +0 -68
- package/src/MenuItem/MenuItem.tsx +0 -35
- package/src/MenuItem/index.ts +0 -1
- package/src/Message/Message.stories.tsx +0 -30
- package/src/Message/Message.test.tsx +0 -90
- package/src/Message/Message.tsx +0 -55
- package/src/Message/index.ts +0 -1
- package/src/Provider/MarigoldProvider.test.tsx +0 -136
- package/src/Provider/MarigoldProvider.tsx +0 -47
- package/src/Provider/index.ts +0 -4
- package/src/Radio/Radio.stories.mdx +0 -97
- package/src/Radio/Radio.test.tsx +0 -119
- package/src/Radio/Radio.tsx +0 -128
- package/src/Radio/RadioIcons.tsx +0 -39
- package/src/Radio/index.ts +0 -1
- package/src/Select/ListBox.tsx +0 -40
- package/src/Select/ListBoxSection.tsx +0 -40
- package/src/Select/Option.tsx +0 -48
- package/src/Select/Popover.tsx +0 -50
- package/src/Select/Select.stories.tsx +0 -81
- package/src/Select/Select.test.tsx +0 -349
- package/src/Select/Select.tsx +0 -174
- package/src/Select/index.ts +0 -1
- package/src/Slider/Slider.stories.tsx +0 -24
- package/src/Slider/Slider.test.tsx +0 -63
- package/src/Slider/Slider.tsx +0 -35
- package/src/Slider/index.ts +0 -1
- package/src/Stack/Stack.stories.tsx +0 -57
- package/src/Stack/Stack.test.tsx +0 -138
- package/src/Stack/Stack.tsx +0 -39
- package/src/Stack/index.ts +0 -1
- package/src/Text/Text.stories.tsx +0 -61
- package/src/Text/Text.test.tsx +0 -99
- package/src/Text/Text.tsx +0 -60
- package/src/Text/index.ts +0 -1
- package/src/Textarea/Textarea.stories.tsx +0 -64
- package/src/Textarea/Textarea.test.tsx +0 -95
- package/src/Textarea/Textarea.tsx +0 -62
- package/src/Textarea/index.ts +0 -1
- package/src/ValidationMessage/ValidationMessage.stories.tsx +0 -27
- package/src/ValidationMessage/ValidationMessage.test.tsx +0 -68
- package/src/ValidationMessage/ValidationMessage.tsx +0 -40
- package/src/ValidationMessage/index.ts +0 -1
- package/src/VisuallyHidden/VisuallyHidden.stories.tsx +0 -19
- package/src/VisuallyHidden/VisuallyHidden.test.tsx +0 -10
- package/src/VisuallyHidden/VisuallyHidden.tsx +0 -1
- package/src/VisuallyHidden/index.ts +0 -1
- package/src/index.ts +0 -34
- package/src/theme.ts +0 -50
- package/tsconfig.build.json +0 -3
package/src/Columns/Columns.tsx
DELETED
|
@@ -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
|
-
};
|
package/src/Columns/index.ts
DELETED
|
@@ -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
|
-
);
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { render, screen } from '@testing-library/react';
|
|
3
|
-
import { Container } from './Container';
|
|
4
|
-
import { Text } from '../Text';
|
|
5
|
-
|
|
6
|
-
test('renders correct HTML element', () => {
|
|
7
|
-
render(
|
|
8
|
-
<Container title="container">
|
|
9
|
-
<Text>sdf</Text>
|
|
10
|
-
</Container>
|
|
11
|
-
);
|
|
12
|
-
const container = screen.getByTitle(/container/);
|
|
13
|
-
|
|
14
|
-
expect(container instanceof HTMLDivElement).toBeTruthy();
|
|
15
|
-
});
|
|
16
|
-
|
|
17
|
-
test('accepts custom styles prop className', () => {
|
|
18
|
-
render(
|
|
19
|
-
<Container className="custom-class-name" title="container">
|
|
20
|
-
<Text>text</Text>
|
|
21
|
-
</Container>
|
|
22
|
-
);
|
|
23
|
-
const container = screen.getByTitle(/container/);
|
|
24
|
-
|
|
25
|
-
expect(container.className).toMatch('custom-class-name');
|
|
26
|
-
});
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { Box } from '../Box';
|
|
3
|
-
|
|
4
|
-
export type ContainerProps = {
|
|
5
|
-
className?: string;
|
|
6
|
-
title?: string; // Used for testing.
|
|
7
|
-
};
|
|
8
|
-
|
|
9
|
-
export const Container: React.FC<ContainerProps> = ({ children, ...props }) => (
|
|
10
|
-
<Box {...props} width="100%">
|
|
11
|
-
{children}
|
|
12
|
-
</Box>
|
|
13
|
-
);
|
package/src/Container/index.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './Container';
|
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import type { Meta, ComponentStory } from '@storybook/react';
|
|
3
|
-
import { Dialog, useDialogButtonProps } from './Dialog';
|
|
4
|
-
import { Button } from '../Button';
|
|
5
|
-
import { Text } from '../Text';
|
|
6
|
-
|
|
7
|
-
export default {
|
|
8
|
-
title: 'Components/Dialog',
|
|
9
|
-
parameters: {
|
|
10
|
-
actions: {
|
|
11
|
-
handles: ['click'],
|
|
12
|
-
},
|
|
13
|
-
},
|
|
14
|
-
argTypes: {
|
|
15
|
-
isOpen: {
|
|
16
|
-
control: {
|
|
17
|
-
type: 'boolean',
|
|
18
|
-
},
|
|
19
|
-
description: 'handled by state from useDialogButtonProps',
|
|
20
|
-
options: [true, false],
|
|
21
|
-
table: {
|
|
22
|
-
defaultValue: {
|
|
23
|
-
summary: false,
|
|
24
|
-
},
|
|
25
|
-
},
|
|
26
|
-
},
|
|
27
|
-
title: {
|
|
28
|
-
control: {
|
|
29
|
-
type: 'text',
|
|
30
|
-
},
|
|
31
|
-
description: 'set dialog title',
|
|
32
|
-
},
|
|
33
|
-
close: {
|
|
34
|
-
control: {
|
|
35
|
-
type: 'text',
|
|
36
|
-
},
|
|
37
|
-
description: 'handled by state from useDialogButtonProps',
|
|
38
|
-
},
|
|
39
|
-
variant: {
|
|
40
|
-
control: {
|
|
41
|
-
type: 'text',
|
|
42
|
-
},
|
|
43
|
-
description: 'Dialog variant',
|
|
44
|
-
table: {
|
|
45
|
-
defaultValue: {
|
|
46
|
-
summary: '__default',
|
|
47
|
-
},
|
|
48
|
-
},
|
|
49
|
-
},
|
|
50
|
-
backdropVariant: {
|
|
51
|
-
control: {
|
|
52
|
-
type: 'text',
|
|
53
|
-
},
|
|
54
|
-
description: 'Dialog backdrop variant',
|
|
55
|
-
table: {
|
|
56
|
-
defaultValue: {
|
|
57
|
-
summary: 'backdrop',
|
|
58
|
-
},
|
|
59
|
-
},
|
|
60
|
-
},
|
|
61
|
-
},
|
|
62
|
-
} as Meta;
|
|
63
|
-
|
|
64
|
-
export const Basic: ComponentStory<typeof Dialog> = args => {
|
|
65
|
-
const { state, openButtonProps, openButtonRef } = useDialogButtonProps();
|
|
66
|
-
return (
|
|
67
|
-
<>
|
|
68
|
-
<Button
|
|
69
|
-
variant="secondary"
|
|
70
|
-
size="small"
|
|
71
|
-
{...openButtonProps}
|
|
72
|
-
ref={openButtonRef}
|
|
73
|
-
>
|
|
74
|
-
Open Dialog
|
|
75
|
-
</Button>
|
|
76
|
-
{state.isOpen && (
|
|
77
|
-
<Dialog
|
|
78
|
-
title="Dialog Title"
|
|
79
|
-
{...args}
|
|
80
|
-
isOpen={state.isOpen}
|
|
81
|
-
close={state.close}
|
|
82
|
-
>
|
|
83
|
-
<Text>Dialog content</Text>
|
|
84
|
-
</Dialog>
|
|
85
|
-
)}
|
|
86
|
-
</>
|
|
87
|
-
);
|
|
88
|
-
};
|
|
@@ -1,158 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { fireEvent, render, screen } from '@testing-library/react';
|
|
3
|
-
import userEvent from '@testing-library/user-event';
|
|
4
|
-
|
|
5
|
-
import { ThemeProvider } from '@marigold/system';
|
|
6
|
-
|
|
7
|
-
import { Dialog, useDialogButtonProps } from './Dialog';
|
|
8
|
-
import { Button } from '../Button';
|
|
9
|
-
|
|
10
|
-
const theme = {
|
|
11
|
-
space: {
|
|
12
|
-
none: 0,
|
|
13
|
-
xxsmall: 1,
|
|
14
|
-
xsmall: 2,
|
|
15
|
-
small: 4,
|
|
16
|
-
medium: 8,
|
|
17
|
-
large: 16,
|
|
18
|
-
},
|
|
19
|
-
dialog: {
|
|
20
|
-
__default: {
|
|
21
|
-
p: 'small',
|
|
22
|
-
},
|
|
23
|
-
default: {
|
|
24
|
-
p: 'medium',
|
|
25
|
-
},
|
|
26
|
-
backdrop: {
|
|
27
|
-
p: 'none',
|
|
28
|
-
},
|
|
29
|
-
},
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
type DialogComponentProps = {
|
|
33
|
-
title?: string;
|
|
34
|
-
variant?: string;
|
|
35
|
-
backdropVariant?: string;
|
|
36
|
-
};
|
|
37
|
-
|
|
38
|
-
const DialogComponent: React.FC<DialogComponentProps> = ({
|
|
39
|
-
variant,
|
|
40
|
-
backdropVariant,
|
|
41
|
-
}) => {
|
|
42
|
-
const { state, openButtonProps, openButtonRef } = useDialogButtonProps();
|
|
43
|
-
return (
|
|
44
|
-
<>
|
|
45
|
-
<Button {...openButtonProps} ref={openButtonRef}>
|
|
46
|
-
Open
|
|
47
|
-
</Button>
|
|
48
|
-
{state.isOpen && (
|
|
49
|
-
<Dialog
|
|
50
|
-
variant={variant}
|
|
51
|
-
backdropVariant={backdropVariant}
|
|
52
|
-
title="Title"
|
|
53
|
-
isOpen={state.isOpen}
|
|
54
|
-
close={state.close}
|
|
55
|
-
>
|
|
56
|
-
Content
|
|
57
|
-
</Dialog>
|
|
58
|
-
)}
|
|
59
|
-
</>
|
|
60
|
-
);
|
|
61
|
-
};
|
|
62
|
-
|
|
63
|
-
test('dialog can be opened by button', () => {
|
|
64
|
-
render(<DialogComponent />);
|
|
65
|
-
const button = screen.getByText(/Open/);
|
|
66
|
-
fireEvent.click(button);
|
|
67
|
-
const dialog = screen.getByText(/Content/);
|
|
68
|
-
expect(dialog).toBeDefined();
|
|
69
|
-
});
|
|
70
|
-
|
|
71
|
-
test('supports default variants', () => {
|
|
72
|
-
render(
|
|
73
|
-
<ThemeProvider theme={theme}>
|
|
74
|
-
<DialogComponent />
|
|
75
|
-
</ThemeProvider>
|
|
76
|
-
);
|
|
77
|
-
const button = screen.getByText(/Open/);
|
|
78
|
-
fireEvent.click(button);
|
|
79
|
-
|
|
80
|
-
const dialog = screen.getByRole(/dialog/);
|
|
81
|
-
expect(dialog).toHaveStyle(`padding: 4px`);
|
|
82
|
-
expect(dialog.parentElement).toHaveStyle(`padding: 0px`);
|
|
83
|
-
});
|
|
84
|
-
|
|
85
|
-
test('supports other variants than default', () => {
|
|
86
|
-
render(
|
|
87
|
-
<ThemeProvider theme={theme}>
|
|
88
|
-
<DialogComponent variant="default" backdropVariant="default" />
|
|
89
|
-
</ThemeProvider>
|
|
90
|
-
);
|
|
91
|
-
const button = screen.getByText(/Open/);
|
|
92
|
-
fireEvent.click(button);
|
|
93
|
-
|
|
94
|
-
const dialog = screen.getByRole(/dialog/);
|
|
95
|
-
expect(dialog).toHaveStyle(`padding: 8px`);
|
|
96
|
-
expect(dialog.parentElement).toHaveStyle(`padding: 8px`);
|
|
97
|
-
});
|
|
98
|
-
|
|
99
|
-
test('dialog has correct baseCSS styles', async () => {
|
|
100
|
-
render(
|
|
101
|
-
<ThemeProvider theme={theme}>
|
|
102
|
-
<DialogComponent variant="default" backdropVariant="default" />
|
|
103
|
-
</ThemeProvider>
|
|
104
|
-
);
|
|
105
|
-
const button = screen.getByText(/Open/);
|
|
106
|
-
fireEvent.click(button);
|
|
107
|
-
|
|
108
|
-
const dialog = screen.getByRole(/dialog/);
|
|
109
|
-
expect(dialog.firstChild).toHaveStyle(`display: flex`);
|
|
110
|
-
expect(dialog.firstChild?.lastChild).toHaveStyle(`alignItems: start`);
|
|
111
|
-
|
|
112
|
-
// ModalDialog baseCSS
|
|
113
|
-
expect(dialog.parentElement).toHaveStyle(`display: grid`);
|
|
114
|
-
});
|
|
115
|
-
|
|
116
|
-
test('dialog has correct baseCSS styles with theme index', async () => {
|
|
117
|
-
render(
|
|
118
|
-
<ThemeProvider theme={theme}>
|
|
119
|
-
<DialogComponent variant="default" backdropVariant="default" />
|
|
120
|
-
</ThemeProvider>
|
|
121
|
-
);
|
|
122
|
-
const button = screen.getByText(/Open/);
|
|
123
|
-
fireEvent.click(button);
|
|
124
|
-
|
|
125
|
-
const dialog = screen.getByRole(/dialog/);
|
|
126
|
-
expect(dialog.firstChild).toHaveStyle(`paddingLeft: 16`);
|
|
127
|
-
expect(dialog.firstChild?.lastChild).toHaveStyle(`paddingTop: 2`);
|
|
128
|
-
|
|
129
|
-
// find all buttons to get the close and not the open button
|
|
130
|
-
const onCloseButton = await screen.findAllByRole('button');
|
|
131
|
-
expect(onCloseButton[1]).toHaveStyle(`paddingLeft: 1`);
|
|
132
|
-
});
|
|
133
|
-
|
|
134
|
-
test('close Dialog by escape key', () => {
|
|
135
|
-
render(<DialogComponent />);
|
|
136
|
-
const button = screen.getByText(/Open/);
|
|
137
|
-
fireEvent.click(button);
|
|
138
|
-
|
|
139
|
-
const dialog = screen.getByText(/Content/);
|
|
140
|
-
userEvent.type(dialog, '{esc}');
|
|
141
|
-
expect(dialog).not.toBeVisible();
|
|
142
|
-
});
|
|
143
|
-
|
|
144
|
-
test('close Dialog by close button', async () => {
|
|
145
|
-
render(<DialogComponent />);
|
|
146
|
-
const button = screen.getByText(/Open/);
|
|
147
|
-
fireEvent.click(button);
|
|
148
|
-
|
|
149
|
-
const dialog = screen.getByRole(/dialog/);
|
|
150
|
-
expect(dialog).toBeVisible();
|
|
151
|
-
|
|
152
|
-
// find all buttons to get the close and not the open button
|
|
153
|
-
const onCloseButton = await screen.findAllByRole('button');
|
|
154
|
-
expect(onCloseButton[1]).toBeVisible();
|
|
155
|
-
fireEvent.click(onCloseButton[1]);
|
|
156
|
-
|
|
157
|
-
expect(dialog).not.toBeVisible();
|
|
158
|
-
});
|
package/src/Dialog/Dialog.tsx
DELETED
|
@@ -1,130 +0,0 @@
|
|
|
1
|
-
import React, { RefObject } from 'react';
|
|
2
|
-
import { ComponentProps } from '@marigold/types';
|
|
3
|
-
import { useOverlayTriggerState } from '@react-stately/overlays';
|
|
4
|
-
import { OverlayContainer } from '@react-aria/overlays';
|
|
5
|
-
import { useButton } from '@react-aria/button';
|
|
6
|
-
import { Close } from '@marigold/icons';
|
|
7
|
-
|
|
8
|
-
import { Box } from '../Box';
|
|
9
|
-
import { Button } from '../Button';
|
|
10
|
-
import { Text } from '../Text';
|
|
11
|
-
|
|
12
|
-
import { ModalDialog, ModalDialogProps } from './ModalDialog';
|
|
13
|
-
|
|
14
|
-
// Props
|
|
15
|
-
// ---------------
|
|
16
|
-
export type DialogProps = {
|
|
17
|
-
backdropVariant?: string;
|
|
18
|
-
close: ComponentProps<typeof Button>['onClick'];
|
|
19
|
-
isOpen: boolean;
|
|
20
|
-
title?: string;
|
|
21
|
-
variant?: string;
|
|
22
|
-
} & ModalDialogProps &
|
|
23
|
-
ComponentProps<'div'>;
|
|
24
|
-
|
|
25
|
-
// Component
|
|
26
|
-
// ---------------
|
|
27
|
-
export const Dialog: React.FC<DialogProps> = ({
|
|
28
|
-
backdropVariant,
|
|
29
|
-
children,
|
|
30
|
-
className,
|
|
31
|
-
close,
|
|
32
|
-
isOpen,
|
|
33
|
-
title,
|
|
34
|
-
variant,
|
|
35
|
-
...props
|
|
36
|
-
}) => {
|
|
37
|
-
const closeButtonRef = React.useRef<HTMLElement>() as RefObject<HTMLElement>;
|
|
38
|
-
|
|
39
|
-
// useButton ensures that focus management is handled correctly,
|
|
40
|
-
// across all browsers. Focus is restored to the button once the
|
|
41
|
-
// dialog closes.
|
|
42
|
-
const { buttonProps: closeButtonProps } = useButton(
|
|
43
|
-
{
|
|
44
|
-
onPress: () => close(),
|
|
45
|
-
},
|
|
46
|
-
closeButtonRef
|
|
47
|
-
);
|
|
48
|
-
|
|
49
|
-
return (
|
|
50
|
-
<OverlayContainer>
|
|
51
|
-
<ModalDialog
|
|
52
|
-
variant={variant}
|
|
53
|
-
backdropVariant={backdropVariant}
|
|
54
|
-
isOpen={isOpen}
|
|
55
|
-
onClose={close}
|
|
56
|
-
isDismissable
|
|
57
|
-
{...props}
|
|
58
|
-
>
|
|
59
|
-
<Box
|
|
60
|
-
__baseCSS={{
|
|
61
|
-
display: 'flex',
|
|
62
|
-
justifyContent: 'space-between',
|
|
63
|
-
borderRadius: 'small',
|
|
64
|
-
pl: 'large',
|
|
65
|
-
pb: 'large',
|
|
66
|
-
}}
|
|
67
|
-
className={className}
|
|
68
|
-
>
|
|
69
|
-
<Box pt="medium">
|
|
70
|
-
{title && (
|
|
71
|
-
<Text as="h4" variant="headline4">
|
|
72
|
-
{title}
|
|
73
|
-
</Text>
|
|
74
|
-
)}
|
|
75
|
-
{children}
|
|
76
|
-
</Box>
|
|
77
|
-
<Box
|
|
78
|
-
__baseCSS={{
|
|
79
|
-
display: 'flex',
|
|
80
|
-
justifyContent: 'flex-end',
|
|
81
|
-
alignItems: 'start',
|
|
82
|
-
paddingTop: 'xsmall',
|
|
83
|
-
paddingX: 'xsmall',
|
|
84
|
-
}}
|
|
85
|
-
>
|
|
86
|
-
<Box
|
|
87
|
-
as={Button}
|
|
88
|
-
__baseCSS={{
|
|
89
|
-
color: 'text',
|
|
90
|
-
bg: 'transparent',
|
|
91
|
-
lineHeight: 'xsmall',
|
|
92
|
-
px: 'xxsmall',
|
|
93
|
-
':hover': {
|
|
94
|
-
color: 'text',
|
|
95
|
-
bg: 'transparent',
|
|
96
|
-
cursor: 'pointer',
|
|
97
|
-
},
|
|
98
|
-
':focus': {
|
|
99
|
-
outline: 0,
|
|
100
|
-
},
|
|
101
|
-
}}
|
|
102
|
-
{...closeButtonProps}
|
|
103
|
-
ref={closeButtonRef}
|
|
104
|
-
>
|
|
105
|
-
<Close size={16} />
|
|
106
|
-
</Box>
|
|
107
|
-
</Box>
|
|
108
|
-
</Box>
|
|
109
|
-
</ModalDialog>
|
|
110
|
-
</OverlayContainer>
|
|
111
|
-
);
|
|
112
|
-
};
|
|
113
|
-
|
|
114
|
-
// get the overlayTriggerState and openButton props for using the dialog component
|
|
115
|
-
export const useDialogButtonProps = () => {
|
|
116
|
-
const state = useOverlayTriggerState({});
|
|
117
|
-
const openButtonRef = React.useRef<HTMLElement>() as RefObject<HTMLElement>;
|
|
118
|
-
const { buttonProps: openButtonProps } = useButton(
|
|
119
|
-
{
|
|
120
|
-
onPress: () => state.open(),
|
|
121
|
-
},
|
|
122
|
-
openButtonRef
|
|
123
|
-
);
|
|
124
|
-
|
|
125
|
-
return {
|
|
126
|
-
state,
|
|
127
|
-
openButtonProps,
|
|
128
|
-
openButtonRef,
|
|
129
|
-
};
|
|
130
|
-
};
|
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
import React, { RefObject } from 'react';
|
|
2
|
-
import {
|
|
3
|
-
useOverlay,
|
|
4
|
-
usePreventScroll,
|
|
5
|
-
useModal,
|
|
6
|
-
OverlayProps,
|
|
7
|
-
} from '@react-aria/overlays';
|
|
8
|
-
import { useDialog } from '@react-aria/dialog';
|
|
9
|
-
import { FocusScope } from '@react-aria/focus';
|
|
10
|
-
import { AriaDialogProps } from '@react-types/dialog';
|
|
11
|
-
|
|
12
|
-
import { Box } from '../Box';
|
|
13
|
-
|
|
14
|
-
// Props
|
|
15
|
-
// ---------------
|
|
16
|
-
export type ModalDialogProps = {
|
|
17
|
-
variant?: string;
|
|
18
|
-
backdropVariant?: string;
|
|
19
|
-
} & OverlayProps &
|
|
20
|
-
AriaDialogProps;
|
|
21
|
-
|
|
22
|
-
// Component
|
|
23
|
-
// ---------------
|
|
24
|
-
export const ModalDialog: React.FC<ModalDialogProps> = ({
|
|
25
|
-
variant,
|
|
26
|
-
backdropVariant = 'backdrop',
|
|
27
|
-
children,
|
|
28
|
-
...props
|
|
29
|
-
}) => {
|
|
30
|
-
const { isDismissable, isOpen, onClose, ...restProps } = props;
|
|
31
|
-
|
|
32
|
-
// Handle interacting outside the dialog and pressing
|
|
33
|
-
// the Escape key to close the modal.
|
|
34
|
-
const ref = React.useRef<HTMLElement>() as RefObject<HTMLElement>;
|
|
35
|
-
const { overlayProps, underlayProps } = useOverlay(
|
|
36
|
-
{ isDismissable, isOpen, onClose },
|
|
37
|
-
ref
|
|
38
|
-
);
|
|
39
|
-
|
|
40
|
-
// Prevent scrolling while the modal is open, and hide content
|
|
41
|
-
// outside the modal from screen readers.
|
|
42
|
-
usePreventScroll();
|
|
43
|
-
|
|
44
|
-
const { modalProps } = useModal();
|
|
45
|
-
const { dialogProps } = useDialog(props, ref);
|
|
46
|
-
|
|
47
|
-
return (
|
|
48
|
-
<Box
|
|
49
|
-
__baseCSS={{
|
|
50
|
-
display: 'grid',
|
|
51
|
-
placeItems: 'center',
|
|
52
|
-
position: 'fixed',
|
|
53
|
-
zIndex: 100,
|
|
54
|
-
top: 0,
|
|
55
|
-
left: 0,
|
|
56
|
-
bottom: 0,
|
|
57
|
-
right: 0,
|
|
58
|
-
}}
|
|
59
|
-
variant={`dialog.${backdropVariant}`}
|
|
60
|
-
{...underlayProps}
|
|
61
|
-
>
|
|
62
|
-
<FocusScope contain restoreFocus autoFocus>
|
|
63
|
-
<Box
|
|
64
|
-
{...overlayProps}
|
|
65
|
-
{...dialogProps}
|
|
66
|
-
{...modalProps}
|
|
67
|
-
ref={ref}
|
|
68
|
-
variant={variant ? `dialog.${variant}` : `dialog`}
|
|
69
|
-
{...restProps}
|
|
70
|
-
>
|
|
71
|
-
{children}
|
|
72
|
-
</Box>
|
|
73
|
-
</FocusScope>
|
|
74
|
-
</Box>
|
|
75
|
-
);
|
|
76
|
-
};
|
package/src/Dialog/index.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './Dialog';
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import type { Meta, ComponentStory } from '@storybook/react';
|
|
3
|
-
import { Divider } from './Divider';
|
|
4
|
-
import { Text } from '../Text';
|
|
5
|
-
|
|
6
|
-
export default {
|
|
7
|
-
title: 'Components/Divider',
|
|
8
|
-
argTypes: {
|
|
9
|
-
variant: {
|
|
10
|
-
control: {
|
|
11
|
-
type: 'select',
|
|
12
|
-
},
|
|
13
|
-
options: ['regular', 'bold'],
|
|
14
|
-
description: 'Thick or thin line',
|
|
15
|
-
table: {
|
|
16
|
-
defaultValue: {
|
|
17
|
-
summary: 'regular',
|
|
18
|
-
},
|
|
19
|
-
},
|
|
20
|
-
},
|
|
21
|
-
},
|
|
22
|
-
} as Meta;
|
|
23
|
-
|
|
24
|
-
export const Basic: ComponentStory<typeof Divider> = args => (
|
|
25
|
-
<>
|
|
26
|
-
<Text>Above</Text>
|
|
27
|
-
<Divider {...args} />
|
|
28
|
-
<Text>Below</Text>
|
|
29
|
-
</>
|
|
30
|
-
);
|
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { render, screen } from '@testing-library/react';
|
|
3
|
-
import { ThemeProvider } from '@marigold/system';
|
|
4
|
-
import { Divider } from './Divider';
|
|
5
|
-
|
|
6
|
-
const theme = {
|
|
7
|
-
space: {
|
|
8
|
-
none: 0,
|
|
9
|
-
small: 2,
|
|
10
|
-
},
|
|
11
|
-
borders: {
|
|
12
|
-
none: 0,
|
|
13
|
-
regular: '1px solid',
|
|
14
|
-
},
|
|
15
|
-
divider: {
|
|
16
|
-
regular: {
|
|
17
|
-
border: 'none',
|
|
18
|
-
borderBottom: 'regular',
|
|
19
|
-
margin: 'small',
|
|
20
|
-
},
|
|
21
|
-
bold: {
|
|
22
|
-
border: 'none',
|
|
23
|
-
borderBottom: '2px solid',
|
|
24
|
-
margin: 'small',
|
|
25
|
-
},
|
|
26
|
-
},
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
test('supports default variant and themeSection', () => {
|
|
30
|
-
render(
|
|
31
|
-
<ThemeProvider theme={theme}>
|
|
32
|
-
<Divider title="divider" />
|
|
33
|
-
</ThemeProvider>
|
|
34
|
-
);
|
|
35
|
-
const divider = screen.getByTitle(/divider/);
|
|
36
|
-
|
|
37
|
-
expect(divider).toHaveStyle(`borderBottom: 1px solid`);
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
test('accepts other variant than default', () => {
|
|
41
|
-
render(
|
|
42
|
-
<ThemeProvider theme={theme}>
|
|
43
|
-
<Divider variant="bold" title="divider" />
|
|
44
|
-
</ThemeProvider>
|
|
45
|
-
);
|
|
46
|
-
const divider = screen.getByTitle(/divider/);
|
|
47
|
-
|
|
48
|
-
expect(divider).toHaveStyle(`borderBottom: 2px solid`);
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
test('renders correct HTML element', () => {
|
|
52
|
-
render(
|
|
53
|
-
<ThemeProvider theme={theme}>
|
|
54
|
-
<Divider title="divider" />
|
|
55
|
-
</ThemeProvider>
|
|
56
|
-
);
|
|
57
|
-
const divider = screen.getByTitle(/divider/);
|
|
58
|
-
|
|
59
|
-
expect(divider instanceof HTMLHRElement).toBeTruthy();
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
test('accepts custom styles prop className', () => {
|
|
63
|
-
render(
|
|
64
|
-
<ThemeProvider theme={theme}>
|
|
65
|
-
<Divider className="custom-class-name" title="divider" />
|
|
66
|
-
</ThemeProvider>
|
|
67
|
-
);
|
|
68
|
-
const divider = screen.getByTitle(/divider/);
|
|
69
|
-
|
|
70
|
-
expect(divider.className).toMatch('custom-class-name');
|
|
71
|
-
});
|