@marigold/components 0.3.2 → 0.5.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 (232) hide show
  1. package/CHANGELOG.md +37 -0
  2. package/dist/index.d.ts +362 -32
  3. package/dist/index.js +1407 -5
  4. package/dist/index.mjs +1355 -0
  5. package/package.json +30 -11
  6. package/dist/ActionGroup/ActionGroup.d.ts +0 -8
  7. package/dist/ActionGroup/ActionGroup.stories.d.ts +0 -5
  8. package/dist/ActionGroup/index.d.ts +0 -1
  9. package/dist/Alert/Alert.d.ts +0 -27
  10. package/dist/Alert/Alert.stories.d.ts +0 -5
  11. package/dist/Alert/index.d.ts +0 -1
  12. package/dist/Badge/Badge.d.ts +0 -13
  13. package/dist/Badge/Badge.stories.d.ts +0 -5
  14. package/dist/Badge/index.d.ts +0 -1
  15. package/dist/Box.d.ts +0 -2
  16. package/dist/Button/Button.d.ts +0 -9
  17. package/dist/Button/Button.stories.d.ts +0 -5
  18. package/dist/Button/index.d.ts +0 -1
  19. package/dist/Card/Card.d.ts +0 -14
  20. package/dist/Card/Card.stories.d.ts +0 -5
  21. package/dist/Card/index.d.ts +0 -1
  22. package/dist/Checkbox/Checkbox.d.ts +0 -20
  23. package/dist/Checkbox/Checkbox.stories.d.ts +0 -5
  24. package/dist/Checkbox/CheckboxIcons.d.ts +0 -9
  25. package/dist/Checkbox/index.d.ts +0 -1
  26. package/dist/Column/Column.d.ts +0 -8
  27. package/dist/Column/Column.stories.d.ts +0 -5
  28. package/dist/Column/index.d.ts +0 -1
  29. package/dist/Columns/Columns.d.ts +0 -10
  30. package/dist/Columns/Columns.stories.d.ts +0 -5
  31. package/dist/Columns/index.d.ts +0 -1
  32. package/dist/Container/Container.d.ts +0 -6
  33. package/dist/Container/Container.stories.d.ts +0 -5
  34. package/dist/Container/index.d.ts +0 -1
  35. package/dist/Dialog/Dialog.d.ts +0 -17
  36. package/dist/Dialog/Dialog.stories.d.ts +0 -5
  37. package/dist/Dialog/ModalDialog.d.ts +0 -8
  38. package/dist/Dialog/index.d.ts +0 -1
  39. package/dist/Divider/Divider.d.ts +0 -11
  40. package/dist/Divider/Divider.stories.d.ts +0 -5
  41. package/dist/Divider/index.d.ts +0 -1
  42. package/dist/Field/Field.d.ts +0 -13
  43. package/dist/Field/Field.stories.d.ts +0 -5
  44. package/dist/Field/index.d.ts +0 -1
  45. package/dist/Image/Image.d.ts +0 -12
  46. package/dist/Image/Image.stories.d.ts +0 -5
  47. package/dist/Image/index.d.ts +0 -1
  48. package/dist/Inline/Inline.d.ts +0 -7
  49. package/dist/Inline/Inline.stories.d.ts +0 -5
  50. package/dist/Inline/index.d.ts +0 -1
  51. package/dist/Input/Input.d.ts +0 -11
  52. package/dist/Input/Input.stories.d.ts +0 -5
  53. package/dist/Input/index.d.ts +0 -1
  54. package/dist/Label/Label.d.ts +0 -19
  55. package/dist/Label/Label.stories.d.ts +0 -5
  56. package/dist/Label/index.d.ts +0 -1
  57. package/dist/Link/Link.d.ts +0 -10
  58. package/dist/Link/Link.stories.d.ts +0 -5
  59. package/dist/Link/index.d.ts +0 -1
  60. package/dist/Menu/Menu.d.ts +0 -15
  61. package/dist/Menu/Menu.stories.d.ts +0 -5
  62. package/dist/Menu/index.d.ts +0 -1
  63. package/dist/MenuItem/MenuItem.d.ts +0 -12
  64. package/dist/MenuItem/MenuItem.stories.d.ts +0 -5
  65. package/dist/MenuItem/index.d.ts +0 -1
  66. package/dist/Message/Message.d.ts +0 -12
  67. package/dist/Message/Message.stories.d.ts +0 -5
  68. package/dist/Message/index.d.ts +0 -1
  69. package/dist/Provider/MarigoldProvider.d.ts +0 -11
  70. package/dist/Provider/index.d.ts +0 -3
  71. package/dist/Radio/Radio.d.ts +0 -19
  72. package/dist/Radio/Radio.stories.d.ts +0 -5
  73. package/dist/Radio/RadioIcon.d.ts +0 -9
  74. package/dist/Radio/index.d.ts +0 -1
  75. package/dist/Select/ListBox.d.ts +0 -9
  76. package/dist/Select/ListBoxSection.d.ts +0 -9
  77. package/dist/Select/Option.d.ts +0 -9
  78. package/dist/Select/Popover.d.ts +0 -9
  79. package/dist/Select/Select.d.ts +0 -27
  80. package/dist/Select/Select.stories.d.ts +0 -5
  81. package/dist/Select/index.d.ts +0 -1
  82. package/dist/Slider/Slider.d.ts +0 -11
  83. package/dist/Slider/Slider.stories.d.ts +0 -5
  84. package/dist/Slider/index.d.ts +0 -1
  85. package/dist/Stack/Stack.d.ts +0 -7
  86. package/dist/Stack/Stack.stories.d.ts +0 -5
  87. package/dist/Stack/index.d.ts +0 -1
  88. package/dist/Text/Text.d.ts +0 -17
  89. package/dist/Text/Text.stories.d.ts +0 -5
  90. package/dist/Text/index.d.ts +0 -1
  91. package/dist/Textarea/Textarea.d.ts +0 -16
  92. package/dist/Textarea/Textarea.stories.d.ts +0 -5
  93. package/dist/Textarea/index.d.ts +0 -1
  94. package/dist/ValidationMessage/ValidationMessage.d.ts +0 -11
  95. package/dist/ValidationMessage/ValidationMessage.stories.d.ts +0 -5
  96. package/dist/ValidationMessage/index.d.ts +0 -1
  97. package/dist/VisuallyHidden/VisuallyHidden.d.ts +0 -1
  98. package/dist/VisuallyHidden/VisuallyHidden.stories.d.ts +0 -5
  99. package/dist/VisuallyHidden/index.d.ts +0 -1
  100. package/dist/components.cjs.development.js +0 -1394
  101. package/dist/components.cjs.development.js.map +0 -1
  102. package/dist/components.cjs.production.min.js +0 -2
  103. package/dist/components.cjs.production.min.js.map +0 -1
  104. package/dist/components.esm.js +0 -1320
  105. package/dist/components.esm.js.map +0 -1
  106. package/dist/theme.d.ts +0 -23
  107. package/src/ActionGroup/ActionGroup.stories.tsx +0 -47
  108. package/src/ActionGroup/ActionGroup.test.tsx +0 -83
  109. package/src/ActionGroup/ActionGroup.tsx +0 -32
  110. package/src/ActionGroup/index.ts +0 -1
  111. package/src/Alert/Alert.stories.tsx +0 -32
  112. package/src/Alert/Alert.test.tsx +0 -82
  113. package/src/Alert/Alert.tsx +0 -52
  114. package/src/Alert/index.ts +0 -1
  115. package/src/Badge/Badge.stories.tsx +0 -38
  116. package/src/Badge/Badge.test.tsx +0 -65
  117. package/src/Badge/Badge.tsx +0 -37
  118. package/src/Badge/index.ts +0 -1
  119. package/src/Box.ts +0 -2
  120. package/src/Button/Button.stories.tsx +0 -57
  121. package/src/Button/Button.test.tsx +0 -149
  122. package/src/Button/Button.tsx +0 -64
  123. package/src/Button/index.ts +0 -1
  124. package/src/Card/Card.stories.tsx +0 -41
  125. package/src/Card/Card.test.tsx +0 -71
  126. package/src/Card/Card.tsx +0 -48
  127. package/src/Card/index.ts +0 -1
  128. package/src/Checkbox/Checkbox.stories.tsx +0 -78
  129. package/src/Checkbox/Checkbox.test.tsx +0 -166
  130. package/src/Checkbox/Checkbox.tsx +0 -101
  131. package/src/Checkbox/CheckboxIcons.tsx +0 -59
  132. package/src/Checkbox/index.ts +0 -1
  133. package/src/Column/Column.stories.tsx +0 -33
  134. package/src/Column/Column.test.tsx +0 -32
  135. package/src/Column/Column.tsx +0 -27
  136. package/src/Column/index.ts +0 -1
  137. package/src/Columns/Columns.stories.tsx +0 -75
  138. package/src/Columns/Columns.test.tsx +0 -113
  139. package/src/Columns/Columns.tsx +0 -69
  140. package/src/Columns/index.ts +0 -1
  141. package/src/Container/Container.stories.tsx +0 -14
  142. package/src/Container/Container.test.tsx +0 -26
  143. package/src/Container/Container.tsx +0 -13
  144. package/src/Container/index.ts +0 -1
  145. package/src/Dialog/Dialog.stories.tsx +0 -88
  146. package/src/Dialog/Dialog.test.tsx +0 -158
  147. package/src/Dialog/Dialog.tsx +0 -130
  148. package/src/Dialog/ModalDialog.tsx +0 -76
  149. package/src/Dialog/index.ts +0 -1
  150. package/src/Divider/Divider.stories.tsx +0 -30
  151. package/src/Divider/Divider.test.tsx +0 -72
  152. package/src/Divider/Divider.tsx +0 -33
  153. package/src/Divider/index.ts +0 -1
  154. package/src/Field/Field.stories.tsx +0 -110
  155. package/src/Field/Field.test.tsx +0 -130
  156. package/src/Field/Field.tsx +0 -56
  157. package/src/Field/index.ts +0 -1
  158. package/src/Image/Image.stories.tsx +0 -34
  159. package/src/Image/Image.test.tsx +0 -73
  160. package/src/Image/Image.tsx +0 -25
  161. package/src/Image/index.ts +0 -1
  162. package/src/Inline/Inline.stories.tsx +0 -39
  163. package/src/Inline/Inline.test.tsx +0 -99
  164. package/src/Inline/Inline.tsx +0 -38
  165. package/src/Inline/index.ts +0 -1
  166. package/src/Input/Input.stories.tsx +0 -54
  167. package/src/Input/Input.test.tsx +0 -74
  168. package/src/Input/Input.tsx +0 -25
  169. package/src/Input/index.ts +0 -1
  170. package/src/Label/Label.stories.tsx +0 -41
  171. package/src/Label/Label.test.tsx +0 -109
  172. package/src/Label/Label.tsx +0 -64
  173. package/src/Label/index.ts +0 -1
  174. package/src/Link/Link.stories.tsx +0 -35
  175. package/src/Link/Link.test.tsx +0 -97
  176. package/src/Link/Link.tsx +0 -43
  177. package/src/Link/index.ts +0 -1
  178. package/src/Menu/Menu.stories.tsx +0 -62
  179. package/src/Menu/Menu.test.tsx +0 -84
  180. package/src/Menu/Menu.tsx +0 -51
  181. package/src/Menu/index.ts +0 -1
  182. package/src/MenuItem/MenuItem.stories.tsx +0 -30
  183. package/src/MenuItem/MenuItem.test.tsx +0 -68
  184. package/src/MenuItem/MenuItem.tsx +0 -35
  185. package/src/MenuItem/index.ts +0 -1
  186. package/src/Message/Message.stories.tsx +0 -30
  187. package/src/Message/Message.test.tsx +0 -90
  188. package/src/Message/Message.tsx +0 -55
  189. package/src/Message/index.ts +0 -1
  190. package/src/Provider/MarigoldProvider.test.tsx +0 -136
  191. package/src/Provider/MarigoldProvider.tsx +0 -47
  192. package/src/Provider/index.ts +0 -4
  193. package/src/Radio/Radio.stories.tsx +0 -78
  194. package/src/Radio/Radio.test.tsx +0 -154
  195. package/src/Radio/Radio.tsx +0 -88
  196. package/src/Radio/RadioIcon.tsx +0 -49
  197. package/src/Radio/index.ts +0 -1
  198. package/src/Select/ListBox.tsx +0 -40
  199. package/src/Select/ListBoxSection.tsx +0 -40
  200. package/src/Select/Option.tsx +0 -48
  201. package/src/Select/Popover.tsx +0 -50
  202. package/src/Select/Select.stories.tsx +0 -81
  203. package/src/Select/Select.test.tsx +0 -349
  204. package/src/Select/Select.tsx +0 -174
  205. package/src/Select/index.ts +0 -1
  206. package/src/Slider/Slider.stories.tsx +0 -24
  207. package/src/Slider/Slider.test.tsx +0 -63
  208. package/src/Slider/Slider.tsx +0 -35
  209. package/src/Slider/index.ts +0 -1
  210. package/src/Stack/Stack.stories.tsx +0 -57
  211. package/src/Stack/Stack.test.tsx +0 -138
  212. package/src/Stack/Stack.tsx +0 -39
  213. package/src/Stack/index.ts +0 -1
  214. package/src/Text/Text.stories.tsx +0 -61
  215. package/src/Text/Text.test.tsx +0 -99
  216. package/src/Text/Text.tsx +0 -60
  217. package/src/Text/index.ts +0 -1
  218. package/src/Textarea/Textarea.stories.tsx +0 -64
  219. package/src/Textarea/Textarea.test.tsx +0 -95
  220. package/src/Textarea/Textarea.tsx +0 -62
  221. package/src/Textarea/index.ts +0 -1
  222. package/src/ValidationMessage/ValidationMessage.stories.tsx +0 -27
  223. package/src/ValidationMessage/ValidationMessage.test.tsx +0 -68
  224. package/src/ValidationMessage/ValidationMessage.tsx +0 -40
  225. package/src/ValidationMessage/index.ts +0 -1
  226. package/src/VisuallyHidden/VisuallyHidden.stories.tsx +0 -19
  227. package/src/VisuallyHidden/VisuallyHidden.test.tsx +0 -10
  228. package/src/VisuallyHidden/VisuallyHidden.tsx +0 -1
  229. package/src/VisuallyHidden/index.ts +0 -1
  230. package/src/index.ts +0 -34
  231. package/src/theme.ts +0 -50
  232. package/tsconfig.build.json +0 -3
@@ -1,57 +0,0 @@
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
- );
@@ -1,138 +0,0 @@
1
- import React from 'react';
2
- import { render, screen } from '@testing-library/react';
3
- import { ThemeProvider } from '@marigold/system';
4
-
5
- import { Stack } from './Stack';
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 getTopPadding = (element: HTMLElement) =>
20
- getComputedStyle(element).getPropertyValue('padding-top');
21
-
22
- test('default space is "none"', () => {
23
- render(
24
- <ThemeProvider theme={theme}>
25
- <Stack>
26
- <Text>first</Text>
27
- <Text>second</Text>
28
- <Text>third</Text>
29
- </Stack>
30
- </ThemeProvider>
31
- );
32
- const first = screen.getByText(/first/).parentElement!;
33
- const second = screen.getByText(/second/).parentElement!;
34
- const third = screen.getByText(/third/).parentElement!;
35
-
36
- expect(getTopPadding(first)).toEqual('');
37
- expect(second).toHaveStyle(`padding-top: 0px`);
38
- expect(third).toHaveStyle(`padding-top: 0px`);
39
- });
40
-
41
- test('accepts and uses spacing from theme', () => {
42
- render(
43
- <ThemeProvider theme={theme}>
44
- <Stack space="small">
45
- <Text>first</Text>
46
- <Text>second</Text>
47
- <Text>third</Text>
48
- </Stack>
49
- </ThemeProvider>
50
- );
51
- const first = screen.getByText(/first/);
52
- const second = screen.getByText(/second/);
53
- const third = screen.getByText(/third/);
54
-
55
- expect(getTopPadding(first)).toEqual('');
56
- expect(second.parentElement).toHaveStyle(`padding-top: 2px`);
57
- expect(third.parentElement).toHaveStyle(`padding-top: 2px`);
58
- });
59
-
60
- test('aligns children left by default', () => {
61
- render(
62
- <Stack data-testid="stack">
63
- <Text>first</Text>
64
- </Stack>
65
- );
66
- const stack = screen.getByTestId('stack');
67
-
68
- expect(stack).toHaveStyle(`align-items: flex-start`);
69
- });
70
-
71
- test('allows to aligns children to the center', () => {
72
- render(
73
- <Stack align="center" data-testid="stack">
74
- <Text>first</Text>
75
- </Stack>
76
- );
77
- const stack = screen.getByTestId('stack');
78
-
79
- expect(stack).toHaveStyle(`align-items: center`);
80
- });
81
-
82
- test('allows to aligns children to the right', () => {
83
- render(
84
- <Stack align="right" data-testid="stack">
85
- <Text>first</Text>
86
- </Stack>
87
- );
88
- const stack = screen.getByTestId('stack');
89
-
90
- expect(stack).toHaveStyle(`align-items: flex-end`);
91
- });
92
-
93
- test('supports nesting', () => {
94
- render(
95
- <ThemeProvider theme={theme}>
96
- <Stack space="large">
97
- <Stack space="small" data-testid="upperStack">
98
- <Text>first</Text>
99
- <Text>second</Text>
100
- </Stack>
101
- <Stack space="small" data-testid="lowerStack">
102
- <Text>third</Text>
103
- <Text>fourth</Text>
104
- </Stack>
105
- </Stack>
106
- </ThemeProvider>
107
- );
108
- const first = screen.getByText(/first/);
109
- const second = screen.getByText(/second/);
110
- const upperStack = screen.getByTestId('upperStack');
111
-
112
- const third = screen.getByText(/third/);
113
- const fourth = screen.getByText(/fourth/);
114
- const lowerStack = screen.getByTestId('lowerStack');
115
-
116
- expect(getTopPadding(upperStack.parentElement!)).toEqual('');
117
- expect(lowerStack.parentElement).toHaveStyle(`padding-top: 8px`);
118
-
119
- expect(getTopPadding(first.parentElement!)).toEqual('');
120
- expect(second.parentElement).toHaveStyle(`padding-top: 2px`);
121
-
122
- expect(getTopPadding(third.parentElement!)).toEqual('');
123
- expect(fourth.parentElement).toHaveStyle(`padding-top: 2px`);
124
- });
125
-
126
- test('renders as div per default', () => {
127
- render(
128
- <ThemeProvider theme={theme}>
129
- <Stack data-testid="stack">
130
- <Text>first</Text>
131
- <Text>second</Text>
132
- </Stack>
133
- </ThemeProvider>
134
- );
135
-
136
- const stack = screen.getByTestId('stack');
137
- expect(stack instanceof HTMLDivElement).toBeTruthy();
138
- });
@@ -1,39 +0,0 @@
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 StackProps = {
9
- space?: ResponsiveStyleValue<string>;
10
- align?: 'left' | 'right' | 'center';
11
- };
12
-
13
- const ALIGNMENT = {
14
- left: 'flex-start',
15
- center: 'center',
16
- right: 'flex-end',
17
- };
18
-
19
- export const Stack: React.FC<StackProps> = ({
20
- space = 'none',
21
- align = 'left',
22
- children,
23
- ...props
24
- }) => (
25
- <Box
26
- {...props}
27
- display="flex"
28
- flexDirection="column"
29
- alignItems={ALIGNMENT[align]}
30
- css={{ '> * + *': { pt: space } }}
31
- >
32
- {Children.map(
33
- flattenChildren(children) as unknown as React.ReactElement,
34
- (child: React.ReactElement) => (
35
- <Box>{React.cloneElement(child, {}, child.props.children)}</Box>
36
- )
37
- )}
38
- </Box>
39
- );
@@ -1 +0,0 @@
1
- export * from './Stack';
@@ -1,61 +0,0 @@
1
- import React from 'react';
2
- import type { Meta, ComponentStory } from '@storybook/react';
3
- import { Text } from './Text';
4
-
5
- export default {
6
- title: 'Components/Text',
7
- argTypes: {
8
- as: {
9
- control: {
10
- type: 'select',
11
- },
12
- options: ['span', 'p', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6'],
13
- description: 'Set HTML element',
14
- table: {
15
- defaultValue: {
16
- summary: 'span',
17
- },
18
- },
19
- },
20
- variant: {
21
- control: {
22
- type: 'select',
23
- },
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',
34
- table: {
35
- defaultValue: {
36
- summary: 'body',
37
- },
38
- },
39
- },
40
- color: {
41
- control: {
42
- type: 'text',
43
- },
44
- description: 'Text color',
45
- table: {
46
- defaultValue: {
47
- summary: 'inherit',
48
- },
49
- },
50
- },
51
- },
52
- } as Meta;
53
-
54
- export const Basic: ComponentStory<typeof Text> = args => (
55
- <Text {...args}>
56
- Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse
57
- dignissim dapibus elit, vel egestas felis pharetra non. Cras malesuada,
58
- massa nec ultricies efficitur, lectus ante consequat magna, a porttitor
59
- massa ex ut quam.
60
- </Text>
61
- );
@@ -1,99 +0,0 @@
1
- import React from 'react';
2
- import { render, screen } from '@testing-library/react';
3
- import { ThemeProvider } from '@marigold/system';
4
-
5
- import { Text } from './Text';
6
-
7
- const theme = {
8
- colors: {
9
- primary: 'hotpink',
10
- black: '#000',
11
- white: '#FFF',
12
- blue: '#2980b9',
13
- },
14
- text: {
15
- body: {
16
- fontFamily: 'Oswald Regular',
17
- },
18
- headline1: {
19
- fontFamily: 'Inter',
20
- },
21
- },
22
- };
23
-
24
- test('uses `text.body` as default variant', () => {
25
- render(
26
- <ThemeProvider theme={theme}>
27
- <Text>text</Text>
28
- </ThemeProvider>
29
- );
30
- const text = screen.getByText(/text/);
31
-
32
- expect(text).toHaveStyle(`font-family: Oswald Regular`);
33
- });
34
-
35
- test('allows to change variants via `variant` prop (with "text" prefix)', () => {
36
- render(
37
- <ThemeProvider theme={theme}>
38
- <Text variant="headline1">text</Text>
39
- </ThemeProvider>
40
- );
41
- const text = screen.getByText(/text/);
42
-
43
- expect(text).toHaveStyle(`font-family: Inter`);
44
- });
45
-
46
- test('renders a <span> element by default', () => {
47
- render(
48
- <ThemeProvider theme={theme}>
49
- <Text>text</Text>
50
- </ThemeProvider>
51
- );
52
- const text = screen.getByText(/text/);
53
-
54
- expect(text instanceof HTMLSpanElement).toBeTruthy();
55
- });
56
-
57
- test('allows to control the rendered element via the `as` prop', () => {
58
- render(
59
- <ThemeProvider theme={theme}>
60
- <Text as="p">text</Text>
61
- </ThemeProvider>
62
- );
63
- const text = screen.getByText(/text/);
64
-
65
- expect(text instanceof HTMLParagraphElement).toBeTruthy();
66
- });
67
-
68
- test.each([
69
- [{ color: 'primary' }, 'color: hotpink'],
70
- [{ color: 'blue' }, 'color: #2980b9'],
71
- [{ align: 'center' }, 'text-align: center'],
72
- [{ cursor: 'pointer' }, 'cursor: pointer'],
73
- [{ outline: 'dashed red' }, 'outline: dashed red'],
74
- [{ userSelect: 'none' }, 'user-select: none'],
75
- ])('test style prop %o', (...args) => {
76
- const props = args.shift();
77
-
78
- render(
79
- <ThemeProvider theme={theme}>
80
- <Text {...props}>This is the Text!</Text>
81
- </ThemeProvider>
82
- );
83
-
84
- const box = screen.getByText('This is the Text!');
85
- args.forEach((style: any) => {
86
- expect(box).toHaveStyle(style);
87
- });
88
- });
89
-
90
- test('forwards ref', () => {
91
- const ref = React.createRef<HTMLButtonElement>();
92
- render(
93
- <Text as="button" ref={ref}>
94
- button
95
- </Text>
96
- );
97
-
98
- expect(ref.current instanceof HTMLButtonElement).toBeTruthy();
99
- });
package/src/Text/Text.tsx DELETED
@@ -1,60 +0,0 @@
1
- import React, { forwardRef } from 'react';
2
- import { ResponsiveStyleValue } from '@marigold/system';
3
- import {
4
- PolymorphicComponentWithRef,
5
- PolymorphicPropsWithRef,
6
- } from '@marigold/types';
7
-
8
- import { Box, BoxOwnProps } from '../Box';
9
-
10
- // Theme Extension
11
- // ---------------
12
- export interface TextThemeExtension<Value> {
13
- text?: {
14
- [key: string]: Value;
15
- };
16
- }
17
-
18
- // Props
19
- // ---------------
20
- export type TextOwnProps = {
21
- align?: ResponsiveStyleValue<string>;
22
- color?: ResponsiveStyleValue<string>;
23
- cursor?: ResponsiveStyleValue<string>;
24
- outline?: ResponsiveStyleValue<string>;
25
- userSelect?: ResponsiveStyleValue<string>;
26
- } & BoxOwnProps;
27
-
28
- export type TextProps = PolymorphicPropsWithRef<TextOwnProps, 'span'>;
29
-
30
- // Component
31
- // ---------------
32
- export const Text: PolymorphicComponentWithRef<TextOwnProps, 'span'> =
33
- forwardRef(
34
- (
35
- {
36
- as = 'span',
37
- variant = 'body',
38
- children,
39
- className,
40
- align,
41
- color,
42
- cursor,
43
- outline,
44
- userSelect,
45
- ...props
46
- },
47
- ref
48
- ) => (
49
- <Box
50
- {...props}
51
- as={as}
52
- variant={`text.${variant}`}
53
- css={{ textAlign: align, color, cursor, outline, userSelect }}
54
- className={className}
55
- ref={ref}
56
- >
57
- {children}
58
- </Box>
59
- )
60
- );
package/src/Text/index.ts DELETED
@@ -1 +0,0 @@
1
- export * from './Text';
@@ -1,64 +0,0 @@
1
- import React from 'react';
2
- import type { Meta, ComponentStory } from '@storybook/react';
3
- import { Textarea } from '.';
4
-
5
- export default {
6
- title: 'Components/Textarea',
7
- argTypes: {
8
- variant: {
9
- control: {
10
- type: 'text',
11
- },
12
- table: {
13
- defaultValue: {
14
- summary: '__default',
15
- },
16
- },
17
- },
18
- label: {
19
- control: {
20
- type: 'text',
21
- },
22
- description: 'Label text',
23
- defaultValue: 'Textarea Label',
24
- },
25
- htmlFor: {
26
- control: {
27
- type: 'text',
28
- },
29
- description: 'Bind to label',
30
- defaultValue: 'textareaId',
31
- },
32
- error: {
33
- control: {
34
- type: 'boolean',
35
- },
36
- description: 'Error',
37
- table: {
38
- defaultValue: {
39
- summary: false,
40
- },
41
- },
42
- },
43
- errorMessage: {
44
- control: {
45
- type: 'text',
46
- },
47
- description: 'Error Message',
48
- },
49
- required: {
50
- control: {
51
- type: 'boolean',
52
- },
53
- table: {
54
- defaultValue: {
55
- summary: false,
56
- },
57
- },
58
- },
59
- },
60
- } as Meta;
61
-
62
- export const Basic: ComponentStory<typeof Textarea> = args => (
63
- <Textarea placeholder="Placeholder..." {...args} />
64
- );
@@ -1,95 +0,0 @@
1
- import React from 'react';
2
- import { render, screen } from '@testing-library/react';
3
- import { ThemeProvider } from '@marigold/system';
4
- import { Textarea } from '../Textarea';
5
-
6
- const theme = {
7
- fonts: {
8
- body: 'Inter Regular',
9
- fancy: 'Roboto',
10
- },
11
- textarea: {
12
- __default: {
13
- fontFamily: 'body',
14
- },
15
- textarea2: {
16
- fontFamily: 'fancy',
17
- },
18
- },
19
- };
20
-
21
- test('supports default variant and themeSection', () => {
22
- render(
23
- <ThemeProvider theme={theme}>
24
- <Textarea title="textarea" />
25
- </ThemeProvider>
26
- );
27
- const textarea = screen.getByTitle(/textarea/);
28
-
29
- expect(textarea).toHaveStyle(`font-family: Inter Regular`);
30
- });
31
-
32
- test('accepts other variant than default', () => {
33
- render(
34
- <ThemeProvider theme={theme}>
35
- <Textarea variant="textarea2" title="textarea" />
36
- </ThemeProvider>
37
- );
38
- const textarea = screen.getByTitle(/textarea/);
39
-
40
- expect(textarea).toHaveStyle(`font-family: Roboto`);
41
- });
42
-
43
- test('renders correct HTML element', () => {
44
- render(
45
- <ThemeProvider theme={theme}>
46
- <Textarea title="textarea" />
47
- </ThemeProvider>
48
- );
49
- const textarea = screen.getByTitle(/textarea/);
50
-
51
- expect(textarea instanceof HTMLTextAreaElement).toBeTruthy();
52
- });
53
-
54
- test('supports label prop', () => {
55
- render(
56
- <ThemeProvider theme={theme}>
57
- <Textarea label="test" htmlFor="myId" title="textarea" />
58
- </ThemeProvider>
59
- );
60
- const textarea = screen.getByText(/test/);
61
-
62
- expect(textarea instanceof HTMLLabelElement).toBeTruthy();
63
- });
64
-
65
- test('supports error and errorMessage prop', () => {
66
- render(
67
- <ThemeProvider theme={theme}>
68
- <Textarea error errorMessage="error" label="label" title="textarea" />
69
- </ThemeProvider>
70
- );
71
- const textarea = screen.getByText(/error/);
72
- expect(textarea).toBeDefined();
73
- });
74
-
75
- test('supports required prop', () => {
76
- render(
77
- <ThemeProvider theme={theme}>
78
- <Textarea label="test" htmlFor="myId" required title="textarea" />
79
- </ThemeProvider>
80
- );
81
- const label = screen.getByText(/test/);
82
-
83
- expect(label.nextSibling instanceof SVGElement).toBeTruthy();
84
- });
85
-
86
- test('accepts custom styles prop className', () => {
87
- render(
88
- <ThemeProvider theme={theme}>
89
- <Textarea className="custom-class-name" title="textarea" />
90
- </ThemeProvider>
91
- );
92
- const textarea = screen.getByTitle(/textarea/);
93
-
94
- expect(textarea.className).toMatch('custom-class-name');
95
- });
@@ -1,62 +0,0 @@
1
- import React from 'react';
2
- import { Exclamation } from '@marigold/icons';
3
- import { ComponentProps } from '@marigold/types';
4
-
5
- import { ValidationMessage } from '../ValidationMessage';
6
- import { Label } from '../Label';
7
- import { Box } from '../Box';
8
-
9
- // Theme Extension
10
- // ---------------
11
- export interface TextareaThemeExtension<Value> {
12
- textarea?: {
13
- [key: string]: Value;
14
- };
15
- }
16
-
17
- // Props
18
- // ---------------
19
- export type TextareaProps = {
20
- variant?: string;
21
- label?: string;
22
- htmlFor?: string;
23
- required?: boolean;
24
- error?: boolean;
25
- errorMessage?: string;
26
- } & ComponentProps<'textarea'>;
27
-
28
- // Component
29
- // ---------------
30
- export const Textarea: React.FC<TextareaProps> = ({
31
- variant = '',
32
- htmlFor = 'textarea',
33
- label,
34
- error,
35
- errorMessage,
36
- required,
37
- className = '',
38
- children,
39
- ...props
40
- }) => (
41
- <Box>
42
- {label && (
43
- <Label htmlFor={htmlFor} required={required}>
44
- {label}
45
- </Label>
46
- )}
47
- <Box
48
- as="textarea"
49
- {...props}
50
- display="block"
51
- variant={`textarea.${variant}`}
52
- css={{ outlineColor: error && 'error' }}
53
- className={className}
54
- />
55
- {error && errorMessage && (
56
- <ValidationMessage>
57
- <Exclamation size={16} />
58
- {errorMessage}
59
- </ValidationMessage>
60
- )}
61
- </Box>
62
- );
@@ -1 +0,0 @@
1
- export * from './Textarea';