@ttoss/ui 0.8.3 → 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/README.md ADDED
@@ -0,0 +1,42 @@
1
+ # @ttoss/ui
2
+
3
+ ## 📚 About
4
+
5
+ <strong> @ttoss/ui</strong> is a easiest way to use Ui components in your React application.
6
+
7
+ ## 🚀 Get Started
8
+
9
+ ### Install @ttoss/ui
10
+
11
+ ```shell
12
+ $ yarn add @ttoss/ui
13
+ # or
14
+ $ npm install @ttoss/ui
15
+ ```
16
+
17
+ ## 📄 Examples of use
18
+
19
+ ```tsx
20
+ import { Flex, Text, Box, Button } from '@ttoss/ui';
21
+
22
+ const App = () => {
23
+ return (
24
+ <ThemeProvider>
25
+ <Flex sx={{ flexDirection: 'column' }}>
26
+ <Text>Text Value</Text>
27
+ <Box>
28
+ <Text>Text Value</Text>
29
+
30
+ <Button>Button Primary</Button>
31
+ </Box>
32
+ </Flex>
33
+ </ThemeProvider>
34
+ );
35
+ };
36
+
37
+ export default App;
38
+ ```
39
+
40
+ ```tsx
41
+
42
+ ```
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 { ThemeProvider as ThemeUiProvider } from "@theme-ui/core";
5
+ import {
6
+ ThemeProvider as ThemeUiProvider,
7
+ merge
8
+ } from "@theme-ui/core";
9
+ import * as React2 from "react";
6
10
 
7
- // src/theme/theme.ts
8
- var theme = {
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 = ({ children }) => {
34
- return /* @__PURE__ */ React.createElement(ThemeUiProvider, {
35
- theme
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,9 +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 {
51
- createElement
52
- } from "react";
67
+ import * as React3 from "react";
53
68
 
54
69
  // src/components/Label/Label.tsx
55
70
  import { Label } from "@theme-ui/components";
@@ -68,11 +83,11 @@ var FormField = ({ children, label, error }) => {
68
83
  }
69
84
  return [];
70
85
  })();
71
- return /* @__PURE__ */ createElement(Box, null, /* @__PURE__ */ createElement(Label, {
86
+ return /* @__PURE__ */ React3.createElement(Box, null, /* @__PURE__ */ React3.createElement(Label, {
72
87
  sx: { display: "flex", flexDirection: "column" }
73
- }, label && /* @__PURE__ */ createElement(Text, {
88
+ }, label && /* @__PURE__ */ React3.createElement(Text, {
74
89
  as: "span"
75
- }, label), children), errorAsArray.map((err) => /* @__PURE__ */ createElement(Text, {
90
+ }, label), children), errorAsArray.map((err) => /* @__PURE__ */ React3.createElement(Text, {
76
91
  key: err,
77
92
  as: "span",
78
93
  variant: "error"
@@ -93,5 +108,6 @@ export {
93
108
  Image,
94
109
  Input,
95
110
  Text,
96
- ThemeProvider_default as ThemeProvider
111
+ ThemeProvider_default as ThemeProvider,
112
+ useTheme
97
113
  };
package/dist/index.d.ts CHANGED
@@ -1,17 +1,18 @@
1
- import { Theme } from '@theme-ui/core';
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 type ThemeProviderProps = {
6
- theme?: Theme | ((outerTheme: Theme) => Theme);
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$1.ReactNode;
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, ThemeProviderProps };
18
+ export { FormField, FormFieldProps, ThemeProvider, useTheme };
package/dist/index.js CHANGED
@@ -1,11 +1,54 @@
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);
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __markAsModule = (target) => __defProp(target, "__esModule", { value: true });
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __reExport = (target, module2, copyDefault, desc) => {
13
+ if (module2 && typeof module2 === "object" || typeof module2 === "function") {
14
+ for (let key of __getOwnPropNames(module2))
15
+ if (!__hasOwnProp.call(target, key) && (copyDefault || key !== "default"))
16
+ __defProp(target, key, { get: () => module2[key], enumerable: !(desc = __getOwnPropDesc(module2, key)) || desc.enumerable });
17
+ }
18
+ return target;
19
+ };
20
+ var __toESM = (module2, isNodeMode) => {
21
+ return __reExport(__markAsModule(__defProp(module2 != null ? __create(__getProtoOf(module2)) : {}, "default", !isNodeMode && module2 && module2.__esModule ? { get: () => module2.default, enumerable: true } : { value: module2, enumerable: true })), module2);
22
+ };
23
+ var __toCommonJS = /* @__PURE__ */ ((cache) => {
24
+ return (module2, temp) => {
25
+ return cache && cache.get(module2) || (temp = __reExport(__markAsModule({}), module2, 1), cache && cache.set(module2, temp), temp);
26
+ };
27
+ })(typeof WeakMap !== "undefined" ? /* @__PURE__ */ new WeakMap() : 0);
28
+
29
+ // src/index.ts
30
+ var src_exports = {};
31
+ __export(src_exports, {
32
+ Box: () => import_components.Box,
33
+ Button: () => import_components2.Button,
34
+ Flex: () => import_components3.Flex,
35
+ FormField: () => FormField_default,
36
+ Image: () => import_components6.Image,
37
+ Input: () => import_components7.Input,
38
+ Text: () => import_components5.Text,
39
+ ThemeProvider: () => ThemeProvider_default,
40
+ useTheme: () => useTheme
41
+ });
42
+
43
+ // tsup.inject.js
44
+ var React = __toESM(require("react"));
3
45
 
4
46
  // src/theme/ThemeProvider.tsx
5
- var _core = require('@theme-ui/core');
47
+ var import_core = require("@theme-ui/core");
48
+ var React2 = __toESM(require("react"));
6
49
 
7
- // src/theme/theme.ts
8
- var theme = {
50
+ // src/theme/defaultTheme.ts
51
+ var defaultTheme = {
9
52
  colors: {
10
53
  text: "#000",
11
54
  background: "#fff",
@@ -30,32 +73,43 @@ var theme = {
30
73
  };
31
74
 
32
75
  // src/theme/ThemeProvider.tsx
33
- var ThemeProvider = ({ children }) => {
34
- return /* @__PURE__ */ React.createElement(_core.ThemeProvider, {
35
- theme
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
36
88
  }, children);
37
89
  };
38
90
  var ThemeProvider_default = ThemeProvider;
39
91
 
92
+ // src/theme/useTheme.ts
93
+ var import_core2 = require("@theme-ui/core");
94
+ var useTheme = import_core2.useThemeUI;
95
+
40
96
  // src/components/Box/Box.tsx
41
- var _components = require('@theme-ui/components');
97
+ var import_components = require("@theme-ui/components");
42
98
 
43
99
  // src/components/Button/Button.tsx
44
-
100
+ var import_components2 = require("@theme-ui/components");
45
101
 
46
102
  // src/components/Flex/Flex.tsx
47
-
103
+ var import_components3 = require("@theme-ui/components");
48
104
 
49
105
  // src/components/FormField/FormField.tsx
50
-
51
-
52
-
106
+ var React3 = __toESM(require("react"));
53
107
 
54
108
  // src/components/Label/Label.tsx
55
-
109
+ var import_components4 = require("@theme-ui/components");
56
110
 
57
111
  // src/components/Text/Text.tsx
58
-
112
+ var import_components5 = require("@theme-ui/components");
59
113
 
60
114
  // src/components/FormField/FormField.tsx
61
115
  var FormField = ({ children, label, error }) => {
@@ -68,11 +122,11 @@ var FormField = ({ children, label, error }) => {
68
122
  }
69
123
  return [];
70
124
  })();
71
- return /* @__PURE__ */ _react.createElement.call(void 0, _components.Box, null, /* @__PURE__ */ _react.createElement.call(void 0, _components.Label, {
125
+ return /* @__PURE__ */ React3.createElement(import_components.Box, null, /* @__PURE__ */ React3.createElement(import_components4.Label, {
72
126
  sx: { display: "flex", flexDirection: "column" }
73
- }, label && /* @__PURE__ */ _react.createElement.call(void 0, _components.Text, {
127
+ }, label && /* @__PURE__ */ React3.createElement(import_components5.Text, {
74
128
  as: "span"
75
- }, label), children), errorAsArray.map((err) => /* @__PURE__ */ _react.createElement.call(void 0, _components.Text, {
129
+ }, label), children), errorAsArray.map((err) => /* @__PURE__ */ React3.createElement(import_components5.Text, {
76
130
  key: err,
77
131
  as: "span",
78
132
  variant: "error"
@@ -81,17 +135,20 @@ var FormField = ({ children, label, error }) => {
81
135
  var FormField_default = FormField;
82
136
 
83
137
  // src/components/Image/Image.tsx
84
-
138
+ var import_components6 = require("@theme-ui/components");
85
139
 
86
140
  // 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;
141
+ var import_components7 = require("@theme-ui/components");
142
+ module.exports = __toCommonJS(src_exports);
143
+ // Annotate the CommonJS export names for ESM import in node:
144
+ 0 && (module.exports = {
145
+ Box,
146
+ Button,
147
+ Flex,
148
+ FormField,
149
+ Image,
150
+ Input,
151
+ Text,
152
+ ThemeProvider,
153
+ useTheme
154
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ttoss/ui",
3
- "version": "0.8.3",
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.11.1",
36
- "@theme-ui/core": "^0.11.1"
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.8.3",
43
- "@ttoss/test-utils": "^0.8.3"
42
+ "@ttoss/config": "^0.9.1",
43
+ "@ttoss/test-utils": "^0.9.1"
44
44
  },
45
- "gitHead": "4a0b5b1f51c9241b0b8d4a35b88a84d856d46d44"
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 { default as Box } from './components/Box/Box';
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
- // import * as React from 'react';
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 { ThemeProvider as ThemeUiProvider, Theme } from '@theme-ui/core';
8
+ import { defaultTheme } from './defaultTheme';
4
9
 
5
- import { theme } from './theme';
10
+ export type { ThemeProviderProps };
6
11
 
7
- export type ThemeProviderProps = {
8
- theme?: Theme | ((outerTheme: Theme) => Theme);
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
- const ThemeProvider: React.FC<ThemeProviderProps> = ({ children }) => {
12
- return <ThemeUiProvider theme={theme}>{children}</ThemeUiProvider>;
24
+ return <ThemeUiProvider theme={mergedTheme}>{children}</ThemeUiProvider>;
13
25
  };
14
26
 
15
27
  export default ThemeProvider;
@@ -1,6 +1,6 @@
1
1
  import { Theme } from '@theme-ui/core';
2
2
 
3
- export const theme: Theme = {
3
+ export const defaultTheme: Theme = {
4
4
  colors: {
5
5
  text: '#000',
6
6
  background: '#fff',
@@ -0,0 +1,3 @@
1
+ import { useThemeUI } from '@theme-ui/core';
2
+
3
+ export const useTheme = useThemeUI;