@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
|
@@ -1,36 +1,45 @@
|
|
|
1
|
-
import { Meta, Story
|
|
2
|
-
import { Link
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import { ArgsTable, Canvas, Meta, Story } from '@storybook/addon-docs';
|
|
2
|
+
import { Link } from './Link';
|
|
3
|
+
import { Text } from '../Text';
|
|
4
|
+
|
|
5
|
+
<Meta
|
|
6
|
+
title="Components/Link"
|
|
7
|
+
argTypes={{
|
|
8
|
+
variant: {
|
|
9
|
+
control: {
|
|
10
|
+
type: 'text',
|
|
11
|
+
},
|
|
12
|
+
description: '?',
|
|
13
|
+
table: {
|
|
14
|
+
defaultValue: {
|
|
15
|
+
summary: 'link',
|
|
16
|
+
},
|
|
17
|
+
},
|
|
18
|
+
},
|
|
19
|
+
href: {
|
|
20
|
+
control: {
|
|
21
|
+
type: 'text',
|
|
22
|
+
},
|
|
23
|
+
description: 'The URL to direct to',
|
|
24
|
+
type: {
|
|
25
|
+
required: true,
|
|
26
|
+
},
|
|
27
|
+
},
|
|
28
|
+
}}
|
|
29
|
+
/>
|
|
5
30
|
|
|
6
31
|
# Link
|
|
7
32
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
| :------------------- | :---------------------- | :------- |
|
|
16
|
-
| `href` | string | |
|
|
17
|
-
|
|
18
|
-
## Import
|
|
19
|
-
|
|
20
|
-
```tsx
|
|
21
|
-
import { Link } from '@marigold/components';
|
|
22
|
-
```
|
|
33
|
+
export const Template = args => (
|
|
34
|
+
<Text>
|
|
35
|
+
<Link href="https://marigold-ui.io" target="_blank">
|
|
36
|
+
Cool site
|
|
37
|
+
</Link>
|
|
38
|
+
</Text>
|
|
39
|
+
);
|
|
23
40
|
|
|
24
|
-
|
|
41
|
+
<Canvas>
|
|
42
|
+
<Story name="Default">{Template.bind({})}</Story>
|
|
43
|
+
</Canvas>
|
|
25
44
|
|
|
26
|
-
<
|
|
27
|
-
<Story name="Link">
|
|
28
|
-
<Text>
|
|
29
|
-
Link something nice like{' '}
|
|
30
|
-
<Link href="#!" target="_blank">
|
|
31
|
-
Marigold
|
|
32
|
-
</Link>{' '}
|
|
33
|
-
in text.
|
|
34
|
-
</Text>
|
|
35
|
-
</Story>
|
|
36
|
-
</Preview>
|
|
45
|
+
<ArgsTable story="Default" />
|
package/src/Link/Link.test.tsx
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { render, screen } from '@testing-library/react';
|
|
3
|
-
import {
|
|
4
|
-
import { Link } from '
|
|
3
|
+
import { ThemeProvider } from '@marigold/system';
|
|
4
|
+
import { Link } from './Link';
|
|
5
5
|
|
|
6
6
|
const theme = {
|
|
7
|
-
|
|
7
|
+
text: {
|
|
8
8
|
link: {
|
|
9
9
|
fontFamily: 'Inter',
|
|
10
10
|
},
|
|
@@ -14,55 +14,80 @@ const theme = {
|
|
|
14
14
|
},
|
|
15
15
|
};
|
|
16
16
|
|
|
17
|
-
test('
|
|
17
|
+
test('uses `text.link` as default variant', () => {
|
|
18
18
|
render(
|
|
19
|
-
<
|
|
20
|
-
<Link href="#!"
|
|
21
|
-
|
|
22
|
-
</Link>
|
|
23
|
-
</MarigoldProvider>
|
|
19
|
+
<ThemeProvider theme={theme}>
|
|
20
|
+
<Link href="#!">Link</Link>
|
|
21
|
+
</ThemeProvider>
|
|
24
22
|
);
|
|
25
|
-
const link = screen.
|
|
23
|
+
const link = screen.getByText(/Link/);
|
|
26
24
|
|
|
27
25
|
expect(link).toHaveStyle(`font-family: Inter`);
|
|
28
26
|
});
|
|
29
27
|
|
|
30
|
-
test('
|
|
28
|
+
test('allows to change variants via `variant` prop (with "text" prefix)', () => {
|
|
31
29
|
render(
|
|
32
|
-
<
|
|
33
|
-
<Link href="#!"
|
|
30
|
+
<ThemeProvider theme={theme}>
|
|
31
|
+
<Link href="#!" variant="second">
|
|
34
32
|
Link
|
|
35
33
|
</Link>
|
|
36
|
-
</
|
|
34
|
+
</ThemeProvider>
|
|
37
35
|
);
|
|
38
|
-
const link = screen.
|
|
36
|
+
const link = screen.getByText(/Link/);
|
|
39
37
|
|
|
40
38
|
expect(link).toHaveStyle(`font-family: Oswald`);
|
|
41
39
|
});
|
|
42
40
|
|
|
43
|
-
test('renders
|
|
41
|
+
test('renders a <a> element by default', () => {
|
|
42
|
+
render(
|
|
43
|
+
<ThemeProvider theme={theme}>
|
|
44
|
+
<Link href="#!">Link</Link>
|
|
45
|
+
</ThemeProvider>
|
|
46
|
+
);
|
|
47
|
+
const link = screen.getByText(/Link/);
|
|
48
|
+
|
|
49
|
+
expect(link instanceof HTMLAnchorElement).toBeTruthy();
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
test('accepts custom className', () => {
|
|
44
53
|
render(
|
|
45
|
-
<
|
|
46
|
-
<Link href="#!"
|
|
54
|
+
<ThemeProvider theme={theme}>
|
|
55
|
+
<Link href="#!" className="custom-class-name">
|
|
47
56
|
Link
|
|
48
57
|
</Link>
|
|
49
|
-
</
|
|
58
|
+
</ThemeProvider>
|
|
50
59
|
);
|
|
51
|
-
const link = screen.
|
|
60
|
+
const link = screen.getByText(/Link/);
|
|
52
61
|
|
|
53
|
-
expect(link).
|
|
62
|
+
expect(link.className).toMatch('custom-class-name');
|
|
54
63
|
});
|
|
55
64
|
|
|
56
|
-
test('
|
|
65
|
+
test('accepts other routing components', () => {
|
|
66
|
+
const RouterLink = React.forwardRef<
|
|
67
|
+
HTMLSpanElement,
|
|
68
|
+
{ to: string; children?: React.ReactNode }
|
|
69
|
+
>(() => <span>I am a Router Link!</span>);
|
|
70
|
+
|
|
57
71
|
render(
|
|
58
|
-
<
|
|
59
|
-
<Link
|
|
72
|
+
<ThemeProvider theme={theme}>
|
|
73
|
+
<Link as={RouterLink} to="/Home">
|
|
60
74
|
Link
|
|
61
75
|
</Link>
|
|
62
|
-
</
|
|
76
|
+
</ThemeProvider>
|
|
63
77
|
);
|
|
64
|
-
const link = screen.getByTitle(/link/);
|
|
65
78
|
|
|
66
|
-
|
|
67
|
-
expect(link).
|
|
79
|
+
const link = screen.getByText('I am a Router Link!');
|
|
80
|
+
expect(link).toBeTruthy();
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
test('a link can be disabled via aria attributes', () => {
|
|
84
|
+
render(
|
|
85
|
+
<ThemeProvider theme={theme}>
|
|
86
|
+
<Link href="#!" disabled={true}>
|
|
87
|
+
Link
|
|
88
|
+
</Link>
|
|
89
|
+
</ThemeProvider>
|
|
90
|
+
);
|
|
91
|
+
const link = screen.getByText(/Link/);
|
|
92
|
+
expect(link.getAttribute('aria-disabled')).toEqual('true');
|
|
68
93
|
});
|
package/src/Link/Link.tsx
CHANGED
|
@@ -1,14 +1,32 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
1
|
+
import React, { useRef } from 'react';
|
|
2
|
+
import { useLink } from '@react-aria/link';
|
|
3
|
+
import { PolymorphicComponent, PolymorphicProps } from '@marigold/types';
|
|
4
|
+
|
|
5
|
+
import { Text, TextOwnProps } from '../Text';
|
|
6
|
+
|
|
7
|
+
export type LinkOwnProps = { disabled?: boolean } & TextOwnProps;
|
|
8
|
+
export type LinkProps = PolymorphicProps<LinkOwnProps, 'a'>;
|
|
9
|
+
|
|
10
|
+
export const Link = (({
|
|
11
|
+
as = 'a',
|
|
12
|
+
variant = 'link',
|
|
13
|
+
children,
|
|
14
|
+
disabled,
|
|
15
|
+
...props
|
|
16
|
+
}: LinkProps) => {
|
|
17
|
+
const ref = useRef<any>();
|
|
18
|
+
const { linkProps } = useLink(
|
|
19
|
+
{
|
|
20
|
+
...props,
|
|
21
|
+
elementType: typeof as === 'string' ? as : 'span',
|
|
22
|
+
isDisabled: disabled,
|
|
23
|
+
},
|
|
24
|
+
ref
|
|
25
|
+
);
|
|
26
|
+
|
|
27
|
+
return (
|
|
28
|
+
<Text {...props} {...linkProps} as={as} variant={variant} ref={ref}>
|
|
29
|
+
{children}
|
|
30
|
+
</Text>
|
|
31
|
+
);
|
|
32
|
+
}) as PolymorphicComponent<LinkOwnProps, 'a'>;
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { ArgsTable, Canvas, Meta, Story } from '@storybook/addon-docs';
|
|
2
|
+
import { Menu } from './Menu';
|
|
3
|
+
import { MenuItem } from '../MenuItem';
|
|
4
|
+
import { BurgerMenu } from '@marigold/icons';
|
|
5
|
+
import { useState } from 'react';
|
|
6
|
+
|
|
7
|
+
<Meta
|
|
8
|
+
title="Components/Menu"
|
|
9
|
+
parameters={{
|
|
10
|
+
actions: {
|
|
11
|
+
handles: ['click'],
|
|
12
|
+
},
|
|
13
|
+
}}
|
|
14
|
+
argTypes={{
|
|
15
|
+
variant: {
|
|
16
|
+
control: {
|
|
17
|
+
type: 'text',
|
|
18
|
+
},
|
|
19
|
+
description: '?',
|
|
20
|
+
table: {
|
|
21
|
+
defaultValue: {
|
|
22
|
+
summary: 'default',
|
|
23
|
+
},
|
|
24
|
+
},
|
|
25
|
+
},
|
|
26
|
+
label: {
|
|
27
|
+
control: {
|
|
28
|
+
type: 'text',
|
|
29
|
+
},
|
|
30
|
+
description: 'Menu label on hover',
|
|
31
|
+
table: {
|
|
32
|
+
defaultValue: {
|
|
33
|
+
summary: 'Menu',
|
|
34
|
+
},
|
|
35
|
+
},
|
|
36
|
+
},
|
|
37
|
+
show: {
|
|
38
|
+
control: {
|
|
39
|
+
type: 'boolean',
|
|
40
|
+
},
|
|
41
|
+
options: [true, false],
|
|
42
|
+
description: 'Show what',
|
|
43
|
+
table: {
|
|
44
|
+
defaultValue: {
|
|
45
|
+
summary: false,
|
|
46
|
+
},
|
|
47
|
+
},
|
|
48
|
+
},
|
|
49
|
+
onClick: {
|
|
50
|
+
control: {
|
|
51
|
+
type: 'text',
|
|
52
|
+
},
|
|
53
|
+
description: 'Function to show menu or toggle something',
|
|
54
|
+
type: { required: true },
|
|
55
|
+
},
|
|
56
|
+
}}
|
|
57
|
+
/>
|
|
58
|
+
|
|
59
|
+
# Menu
|
|
60
|
+
|
|
61
|
+
export const Template = ({ onClick, ...args }) => {
|
|
62
|
+
const [showMenu, setShowMenu] = React.useState(false);
|
|
63
|
+
return (
|
|
64
|
+
<Menu
|
|
65
|
+
onClick={() => setShowMenu(!showMenu)}
|
|
66
|
+
show={showMenu}
|
|
67
|
+
label={<BurgerMenu />}
|
|
68
|
+
{...args}
|
|
69
|
+
>
|
|
70
|
+
<MenuItem href="#">Home</MenuItem>
|
|
71
|
+
<MenuItem href="#">Tickets</MenuItem>
|
|
72
|
+
<MenuItem href="#">Logout</MenuItem>
|
|
73
|
+
</Menu>
|
|
74
|
+
);
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
<Canvas>
|
|
78
|
+
<Story name="Mini menu">{Template.bind({})}</Story>
|
|
79
|
+
</Canvas>
|
|
80
|
+
|
|
81
|
+
<ArgsTable story="Mini menu" />
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { render, screen } from '@testing-library/react';
|
|
3
|
+
import { ThemeProvider } from '@marigold/system';
|
|
4
|
+
import { Menu } from './Menu';
|
|
5
|
+
import { MenuItem } from '../MenuItem';
|
|
6
|
+
|
|
7
|
+
const theme = {
|
|
8
|
+
menu: {
|
|
9
|
+
default: {
|
|
10
|
+
padding: '4px',
|
|
11
|
+
},
|
|
12
|
+
custom: {
|
|
13
|
+
padding: '8px',
|
|
14
|
+
},
|
|
15
|
+
},
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
test('supports default variant and themeSection', () => {
|
|
19
|
+
render(
|
|
20
|
+
<ThemeProvider theme={theme}>
|
|
21
|
+
<Menu title="menu" onClick={() => {}}>
|
|
22
|
+
<MenuItem href="#">Home</MenuItem>
|
|
23
|
+
</Menu>
|
|
24
|
+
</ThemeProvider>
|
|
25
|
+
);
|
|
26
|
+
const menu = screen.getByTitle(/menu/);
|
|
27
|
+
|
|
28
|
+
expect(menu).toHaveStyle(`padding: 4px`);
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
test('accepts other variant than default', () => {
|
|
32
|
+
render(
|
|
33
|
+
<ThemeProvider theme={theme}>
|
|
34
|
+
<Menu variant="custom" title="menu" onClick={() => {}}>
|
|
35
|
+
<MenuItem href="#">Home</MenuItem>
|
|
36
|
+
</Menu>
|
|
37
|
+
</ThemeProvider>
|
|
38
|
+
);
|
|
39
|
+
const menu = screen.getByTitle(/menu/);
|
|
40
|
+
|
|
41
|
+
expect(menu).toHaveStyle(`padding: 8px`);
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
test('supports show prop', () => {
|
|
45
|
+
render(
|
|
46
|
+
<ThemeProvider theme={theme}>
|
|
47
|
+
<Menu show={true} title="menu" onClick={() => {}}>
|
|
48
|
+
<MenuItem href="#">Home</MenuItem>
|
|
49
|
+
</Menu>
|
|
50
|
+
</ThemeProvider>
|
|
51
|
+
);
|
|
52
|
+
const menu = screen.getByTitle(/menu/);
|
|
53
|
+
|
|
54
|
+
expect(menu).toHaveStyle(`display: block`);
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
test('renders correct HTML element', () => {
|
|
58
|
+
render(
|
|
59
|
+
<ThemeProvider theme={theme}>
|
|
60
|
+
<Menu title="menu" onClick={() => {}}>
|
|
61
|
+
<MenuItem href="#">Home</MenuItem>
|
|
62
|
+
</Menu>
|
|
63
|
+
</ThemeProvider>
|
|
64
|
+
);
|
|
65
|
+
const menu = screen.getByTitle(/menu/);
|
|
66
|
+
|
|
67
|
+
expect(menu instanceof HTMLDivElement).toBeTruthy();
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
test('accepts custom styles prop className', () => {
|
|
71
|
+
render(
|
|
72
|
+
<Menu title="menu" onClick={() => {}} className="custom-class-name">
|
|
73
|
+
<MenuItem href="#">Home</MenuItem>
|
|
74
|
+
</Menu>
|
|
75
|
+
);
|
|
76
|
+
const menu = screen.getByTitle(/menu/);
|
|
77
|
+
|
|
78
|
+
expect(menu.className).toMatch('custom-class-name');
|
|
79
|
+
});
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { ComponentProps } from '@marigold/types';
|
|
3
|
+
|
|
4
|
+
import { Button } from '../Button';
|
|
5
|
+
import { Box } from '../Box';
|
|
6
|
+
|
|
7
|
+
export type MenuProps = {
|
|
8
|
+
variant?: string;
|
|
9
|
+
label?: string;
|
|
10
|
+
onClick: ComponentProps<typeof Button>['onClick'];
|
|
11
|
+
show?: boolean;
|
|
12
|
+
className?: string;
|
|
13
|
+
title?: string; // For testing
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export const Menu: React.FC<MenuProps> = ({
|
|
17
|
+
variant = 'default',
|
|
18
|
+
label = 'Menu',
|
|
19
|
+
onClick,
|
|
20
|
+
show = false,
|
|
21
|
+
children,
|
|
22
|
+
...props
|
|
23
|
+
}) => {
|
|
24
|
+
return (
|
|
25
|
+
<Box variant={`menu.${variant}`} {...props}>
|
|
26
|
+
<Button onClick={onClick} variant="menu">
|
|
27
|
+
{label}
|
|
28
|
+
</Button>
|
|
29
|
+
{show ? (
|
|
30
|
+
<Box
|
|
31
|
+
display="block"
|
|
32
|
+
position="absolute"
|
|
33
|
+
minWidth="120px"
|
|
34
|
+
borderRadius="2px"
|
|
35
|
+
>
|
|
36
|
+
{children}
|
|
37
|
+
</Box>
|
|
38
|
+
) : null}
|
|
39
|
+
</Box>
|
|
40
|
+
);
|
|
41
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './Menu';
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { ArgsTable, Canvas, Meta, Story } from '@storybook/addon-docs';
|
|
2
|
+
import { Menu } from '../Menu';
|
|
3
|
+
import { MenuItem } from './MenuItem';
|
|
4
|
+
|
|
5
|
+
<Meta
|
|
6
|
+
title="Components/MenuItem"
|
|
7
|
+
parameters={{
|
|
8
|
+
actions: {
|
|
9
|
+
handles: ['click'],
|
|
10
|
+
},
|
|
11
|
+
}}
|
|
12
|
+
argTypes={{
|
|
13
|
+
variant: {
|
|
14
|
+
control: {
|
|
15
|
+
type: 'text',
|
|
16
|
+
},
|
|
17
|
+
description: '?',
|
|
18
|
+
table: {
|
|
19
|
+
defaultValue: {
|
|
20
|
+
summary: 'default',
|
|
21
|
+
},
|
|
22
|
+
},
|
|
23
|
+
},
|
|
24
|
+
}}
|
|
25
|
+
/>
|
|
26
|
+
|
|
27
|
+
# Menu Item
|
|
28
|
+
|
|
29
|
+
export const Template = args => {
|
|
30
|
+
return <MenuItem href="#">Home</MenuItem>;
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
<Canvas>
|
|
34
|
+
<Story name="Menu Item">{Template.bind({})}</Story>
|
|
35
|
+
</Canvas>
|
|
36
|
+
|
|
37
|
+
<ArgsTable story="Menu Item" />
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { render, screen } from '@testing-library/react';
|
|
3
|
+
import { ThemeProvider } from '@marigold/system';
|
|
4
|
+
import { MenuItem } from './MenuItem';
|
|
5
|
+
|
|
6
|
+
const theme = {
|
|
7
|
+
menuItem: {
|
|
8
|
+
default: {
|
|
9
|
+
padding: '4px',
|
|
10
|
+
},
|
|
11
|
+
item: {
|
|
12
|
+
padding: '8px',
|
|
13
|
+
},
|
|
14
|
+
},
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
test('supports default variant', () => {
|
|
18
|
+
render(
|
|
19
|
+
<ThemeProvider theme={theme}>
|
|
20
|
+
<MenuItem title="menuItem">Item</MenuItem>
|
|
21
|
+
</ThemeProvider>
|
|
22
|
+
);
|
|
23
|
+
const menuItem = screen.getByTitle(/menuItem/);
|
|
24
|
+
|
|
25
|
+
expect(menuItem.parentElement).toHaveStyle(`padding: 4px`);
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
test('accepts other variant than default', () => {
|
|
29
|
+
render(
|
|
30
|
+
<ThemeProvider theme={theme}>
|
|
31
|
+
<MenuItem title="menuItem" variant="item">
|
|
32
|
+
Item
|
|
33
|
+
</MenuItem>
|
|
34
|
+
</ThemeProvider>
|
|
35
|
+
);
|
|
36
|
+
const menuItem = screen.getByTitle(/menuItem/);
|
|
37
|
+
|
|
38
|
+
expect(menuItem.parentElement).toHaveStyle(`padding: 8px`);
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
test('renders correct HTML element', () => {
|
|
42
|
+
render(
|
|
43
|
+
<ThemeProvider theme={theme}>
|
|
44
|
+
<MenuItem title="menuItem">Item</MenuItem>
|
|
45
|
+
</ThemeProvider>
|
|
46
|
+
);
|
|
47
|
+
const menuItem = screen.getByTitle(/menuItem/);
|
|
48
|
+
|
|
49
|
+
expect(menuItem instanceof HTMLAnchorElement).toBeTruthy();
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
test('accepts custom styles prop className', () => {
|
|
53
|
+
render(
|
|
54
|
+
<ThemeProvider theme={theme}>
|
|
55
|
+
<MenuItem title="menuItem" className="custom-class-name">
|
|
56
|
+
Item
|
|
57
|
+
</MenuItem>
|
|
58
|
+
</ThemeProvider>
|
|
59
|
+
);
|
|
60
|
+
const menuItem = screen.getByText(/Item/).parentElement;
|
|
61
|
+
|
|
62
|
+
expect(menuItem).toHaveClass('custom-class-name');
|
|
63
|
+
});
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { ComponentProps } from '@marigold/types';
|
|
3
|
+
import { Link } from '../Link';
|
|
4
|
+
import { Box } from '../Box';
|
|
5
|
+
|
|
6
|
+
export type MenuItemProps = {
|
|
7
|
+
variant?: string;
|
|
8
|
+
} & ComponentProps<typeof Link>;
|
|
9
|
+
|
|
10
|
+
export const MenuItem: React.FC<MenuItemProps> = ({
|
|
11
|
+
variant = 'default',
|
|
12
|
+
className,
|
|
13
|
+
children,
|
|
14
|
+
...props
|
|
15
|
+
}) => {
|
|
16
|
+
return (
|
|
17
|
+
<Box variant={`menuItem.${variant}`} className={className}>
|
|
18
|
+
<Link variant="menuItemLink" {...props}>
|
|
19
|
+
{children}
|
|
20
|
+
</Link>
|
|
21
|
+
</Box>
|
|
22
|
+
);
|
|
23
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './MenuItem';
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { ArgsTable, Canvas, Meta, Story } from '@storybook/addon-docs';
|
|
2
|
+
import { Message } from './Message';
|
|
3
|
+
import { Text } from '../Text';
|
|
4
|
+
|
|
5
|
+
<Meta
|
|
6
|
+
title="Components/Message"
|
|
7
|
+
argTypes={{
|
|
8
|
+
variant: {
|
|
9
|
+
control: {
|
|
10
|
+
type: 'select',
|
|
11
|
+
},
|
|
12
|
+
options: ['warning', 'error', 'info'],
|
|
13
|
+
description: 'Messaging in different colors and icons',
|
|
14
|
+
table: {
|
|
15
|
+
defaultValue: {
|
|
16
|
+
summary: 'info',
|
|
17
|
+
},
|
|
18
|
+
},
|
|
19
|
+
},
|
|
20
|
+
messageTitle: {
|
|
21
|
+
control: {
|
|
22
|
+
type: 'text',
|
|
23
|
+
},
|
|
24
|
+
description: 'Content',
|
|
25
|
+
type: {
|
|
26
|
+
required: true,
|
|
27
|
+
},
|
|
28
|
+
},
|
|
29
|
+
}}
|
|
30
|
+
/>
|
|
31
|
+
|
|
32
|
+
# Message
|
|
33
|
+
|
|
34
|
+
export const Template = args => (
|
|
35
|
+
<Message messageTitle="Danger Zone!" {...args}>
|
|
36
|
+
<Text>Hello, I am a simple message.</Text>
|
|
37
|
+
</Message>
|
|
38
|
+
);
|
|
39
|
+
|
|
40
|
+
<Canvas>
|
|
41
|
+
<Story name="Default">{Template.bind({})}</Story>
|
|
42
|
+
</Canvas>
|
|
43
|
+
|
|
44
|
+
<ArgsTable story="Default" />
|