@uni-design-system/uni-react 0.0.16 → 0.0.17

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.
@@ -17,7 +17,7 @@ exports.Text = Text;
17
17
  function Style(theme, textAlign, role, color) {
18
18
  const { fontSize, letterSpacing, lineHeight, fontWeight, fontFamily, fontStyle, textTransform } = theme.typography[role];
19
19
  return {
20
- color: theme.colors[color],
20
+ color: theme.colors[color || 'on-background'],
21
21
  fontSize: fontSize + 'px',
22
22
  letterSpacing,
23
23
  textAlign,
@@ -1,2 +1,9 @@
1
- export * from './theme.hook';
2
- export * from './theme.provider';
1
+ /// <reference types="react" />
2
+ import { Theme } from '@uni-design-system/uni-core';
3
+ export declare const ThemeProvider: import("react").ComponentType<{
4
+ theme?: Theme | undefined;
5
+ }>, withTheme: <Props extends {
6
+ theme: Theme;
7
+ }, C>(WrappedComponent: import("react").ComponentType<Props> & C) => import("react").ComponentType<import("@callstack/react-theme-provider").$Without<Props, "theme"> & {
8
+ theme?: import("@callstack/react-theme-provider").$DeepPartial<Theme> | undefined;
9
+ }> & import("@callstack/react-theme-provider/typings/hoist-non-react-statics").NonReactStatics<import("react").ComponentType<Props> & C, {}>, useTheme: <T = Theme>(overrides?: import("@callstack/react-theme-provider").$DeepPartial<T> | undefined) => T;
@@ -1,18 +1,7 @@
1
1
  "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
2
+ var _a;
16
3
  Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./theme.hook"), exports);
18
- __exportStar(require("./theme.provider"), exports);
4
+ exports.useTheme = exports.withTheme = exports.ThemeProvider = void 0;
5
+ const react_theme_provider_1 = require("@callstack/react-theme-provider");
6
+ const uni_core_1 = require("@uni-design-system/uni-core");
7
+ _a = (0, react_theme_provider_1.createTheming)(uni_core_1.LightTheme), exports.ThemeProvider = _a.ThemeProvider, exports.withTheme = _a.withTheme, exports.useTheme = _a.useTheme;
@@ -1,4 +1,9 @@
1
1
  import React from 'react';
2
- import { ThemeProps } from '@uni-design-system/uni-core';
3
- declare const ThemeContext: React.Context<ThemeProps>;
2
+ import { Theme } from '@uni-design-system/uni-core';
3
+ export interface ThemeContextProps {
4
+ themeId?: string;
5
+ themes?: Record<string, Theme>;
6
+ switchTheme: (themeId: string) => void;
7
+ }
8
+ declare const ThemeContext: React.Context<ThemeContextProps>;
4
9
  export default ThemeContext;
@@ -4,7 +4,12 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const react_1 = __importDefault(require("react"));
7
- const ThemeContext = react_1.default.createContext({});
7
+ const uni_core_1 = require("@uni-design-system/uni-core");
8
+ const ThemeContext = react_1.default.createContext({
9
+ themeId: 'LightTheme',
10
+ themes: { LightTheme: uni_core_1.LightTheme },
11
+ switchTheme: () => { },
12
+ });
8
13
  if (process.env.NODE_ENV !== 'production') {
9
14
  ThemeContext.displayName = 'ThemeContext';
10
15
  }
@@ -1,3 +1,5 @@
1
1
  import { Theme } from '@uni-design-system/uni-core';
2
2
  export declare const useTheme: () => Theme;
3
- export declare const useSwitchTheme: (defaultThemeId?: string) => [string, (themeId?: string) => void];
3
+ export declare const useSwitchTheme: () => {
4
+ switchTheme: (themeId: string) => void;
5
+ };
@@ -30,28 +30,24 @@ exports.useSwitchTheme = exports.useTheme = void 0;
30
30
  const react_1 = __importStar(require("react"));
31
31
  const theme_context_1 = __importDefault(require("./theme.context"));
32
32
  const uni_core_1 = require("@uni-design-system/uni-core");
33
- const findTheme = (props) => {
34
- const { themeId, themes } = props;
35
- return themes && themeId ? themes[themeId] : uni_core_1.BaseTheme;
36
- };
37
33
  const useTheme = () => {
38
- const themeProps = (0, react_1.useContext)(theme_context_1.default);
39
- const theme = findTheme(themeProps);
34
+ const { themeId, themes } = (0, react_1.useContext)(theme_context_1.default);
35
+ let theme = themes && themeId ? themes[themeId] : uni_core_1.BaseTheme;
36
+ (0, react_1.useEffect)(() => { }, [themeId]);
40
37
  if (process.env.NODE_ENV !== 'production') {
41
38
  // eslint-disable-next-line react-hooks/rules-of-hooks
42
39
  react_1.default.useDebugValue(theme);
43
40
  }
41
+ (0, react_1.useEffect)(() => {
42
+ console.log(themeId);
43
+ theme = themes && themeId ? themes[themeId] : uni_core_1.BaseTheme;
44
+ }, [themeId]);
44
45
  // return theme || LightTheme;
45
46
  return theme;
46
47
  };
47
48
  exports.useTheme = useTheme;
48
- const useSwitchTheme = (defaultThemeId) => {
49
- const [themeId, setThemeId] = (0, react_1.useState)(defaultThemeId || uni_core_1.DefaultThemeId);
50
- const switchTheme = (themeId) => {
51
- if (!themeId)
52
- return;
53
- setThemeId(themeId);
54
- };
55
- return [themeId, switchTheme];
49
+ const useSwitchTheme = () => {
50
+ const { switchTheme } = (0, react_1.useContext)(theme_context_1.default);
51
+ return { switchTheme };
56
52
  };
57
53
  exports.useSwitchTheme = useSwitchTheme;
@@ -38,17 +38,16 @@ Object.defineProperty(exports, "__esModule", { value: true });
38
38
  exports.ThemeProvider = void 0;
39
39
  const react_1 = __importStar(require("react"));
40
40
  const theme_context_1 = __importDefault(require("./theme.context"));
41
- const theme_hook_1 = require("./theme.hook");
42
41
  const STORAGE_KEY = 'THEME_ID';
43
42
  const ThemeProvider = ({ children, themeId, themes }) => {
44
- const [_themeId, setThemeId] = (0, theme_hook_1.useSwitchTheme)(themeId);
43
+ const [_themeId, setThemeId] = (0, react_1.useState)(themeId);
45
44
  (0, react_1.useEffect)(() => {
46
45
  (() => __awaiter(void 0, void 0, void 0, function* () {
47
46
  const id = localStorage.getItem(STORAGE_KEY);
48
47
  setThemeId(id || themeId);
49
48
  }))();
50
49
  }, [themeId]);
51
- return (react_1.default.createElement(theme_context_1.default.Provider, { value: { themeId: _themeId, themes } }, _themeId ? children : null));
50
+ return (react_1.default.createElement(theme_context_1.default.Provider, { value: { themeId: _themeId, themes, switchTheme: setThemeId } }, _themeId ? children : null));
52
51
  };
53
52
  exports.ThemeProvider = ThemeProvider;
54
53
  /*export function withTheme(Component: ({children, theme, themes }: (any & ThemeProps)) => JSX.Element) {
@@ -1,2 +1,3 @@
1
1
  export * from './core';
2
2
  export * from './components';
3
+ export * from './utils';
package/dist/cjs/index.js CHANGED
@@ -16,3 +16,4 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./core"), exports);
18
18
  __exportStar(require("./components"), exports);
19
+ __exportStar(require("./utils"), exports);
@@ -0,0 +1 @@
1
+ export * from './storage-manager';
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./storage-manager"), exports);
@@ -0,0 +1,7 @@
1
+ export interface StorageManager<T> {
2
+ type: 'cookie' | 'localStorage';
3
+ get(init?: T): T | undefined;
4
+ set(value: T): void;
5
+ }
6
+ export declare const createLocalStorageManager: <T>(key: string) => StorageManager<T>;
7
+ export declare const createCookieStorageManager: (key: string, cookie?: string) => StorageManager<string>;
@@ -0,0 +1,49 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createCookieStorageManager = exports.createLocalStorageManager = void 0;
4
+ // Usage
5
+ // export const localStorageManager = createLocalStorageManager(STORAGE_KEY);
6
+ const createLocalStorageManager = (key) => ({
7
+ type: 'localStorage',
8
+ get(init) {
9
+ if (!(globalThis === null || globalThis === void 0 ? void 0 : globalThis.document))
10
+ return init;
11
+ let value;
12
+ try {
13
+ value = localStorage.getItem(key) || init;
14
+ }
15
+ catch (e) {
16
+ // no op
17
+ }
18
+ return JSON.parse(value) || init;
19
+ },
20
+ set(value) {
21
+ try {
22
+ localStorage.setItem(key, JSON.stringify(value));
23
+ }
24
+ catch (e) {
25
+ // no op
26
+ }
27
+ },
28
+ });
29
+ exports.createLocalStorageManager = createLocalStorageManager;
30
+ const parseCookie = (cookie, key) => {
31
+ const match = cookie.match(new RegExp(`(^| )${key}=([^;]+)`));
32
+ return match === null || match === void 0 ? void 0 : match[2];
33
+ };
34
+ // Usage
35
+ // export const cookieStorageManager = createCookieStorageManager(STORAGE_KEY);
36
+ const createCookieStorageManager = (key, cookie) => ({
37
+ type: 'cookie',
38
+ get(init) {
39
+ if (cookie)
40
+ return parseCookie(cookie, key);
41
+ if (!(globalThis === null || globalThis === void 0 ? void 0 : globalThis.document))
42
+ return init;
43
+ return parseCookie(document.cookie, key) || init;
44
+ },
45
+ set(value) {
46
+ document.cookie = `${key}=${value}; max-age=31536000; path=/`;
47
+ },
48
+ });
49
+ exports.createCookieStorageManager = createCookieStorageManager;
@@ -10,7 +10,7 @@ export function Text(props) {
10
10
  function Style(theme, textAlign, role, color) {
11
11
  const { fontSize, letterSpacing, lineHeight, fontWeight, fontFamily, fontStyle, textTransform } = theme.typography[role];
12
12
  return {
13
- color: theme.colors[color],
13
+ color: theme.colors[color || 'on-background'],
14
14
  fontSize: fontSize + 'px',
15
15
  letterSpacing,
16
16
  textAlign,
@@ -1,2 +1,9 @@
1
- export * from './theme.hook';
2
- export * from './theme.provider';
1
+ /// <reference types="react" />
2
+ import { Theme } from '@uni-design-system/uni-core';
3
+ export declare const ThemeProvider: import("react").ComponentType<{
4
+ theme?: Theme | undefined;
5
+ }>, withTheme: <Props extends {
6
+ theme: Theme;
7
+ }, C>(WrappedComponent: import("react").ComponentType<Props> & C) => import("react").ComponentType<import("@callstack/react-theme-provider").$Without<Props, "theme"> & {
8
+ theme?: import("@callstack/react-theme-provider").$DeepPartial<Theme> | undefined;
9
+ }> & import("@callstack/react-theme-provider/typings/hoist-non-react-statics").NonReactStatics<import("react").ComponentType<Props> & C, {}>, useTheme: <T = Theme>(overrides?: import("@callstack/react-theme-provider").$DeepPartial<T> | undefined) => T;
@@ -1,2 +1,3 @@
1
- export * from './theme.hook';
2
- export * from './theme.provider';
1
+ import { createTheming } from '@callstack/react-theme-provider';
2
+ import { LightTheme } from '@uni-design-system/uni-core';
3
+ export const { ThemeProvider, withTheme, useTheme } = createTheming(LightTheme);
@@ -1,4 +1,9 @@
1
1
  import React from 'react';
2
- import { ThemeProps } from '@uni-design-system/uni-core';
3
- declare const ThemeContext: React.Context<ThemeProps>;
2
+ import { Theme } from '@uni-design-system/uni-core';
3
+ export interface ThemeContextProps {
4
+ themeId?: string;
5
+ themes?: Record<string, Theme>;
6
+ switchTheme: (themeId: string) => void;
7
+ }
8
+ declare const ThemeContext: React.Context<ThemeContextProps>;
4
9
  export default ThemeContext;
@@ -1,5 +1,10 @@
1
1
  import React from 'react';
2
- const ThemeContext = React.createContext({});
2
+ import { LightTheme } from '@uni-design-system/uni-core';
3
+ const ThemeContext = React.createContext({
4
+ themeId: 'LightTheme',
5
+ themes: { LightTheme },
6
+ switchTheme: () => { },
7
+ });
3
8
  if (process.env.NODE_ENV !== 'production') {
4
9
  ThemeContext.displayName = 'ThemeContext';
5
10
  }
@@ -1,3 +1,5 @@
1
1
  import { Theme } from '@uni-design-system/uni-core';
2
2
  export declare const useTheme: () => Theme;
3
- export declare const useSwitchTheme: (defaultThemeId?: string) => [string, (themeId?: string) => void];
3
+ export declare const useSwitchTheme: () => {
4
+ switchTheme: (themeId: string) => void;
5
+ };
@@ -1,26 +1,22 @@
1
- import React, { useContext, useState } from 'react';
1
+ import React, { useContext, useEffect } from 'react';
2
2
  import ThemeContext from './theme.context';
3
- import { BaseTheme, DefaultThemeId } from '@uni-design-system/uni-core';
4
- const findTheme = (props) => {
5
- const { themeId, themes } = props;
6
- return themes && themeId ? themes[themeId] : BaseTheme;
7
- };
3
+ import { BaseTheme } from '@uni-design-system/uni-core';
8
4
  export const useTheme = () => {
9
- const themeProps = useContext(ThemeContext);
10
- const theme = findTheme(themeProps);
5
+ const { themeId, themes } = useContext(ThemeContext);
6
+ let theme = themes && themeId ? themes[themeId] : BaseTheme;
7
+ useEffect(() => { }, [themeId]);
11
8
  if (process.env.NODE_ENV !== 'production') {
12
9
  // eslint-disable-next-line react-hooks/rules-of-hooks
13
10
  React.useDebugValue(theme);
14
11
  }
12
+ useEffect(() => {
13
+ console.log(themeId);
14
+ theme = themes && themeId ? themes[themeId] : BaseTheme;
15
+ }, [themeId]);
15
16
  // return theme || LightTheme;
16
17
  return theme;
17
18
  };
18
- export const useSwitchTheme = (defaultThemeId) => {
19
- const [themeId, setThemeId] = useState(defaultThemeId || DefaultThemeId);
20
- const switchTheme = (themeId) => {
21
- if (!themeId)
22
- return;
23
- setThemeId(themeId);
24
- };
25
- return [themeId, switchTheme];
19
+ export const useSwitchTheme = () => {
20
+ const { switchTheme } = useContext(ThemeContext);
21
+ return { switchTheme };
26
22
  };
@@ -7,19 +7,18 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
7
7
  step((generator = generator.apply(thisArg, _arguments || [])).next());
8
8
  });
9
9
  };
10
- import React, { useEffect } from 'react';
10
+ import React, { useEffect, useState } from 'react';
11
11
  import ThemeContext from './theme.context';
12
- import { useSwitchTheme } from './theme.hook';
13
12
  const STORAGE_KEY = 'THEME_ID';
14
13
  export const ThemeProvider = ({ children, themeId, themes }) => {
15
- const [_themeId, setThemeId] = useSwitchTheme(themeId);
14
+ const [_themeId, setThemeId] = useState(themeId);
16
15
  useEffect(() => {
17
16
  (() => __awaiter(void 0, void 0, void 0, function* () {
18
17
  const id = localStorage.getItem(STORAGE_KEY);
19
18
  setThemeId(id || themeId);
20
19
  }))();
21
20
  }, [themeId]);
22
- return (React.createElement(ThemeContext.Provider, { value: { themeId: _themeId, themes } }, _themeId ? children : null));
21
+ return (React.createElement(ThemeContext.Provider, { value: { themeId: _themeId, themes, switchTheme: setThemeId } }, _themeId ? children : null));
23
22
  };
24
23
  /*export function withTheme(Component: ({children, theme, themes }: (any & ThemeProps)) => JSX.Element) {
25
24
 
@@ -1,2 +1,3 @@
1
1
  export * from './core';
2
2
  export * from './components';
3
+ export * from './utils';
package/dist/esm/index.js CHANGED
@@ -1,2 +1,3 @@
1
1
  export * from './core';
2
2
  export * from './components';
3
+ export * from './utils';
@@ -0,0 +1 @@
1
+ export * from './storage-manager';
@@ -0,0 +1 @@
1
+ export * from './storage-manager';
@@ -0,0 +1,7 @@
1
+ export interface StorageManager<T> {
2
+ type: 'cookie' | 'localStorage';
3
+ get(init?: T): T | undefined;
4
+ set(value: T): void;
5
+ }
6
+ export declare const createLocalStorageManager: <T>(key: string) => StorageManager<T>;
7
+ export declare const createCookieStorageManager: (key: string, cookie?: string) => StorageManager<string>;
@@ -0,0 +1,44 @@
1
+ // Usage
2
+ // export const localStorageManager = createLocalStorageManager(STORAGE_KEY);
3
+ export const createLocalStorageManager = (key) => ({
4
+ type: 'localStorage',
5
+ get(init) {
6
+ if (!(globalThis === null || globalThis === void 0 ? void 0 : globalThis.document))
7
+ return init;
8
+ let value;
9
+ try {
10
+ value = localStorage.getItem(key) || init;
11
+ }
12
+ catch (e) {
13
+ // no op
14
+ }
15
+ return JSON.parse(value) || init;
16
+ },
17
+ set(value) {
18
+ try {
19
+ localStorage.setItem(key, JSON.stringify(value));
20
+ }
21
+ catch (e) {
22
+ // no op
23
+ }
24
+ },
25
+ });
26
+ const parseCookie = (cookie, key) => {
27
+ const match = cookie.match(new RegExp(`(^| )${key}=([^;]+)`));
28
+ return match === null || match === void 0 ? void 0 : match[2];
29
+ };
30
+ // Usage
31
+ // export const cookieStorageManager = createCookieStorageManager(STORAGE_KEY);
32
+ export const createCookieStorageManager = (key, cookie) => ({
33
+ type: 'cookie',
34
+ get(init) {
35
+ if (cookie)
36
+ return parseCookie(cookie, key);
37
+ if (!(globalThis === null || globalThis === void 0 ? void 0 : globalThis.document))
38
+ return init;
39
+ return parseCookie(document.cookie, key) || init;
40
+ },
41
+ set(value) {
42
+ document.cookie = `${key}=${value}; max-age=31536000; path=/`;
43
+ },
44
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uni-design-system/uni-react",
3
- "version": "0.0.16",
3
+ "version": "0.0.17",
4
4
  "description": "React component library for the UNI Design System.",
5
5
  "main": "dist/cjs/index.js",
6
6
  "module": "dist/esm/index.js",
@@ -33,10 +33,11 @@
33
33
  "homepage": "https://github.com/uni-design-system/uni-react#readme",
34
34
  "packageManager": "yarn@3.0.2",
35
35
  "dependencies": {
36
+ "@callstack/react-theme-provider": "^3.0.8",
36
37
  "@dnd-kit/core": "^6.0.7",
37
38
  "@dnd-kit/modifiers": "^6.0.1",
38
39
  "@dnd-kit/sortable": "^7.0.2",
39
- "@uni-design-system/uni-core": "^0.0.34",
40
+ "@uni-design-system/uni-core": "^0.0.35",
40
41
  "@uni-design-system/uni-react-icons": "^0.1.2",
41
42
  "framer-motion": "4.1.17",
42
43
  "use-ripple-hook": "^1.0.22"