@ttoss/ui 0.8.4 → 0.9.2
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/package.json +8 -6
- package/src/components/Card/Card.tsx +3 -0
- package/src/index.ts +3 -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 +0 -97
- package/dist/index.d.ts +0 -17
- package/dist/index.js +0 -97
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ttoss/ui",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.9.2",
|
|
4
4
|
"description": "Primitive layout, typographic, and other components for styling applications.",
|
|
5
5
|
"license": "UNLICENSED",
|
|
6
6
|
"publishConfig": {
|
|
@@ -32,15 +32,17 @@
|
|
|
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/components": "^0.13.1",
|
|
38
|
+
"@theme-ui/core": "^0.13.1"
|
|
37
39
|
},
|
|
38
40
|
"peerDependencies": {
|
|
39
41
|
"react": ">=16.8.0"
|
|
40
42
|
},
|
|
41
43
|
"devDependencies": {
|
|
42
|
-
"@ttoss/config": "^0.
|
|
43
|
-
"@ttoss/test-utils": "^0.
|
|
44
|
+
"@ttoss/config": "^0.9.2",
|
|
45
|
+
"@ttoss/test-utils": "^0.9.2"
|
|
44
46
|
},
|
|
45
|
-
"gitHead": "
|
|
47
|
+
"gitHead": "6a904124b42ad72f3ba318ec42b861f803acb218"
|
|
46
48
|
}
|
package/src/index.ts
CHANGED
|
@@ -3,10 +3,11 @@ 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
|
+
export { default as Card, CardProps } from './components/Card/Card';
|
|
10
11
|
export { default as Flex, FlexProps } from './components/Flex/Flex';
|
|
11
12
|
export {
|
|
12
13
|
default as FormField,
|
|
@@ -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;
|
package/dist/esm/index.js
DELETED
|
@@ -1,97 +0,0 @@
|
|
|
1
|
-
// tsup.inject.js
|
|
2
|
-
import * as React from "react";
|
|
3
|
-
|
|
4
|
-
// src/theme/ThemeProvider.tsx
|
|
5
|
-
import { ThemeProvider as ThemeUiProvider } from "@theme-ui/core";
|
|
6
|
-
|
|
7
|
-
// src/theme/theme.ts
|
|
8
|
-
var theme = {
|
|
9
|
-
colors: {
|
|
10
|
-
text: "#000",
|
|
11
|
-
background: "#fff",
|
|
12
|
-
primary: "#07c",
|
|
13
|
-
secondary: "#639",
|
|
14
|
-
gray: "#555"
|
|
15
|
-
},
|
|
16
|
-
buttons: {
|
|
17
|
-
primary: {
|
|
18
|
-
color: "background",
|
|
19
|
-
bg: "primary"
|
|
20
|
-
},
|
|
21
|
-
secondary: {
|
|
22
|
-
color: "background",
|
|
23
|
-
bg: "secondary"
|
|
24
|
-
},
|
|
25
|
-
gray: {
|
|
26
|
-
color: "background",
|
|
27
|
-
bg: "gray"
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
// src/theme/ThemeProvider.tsx
|
|
33
|
-
var ThemeProvider = ({ children }) => {
|
|
34
|
-
return /* @__PURE__ */ React.createElement(ThemeUiProvider, {
|
|
35
|
-
theme
|
|
36
|
-
}, children);
|
|
37
|
-
};
|
|
38
|
-
var ThemeProvider_default = ThemeProvider;
|
|
39
|
-
|
|
40
|
-
// src/components/Box/Box.tsx
|
|
41
|
-
import { Box } from "@theme-ui/components";
|
|
42
|
-
|
|
43
|
-
// src/components/Button/Button.tsx
|
|
44
|
-
import { Button } from "@theme-ui/components";
|
|
45
|
-
|
|
46
|
-
// src/components/Flex/Flex.tsx
|
|
47
|
-
import { Flex } from "@theme-ui/components";
|
|
48
|
-
|
|
49
|
-
// src/components/FormField/FormField.tsx
|
|
50
|
-
import {
|
|
51
|
-
createElement
|
|
52
|
-
} from "react";
|
|
53
|
-
|
|
54
|
-
// src/components/Label/Label.tsx
|
|
55
|
-
import { Label } from "@theme-ui/components";
|
|
56
|
-
|
|
57
|
-
// src/components/Text/Text.tsx
|
|
58
|
-
import { Text } from "@theme-ui/components";
|
|
59
|
-
|
|
60
|
-
// src/components/FormField/FormField.tsx
|
|
61
|
-
var FormField = ({ children, label, error }) => {
|
|
62
|
-
const errorAsArray = (() => {
|
|
63
|
-
if (Array.isArray(error)) {
|
|
64
|
-
return error;
|
|
65
|
-
}
|
|
66
|
-
if (typeof error === "string") {
|
|
67
|
-
return [error];
|
|
68
|
-
}
|
|
69
|
-
return [];
|
|
70
|
-
})();
|
|
71
|
-
return /* @__PURE__ */ createElement(Box, null, /* @__PURE__ */ createElement(Label, {
|
|
72
|
-
sx: { display: "flex", flexDirection: "column" }
|
|
73
|
-
}, label && /* @__PURE__ */ createElement(Text, {
|
|
74
|
-
as: "span"
|
|
75
|
-
}, label), children), errorAsArray.map((err) => /* @__PURE__ */ createElement(Text, {
|
|
76
|
-
key: err,
|
|
77
|
-
as: "span",
|
|
78
|
-
variant: "error"
|
|
79
|
-
}, err)));
|
|
80
|
-
};
|
|
81
|
-
var FormField_default = FormField;
|
|
82
|
-
|
|
83
|
-
// src/components/Image/Image.tsx
|
|
84
|
-
import { Image } from "@theme-ui/components";
|
|
85
|
-
|
|
86
|
-
// src/components/Input/Input.tsx
|
|
87
|
-
import { Input } from "@theme-ui/components";
|
|
88
|
-
export {
|
|
89
|
-
Box,
|
|
90
|
-
Button,
|
|
91
|
-
Flex,
|
|
92
|
-
FormField_default as FormField,
|
|
93
|
-
Image,
|
|
94
|
-
Input,
|
|
95
|
-
Text,
|
|
96
|
-
ThemeProvider_default as ThemeProvider
|
|
97
|
-
};
|
package/dist/index.d.ts
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { Theme } from '@theme-ui/core';
|
|
2
|
-
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
|
-
|
|
5
|
-
declare type ThemeProviderProps = {
|
|
6
|
-
theme?: Theme | ((outerTheme: Theme) => Theme);
|
|
7
|
-
};
|
|
8
|
-
declare const ThemeProvider: React.FC<ThemeProviderProps>;
|
|
9
|
-
|
|
10
|
-
declare type FormFieldProps = {
|
|
11
|
-
children?: React$1.ReactNode;
|
|
12
|
-
label?: string;
|
|
13
|
-
error?: string[] | string;
|
|
14
|
-
};
|
|
15
|
-
declare const FormField: ({ children, label, error }: FormFieldProps) => JSX.Element;
|
|
16
|
-
|
|
17
|
-
export { FormField, FormFieldProps, ThemeProvider, ThemeProviderProps };
|
package/dist/index.js
DELETED
|
@@ -1,97 +0,0 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } }// tsup.inject.js
|
|
2
|
-
var _react = require('react'); var React = _interopRequireWildcard(_react);
|
|
3
|
-
|
|
4
|
-
// src/theme/ThemeProvider.tsx
|
|
5
|
-
var _core = require('@theme-ui/core');
|
|
6
|
-
|
|
7
|
-
// src/theme/theme.ts
|
|
8
|
-
var theme = {
|
|
9
|
-
colors: {
|
|
10
|
-
text: "#000",
|
|
11
|
-
background: "#fff",
|
|
12
|
-
primary: "#07c",
|
|
13
|
-
secondary: "#639",
|
|
14
|
-
gray: "#555"
|
|
15
|
-
},
|
|
16
|
-
buttons: {
|
|
17
|
-
primary: {
|
|
18
|
-
color: "background",
|
|
19
|
-
bg: "primary"
|
|
20
|
-
},
|
|
21
|
-
secondary: {
|
|
22
|
-
color: "background",
|
|
23
|
-
bg: "secondary"
|
|
24
|
-
},
|
|
25
|
-
gray: {
|
|
26
|
-
color: "background",
|
|
27
|
-
bg: "gray"
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
// src/theme/ThemeProvider.tsx
|
|
33
|
-
var ThemeProvider = ({ children }) => {
|
|
34
|
-
return /* @__PURE__ */ React.createElement(_core.ThemeProvider, {
|
|
35
|
-
theme
|
|
36
|
-
}, children);
|
|
37
|
-
};
|
|
38
|
-
var ThemeProvider_default = ThemeProvider;
|
|
39
|
-
|
|
40
|
-
// src/components/Box/Box.tsx
|
|
41
|
-
var _components = require('@theme-ui/components');
|
|
42
|
-
|
|
43
|
-
// src/components/Button/Button.tsx
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
// src/components/Flex/Flex.tsx
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
// src/components/FormField/FormField.tsx
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
// src/components/Label/Label.tsx
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
// src/components/Text/Text.tsx
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
// src/components/FormField/FormField.tsx
|
|
61
|
-
var FormField = ({ children, label, error }) => {
|
|
62
|
-
const errorAsArray = (() => {
|
|
63
|
-
if (Array.isArray(error)) {
|
|
64
|
-
return error;
|
|
65
|
-
}
|
|
66
|
-
if (typeof error === "string") {
|
|
67
|
-
return [error];
|
|
68
|
-
}
|
|
69
|
-
return [];
|
|
70
|
-
})();
|
|
71
|
-
return /* @__PURE__ */ _react.createElement.call(void 0, _components.Box, null, /* @__PURE__ */ _react.createElement.call(void 0, _components.Label, {
|
|
72
|
-
sx: { display: "flex", flexDirection: "column" }
|
|
73
|
-
}, label && /* @__PURE__ */ _react.createElement.call(void 0, _components.Text, {
|
|
74
|
-
as: "span"
|
|
75
|
-
}, label), children), errorAsArray.map((err) => /* @__PURE__ */ _react.createElement.call(void 0, _components.Text, {
|
|
76
|
-
key: err,
|
|
77
|
-
as: "span",
|
|
78
|
-
variant: "error"
|
|
79
|
-
}, err)));
|
|
80
|
-
};
|
|
81
|
-
var FormField_default = FormField;
|
|
82
|
-
|
|
83
|
-
// src/components/Image/Image.tsx
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
// src/components/Input/Input.tsx
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
exports.Box = _components.Box; exports.Button = _components.Button; exports.Flex = _components.Flex; exports.FormField = FormField_default; exports.Image = _components.Image; exports.Input = _components.Input; exports.Text = _components.Text; exports.ThemeProvider = ThemeProvider_default;
|