@marigold/components 0.2.0 → 0.3.3

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 (201) hide show
  1. package/CHANGELOG.md +180 -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 +7 -1
  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 +7 -3
  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 +3 -0
  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 +9 -5
  47. package/dist/Radio/Radio.stories.d.ts +5 -0
  48. package/dist/Radio/RadioIcon.d.ts +9 -0
  49. package/dist/Select/ListBox.d.ts +1 -0
  50. package/dist/Select/ListBoxSection.d.ts +1 -0
  51. package/dist/Select/Option.d.ts +1 -0
  52. package/dist/Select/Select.d.ts +15 -1
  53. package/dist/Select/Select.stories.d.ts +5 -0
  54. package/dist/Slider/Slider.d.ts +5 -0
  55. package/dist/Slider/Slider.stories.d.ts +5 -0
  56. package/dist/Stack/Stack.stories.d.ts +5 -0
  57. package/dist/Text/Text.d.ts +5 -0
  58. package/dist/Text/Text.stories.d.ts +5 -0
  59. package/dist/Textarea/Textarea.d.ts +5 -0
  60. package/dist/Textarea/Textarea.stories.d.ts +5 -0
  61. package/dist/ValidationMessage/ValidationMessage.d.ts +5 -0
  62. package/dist/ValidationMessage/ValidationMessage.stories.d.ts +5 -0
  63. package/dist/VisuallyHidden/VisuallyHidden.d.ts +1 -0
  64. package/dist/VisuallyHidden/VisuallyHidden.stories.d.ts +5 -0
  65. package/dist/VisuallyHidden/index.d.ts +1 -0
  66. package/dist/components.cjs.development.js +536 -580
  67. package/dist/components.cjs.development.js.map +1 -1
  68. package/dist/components.cjs.production.min.js +1 -1
  69. package/dist/components.cjs.production.min.js.map +1 -1
  70. package/dist/components.esm.js +481 -535
  71. package/dist/components.esm.js.map +1 -1
  72. package/dist/index.d.ts +2 -2
  73. package/dist/theme.d.ts +23 -48
  74. package/package.json +8 -4
  75. package/src/ActionGroup/ActionGroup.stories.tsx +47 -0
  76. package/src/ActionGroup/ActionGroup.test.tsx +36 -36
  77. package/src/ActionGroup/ActionGroup.tsx +17 -28
  78. package/src/Alert/Alert.stories.tsx +32 -0
  79. package/src/Alert/Alert.test.tsx +4 -1
  80. package/src/Alert/Alert.tsx +18 -3
  81. package/src/Badge/Badge.stories.tsx +38 -0
  82. package/src/Badge/Badge.test.tsx +5 -1
  83. package/src/Badge/Badge.tsx +13 -1
  84. package/src/Box.ts +2 -0
  85. package/src/Button/{Button.stories.mdx → Button.stories.tsx} +10 -17
  86. package/src/Button/Button.test.tsx +34 -11
  87. package/src/Button/Button.tsx +17 -3
  88. package/src/Card/{Card.stories.mdx → Card.stories.tsx} +9 -17
  89. package/src/Card/Card.test.tsx +8 -3
  90. package/src/Card/Card.tsx +13 -1
  91. package/src/Checkbox/{Checkbox.stories.mdx → Checkbox.stories.tsx} +31 -39
  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/Column/Column.tsx +0 -0
  97. package/src/Columns/Columns.stories.tsx +75 -0
  98. package/src/Columns/Columns.test.tsx +34 -23
  99. package/src/Columns/Columns.tsx +30 -30
  100. package/src/Container/Container.stories.tsx +14 -0
  101. package/src/Container/Container.tsx +0 -0
  102. package/src/Dialog/{Dialog.stories.mdx → Dialog.stories.tsx} +33 -18
  103. package/src/Dialog/Dialog.test.tsx +91 -20
  104. package/src/Dialog/Dialog.tsx +63 -17
  105. package/src/Dialog/ModalDialog.tsx +33 -4
  106. package/src/Divider/Divider.stories.tsx +30 -0
  107. package/src/Divider/Divider.test.tsx +32 -23
  108. package/src/Divider/Divider.tsx +27 -7
  109. package/src/Field/{Field.stories.mdx → Field.stories.tsx} +33 -20
  110. package/src/Field/Field.test.tsx +55 -5
  111. package/src/Field/Field.tsx +10 -8
  112. package/src/Image/Image.stories.tsx +34 -0
  113. package/src/Image/Image.test.tsx +4 -1
  114. package/src/Image/Image.tsx +13 -1
  115. package/src/Inline/Inline.stories.tsx +39 -0
  116. package/src/Inline/Inline.test.tsx +99 -0
  117. package/src/Inline/Inline.tsx +38 -0
  118. package/src/Inline/index.ts +1 -0
  119. package/src/Input/{Input.stories.mdx → Input.stories.tsx} +10 -17
  120. package/src/Input/Input.test.tsx +7 -3
  121. package/src/Input/Input.tsx +13 -1
  122. package/src/Label/{Label.stories.mdx → Label.stories.tsx} +10 -21
  123. package/src/Label/Label.test.tsx +25 -4
  124. package/src/Label/Label.tsx +42 -9
  125. package/src/Link/Link.stories.tsx +35 -0
  126. package/src/Link/Link.test.tsx +6 -2
  127. package/src/Link/Link.tsx +12 -1
  128. package/src/Menu/{Menu.stories.mdx → Menu.stories.tsx} +13 -32
  129. package/src/Menu/Menu.test.tsx +7 -2
  130. package/src/Menu/Menu.tsx +10 -0
  131. package/src/MenuItem/MenuItem.stories.tsx +30 -0
  132. package/src/MenuItem/MenuItem.test.tsx +7 -2
  133. package/src/MenuItem/MenuItem.tsx +12 -0
  134. package/src/Message/Message.stories.tsx +30 -0
  135. package/src/Message/Message.test.tsx +4 -1
  136. package/src/Message/Message.tsx +17 -5
  137. package/src/Provider/MarigoldProvider.test.tsx +65 -55
  138. package/src/Provider/MarigoldProvider.tsx +37 -19
  139. package/src/Provider/index.ts +2 -1
  140. package/src/Radio/{Radio.stories.mdx → Radio.stories.tsx} +31 -39
  141. package/src/Radio/Radio.test.tsx +78 -9
  142. package/src/Radio/Radio.tsx +58 -87
  143. package/src/Radio/RadioIcon.tsx +49 -0
  144. package/src/Select/ListBox.tsx +1 -0
  145. package/src/Select/{Select.stories.mdx → Select.stories.tsx} +23 -20
  146. package/src/Select/Select.test.tsx +39 -1
  147. package/src/Select/Select.tsx +24 -13
  148. package/src/Slider/Slider.stories.tsx +24 -0
  149. package/src/Slider/Slider.test.tsx +10 -6
  150. package/src/Slider/Slider.tsx +25 -13
  151. package/src/Stack/Stack.stories.tsx +57 -0
  152. package/src/Stack/Stack.test.tsx +16 -7
  153. package/src/Stack/Stack.tsx +0 -0
  154. package/src/Text/{Text.stories.mdx → Text.stories.tsx} +20 -19
  155. package/src/Text/Text.test.tsx +2 -2
  156. package/src/Text/Text.tsx +12 -0
  157. package/src/Textarea/{Textarea.stories.mdx → Textarea.stories.tsx} +14 -24
  158. package/src/Textarea/Textarea.test.tsx +7 -3
  159. package/src/Textarea/Textarea.tsx +13 -1
  160. package/src/ValidationMessage/{ValidationMessage.stories.mdx → ValidationMessage.stories.tsx} +8 -17
  161. package/src/ValidationMessage/ValidationMessage.test.tsx +7 -2
  162. package/src/ValidationMessage/ValidationMessage.tsx +12 -0
  163. package/src/VisuallyHidden/VisuallyHidden.stories.tsx +19 -0
  164. package/src/VisuallyHidden/VisuallyHidden.test.tsx +10 -0
  165. package/src/VisuallyHidden/VisuallyHidden.tsx +1 -0
  166. package/src/VisuallyHidden/index.ts +1 -0
  167. package/src/index.ts +2 -2
  168. package/src/theme.ts +49 -48
  169. package/dist/Box/Box.d.ts +0 -47
  170. package/dist/Box/index.d.ts +0 -1
  171. package/dist/Heading/Heading.d.ts +0 -7
  172. package/dist/Heading/index.d.ts +0 -1
  173. package/dist/Hidden/Hidden.d.ts +0 -5
  174. package/dist/Hidden/index.d.ts +0 -1
  175. package/dist/Radio/RadioIcons.d.ts +0 -9
  176. package/src/ActionGroup/ActionGroup.stories.mdx +0 -62
  177. package/src/Alert/Alert.stories.mdx +0 -35
  178. package/src/Badge/Badge.stories.mdx +0 -57
  179. package/src/Box/Box.stories.mdx +0 -334
  180. package/src/Box/Box.test.tsx +0 -133
  181. package/src/Box/Box.tsx +0 -165
  182. package/src/Box/index.ts +0 -1
  183. package/src/Column/Column.stories.mdx +0 -49
  184. package/src/Columns/Columns.stories.mdx +0 -65
  185. package/src/Container/Container.stories.mdx +0 -19
  186. package/src/Divider/Divider.stories.mdx +0 -37
  187. package/src/Heading/Heading.stories.mdx +0 -39
  188. package/src/Heading/Heading.test.tsx +0 -77
  189. package/src/Heading/Heading.tsx +0 -19
  190. package/src/Heading/index.ts +0 -1
  191. package/src/Hidden/Hidden.stories.mdx +0 -39
  192. package/src/Hidden/Hidden.test.tsx +0 -24
  193. package/src/Hidden/Hidden.tsx +0 -16
  194. package/src/Hidden/index.ts +0 -1
  195. package/src/Image/Image.stories.mdx +0 -36
  196. package/src/Link/Link.stories.mdx +0 -45
  197. package/src/MenuItem/MenuItem.stories.mdx +0 -37
  198. package/src/Message/Message.stories.mdx +0 -44
  199. package/src/Radio/RadioIcons.tsx +0 -39
  200. package/src/Slider/Slider.stories.mdx +0 -31
  201. package/src/Stack/Stack.stories.mdx +0 -51
@@ -0,0 +1,49 @@
1
+ import React from 'react';
2
+ import { conditional, State, SVG } from '@marigold/system';
3
+
4
+ import { Box } from '../Box';
5
+
6
+ // Radio Icon
7
+ // ---------------
8
+ export type RadioIconProps = {
9
+ variant?: string;
10
+ checked?: boolean;
11
+ disabled?: boolean;
12
+ error?: boolean;
13
+ children?: never;
14
+ };
15
+
16
+ export const RadioIcon: React.FC<RadioIconProps> = ({
17
+ variant = '',
18
+ checked = false,
19
+ disabled = false,
20
+ error = false,
21
+ }) => {
22
+ const conditionalStates: State = disabled
23
+ ? {
24
+ disabled: disabled,
25
+ }
26
+ : {
27
+ checked: checked,
28
+ error: error,
29
+ };
30
+
31
+ return (
32
+ <SVG
33
+ width="16"
34
+ height="32"
35
+ viewBox="0 0 16 32"
36
+ fill="none"
37
+ aria-hidden="true"
38
+ >
39
+ <Box
40
+ variant={conditional(`radio.${variant}`, conditionalStates)}
41
+ as="circle"
42
+ cx="8"
43
+ cy="16"
44
+ r="7.5"
45
+ />
46
+ {checked && <circle fill="white" cx="8" cy="16" r="3" />}
47
+ </SVG>
48
+ );
49
+ };
@@ -20,6 +20,7 @@ export const ListBox = (props: ListBoxProps) => {
20
20
  return (
21
21
  <Box
22
22
  as="ul"
23
+ p="none"
23
24
  css={{
24
25
  listStyle: 'none',
25
26
  }}
@@ -1,10 +1,22 @@
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 { Select } from './Select';
3
4
  import { Item } from '@marigold/components';
4
5
 
5
- <Meta
6
- title="Components/Select"
7
- argTypes={{
6
+ export default {
7
+ title: 'Components/Select',
8
+ argTypes: {
9
+ label: {
10
+ control: {
11
+ type: 'text',
12
+ },
13
+ table: {
14
+ defaultValue: {
15
+ summary: 'Select label',
16
+ },
17
+ },
18
+ defaultValue: 'Favorite Color',
19
+ },
8
20
  placeholder: {
9
21
  control: {
10
22
  type: 'text',
@@ -57,22 +69,13 @@ import { Item } from '@marigold/components';
57
69
  width: {
58
70
  control: 'number',
59
71
  },
60
- }}
61
- />
62
-
63
- # Select
72
+ },
73
+ } as Meta;
64
74
 
65
- export const Template = args => (
66
- <Select label="Favorite Color" htmlFor="id" {...args}>
67
- {/* Storybook crashes with imported <Item> component
68
- <Item>Red</Item>
69
- <Item>Orange</Item>
70
- <Item>Yellow</Item> */}
75
+ export const Basic: ComponentStory<typeof Select> = args => (
76
+ <Select {...args}>
77
+ <Item>Red</Item>
78
+ <Item>Orange</Item>
79
+ <Item>Yellow</Item>
71
80
  </Select>
72
81
  );
73
-
74
- <Canvas>
75
- <Story name="Default">{Template.bind({})}</Story>
76
- </Canvas>
77
-
78
- <ArgsTable story="Default" />
@@ -6,14 +6,28 @@ import { Item, MarigoldProvider, Section } from '..';
6
6
  import { Select } from './Select';
7
7
 
8
8
  const theme = {
9
+ colors: {
10
+ red: 'red',
11
+ },
12
+ fonts: {
13
+ body: 'Inter',
14
+ },
9
15
  button: {
10
16
  select: {
11
- fontFamily: 'Inter',
17
+ fontFamily: 'body',
12
18
  errorOpened: {
13
19
  color: 'red',
14
20
  },
15
21
  },
16
22
  },
23
+ label: {
24
+ above: {
25
+ fontSize: '8px',
26
+ },
27
+ inline: {
28
+ fontSize: '14px',
29
+ },
30
+ },
17
31
  };
18
32
 
19
33
  test('supports button select variant', () => {
@@ -29,6 +43,30 @@ test('supports button select variant', () => {
29
43
  expect(select).toHaveStyle(`font-family: Inter`);
30
44
  });
31
45
 
46
+ test('supports default labelVariant', () => {
47
+ render(
48
+ <MarigoldProvider theme={theme}>
49
+ <Select label="MyLabel" data-testid="selectId">
50
+ <Item>1</Item>
51
+ </Select>
52
+ </MarigoldProvider>
53
+ );
54
+ const label = screen.getAllByText('MyLabel');
55
+ expect(label[0]).toHaveStyle(`font-size: 8px`);
56
+ });
57
+
58
+ test('supports other labelVariant than default', () => {
59
+ render(
60
+ <MarigoldProvider theme={theme}>
61
+ <Select label="MyLabel" data-testid="selectId" labelVariant="inline">
62
+ <Item>1</Item>
63
+ </Select>
64
+ </MarigoldProvider>
65
+ );
66
+ const label = screen.getAllByText('MyLabel');
67
+ expect(label[0]).toHaveStyle(`font-size: 14px`);
68
+ });
69
+
32
70
  test('accepts custom styles prop className', () => {
33
71
  render(
34
72
  <MarigoldProvider theme={theme}>
@@ -19,7 +19,25 @@ import { ValidationMessage } from '../ValidationMessage';
19
19
  import { ListBox } from './ListBox';
20
20
  import { Popover } from './Popover';
21
21
 
22
+ // Theme Extension
23
+ // ---------------
24
+ export interface SelectThemeExtension<Value> {
25
+ select?: {
26
+ __default: Value;
27
+ disabled?: Value;
28
+ listbox?: {
29
+ __default: Value;
30
+ error?: Value;
31
+ };
32
+ section?: Value;
33
+ option?: Value;
34
+ };
35
+ }
36
+
37
+ // Props
38
+ // ---------------
22
39
  export type SelectProps = {
40
+ labelVariant?: string;
23
41
  placeholder?: string;
24
42
  disabled?: boolean;
25
43
  required?: boolean;
@@ -30,7 +48,10 @@ export type SelectProps = {
30
48
  AriaSelectProps<object> &
31
49
  SingleSelection;
32
50
 
51
+ // Component
52
+ // ---------------
33
53
  export const Select = ({
54
+ labelVariant = 'above',
34
55
  placeholder = 'Select an option',
35
56
  disabled,
36
57
  required,
@@ -75,11 +96,7 @@ export const Select = ({
75
96
  <Box position="relative" display="inline-block" width={width && width}>
76
97
  {props.label && (
77
98
  <Box>
78
- <Label
79
- {...labelProps}
80
- htmlFor={labelProps.id}
81
- variant={disabled ? 'disabled' : 'above'}
82
- >
99
+ <Label {...labelProps} htmlFor={labelProps.id} variant={labelVariant}>
83
100
  {required ? (
84
101
  <Box as="span" display="inline-flex" alignItems="center">
85
102
  {props.label}
@@ -122,11 +139,7 @@ export const Select = ({
122
139
  {state.selectedItem ? state.selectedItem.rendered : placeholder}
123
140
  </Box>
124
141
  {state.isOpen && !disabled ? (
125
- <Box
126
- as={ArrowUp}
127
- size={16}
128
- css={{ fill: disabled ? 'disabled' : 'text' }}
129
- />
142
+ <Box as={ArrowUp} size={16} css={{ fill: 'text' }} />
130
143
  ) : (
131
144
  <Box
132
145
  as={ArrowDown}
@@ -141,9 +154,7 @@ export const Select = ({
141
154
  {...overlayProps}
142
155
  {...positionProps}
143
156
  css={{
144
- width: width
145
- ? width
146
- : triggerRef.current && triggerRef.current.offsetWidth + 'px',
157
+ width: triggerRef.current && triggerRef.current.offsetWidth + 'px',
147
158
  }}
148
159
  ref={overlayRef as Ref<HTMLDivElement>}
149
160
  isOpen={state.isOpen}
@@ -0,0 +1,24 @@
1
+ import React from 'react';
2
+ import type { Meta, ComponentStory } from '@storybook/react';
3
+ import { Slider } from './Slider';
4
+
5
+ export default {
6
+ title: 'Components/Slider',
7
+ argTypes: {
8
+ variant: {
9
+ control: {
10
+ type: 'text',
11
+ },
12
+ description: 'Style',
13
+ table: {
14
+ defaultValue: {
15
+ summary: '__default',
16
+ },
17
+ },
18
+ },
19
+ },
20
+ } as Meta;
21
+
22
+ export const Basic: ComponentStory<typeof Slider> = args => (
23
+ <Slider name="vol" min="0" max="50" {...args} />
24
+ );
@@ -4,12 +4,16 @@ import { ThemeProvider } from '@marigold/system';
4
4
  import { Slider } from './Slider';
5
5
 
6
6
  const theme = {
7
- form: {
8
- slider: {
9
- fontFamily: 'Oswald Regular',
7
+ fonts: {
8
+ regular: 'Oswald Regular',
9
+ body: 'Inter',
10
+ },
11
+ slider: {
12
+ __default: {
13
+ fontFamily: 'regular',
10
14
  },
11
- range: {
12
- fontFamily: 'Inter',
15
+ special: {
16
+ fontFamily: 'body',
13
17
  },
14
18
  },
15
19
  };
@@ -28,7 +32,7 @@ test('supports default variant and themeSection', () => {
28
32
  test('accepts other variant than default', () => {
29
33
  render(
30
34
  <ThemeProvider theme={theme}>
31
- <Slider variant="range" title="slider" />
35
+ <Slider variant="special" title="slider" />
32
36
  </ThemeProvider>
33
37
  );
34
38
  const slider = screen.getByTitle(/slider/);
@@ -1,23 +1,35 @@
1
1
  import React from 'react';
2
- import { useStyles } from '@marigold/system';
3
2
  import { ComponentProps } from '@marigold/types';
4
3
 
4
+ import { Box } from '../Box';
5
+
6
+ // Theme Extension
7
+ // ---------------
8
+ export interface SliderThemeExtension<Value> {
9
+ slider?: {
10
+ [key: string]: Value;
11
+ };
12
+ }
13
+
14
+ // Props
15
+ // ---------------
5
16
  export type SliderProps = {
6
17
  variant?: string;
7
18
  } & ComponentProps<'input'>;
8
19
 
20
+ // Component
21
+ // ---------------
9
22
  export const Slider: React.FC<SliderProps> = ({
10
- variant = 'slider',
23
+ variant = '',
11
24
  className,
12
25
  ...props
13
- }) => {
14
- const classNames = useStyles({
15
- variant: `form.${variant}`,
16
- css: {
17
- verticalAlign: 'middle',
18
- },
19
- className,
20
- });
21
-
22
- return <input type="range" className={classNames} {...props} />;
23
- };
26
+ }) => (
27
+ <Box
28
+ as="input"
29
+ type="range"
30
+ css={{ verticalAlign: 'middle' }}
31
+ variant={`slider.${variant}`}
32
+ className={className}
33
+ {...props}
34
+ />
35
+ );
@@ -0,0 +1,57 @@
1
+ import React from 'react';
2
+ import type { Meta, ComponentStory } from '@storybook/react';
3
+ import { Stack } from './Stack';
4
+ import { Text } from '../Text';
5
+
6
+ export default {
7
+ title: 'Components/Stack',
8
+ argTypes: {
9
+ space: {
10
+ control: {
11
+ type: 'select',
12
+ },
13
+ options: [
14
+ 'none',
15
+ 'xxsmall',
16
+ 'xsmall',
17
+ 'small',
18
+ 'medium',
19
+ 'large',
20
+ 'xlarge',
21
+ 'xxlarge',
22
+ ],
23
+ description: 'Responsive Style Value',
24
+ table: {
25
+ defaultValue: {
26
+ summary: 'none',
27
+ },
28
+ },
29
+ },
30
+ align: {
31
+ control: {
32
+ type: 'select',
33
+ },
34
+ options: ['left', 'right', 'center'],
35
+ description: 'HTML element style',
36
+ table: {
37
+ defaultValue: {
38
+ summary: 'left',
39
+ },
40
+ },
41
+ },
42
+ },
43
+ } as Meta;
44
+
45
+ export const Basic: ComponentStory<typeof Stack> = args => (
46
+ <Stack {...args}>
47
+ <Text as="h2" variant="headline2">
48
+ Heading
49
+ </Text>
50
+ <Text>
51
+ Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse
52
+ dignissim dapibus elit, vel egestas felis pharetra non. Cras malesuada,
53
+ massa nec ultricies efficitur, lectus ante consequat magna, a porttitor
54
+ massa ex ut quam.
55
+ </Text>
56
+ </Stack>
57
+ );
@@ -16,20 +16,26 @@ const theme = {
16
16
  },
17
17
  };
18
18
 
19
+ const getTopPadding = (element: HTMLElement) =>
20
+ getComputedStyle(element).getPropertyValue('padding-top');
21
+
19
22
  test('default space is "none"', () => {
20
23
  render(
21
24
  <ThemeProvider theme={theme}>
22
25
  <Stack>
23
26
  <Text>first</Text>
24
27
  <Text>second</Text>
28
+ <Text>third</Text>
25
29
  </Stack>
26
30
  </ThemeProvider>
27
31
  );
28
- const first = screen.getByText(/first/);
29
- const second = screen.getByText(/second/);
32
+ const first = screen.getByText(/first/).parentElement!;
33
+ const second = screen.getByText(/second/).parentElement!;
34
+ const third = screen.getByText(/third/).parentElement!;
30
35
 
31
- expect(first).toHaveStyle(`padding-top: 0px`);
36
+ expect(getTopPadding(first)).toEqual('');
32
37
  expect(second).toHaveStyle(`padding-top: 0px`);
38
+ expect(third).toHaveStyle(`padding-top: 0px`);
33
39
  });
34
40
 
35
41
  test('accepts and uses spacing from theme', () => {
@@ -38,14 +44,17 @@ test('accepts and uses spacing from theme', () => {
38
44
  <Stack space="small">
39
45
  <Text>first</Text>
40
46
  <Text>second</Text>
47
+ <Text>third</Text>
41
48
  </Stack>
42
49
  </ThemeProvider>
43
50
  );
44
51
  const first = screen.getByText(/first/);
45
52
  const second = screen.getByText(/second/);
53
+ const third = screen.getByText(/third/);
46
54
 
47
- expect(first.parentElement).toHaveStyle(`padding-top: 0px`);
55
+ expect(getTopPadding(first)).toEqual('');
48
56
  expect(second.parentElement).toHaveStyle(`padding-top: 2px`);
57
+ expect(third.parentElement).toHaveStyle(`padding-top: 2px`);
49
58
  });
50
59
 
51
60
  test('aligns children left by default', () => {
@@ -104,13 +113,13 @@ test('supports nesting', () => {
104
113
  const fourth = screen.getByText(/fourth/);
105
114
  const lowerStack = screen.getByTestId('lowerStack');
106
115
 
107
- expect(upperStack.parentElement).toHaveStyle(`padding-top: 0px`);
116
+ expect(getTopPadding(upperStack.parentElement!)).toEqual('');
108
117
  expect(lowerStack.parentElement).toHaveStyle(`padding-top: 8px`);
109
118
 
110
- expect(first.parentElement).toHaveStyle(`padding-top: 0px`);
119
+ expect(getTopPadding(first.parentElement!)).toEqual('');
111
120
  expect(second.parentElement).toHaveStyle(`padding-top: 2px`);
112
121
 
113
- expect(third.parentElement).toHaveStyle(`padding-top: 0px`);
122
+ expect(getTopPadding(third.parentElement!)).toEqual('');
114
123
  expect(fourth.parentElement).toHaveStyle(`padding-top: 2px`);
115
124
  });
116
125
 
File without changes
@@ -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 { Text } from './Text';
3
4
 
4
- <Meta
5
- title="Components/Text"
6
- argTypes={{
5
+ export default {
6
+ title: 'Components/Text',
7
+ argTypes: {
7
8
  as: {
8
9
  control: {
9
10
  type: 'select',
10
11
  },
11
- options: ['span', 'p'],
12
- description: 'Set inline',
12
+ options: ['span', 'p', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6'],
13
+ description: 'Set HTML element',
13
14
  table: {
14
15
  defaultValue: {
15
16
  summary: 'span',
@@ -20,8 +21,16 @@ import { Text } from './Text';
20
21
  control: {
21
22
  type: 'select',
22
23
  },
23
- options: ['body', 'heading'],
24
- description: 'Doesnt matter',
24
+ options: [
25
+ 'body',
26
+ 'headline1',
27
+ 'headline2',
28
+ 'headline3',
29
+ 'headline4',
30
+ 'headline5',
31
+ 'headline6',
32
+ ],
33
+ description: 'CHoose between body and different headlines',
25
34
  table: {
26
35
  defaultValue: {
27
36
  summary: 'body',
@@ -39,12 +48,10 @@ import { Text } from './Text';
39
48
  },
40
49
  },
41
50
  },
42
- }}
43
- />
51
+ },
52
+ } as Meta;
44
53
 
45
- # Text
46
-
47
- export const Template = args => (
54
+ export const Basic: ComponentStory<typeof Text> = args => (
48
55
  <Text {...args}>
49
56
  Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse
50
57
  dignissim dapibus elit, vel egestas felis pharetra non. Cras malesuada,
@@ -52,9 +59,3 @@ export const Template = args => (
52
59
  massa ex ut quam.
53
60
  </Text>
54
61
  );
55
-
56
- <Canvas>
57
- <Story name="Default">{Template.bind({})}</Story>
58
- </Canvas>
59
-
60
- <ArgsTable story="Default" />
@@ -15,7 +15,7 @@ const theme = {
15
15
  body: {
16
16
  fontFamily: 'Oswald Regular',
17
17
  },
18
- heading: {
18
+ headline1: {
19
19
  fontFamily: 'Inter',
20
20
  },
21
21
  },
@@ -35,7 +35,7 @@ test('uses `text.body` as default variant', () => {
35
35
  test('allows to change variants via `variant` prop (with "text" prefix)', () => {
36
36
  render(
37
37
  <ThemeProvider theme={theme}>
38
- <Text variant="heading">text</Text>
38
+ <Text variant="headline1">text</Text>
39
39
  </ThemeProvider>
40
40
  );
41
41
  const text = screen.getByText(/text/);
package/src/Text/Text.tsx CHANGED
@@ -7,6 +7,16 @@ import {
7
7
 
8
8
  import { Box, BoxOwnProps } from '../Box';
9
9
 
10
+ // Theme Extension
11
+ // ---------------
12
+ export interface TextThemeExtension<Value> {
13
+ text?: {
14
+ [key: string]: Value;
15
+ };
16
+ }
17
+
18
+ // Props
19
+ // ---------------
10
20
  export type TextOwnProps = {
11
21
  align?: ResponsiveStyleValue<string>;
12
22
  color?: ResponsiveStyleValue<string>;
@@ -17,6 +27,8 @@ export type TextOwnProps = {
17
27
 
18
28
  export type TextProps = PolymorphicPropsWithRef<TextOwnProps, 'span'>;
19
29
 
30
+ // Component
31
+ // ---------------
20
32
  export const Text: PolymorphicComponentWithRef<TextOwnProps, 'span'> =
21
33
  forwardRef(
22
34
  (
@@ -1,16 +1,17 @@
1
- import { ArgsTable, Canvas, Meta, Story } from '@storybook/addon-docs';
2
- import { Textarea } from '../Textarea';
1
+ import React from 'react';
2
+ import type { Meta, ComponentStory } from '@storybook/react';
3
+ import { Textarea } from '.';
3
4
 
4
- <Meta
5
- title="Components/Textarea"
6
- argTypes={{
5
+ export default {
6
+ title: 'Components/Textarea',
7
+ argTypes: {
7
8
  variant: {
8
9
  control: {
9
10
  type: 'text',
10
11
  },
11
12
  table: {
12
13
  defaultValue: {
13
- summary: 'default',
14
+ summary: '__default',
14
15
  },
15
16
  },
16
17
  },
@@ -18,18 +19,15 @@ import { Textarea } from '../Textarea';
18
19
  control: {
19
20
  type: 'text',
20
21
  },
21
- description: 'Text above',
22
+ description: 'Label text',
23
+ defaultValue: 'Textarea Label',
22
24
  },
23
25
  htmlFor: {
24
26
  control: {
25
27
  type: 'text',
26
28
  },
27
29
  description: 'Bind to label',
28
- table: {
29
- defaultValue: {
30
- summary: 'textarea',
31
- },
32
- },
30
+ defaultValue: 'textareaId',
33
31
  },
34
32
  error: {
35
33
  control: {
@@ -58,17 +56,9 @@ import { Textarea } from '../Textarea';
58
56
  },
59
57
  },
60
58
  },
61
- }}
62
- />
59
+ },
60
+ } as Meta;
63
61
 
64
- # Textarea
65
-
66
- export const Template = args => (
67
- <Textarea placeholder="Placeholder..." label="Textarea Label" {...args} />
62
+ export const Basic: ComponentStory<typeof Textarea> = args => (
63
+ <Textarea placeholder="Placeholder..." {...args} />
68
64
  );
69
-
70
- <Canvas>
71
- <Story name="Default">{Template.bind({})}</Story>
72
- </Canvas>
73
-
74
- <ArgsTable story="Default" />
@@ -4,12 +4,16 @@ import { ThemeProvider } from '@marigold/system';
4
4
  import { Textarea } from '../Textarea';
5
5
 
6
6
  const theme = {
7
+ fonts: {
8
+ body: 'Inter Regular',
9
+ fancy: 'Roboto',
10
+ },
7
11
  textarea: {
8
- default: {
9
- fontFamily: 'Inter Regular',
12
+ __default: {
13
+ fontFamily: 'body',
10
14
  },
11
15
  textarea2: {
12
- fontFamily: 'Roboto',
16
+ fontFamily: 'fancy',
13
17
  },
14
18
  },
15
19
  };