@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
@@ -1,10 +1,11 @@
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 { Divider } from './Divider';
3
4
  import { Text } from '../Text';
4
5
 
5
- <Meta
6
- title="Components/Divider"
7
- argTypes={{
6
+ export default {
7
+ title: 'Components/Divider',
8
+ argTypes: {
8
9
  variant: {
9
10
  control: {
10
11
  type: 'select',
@@ -17,21 +18,13 @@ import { Text } from '../Text';
17
18
  },
18
19
  },
19
20
  },
20
- }}
21
- />
21
+ },
22
+ } as Meta;
22
23
 
23
- # Divider
24
-
25
- export const Template = args => (
26
- <div>
24
+ export const Basic: ComponentStory<typeof Divider> = args => (
25
+ <>
27
26
  <Text>Above</Text>
28
27
  <Divider {...args} />
29
28
  <Text>Below</Text>
30
- </div>
29
+ </>
31
30
  );
32
-
33
- <Canvas>
34
- <Story name="Default">{Template.bind({})}</Story>
35
- </Canvas>
36
-
37
- <ArgsTable story="Default" />
@@ -4,16 +4,24 @@ import { ThemeProvider } from '@marigold/system';
4
4
  import { Divider } from './Divider';
5
5
 
6
6
  const theme = {
7
+ space: {
8
+ none: 0,
9
+ small: 2,
10
+ },
11
+ borders: {
12
+ none: 0,
13
+ regular: '1px solid',
14
+ },
7
15
  divider: {
8
16
  regular: {
9
- border: 0,
10
- borderBottom: '1px solid',
11
- margin: '2px',
17
+ border: 'none',
18
+ borderBottom: 'regular',
19
+ margin: 'small',
12
20
  },
13
21
  bold: {
14
- border: 0,
22
+ border: 'none',
15
23
  borderBottom: '2px solid',
16
- margin: '2px',
24
+ margin: 'small',
17
25
  },
18
26
  },
19
27
  };
@@ -1,12 +1,24 @@
1
1
  import React from 'react';
2
2
  import { Box } from '../Box';
3
3
 
4
+ // Theme Extension
5
+ // ---------------
6
+ export interface DividerThemeExtension<Value> {
7
+ divider?: {
8
+ [key: string]: Value;
9
+ };
10
+ }
11
+
12
+ // Props
13
+ // ---------------
4
14
  export type DividerProps = {
5
15
  className?: string;
6
16
  variant?: string;
7
17
  title?: string; // Should only be used for testing.
8
18
  };
9
19
 
20
+ // Component
21
+ // ---------------
10
22
  export const Divider: React.FC<DividerProps> = ({
11
23
  variant = 'regular',
12
24
  ...props
@@ -1,20 +1,43 @@
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 { Field } from './Field';
3
4
 
4
- <Meta
5
- title="Components/Field"
6
- argTypes={{
5
+ export default {
6
+ title: 'Components/Field',
7
+ argTypes: {
8
+ variant: {
9
+ control: {
10
+ type: 'text',
11
+ },
12
+ description: 'Field variant',
13
+ table: {
14
+ defaultValue: {
15
+ summary: '__default',
16
+ },
17
+ },
18
+ },
19
+ labelVariant: {
20
+ control: {
21
+ type: 'text',
22
+ },
23
+ description: 'Field label variant',
24
+ table: {
25
+ defaultValue: {
26
+ summary: 'above',
27
+ },
28
+ },
29
+ },
7
30
  htmlFor: {
8
31
  control: {
9
32
  type: 'text',
10
33
  },
11
- type: { required: true },
34
+ defaultValue: 'id',
12
35
  },
13
36
  label: {
14
37
  control: {
15
38
  type: 'text',
16
39
  },
17
- type: { required: true },
40
+ defaultValue: 'Label',
18
41
  },
19
42
  error: {
20
43
  control: {
@@ -74,24 +97,14 @@ import { Field } from './Field';
74
97
  'url',
75
98
  'week',
76
99
  ],
77
- type: { required: true },
100
+ defaultValue: 'text',
78
101
  table: {
79
102
  defaultValue: {
80
103
  summary: 'text',
81
104
  },
82
105
  },
83
106
  },
84
- }}
85
- />
86
-
87
- # Field
88
-
89
- export const Template = args => (
90
- <Field htmlFor="id" label="A label" type="text" {...args} />
91
- );
92
-
93
- <Canvas>
94
- <Story name="Default">{Template.bind({})}</Story>
95
- </Canvas>
107
+ },
108
+ } as Meta;
96
109
 
97
- <ArgsTable story="Default" />
110
+ export const Basic: ComponentStory<typeof Field> = args => <Field {...args} />;
@@ -4,12 +4,22 @@ import { ThemeProvider } from '@marigold/system';
4
4
  import { Field } from './Field';
5
5
 
6
6
  const theme = {
7
- field: {
8
- default: {
9
- padding: '4px',
7
+ space: {
8
+ none: 0,
9
+ small: 4,
10
+ medium: 8,
11
+ },
12
+ label: {
13
+ above: {
14
+ fontSize: '14px',
15
+ },
16
+ },
17
+ input: {
18
+ __default: {
19
+ padding: 'small',
10
20
  },
11
- inputField: {
12
- padding: '8px',
21
+ error: {
22
+ padding: 'medium',
13
23
  },
14
24
  },
15
25
  };
@@ -25,6 +35,46 @@ test('renders correct HTML element', () => {
25
35
  expect(field instanceof HTMLLabelElement).toBeTruthy();
26
36
  });
27
37
 
38
+ test('supports default variant', () => {
39
+ render(
40
+ <ThemeProvider theme={theme}>
41
+ <Field htmlFor="myId" label="Name" data-testid="field" />
42
+ </ThemeProvider>
43
+ );
44
+ const field = screen.getByTestId(/field/);
45
+ expect(field).toHaveStyle(`padding: 4px`);
46
+ });
47
+
48
+ test('supports other variant than default', () => {
49
+ render(
50
+ <ThemeProvider theme={theme}>
51
+ <Field htmlFor="myId" label="Name" variant="error" data-testid="field" />
52
+ </ThemeProvider>
53
+ );
54
+ const field = screen.getByTestId(/field/);
55
+ expect(field).toHaveStyle(`padding: 8px`);
56
+ });
57
+
58
+ test('supports default variantLabel', () => {
59
+ render(
60
+ <ThemeProvider theme={theme}>
61
+ <Field htmlFor="myId" label="Name" />
62
+ </ThemeProvider>
63
+ );
64
+ const label = screen.getByText(/Name/);
65
+ expect(label).toHaveStyle(`font-size: 14px`);
66
+ });
67
+
68
+ test('supports other variantLabel than default', () => {
69
+ render(
70
+ <ThemeProvider theme={theme}>
71
+ <Field htmlFor="myId" label="Name" />
72
+ </ThemeProvider>
73
+ );
74
+ const label = screen.getByText(/Name/);
75
+ expect(label).toHaveStyle(`font-size: 14px`);
76
+ });
77
+
28
78
  test('supports label prop', () => {
29
79
  render(<Field htmlFor="myId" label="Name" />);
30
80
  const field = screen.getByText(/Name/);
@@ -6,7 +6,11 @@ import { Input } from '../Input';
6
6
  import { Label } from '../Label';
7
7
  import { ValidationMessage } from '../ValidationMessage';
8
8
 
9
+ // Props
10
+ // ---------------
9
11
  export type FieldProps = {
12
+ variant?: string;
13
+ labelVariant?: string;
10
14
  htmlFor: string;
11
15
  label: string;
12
16
  required?: boolean;
@@ -15,9 +19,12 @@ export type FieldProps = {
15
19
  disabled?: boolean;
16
20
  } & ComponentProps<'input'>;
17
21
 
22
+ // Component
23
+ // ---------------
18
24
  export const Field: React.FC<FieldProps> = ({
19
25
  type = 'text',
20
- className,
26
+ variant = '',
27
+ labelVariant = 'above',
21
28
  htmlFor,
22
29
  label,
23
30
  required,
@@ -28,11 +35,7 @@ export const Field: React.FC<FieldProps> = ({
28
35
  }) => {
29
36
  return (
30
37
  <>
31
- <Label
32
- variant={disabled ? 'disabled' : 'above'}
33
- htmlFor={htmlFor}
34
- required={required}
35
- >
38
+ <Label variant={labelVariant} htmlFor={htmlFor} required={required}>
36
39
  {label}
37
40
  </Label>
38
41
  <Input
@@ -40,8 +43,7 @@ export const Field: React.FC<FieldProps> = ({
40
43
  type={type}
41
44
  id={htmlFor}
42
45
  disabled={disabled}
43
- variant={error ? 'error' : 'default'}
44
- className={className}
46
+ variant={variant}
45
47
  />
46
48
  {error && errorMessage && (
47
49
  <ValidationMessage>
@@ -0,0 +1,34 @@
1
+ import React from 'react';
2
+ import type { Meta, ComponentStory } from '@storybook/react';
3
+ import { Image } from './Image';
4
+
5
+ export default {
6
+ title: 'Components/Image',
7
+ argTypes: {
8
+ variant: {
9
+ control: {
10
+ type: 'text',
11
+ },
12
+ description: 'there is only one variant',
13
+ table: {
14
+ defaultValue: {
15
+ summary: 'fullWidth',
16
+ },
17
+ },
18
+ },
19
+ alt: {
20
+ control: {
21
+ type: 'text',
22
+ },
23
+ description: 'Description text for screenreaders',
24
+ },
25
+ },
26
+ } as Meta;
27
+
28
+ export const Basic: ComponentStory<typeof Image> = args => (
29
+ <Image
30
+ src="https://www.reservix.net/_Resources/Persistent/0e8f5885125940fdb2bc2d54840f497782f56584/Reservix_Logo_dtp_web_rgb_font_black_180704.png"
31
+ alt="marigold_logo"
32
+ {...args}
33
+ />
34
+ );
@@ -4,7 +4,10 @@ import { ThemeProvider } from '@marigold/system';
4
4
  import { Image } from './Image';
5
5
 
6
6
  const theme = {
7
- images: {
7
+ colors: {
8
+ primary: 'hotpink',
9
+ },
10
+ image: {
8
11
  fullWidth: {
9
12
  alignItems: 'center',
10
13
  },
@@ -2,12 +2,24 @@ 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 ImageThemeExtension<Value> {
8
+ image?: {
9
+ [key: string]: Value;
10
+ };
11
+ }
12
+
13
+ // Props
14
+ // ---------------
5
15
  export type ImageProps = {
6
16
  variant?: string;
7
17
  children?: never;
8
18
  } & ComponentProps<'img'>;
9
19
 
20
+ // Component
21
+ // ---------------
10
22
  export const Image: React.FC<ImageProps> = ({
11
23
  variant = 'fullWidth',
12
24
  ...props
13
- }) => <Box {...props} as="img" variant={`images.${variant}`} />;
25
+ }) => <Box {...props} as="img" variant={`image.${variant}`} />;
@@ -0,0 +1,39 @@
1
+ import React from 'react';
2
+ import type { Meta, ComponentStory } from '@storybook/react';
3
+ import { Text } from '../Text';
4
+ import { Inline } from './Inline';
5
+ import { Check } from '@marigold/icons';
6
+
7
+ export default {
8
+ title: 'Components/Inline',
9
+ argTypes: {
10
+ space: {
11
+ control: {
12
+ type: 'select',
13
+ },
14
+ options: [
15
+ 'none',
16
+ 'xxsmall',
17
+ 'xsmall',
18
+ 'small',
19
+ 'medium',
20
+ 'large',
21
+ 'xlarge',
22
+ 'xxlarge',
23
+ ],
24
+ description: 'Responsive Style Value',
25
+ table: {
26
+ defaultValue: {
27
+ summary: 'none',
28
+ },
29
+ },
30
+ },
31
+ },
32
+ } as Meta;
33
+
34
+ export const Basic: ComponentStory<typeof Inline> = args => (
35
+ <Inline {...args}>
36
+ <Check />
37
+ <Text>Check</Text>
38
+ </Inline>
39
+ );
@@ -0,0 +1,99 @@
1
+ import React from 'react';
2
+ import { render, screen } from '@testing-library/react';
3
+ import { ThemeProvider } from '@marigold/system';
4
+
5
+ import { Inline } from './Inline';
6
+ import { Text } from '../Text';
7
+
8
+ // Setup
9
+ // ---------------
10
+ const theme = {
11
+ space: {
12
+ none: 0,
13
+ small: 2,
14
+ medium: 4,
15
+ large: 8,
16
+ },
17
+ };
18
+
19
+ const getLeftPadding = (element: HTMLElement) =>
20
+ getComputedStyle(element).getPropertyValue('padding-left');
21
+
22
+ test('default space is "none"', () => {
23
+ render(
24
+ <ThemeProvider theme={theme}>
25
+ <Inline>
26
+ <Text>first</Text>
27
+ <Text>second</Text>
28
+ </Inline>
29
+ </ThemeProvider>
30
+ );
31
+ const first = screen.getByText(/first/).parentElement!;
32
+ const second = screen.getByText(/second/).parentElement!;
33
+
34
+ expect(getLeftPadding(first)).toEqual('');
35
+ expect(second).toHaveStyle(`padding-left: 0px`);
36
+ });
37
+
38
+ test('accepts and uses spacing from theme', () => {
39
+ render(
40
+ <ThemeProvider theme={theme}>
41
+ <Inline space="small">
42
+ <Text>first</Text>
43
+ <Text>second</Text>
44
+ </Inline>
45
+ </ThemeProvider>
46
+ );
47
+ const first = screen.getByText(/first/);
48
+ const second = screen.getByText(/second/);
49
+
50
+ expect(getLeftPadding(first)).toEqual('');
51
+ expect(second.parentElement).toHaveStyle(`padding-left: 2px`);
52
+ });
53
+
54
+ test('supports nesting', () => {
55
+ render(
56
+ <ThemeProvider theme={theme}>
57
+ <Inline space="large">
58
+ <Inline space="small" data-testid="leftInline">
59
+ <Text>first</Text>
60
+ <Text>second</Text>
61
+ </Inline>
62
+ <Inline space="small" data-testid="rightInline">
63
+ <Text>third</Text>
64
+ <Text>fourth</Text>
65
+ </Inline>
66
+ </Inline>
67
+ </ThemeProvider>
68
+ );
69
+ const first = screen.getByText(/first/);
70
+ const second = screen.getByText(/second/);
71
+ const leftInline = screen.getByTestId('leftInline');
72
+
73
+ const third = screen.getByText(/third/);
74
+ const fourth = screen.getByText(/fourth/);
75
+ const rightInline = screen.getByTestId('rightInline');
76
+
77
+ expect(getLeftPadding(leftInline.parentElement!)).toEqual('');
78
+ expect(rightInline.parentElement).toHaveStyle(`padding-left: 8px`);
79
+
80
+ expect(getLeftPadding(first.parentElement!)).toEqual('');
81
+ expect(second.parentElement).toHaveStyle(`padding-left: 2px`);
82
+
83
+ expect(getLeftPadding(third.parentElement!)).toEqual('');
84
+ expect(fourth.parentElement).toHaveStyle(`padding-left: 2px`);
85
+ });
86
+
87
+ test('renders div per default', () => {
88
+ render(
89
+ <ThemeProvider theme={theme}>
90
+ <Inline data-testid="inline">
91
+ <Text>first</Text>
92
+ <Text>second</Text>
93
+ </Inline>
94
+ </ThemeProvider>
95
+ );
96
+
97
+ const inline = screen.getByTestId('inline');
98
+ expect(inline instanceof HTMLDivElement).toBeTruthy();
99
+ });
@@ -0,0 +1,38 @@
1
+ import React, { Children } from 'react';
2
+ import flattenChildren from 'react-keyed-flatten-children';
3
+
4
+ import { ResponsiveStyleValue } from '@marigold/system';
5
+
6
+ import { Box } from '../Box';
7
+
8
+ export type InlineProps = {
9
+ space?: ResponsiveStyleValue<string>;
10
+ align?: 'top' | 'center' | 'bottom';
11
+ };
12
+
13
+ const ALIGNMENT = {
14
+ top: 'flex-start',
15
+ center: 'center',
16
+ bottom: 'flex-end',
17
+ };
18
+
19
+ export const Inline: React.FC<InlineProps> = ({
20
+ space = 'none',
21
+ align = 'center',
22
+ children,
23
+ ...props
24
+ }) => (
25
+ <Box
26
+ display="inline-flex"
27
+ css={{ '> * + *': { pl: space } }}
28
+ alignItems={ALIGNMENT[align]}
29
+ {...props}
30
+ >
31
+ {Children.map(
32
+ flattenChildren(children) as unknown as React.ReactElement,
33
+ (child: React.ReactElement) => (
34
+ <Box>{React.cloneElement(child, {}, child.props.children)}</Box>
35
+ )
36
+ )}
37
+ </Box>
38
+ );
@@ -0,0 +1 @@
1
+ export * from './Inline';
@@ -1,10 +1,11 @@
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 { Input } from './Input';
3
4
  import { Label } from '../Label';
4
5
 
5
- <Meta
6
- title="Components/Input"
7
- argTypes={{
6
+ export default {
7
+ title: 'Components/Input',
8
+ argTypes: {
8
9
  variant: {
9
10
  control: {
10
11
  type: 'text',
@@ -12,7 +13,7 @@ import { Label } from '../Label';
12
13
  description: '?',
13
14
  table: {
14
15
  defaultValue: {
15
- summary: 'default',
16
+ summary: '__default',
16
17
  },
17
18
  },
18
19
  },
@@ -35,27 +36,19 @@ import { Label } from '../Label';
35
36
  'url',
36
37
  'week',
37
38
  ],
38
- type: { required: true },
39
+ defaultValue: 'text',
39
40
  table: {
40
41
  defaultValue: {
41
42
  summary: 'text',
42
43
  },
43
44
  },
44
45
  },
45
- }}
46
- />
46
+ },
47
+ } as Meta;
47
48
 
48
- # Input
49
-
50
- export const Template = args => (
49
+ export const Basic: ComponentStory<typeof Input> = args => (
51
50
  <Label htmlFor="input">
52
51
  Label
53
52
  <Input id="input" placeholder="Placeholder..." {...args} />
54
53
  </Label>
55
54
  );
56
-
57
- <Canvas>
58
- <Story name="Default">{Template.bind({})}</Story>
59
- </Canvas>
60
-
61
- <ArgsTable story="Default" />
@@ -4,12 +4,16 @@ import { ThemeProvider } from '@marigold/system';
4
4
  import { Input } from './Input';
5
5
 
6
6
  const theme = {
7
+ fonts: {
8
+ body: 'Inter',
9
+ forms: 'Roboto',
10
+ },
7
11
  input: {
8
- default: {
9
- fontFamily: 'Inter',
12
+ __default: {
13
+ fontFamily: 'body',
10
14
  },
11
15
  input2: {
12
- fontFamily: 'Roboto',
16
+ fontFamily: 'forms',
13
17
  },
14
18
  },
15
19
  };
@@ -2,12 +2,24 @@ 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 InputThemeExtension<Value> {
8
+ input?: {
9
+ [key: string]: Value;
10
+ };
11
+ }
12
+
13
+ // Props
14
+ // ---------------
5
15
  export type InputProps = {
6
16
  variant?: string;
7
17
  } & ComponentProps<'input'>;
8
18
 
19
+ // Component
20
+ // ---------------
9
21
  export const Input: React.FC<InputProps> = ({
10
- variant = 'default',
22
+ variant = '',
11
23
  type = 'text',
12
24
  ...props
13
25
  }) => <Box {...props} as="input" type={type} variant={`input.${variant}`} />;