@ttoss/ui 0.9.0 → 1.3.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/esm/index.js +101 -22
- package/dist/index.d.ts +18 -8
- package/dist/index.js +108 -30
- package/package.json +11 -7
- package/src/components/Button/Button.tsx +12 -2
- package/src/components/Card/Card.tsx +3 -0
- package/src/components/FormField/FormField.spec.tsx +5 -5
- package/src/components/Link/Link.tsx +3 -0
- package/src/index.ts +8 -2
- package/src/theme/ThemeProvider.spec.tsx +74 -0
- package/src/theme/ThemeProvider.tsx +33 -8
- package/src/theme/defaultTheme.ts +42 -0
- package/src/theme/useTheme.ts +3 -0
- package/src/theme/theme.ts +0 -25
package/dist/esm/index.js
CHANGED
|
@@ -1,11 +1,40 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __defProps = Object.defineProperties;
|
|
3
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
4
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
7
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
8
|
+
var __spreadValues = (a, b) => {
|
|
9
|
+
for (var prop in b || (b = {}))
|
|
10
|
+
if (__hasOwnProp.call(b, prop))
|
|
11
|
+
__defNormalProp(a, prop, b[prop]);
|
|
12
|
+
if (__getOwnPropSymbols)
|
|
13
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
14
|
+
if (__propIsEnum.call(b, prop))
|
|
15
|
+
__defNormalProp(a, prop, b[prop]);
|
|
16
|
+
}
|
|
17
|
+
return a;
|
|
18
|
+
};
|
|
19
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
20
|
+
|
|
1
21
|
// tsup.inject.js
|
|
2
22
|
import * as React from "react";
|
|
3
23
|
|
|
24
|
+
// src/index.ts
|
|
25
|
+
import * as color from "@theme-ui/color";
|
|
26
|
+
import { Themed } from "@theme-ui/mdx";
|
|
27
|
+
|
|
4
28
|
// src/theme/ThemeProvider.tsx
|
|
5
|
-
import {
|
|
29
|
+
import { Global } from "@emotion/react";
|
|
30
|
+
import {
|
|
31
|
+
ThemeProvider as ThemeUiProvider,
|
|
32
|
+
merge
|
|
33
|
+
} from "@theme-ui/core";
|
|
34
|
+
import * as React2 from "react";
|
|
6
35
|
|
|
7
|
-
// src/theme/
|
|
8
|
-
var
|
|
36
|
+
// src/theme/defaultTheme.ts
|
|
37
|
+
var defaultTheme = {
|
|
9
38
|
colors: {
|
|
10
39
|
text: "#000",
|
|
11
40
|
background: "#fff",
|
|
@@ -13,41 +42,83 @@ var theme = {
|
|
|
13
42
|
secondary: "#639",
|
|
14
43
|
gray: "#555"
|
|
15
44
|
},
|
|
45
|
+
space: [0, 4, 8, 16, 32, 64, 128, 256, 512],
|
|
46
|
+
styles: {
|
|
47
|
+
a: {
|
|
48
|
+
color: "primary",
|
|
49
|
+
textDecoration: "underline",
|
|
50
|
+
cursor: "pointer"
|
|
51
|
+
}
|
|
52
|
+
},
|
|
16
53
|
buttons: {
|
|
17
54
|
primary: {
|
|
18
|
-
color: "
|
|
19
|
-
|
|
55
|
+
color: "white",
|
|
56
|
+
backgroundColor: "primary"
|
|
20
57
|
},
|
|
21
58
|
secondary: {
|
|
22
|
-
color: "
|
|
23
|
-
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
59
|
+
color: "white",
|
|
60
|
+
backgroundColor: "secondary"
|
|
61
|
+
}
|
|
62
|
+
},
|
|
63
|
+
cards: {
|
|
64
|
+
primary: {
|
|
65
|
+
backgroundColor: "background",
|
|
66
|
+
border: "1px solid black",
|
|
67
|
+
padding: [4, 5]
|
|
68
|
+
}
|
|
69
|
+
},
|
|
70
|
+
text: {
|
|
71
|
+
title: {
|
|
72
|
+
fontSize: [4, 5],
|
|
73
|
+
textAlign: "center"
|
|
28
74
|
}
|
|
29
75
|
}
|
|
30
76
|
};
|
|
31
77
|
|
|
32
78
|
// src/theme/ThemeProvider.tsx
|
|
33
|
-
var ThemeProvider = ({ children }) => {
|
|
34
|
-
|
|
35
|
-
theme
|
|
36
|
-
|
|
79
|
+
var ThemeProvider = ({ children, theme = {} }) => {
|
|
80
|
+
const mergedTheme = React2.useMemo(() => {
|
|
81
|
+
if (typeof theme === "function") {
|
|
82
|
+
return theme;
|
|
83
|
+
}
|
|
84
|
+
return merge(defaultTheme, theme);
|
|
85
|
+
}, [theme]);
|
|
86
|
+
return /* @__PURE__ */ React2.createElement(React2.Fragment, null, /* @__PURE__ */ React2.createElement(ThemeUiProvider, {
|
|
87
|
+
theme: mergedTheme
|
|
88
|
+
}, /* @__PURE__ */ React2.createElement(Global, {
|
|
89
|
+
styles: {
|
|
90
|
+
"*": {
|
|
91
|
+
margin: 0
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}), children));
|
|
37
95
|
};
|
|
38
96
|
var ThemeProvider_default = ThemeProvider;
|
|
39
97
|
|
|
98
|
+
// src/theme/useTheme.ts
|
|
99
|
+
import { useThemeUI } from "@theme-ui/core";
|
|
100
|
+
var useTheme = useThemeUI;
|
|
101
|
+
|
|
40
102
|
// src/components/Box/Box.tsx
|
|
41
103
|
import { Box } from "@theme-ui/components";
|
|
42
104
|
|
|
43
105
|
// src/components/Button/Button.tsx
|
|
44
|
-
import { Button } from "@theme-ui/components";
|
|
106
|
+
import { Button as ButtonUi } from "@theme-ui/components";
|
|
107
|
+
var Button = (props) => {
|
|
108
|
+
return /* @__PURE__ */ React.createElement(ButtonUi, __spreadProps(__spreadValues({}, props), {
|
|
109
|
+
sx: __spreadValues({ cursor: "pointer", padding: 2 }, props.sx)
|
|
110
|
+
}));
|
|
111
|
+
};
|
|
112
|
+
var Button_default = Button;
|
|
113
|
+
|
|
114
|
+
// src/components/Card/Card.tsx
|
|
115
|
+
import { Card } from "@theme-ui/components";
|
|
45
116
|
|
|
46
117
|
// src/components/Flex/Flex.tsx
|
|
47
118
|
import { Flex } from "@theme-ui/components";
|
|
48
119
|
|
|
49
120
|
// src/components/FormField/FormField.tsx
|
|
50
|
-
import * as
|
|
121
|
+
import * as React3 from "react";
|
|
51
122
|
|
|
52
123
|
// src/components/Label/Label.tsx
|
|
53
124
|
import { Label } from "@theme-ui/components";
|
|
@@ -66,11 +137,11 @@ var FormField = ({ children, label, error }) => {
|
|
|
66
137
|
}
|
|
67
138
|
return [];
|
|
68
139
|
})();
|
|
69
|
-
return /* @__PURE__ */
|
|
140
|
+
return /* @__PURE__ */ React3.createElement(Box, null, /* @__PURE__ */ React3.createElement(Label, {
|
|
70
141
|
sx: { display: "flex", flexDirection: "column" }
|
|
71
|
-
}, label && /* @__PURE__ */
|
|
142
|
+
}, label && /* @__PURE__ */ React3.createElement(Text, {
|
|
72
143
|
as: "span"
|
|
73
|
-
}, label), children), errorAsArray.map((err) => /* @__PURE__ */
|
|
144
|
+
}, label), children), errorAsArray.map((err) => /* @__PURE__ */ React3.createElement(Text, {
|
|
74
145
|
key: err,
|
|
75
146
|
as: "span",
|
|
76
147
|
variant: "error"
|
|
@@ -83,13 +154,21 @@ import { Image } from "@theme-ui/components";
|
|
|
83
154
|
|
|
84
155
|
// src/components/Input/Input.tsx
|
|
85
156
|
import { Input } from "@theme-ui/components";
|
|
157
|
+
|
|
158
|
+
// src/components/Link/Link.tsx
|
|
159
|
+
import { Link } from "@theme-ui/components";
|
|
86
160
|
export {
|
|
87
161
|
Box,
|
|
88
|
-
Button,
|
|
162
|
+
Button_default as Button,
|
|
163
|
+
Card,
|
|
89
164
|
Flex,
|
|
90
165
|
FormField_default as FormField,
|
|
91
166
|
Image,
|
|
92
167
|
Input,
|
|
168
|
+
Link,
|
|
93
169
|
Text,
|
|
94
|
-
ThemeProvider_default as ThemeProvider
|
|
170
|
+
ThemeProvider_default as ThemeProvider,
|
|
171
|
+
Themed,
|
|
172
|
+
color,
|
|
173
|
+
useTheme
|
|
95
174
|
};
|
package/dist/index.d.ts
CHANGED
|
@@ -1,17 +1,27 @@
|
|
|
1
|
-
import
|
|
2
|
-
export {
|
|
3
|
-
import * as
|
|
1
|
+
import * as color from '@theme-ui/color';
|
|
2
|
+
export { color };
|
|
3
|
+
import * as _theme_ui_core from '@theme-ui/core';
|
|
4
|
+
import { ThemeProviderProps as ThemeProviderProps$1 } from '@theme-ui/core';
|
|
5
|
+
export { Theme } from '@theme-ui/core';
|
|
6
|
+
export { Themed } from '@theme-ui/mdx';
|
|
7
|
+
import * as React from 'react';
|
|
8
|
+
import { ButtonProps } from '@theme-ui/components';
|
|
9
|
+
export { Box, BoxProps, ButtonProps, Card, CardProps, Flex, FlexProps, Image, ImageProps, Input, InputProps, Link, LinkProps, Text, TextProps } from '@theme-ui/components';
|
|
4
10
|
|
|
5
|
-
declare type ThemeProviderProps = {
|
|
6
|
-
|
|
11
|
+
declare type ThemeProviderProps = ThemeProviderProps$1 & {
|
|
12
|
+
children?: React.ReactNode;
|
|
7
13
|
};
|
|
8
|
-
declare const ThemeProvider:
|
|
14
|
+
declare const ThemeProvider: ({ children, theme }: ThemeProviderProps) => JSX.Element;
|
|
15
|
+
|
|
16
|
+
declare const useTheme: () => _theme_ui_core.ThemeUIContextValue;
|
|
17
|
+
|
|
18
|
+
declare const Button: (props: ButtonProps) => JSX.Element;
|
|
9
19
|
|
|
10
20
|
declare type FormFieldProps = {
|
|
11
|
-
children?: React
|
|
21
|
+
children?: React.ReactNode;
|
|
12
22
|
label?: string;
|
|
13
23
|
error?: string[] | string;
|
|
14
24
|
};
|
|
15
25
|
declare const FormField: ({ children, label, error }: FormFieldProps) => JSX.Element;
|
|
16
26
|
|
|
17
|
-
export { FormField, FormFieldProps, ThemeProvider, ThemeProviderProps };
|
|
27
|
+
export { Button, FormField, FormFieldProps, ThemeProvider, ThemeProviderProps, useTheme };
|
package/dist/index.js
CHANGED
|
@@ -1,9 +1,26 @@
|
|
|
1
1
|
var __create = Object.create;
|
|
2
2
|
var __defProp = Object.defineProperty;
|
|
3
|
+
var __defProps = Object.defineProperties;
|
|
3
4
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
4
6
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
5
8
|
var __getProtoOf = Object.getPrototypeOf;
|
|
6
9
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
10
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
11
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
12
|
+
var __spreadValues = (a, b) => {
|
|
13
|
+
for (var prop in b || (b = {}))
|
|
14
|
+
if (__hasOwnProp.call(b, prop))
|
|
15
|
+
__defNormalProp(a, prop, b[prop]);
|
|
16
|
+
if (__getOwnPropSymbols)
|
|
17
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
18
|
+
if (__propIsEnum.call(b, prop))
|
|
19
|
+
__defNormalProp(a, prop, b[prop]);
|
|
20
|
+
}
|
|
21
|
+
return a;
|
|
22
|
+
};
|
|
23
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
7
24
|
var __markAsModule = (target) => __defProp(target, "__esModule", { value: true });
|
|
8
25
|
var __export = (target, all) => {
|
|
9
26
|
for (var name in all)
|
|
@@ -30,23 +47,34 @@ var __toCommonJS = /* @__PURE__ */ ((cache) => {
|
|
|
30
47
|
var src_exports = {};
|
|
31
48
|
__export(src_exports, {
|
|
32
49
|
Box: () => import_components.Box,
|
|
33
|
-
Button: () =>
|
|
34
|
-
|
|
50
|
+
Button: () => Button_default,
|
|
51
|
+
Card: () => import_components3.Card,
|
|
52
|
+
Flex: () => import_components4.Flex,
|
|
35
53
|
FormField: () => FormField_default,
|
|
36
|
-
Image: () =>
|
|
37
|
-
Input: () =>
|
|
38
|
-
|
|
39
|
-
|
|
54
|
+
Image: () => import_components7.Image,
|
|
55
|
+
Input: () => import_components8.Input,
|
|
56
|
+
Link: () => import_components9.Link,
|
|
57
|
+
Text: () => import_components6.Text,
|
|
58
|
+
ThemeProvider: () => ThemeProvider_default,
|
|
59
|
+
Themed: () => import_mdx.Themed,
|
|
60
|
+
color: () => color,
|
|
61
|
+
useTheme: () => useTheme
|
|
40
62
|
});
|
|
41
63
|
|
|
42
64
|
// tsup.inject.js
|
|
43
65
|
var React = __toESM(require("react"));
|
|
44
66
|
|
|
67
|
+
// src/index.ts
|
|
68
|
+
var color = __toESM(require("@theme-ui/color"));
|
|
69
|
+
var import_mdx = require("@theme-ui/mdx");
|
|
70
|
+
|
|
45
71
|
// src/theme/ThemeProvider.tsx
|
|
72
|
+
var import_react = require("@emotion/react");
|
|
46
73
|
var import_core = require("@theme-ui/core");
|
|
74
|
+
var React2 = __toESM(require("react"));
|
|
47
75
|
|
|
48
|
-
// src/theme/
|
|
49
|
-
var
|
|
76
|
+
// src/theme/defaultTheme.ts
|
|
77
|
+
var defaultTheme = {
|
|
50
78
|
colors: {
|
|
51
79
|
text: "#000",
|
|
52
80
|
background: "#fff",
|
|
@@ -54,47 +82,89 @@ var theme = {
|
|
|
54
82
|
secondary: "#639",
|
|
55
83
|
gray: "#555"
|
|
56
84
|
},
|
|
85
|
+
space: [0, 4, 8, 16, 32, 64, 128, 256, 512],
|
|
86
|
+
styles: {
|
|
87
|
+
a: {
|
|
88
|
+
color: "primary",
|
|
89
|
+
textDecoration: "underline",
|
|
90
|
+
cursor: "pointer"
|
|
91
|
+
}
|
|
92
|
+
},
|
|
57
93
|
buttons: {
|
|
58
94
|
primary: {
|
|
59
|
-
color: "
|
|
60
|
-
|
|
95
|
+
color: "white",
|
|
96
|
+
backgroundColor: "primary"
|
|
61
97
|
},
|
|
62
98
|
secondary: {
|
|
63
|
-
color: "
|
|
64
|
-
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
99
|
+
color: "white",
|
|
100
|
+
backgroundColor: "secondary"
|
|
101
|
+
}
|
|
102
|
+
},
|
|
103
|
+
cards: {
|
|
104
|
+
primary: {
|
|
105
|
+
backgroundColor: "background",
|
|
106
|
+
border: "1px solid black",
|
|
107
|
+
padding: [4, 5]
|
|
108
|
+
}
|
|
109
|
+
},
|
|
110
|
+
text: {
|
|
111
|
+
title: {
|
|
112
|
+
fontSize: [4, 5],
|
|
113
|
+
textAlign: "center"
|
|
69
114
|
}
|
|
70
115
|
}
|
|
71
116
|
};
|
|
72
117
|
|
|
73
118
|
// src/theme/ThemeProvider.tsx
|
|
74
|
-
var ThemeProvider = ({ children }) => {
|
|
75
|
-
|
|
76
|
-
theme
|
|
77
|
-
|
|
119
|
+
var ThemeProvider = ({ children, theme = {} }) => {
|
|
120
|
+
const mergedTheme = React2.useMemo(() => {
|
|
121
|
+
if (typeof theme === "function") {
|
|
122
|
+
return theme;
|
|
123
|
+
}
|
|
124
|
+
return (0, import_core.merge)(defaultTheme, theme);
|
|
125
|
+
}, [theme]);
|
|
126
|
+
return /* @__PURE__ */ React2.createElement(React2.Fragment, null, /* @__PURE__ */ React2.createElement(import_core.ThemeProvider, {
|
|
127
|
+
theme: mergedTheme
|
|
128
|
+
}, /* @__PURE__ */ React2.createElement(import_react.Global, {
|
|
129
|
+
styles: {
|
|
130
|
+
"*": {
|
|
131
|
+
margin: 0
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
}), children));
|
|
78
135
|
};
|
|
79
136
|
var ThemeProvider_default = ThemeProvider;
|
|
80
137
|
|
|
138
|
+
// src/theme/useTheme.ts
|
|
139
|
+
var import_core2 = require("@theme-ui/core");
|
|
140
|
+
var useTheme = import_core2.useThemeUI;
|
|
141
|
+
|
|
81
142
|
// src/components/Box/Box.tsx
|
|
82
143
|
var import_components = require("@theme-ui/components");
|
|
83
144
|
|
|
84
145
|
// src/components/Button/Button.tsx
|
|
85
146
|
var import_components2 = require("@theme-ui/components");
|
|
147
|
+
var Button = (props) => {
|
|
148
|
+
return /* @__PURE__ */ React.createElement(import_components2.Button, __spreadProps(__spreadValues({}, props), {
|
|
149
|
+
sx: __spreadValues({ cursor: "pointer", padding: 2 }, props.sx)
|
|
150
|
+
}));
|
|
151
|
+
};
|
|
152
|
+
var Button_default = Button;
|
|
86
153
|
|
|
87
|
-
// src/components/
|
|
154
|
+
// src/components/Card/Card.tsx
|
|
88
155
|
var import_components3 = require("@theme-ui/components");
|
|
89
156
|
|
|
157
|
+
// src/components/Flex/Flex.tsx
|
|
158
|
+
var import_components4 = require("@theme-ui/components");
|
|
159
|
+
|
|
90
160
|
// src/components/FormField/FormField.tsx
|
|
91
|
-
var
|
|
161
|
+
var React3 = __toESM(require("react"));
|
|
92
162
|
|
|
93
163
|
// src/components/Label/Label.tsx
|
|
94
|
-
var
|
|
164
|
+
var import_components5 = require("@theme-ui/components");
|
|
95
165
|
|
|
96
166
|
// src/components/Text/Text.tsx
|
|
97
|
-
var
|
|
167
|
+
var import_components6 = require("@theme-ui/components");
|
|
98
168
|
|
|
99
169
|
// src/components/FormField/FormField.tsx
|
|
100
170
|
var FormField = ({ children, label, error }) => {
|
|
@@ -107,11 +177,11 @@ var FormField = ({ children, label, error }) => {
|
|
|
107
177
|
}
|
|
108
178
|
return [];
|
|
109
179
|
})();
|
|
110
|
-
return /* @__PURE__ */
|
|
180
|
+
return /* @__PURE__ */ React3.createElement(import_components.Box, null, /* @__PURE__ */ React3.createElement(import_components5.Label, {
|
|
111
181
|
sx: { display: "flex", flexDirection: "column" }
|
|
112
|
-
}, label && /* @__PURE__ */
|
|
182
|
+
}, label && /* @__PURE__ */ React3.createElement(import_components6.Text, {
|
|
113
183
|
as: "span"
|
|
114
|
-
}, label), children), errorAsArray.map((err) => /* @__PURE__ */
|
|
184
|
+
}, label), children), errorAsArray.map((err) => /* @__PURE__ */ React3.createElement(import_components6.Text, {
|
|
115
185
|
key: err,
|
|
116
186
|
as: "span",
|
|
117
187
|
variant: "error"
|
|
@@ -120,19 +190,27 @@ var FormField = ({ children, label, error }) => {
|
|
|
120
190
|
var FormField_default = FormField;
|
|
121
191
|
|
|
122
192
|
// src/components/Image/Image.tsx
|
|
123
|
-
var
|
|
193
|
+
var import_components7 = require("@theme-ui/components");
|
|
124
194
|
|
|
125
195
|
// src/components/Input/Input.tsx
|
|
126
|
-
var
|
|
196
|
+
var import_components8 = require("@theme-ui/components");
|
|
197
|
+
|
|
198
|
+
// src/components/Link/Link.tsx
|
|
199
|
+
var import_components9 = require("@theme-ui/components");
|
|
127
200
|
module.exports = __toCommonJS(src_exports);
|
|
128
201
|
// Annotate the CommonJS export names for ESM import in node:
|
|
129
202
|
0 && (module.exports = {
|
|
130
203
|
Box,
|
|
131
204
|
Button,
|
|
205
|
+
Card,
|
|
132
206
|
Flex,
|
|
133
207
|
FormField,
|
|
134
208
|
Image,
|
|
135
209
|
Input,
|
|
210
|
+
Link,
|
|
136
211
|
Text,
|
|
137
|
-
ThemeProvider
|
|
212
|
+
ThemeProvider,
|
|
213
|
+
Themed,
|
|
214
|
+
color,
|
|
215
|
+
useTheme
|
|
138
216
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ttoss/ui",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "1.3.0",
|
|
4
4
|
"description": "Primitive layout, typographic, and other components for styling applications.",
|
|
5
5
|
"license": "UNLICENSED",
|
|
6
6
|
"publishConfig": {
|
|
@@ -32,15 +32,19 @@
|
|
|
32
32
|
"dev": "yarn workspace @ttoss/storybook run dev"
|
|
33
33
|
},
|
|
34
34
|
"dependencies": {
|
|
35
|
-
"@
|
|
36
|
-
"@
|
|
35
|
+
"@emotion/react": "^11",
|
|
36
|
+
"@emotion/styled": "^11",
|
|
37
|
+
"@theme-ui/color": "^0.13.1",
|
|
38
|
+
"@theme-ui/components": "^0.13.1",
|
|
39
|
+
"@theme-ui/core": "^0.13.1",
|
|
40
|
+
"@theme-ui/mdx": "^0.13.1"
|
|
37
41
|
},
|
|
38
42
|
"peerDependencies": {
|
|
39
|
-
"react": ">=
|
|
43
|
+
"react": ">=17.0.2"
|
|
40
44
|
},
|
|
41
45
|
"devDependencies": {
|
|
42
|
-
"@ttoss/config": "^
|
|
43
|
-
"@ttoss/test-utils": "^
|
|
46
|
+
"@ttoss/config": "^1.3.0",
|
|
47
|
+
"@ttoss/test-utils": "^1.3.0"
|
|
44
48
|
},
|
|
45
|
-
"gitHead": "
|
|
49
|
+
"gitHead": "c709beaea1ad270f740d860e91b1a42641ebccda"
|
|
46
50
|
}
|
|
@@ -1,3 +1,13 @@
|
|
|
1
|
-
|
|
1
|
+
import { Button as ButtonUi } from '@theme-ui/components';
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
import type { ButtonProps } from '@theme-ui/components';
|
|
4
|
+
|
|
5
|
+
export type { ButtonProps };
|
|
6
|
+
|
|
7
|
+
const Button = (props: ButtonProps) => {
|
|
8
|
+
return (
|
|
9
|
+
<ButtonUi {...props} sx={{ cursor: 'pointer', padding: 2, ...props.sx }} />
|
|
10
|
+
);
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
export default Button;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { render, screen } from '@ttoss/test-utils';
|
|
2
2
|
|
|
3
3
|
import Input from '../Input/Input';
|
|
4
4
|
|
|
@@ -8,7 +8,7 @@ const label = 'Label';
|
|
|
8
8
|
const value = 'Value';
|
|
9
9
|
|
|
10
10
|
test('check if label is rendered on screen', () => {
|
|
11
|
-
|
|
11
|
+
render(
|
|
12
12
|
<FormField label={label}>
|
|
13
13
|
<Input defaultValue={value} />
|
|
14
14
|
</FormField>
|
|
@@ -18,7 +18,7 @@ test('check if label is rendered on screen', () => {
|
|
|
18
18
|
});
|
|
19
19
|
|
|
20
20
|
test('check if label is associated with input', () => {
|
|
21
|
-
|
|
21
|
+
render(
|
|
22
22
|
<FormField label={label}>
|
|
23
23
|
<Input defaultValue={value} />
|
|
24
24
|
</FormField>
|
|
@@ -30,7 +30,7 @@ test('check if label is associated with input', () => {
|
|
|
30
30
|
test('check if renders a single error', () => {
|
|
31
31
|
const error = 'Error';
|
|
32
32
|
|
|
33
|
-
|
|
33
|
+
render(
|
|
34
34
|
<FormField label={label} error={error}>
|
|
35
35
|
<Input defaultValue={value} />
|
|
36
36
|
</FormField>
|
|
@@ -42,7 +42,7 @@ test('check if renders a single error', () => {
|
|
|
42
42
|
test('check if renders multiple errors', () => {
|
|
43
43
|
const errors = ['Error1', 'Error2', 'Error3'];
|
|
44
44
|
|
|
45
|
-
|
|
45
|
+
render(
|
|
46
46
|
<FormField label={label} error={errors}>
|
|
47
47
|
<Input defaultValue={value} />
|
|
48
48
|
</FormField>
|
package/src/index.ts
CHANGED
|
@@ -1,12 +1,17 @@
|
|
|
1
|
+
export * as color from '@theme-ui/color';
|
|
2
|
+
export type { Theme } from '@theme-ui/core';
|
|
3
|
+
export { Themed } from '@theme-ui/mdx';
|
|
4
|
+
|
|
1
5
|
export {
|
|
2
6
|
default as ThemeProvider,
|
|
3
7
|
ThemeProviderProps,
|
|
4
8
|
} from './theme/ThemeProvider';
|
|
5
9
|
|
|
6
|
-
export {
|
|
7
|
-
export type { BoxProps } from './components/Box/Box';
|
|
10
|
+
export { useTheme } from './theme/useTheme';
|
|
8
11
|
|
|
12
|
+
export { default as Box, BoxProps } from './components/Box/Box';
|
|
9
13
|
export { default as Button, ButtonProps } from './components/Button/Button';
|
|
14
|
+
export { default as Card, CardProps } from './components/Card/Card';
|
|
10
15
|
export { default as Flex, FlexProps } from './components/Flex/Flex';
|
|
11
16
|
export {
|
|
12
17
|
default as FormField,
|
|
@@ -14,4 +19,5 @@ export {
|
|
|
14
19
|
} from './components/FormField/FormField';
|
|
15
20
|
export { default as Image, ImageProps } from './components/Image/Image';
|
|
16
21
|
export { default as Input, InputProps } from './components/Input/Input';
|
|
22
|
+
export { default as Link, LinkProps } from './components/Link/Link';
|
|
17
23
|
export { default as Text, TextProps } from './components/Text/Text';
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { renderHook } from '@ttoss/test-utils';
|
|
2
|
+
|
|
3
|
+
import { defaultTheme } from './defaultTheme';
|
|
4
|
+
import ThemeProvider from './ThemeProvider';
|
|
5
|
+
import { useTheme } from './useTheme';
|
|
6
|
+
|
|
7
|
+
test('should return default theme colors', () => {
|
|
8
|
+
const { result } = renderHook(() => useTheme(), {
|
|
9
|
+
wrapper: ThemeProvider,
|
|
10
|
+
initialProps: { theme: {} },
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
expect(result.current.theme.colors).toEqual(defaultTheme.colors);
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
test('should return new theme colors', () => {
|
|
17
|
+
const newColor = '#000';
|
|
18
|
+
|
|
19
|
+
const { result } = renderHook(() => useTheme(), {
|
|
20
|
+
wrapper: ThemeProvider,
|
|
21
|
+
initialProps: {
|
|
22
|
+
theme: {
|
|
23
|
+
colors: {
|
|
24
|
+
background: newColor,
|
|
25
|
+
text: newColor,
|
|
26
|
+
primary: newColor,
|
|
27
|
+
secondary: newColor,
|
|
28
|
+
},
|
|
29
|
+
},
|
|
30
|
+
},
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
expect(result.current.theme.colors?.background).toEqual(newColor);
|
|
34
|
+
expect(result.current.theme.colors?.text).toEqual(newColor);
|
|
35
|
+
expect(result.current.theme.colors?.primary).toEqual(newColor);
|
|
36
|
+
expect(result.current.theme.colors?.secondary).toEqual(newColor);
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
test('should pass variants', () => {
|
|
40
|
+
const authCard = {
|
|
41
|
+
backgroundColor: 'red',
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
const authLayout = {
|
|
45
|
+
backgroundColor: 'blue',
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
const variants = {
|
|
49
|
+
layout: {
|
|
50
|
+
auth: authLayout,
|
|
51
|
+
},
|
|
52
|
+
cards: {
|
|
53
|
+
auth: authCard,
|
|
54
|
+
},
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
const { result } = renderHook(() => useTheme(), {
|
|
58
|
+
wrapper: ThemeProvider,
|
|
59
|
+
initialProps: {
|
|
60
|
+
theme: {
|
|
61
|
+
colors: {},
|
|
62
|
+
...variants,
|
|
63
|
+
},
|
|
64
|
+
},
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
expect(result.current.theme.cards).toEqual(
|
|
68
|
+
expect.objectContaining(variants.cards)
|
|
69
|
+
);
|
|
70
|
+
|
|
71
|
+
expect(result.current.theme.layout).toEqual(
|
|
72
|
+
expect.objectContaining(variants.layout)
|
|
73
|
+
);
|
|
74
|
+
});
|
|
@@ -1,15 +1,40 @@
|
|
|
1
|
-
|
|
1
|
+
import { Global } from '@emotion/react';
|
|
2
|
+
import {
|
|
3
|
+
ThemeProvider as ThemeUiProvider,
|
|
4
|
+
ThemeProviderProps as ThemeUiProviderProps,
|
|
5
|
+
merge,
|
|
6
|
+
} from '@theme-ui/core';
|
|
7
|
+
import * as React from 'react';
|
|
2
8
|
|
|
3
|
-
import {
|
|
9
|
+
import { defaultTheme } from './defaultTheme';
|
|
4
10
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
export type ThemeProviderProps = {
|
|
8
|
-
theme?: Theme | ((outerTheme: Theme) => Theme);
|
|
11
|
+
export type ThemeProviderProps = ThemeUiProviderProps & {
|
|
12
|
+
children?: React.ReactNode;
|
|
9
13
|
};
|
|
10
14
|
|
|
11
|
-
const ThemeProvider
|
|
12
|
-
|
|
15
|
+
const ThemeProvider = ({ children, theme = {} }: ThemeProviderProps) => {
|
|
16
|
+
const mergedTheme = React.useMemo(() => {
|
|
17
|
+
if (typeof theme === 'function') {
|
|
18
|
+
return theme;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
return merge(defaultTheme, theme);
|
|
22
|
+
}, [theme]);
|
|
23
|
+
|
|
24
|
+
return (
|
|
25
|
+
<>
|
|
26
|
+
<ThemeUiProvider theme={mergedTheme}>
|
|
27
|
+
<Global
|
|
28
|
+
styles={{
|
|
29
|
+
'*': {
|
|
30
|
+
margin: 0,
|
|
31
|
+
},
|
|
32
|
+
}}
|
|
33
|
+
/>
|
|
34
|
+
{children}
|
|
35
|
+
</ThemeUiProvider>
|
|
36
|
+
</>
|
|
37
|
+
);
|
|
13
38
|
};
|
|
14
39
|
|
|
15
40
|
export default ThemeProvider;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { Theme } from '@theme-ui/core';
|
|
2
|
+
|
|
3
|
+
export const defaultTheme: Theme = {
|
|
4
|
+
colors: {
|
|
5
|
+
text: '#000',
|
|
6
|
+
background: '#fff',
|
|
7
|
+
primary: '#07c',
|
|
8
|
+
secondary: '#639',
|
|
9
|
+
gray: '#555',
|
|
10
|
+
},
|
|
11
|
+
space: [0, 4, 8, 16, 32, 64, 128, 256, 512],
|
|
12
|
+
styles: {
|
|
13
|
+
a: {
|
|
14
|
+
color: 'primary',
|
|
15
|
+
textDecoration: 'underline',
|
|
16
|
+
cursor: 'pointer',
|
|
17
|
+
},
|
|
18
|
+
},
|
|
19
|
+
buttons: {
|
|
20
|
+
primary: {
|
|
21
|
+
color: 'white',
|
|
22
|
+
backgroundColor: 'primary',
|
|
23
|
+
},
|
|
24
|
+
secondary: {
|
|
25
|
+
color: 'white',
|
|
26
|
+
backgroundColor: 'secondary',
|
|
27
|
+
},
|
|
28
|
+
},
|
|
29
|
+
cards: {
|
|
30
|
+
primary: {
|
|
31
|
+
backgroundColor: 'background',
|
|
32
|
+
border: '1px solid black',
|
|
33
|
+
padding: [4, 5],
|
|
34
|
+
},
|
|
35
|
+
},
|
|
36
|
+
text: {
|
|
37
|
+
title: {
|
|
38
|
+
fontSize: [4, 5],
|
|
39
|
+
textAlign: 'center',
|
|
40
|
+
},
|
|
41
|
+
},
|
|
42
|
+
};
|
package/src/theme/theme.ts
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { Theme } from '@theme-ui/core';
|
|
2
|
-
|
|
3
|
-
export const theme: Theme = {
|
|
4
|
-
colors: {
|
|
5
|
-
text: '#000',
|
|
6
|
-
background: '#fff',
|
|
7
|
-
primary: '#07c',
|
|
8
|
-
secondary: '#639',
|
|
9
|
-
gray: '#555',
|
|
10
|
-
},
|
|
11
|
-
buttons: {
|
|
12
|
-
primary: {
|
|
13
|
-
color: 'background',
|
|
14
|
-
bg: 'primary',
|
|
15
|
-
},
|
|
16
|
-
secondary: {
|
|
17
|
-
color: 'background',
|
|
18
|
-
bg: 'secondary',
|
|
19
|
-
},
|
|
20
|
-
gray: {
|
|
21
|
-
color: 'background',
|
|
22
|
-
bg: 'gray',
|
|
23
|
-
},
|
|
24
|
-
},
|
|
25
|
-
};
|