@marigold/components 0.2.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (195) hide show
  1. package/CHANGELOG.md +294 -0
  2. package/dist/ActionGroup/ActionGroup.d.ts +1 -2
  3. package/dist/ActionGroup/ActionGroup.stories.d.ts +5 -0
  4. package/dist/Alert/Alert.d.ts +10 -13
  5. package/dist/Alert/Alert.stories.d.ts +5 -0
  6. package/dist/Badge/Badge.d.ts +5 -0
  7. package/dist/Badge/Badge.stories.d.ts +5 -0
  8. package/dist/Box.d.ts +2 -0
  9. package/dist/Button/Button.d.ts +5 -0
  10. package/dist/Button/Button.stories.d.ts +5 -0
  11. package/dist/Card/Card.d.ts +5 -0
  12. package/dist/Card/Card.stories.d.ts +5 -0
  13. package/dist/Checkbox/Checkbox.d.ts +10 -5
  14. package/dist/Checkbox/Checkbox.stories.d.ts +5 -0
  15. package/dist/Checkbox/CheckboxIcons.d.ts +9 -9
  16. package/dist/Column/Column.stories.d.ts +5 -0
  17. package/dist/Columns/Columns.d.ts +2 -2
  18. package/dist/Columns/Columns.stories.d.ts +5 -0
  19. package/dist/Container/Container.stories.d.ts +5 -0
  20. package/dist/Dialog/Dialog.d.ts +5 -2
  21. package/dist/Dialog/Dialog.stories.d.ts +5 -0
  22. package/dist/Dialog/ModalDialog.d.ts +4 -1
  23. package/dist/Divider/Divider.d.ts +5 -0
  24. package/dist/Divider/Divider.stories.d.ts +5 -0
  25. package/dist/Field/Field.d.ts +2 -0
  26. package/dist/Field/Field.stories.d.ts +5 -0
  27. package/dist/Image/Image.d.ts +5 -0
  28. package/dist/Image/Image.stories.d.ts +5 -0
  29. package/dist/Inline/Inline.d.ts +7 -0
  30. package/dist/Inline/Inline.stories.d.ts +5 -0
  31. package/dist/Inline/index.d.ts +1 -0
  32. package/dist/Input/Input.d.ts +5 -0
  33. package/dist/Input/Input.stories.d.ts +5 -0
  34. package/dist/Label/Label.d.ts +12 -1
  35. package/dist/Label/Label.stories.d.ts +5 -0
  36. package/dist/Link/Link.d.ts +4 -1
  37. package/dist/Link/Link.stories.d.ts +5 -0
  38. package/dist/Menu/Menu.d.ts +3 -0
  39. package/dist/Menu/Menu.stories.d.ts +5 -0
  40. package/dist/MenuItem/MenuItem.d.ts +5 -0
  41. package/dist/MenuItem/MenuItem.stories.d.ts +5 -0
  42. package/dist/Message/Message.d.ts +5 -0
  43. package/dist/Message/Message.stories.d.ts +5 -0
  44. package/dist/Provider/MarigoldProvider.d.ts +11 -3
  45. package/dist/Provider/index.d.ts +1 -1
  46. package/dist/Radio/Radio.d.ts +6 -0
  47. package/dist/Radio/RadioIcons.d.ts +1 -0
  48. package/dist/Select/ListBox.d.ts +1 -0
  49. package/dist/Select/ListBoxSection.d.ts +1 -0
  50. package/dist/Select/Option.d.ts +1 -0
  51. package/dist/Select/Select.d.ts +15 -1
  52. package/dist/Select/Select.stories.d.ts +5 -0
  53. package/dist/Slider/Slider.d.ts +5 -0
  54. package/dist/Slider/Slider.stories.d.ts +5 -0
  55. package/dist/Stack/Stack.stories.d.ts +5 -0
  56. package/dist/Text/Text.d.ts +5 -0
  57. package/dist/Text/Text.stories.d.ts +5 -0
  58. package/dist/Textarea/Textarea.d.ts +5 -0
  59. package/dist/Textarea/Textarea.stories.d.ts +5 -0
  60. package/dist/ValidationMessage/ValidationMessage.d.ts +5 -0
  61. package/dist/ValidationMessage/ValidationMessage.stories.d.ts +5 -0
  62. package/dist/VisuallyHidden/VisuallyHidden.d.ts +1 -0
  63. package/dist/VisuallyHidden/VisuallyHidden.stories.d.ts +5 -0
  64. package/dist/VisuallyHidden/index.d.ts +1 -0
  65. package/dist/components.cjs.development.js +480 -496
  66. package/dist/components.cjs.development.js.map +1 -1
  67. package/dist/components.cjs.production.min.js +1 -1
  68. package/dist/components.cjs.production.min.js.map +1 -1
  69. package/dist/components.esm.js +415 -441
  70. package/dist/components.esm.js.map +1 -1
  71. package/dist/index.d.ts +2 -2
  72. package/dist/theme.d.ts +23 -48
  73. package/package.json +4 -1
  74. package/src/ActionGroup/ActionGroup.stories.tsx +47 -0
  75. package/src/ActionGroup/ActionGroup.test.tsx +36 -36
  76. package/src/ActionGroup/ActionGroup.tsx +17 -28
  77. package/src/Alert/Alert.stories.tsx +32 -0
  78. package/src/Alert/Alert.test.tsx +4 -1
  79. package/src/Alert/Alert.tsx +18 -3
  80. package/src/Badge/Badge.stories.tsx +38 -0
  81. package/src/Badge/Badge.test.tsx +5 -1
  82. package/src/Badge/Badge.tsx +13 -1
  83. package/src/Box.ts +2 -0
  84. package/src/Button/{Button.stories.mdx → Button.stories.tsx} +10 -17
  85. package/src/Button/Button.test.tsx +34 -11
  86. package/src/Button/Button.tsx +17 -3
  87. package/src/Card/{Card.stories.mdx → Card.stories.tsx} +9 -17
  88. package/src/Card/Card.test.tsx +8 -3
  89. package/src/Card/Card.tsx +13 -1
  90. package/src/Checkbox/Checkbox.stories.mdx +11 -0
  91. package/src/Checkbox/Checkbox.stories.tsx +78 -0
  92. package/src/Checkbox/Checkbox.test.tsx +77 -8
  93. package/src/Checkbox/Checkbox.tsx +70 -90
  94. package/src/Checkbox/CheckboxIcons.tsx +51 -41
  95. package/src/Column/Column.stories.tsx +33 -0
  96. package/src/Columns/Columns.stories.tsx +75 -0
  97. package/src/Columns/Columns.test.tsx +34 -23
  98. package/src/Columns/Columns.tsx +30 -30
  99. package/src/Container/Container.stories.tsx +14 -0
  100. package/src/Dialog/{Dialog.stories.mdx → Dialog.stories.tsx} +33 -18
  101. package/src/Dialog/Dialog.test.tsx +91 -20
  102. package/src/Dialog/Dialog.tsx +63 -17
  103. package/src/Dialog/ModalDialog.tsx +33 -4
  104. package/src/Divider/{Divider.stories.mdx → Divider.stories.tsx} +10 -17
  105. package/src/Divider/Divider.test.tsx +13 -5
  106. package/src/Divider/Divider.tsx +12 -0
  107. package/src/Field/{Field.stories.mdx → Field.stories.tsx} +33 -20
  108. package/src/Field/Field.test.tsx +55 -5
  109. package/src/Field/Field.tsx +10 -8
  110. package/src/Image/Image.stories.tsx +34 -0
  111. package/src/Image/Image.test.tsx +4 -1
  112. package/src/Image/Image.tsx +13 -1
  113. package/src/Inline/Inline.stories.tsx +39 -0
  114. package/src/Inline/Inline.test.tsx +99 -0
  115. package/src/Inline/Inline.tsx +38 -0
  116. package/src/Inline/index.ts +1 -0
  117. package/src/Input/{Input.stories.mdx → Input.stories.tsx} +10 -17
  118. package/src/Input/Input.test.tsx +7 -3
  119. package/src/Input/Input.tsx +13 -1
  120. package/src/Label/{Label.stories.mdx → Label.stories.tsx} +10 -21
  121. package/src/Label/Label.test.tsx +25 -4
  122. package/src/Label/Label.tsx +42 -9
  123. package/src/Link/Link.stories.tsx +35 -0
  124. package/src/Link/Link.test.tsx +6 -2
  125. package/src/Link/Link.tsx +10 -0
  126. package/src/Menu/{Menu.stories.mdx → Menu.stories.tsx} +13 -32
  127. package/src/Menu/Menu.test.tsx +7 -2
  128. package/src/Menu/Menu.tsx +10 -0
  129. package/src/MenuItem/MenuItem.stories.tsx +30 -0
  130. package/src/MenuItem/MenuItem.test.tsx +7 -2
  131. package/src/MenuItem/MenuItem.tsx +12 -0
  132. package/src/Message/Message.stories.tsx +30 -0
  133. package/src/Message/Message.test.tsx +4 -1
  134. package/src/Message/Message.tsx +17 -5
  135. package/src/Provider/MarigoldProvider.test.tsx +65 -55
  136. package/src/Provider/MarigoldProvider.tsx +37 -19
  137. package/src/Provider/index.ts +2 -1
  138. package/src/Radio/Radio.stories.mdx +11 -0
  139. package/src/Radio/Radio.test.tsx +36 -2
  140. package/src/Radio/Radio.tsx +13 -2
  141. package/src/Radio/RadioIcons.tsx +1 -1
  142. package/src/Select/ListBox.tsx +1 -0
  143. package/src/Select/{Select.stories.mdx → Select.stories.tsx} +23 -20
  144. package/src/Select/Select.test.tsx +39 -1
  145. package/src/Select/Select.tsx +24 -13
  146. package/src/Slider/Slider.stories.tsx +24 -0
  147. package/src/Slider/Slider.test.tsx +10 -6
  148. package/src/Slider/Slider.tsx +25 -13
  149. package/src/Stack/Stack.stories.tsx +57 -0
  150. package/src/Stack/Stack.test.tsx +16 -7
  151. package/src/Text/{Text.stories.mdx → Text.stories.tsx} +20 -19
  152. package/src/Text/Text.test.tsx +2 -2
  153. package/src/Text/Text.tsx +12 -0
  154. package/src/Textarea/{Textarea.stories.mdx → Textarea.stories.tsx} +14 -24
  155. package/src/Textarea/Textarea.test.tsx +7 -3
  156. package/src/Textarea/Textarea.tsx +13 -1
  157. package/src/ValidationMessage/{ValidationMessage.stories.mdx → ValidationMessage.stories.tsx} +8 -17
  158. package/src/ValidationMessage/ValidationMessage.test.tsx +7 -2
  159. package/src/ValidationMessage/ValidationMessage.tsx +12 -0
  160. package/src/VisuallyHidden/VisuallyHidden.stories.tsx +19 -0
  161. package/src/VisuallyHidden/VisuallyHidden.test.tsx +10 -0
  162. package/src/VisuallyHidden/VisuallyHidden.tsx +1 -0
  163. package/src/VisuallyHidden/index.ts +1 -0
  164. package/src/index.ts +2 -2
  165. package/src/theme.ts +49 -48
  166. package/dist/Box/Box.d.ts +0 -47
  167. package/dist/Box/index.d.ts +0 -1
  168. package/dist/Heading/Heading.d.ts +0 -7
  169. package/dist/Heading/index.d.ts +0 -1
  170. package/dist/Hidden/Hidden.d.ts +0 -5
  171. package/dist/Hidden/index.d.ts +0 -1
  172. package/src/ActionGroup/ActionGroup.stories.mdx +0 -62
  173. package/src/Alert/Alert.stories.mdx +0 -35
  174. package/src/Badge/Badge.stories.mdx +0 -57
  175. package/src/Box/Box.stories.mdx +0 -334
  176. package/src/Box/Box.test.tsx +0 -133
  177. package/src/Box/Box.tsx +0 -165
  178. package/src/Box/index.ts +0 -1
  179. package/src/Column/Column.stories.mdx +0 -49
  180. package/src/Columns/Columns.stories.mdx +0 -65
  181. package/src/Container/Container.stories.mdx +0 -19
  182. package/src/Heading/Heading.stories.mdx +0 -39
  183. package/src/Heading/Heading.test.tsx +0 -77
  184. package/src/Heading/Heading.tsx +0 -19
  185. package/src/Heading/index.ts +0 -1
  186. package/src/Hidden/Hidden.stories.mdx +0 -39
  187. package/src/Hidden/Hidden.test.tsx +0 -24
  188. package/src/Hidden/Hidden.tsx +0 -16
  189. package/src/Hidden/index.ts +0 -1
  190. package/src/Image/Image.stories.mdx +0 -36
  191. package/src/Link/Link.stories.mdx +0 -45
  192. package/src/MenuItem/MenuItem.stories.mdx +0 -37
  193. package/src/Message/Message.stories.mdx +0 -44
  194. package/src/Slider/Slider.stories.mdx +0 -31
  195. package/src/Stack/Stack.stories.mdx +0 -51
@@ -5,36 +5,32 @@ import { ActionGroup } from './ActionGroup';
5
5
  import { Button } from '../Button';
6
6
 
7
7
  const theme = {
8
- actionGroup: {
9
- default: {
10
- p: '8px',
11
- },
12
- custom: {
13
- p: '12px',
14
- },
8
+ space: {
9
+ none: 0,
10
+ small: 2,
15
11
  },
16
12
  };
17
13
 
18
- test('supports default variant and themeSection', () => {
19
- render(
20
- <ThemeProvider theme={theme}>
21
- <ActionGroup title="actionGroup" />
22
- </ThemeProvider>
23
- );
24
- const actionGroup = screen.getByTitle(/actionGroup/);
14
+ const getLeftPadding = (element: HTMLElement) =>
15
+ getComputedStyle(element).getPropertyValue('padding-left');
25
16
 
26
- expect(actionGroup).toHaveStyle(`padding: 8px;`);
27
- });
17
+ const getTopPadding = (element: HTMLElement) =>
18
+ getComputedStyle(element).getPropertyValue('padding-top');
28
19
 
29
- test('supports other variant than default', () => {
20
+ test('default space is "none"', () => {
30
21
  render(
31
22
  <ThemeProvider theme={theme}>
32
- <ActionGroup variant="custom" title="actionGroup" />
23
+ <ActionGroup title="actionGroup">
24
+ <Button title="Button1">Button1</Button>
25
+ <Button title="Button2">Button2</Button>
26
+ </ActionGroup>
33
27
  </ThemeProvider>
34
28
  );
35
- const actionGroup = screen.getByTitle(/actionGroup/);
29
+ const first = screen.getByTitle(/Button1/).parentElement!;
30
+ const second = screen.getByTitle(/Button2/).parentElement!;
36
31
 
37
- expect(actionGroup).toHaveStyle(`padding: 12px;`);
32
+ expect(getLeftPadding(first)).toEqual('');
33
+ expect(second).toHaveStyle(`padding-left: 0px`);
38
34
  });
39
35
 
40
36
  test('supports space prop', () => {
@@ -46,38 +42,42 @@ test('supports space prop', () => {
46
42
  </ActionGroup>
47
43
  </ThemeProvider>
48
44
  );
49
- const button1 = screen.getByTitle(/Button1/);
50
- const button2 = screen.getByTitle(/Button2/);
45
+ const first = screen.getByTitle(/Button1/).parentElement!;
46
+ const second = screen.getByTitle(/Button2/).parentElement;
51
47
 
52
- expect(button1.parentElement instanceof HTMLSpanElement).toBeTruthy();
53
- expect(button1.parentElement).toHaveStyle(`margin-right: 8px;`);
54
- expect(button2.parentElement).not.toHaveStyle(`margin-right: 8px;`);
48
+ expect(getLeftPadding(first)).toEqual('');
49
+ expect(second).toHaveStyle(`padding-left: 8px`);
55
50
  });
56
51
 
57
- test('supports verticalAlignment prop', () => {
52
+ test('accepts and uses spacing from theme', () => {
58
53
  render(
59
54
  <ThemeProvider theme={theme}>
60
- <ActionGroup title="actionGroup" space="8px" verticalAlignment>
55
+ <ActionGroup title="actionGroup" space="small">
61
56
  <Button title="Button1">Button1</Button>
62
57
  <Button title="Button2">Button2</Button>
63
58
  </ActionGroup>
64
59
  </ThemeProvider>
65
60
  );
66
- const button1 = screen.getByTitle(/Button1/);
67
- const button2 = screen.getByTitle(/Button2/);
61
+ const first = screen.getByTitle(/Button1/).parentElement!;
62
+ const second = screen.getByTitle(/Button2/).parentElement;
68
63
 
69
- expect(button1.parentElement instanceof HTMLDivElement).toBeTruthy();
70
- expect(button1.parentElement).toHaveStyle(`margin-bottom: 8px;`);
71
- expect(button2.parentElement).not.toHaveStyle(`margin-bottom: 8px;`);
64
+ expect(getLeftPadding(first)).toEqual('');
65
+ expect(second).toHaveStyle(`padding-left: 2px`);
72
66
  });
73
67
 
74
- test('renders correct HTML element', () => {
68
+ test('supports verticalAlignment prop', () => {
75
69
  render(
76
70
  <ThemeProvider theme={theme}>
77
- <ActionGroup title="actionGroup" />
71
+ <ActionGroup title="actionGroup" space="small" verticalAlignment>
72
+ <Button title="Button1">Button1</Button>
73
+ <Button title="Button2">Button2</Button>
74
+ </ActionGroup>
78
75
  </ThemeProvider>
79
76
  );
80
- const actionGroup = screen.getByTitle(/actionGroup/);
81
77
 
82
- expect(actionGroup instanceof HTMLDivElement).toBeTruthy();
78
+ const button1 = screen.getByText(/Button1/);
79
+ const button2 = screen.getByText(/Button2/);
80
+
81
+ expect(getTopPadding(button1.parentElement!)).toEqual('');
82
+ expect(button2.parentElement).toHaveStyle(`padding-top: 2px`);
83
83
  });
@@ -1,43 +1,32 @@
1
- import React, { Children } from 'react';
2
- import flattenChildren from 'react-keyed-flatten-children';
1
+ import React from 'react';
3
2
 
4
3
  import { ResponsiveStyleValue } from '@marigold/system';
5
4
  import { ComponentProps } from '@marigold/types';
6
5
 
7
- import { Box } from '../Box';
6
+ import { Inline } from '../Inline';
7
+ import { Stack } from '../Stack';
8
8
 
9
+ // Props
10
+ // ---------------
9
11
  export type ActionGroupProps = {
10
- variant?: string;
11
- space?: ResponsiveStyleValue<number | string>;
12
+ space?: ResponsiveStyleValue<string>;
12
13
  verticalAlignment?: boolean;
13
14
  } & ComponentProps<'div'>;
14
15
 
16
+ // Component
17
+ // ---------------
15
18
  export const ActionGroup: React.FC<ActionGroupProps> = ({
16
- variant = 'default',
17
19
  space = 'none',
18
20
  verticalAlignment = false,
19
21
  children,
20
- className,
21
22
  ...props
22
- }) => {
23
- const childStyle = verticalAlignment
24
- ? { marginBottom: space }
25
- : { marginRight: space };
26
- return (
27
- <Box variant={`actionGroup.${variant}`} className={className} {...props}>
28
- {Children.map(
29
- flattenChildren(children),
30
- (child, i) =>
31
- child !== null &&
32
- child !== undefined && (
33
- <Box
34
- as={verticalAlignment ? 'div' : 'span'}
35
- css={i < Children.count(children) - 1 ? childStyle : undefined}
36
- >
37
- {child}
38
- </Box>
39
- )
40
- )}
41
- </Box>
23
+ }) =>
24
+ verticalAlignment ? (
25
+ <Stack space={space} {...props}>
26
+ {children}
27
+ </Stack>
28
+ ) : (
29
+ <Inline space={space} {...props}>
30
+ {children}
31
+ </Inline>
42
32
  );
43
- };
@@ -0,0 +1,32 @@
1
+ import React from 'react';
2
+ import type { Meta, ComponentStory } from '@storybook/react';
3
+
4
+ import { Alert } from './Alert';
5
+ import { Text } from '../Text';
6
+
7
+ export default {
8
+ title: 'Components/Alert',
9
+ argTypes: {
10
+ variant: {
11
+ description: 'usage types',
12
+ control: {
13
+ type: 'select',
14
+ },
15
+ options: ['success', 'warning', 'error'],
16
+ defaultValue: 'success',
17
+ },
18
+ children: {
19
+ description: 'text to display',
20
+ control: {
21
+ type: 'text',
22
+ },
23
+ defaultValue: 'Put some text here!',
24
+ },
25
+ },
26
+ } as Meta;
27
+
28
+ export const Basic: ComponentStory<typeof Alert> = ({ children, ...args }) => (
29
+ <Alert {...args}>
30
+ <Text>{children}</Text>
31
+ </Alert>
32
+ );
@@ -4,7 +4,10 @@ import { ThemeProvider } from '@marigold/system';
4
4
  import { Alert } from './Alert';
5
5
 
6
6
  const theme = {
7
- alerts: {
7
+ colors: {
8
+ primary: '#000',
9
+ },
10
+ alert: {
8
11
  success: {
9
12
  alignItems: 'center',
10
13
  },
@@ -1,6 +1,7 @@
1
1
  import React from 'react';
2
- import { ComponentProps } from '@marigold/types';
3
2
  import { Exclamation, Check, Notification } from '@marigold/icons';
3
+ import { type ComponentProps } from '@marigold/types';
4
+
4
5
  import { Box } from '../Box';
5
6
 
6
7
  const ICON_MAP = {
@@ -9,10 +10,24 @@ const ICON_MAP = {
9
10
  error: Exclamation,
10
11
  } as const;
11
12
 
13
+ export type AlertVariants = keyof typeof ICON_MAP;
14
+
15
+ // Theme Extension
16
+ // ---------------
17
+ export interface AlertThemeExtension<Value> {
18
+ alert?: {
19
+ [key in AlertVariants]?: Value;
20
+ };
21
+ }
22
+
23
+ // Props
24
+ // ---------------
12
25
  export type AlertProps = {
13
- variant?: keyof typeof ICON_MAP;
26
+ variant?: AlertVariants;
14
27
  } & ComponentProps<'div'>;
15
28
 
29
+ // Component
30
+ // ---------------
16
31
  export const Alert: React.FC<AlertProps> = ({
17
32
  variant = 'success',
18
33
  children,
@@ -21,7 +36,7 @@ export const Alert: React.FC<AlertProps> = ({
21
36
  const Icon = ICON_MAP[variant];
22
37
 
23
38
  return (
24
- <Box {...props} display="flex" variant={`alerts.${variant}`}>
39
+ <Box {...props} display="flex" variant={`alert.${variant}`}>
25
40
  <Box
26
41
  display="inline-block"
27
42
  alignItems="center"
@@ -0,0 +1,38 @@
1
+ import React from 'react';
2
+ import type { Meta, ComponentStory } from '@storybook/react';
3
+
4
+ import { Badge } from './Badge';
5
+ import { Check } from '@marigold/icons';
6
+
7
+ export default {
8
+ title: 'Components/Badge',
9
+ argTypes: {
10
+ variant: {
11
+ description: 'badge variant',
12
+ control: {
13
+ type: 'text',
14
+ },
15
+ defaultValue: '',
16
+ },
17
+ bgColor: {
18
+ description: 'background color',
19
+ control: {
20
+ type: 'text',
21
+ },
22
+ defaultValue: 'primary',
23
+ },
24
+ borderColor: {
25
+ description: 'outline color',
26
+ control: {
27
+ type: 'text',
28
+ },
29
+ defaultValue: 'transparent',
30
+ },
31
+ },
32
+ } as Meta;
33
+
34
+ export const Basic: ComponentStory<typeof Badge> = args => (
35
+ <Badge {...args}>
36
+ <Check /> Check
37
+ </Badge>
38
+ );
@@ -4,8 +4,12 @@ import { ThemeProvider } from '@marigold/system';
4
4
  import { Badge } from './Badge';
5
5
 
6
6
  const theme = {
7
+ radii: {
8
+ none: 0,
9
+ larger: 8,
10
+ },
7
11
  badge: {
8
- default: {
12
+ __default: {
9
13
  borderRadius: '8px',
10
14
  },
11
15
  fatBadge: {
@@ -2,14 +2,26 @@ import React from 'react';
2
2
  import { ComponentProps } from '@marigold/types';
3
3
  import { Box } from '../Box';
4
4
 
5
+ // Theme Extension
6
+ // ---------------
7
+ export interface BadgeThemeExtension<Value> {
8
+ badge?: {
9
+ [key: string]: Value;
10
+ };
11
+ }
12
+
13
+ // Props
14
+ // ---------------
5
15
  export type BadgeProps = {
6
16
  variant?: string;
7
17
  bgColor?: string;
8
18
  borderColor?: string;
9
19
  } & ComponentProps<'div'>;
10
20
 
21
+ // Component
22
+ // ---------------
11
23
  export const Badge: React.FC<BadgeProps> = ({
12
- variant = 'default',
24
+ variant = '',
13
25
  bgColor = 'transparent',
14
26
  borderColor = 'transparent',
15
27
  children,
package/src/Box.ts ADDED
@@ -0,0 +1,2 @@
1
+ export { Box } from '@marigold/system';
2
+ export type { BoxProps, BoxOwnProps, StyleProps } from '@marigold/system';
@@ -1,15 +1,16 @@
1
- import { ArgsTable, Canvas, Meta, Story } from '@storybook/addon-docs';
1
+ import React from 'react';
2
+ import type { Meta, ComponentStory } from '@storybook/react';
2
3
  import { Facebook } from '@marigold/icons';
3
4
  import { Button } from './Button';
4
5
 
5
- <Meta
6
- title="Components/Button"
7
- parameters={{
6
+ export default {
7
+ title: 'Components/Button',
8
+ parameters: {
8
9
  actions: {
9
10
  handles: ['click'],
10
11
  },
11
- }}
12
- argTypes={{
12
+ },
13
+ argTypes: {
13
14
  variant: {
14
15
  control: {
15
16
  type: 'select',
@@ -46,19 +47,11 @@ import { Button } from './Button';
46
47
  },
47
48
  },
48
49
  },
49
- }}
50
- />
50
+ },
51
+ } as Meta;
51
52
 
52
- # Button
53
-
54
- export const Template = args => (
53
+ export const Basic: ComponentStory<typeof Button> = args => (
55
54
  <Button {...args}>
56
55
  <Facebook /> Like me
57
56
  </Button>
58
57
  );
59
-
60
- <Canvas>
61
- <Story name="Default">{Template.bind({})}</Story>
62
- </Canvas>
63
-
64
- <ArgsTable story="Default" />
@@ -5,18 +5,27 @@ import { Button } from './Button';
5
5
  import { Facebook } from '@marigold/icons';
6
6
 
7
7
  const theme = {
8
+ fonts: {
9
+ body: 'Arial',
10
+ fancy: 'Inter',
11
+ },
12
+ space: {
13
+ none: 0,
14
+ small: 2,
15
+ large: 16,
16
+ },
8
17
  button: {
9
18
  large: {
10
- p: '16px',
19
+ p: 'large',
11
20
  },
12
21
  small: {
13
- p: '16px',
22
+ p: 'large',
14
23
  },
15
24
  primary: {
16
- fontFamily: 'Inter',
25
+ fontFamily: 'fancy',
17
26
  },
18
27
  secondary: {
19
- fontFamily: 'Arial',
28
+ fontFamily: 'body',
20
29
  },
21
30
  },
22
31
  };
@@ -29,7 +38,7 @@ test('supports default variant', () => {
29
38
  );
30
39
  const button = screen.getByText(/button/);
31
40
 
32
- expect(button.parentElement).toHaveStyle(`font-family: Inter`);
41
+ expect(button).toHaveStyle(`font-family: Inter`);
33
42
  });
34
43
 
35
44
  test('supports default size', () => {
@@ -40,7 +49,7 @@ test('supports default size', () => {
40
49
  );
41
50
  const button = screen.getByText(/button/);
42
51
 
43
- expect(button.parentElement).toHaveStyle(`padding: 16px`);
52
+ expect(button).toHaveStyle(`padding: 16px`);
44
53
  });
45
54
 
46
55
  test('accepts other variant than default', () => {
@@ -51,7 +60,7 @@ test('accepts other variant than default', () => {
51
60
  );
52
61
  const button = screen.getByText(/button/);
53
62
 
54
- expect(button.parentElement).toHaveStyle(`font-family: Arial`);
63
+ expect(button).toHaveStyle(`font-family: Arial`);
55
64
  });
56
65
 
57
66
  test('accepts other size than default', () => {
@@ -62,7 +71,7 @@ test('accepts other size than default', () => {
62
71
  );
63
72
  const button = screen.getByText(/button/);
64
73
 
65
- expect(button.parentElement).toHaveStyle(`padding: 16px`);
74
+ expect(button).toHaveStyle(`padding: 16px`);
66
75
  });
67
76
 
68
77
  test('renders <button> element', () => {
@@ -73,8 +82,7 @@ test('renders <button> element', () => {
73
82
  );
74
83
  const button = screen.getByText(/button/);
75
84
 
76
- expect(button.parentElement instanceof HTMLButtonElement).toBeTruthy();
77
- expect(button instanceof HTMLSpanElement).toBeTruthy();
85
+ expect(button instanceof HTMLButtonElement).toBeTruthy();
78
86
  });
79
87
 
80
88
  test('accepts other button components', () => {
@@ -105,13 +113,28 @@ test('add icon in button works as expected', () => {
105
113
  const button = screen.getByText(/iconbutton/);
106
114
  const icon = screen.getByTitle(/facebook/);
107
115
 
108
- expect(button instanceof HTMLSpanElement).toBeTruthy();
116
+ expect(button instanceof HTMLButtonElement).toBeTruthy();
109
117
  expect(button).toHaveStyle('display: inline-flex');
110
118
  expect(button.firstChild instanceof SVGElement).toBeTruthy();
111
119
  expect(icon.getAttribute('fill')).toEqual('red');
112
120
  expect(icon.getAttribute('width')).toEqual('30');
113
121
  });
114
122
 
123
+ test('add space to button works as expected', () => {
124
+ render(
125
+ <ThemeProvider theme={theme}>
126
+ <Button title="iconbutton" space="small">
127
+ <Facebook fill="red" size={30} title="facebook" />
128
+ iconbutton
129
+ </Button>
130
+ </ThemeProvider>
131
+ );
132
+ const button = screen.getByTitle(/iconbutton/);
133
+
134
+ const style = window.getComputedStyle(button);
135
+ expect(style.columnGap).toBe(`2px`);
136
+ });
137
+
115
138
  test('accepts custom styles prop className', () => {
116
139
  render(
117
140
  <ThemeProvider theme={theme}>
@@ -7,8 +7,20 @@ import {
7
7
 
8
8
  import { Box, BoxOwnProps } from '../Box';
9
9
 
10
+ // Theme Extension
11
+ // ---------------
12
+ export interface ButtonThemeExtension<Value> {
13
+ button?: {
14
+ [key: string]: Value;
15
+ };
16
+ }
17
+
18
+ // Props
19
+ // ---------------
10
20
  export type ButtonProps = PolymorphicPropsWithRef<BoxOwnProps, 'button'>;
11
21
 
22
+ // Component
23
+ // ---------------
12
24
  export const Button: PolymorphicComponentWithRef<BoxOwnProps, 'button'> =
13
25
  forwardRef(
14
26
  (
@@ -16,6 +28,7 @@ export const Button: PolymorphicComponentWithRef<BoxOwnProps, 'button'> =
16
28
  as = 'button',
17
29
  variant = 'primary',
18
30
  size = 'large',
31
+ space = 'none',
19
32
  disabled,
20
33
  children,
21
34
  className,
@@ -37,13 +50,14 @@ export const Button: PolymorphicComponentWithRef<BoxOwnProps, 'button'> =
37
50
  {...buttonProps}
38
51
  {...props}
39
52
  as={as}
53
+ display="inline-flex"
54
+ alignItems="center"
40
55
  variant={[`button.${variant}`, `button.${size}`]}
41
56
  className={className}
42
57
  ref={ref}
58
+ css={{ columnGap: space }}
43
59
  >
44
- <Box as="span" display="inline-flex" alignItems="center">
45
- {children}
46
- </Box>
60
+ {children}
47
61
  </Box>
48
62
  );
49
63
  }
@@ -1,18 +1,18 @@
1
- import { ArgsTable, Canvas, Meta, Story } from '@storybook/addon-docs';
2
- import { Heading } from '../Heading';
1
+ import React from 'react';
2
+ import type { Meta, ComponentStory } from '@storybook/react';
3
3
  import { Card } from './Card';
4
4
  import { Text } from '../Text';
5
5
 
6
- <Meta
7
- title="Components/Card"
8
- argTypes={{
6
+ export default {
7
+ title: 'Components/Card',
8
+ argTypes: {
9
9
  variant: {
10
10
  control: {
11
11
  type: 'text',
12
12
  },
13
13
  table: {
14
14
  defaultValue: {
15
- summary: 'default',
15
+ summary: '__default',
16
16
  },
17
17
  },
18
18
  },
@@ -28,12 +28,10 @@ import { Text } from '../Text';
28
28
  },
29
29
  description: 'max width of the card',
30
30
  },
31
- }}
32
- />
31
+ },
32
+ } as Meta;
33
33
 
34
- # Card
35
-
36
- export const Template = args => (
34
+ export const Basic: ComponentStory<typeof Card> = args => (
37
35
  <Card title="Card" {...args}>
38
36
  <Text>
39
37
  Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse
@@ -41,9 +39,3 @@ export const Template = args => (
41
39
  </Text>
42
40
  </Card>
43
41
  );
44
-
45
- <Canvas>
46
- <Story name="Default">{Template.bind({})}</Story>
47
- </Canvas>
48
-
49
- <ArgsTable story="Default" />
@@ -5,12 +5,17 @@ import { ThemeProvider } from '@marigold/system';
5
5
  import { Card } from './Card';
6
6
 
7
7
  const theme = {
8
+ space: {
9
+ none: 0,
10
+ small: 4,
11
+ medium: 8,
12
+ },
8
13
  card: {
9
- default: {
10
- p: '8px',
14
+ __default: {
15
+ p: 'medium',
11
16
  },
12
17
  custom: {
13
- p: '4px',
18
+ p: 'small',
14
19
  },
15
20
  },
16
21
  };
package/src/Card/Card.tsx CHANGED
@@ -4,14 +4,26 @@ import { ComponentProps } from '@marigold/types';
4
4
 
5
5
  import { Box } from '../Box';
6
6
 
7
+ // Theme Extension
8
+ // ---------------
9
+ export interface CardThemeExtension<Value> {
10
+ card?: {
11
+ [key: string]: Value;
12
+ };
13
+ }
14
+
15
+ // Props
16
+ // ---------------
7
17
  export type CardProps = {
8
18
  title?: string;
9
19
  width?: ResponsiveStyleValue<string>;
10
20
  variant?: string;
11
21
  } & ComponentProps<'div'>;
12
22
 
23
+ // Component
24
+ // ---------------
13
25
  export const Card: React.FC<CardProps> = ({
14
- variant = 'default',
26
+ variant = '',
15
27
  title,
16
28
  width,
17
29
  className,
@@ -28,6 +28,17 @@ import { useState } from 'react';
28
28
  },
29
29
  },
30
30
  },
31
+ labelVariant: {
32
+ control: {
33
+ type: 'text',
34
+ },
35
+ description: 'Checkbox label variant',
36
+ table: {
37
+ defaultValue: {
38
+ summary: 'inline',
39
+ },
40
+ },
41
+ },
31
42
  label: {
32
43
  control: {
33
44
  type: 'text',