@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.
Files changed (194) hide show
  1. package/dist/ActionGroup/ActionGroup.d.ts +9 -0
  2. package/dist/ActionGroup/index.d.ts +1 -0
  3. package/dist/Alert/Alert.d.ts +20 -2
  4. package/dist/Badge/Badge.d.ts +8 -0
  5. package/dist/Badge/index.d.ts +1 -0
  6. package/dist/Box/Box.d.ts +47 -0
  7. package/dist/Box/index.d.ts +1 -0
  8. package/dist/Button/Button.d.ts +4 -3
  9. package/dist/Card/Card.d.ts +9 -0
  10. package/dist/Card/index.d.ts +1 -0
  11. package/dist/Checkbox/Checkbox.d.ts +14 -2
  12. package/dist/Checkbox/CheckboxIcons.d.ts +9 -0
  13. package/dist/Column/Column.d.ts +8 -0
  14. package/dist/Column/index.d.ts +1 -0
  15. package/dist/Columns/Columns.d.ts +10 -0
  16. package/dist/Columns/index.d.ts +1 -0
  17. package/dist/Container/Container.d.ts +6 -0
  18. package/dist/Container/index.d.ts +1 -0
  19. package/dist/Dialog/Dialog.d.ts +14 -0
  20. package/dist/Dialog/ModalDialog.d.ts +5 -0
  21. package/dist/Dialog/index.d.ts +1 -0
  22. package/dist/Divider/Divider.d.ts +7 -0
  23. package/dist/Divider/index.d.ts +1 -0
  24. package/dist/Field/Field.d.ts +11 -0
  25. package/dist/Field/index.d.ts +1 -0
  26. package/dist/Heading/Heading.d.ts +7 -5
  27. package/dist/Hidden/Hidden.d.ts +5 -0
  28. package/dist/Hidden/index.d.ts +1 -0
  29. package/dist/Image/Image.d.ts +7 -0
  30. package/dist/Image/index.d.ts +1 -0
  31. package/dist/Input/Input.d.ts +6 -0
  32. package/dist/Input/index.d.ts +1 -0
  33. package/dist/Label/Label.d.ts +8 -5
  34. package/dist/Link/Link.d.ts +7 -3
  35. package/dist/Menu/Menu.d.ts +12 -0
  36. package/dist/Menu/index.d.ts +1 -0
  37. package/dist/MenuItem/MenuItem.d.ts +7 -0
  38. package/dist/MenuItem/index.d.ts +1 -0
  39. package/dist/Message/Message.d.ts +7 -0
  40. package/dist/Message/index.d.ts +1 -0
  41. package/dist/Provider/MarigoldProvider.d.ts +3 -0
  42. package/dist/Provider/index.d.ts +3 -0
  43. package/dist/Radio/Radio.d.ts +14 -2
  44. package/dist/Radio/RadioIcons.d.ts +9 -0
  45. package/dist/Select/ListBox.d.ts +8 -0
  46. package/dist/Select/ListBoxSection.d.ts +8 -0
  47. package/dist/Select/Option.d.ts +8 -0
  48. package/dist/Select/Popover.d.ts +9 -0
  49. package/dist/Select/Select.d.ts +13 -3
  50. package/dist/Slider/Slider.d.ts +6 -3
  51. package/dist/Stack/Stack.d.ts +7 -0
  52. package/dist/Stack/index.d.ts +1 -0
  53. package/dist/Text/Text.d.ts +12 -3
  54. package/dist/Textarea/Textarea.d.ts +11 -3
  55. package/dist/ValidationMessage/ValidationMessage.d.ts +6 -0
  56. package/dist/ValidationMessage/index.d.ts +1 -0
  57. package/dist/components.cjs.development.js +1308 -195
  58. package/dist/components.cjs.development.js.map +1 -1
  59. package/dist/components.cjs.production.min.js +1 -1
  60. package/dist/components.cjs.production.min.js.map +1 -1
  61. package/dist/components.esm.js +1267 -185
  62. package/dist/components.esm.js.map +1 -1
  63. package/dist/index.d.ts +21 -4
  64. package/dist/theme.d.ts +24 -4
  65. package/package.json +24 -4
  66. package/src/ActionGroup/ActionGroup.stories.mdx +62 -0
  67. package/src/ActionGroup/ActionGroup.test.tsx +83 -0
  68. package/src/ActionGroup/ActionGroup.tsx +43 -0
  69. package/src/ActionGroup/index.ts +1 -0
  70. package/src/Alert/Alert.stories.mdx +30 -42
  71. package/src/Alert/Alert.test.tsx +37 -22
  72. package/src/Alert/Alert.tsx +31 -21
  73. package/src/Badge/Badge.stories.mdx +57 -0
  74. package/src/Badge/Badge.test.tsx +61 -0
  75. package/src/Badge/Badge.tsx +25 -0
  76. package/src/Badge/index.ts +1 -0
  77. package/src/Box/Box.stories.mdx +334 -0
  78. package/src/Box/Box.test.tsx +133 -0
  79. package/src/Box/Box.tsx +165 -0
  80. package/src/Box/index.ts +1 -0
  81. package/src/Button/Button.stories.mdx +58 -134
  82. package/src/Button/Button.test.tsx +65 -23
  83. package/src/Button/Button.tsx +48 -14
  84. package/src/Card/Card.stories.mdx +49 -0
  85. package/src/Card/Card.test.tsx +66 -0
  86. package/src/Card/Card.tsx +36 -0
  87. package/src/Card/index.ts +1 -0
  88. package/src/Checkbox/Checkbox.stories.mdx +79 -101
  89. package/src/Checkbox/Checkbox.test.tsx +73 -32
  90. package/src/Checkbox/Checkbox.tsx +114 -35
  91. package/src/Checkbox/CheckboxIcons.tsx +49 -0
  92. package/src/Column/Column.stories.mdx +49 -0
  93. package/src/Column/Column.test.tsx +32 -0
  94. package/src/Column/Column.tsx +27 -0
  95. package/src/Column/index.ts +1 -0
  96. package/src/Columns/Columns.stories.mdx +65 -0
  97. package/src/Columns/Columns.test.tsx +102 -0
  98. package/src/Columns/Columns.tsx +69 -0
  99. package/src/Columns/index.ts +1 -0
  100. package/src/Container/Container.stories.mdx +19 -0
  101. package/src/Container/Container.test.tsx +26 -0
  102. package/src/Container/Container.tsx +13 -0
  103. package/src/Container/index.ts +1 -0
  104. package/src/Dialog/Dialog.stories.mdx +73 -0
  105. package/src/Dialog/Dialog.test.tsx +87 -0
  106. package/src/Dialog/Dialog.tsx +84 -0
  107. package/src/Dialog/ModalDialog.tsx +47 -0
  108. package/src/Dialog/index.ts +1 -0
  109. package/src/Divider/Divider.stories.mdx +37 -0
  110. package/src/Divider/Divider.test.tsx +63 -0
  111. package/src/Divider/Divider.tsx +13 -0
  112. package/src/Divider/index.ts +1 -0
  113. package/src/Field/Field.stories.mdx +97 -0
  114. package/src/Field/Field.test.tsx +80 -0
  115. package/src/Field/Field.tsx +54 -0
  116. package/src/Field/index.ts +1 -0
  117. package/src/Heading/Heading.stories.mdx +36 -76
  118. package/src/Heading/Heading.test.tsx +31 -17
  119. package/src/Heading/Heading.tsx +15 -12
  120. package/src/Hidden/Hidden.stories.mdx +39 -0
  121. package/src/Hidden/Hidden.test.tsx +24 -0
  122. package/src/Hidden/Hidden.tsx +16 -0
  123. package/src/Hidden/index.ts +1 -0
  124. package/src/Image/Image.stories.mdx +36 -0
  125. package/src/Image/Image.test.tsx +70 -0
  126. package/src/Image/Image.tsx +13 -0
  127. package/src/Image/index.ts +1 -0
  128. package/src/Input/Input.stories.mdx +61 -0
  129. package/src/Input/Input.test.tsx +70 -0
  130. package/src/Input/Input.tsx +13 -0
  131. package/src/Input/index.ts +1 -0
  132. package/src/Label/Label.stories.mdx +50 -34
  133. package/src/Label/Label.test.tsx +45 -16
  134. package/src/Label/Label.tsx +26 -17
  135. package/src/Link/Link.stories.mdx +40 -31
  136. package/src/Link/Link.test.tsx +53 -28
  137. package/src/Link/Link.tsx +32 -14
  138. package/src/Menu/Menu.stories.mdx +81 -0
  139. package/src/Menu/Menu.test.tsx +79 -0
  140. package/src/Menu/Menu.tsx +41 -0
  141. package/src/Menu/index.ts +1 -0
  142. package/src/MenuItem/MenuItem.stories.mdx +37 -0
  143. package/src/MenuItem/MenuItem.test.tsx +63 -0
  144. package/src/MenuItem/MenuItem.tsx +23 -0
  145. package/src/MenuItem/index.ts +1 -0
  146. package/src/Message/Message.stories.mdx +44 -0
  147. package/src/Message/Message.test.tsx +87 -0
  148. package/src/Message/Message.tsx +43 -0
  149. package/src/Message/index.ts +1 -0
  150. package/src/Provider/MarigoldProvider.test.tsx +126 -0
  151. package/src/Provider/MarigoldProvider.tsx +29 -0
  152. package/src/Provider/index.ts +3 -0
  153. package/src/Radio/Radio.stories.mdx +80 -83
  154. package/src/Radio/Radio.test.tsx +63 -22
  155. package/src/Radio/Radio.tsx +110 -35
  156. package/src/Radio/RadioIcons.tsx +39 -0
  157. package/src/Select/ListBox.tsx +39 -0
  158. package/src/Select/ListBoxSection.tsx +40 -0
  159. package/src/Select/Option.tsx +48 -0
  160. package/src/Select/Popover.tsx +50 -0
  161. package/src/Select/Select.stories.mdx +72 -37
  162. package/src/Select/Select.test.tsx +271 -28
  163. package/src/Select/Select.tsx +158 -23
  164. package/src/Slider/Slider.stories.mdx +26 -54
  165. package/src/Slider/Slider.test.tsx +13 -13
  166. package/src/Slider/Slider.tsx +20 -18
  167. package/src/Stack/Stack.stories.mdx +51 -0
  168. package/src/Stack/Stack.test.tsx +129 -0
  169. package/src/Stack/Stack.tsx +39 -0
  170. package/src/Stack/index.ts +1 -0
  171. package/src/Text/Text.stories.mdx +53 -47
  172. package/src/Text/Text.test.tsx +55 -15
  173. package/src/Text/Text.tsx +44 -10
  174. package/src/Textarea/Textarea.stories.mdx +68 -21
  175. package/src/Textarea/Textarea.test.tsx +47 -16
  176. package/src/Textarea/Textarea.tsx +46 -14
  177. package/src/ValidationMessage/ValidationMessage.stories.mdx +36 -0
  178. package/src/ValidationMessage/ValidationMessage.test.tsx +63 -0
  179. package/src/ValidationMessage/ValidationMessage.tsx +28 -0
  180. package/src/ValidationMessage/index.ts +1 -0
  181. package/src/index.ts +22 -4
  182. package/src/theme.ts +24 -4
  183. package/dist/Svg/Svg.d.ts +0 -5
  184. package/dist/Svg/index.d.ts +0 -1
  185. package/dist/TextInput/TextInput.d.ts +0 -3
  186. package/dist/TextInput/index.d.ts +0 -1
  187. package/src/Svg/Svg.stories.mdx +0 -47
  188. package/src/Svg/Svg.test.tsx +0 -58
  189. package/src/Svg/Svg.tsx +0 -25
  190. package/src/Svg/index.ts +0 -1
  191. package/src/TextInput/TextInput.stories.mdx +0 -37
  192. package/src/TextInput/TextInput.test.tsx +0 -71
  193. package/src/TextInput/TextInput.tsx +0 -21
  194. package/src/TextInput/index.ts +0 -1
@@ -1,16 +1,19 @@
1
1
  import React from 'react';
2
- import { Box, system } from '@marigold/system';
2
+ import { ComponentProps } from '@marigold/types';
3
+ import { Box } from '../Box';
3
4
 
4
- type HeadingProps = {
5
- headingStyle?: 'h1' | 'h2' | 'h3' | 'h4' | 'h5' | 'h6';
6
- };
5
+ export type HeadingProps = {
6
+ as?: 'h1' | 'h2' | 'h3' | 'h4' | 'h5' | 'h6';
7
+ variant?: string;
8
+ } & ComponentProps<'h1'>;
7
9
 
8
- export const Heading = system<HeadingProps, 'h2'>(
9
- ({ headingStyle = 'h2', children, ...props }) => {
10
- return (
11
- <Box as="h2" themeSection="text" variant={headingStyle} {...props}>
12
- {children}
13
- </Box>
14
- );
15
- }
10
+ export const Heading: React.FC<HeadingProps> = ({
11
+ as = 'h2',
12
+ variant = 'h2',
13
+ children,
14
+ ...props
15
+ }) => (
16
+ <Box {...props} as={as} variant={`text.${variant}`}>
17
+ {children}
18
+ </Box>
16
19
  );
@@ -0,0 +1,39 @@
1
+ import { ArgsTable, Canvas, Meta, Story } from '@storybook/addon-docs';
2
+ import { Hidden } from './Hidden';
3
+ import { Text } from '../Text';
4
+
5
+ <Meta
6
+ title="Components/Hidden"
7
+ argTypes={{
8
+ show: {
9
+ control: {
10
+ type: 'boolean',
11
+ },
12
+ options: [true, false],
13
+ description: 'Show or hide',
14
+ table: {
15
+ defaultValue: {
16
+ summary: false,
17
+ },
18
+ },
19
+ },
20
+ }}
21
+ />
22
+
23
+ # Hidden
24
+
25
+ export const Template = args => (
26
+ <div>
27
+ <Text>Change the "show" switch to "true"</Text>
28
+ <Hidden {...args}>
29
+ <br />
30
+ <Text>Hello here I am!</Text>
31
+ </Hidden>
32
+ </div>
33
+ );
34
+
35
+ <Canvas>
36
+ <Story name="Default">{Template.bind({})}</Story>
37
+ </Canvas>
38
+
39
+ <ArgsTable story="Default" />
@@ -0,0 +1,24 @@
1
+ import React from 'react';
2
+ import { render, screen } from '@testing-library/react';
3
+ import { Hidden } from './Hidden';
4
+
5
+ test('text is not visible, show prop = false', () => {
6
+ render(<Hidden>Default</Hidden>);
7
+ const hidden = screen.getByText('Default');
8
+
9
+ expect(hidden).not.toBeVisible();
10
+ });
11
+
12
+ test('support show prop = true', () => {
13
+ render(<Hidden show={true}>Default</Hidden>);
14
+ const hidden = screen.getByText('Default');
15
+
16
+ expect(hidden).toBeVisible();
17
+ });
18
+
19
+ test('renders correct HTML element', () => {
20
+ render(<Hidden>Default</Hidden>);
21
+ const hidden = screen.getByText('Default');
22
+
23
+ expect(hidden instanceof HTMLSpanElement).toBeTruthy();
24
+ });
@@ -0,0 +1,16 @@
1
+ import React from 'react';
2
+ import { Box } from '../Box';
3
+
4
+ export type HiddenProps = {
5
+ show?: boolean;
6
+ };
7
+
8
+ export const Hidden: React.FC<HiddenProps> = ({
9
+ show = false,
10
+ children,
11
+ ...props
12
+ }) => (
13
+ <Box {...props} as="span" display={show ? 'display' : 'none'}>
14
+ {children}
15
+ </Box>
16
+ );
@@ -0,0 +1 @@
1
+ export * from './Hidden';
@@ -0,0 +1,36 @@
1
+ import { ArgsTable, Canvas, Meta, Story } from '@storybook/addon-docs';
2
+ import { Image } from './Image';
3
+ import image1 from '../../../images/src/type_logo.png';
4
+
5
+ <Meta
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
+ />
27
+
28
+ # Image
29
+
30
+ export const Template = args => <Image src={image1} alt="marigold_logo" />;
31
+
32
+ <Canvas>
33
+ <Story name="Default">{Template.bind({})}</Story>
34
+ </Canvas>
35
+
36
+ <ArgsTable story="Default" />
@@ -0,0 +1,70 @@
1
+ import React from 'react';
2
+ import { render, screen } from '@testing-library/react';
3
+ import { ThemeProvider } from '@marigold/system';
4
+ import { Image } from './Image';
5
+
6
+ const theme = {
7
+ images: {
8
+ fullWidth: {
9
+ alignItems: 'center',
10
+ },
11
+ logos: {
12
+ alignItems: 'right',
13
+ },
14
+ },
15
+ };
16
+
17
+ test('supports default variant and themeSection', () => {
18
+ render(
19
+ <ThemeProvider theme={theme}>
20
+ <Image title="images" />
21
+ </ThemeProvider>
22
+ );
23
+ const img = screen.getByTitle(/images/);
24
+
25
+ expect(img).toHaveStyle(`align-items: center`);
26
+ });
27
+
28
+ test('accepts other variant than default', () => {
29
+ render(
30
+ <ThemeProvider theme={theme}>
31
+ <Image title="logos" variant="logos" />
32
+ </ThemeProvider>
33
+ );
34
+ const img = screen.getByTitle(/logos/);
35
+
36
+ expect(img).toHaveStyle(`align-items: right`);
37
+ });
38
+
39
+ test('renders correct HTML element', () => {
40
+ render(
41
+ <ThemeProvider theme={theme}>
42
+ <Image title="default" />
43
+ </ThemeProvider>
44
+ );
45
+ const img = screen.getByTitle(/default/);
46
+
47
+ expect(img instanceof HTMLImageElement).toBeTruthy();
48
+ });
49
+
50
+ test('accept alt', () => {
51
+ render(
52
+ <ThemeProvider theme={theme}>
53
+ <Image alt="altText" title="default" />
54
+ </ThemeProvider>
55
+ );
56
+ const img = screen.getByTitle(/default/);
57
+
58
+ expect(img.getAttribute('alt')).toEqual('altText');
59
+ });
60
+
61
+ test('accepts custom styles prop className', () => {
62
+ render(
63
+ <ThemeProvider theme={theme}>
64
+ <Image className="custom-class-name" title="image" />
65
+ </ThemeProvider>
66
+ );
67
+ const image = screen.getByTitle(/image/);
68
+
69
+ expect(image.className).toMatch('custom-class-name');
70
+ });
@@ -0,0 +1,13 @@
1
+ import React from 'react';
2
+ import { ComponentProps } from '@marigold/types';
3
+ import { Box } from '../Box';
4
+
5
+ export type ImageProps = {
6
+ variant?: string;
7
+ children?: never;
8
+ } & ComponentProps<'img'>;
9
+
10
+ export const Image: React.FC<ImageProps> = ({
11
+ variant = 'fullWidth',
12
+ ...props
13
+ }) => <Box {...props} as="img" variant={`images.${variant}`} />;
@@ -0,0 +1 @@
1
+ export * from './Image';
@@ -0,0 +1,61 @@
1
+ import { ArgsTable, Canvas, Meta, Story } from '@storybook/addon-docs';
2
+ import { Input } from './Input';
3
+ import { Label } from '../Label';
4
+
5
+ <Meta
6
+ title="Components/Input"
7
+ argTypes={{
8
+ variant: {
9
+ control: {
10
+ type: 'text',
11
+ },
12
+ description: '?',
13
+ table: {
14
+ defaultValue: {
15
+ summary: 'default',
16
+ },
17
+ },
18
+ },
19
+ type: {
20
+ control: {
21
+ type: 'select',
22
+ },
23
+ options: [
24
+ 'date',
25
+ 'datetime-local',
26
+ 'email',
27
+ 'month',
28
+ 'number',
29
+ 'password',
30
+ 'search',
31
+ 'tel',
32
+ 'text',
33
+ 'time',
34
+ 'time',
35
+ 'url',
36
+ 'week',
37
+ ],
38
+ type: { required: true },
39
+ table: {
40
+ defaultValue: {
41
+ summary: 'text',
42
+ },
43
+ },
44
+ },
45
+ }}
46
+ />
47
+
48
+ # Input
49
+
50
+ export const Template = args => (
51
+ <Label htmlFor="input">
52
+ Label
53
+ <Input id="input" placeholder="Placeholder..." {...args} />
54
+ </Label>
55
+ );
56
+
57
+ <Canvas>
58
+ <Story name="Default">{Template.bind({})}</Story>
59
+ </Canvas>
60
+
61
+ <ArgsTable story="Default" />
@@ -0,0 +1,70 @@
1
+ import React from 'react';
2
+ import { render, screen } from '@testing-library/react';
3
+ import { ThemeProvider } from '@marigold/system';
4
+ import { Input } from './Input';
5
+
6
+ const theme = {
7
+ input: {
8
+ default: {
9
+ fontFamily: 'Inter',
10
+ },
11
+ input2: {
12
+ fontFamily: 'Roboto',
13
+ },
14
+ },
15
+ };
16
+
17
+ test('supports default variant and themeSection', () => {
18
+ render(
19
+ <ThemeProvider theme={theme}>
20
+ <Input title="input" />
21
+ </ThemeProvider>
22
+ );
23
+ const input = screen.getByTitle('input');
24
+
25
+ expect(input).toHaveStyle(`font-family: Inter`);
26
+ });
27
+
28
+ test('accepts other variant than default', () => {
29
+ render(
30
+ <ThemeProvider theme={theme}>
31
+ <Input title="input" variant="input2" />
32
+ </ThemeProvider>
33
+ );
34
+ const input = screen.getByTitle('input');
35
+
36
+ expect(input).toHaveStyle(`font-family: Roboto`);
37
+ });
38
+
39
+ test('renders correct HTML element', () => {
40
+ render(
41
+ <ThemeProvider theme={theme}>
42
+ <Input title="input" />
43
+ </ThemeProvider>
44
+ );
45
+ const input = screen.getByTitle('input');
46
+
47
+ expect(input instanceof HTMLInputElement).toBeTruthy();
48
+ });
49
+
50
+ test('supports custom prop', () => {
51
+ render(
52
+ <ThemeProvider theme={theme}>
53
+ <Input title="input" placeholder="placeholder" />
54
+ </ThemeProvider>
55
+ );
56
+ const input = screen.getByTitle('input');
57
+
58
+ expect(input).toHaveAttribute('placeholder');
59
+ });
60
+
61
+ test('accepts custom styles prop className', () => {
62
+ render(
63
+ <ThemeProvider theme={theme}>
64
+ <Input className="custom-class-name" title="input" />
65
+ </ThemeProvider>
66
+ );
67
+ const input = screen.getByTitle(/input/);
68
+
69
+ expect(input.className).toMatch('custom-class-name');
70
+ });
@@ -0,0 +1,13 @@
1
+ import React from 'react';
2
+ import { ComponentProps } from '@marigold/types';
3
+ import { Box } from '../Box';
4
+
5
+ export type InputProps = {
6
+ variant?: string;
7
+ } & ComponentProps<'input'>;
8
+
9
+ export const Input: React.FC<InputProps> = ({
10
+ variant = 'default',
11
+ type = 'text',
12
+ ...props
13
+ }) => <Box {...props} as="input" type={type} variant={`input.${variant}`} />;
@@ -0,0 +1 @@
1
+ export * from './Input';
@@ -1,36 +1,52 @@
1
- import { Meta, Story, Preview } from '@storybook/addon-docs/blocks';
1
+ import { ArgsTable, Canvas, Meta, Story } from '@storybook/addon-docs';
2
2
  import { Label } from './Label';
3
3
 
4
- <Meta title="Components/Form/Label" />
5
-
6
- # Label-Component
7
-
8
- ## Description
9
-
10
- With the Label component you can add a HTML `<Label>` element to your form.
11
- The element uses always the themeSection with the name: `form` in your given theme. The variant in your section can be added with the variant prop. The default variant is `label`.
12
- Specific css style prop can also be added.
13
-
14
- ## Properties
15
-
16
- | Property | Type | Default |
17
- | :-------- | :---------- | :-------- |
18
- | `variant` | `string` | `'label'` |
19
- | `htmlFor` | `string` | |
20
- | `css` | `css props` | |
21
-
22
- ## Import
23
-
24
- ```tsx
25
- import { Label } from '@marigold/components';
26
- ```
27
-
28
- ## Usage
29
-
30
- <Preview>
31
- <Story name="label">
32
- <Label variant="label" htmlFor="labelId">
33
- I am a Label!
34
- </Label>
35
- </Story>
36
- </Preview>
4
+ <Meta
5
+ title="Components/Label"
6
+ argTypes={{
7
+ variant: {
8
+ control: {
9
+ type: 'text',
10
+ },
11
+ description: '?',
12
+ table: {
13
+ defaultValue: {
14
+ summary: 'above',
15
+ },
16
+ },
17
+ },
18
+ htmlFor: {
19
+ control: {
20
+ type: 'text',
21
+ },
22
+ type: {
23
+ required: true,
24
+ },
25
+ },
26
+ required: {
27
+ control: {
28
+ type: 'boolean',
29
+ },
30
+ description: 'Adds required Icon to label',
31
+ table: {
32
+ defaultValue: {
33
+ summary: false,
34
+ },
35
+ },
36
+ },
37
+ }}
38
+ />
39
+
40
+ # Label
41
+
42
+ export const Template = args => (
43
+ <Label htmlFor="input" {...args}>
44
+ Label
45
+ </Label>
46
+ );
47
+
48
+ <Canvas>
49
+ <Story name="Default">{Template.bind({})}</Story>
50
+ </Canvas>
51
+
52
+ <ArgsTable story="Default" />
@@ -1,59 +1,88 @@
1
1
  import React from 'react';
2
2
  import { render, screen } from '@testing-library/react';
3
- import { MarigoldProvider } from '@marigold/system';
3
+ import { ThemeProvider } from '@marigold/system';
4
4
  import { Label } from './Label';
5
5
 
6
6
  const theme = {
7
- form: {
8
- label: {
7
+ label: {
8
+ above: {
9
9
  fontFamily: 'Inter Regular',
10
10
  },
11
+ myLabel: {
12
+ fontFamily: 'Oswald Regular',
13
+ },
11
14
  },
12
15
  };
13
16
 
14
17
  test('supports default variant and themeSection', () => {
15
18
  render(
16
- <MarigoldProvider theme={theme}>
19
+ <ThemeProvider theme={theme}>
17
20
  <Label htmlFor="labelId">label</Label>
18
- </MarigoldProvider>
21
+ </ThemeProvider>
19
22
  );
20
23
  const label = screen.getByText(/label/);
21
24
 
22
25
  expect(label).toHaveStyle(`font-family: Inter Regular`);
23
26
  });
24
27
 
28
+ test('supports other variant than default', () => {
29
+ render(
30
+ <ThemeProvider theme={theme}>
31
+ <Label htmlFor="labelId" variant="myLabel">
32
+ label
33
+ </Label>
34
+ </ThemeProvider>
35
+ );
36
+ const label = screen.getByText(/label/);
37
+
38
+ expect(label).toHaveStyle(`font-family: Oswald Regular`);
39
+ });
40
+
25
41
  test('supports htmlFor prop', () => {
26
42
  render(
27
- <MarigoldProvider theme={theme}>
43
+ <ThemeProvider theme={theme}>
28
44
  <Label htmlFor="labelId">label</Label>
29
- </MarigoldProvider>
45
+ </ThemeProvider>
30
46
  );
31
47
  const label = screen.getByText(/label/);
32
48
 
33
49
  expect(label).toHaveAttribute('for');
34
50
  });
35
51
 
52
+ test('supports required prop', () => {
53
+ render(
54
+ <ThemeProvider theme={theme}>
55
+ <Label htmlFor="labelId" required>
56
+ label
57
+ </Label>
58
+ </ThemeProvider>
59
+ );
60
+ const label = screen.getByText(/label/);
61
+ const parent = label.parentElement;
62
+
63
+ expect(parent instanceof HTMLSpanElement).toBeTruthy();
64
+ });
65
+
36
66
  test('renders <label> element', () => {
37
67
  render(
38
- <MarigoldProvider theme={theme}>
68
+ <ThemeProvider theme={theme}>
39
69
  <Label htmlFor="labelId">label</Label>
40
- </MarigoldProvider>
70
+ </ThemeProvider>
41
71
  );
42
72
  const label = screen.getByText(/label/);
43
73
 
44
74
  expect(label instanceof HTMLLabelElement).toBeTruthy();
45
75
  });
46
76
 
47
- test('variant styles cannot be overridden with CSS prop', () => {
77
+ test('accepts custom styles prop className', () => {
48
78
  render(
49
- <MarigoldProvider theme={theme}>
50
- <Label htmlFor="labelId" css={{ fontFamily: 'Oswald Regular' }}>
79
+ <ThemeProvider theme={theme}>
80
+ <Label htmlFor="labelId" className="custom-class-name" title="label">
51
81
  label
52
82
  </Label>
53
- </MarigoldProvider>
83
+ </ThemeProvider>
54
84
  );
55
- const label = screen.getByText(/label/);
85
+ const label = screen.getByTitle(/label/);
56
86
 
57
- expect(label).not.toHaveStyle(`font-family: Oswald Regular`);
58
- expect(label).toHaveStyle(`font-family: Inter Regular`);
87
+ expect(label.className).toMatch('custom-class-name');
59
88
  });
@@ -1,22 +1,31 @@
1
1
  import React from 'react';
2
- import { system, Box } from '@marigold/system';
2
+ import { ComponentProps } from '@marigold/types';
3
+ import { Required } from '@marigold/icons';
3
4
 
4
- type LabelProps = {
5
- htmlFor: string;
6
- };
5
+ import { Box } from '../Box';
6
+
7
+ export type LabelProps = {
8
+ htmlFor?: string;
9
+ variant?: string;
10
+ required?: boolean;
11
+ } & ComponentProps<'label'>;
7
12
 
8
- export const Label = system<LabelProps, 'label'>(
9
- ({ variant = 'label', htmlFor, children, ...props }) => {
10
- return (
11
- <Box
12
- as="label"
13
- themeSection="form"
14
- variant={variant}
15
- htmlFor={htmlFor}
16
- {...props}
17
- >
13
+ export const Label: React.FC<LabelProps> = ({
14
+ variant = 'above',
15
+ required,
16
+ children,
17
+ ...props
18
+ }) => {
19
+ return required ? (
20
+ <Box as="span" display="inline-flex" alignItems="center">
21
+ <Box {...props} as="label" variant={`label.${variant}`}>
18
22
  {children}
19
23
  </Box>
20
- );
21
- }
22
- );
24
+ {required && <Box as={Required} size={16} css={{ color: 'red60' }} />}
25
+ </Box>
26
+ ) : (
27
+ <Box {...props} as="label" variant={`label.${variant}`}>
28
+ {children}
29
+ </Box>
30
+ );
31
+ };