@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
|
@@ -0,0 +1,286 @@
|
|
|
1
|
+
import React, { ElementType } from 'react';
|
|
2
|
+
import { renderHook } from '@testing-library/react-hooks';
|
|
3
|
+
import { render, screen } from '@testing-library/react';
|
|
4
|
+
import { useStyles } from './useStyles';
|
|
5
|
+
import { ThemeProvider } from './useTheme';
|
|
6
|
+
|
|
7
|
+
// Setup
|
|
8
|
+
// ---------------
|
|
9
|
+
const theme = {
|
|
10
|
+
text: {
|
|
11
|
+
body: {
|
|
12
|
+
fontSize: 1,
|
|
13
|
+
color: 'black',
|
|
14
|
+
marginTop: '2px',
|
|
15
|
+
},
|
|
16
|
+
heading: {
|
|
17
|
+
fontSize: 3,
|
|
18
|
+
color: 'primary',
|
|
19
|
+
},
|
|
20
|
+
padding: {
|
|
21
|
+
paddingTop: '2px',
|
|
22
|
+
},
|
|
23
|
+
},
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
const wrapper: React.FC = ({ children }) => (
|
|
27
|
+
<ThemeProvider theme={theme}>{children}</ThemeProvider>
|
|
28
|
+
);
|
|
29
|
+
|
|
30
|
+
test('create a string classname', () => {
|
|
31
|
+
const { result } = renderHook(
|
|
32
|
+
() => useStyles({ element: 'a', css: { color: 'primary' } }),
|
|
33
|
+
{
|
|
34
|
+
wrapper,
|
|
35
|
+
}
|
|
36
|
+
);
|
|
37
|
+
expect(result.current).toEqual(expect.any(String));
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
// Tests
|
|
41
|
+
// ---------------
|
|
42
|
+
|
|
43
|
+
test('base styles first', () => {
|
|
44
|
+
const TestComponent: React.FC<{}> = ({ children, ...props }) => {
|
|
45
|
+
const classNames = useStyles({ element: 'p' });
|
|
46
|
+
return (
|
|
47
|
+
<p className={classNames} {...props}>
|
|
48
|
+
{children}
|
|
49
|
+
</p>
|
|
50
|
+
);
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
const { getByText } = render(
|
|
54
|
+
<ThemeProvider theme={theme}>
|
|
55
|
+
<TestComponent>Text</TestComponent>
|
|
56
|
+
</ThemeProvider>
|
|
57
|
+
);
|
|
58
|
+
const testelem = getByText('Text');
|
|
59
|
+
const style = getComputedStyle(testelem);
|
|
60
|
+
|
|
61
|
+
expect(style.marginTop).toEqual('0px'); // 0px come from base
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
test('variant styles second', () => {
|
|
65
|
+
const TestComponent: React.FC<{ variant?: 'body' }> = ({
|
|
66
|
+
variant = 'body',
|
|
67
|
+
children,
|
|
68
|
+
...props
|
|
69
|
+
}) => {
|
|
70
|
+
const classNames = useStyles({
|
|
71
|
+
element: 'p',
|
|
72
|
+
variant: `text.${variant}`,
|
|
73
|
+
});
|
|
74
|
+
return (
|
|
75
|
+
<p className={classNames} {...props}>
|
|
76
|
+
{children}
|
|
77
|
+
</p>
|
|
78
|
+
);
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
const { getByText } = render(
|
|
82
|
+
<ThemeProvider theme={theme}>
|
|
83
|
+
<TestComponent>Text</TestComponent>
|
|
84
|
+
</ThemeProvider>
|
|
85
|
+
);
|
|
86
|
+
const testelem = getByText('Text');
|
|
87
|
+
const style = getComputedStyle(testelem);
|
|
88
|
+
|
|
89
|
+
expect(style.marginTop).not.toEqual('0px'); // 0px come from base
|
|
90
|
+
expect(style.marginBottom).toEqual('0px'); // 0px still come from base
|
|
91
|
+
expect(style.marginTop).toEqual('2px'); // 2px come from variant
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
test('array of variant styles', () => {
|
|
95
|
+
const TestComponent: React.FC<{ variant?: 'body' }> = ({
|
|
96
|
+
variant = 'body',
|
|
97
|
+
children,
|
|
98
|
+
...props
|
|
99
|
+
}) => {
|
|
100
|
+
const classNames = useStyles({
|
|
101
|
+
element: 'p',
|
|
102
|
+
variant: [`text.${variant}`, `text.padding`],
|
|
103
|
+
});
|
|
104
|
+
return (
|
|
105
|
+
<p className={classNames} {...props}>
|
|
106
|
+
{children}
|
|
107
|
+
</p>
|
|
108
|
+
);
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
const { getByText } = render(
|
|
112
|
+
<ThemeProvider theme={theme}>
|
|
113
|
+
<TestComponent>Text</TestComponent>
|
|
114
|
+
</ThemeProvider>
|
|
115
|
+
);
|
|
116
|
+
const testelem = getByText('Text');
|
|
117
|
+
const style = getComputedStyle(testelem);
|
|
118
|
+
|
|
119
|
+
expect(style.marginTop).not.toEqual('0px'); // 0px come from base
|
|
120
|
+
expect(style.marginBottom).toEqual('0px'); // 0px still come from base
|
|
121
|
+
expect(style.marginTop).toEqual('2px'); // 2px marginTop come from variant
|
|
122
|
+
expect(style.paddingTop).toEqual('2px'); // 2px paddingTop come from variant
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
test('custom styles third', () => {
|
|
126
|
+
const TestComponent: React.FC<{ variant?: 'body' }> = ({
|
|
127
|
+
variant = 'body',
|
|
128
|
+
children,
|
|
129
|
+
...props
|
|
130
|
+
}) => {
|
|
131
|
+
const classNames = useStyles({
|
|
132
|
+
element: 'p',
|
|
133
|
+
variant: `text.${variant}`,
|
|
134
|
+
css: {
|
|
135
|
+
marginTop: '4px',
|
|
136
|
+
},
|
|
137
|
+
});
|
|
138
|
+
return (
|
|
139
|
+
<p className={classNames} {...props}>
|
|
140
|
+
{children}
|
|
141
|
+
</p>
|
|
142
|
+
);
|
|
143
|
+
};
|
|
144
|
+
|
|
145
|
+
const { getByText } = render(
|
|
146
|
+
<ThemeProvider theme={theme}>
|
|
147
|
+
<TestComponent>Text</TestComponent>
|
|
148
|
+
</ThemeProvider>
|
|
149
|
+
);
|
|
150
|
+
const testelem = getByText('Text');
|
|
151
|
+
const style = getComputedStyle(testelem);
|
|
152
|
+
|
|
153
|
+
expect(style.marginTop).not.toEqual('0px'); // do not apply 0px from base
|
|
154
|
+
expect(style.marginTop).not.toEqual('2px'); // do not apply 2px from variant
|
|
155
|
+
expect(style.marginTop).toEqual('4px'); // apply 4px from custom styles
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
test('customClassName styles fourth', () => {
|
|
159
|
+
const TestComponent: React.FC<{ variant?: 'body' }> = ({
|
|
160
|
+
variant = 'body',
|
|
161
|
+
children,
|
|
162
|
+
...props
|
|
163
|
+
}) => {
|
|
164
|
+
const custom = useStyles({ element: 'p', css: { marginTop: '8px' } });
|
|
165
|
+
const classNames = useStyles({
|
|
166
|
+
element: 'p',
|
|
167
|
+
variant: `text.${variant}`,
|
|
168
|
+
css: {
|
|
169
|
+
marginTop: '4px',
|
|
170
|
+
},
|
|
171
|
+
className: custom,
|
|
172
|
+
});
|
|
173
|
+
return (
|
|
174
|
+
<p className={classNames} {...props}>
|
|
175
|
+
{children}
|
|
176
|
+
</p>
|
|
177
|
+
);
|
|
178
|
+
};
|
|
179
|
+
|
|
180
|
+
const { getByText } = render(
|
|
181
|
+
<ThemeProvider theme={theme}>
|
|
182
|
+
<TestComponent>Text</TestComponent>
|
|
183
|
+
</ThemeProvider>
|
|
184
|
+
);
|
|
185
|
+
const testelem = getByText('Text');
|
|
186
|
+
const style = getComputedStyle(testelem);
|
|
187
|
+
|
|
188
|
+
expect(style.marginTop).not.toEqual('0px'); // do not apply 0px from base
|
|
189
|
+
expect(style.marginTop).not.toEqual('2px'); // do not apply 2px from variant
|
|
190
|
+
expect(style.marginTop).not.toEqual('4px'); // do not apply 4px from custom styles
|
|
191
|
+
expect(style.marginTop).toEqual('8px'); // apply 8px from customClassNames styles
|
|
192
|
+
});
|
|
193
|
+
|
|
194
|
+
test("don't apply the same reset multiple times", () => {
|
|
195
|
+
const Button = ({ className }: { className?: string }) => {
|
|
196
|
+
const classNames = useStyles({ element: 'button', className });
|
|
197
|
+
return (
|
|
198
|
+
<button title="button" className={classNames}>
|
|
199
|
+
Click me!
|
|
200
|
+
</button>
|
|
201
|
+
);
|
|
202
|
+
};
|
|
203
|
+
const Wrapper = () => <Button className={useStyles({ element: 'button' })} />;
|
|
204
|
+
|
|
205
|
+
render(<Wrapper />);
|
|
206
|
+
const button = screen.getByTitle('button');
|
|
207
|
+
const classNames = button.className.split(' ').filter(i => i.length);
|
|
208
|
+
|
|
209
|
+
// Test if applied classnames are unique
|
|
210
|
+
expect(classNames.length).toEqual([...new Set(classNames)].length);
|
|
211
|
+
});
|
|
212
|
+
|
|
213
|
+
test('element resets are applied dynamically', () => {
|
|
214
|
+
const Component = ({ element }: { element?: ElementType }) => (
|
|
215
|
+
<div title="element" className={useStyles({ element })}>
|
|
216
|
+
div
|
|
217
|
+
</div>
|
|
218
|
+
);
|
|
219
|
+
|
|
220
|
+
const { rerender } = render(<Component element="input" />);
|
|
221
|
+
const inputClassName = screen.getByTitle('element').className;
|
|
222
|
+
|
|
223
|
+
rerender(<Component element="table" />);
|
|
224
|
+
const tableClassName = screen.getByTitle('element').className;
|
|
225
|
+
|
|
226
|
+
expect(inputClassName).not.toEqual(tableClassName);
|
|
227
|
+
});
|
|
228
|
+
|
|
229
|
+
test('normalize base without element prop', () => {
|
|
230
|
+
const TestComponent: React.FC<{ variant?: 'body' }> = ({
|
|
231
|
+
variant = 'normal',
|
|
232
|
+
children,
|
|
233
|
+
...props
|
|
234
|
+
}) => {
|
|
235
|
+
const classNames = useStyles({
|
|
236
|
+
variant: `text.${variant}`,
|
|
237
|
+
});
|
|
238
|
+
return (
|
|
239
|
+
<a className={classNames} {...props}>
|
|
240
|
+
{children}
|
|
241
|
+
</a>
|
|
242
|
+
);
|
|
243
|
+
};
|
|
244
|
+
|
|
245
|
+
const { getByText } = render(
|
|
246
|
+
<ThemeProvider theme={theme}>
|
|
247
|
+
<TestComponent>Link</TestComponent>
|
|
248
|
+
</ThemeProvider>
|
|
249
|
+
);
|
|
250
|
+
const testelem = getByText('Link');
|
|
251
|
+
const style = getComputedStyle(testelem);
|
|
252
|
+
|
|
253
|
+
expect(style.boxSizing).toEqual('border-box');
|
|
254
|
+
expect(style.margin).toEqual('0px');
|
|
255
|
+
expect(style.padding).toEqual('0px');
|
|
256
|
+
expect(style.minWidth).toEqual('0');
|
|
257
|
+
});
|
|
258
|
+
|
|
259
|
+
test('normalize tag name <a>', () => {
|
|
260
|
+
const TestComponent: React.FC<{ variant?: 'body' }> = ({
|
|
261
|
+
variant = 'body',
|
|
262
|
+
children,
|
|
263
|
+
...props
|
|
264
|
+
}) => {
|
|
265
|
+
const classNames = useStyles({
|
|
266
|
+
element: 'a',
|
|
267
|
+
variant: `text.${variant}`,
|
|
268
|
+
});
|
|
269
|
+
return (
|
|
270
|
+
<a className={classNames} {...props}>
|
|
271
|
+
{children}
|
|
272
|
+
</a>
|
|
273
|
+
);
|
|
274
|
+
};
|
|
275
|
+
|
|
276
|
+
const { getByText } = render(
|
|
277
|
+
<ThemeProvider theme={theme}>
|
|
278
|
+
<TestComponent>Link</TestComponent>
|
|
279
|
+
</ThemeProvider>
|
|
280
|
+
);
|
|
281
|
+
const testelem = getByText('Link');
|
|
282
|
+
const style = getComputedStyle(testelem);
|
|
283
|
+
|
|
284
|
+
expect(style.boxSizing).toEqual('border-box'); // from base
|
|
285
|
+
expect(style.textDecoration).toEqual('none'); // from a
|
|
286
|
+
});
|
package/src/useStyles.ts
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { ElementType } from 'react';
|
|
2
|
+
import { reset } from './reset';
|
|
3
|
+
import { CSSObject } from './types';
|
|
4
|
+
import { useClassname } from './useClassname';
|
|
5
|
+
|
|
6
|
+
export type UseStyleInput = {
|
|
7
|
+
element?: ElementType;
|
|
8
|
+
css?: Omit<CSSObject, 'variant' | 'element'> & {
|
|
9
|
+
variant?: never;
|
|
10
|
+
element?: never;
|
|
11
|
+
};
|
|
12
|
+
variant?: string | string[];
|
|
13
|
+
className?: string;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Hook that can adds base styles, reset for certain elements, variants and custom styles
|
|
18
|
+
*/
|
|
19
|
+
export const useStyles = ({
|
|
20
|
+
element,
|
|
21
|
+
css: styles = {},
|
|
22
|
+
variant,
|
|
23
|
+
className = '',
|
|
24
|
+
}: UseStyleInput) => {
|
|
25
|
+
/**
|
|
26
|
+
* Get reset styles. Base is always applied. An additional reset maybe applied
|
|
27
|
+
* based on the passed element.
|
|
28
|
+
*
|
|
29
|
+
* We check the passed className if it already includes the reset styles so no
|
|
30
|
+
* duplicates are applied.
|
|
31
|
+
*/
|
|
32
|
+
const baseClassName = className.includes(reset.base) ? '' : reset.base;
|
|
33
|
+
const resetClassName =
|
|
34
|
+
typeof element === 'string'
|
|
35
|
+
? className.includes((reset as { [key: string]: string })[element])
|
|
36
|
+
? ''
|
|
37
|
+
: (reset as { [key: string]: string })[element]
|
|
38
|
+
: '';
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Get variant styles (from theme).
|
|
42
|
+
*/
|
|
43
|
+
const variants = Array.isArray(variant)
|
|
44
|
+
? variant.map(v => ({ variant: v }))
|
|
45
|
+
: [{ variant }];
|
|
46
|
+
const variantsClassName = useClassname(...variants);
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Custom styles are applied "on runtime". They are usually controlled via component
|
|
50
|
+
* props and can change between component instances.
|
|
51
|
+
*/
|
|
52
|
+
const customClassName = useClassname(styles);
|
|
53
|
+
|
|
54
|
+
return [
|
|
55
|
+
baseClassName,
|
|
56
|
+
resetClassName,
|
|
57
|
+
variantsClassName,
|
|
58
|
+
customClassName,
|
|
59
|
+
className,
|
|
60
|
+
]
|
|
61
|
+
.filter(Boolean)
|
|
62
|
+
.join(' ');
|
|
63
|
+
};
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { render, screen } from '@testing-library/react';
|
|
3
|
+
import { renderHook } from '@testing-library/react-hooks';
|
|
4
|
+
|
|
5
|
+
import { ThemeProvider, useTheme } from './useTheme';
|
|
6
|
+
|
|
7
|
+
// Setup
|
|
8
|
+
// ---------------
|
|
9
|
+
const theme = {
|
|
10
|
+
colors: {
|
|
11
|
+
primary: 'hotpink',
|
|
12
|
+
black: '#000',
|
|
13
|
+
},
|
|
14
|
+
space: {
|
|
15
|
+
none: 0,
|
|
16
|
+
small: 16,
|
|
17
|
+
medium: 24,
|
|
18
|
+
large: 32,
|
|
19
|
+
},
|
|
20
|
+
text: {
|
|
21
|
+
body: {
|
|
22
|
+
fontSize: 1,
|
|
23
|
+
color: 'black',
|
|
24
|
+
},
|
|
25
|
+
heading: {
|
|
26
|
+
fontSize: 3,
|
|
27
|
+
color: 'primary',
|
|
28
|
+
},
|
|
29
|
+
},
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
const wrapper: React.FC = ({ children }) => (
|
|
33
|
+
<ThemeProvider theme={theme}>{children}</ThemeProvider>
|
|
34
|
+
);
|
|
35
|
+
|
|
36
|
+
test('returns the theme', () => {
|
|
37
|
+
const { result } = renderHook(() => useTheme(), { wrapper });
|
|
38
|
+
expect(result.current.theme).toEqual(theme);
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
test('returns a "css" function', () => {
|
|
42
|
+
const { result } = renderHook(() => useTheme(), { wrapper });
|
|
43
|
+
expect(result.current.css).toEqual(expect.any(Function));
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
test('transpile style object to css object', () => {
|
|
47
|
+
const { result } = renderHook(() => useTheme(), { wrapper });
|
|
48
|
+
const css = result.current.css;
|
|
49
|
+
|
|
50
|
+
expect(css({ p: 'small' })).toMatchInlineSnapshot(`
|
|
51
|
+
Object {
|
|
52
|
+
"padding": 16,
|
|
53
|
+
}
|
|
54
|
+
`);
|
|
55
|
+
expect(css({ color: 'primary', p: 'large' })).toMatchInlineSnapshot(`
|
|
56
|
+
Object {
|
|
57
|
+
"color": "hotpink",
|
|
58
|
+
"padding": 32,
|
|
59
|
+
}
|
|
60
|
+
`);
|
|
61
|
+
expect(css({ variant: 'text.body' })).toMatchInlineSnapshot(`
|
|
62
|
+
Object {
|
|
63
|
+
"color": "#000",
|
|
64
|
+
"fontSize": 14,
|
|
65
|
+
}
|
|
66
|
+
`);
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
test('themes can be cascaded', () => {
|
|
70
|
+
const outerTheme = {
|
|
71
|
+
colors: {
|
|
72
|
+
primary: 'coral',
|
|
73
|
+
},
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
const innerTheme = {
|
|
77
|
+
colors: {
|
|
78
|
+
primary: 'gainsboro',
|
|
79
|
+
},
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
const Theme = ({ testId }: { testId: string }) => {
|
|
83
|
+
const { theme } = useTheme();
|
|
84
|
+
return <div data-testid={testId}>{JSON.stringify(theme, null, 2)}</div>;
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
render(
|
|
88
|
+
<ThemeProvider theme={outerTheme}>
|
|
89
|
+
<>
|
|
90
|
+
<Theme testId="outer" />
|
|
91
|
+
<ThemeProvider theme={innerTheme}>
|
|
92
|
+
<Theme testId="inner" />
|
|
93
|
+
</ThemeProvider>
|
|
94
|
+
</>
|
|
95
|
+
</ThemeProvider>
|
|
96
|
+
);
|
|
97
|
+
|
|
98
|
+
const outer = screen.getByTestId('outer');
|
|
99
|
+
const inner = screen.getByTestId('inner');
|
|
100
|
+
|
|
101
|
+
expect(outer.innerHTML).toMatchInlineSnapshot(`
|
|
102
|
+
"{
|
|
103
|
+
\\"colors\\": {
|
|
104
|
+
\\"primary\\": \\"coral\\"
|
|
105
|
+
}
|
|
106
|
+
}"
|
|
107
|
+
`);
|
|
108
|
+
expect(inner.innerHTML).toMatchInlineSnapshot(`
|
|
109
|
+
"{
|
|
110
|
+
\\"colors\\": {
|
|
111
|
+
\\"primary\\": \\"gainsboro\\"
|
|
112
|
+
}
|
|
113
|
+
}"
|
|
114
|
+
`);
|
|
115
|
+
});
|
package/src/useTheme.tsx
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import React, { createContext, useCallback, useContext } from 'react';
|
|
2
|
+
import { css as themeUi } from '@theme-ui/css';
|
|
3
|
+
import { Theme } from '@marigold/system';
|
|
4
|
+
|
|
5
|
+
import { StyleObject } from './types';
|
|
6
|
+
|
|
7
|
+
const Context = createContext<Theme>({});
|
|
8
|
+
|
|
9
|
+
export const useTheme = () => {
|
|
10
|
+
const theme = useContext(Context);
|
|
11
|
+
const css = useCallback(
|
|
12
|
+
(style: StyleObject) => themeUi(style)(theme),
|
|
13
|
+
[theme]
|
|
14
|
+
);
|
|
15
|
+
return { theme, css };
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export type ThemeProviderProps = { theme: any };
|
|
19
|
+
export const ThemeProvider: React.FC<ThemeProviderProps> = ({
|
|
20
|
+
theme,
|
|
21
|
+
children,
|
|
22
|
+
}) => <Context.Provider value={theme}>{children}</Context.Provider>;
|
package/dist/Box/Box.d.ts
DELETED
package/dist/Box/index.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './Box';
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
export declare type MarigoldProviderProps<T extends any> = React.PropsWithChildren<{
|
|
3
|
-
theme: T;
|
|
4
|
-
}>;
|
|
5
|
-
export declare const MarigoldProvider: <T extends unknown>({ theme, children, }: React.PropsWithChildren<{
|
|
6
|
-
theme: T;
|
|
7
|
-
}>) => JSX.Element;
|
package/dist/categories.d.ts
DELETED
|
@@ -1,169 +0,0 @@
|
|
|
1
|
-
import { PropertiesFallback } from 'csstype';
|
|
2
|
-
/**
|
|
3
|
-
* System categories are based on https://primer.style/components/docs/system-props
|
|
4
|
-
*/
|
|
5
|
-
export declare const SPACE_PROPS: string[];
|
|
6
|
-
declare type StandardCSSProperties = PropertiesFallback<number | string>;
|
|
7
|
-
export declare type SpacingProps = {
|
|
8
|
-
/**
|
|
9
|
-
* 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`.
|
|
10
|
-
*
|
|
11
|
-
* @see https://developer.mozilla.org/docs/Web/CSS/margin
|
|
12
|
-
*/
|
|
13
|
-
m?: StandardCSSProperties['margin'];
|
|
14
|
-
/**
|
|
15
|
-
* 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.
|
|
16
|
-
*
|
|
17
|
-
* **Initial value**: `0`
|
|
18
|
-
*
|
|
19
|
-
* @see https://developer.mozilla.org/docs/Web/CSS/margin-top
|
|
20
|
-
*/
|
|
21
|
-
mt?: StandardCSSProperties['marginTop'];
|
|
22
|
-
/**
|
|
23
|
-
* 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.
|
|
24
|
-
*
|
|
25
|
-
* **Initial value**: `0`
|
|
26
|
-
*
|
|
27
|
-
* @see https://developer.mozilla.org/docs/Web/CSS/margin-right
|
|
28
|
-
*/
|
|
29
|
-
mr?: StandardCSSProperties['marginRight'];
|
|
30
|
-
/**
|
|
31
|
-
* 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.
|
|
32
|
-
*
|
|
33
|
-
* **Initial value**: `0`
|
|
34
|
-
*
|
|
35
|
-
* @see https://developer.mozilla.org/docs/Web/CSS/margin-bottom
|
|
36
|
-
*/
|
|
37
|
-
mb?: StandardCSSProperties['marginBottom'];
|
|
38
|
-
/**
|
|
39
|
-
* 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.
|
|
40
|
-
*
|
|
41
|
-
* **Initial value**: `0`
|
|
42
|
-
*
|
|
43
|
-
* @see https://developer.mozilla.org/docs/Web/CSS/margin-left
|
|
44
|
-
*/
|
|
45
|
-
ml?: StandardCSSProperties['marginLeft'];
|
|
46
|
-
/**
|
|
47
|
-
* 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
|
|
48
|
-
* farther from its neighbors, while a negative value places it closer.
|
|
49
|
-
*
|
|
50
|
-
* **Initial value**: `0`
|
|
51
|
-
*
|
|
52
|
-
* @see https://styled-system.com/#margin-props
|
|
53
|
-
* @see https://developer.mozilla.org/docs/Web/CSS/margin-left
|
|
54
|
-
* @see https://developer.mozilla.org/docs/Web/CSS/margin-right
|
|
55
|
-
*/
|
|
56
|
-
mx?: StandardCSSProperties['marginLeft'];
|
|
57
|
-
/**
|
|
58
|
-
* 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
|
|
59
|
-
* places it farther from its neighbors, while a negative value places it closer.
|
|
60
|
-
*
|
|
61
|
-
* **Initial value**: `0`
|
|
62
|
-
*
|
|
63
|
-
* @see https://styled-system.com/#margin-props
|
|
64
|
-
* @see https://developer.mozilla.org/docs/Web/CSS/margin-left
|
|
65
|
-
* @see https://developer.mozilla.org/docs/Web/CSS/margin-right
|
|
66
|
-
*/
|
|
67
|
-
marginX?: StandardCSSProperties['marginLeft'];
|
|
68
|
-
/**
|
|
69
|
-
* 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
|
|
70
|
-
* farther from its neighbors, while a negative value places it closer.
|
|
71
|
-
*
|
|
72
|
-
* **Initial value**: `0`
|
|
73
|
-
*
|
|
74
|
-
* @see https://styled-system.com/#margin-props
|
|
75
|
-
* @see https://developer.mozilla.org/docs/Web/CSS/margin-top
|
|
76
|
-
* @see https://developer.mozilla.org/docs/Web/CSS/margin-bottom
|
|
77
|
-
*/
|
|
78
|
-
my?: StandardCSSProperties['marginTop'];
|
|
79
|
-
/**
|
|
80
|
-
* 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
|
|
81
|
-
* it farther from its neighbors, while a negative value places it closer.
|
|
82
|
-
*
|
|
83
|
-
* **Initial value**: `0`
|
|
84
|
-
*
|
|
85
|
-
* @see https://styled-system.com/#margin-props
|
|
86
|
-
* @see https://developer.mozilla.org/docs/Web/CSS/margin-top
|
|
87
|
-
* @see https://developer.mozilla.org/docs/Web/CSS/margin-bottom
|
|
88
|
-
*/
|
|
89
|
-
marginY?: StandardCSSProperties['marginTop'];
|
|
90
|
-
/**
|
|
91
|
-
* 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`.
|
|
92
|
-
*
|
|
93
|
-
* @see https://developer.mozilla.org/docs/Web/CSS/padding
|
|
94
|
-
*/
|
|
95
|
-
p?: StandardCSSProperties['padding'];
|
|
96
|
-
/**
|
|
97
|
-
* The **`padding-top`** padding area on the top of an element.
|
|
98
|
-
*
|
|
99
|
-
* **Initial value**: `0`
|
|
100
|
-
*
|
|
101
|
-
* @see https://developer.mozilla.org/docs/Web/CSS/padding-top
|
|
102
|
-
*/
|
|
103
|
-
pt?: StandardCSSProperties['paddingTop'];
|
|
104
|
-
/**
|
|
105
|
-
* The **`padding-right`** CSS property sets the width of the padding area on the right side of an element.
|
|
106
|
-
*
|
|
107
|
-
* **Initial value**: `0`
|
|
108
|
-
*
|
|
109
|
-
* @see https://developer.mozilla.org/docs/Web/CSS/padding-right
|
|
110
|
-
*/
|
|
111
|
-
pr?: StandardCSSProperties['paddingRight'];
|
|
112
|
-
/**
|
|
113
|
-
* The **`padding-bottom`** CSS property sets the height of the padding area on the bottom of an element.
|
|
114
|
-
*
|
|
115
|
-
* **Initial value**: `0`
|
|
116
|
-
*
|
|
117
|
-
* @see https://developer.mozilla.org/docs/Web/CSS/padding-bottom
|
|
118
|
-
*/
|
|
119
|
-
pb?: StandardCSSProperties['paddingBottom'];
|
|
120
|
-
/**
|
|
121
|
-
* The **`padding-left`** CSS property sets the width of the padding area on the left side of an element.
|
|
122
|
-
*
|
|
123
|
-
* **Initial value**: `0`
|
|
124
|
-
*
|
|
125
|
-
* @see https://developer.mozilla.org/docs/Web/CSS/padding-left
|
|
126
|
-
*/
|
|
127
|
-
pl?: StandardCSSProperties['paddingLeft'];
|
|
128
|
-
/**
|
|
129
|
-
* 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.
|
|
130
|
-
*
|
|
131
|
-
* **Initial value**: `0`
|
|
132
|
-
*
|
|
133
|
-
* @see https://styled-system.com/#padding-props
|
|
134
|
-
* @see https://developer.mozilla.org/docs/Web/CSS/padding-left
|
|
135
|
-
* @see https://developer.mozilla.org/docs/Web/CSS/padding-right
|
|
136
|
-
*/
|
|
137
|
-
px?: StandardCSSProperties['paddingLeft'];
|
|
138
|
-
/**
|
|
139
|
-
* 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.
|
|
140
|
-
*
|
|
141
|
-
* **Initial value**: `0`
|
|
142
|
-
*
|
|
143
|
-
* @see https://styled-system.com/#padding-props
|
|
144
|
-
* @see https://developer.mozilla.org/docs/Web/CSS/padding-left
|
|
145
|
-
* @see https://developer.mozilla.org/docs/Web/CSS/padding-right
|
|
146
|
-
*/
|
|
147
|
-
paddingX?: StandardCSSProperties['paddingLeft'];
|
|
148
|
-
/**
|
|
149
|
-
* 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.
|
|
150
|
-
*
|
|
151
|
-
* **Initial value**: `0`
|
|
152
|
-
*
|
|
153
|
-
* @see https://styled-system.com/#padding-props
|
|
154
|
-
* @see https://developer.mozilla.org/docs/Web/CSS/padding-top
|
|
155
|
-
* @see https://developer.mozilla.org/docs/Web/CSS/padding-bottom
|
|
156
|
-
*/
|
|
157
|
-
py?: StandardCSSProperties['paddingTop'];
|
|
158
|
-
/**
|
|
159
|
-
* 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.
|
|
160
|
-
*
|
|
161
|
-
* **Initial value**: `0`
|
|
162
|
-
*
|
|
163
|
-
* @see https://styled-system.com/#padding-props
|
|
164
|
-
* @see https://developer.mozilla.org/docs/Web/CSS/padding-top
|
|
165
|
-
* @see https://developer.mozilla.org/docs/Web/CSS/padding-bottom
|
|
166
|
-
*/
|
|
167
|
-
paddingY?: StandardCSSProperties['paddingTop'];
|
|
168
|
-
};
|
|
169
|
-
export {};
|
package/dist/emotion.d.ts
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
export declare const jsx: typeof React.createElement;
|
|
3
|
-
export declare const css: (template: TemplateStringsArray, ...args: any[]) => object;
|
|
4
|
-
export declare const ThemeContext: React.Context<any>;
|
|
5
|
-
export declare const Global: (props: React.PropsWithChildren<{
|
|
6
|
-
styles: any;
|
|
7
|
-
}>) => React.ReactElement;
|