@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
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { render, screen } from '@testing-library/react';
|
|
3
|
+
|
|
4
|
+
import { ThemeProvider } from '@marigold/system';
|
|
5
|
+
import { Box } from './Box';
|
|
6
|
+
|
|
7
|
+
// Setup
|
|
8
|
+
// ---------------
|
|
9
|
+
const theme = {
|
|
10
|
+
colors: {
|
|
11
|
+
primary: 'hotpink',
|
|
12
|
+
black: '#000',
|
|
13
|
+
white: '#FFF',
|
|
14
|
+
blue: '#2980b9',
|
|
15
|
+
},
|
|
16
|
+
space: [0, 2, 4, 8],
|
|
17
|
+
sizes: [0, 8, 16, 32],
|
|
18
|
+
borders: ['none', '1px solid black'],
|
|
19
|
+
radii: [0, 2, 4],
|
|
20
|
+
opacities: [0, 0.5, 1],
|
|
21
|
+
transitions: ['none', '1s opacity'],
|
|
22
|
+
shadows: ['none', '3px 3px 5px 6px #ccc', 'inset 0 0 10px #000000'],
|
|
23
|
+
variant: {
|
|
24
|
+
color: 'primary',
|
|
25
|
+
p: 2,
|
|
26
|
+
},
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
// Tests
|
|
30
|
+
// ---------------
|
|
31
|
+
test('renders a <div> by default', () => {
|
|
32
|
+
render(<Box>box</Box>);
|
|
33
|
+
const box = screen.getByText(/box/);
|
|
34
|
+
|
|
35
|
+
expect(box instanceof HTMLDivElement).toBeTruthy();
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
test('changes rendered element via as prop', () => {
|
|
39
|
+
render(<Box as="span">box</Box>);
|
|
40
|
+
const box = screen.getByText(/box/);
|
|
41
|
+
|
|
42
|
+
expect(box instanceof HTMLSpanElement).toBeTruthy();
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
test('passes down HTML attributes', () => {
|
|
46
|
+
render(
|
|
47
|
+
<Box className="my-custom-class" id="box-id" disabled>
|
|
48
|
+
box
|
|
49
|
+
</Box>
|
|
50
|
+
);
|
|
51
|
+
const box = screen.getByText(/box/);
|
|
52
|
+
|
|
53
|
+
expect(box.getAttribute('id')).toEqual('box-id');
|
|
54
|
+
expect(box.getAttribute('disabled')).toMatch('');
|
|
55
|
+
expect(box.getAttribute('class')).toMatch('my-custom-class');
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
test('forwards ref', () => {
|
|
59
|
+
const ref = React.createRef<HTMLButtonElement>();
|
|
60
|
+
render(
|
|
61
|
+
<Box as="button" ref={ref}>
|
|
62
|
+
button
|
|
63
|
+
</Box>
|
|
64
|
+
);
|
|
65
|
+
|
|
66
|
+
expect(ref.current instanceof HTMLButtonElement).toBeTruthy();
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
test.each([
|
|
70
|
+
[{ display: 'flex' }, 'display: flex'],
|
|
71
|
+
[{ height: 1 }, 'height: 8px'],
|
|
72
|
+
[{ width: 2 }, 'width: 16px'],
|
|
73
|
+
[{ minWidth: 1 }, 'min-width: 8px'],
|
|
74
|
+
[{ maxWidth: 3 }, 'max-width: 32px'],
|
|
75
|
+
[{ position: 'absolute' }, 'position: absolute'],
|
|
76
|
+
[{ top: 0 }, 'top: 0px'],
|
|
77
|
+
[{ bottom: 1 }, 'bottom: 2px'],
|
|
78
|
+
[{ right: 3 }, 'right: 8px'],
|
|
79
|
+
[{ left: 2 }, 'left: 4px'],
|
|
80
|
+
[{ zIndex: 1000 }, 'z-index: 1000'],
|
|
81
|
+
[{ p: 1 }, 'padding: 2px'],
|
|
82
|
+
[{ px: 1 }, 'padding-left: 2px', 'padding-right: 2px'],
|
|
83
|
+
[{ py: 2 }, 'padding-top: 4px', 'padding-bottom: 4px'],
|
|
84
|
+
[{ pt: 1 }, 'padding-top: 2px'],
|
|
85
|
+
[{ pb: 1 }, 'padding-bottom: 2px'],
|
|
86
|
+
[{ pl: 1 }, 'padding-left: 2px'],
|
|
87
|
+
[{ pr: 1 }, 'padding-right: 2px'],
|
|
88
|
+
[{ m: 1 }, 'margin: 2px'],
|
|
89
|
+
[{ mx: 1 }, 'margin-left: 2px', 'margin-right: 2px'],
|
|
90
|
+
[{ my: 2 }, 'margin-top: 4px', 'margin-bottom: 4px'],
|
|
91
|
+
[{ mt: 1 }, 'margin-top: 2px'],
|
|
92
|
+
[{ mb: 1 }, 'margin-bottom: 2px'],
|
|
93
|
+
[{ ml: 1 }, 'margin-left: 2px'],
|
|
94
|
+
[{ mr: 1 }, 'margin-right: 2px'],
|
|
95
|
+
[{ flexDirection: 'column' }, 'flex-direction: column'],
|
|
96
|
+
[{ flexWrap: 'wrap' }, 'flex-wrap: wrap'],
|
|
97
|
+
[{ flexShrink: 5 }, 'flex-shrink: 5'],
|
|
98
|
+
[{ flexGrow: 1 }, 'flex-grow: 1'],
|
|
99
|
+
[{ alignItems: 'baseline' }, 'align-items: baseline'],
|
|
100
|
+
[{ justifyContent: 'space-between' }, 'justify-content: space-between'],
|
|
101
|
+
[{ bg: 'primary' }, 'background-color: hotpink'],
|
|
102
|
+
[{ border: 1 }, 'border: 1px solid black'],
|
|
103
|
+
[{ borderRadius: 2 }, 'border-radius: 4px'],
|
|
104
|
+
[{ boxShadow: 1 }, 'box-shadow: 3px 3px 5px 6px #ccc'],
|
|
105
|
+
[{ opacity: 1 }, 'opacity: 0.5'],
|
|
106
|
+
[{ overflow: 'hidden' }, 'overflow: hidden'],
|
|
107
|
+
[{ transition: 1 }, 'transition: 1s opacity'],
|
|
108
|
+
])('test style prop %o', (...args) => {
|
|
109
|
+
const props = args.shift();
|
|
110
|
+
|
|
111
|
+
render(
|
|
112
|
+
<ThemeProvider theme={theme}>
|
|
113
|
+
<Box {...props}>What's in the box!</Box>
|
|
114
|
+
</ThemeProvider>
|
|
115
|
+
);
|
|
116
|
+
|
|
117
|
+
const box = screen.getByText(`What's in the box!`);
|
|
118
|
+
args.forEach((style: any) => {
|
|
119
|
+
expect(box).toHaveStyle(style);
|
|
120
|
+
});
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
test('support variants', () => {
|
|
124
|
+
render(
|
|
125
|
+
<ThemeProvider theme={theme}>
|
|
126
|
+
<Box variant="variant">What's in the box!</Box>
|
|
127
|
+
</ThemeProvider>
|
|
128
|
+
);
|
|
129
|
+
|
|
130
|
+
const box = screen.getByText(`What's in the box!`);
|
|
131
|
+
expect(box).toHaveStyle('color: hotpink');
|
|
132
|
+
expect(box).toHaveStyle('padding: 4px');
|
|
133
|
+
});
|
package/src/Box/Box.tsx
ADDED
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
import React, { forwardRef } from 'react';
|
|
2
|
+
import { CSSObject, Element, ResponsiveStyleValue } from '@marigold/system';
|
|
3
|
+
import {
|
|
4
|
+
PolymorphicPropsWithRef,
|
|
5
|
+
PolymorphicComponentWithRef,
|
|
6
|
+
} from '@marigold/types';
|
|
7
|
+
|
|
8
|
+
export type BoxOwnProps = {
|
|
9
|
+
className?: string;
|
|
10
|
+
variant?: string | string[];
|
|
11
|
+
css?: CSSObject;
|
|
12
|
+
|
|
13
|
+
display?: ResponsiveStyleValue<string>;
|
|
14
|
+
|
|
15
|
+
height?: ResponsiveStyleValue<number | string>;
|
|
16
|
+
width?: ResponsiveStyleValue<number | string>;
|
|
17
|
+
minWidth?: ResponsiveStyleValue<number | string>;
|
|
18
|
+
maxWidth?: ResponsiveStyleValue<number | string>;
|
|
19
|
+
|
|
20
|
+
position?: ResponsiveStyleValue<string>;
|
|
21
|
+
top?: ResponsiveStyleValue<number | string>;
|
|
22
|
+
bottom?: ResponsiveStyleValue<number | string>;
|
|
23
|
+
right?: ResponsiveStyleValue<number | string>;
|
|
24
|
+
left?: ResponsiveStyleValue<number | string>;
|
|
25
|
+
zIndex?: ResponsiveStyleValue<number | string>;
|
|
26
|
+
|
|
27
|
+
p?: ResponsiveStyleValue<number | string>;
|
|
28
|
+
px?: ResponsiveStyleValue<number | string>;
|
|
29
|
+
py?: ResponsiveStyleValue<number | string>;
|
|
30
|
+
pt?: ResponsiveStyleValue<number | string>;
|
|
31
|
+
pb?: ResponsiveStyleValue<number | string>;
|
|
32
|
+
pl?: ResponsiveStyleValue<number | string>;
|
|
33
|
+
pr?: ResponsiveStyleValue<number | string>;
|
|
34
|
+
|
|
35
|
+
m?: ResponsiveStyleValue<number | string>;
|
|
36
|
+
mx?: ResponsiveStyleValue<number | string>;
|
|
37
|
+
my?: ResponsiveStyleValue<number | string>;
|
|
38
|
+
mt?: ResponsiveStyleValue<number | string>;
|
|
39
|
+
mb?: ResponsiveStyleValue<number | string>;
|
|
40
|
+
ml?: ResponsiveStyleValue<number | string>;
|
|
41
|
+
mr?: ResponsiveStyleValue<number | string>;
|
|
42
|
+
|
|
43
|
+
flexDirection?: ResponsiveStyleValue<string>;
|
|
44
|
+
flexWrap?: ResponsiveStyleValue<string>;
|
|
45
|
+
flexShrink?: ResponsiveStyleValue<number | string>;
|
|
46
|
+
flexGrow?: ResponsiveStyleValue<number | string>;
|
|
47
|
+
alignItems?: ResponsiveStyleValue<string>;
|
|
48
|
+
justifyContent?: ResponsiveStyleValue<string>;
|
|
49
|
+
|
|
50
|
+
bg?: ResponsiveStyleValue<number | string>;
|
|
51
|
+
border?: ResponsiveStyleValue<number | string>;
|
|
52
|
+
borderRadius?: ResponsiveStyleValue<number | string>;
|
|
53
|
+
boxShadow?: ResponsiveStyleValue<number | string>;
|
|
54
|
+
opacity?: ResponsiveStyleValue<number | string>;
|
|
55
|
+
overflow?: ResponsiveStyleValue<string>;
|
|
56
|
+
|
|
57
|
+
transition?: ResponsiveStyleValue<number | string>;
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
export type BoxProps = PolymorphicPropsWithRef<BoxOwnProps, 'div'>;
|
|
61
|
+
|
|
62
|
+
export const Box: PolymorphicComponentWithRef<BoxOwnProps, 'div'> = forwardRef(
|
|
63
|
+
(
|
|
64
|
+
{
|
|
65
|
+
variant,
|
|
66
|
+
as = 'div',
|
|
67
|
+
css,
|
|
68
|
+
children,
|
|
69
|
+
className,
|
|
70
|
+
display,
|
|
71
|
+
height,
|
|
72
|
+
width,
|
|
73
|
+
minWidth,
|
|
74
|
+
maxWidth,
|
|
75
|
+
position,
|
|
76
|
+
top,
|
|
77
|
+
bottom,
|
|
78
|
+
right,
|
|
79
|
+
left,
|
|
80
|
+
zIndex,
|
|
81
|
+
p,
|
|
82
|
+
px,
|
|
83
|
+
py,
|
|
84
|
+
pt,
|
|
85
|
+
pb,
|
|
86
|
+
pl,
|
|
87
|
+
pr,
|
|
88
|
+
m,
|
|
89
|
+
mx,
|
|
90
|
+
my,
|
|
91
|
+
mt,
|
|
92
|
+
mb,
|
|
93
|
+
ml,
|
|
94
|
+
mr,
|
|
95
|
+
flexDirection,
|
|
96
|
+
flexWrap,
|
|
97
|
+
flexShrink,
|
|
98
|
+
flexGrow,
|
|
99
|
+
alignItems,
|
|
100
|
+
justifyContent,
|
|
101
|
+
bg,
|
|
102
|
+
border,
|
|
103
|
+
borderRadius,
|
|
104
|
+
boxShadow,
|
|
105
|
+
opacity,
|
|
106
|
+
overflow,
|
|
107
|
+
transition,
|
|
108
|
+
...props
|
|
109
|
+
},
|
|
110
|
+
ref
|
|
111
|
+
) => (
|
|
112
|
+
<Element
|
|
113
|
+
as={as}
|
|
114
|
+
ref={ref}
|
|
115
|
+
variant={variant}
|
|
116
|
+
css={{
|
|
117
|
+
...{
|
|
118
|
+
display,
|
|
119
|
+
height,
|
|
120
|
+
width,
|
|
121
|
+
minWidth,
|
|
122
|
+
maxWidth,
|
|
123
|
+
position,
|
|
124
|
+
top,
|
|
125
|
+
bottom,
|
|
126
|
+
right,
|
|
127
|
+
left,
|
|
128
|
+
zIndex,
|
|
129
|
+
p,
|
|
130
|
+
px,
|
|
131
|
+
py,
|
|
132
|
+
pt,
|
|
133
|
+
pb,
|
|
134
|
+
pl,
|
|
135
|
+
pr,
|
|
136
|
+
m,
|
|
137
|
+
mx,
|
|
138
|
+
my,
|
|
139
|
+
mt,
|
|
140
|
+
mb,
|
|
141
|
+
ml,
|
|
142
|
+
mr,
|
|
143
|
+
flexDirection,
|
|
144
|
+
flexWrap,
|
|
145
|
+
flexShrink,
|
|
146
|
+
flexGrow,
|
|
147
|
+
alignItems,
|
|
148
|
+
justifyContent,
|
|
149
|
+
bg,
|
|
150
|
+
border,
|
|
151
|
+
borderRadius,
|
|
152
|
+
boxShadow,
|
|
153
|
+
opacity,
|
|
154
|
+
overflow,
|
|
155
|
+
transition,
|
|
156
|
+
},
|
|
157
|
+
...css,
|
|
158
|
+
}}
|
|
159
|
+
className={className}
|
|
160
|
+
{...props}
|
|
161
|
+
>
|
|
162
|
+
{children}
|
|
163
|
+
</Element>
|
|
164
|
+
)
|
|
165
|
+
);
|
package/src/Box/index.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './Box';
|
|
@@ -1,140 +1,64 @@
|
|
|
1
|
-
import { Meta, Story
|
|
1
|
+
import { ArgsTable, Canvas, Meta, Story } from '@storybook/addon-docs';
|
|
2
2
|
import { Facebook } from '@marigold/icons';
|
|
3
|
-
import { Button } from '
|
|
4
|
-
|
|
5
|
-
<Meta
|
|
3
|
+
import { Button } from './Button';
|
|
4
|
+
|
|
5
|
+
<Meta
|
|
6
|
+
title="Components/Button"
|
|
7
|
+
parameters={{
|
|
8
|
+
actions: {
|
|
9
|
+
handles: ['click'],
|
|
10
|
+
},
|
|
11
|
+
}}
|
|
12
|
+
argTypes={{
|
|
13
|
+
variant: {
|
|
14
|
+
control: {
|
|
15
|
+
type: 'select',
|
|
16
|
+
},
|
|
17
|
+
options: ['primary', 'secondary', 'ghost', 'text', 'menu', 'select'],
|
|
18
|
+
description: 'What the button looks like',
|
|
19
|
+
table: {
|
|
20
|
+
defaultValue: {
|
|
21
|
+
summary: 'primary',
|
|
22
|
+
},
|
|
23
|
+
},
|
|
24
|
+
},
|
|
25
|
+
size: {
|
|
26
|
+
control: {
|
|
27
|
+
type: 'select',
|
|
28
|
+
},
|
|
29
|
+
options: ['large', 'small'],
|
|
30
|
+
description: 'How big the button is rendered',
|
|
31
|
+
table: {
|
|
32
|
+
defaultValue: {
|
|
33
|
+
summary: 'large',
|
|
34
|
+
},
|
|
35
|
+
},
|
|
36
|
+
},
|
|
37
|
+
disabled: {
|
|
38
|
+
control: {
|
|
39
|
+
type: 'boolean',
|
|
40
|
+
},
|
|
41
|
+
options: [true, false],
|
|
42
|
+
description: 'Disable the button',
|
|
43
|
+
table: {
|
|
44
|
+
defaultValue: {
|
|
45
|
+
summary: 'false',
|
|
46
|
+
},
|
|
47
|
+
},
|
|
48
|
+
},
|
|
49
|
+
}}
|
|
50
|
+
/>
|
|
6
51
|
|
|
7
52
|
# Button
|
|
8
53
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
## Properties
|
|
16
|
-
|
|
17
|
-
| Property | Type | Default |
|
|
18
|
-
| :------------------- | :--------------------------------------------------------------------------------------------------- | :-------------- |
|
|
19
|
-
| `variant` (optional) | `primary.small`, `primary.large`, `secondary.small`, `secondary.large`, `ghost.small`, `ghost.large` | `primary.large` |
|
|
20
|
-
|
|
21
|
-
## Import
|
|
22
|
-
|
|
23
|
-
```tsx
|
|
24
|
-
import { Button } from '@marigold/components';
|
|
25
|
-
```
|
|
26
|
-
|
|
27
|
-
## Usage
|
|
28
|
-
|
|
29
|
-
### Large
|
|
30
|
-
|
|
31
|
-
<Preview>
|
|
32
|
-
<Story name="primary.large">
|
|
33
|
-
<Button variant="primary.large">Primary</Button>
|
|
34
|
-
</Story>
|
|
35
|
-
<Story name="secondary.large">
|
|
36
|
-
<Button variant="secondary.large">Secondary</Button>
|
|
37
|
-
</Story>
|
|
38
|
-
<Story name="ghost.large">
|
|
39
|
-
<Button variant="ghost.large">Ghost</Button>
|
|
40
|
-
</Story>
|
|
41
|
-
</Preview>
|
|
42
|
-
|
|
43
|
-
### Small
|
|
44
|
-
|
|
45
|
-
<Preview>
|
|
46
|
-
<Story name="primary.small">
|
|
47
|
-
<Button variant="primary.small">Primary</Button>
|
|
48
|
-
</Story>
|
|
49
|
-
<Story name="secondary.small">
|
|
50
|
-
<Button variant="secondary.small">Secondary</Button>
|
|
51
|
-
</Story>
|
|
52
|
-
<Story name="ghost.small">
|
|
53
|
-
<Button variant="ghost.small">Ghost</Button>
|
|
54
|
-
</Story>
|
|
55
|
-
</Preview>
|
|
56
|
-
|
|
57
|
-
### Disabled
|
|
58
|
-
|
|
59
|
-
<Preview>
|
|
60
|
-
<Story name="primary.large.disabled">
|
|
61
|
-
<Button variant="primary.large" disabled>
|
|
62
|
-
Primary Large Disabled
|
|
63
|
-
</Button>
|
|
64
|
-
</Story>
|
|
65
|
-
<Story name="secondary.large.disabled">
|
|
66
|
-
<Button variant="secondary.large" disabled>
|
|
67
|
-
Secondary Large Disabled
|
|
68
|
-
</Button>
|
|
69
|
-
</Story>
|
|
70
|
-
<Story name="ghost.large.disabled">
|
|
71
|
-
<Button variant="ghost.large" disabled>
|
|
72
|
-
Ghost Large Disabled
|
|
73
|
-
</Button>
|
|
74
|
-
</Story>
|
|
75
|
-
</Preview>
|
|
76
|
-
|
|
77
|
-
### Default with icon
|
|
78
|
-
|
|
79
|
-
<Preview>
|
|
80
|
-
<Story name="primary.large with default icon">
|
|
81
|
-
<Button variant="primary.large">
|
|
82
|
-
<Facebook /> Like me!
|
|
83
|
-
</Button>
|
|
84
|
-
</Story>
|
|
85
|
-
<Story name="primary.small with default icon">
|
|
86
|
-
<Button variant="primary.small">
|
|
87
|
-
<Facebook /> Like me!
|
|
88
|
-
</Button>
|
|
89
|
-
</Story>
|
|
90
|
-
<Story name="secondary.large with default icon">
|
|
91
|
-
<Button variant="secondary.large">
|
|
92
|
-
<Facebook /> Like me!
|
|
93
|
-
</Button>
|
|
94
|
-
</Story>
|
|
95
|
-
<Story name="secondary.small with default icon">
|
|
96
|
-
<Button variant="secondary.small">
|
|
97
|
-
<Facebook /> Like me!
|
|
98
|
-
</Button>
|
|
99
|
-
</Story>
|
|
100
|
-
<Story name="ghost.large with default icon">
|
|
101
|
-
<Button variant="ghost.large">
|
|
102
|
-
<Facebook /> Like me!
|
|
103
|
-
</Button>
|
|
104
|
-
</Story>
|
|
105
|
-
<Story name="ghost.small with default icon">
|
|
106
|
-
<Button variant="ghost.small">
|
|
107
|
-
<Facebook /> Like me!
|
|
108
|
-
</Button>
|
|
109
|
-
</Story>
|
|
110
|
-
</Preview>
|
|
111
|
-
|
|
112
|
-
### Large with large icon
|
|
113
|
-
|
|
114
|
-
<Preview>
|
|
115
|
-
<Story name="primary.large with large icon">
|
|
116
|
-
<Button variant="primary.large">
|
|
117
|
-
<Facebook size={48} /> Like me!
|
|
118
|
-
</Button>
|
|
119
|
-
</Story>
|
|
120
|
-
</Preview>
|
|
121
|
-
|
|
122
|
-
### Small with small icon
|
|
123
|
-
|
|
124
|
-
<Preview>
|
|
125
|
-
<Story name="primary.small with small icon">
|
|
126
|
-
<Button variant="primary.small">
|
|
127
|
-
<Facebook size={20} /> Like me!
|
|
128
|
-
</Button>
|
|
129
|
-
</Story>
|
|
130
|
-
</Preview>
|
|
54
|
+
export const Template = args => (
|
|
55
|
+
<Button {...args}>
|
|
56
|
+
<Facebook /> Like me
|
|
57
|
+
</Button>
|
|
58
|
+
);
|
|
131
59
|
|
|
132
|
-
|
|
60
|
+
<Canvas>
|
|
61
|
+
<Story name="Default">{Template.bind({})}</Story>
|
|
62
|
+
</Canvas>
|
|
133
63
|
|
|
134
|
-
<
|
|
135
|
-
<Story name="with color">
|
|
136
|
-
<Button variant="primary.small">
|
|
137
|
-
<Facebook fill="black" /> Like me!
|
|
138
|
-
</Button>
|
|
139
|
-
</Story>
|
|
140
|
-
</Preview>
|
|
64
|
+
<ArgsTable story="Default" />
|
|
@@ -1,51 +1,75 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { render, screen } from '@testing-library/react';
|
|
3
|
-
import {
|
|
3
|
+
import { ThemeProvider } from '@marigold/system';
|
|
4
4
|
import { Button } from './Button';
|
|
5
5
|
import { Facebook } from '@marigold/icons';
|
|
6
6
|
|
|
7
7
|
const theme = {
|
|
8
8
|
button: {
|
|
9
|
+
large: {
|
|
10
|
+
p: '16px',
|
|
11
|
+
},
|
|
12
|
+
small: {
|
|
13
|
+
p: '16px',
|
|
14
|
+
},
|
|
9
15
|
primary: {
|
|
10
|
-
|
|
11
|
-
fontFamily: 'Inter',
|
|
12
|
-
},
|
|
16
|
+
fontFamily: 'Inter',
|
|
13
17
|
},
|
|
14
18
|
secondary: {
|
|
15
|
-
|
|
16
|
-
fontFamily: 'Arial',
|
|
17
|
-
},
|
|
19
|
+
fontFamily: 'Arial',
|
|
18
20
|
},
|
|
19
21
|
},
|
|
20
22
|
};
|
|
21
23
|
|
|
22
|
-
test('supports default variant
|
|
24
|
+
test('supports default variant', () => {
|
|
23
25
|
render(
|
|
24
|
-
<
|
|
26
|
+
<ThemeProvider theme={theme}>
|
|
25
27
|
<Button>button</Button>
|
|
26
|
-
</
|
|
28
|
+
</ThemeProvider>
|
|
27
29
|
);
|
|
28
30
|
const button = screen.getByText(/button/);
|
|
29
31
|
|
|
30
32
|
expect(button.parentElement).toHaveStyle(`font-family: Inter`);
|
|
31
33
|
});
|
|
32
34
|
|
|
35
|
+
test('supports default size', () => {
|
|
36
|
+
render(
|
|
37
|
+
<ThemeProvider theme={theme}>
|
|
38
|
+
<Button>button</Button>
|
|
39
|
+
</ThemeProvider>
|
|
40
|
+
);
|
|
41
|
+
const button = screen.getByText(/button/);
|
|
42
|
+
|
|
43
|
+
expect(button.parentElement).toHaveStyle(`padding: 16px`);
|
|
44
|
+
});
|
|
45
|
+
|
|
33
46
|
test('accepts other variant than default', () => {
|
|
34
47
|
render(
|
|
35
|
-
<
|
|
36
|
-
<Button variant="secondary
|
|
37
|
-
</
|
|
48
|
+
<ThemeProvider theme={theme}>
|
|
49
|
+
<Button variant="secondary">button</Button>
|
|
50
|
+
</ThemeProvider>
|
|
38
51
|
);
|
|
39
52
|
const button = screen.getByText(/button/);
|
|
40
53
|
|
|
41
54
|
expect(button.parentElement).toHaveStyle(`font-family: Arial`);
|
|
42
55
|
});
|
|
43
56
|
|
|
57
|
+
test('accepts other size than default', () => {
|
|
58
|
+
render(
|
|
59
|
+
<ThemeProvider theme={theme}>
|
|
60
|
+
<Button size="small">button</Button>
|
|
61
|
+
</ThemeProvider>
|
|
62
|
+
);
|
|
63
|
+
const button = screen.getByText(/button/);
|
|
64
|
+
|
|
65
|
+
expect(button.parentElement).toHaveStyle(`padding: 16px`);
|
|
66
|
+
});
|
|
67
|
+
|
|
44
68
|
test('renders <button> element', () => {
|
|
45
69
|
render(
|
|
46
|
-
<
|
|
70
|
+
<ThemeProvider theme={theme}>
|
|
47
71
|
<Button>button</Button>
|
|
48
|
-
</
|
|
72
|
+
</ThemeProvider>
|
|
49
73
|
);
|
|
50
74
|
const button = screen.getByText(/button/);
|
|
51
75
|
|
|
@@ -53,25 +77,30 @@ test('renders <button> element', () => {
|
|
|
53
77
|
expect(button instanceof HTMLSpanElement).toBeTruthy();
|
|
54
78
|
});
|
|
55
79
|
|
|
56
|
-
test('
|
|
80
|
+
test('accepts other button components', () => {
|
|
81
|
+
const CustomButton = React.forwardRef<
|
|
82
|
+
HTMLSpanElement,
|
|
83
|
+
{ children?: React.ReactNode }
|
|
84
|
+
>(() => <span>I am a Button!</span>);
|
|
85
|
+
|
|
57
86
|
render(
|
|
58
|
-
<
|
|
59
|
-
<Button
|
|
60
|
-
</
|
|
87
|
+
<ThemeProvider theme={theme}>
|
|
88
|
+
<Button as={CustomButton}>Button</Button>
|
|
89
|
+
</ThemeProvider>
|
|
61
90
|
);
|
|
62
|
-
const button = screen.getByText(/button/);
|
|
63
91
|
|
|
64
|
-
|
|
92
|
+
const button = screen.getByText('I am a Button!');
|
|
93
|
+
expect(button).toBeTruthy();
|
|
65
94
|
});
|
|
66
95
|
|
|
67
96
|
test('add icon in button works as expected', () => {
|
|
68
97
|
render(
|
|
69
|
-
<
|
|
98
|
+
<ThemeProvider theme={theme}>
|
|
70
99
|
<Button>
|
|
71
100
|
<Facebook fill="red" size={30} title="facebook" />
|
|
72
101
|
iconbutton
|
|
73
102
|
</Button>
|
|
74
|
-
</
|
|
103
|
+
</ThemeProvider>
|
|
75
104
|
);
|
|
76
105
|
const button = screen.getByText(/iconbutton/);
|
|
77
106
|
const icon = screen.getByTitle(/facebook/);
|
|
@@ -82,3 +111,16 @@ test('add icon in button works as expected', () => {
|
|
|
82
111
|
expect(icon.getAttribute('fill')).toEqual('red');
|
|
83
112
|
expect(icon.getAttribute('width')).toEqual('30');
|
|
84
113
|
});
|
|
114
|
+
|
|
115
|
+
test('accepts custom styles prop className', () => {
|
|
116
|
+
render(
|
|
117
|
+
<ThemeProvider theme={theme}>
|
|
118
|
+
<Button className="custom-class-name" title="button">
|
|
119
|
+
click
|
|
120
|
+
</Button>
|
|
121
|
+
</ThemeProvider>
|
|
122
|
+
);
|
|
123
|
+
const button = screen.getByTitle(/button/);
|
|
124
|
+
|
|
125
|
+
expect(button.className).toMatch('custom-class-name');
|
|
126
|
+
});
|