@ttoss/ui 0.9.0 → 0.9.1
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 +29 -11
- package/dist/index.d.ts +9 -8
- package/dist/index.js +27 -11
- package/package.json +6 -6
- package/src/index.ts +2 -2
- package/src/theme/ThemeProvider.spec.tsx +68 -0
- package/src/theme/ThemeProvider.tsx +20 -8
- package/src/theme/{theme.ts → defaultTheme.ts} +1 -1
- package/src/theme/useTheme.ts +3 -0
package/dist/esm/index.js
CHANGED
|
@@ -2,10 +2,14 @@
|
|
|
2
2
|
import * as React from "react";
|
|
3
3
|
|
|
4
4
|
// src/theme/ThemeProvider.tsx
|
|
5
|
-
import {
|
|
5
|
+
import {
|
|
6
|
+
ThemeProvider as ThemeUiProvider,
|
|
7
|
+
merge
|
|
8
|
+
} from "@theme-ui/core";
|
|
9
|
+
import * as React2 from "react";
|
|
6
10
|
|
|
7
|
-
// src/theme/
|
|
8
|
-
var
|
|
11
|
+
// src/theme/defaultTheme.ts
|
|
12
|
+
var defaultTheme = {
|
|
9
13
|
colors: {
|
|
10
14
|
text: "#000",
|
|
11
15
|
background: "#fff",
|
|
@@ -30,13 +34,26 @@ var theme = {
|
|
|
30
34
|
};
|
|
31
35
|
|
|
32
36
|
// src/theme/ThemeProvider.tsx
|
|
33
|
-
var ThemeProvider = ({
|
|
34
|
-
|
|
35
|
-
|
|
37
|
+
var ThemeProvider = ({
|
|
38
|
+
children,
|
|
39
|
+
theme = {}
|
|
40
|
+
}) => {
|
|
41
|
+
const mergedTheme = React2.useMemo(() => {
|
|
42
|
+
if (typeof theme === "function") {
|
|
43
|
+
return theme;
|
|
44
|
+
}
|
|
45
|
+
return merge(defaultTheme, theme);
|
|
46
|
+
}, [theme]);
|
|
47
|
+
return /* @__PURE__ */ React2.createElement(ThemeUiProvider, {
|
|
48
|
+
theme: mergedTheme
|
|
36
49
|
}, children);
|
|
37
50
|
};
|
|
38
51
|
var ThemeProvider_default = ThemeProvider;
|
|
39
52
|
|
|
53
|
+
// src/theme/useTheme.ts
|
|
54
|
+
import { useThemeUI } from "@theme-ui/core";
|
|
55
|
+
var useTheme = useThemeUI;
|
|
56
|
+
|
|
40
57
|
// src/components/Box/Box.tsx
|
|
41
58
|
import { Box } from "@theme-ui/components";
|
|
42
59
|
|
|
@@ -47,7 +64,7 @@ import { Button } from "@theme-ui/components";
|
|
|
47
64
|
import { Flex } from "@theme-ui/components";
|
|
48
65
|
|
|
49
66
|
// src/components/FormField/FormField.tsx
|
|
50
|
-
import * as
|
|
67
|
+
import * as React3 from "react";
|
|
51
68
|
|
|
52
69
|
// src/components/Label/Label.tsx
|
|
53
70
|
import { Label } from "@theme-ui/components";
|
|
@@ -66,11 +83,11 @@ var FormField = ({ children, label, error }) => {
|
|
|
66
83
|
}
|
|
67
84
|
return [];
|
|
68
85
|
})();
|
|
69
|
-
return /* @__PURE__ */
|
|
86
|
+
return /* @__PURE__ */ React3.createElement(Box, null, /* @__PURE__ */ React3.createElement(Label, {
|
|
70
87
|
sx: { display: "flex", flexDirection: "column" }
|
|
71
|
-
}, label && /* @__PURE__ */
|
|
88
|
+
}, label && /* @__PURE__ */ React3.createElement(Text, {
|
|
72
89
|
as: "span"
|
|
73
|
-
}, label), children), errorAsArray.map((err) => /* @__PURE__ */
|
|
90
|
+
}, label), children), errorAsArray.map((err) => /* @__PURE__ */ React3.createElement(Text, {
|
|
74
91
|
key: err,
|
|
75
92
|
as: "span",
|
|
76
93
|
variant: "error"
|
|
@@ -91,5 +108,6 @@ export {
|
|
|
91
108
|
Image,
|
|
92
109
|
Input,
|
|
93
110
|
Text,
|
|
94
|
-
ThemeProvider_default as ThemeProvider
|
|
111
|
+
ThemeProvider_default as ThemeProvider,
|
|
112
|
+
useTheme
|
|
95
113
|
};
|
package/dist/index.d.ts
CHANGED
|
@@ -1,17 +1,18 @@
|
|
|
1
|
-
import
|
|
1
|
+
import * as _theme_ui_core from '@theme-ui/core';
|
|
2
|
+
import { ThemeProviderProps } from '@theme-ui/core';
|
|
3
|
+
export { ThemeProviderProps } from '@theme-ui/core';
|
|
4
|
+
import * as React from 'react';
|
|
2
5
|
export { Box, BoxProps, Button, ButtonProps, Flex, FlexProps, Image, ImageProps, Input, InputProps, Text, TextProps } from '@theme-ui/components';
|
|
3
|
-
import * as React$1 from 'react';
|
|
4
6
|
|
|
5
|
-
declare
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
declare const ThemeProvider: React.FC<ThemeProviderProps>;
|
|
7
|
+
declare const ThemeProvider: React.FC<Partial<ThemeProviderProps>>;
|
|
8
|
+
|
|
9
|
+
declare const useTheme: () => _theme_ui_core.ThemeUIContextValue;
|
|
9
10
|
|
|
10
11
|
declare type FormFieldProps = {
|
|
11
|
-
children?: React
|
|
12
|
+
children?: React.ReactNode;
|
|
12
13
|
label?: string;
|
|
13
14
|
error?: string[] | string;
|
|
14
15
|
};
|
|
15
16
|
declare const FormField: ({ children, label, error }: FormFieldProps) => JSX.Element;
|
|
16
17
|
|
|
17
|
-
export { FormField, FormFieldProps, ThemeProvider,
|
|
18
|
+
export { FormField, FormFieldProps, ThemeProvider, useTheme };
|
package/dist/index.js
CHANGED
|
@@ -36,7 +36,8 @@ __export(src_exports, {
|
|
|
36
36
|
Image: () => import_components6.Image,
|
|
37
37
|
Input: () => import_components7.Input,
|
|
38
38
|
Text: () => import_components5.Text,
|
|
39
|
-
ThemeProvider: () => ThemeProvider_default
|
|
39
|
+
ThemeProvider: () => ThemeProvider_default,
|
|
40
|
+
useTheme: () => useTheme
|
|
40
41
|
});
|
|
41
42
|
|
|
42
43
|
// tsup.inject.js
|
|
@@ -44,9 +45,10 @@ var React = __toESM(require("react"));
|
|
|
44
45
|
|
|
45
46
|
// src/theme/ThemeProvider.tsx
|
|
46
47
|
var import_core = require("@theme-ui/core");
|
|
48
|
+
var React2 = __toESM(require("react"));
|
|
47
49
|
|
|
48
|
-
// src/theme/
|
|
49
|
-
var
|
|
50
|
+
// src/theme/defaultTheme.ts
|
|
51
|
+
var defaultTheme = {
|
|
50
52
|
colors: {
|
|
51
53
|
text: "#000",
|
|
52
54
|
background: "#fff",
|
|
@@ -71,13 +73,26 @@ var theme = {
|
|
|
71
73
|
};
|
|
72
74
|
|
|
73
75
|
// src/theme/ThemeProvider.tsx
|
|
74
|
-
var ThemeProvider = ({
|
|
75
|
-
|
|
76
|
-
|
|
76
|
+
var ThemeProvider = ({
|
|
77
|
+
children,
|
|
78
|
+
theme = {}
|
|
79
|
+
}) => {
|
|
80
|
+
const mergedTheme = React2.useMemo(() => {
|
|
81
|
+
if (typeof theme === "function") {
|
|
82
|
+
return theme;
|
|
83
|
+
}
|
|
84
|
+
return (0, import_core.merge)(defaultTheme, theme);
|
|
85
|
+
}, [theme]);
|
|
86
|
+
return /* @__PURE__ */ React2.createElement(import_core.ThemeProvider, {
|
|
87
|
+
theme: mergedTheme
|
|
77
88
|
}, children);
|
|
78
89
|
};
|
|
79
90
|
var ThemeProvider_default = ThemeProvider;
|
|
80
91
|
|
|
92
|
+
// src/theme/useTheme.ts
|
|
93
|
+
var import_core2 = require("@theme-ui/core");
|
|
94
|
+
var useTheme = import_core2.useThemeUI;
|
|
95
|
+
|
|
81
96
|
// src/components/Box/Box.tsx
|
|
82
97
|
var import_components = require("@theme-ui/components");
|
|
83
98
|
|
|
@@ -88,7 +103,7 @@ var import_components2 = require("@theme-ui/components");
|
|
|
88
103
|
var import_components3 = require("@theme-ui/components");
|
|
89
104
|
|
|
90
105
|
// src/components/FormField/FormField.tsx
|
|
91
|
-
var
|
|
106
|
+
var React3 = __toESM(require("react"));
|
|
92
107
|
|
|
93
108
|
// src/components/Label/Label.tsx
|
|
94
109
|
var import_components4 = require("@theme-ui/components");
|
|
@@ -107,11 +122,11 @@ var FormField = ({ children, label, error }) => {
|
|
|
107
122
|
}
|
|
108
123
|
return [];
|
|
109
124
|
})();
|
|
110
|
-
return /* @__PURE__ */
|
|
125
|
+
return /* @__PURE__ */ React3.createElement(import_components.Box, null, /* @__PURE__ */ React3.createElement(import_components4.Label, {
|
|
111
126
|
sx: { display: "flex", flexDirection: "column" }
|
|
112
|
-
}, label && /* @__PURE__ */
|
|
127
|
+
}, label && /* @__PURE__ */ React3.createElement(import_components5.Text, {
|
|
113
128
|
as: "span"
|
|
114
|
-
}, label), children), errorAsArray.map((err) => /* @__PURE__ */
|
|
129
|
+
}, label), children), errorAsArray.map((err) => /* @__PURE__ */ React3.createElement(import_components5.Text, {
|
|
115
130
|
key: err,
|
|
116
131
|
as: "span",
|
|
117
132
|
variant: "error"
|
|
@@ -134,5 +149,6 @@ module.exports = __toCommonJS(src_exports);
|
|
|
134
149
|
Image,
|
|
135
150
|
Input,
|
|
136
151
|
Text,
|
|
137
|
-
ThemeProvider
|
|
152
|
+
ThemeProvider,
|
|
153
|
+
useTheme
|
|
138
154
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ttoss/ui",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.1",
|
|
4
4
|
"description": "Primitive layout, typographic, and other components for styling applications.",
|
|
5
5
|
"license": "UNLICENSED",
|
|
6
6
|
"publishConfig": {
|
|
@@ -32,15 +32,15 @@
|
|
|
32
32
|
"dev": "yarn workspace @ttoss/storybook run dev"
|
|
33
33
|
},
|
|
34
34
|
"dependencies": {
|
|
35
|
-
"@theme-ui/components": "^0.
|
|
36
|
-
"@theme-ui/core": "^0.
|
|
35
|
+
"@theme-ui/components": "^0.13.1",
|
|
36
|
+
"@theme-ui/core": "^0.13.1"
|
|
37
37
|
},
|
|
38
38
|
"peerDependencies": {
|
|
39
39
|
"react": ">=16.8.0"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
|
-
"@ttoss/config": "^0.9.
|
|
43
|
-
"@ttoss/test-utils": "^0.9.
|
|
42
|
+
"@ttoss/config": "^0.9.1",
|
|
43
|
+
"@ttoss/test-utils": "^0.9.1"
|
|
44
44
|
},
|
|
45
|
-
"gitHead": "
|
|
45
|
+
"gitHead": "22b5b5069d316cf219a95635bb05c21b8e3367a4"
|
|
46
46
|
}
|
package/src/index.ts
CHANGED
|
@@ -3,9 +3,9 @@ export {
|
|
|
3
3
|
ThemeProviderProps,
|
|
4
4
|
} from './theme/ThemeProvider';
|
|
5
5
|
|
|
6
|
-
export {
|
|
7
|
-
export type { BoxProps } from './components/Box/Box';
|
|
6
|
+
export { useTheme } from './theme/useTheme';
|
|
8
7
|
|
|
8
|
+
export { default as Box, BoxProps } from './components/Box/Box';
|
|
9
9
|
export { default as Button, ButtonProps } from './components/Button/Button';
|
|
10
10
|
export { default as Flex, FlexProps } from './components/Flex/Flex';
|
|
11
11
|
export {
|
|
@@ -0,0 +1,68 @@
|
|
|
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).toEqual(expect.objectContaining(variants));
|
|
68
|
+
});
|
|
@@ -1,15 +1,27 @@
|
|
|
1
|
-
|
|
1
|
+
import {
|
|
2
|
+
ThemeProvider as ThemeUiProvider,
|
|
3
|
+
ThemeProviderProps,
|
|
4
|
+
merge,
|
|
5
|
+
} from '@theme-ui/core';
|
|
6
|
+
import * as React from 'react';
|
|
2
7
|
|
|
3
|
-
import {
|
|
8
|
+
import { defaultTheme } from './defaultTheme';
|
|
4
9
|
|
|
5
|
-
|
|
10
|
+
export type { ThemeProviderProps };
|
|
6
11
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
}
|
|
12
|
+
const ThemeProvider: React.FC<Partial<ThemeProviderProps>> = ({
|
|
13
|
+
children,
|
|
14
|
+
theme = {},
|
|
15
|
+
}) => {
|
|
16
|
+
const mergedTheme = React.useMemo(() => {
|
|
17
|
+
if (typeof theme === 'function') {
|
|
18
|
+
return theme;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
return merge(defaultTheme, theme);
|
|
22
|
+
}, [theme]);
|
|
10
23
|
|
|
11
|
-
|
|
12
|
-
return <ThemeUiProvider theme={theme}>{children}</ThemeUiProvider>;
|
|
24
|
+
return <ThemeUiProvider theme={mergedTheme}>{children}</ThemeUiProvider>;
|
|
13
25
|
};
|
|
14
26
|
|
|
15
27
|
export default ThemeProvider;
|