@marigold/system 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.
- package/dist/Element.d.ts +8 -0
- package/dist/cache.d.ts +4 -0
- package/dist/index.d.ts +6 -4
- package/dist/normalize.d.ts +110 -0
- package/dist/reset.d.ts +24 -0
- package/dist/system.cjs.development.js +332 -95
- package/dist/system.cjs.development.js.map +1 -1
- package/dist/system.cjs.production.min.js +1 -1
- package/dist/system.cjs.production.min.js.map +1 -1
- package/dist/system.esm.js +323 -92
- package/dist/system.esm.js.map +1 -1
- package/dist/types.d.ts +9 -0
- package/dist/useClassname.d.ts +2 -0
- package/dist/useStyles.d.ts +15 -0
- package/dist/useTheme.d.ts +10 -0
- package/package.json +7 -10
- package/src/Colors.stories.mdx +616 -448
- package/src/Element.test.tsx +203 -0
- package/src/Element.tsx +59 -0
- package/src/cache.ts +4 -0
- package/src/concepts-principles.mdx +1 -1
- package/src/index.ts +6 -4
- package/src/normalize.test.tsx +42 -0
- package/src/normalize.ts +131 -0
- package/src/reset.ts +108 -0
- package/src/types.ts +16 -0
- package/src/useClassname.test.tsx +70 -0
- package/src/useClassname.ts +23 -0
- package/src/useStyles.stories.mdx +24 -0
- package/src/useStyles.test.tsx +286 -0
- package/src/useStyles.ts +63 -0
- package/src/useTheme.test.tsx +115 -0
- package/src/useTheme.tsx +22 -0
- package/dist/Box/Box.d.ts +0 -6
- package/dist/Box/index.d.ts +0 -1
- package/dist/MarigoldProvider.d.ts +0 -7
- package/dist/categories.d.ts +0 -169
- package/dist/emotion.d.ts +0 -7
- package/dist/system.d.ts +0 -37
- package/src/Box/Box.stories.mdx +0 -148
- package/src/Box/Box.test.tsx +0 -215
- package/src/Box/Box.tsx +0 -58
- package/src/Box/index.ts +0 -1
- package/src/MarigoldProvider.test.tsx +0 -80
- package/src/MarigoldProvider.tsx +0 -37
- package/src/categories.ts +0 -203
- package/src/emotion.ts +0 -39
- package/src/system.test.tsx +0 -84
- package/src/system.tsx +0 -55
- package/src/writeComponent.stories.mdx +0 -114
package/src/categories.ts
DELETED
|
@@ -1,203 +0,0 @@
|
|
|
1
|
-
import { PropertiesFallback } from 'csstype';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* System categories are based on https://primer.style/components/docs/system-props
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
// Spacing
|
|
8
|
-
// ---------------
|
|
9
|
-
export const SPACE_PROPS = [
|
|
10
|
-
'm',
|
|
11
|
-
'margin',
|
|
12
|
-
'mt',
|
|
13
|
-
'marginTop',
|
|
14
|
-
'mr',
|
|
15
|
-
'marginRight',
|
|
16
|
-
'mb',
|
|
17
|
-
'marginBottom',
|
|
18
|
-
'ml',
|
|
19
|
-
'marginLeft',
|
|
20
|
-
'mx',
|
|
21
|
-
'marginX',
|
|
22
|
-
'my',
|
|
23
|
-
'marginY',
|
|
24
|
-
'p',
|
|
25
|
-
'padding',
|
|
26
|
-
'pt',
|
|
27
|
-
'paddingTop',
|
|
28
|
-
'pr',
|
|
29
|
-
'paddingRight',
|
|
30
|
-
'pb',
|
|
31
|
-
'paddingBottom',
|
|
32
|
-
'pl',
|
|
33
|
-
'paddingLeft',
|
|
34
|
-
'px',
|
|
35
|
-
'paddingX',
|
|
36
|
-
'py',
|
|
37
|
-
'paddingY',
|
|
38
|
-
];
|
|
39
|
-
|
|
40
|
-
type StandardCSSProperties = PropertiesFallback<number | string>;
|
|
41
|
-
|
|
42
|
-
export type SpacingProps = {
|
|
43
|
-
/**
|
|
44
|
-
* The **`margin`** CSS property sets the margin area on all four sides of an element. It is a shorthand for `margin-top`, `margin-right`, `margin-bottom`, and `margin-left`.
|
|
45
|
-
*
|
|
46
|
-
* @see https://developer.mozilla.org/docs/Web/CSS/margin
|
|
47
|
-
*/
|
|
48
|
-
m?: StandardCSSProperties['margin'];
|
|
49
|
-
/**
|
|
50
|
-
* The **`margin-top`** CSS property sets the margin area on the top of an element. A positive value places it farther from its neighbors, while a negative value places it closer.
|
|
51
|
-
*
|
|
52
|
-
* **Initial value**: `0`
|
|
53
|
-
*
|
|
54
|
-
* @see https://developer.mozilla.org/docs/Web/CSS/margin-top
|
|
55
|
-
*/
|
|
56
|
-
mt?: StandardCSSProperties['marginTop'];
|
|
57
|
-
/**
|
|
58
|
-
* The **`margin-right`** CSS property sets the margin area on the right side of an element. A positive value places it farther from its neighbors, while a negative value places it closer.
|
|
59
|
-
*
|
|
60
|
-
* **Initial value**: `0`
|
|
61
|
-
*
|
|
62
|
-
* @see https://developer.mozilla.org/docs/Web/CSS/margin-right
|
|
63
|
-
*/
|
|
64
|
-
mr?: StandardCSSProperties['marginRight'];
|
|
65
|
-
/**
|
|
66
|
-
* The **`margin-bottom`** CSS property sets the margin area on the bottom of an element. A positive value places it farther from its neighbors, while a negative value places it closer.
|
|
67
|
-
*
|
|
68
|
-
* **Initial value**: `0`
|
|
69
|
-
*
|
|
70
|
-
* @see https://developer.mozilla.org/docs/Web/CSS/margin-bottom
|
|
71
|
-
*/
|
|
72
|
-
mb?: StandardCSSProperties['marginBottom'];
|
|
73
|
-
/**
|
|
74
|
-
* The **`margin-left`** CSS property sets the margin area on the left side of an element. A positive value places it farther from its neighbors, while a negative value places it closer.
|
|
75
|
-
*
|
|
76
|
-
* **Initial value**: `0`
|
|
77
|
-
*
|
|
78
|
-
* @see https://developer.mozilla.org/docs/Web/CSS/margin-left
|
|
79
|
-
*/
|
|
80
|
-
ml?: StandardCSSProperties['marginLeft'];
|
|
81
|
-
/**
|
|
82
|
-
* The **`mx`** is shorthand for using both **`margin-left`** and **`margin-right`** CSS properties. They set the margin area on the left and right side of an element. A positive value placesit
|
|
83
|
-
* farther from its neighbors, while a negative value places it closer.
|
|
84
|
-
*
|
|
85
|
-
* **Initial value**: `0`
|
|
86
|
-
*
|
|
87
|
-
* @see https://styled-system.com/#margin-props
|
|
88
|
-
* @see https://developer.mozilla.org/docs/Web/CSS/margin-left
|
|
89
|
-
* @see https://developer.mozilla.org/docs/Web/CSS/margin-right
|
|
90
|
-
*/
|
|
91
|
-
mx?: StandardCSSProperties['marginLeft'];
|
|
92
|
-
/**
|
|
93
|
-
* The **`marginX`** is shorthand for using both **`margin-left`** and **`margin-right`** CSS properties. They set the margin area on the left and right side of an element. A positive value
|
|
94
|
-
* places it farther from its neighbors, while a negative value places it closer.
|
|
95
|
-
*
|
|
96
|
-
* **Initial value**: `0`
|
|
97
|
-
*
|
|
98
|
-
* @see https://styled-system.com/#margin-props
|
|
99
|
-
* @see https://developer.mozilla.org/docs/Web/CSS/margin-left
|
|
100
|
-
* @see https://developer.mozilla.org/docs/Web/CSS/margin-right
|
|
101
|
-
*/
|
|
102
|
-
marginX?: StandardCSSProperties['marginLeft'];
|
|
103
|
-
/**
|
|
104
|
-
* The **`my`** is shorthard for using both **`margin-top`** and **`margin-bottom`** CSS properties. They set the margin area on the top and bottom of an element. A positive value places it
|
|
105
|
-
* farther from its neighbors, while a negative value places it closer.
|
|
106
|
-
*
|
|
107
|
-
* **Initial value**: `0`
|
|
108
|
-
*
|
|
109
|
-
* @see https://styled-system.com/#margin-props
|
|
110
|
-
* @see https://developer.mozilla.org/docs/Web/CSS/margin-top
|
|
111
|
-
* @see https://developer.mozilla.org/docs/Web/CSS/margin-bottom
|
|
112
|
-
*/
|
|
113
|
-
my?: StandardCSSProperties['marginTop'];
|
|
114
|
-
/**
|
|
115
|
-
* The **`marginY`** is shorthard for using both **`margin-top`** and **`margin-bottom`** CSS properties. They set the margin area on the top and bottom of an element. A positive value places
|
|
116
|
-
* it farther from its neighbors, while a negative value places it closer.
|
|
117
|
-
*
|
|
118
|
-
* **Initial value**: `0`
|
|
119
|
-
*
|
|
120
|
-
* @see https://styled-system.com/#margin-props
|
|
121
|
-
* @see https://developer.mozilla.org/docs/Web/CSS/margin-top
|
|
122
|
-
* @see https://developer.mozilla.org/docs/Web/CSS/margin-bottom
|
|
123
|
-
*/
|
|
124
|
-
marginY?: StandardCSSProperties['marginTop'];
|
|
125
|
-
/**
|
|
126
|
-
* The **`padding`** CSS property sets the padding area on all four sides of an element. It is a shorthand for `padding-top`, `padding-right`, `padding-bottom`, and `padding-left`.
|
|
127
|
-
*
|
|
128
|
-
* @see https://developer.mozilla.org/docs/Web/CSS/padding
|
|
129
|
-
*/
|
|
130
|
-
p?: StandardCSSProperties['padding'];
|
|
131
|
-
/**
|
|
132
|
-
* The **`padding-top`** padding area on the top of an element.
|
|
133
|
-
*
|
|
134
|
-
* **Initial value**: `0`
|
|
135
|
-
*
|
|
136
|
-
* @see https://developer.mozilla.org/docs/Web/CSS/padding-top
|
|
137
|
-
*/
|
|
138
|
-
pt?: StandardCSSProperties['paddingTop'];
|
|
139
|
-
/**
|
|
140
|
-
* The **`padding-right`** CSS property sets the width of the padding area on the right side of an element.
|
|
141
|
-
*
|
|
142
|
-
* **Initial value**: `0`
|
|
143
|
-
*
|
|
144
|
-
* @see https://developer.mozilla.org/docs/Web/CSS/padding-right
|
|
145
|
-
*/
|
|
146
|
-
pr?: StandardCSSProperties['paddingRight'];
|
|
147
|
-
/**
|
|
148
|
-
* The **`padding-bottom`** CSS property sets the height of the padding area on the bottom of an element.
|
|
149
|
-
*
|
|
150
|
-
* **Initial value**: `0`
|
|
151
|
-
*
|
|
152
|
-
* @see https://developer.mozilla.org/docs/Web/CSS/padding-bottom
|
|
153
|
-
*/
|
|
154
|
-
pb?: StandardCSSProperties['paddingBottom'];
|
|
155
|
-
/**
|
|
156
|
-
* The **`padding-left`** CSS property sets the width of the padding area on the left side of an element.
|
|
157
|
-
*
|
|
158
|
-
* **Initial value**: `0`
|
|
159
|
-
*
|
|
160
|
-
* @see https://developer.mozilla.org/docs/Web/CSS/padding-left
|
|
161
|
-
*/
|
|
162
|
-
pl?: StandardCSSProperties['paddingLeft'];
|
|
163
|
-
/**
|
|
164
|
-
* The **`px`** is shorthand property for CSS properties **`padding-left`** and **`padding-right`**. They set the width of the padding area on the left and right side of an element.
|
|
165
|
-
*
|
|
166
|
-
* **Initial value**: `0`
|
|
167
|
-
*
|
|
168
|
-
* @see https://styled-system.com/#padding-props
|
|
169
|
-
* @see https://developer.mozilla.org/docs/Web/CSS/padding-left
|
|
170
|
-
* @see https://developer.mozilla.org/docs/Web/CSS/padding-right
|
|
171
|
-
*/
|
|
172
|
-
px?: StandardCSSProperties['paddingLeft'];
|
|
173
|
-
/**
|
|
174
|
-
* The **`paddingX`** is shorthand property for CSS properties **`padding-left`** and **`padding-right`**. They set the width of the padding area on the left and right side of an element.
|
|
175
|
-
*
|
|
176
|
-
* **Initial value**: `0`
|
|
177
|
-
*
|
|
178
|
-
* @see https://styled-system.com/#padding-props
|
|
179
|
-
* @see https://developer.mozilla.org/docs/Web/CSS/padding-left
|
|
180
|
-
* @see https://developer.mozilla.org/docs/Web/CSS/padding-right
|
|
181
|
-
*/
|
|
182
|
-
paddingX?: StandardCSSProperties['paddingLeft'];
|
|
183
|
-
/**
|
|
184
|
-
* The **`py`** is shorthand property for CSS properties **`padding-top`** and **`padding-bottom`**. They set the width of the padding area on the top and bottom of an element.
|
|
185
|
-
*
|
|
186
|
-
* **Initial value**: `0`
|
|
187
|
-
*
|
|
188
|
-
* @see https://styled-system.com/#padding-props
|
|
189
|
-
* @see https://developer.mozilla.org/docs/Web/CSS/padding-top
|
|
190
|
-
* @see https://developer.mozilla.org/docs/Web/CSS/padding-bottom
|
|
191
|
-
*/
|
|
192
|
-
py?: StandardCSSProperties['paddingTop'];
|
|
193
|
-
/**
|
|
194
|
-
* The **`paddingY`** is shorthand property for CSS properties **`padding-top`** and **`padding-bottom`**. They set the width of the padding area on the top and bottom of an element.
|
|
195
|
-
*
|
|
196
|
-
* **Initial value**: `0`
|
|
197
|
-
*
|
|
198
|
-
* @see https://styled-system.com/#padding-props
|
|
199
|
-
* @see https://developer.mozilla.org/docs/Web/CSS/padding-top
|
|
200
|
-
* @see https://developer.mozilla.org/docs/Web/CSS/padding-bottom
|
|
201
|
-
*/
|
|
202
|
-
paddingY?: StandardCSSProperties['paddingTop'];
|
|
203
|
-
};
|
package/src/emotion.ts
DELETED
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Fix until the global JSX augmentation is not included in
|
|
5
|
-
* `@emotion/core`. See https://github.com/emotion-js/emotion/issues/1257
|
|
6
|
-
* for more information.
|
|
7
|
-
*
|
|
8
|
-
* *Why is this a problem?*
|
|
9
|
-
*
|
|
10
|
-
* (1) Every JSX element accepts a `css` prop, but we don't parse that.
|
|
11
|
-
* (2) Every JSX element only accepts a type that is compatible with emotion's
|
|
12
|
-
* css prop, which we don't care, since we first pass the `css` prop
|
|
13
|
-
* to styled-system.
|
|
14
|
-
*
|
|
15
|
-
* *The fix consist of two parts:*
|
|
16
|
-
*
|
|
17
|
-
* (1) using `.yarnclean` to remove the `emotion/core` typings completly.
|
|
18
|
-
* (2) having this sink file to re-apply the typings and tell TS to ignore
|
|
19
|
-
* the untyped import.
|
|
20
|
-
*/
|
|
21
|
-
import {
|
|
22
|
-
css as cssEmotion,
|
|
23
|
-
jsx as createElement,
|
|
24
|
-
Global as EmotionGlobal,
|
|
25
|
-
ThemeContext as EmotionContext,
|
|
26
|
-
// @ts-ignore
|
|
27
|
-
} from '@emotion/core';
|
|
28
|
-
|
|
29
|
-
// Emotion API
|
|
30
|
-
// ---------------
|
|
31
|
-
export const jsx = createElement as typeof React.createElement;
|
|
32
|
-
export const css = cssEmotion as (
|
|
33
|
-
template: TemplateStringsArray,
|
|
34
|
-
...args: any[]
|
|
35
|
-
) => object;
|
|
36
|
-
export const ThemeContext = EmotionContext as React.Context<any>;
|
|
37
|
-
export const Global = EmotionGlobal as (
|
|
38
|
-
props: React.PropsWithChildren<{ styles: any }>
|
|
39
|
-
) => React.ReactElement;
|
package/src/system.test.tsx
DELETED
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { render } from '@testing-library/react';
|
|
3
|
-
import { system } from './system';
|
|
4
|
-
|
|
5
|
-
test('did we break React.forwardRef?', () => {
|
|
6
|
-
const myRef = React.createRef<HTMLElement>();
|
|
7
|
-
const Component = system<{}, 'div'>(props => <div {...props} />);
|
|
8
|
-
render(<Component ref={myRef}>I have a ref!</Component>);
|
|
9
|
-
|
|
10
|
-
expect(myRef.current).toBeInstanceOf(HTMLDivElement);
|
|
11
|
-
});
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* The following tests are not actually testing anything, rather
|
|
15
|
-
* make sure that the typings work as intended.
|
|
16
|
-
*
|
|
17
|
-
* If we mess something up, the typechecking will not work.
|
|
18
|
-
*/
|
|
19
|
-
test('usage with `as` prop', () => {
|
|
20
|
-
type ComponentProps = {
|
|
21
|
-
extra: string;
|
|
22
|
-
children?: React.ReactNode | ((value?: number) => JSX.Element);
|
|
23
|
-
};
|
|
24
|
-
const Component = system<ComponentProps, 'button'>(
|
|
25
|
-
({ as: Comp = 'button', extra, className, children, ...props }) => {
|
|
26
|
-
return (
|
|
27
|
-
<Comp {...props}>
|
|
28
|
-
{typeof children === 'function' ? children(56) : children}
|
|
29
|
-
</Comp>
|
|
30
|
-
);
|
|
31
|
-
}
|
|
32
|
-
);
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* Prop `extra` is required and button attributes allowed.
|
|
36
|
-
*/
|
|
37
|
-
expect(() => {
|
|
38
|
-
render(<Component extra="prop" type="button" />);
|
|
39
|
-
}).not.toThrow();
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
* Yay, the `href` attribute is allowed because we're rendering
|
|
43
|
-
* an anchor tag!
|
|
44
|
-
*/
|
|
45
|
-
expect(() => {
|
|
46
|
-
render(<Component as="a" extra="required" href="example.com" />);
|
|
47
|
-
}).not.toThrow();
|
|
48
|
-
|
|
49
|
-
/**
|
|
50
|
-
* Render another component and adhere to its props. In this case
|
|
51
|
-
* the `to` prop is required by `<Link />`. Also, the `extra` prop
|
|
52
|
-
* from our original component is still required.
|
|
53
|
-
*/
|
|
54
|
-
expect(() => {
|
|
55
|
-
const Link: React.FC<{ to: string; optional?: boolean }> = ({
|
|
56
|
-
to,
|
|
57
|
-
children,
|
|
58
|
-
...props
|
|
59
|
-
}) => (
|
|
60
|
-
<a href={to} {...props}>
|
|
61
|
-
{children}
|
|
62
|
-
</a>
|
|
63
|
-
);
|
|
64
|
-
|
|
65
|
-
render(<Component as={Link} extra="extra" to="adticket.de" />);
|
|
66
|
-
}).not.toThrow();
|
|
67
|
-
});
|
|
68
|
-
|
|
69
|
-
test('usage of the `variant` prop', () => {
|
|
70
|
-
type ComponentProps = {};
|
|
71
|
-
const Component = system<ComponentProps, 'div'>(
|
|
72
|
-
({ as: Comp = 'div', variant = 'basic', children, ...props }) => (
|
|
73
|
-
<Comp {...props} />
|
|
74
|
-
)
|
|
75
|
-
);
|
|
76
|
-
|
|
77
|
-
expect(() => {
|
|
78
|
-
render(<Component />);
|
|
79
|
-
}).not.toThrow();
|
|
80
|
-
|
|
81
|
-
expect(() => {
|
|
82
|
-
render(<Component variant="advanced" />);
|
|
83
|
-
}).not.toThrow();
|
|
84
|
-
});
|
package/src/system.tsx
DELETED
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Typings are based on [Reach UI](https://github.com/reach/reach-ui/blob/4cb497f530b0f83f80c6f6f2da46ab55b1160cb6/packages/utils/src/types.tsx).
|
|
3
|
-
*/
|
|
4
|
-
import {
|
|
5
|
-
forwardRef,
|
|
6
|
-
ComponentPropsWithRef,
|
|
7
|
-
ElementType,
|
|
8
|
-
ReactElement,
|
|
9
|
-
ValidationMap,
|
|
10
|
-
WeakValidationMap,
|
|
11
|
-
} from 'react';
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* SystemProps support the `as` and `variant` prop. The former
|
|
15
|
-
* is used to changed the rendered root element of a component.
|
|
16
|
-
*
|
|
17
|
-
* These props also infer additional allowed props based on the
|
|
18
|
-
* value of the `as` prop. For example, setting `as="button"` will
|
|
19
|
-
* allow to use HTMLButtonAttributes on the component.
|
|
20
|
-
*/
|
|
21
|
-
export type SystemProps<P, T extends ElementType> = P &
|
|
22
|
-
Omit<ComponentPropsWithRef<T>, 'as' | keyof P> & {
|
|
23
|
-
as?: T;
|
|
24
|
-
variant?: string;
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* Enhanced version of `React.FunctionComponent` that accepts `SystemProps`
|
|
29
|
-
* and infers allowed properties based on the `as` prop.
|
|
30
|
-
*/
|
|
31
|
-
export interface SystemComponent<P, T extends ElementType> {
|
|
32
|
-
/**
|
|
33
|
-
* These types are a bit of a hack, but cover us in cases where the `as` prop
|
|
34
|
-
* is not a JSX string type. Makes the compiler happy so 🤷♂️
|
|
35
|
-
*/
|
|
36
|
-
<TT extends ElementType>(props: SystemProps<P, TT>): ReactElement | null;
|
|
37
|
-
(props: SystemProps<P, T>): ReactElement | null;
|
|
38
|
-
|
|
39
|
-
displayName?: string;
|
|
40
|
-
propTypes?: WeakValidationMap<SystemProps<P, T>>;
|
|
41
|
-
contextTypes?: ValidationMap<any>;
|
|
42
|
-
defaultProps?: Partial<SystemProps<P, T>>;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
/**
|
|
46
|
-
* Helper to write components that adhere to a common design system API,
|
|
47
|
-
* which includes the `as` and `variant` prop.
|
|
48
|
-
*/
|
|
49
|
-
export function system<P, T extends ElementType>(
|
|
50
|
-
render: (props: SystemProps<P, T>) => ReactElement | null
|
|
51
|
-
) {
|
|
52
|
-
return forwardRef((props: any, ref) =>
|
|
53
|
-
render({ ...props, ref })
|
|
54
|
-
) as SystemComponent<P, T>;
|
|
55
|
-
}
|
|
@@ -1,114 +0,0 @@
|
|
|
1
|
-
import { Meta, Story, Preview } from '@storybook/addon-docs/blocks';
|
|
2
|
-
|
|
3
|
-
<Meta title="Guides/How to Write and Use Components" />
|
|
4
|
-
|
|
5
|
-
# How to Write and Use Components
|
|
6
|
-
|
|
7
|
-
Small guidance for creating components using the `<Box>` primitive.
|
|
8
|
-
|
|
9
|
-
## API
|
|
10
|
-
|
|
11
|
-
### Use the Box
|
|
12
|
-
|
|
13
|
-
Use the `<Box>` primitive as a basic structure to apply styling to the element you wish to build.
|
|
14
|
-
With the `as` prop you define the rendered HTML element like in the example where a `<button>` element is rendered:
|
|
15
|
-
|
|
16
|
-
```tsx
|
|
17
|
-
import React from 'react';
|
|
18
|
-
import { Box } from '@marigold/system';
|
|
19
|
-
|
|
20
|
-
<Box as="button" themeSection="buttons" variant="outlined" />;
|
|
21
|
-
```
|
|
22
|
-
|
|
23
|
-
### Add theme
|
|
24
|
-
|
|
25
|
-
In order to add styles to your component, you have two levels to work on. The first one is using theme styles which are defined in a globally accessible theme file.
|
|
26
|
-
When using the component, those styles are accessed via the `themeSection` and `variant` props.
|
|
27
|
-
The theme is indicated in the `<MarigoldProvider>` in which you wrap the component when you use it. See the render method in the example below.
|
|
28
|
-
In the theme, you define theme specific stylings like colors and spacings.
|
|
29
|
-
|
|
30
|
-
### Add styling
|
|
31
|
-
|
|
32
|
-
Add more styling to the component with style props using the `css` prop. Those styles are applied independently of your theme to all instances of the component.
|
|
33
|
-
While using the component, you can override all spacing styles.
|
|
34
|
-
|
|
35
|
-
### Example
|
|
36
|
-
|
|
37
|
-
```tsx
|
|
38
|
-
import React from 'react';
|
|
39
|
-
import { Box, MarigoldProvider, system } from '@marigold/system';
|
|
40
|
-
import { render } from '@testing-library/react';
|
|
41
|
-
|
|
42
|
-
const theme = {
|
|
43
|
-
...anyTheme,
|
|
44
|
-
buttons: {
|
|
45
|
-
// themeSection
|
|
46
|
-
outlined: {
|
|
47
|
-
// variant
|
|
48
|
-
border: '1px solid orange',
|
|
49
|
-
mx: 2,
|
|
50
|
-
},
|
|
51
|
-
},
|
|
52
|
-
};
|
|
53
|
-
// Define custom properties for your component
|
|
54
|
-
type ButtonProps = {
|
|
55
|
-
kind?: 'basic' | 'other';
|
|
56
|
-
size?: 'small' | 'medium' | 'large';
|
|
57
|
-
};
|
|
58
|
-
|
|
59
|
-
// Specify the HTML element you want to render and merge its properties with the custom component props
|
|
60
|
-
const Button = system<ButtonProps, 'button'>(
|
|
61
|
-
// Set default values for extra props
|
|
62
|
-
({
|
|
63
|
-
as: Button = 'button',
|
|
64
|
-
kind = 'basic',
|
|
65
|
-
size = 'medium',
|
|
66
|
-
children,
|
|
67
|
-
...props
|
|
68
|
-
}) => {
|
|
69
|
-
// Place logic here like toggle states, calculations, mappings etc.
|
|
70
|
-
return (
|
|
71
|
-
// Use theme styles and specify additional styling using the `css` prop
|
|
72
|
-
<Box
|
|
73
|
-
as={as}
|
|
74
|
-
css={{ bg: 'white' }}
|
|
75
|
-
themeSection="buttons"
|
|
76
|
-
variant="outlined"
|
|
77
|
-
{...props}
|
|
78
|
-
>
|
|
79
|
-
{children}
|
|
80
|
-
</Box>
|
|
81
|
-
);
|
|
82
|
-
}
|
|
83
|
-
);
|
|
84
|
-
// Use the component: don't forget the imports!
|
|
85
|
-
render(
|
|
86
|
-
<MarigoldProvider theme={theme}>
|
|
87
|
-
<Button /> // Default Button component instance
|
|
88
|
-
<Button mx={3} /> // Button component instance with custom margin that overrides
|
|
89
|
-
theme and given styles
|
|
90
|
-
</MarigoldProvider>
|
|
91
|
-
);
|
|
92
|
-
```
|
|
93
|
-
|
|
94
|
-
A default base for all browsers is applied to all components built with the `<Box>` primitive so that all instances of the component look the same in every browser.
|
|
95
|
-
|
|
96
|
-
### Folder Structure
|
|
97
|
-
|
|
98
|
-
Place the file with the component in a separate folder under `packages/components/src`. Create an `index.ts` file to export the component. Write tests to show your component works as intended.
|
|
99
|
-
Add documentation, usage instructions and examples in a stories file (naming convention: `Component.stories.mdx`).
|
|
100
|
-
|
|
101
|
-
```
|
|
102
|
-
packages
|
|
103
|
-
└─── system
|
|
104
|
-
|
|
|
105
|
-
└─── components
|
|
106
|
-
| index.ts
|
|
107
|
-
| theme.ts
|
|
108
|
-
└─── src
|
|
109
|
-
└─── Button
|
|
110
|
-
| index.ts
|
|
111
|
-
| Button.tsx
|
|
112
|
-
| Button.test.tsx
|
|
113
|
-
| Button.stories.mdx
|
|
114
|
-
```
|