@uni-design-system/uni-react 0.0.15 → 0.0.16
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/cjs/core/theme/theme.hook.d.ts +2 -1
- package/dist/cjs/core/theme/theme.hook.js +44 -7
- package/dist/cjs/core/theme/theme.provider.d.ts +2 -2
- package/dist/cjs/core/theme/theme.provider.js +5 -10
- package/dist/esm/core/theme/theme.hook.d.ts +2 -1
- package/dist/esm/core/theme/theme.hook.js +20 -7
- package/dist/esm/core/theme/theme.provider.d.ts +2 -2
- package/dist/esm/core/theme/theme.provider.js +6 -11
- package/package.json +1 -1
|
@@ -1,20 +1,57 @@
|
|
|
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 __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
2
25
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
26
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
27
|
};
|
|
5
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.useTheme = void 0;
|
|
7
|
-
const react_1 =
|
|
29
|
+
exports.useSwitchTheme = exports.useTheme = void 0;
|
|
30
|
+
const react_1 = __importStar(require("react"));
|
|
8
31
|
const theme_context_1 = __importDefault(require("./theme.context"));
|
|
9
32
|
const uni_core_1 = require("@uni-design-system/uni-core");
|
|
10
|
-
|
|
11
|
-
const
|
|
12
|
-
|
|
33
|
+
const findTheme = (props) => {
|
|
34
|
+
const { themeId, themes } = props;
|
|
35
|
+
return themes && themeId ? themes[themeId] : uni_core_1.BaseTheme;
|
|
36
|
+
};
|
|
37
|
+
const useTheme = () => {
|
|
38
|
+
const themeProps = (0, react_1.useContext)(theme_context_1.default);
|
|
39
|
+
const theme = findTheme(themeProps);
|
|
13
40
|
if (process.env.NODE_ENV !== 'production') {
|
|
14
41
|
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
15
42
|
react_1.default.useDebugValue(theme);
|
|
16
43
|
}
|
|
17
44
|
// return theme || LightTheme;
|
|
18
|
-
return theme
|
|
19
|
-
}
|
|
45
|
+
return theme;
|
|
46
|
+
};
|
|
20
47
|
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];
|
|
56
|
+
};
|
|
57
|
+
exports.useSwitchTheme = useSwitchTheme;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { Theme } from '@uni-design-system/uni-core';
|
|
3
3
|
interface ThemeProviderProps {
|
|
4
|
-
themeId
|
|
5
|
-
themes
|
|
4
|
+
themeId?: string;
|
|
5
|
+
themes?: Record<string, Theme>;
|
|
6
6
|
children?: React.ReactChild;
|
|
7
7
|
}
|
|
8
8
|
export declare const ThemeProvider: ({ children, themeId, themes }: ThemeProviderProps) => JSX.Element;
|
|
@@ -37,23 +37,18 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
37
37
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
38
38
|
exports.ThemeProvider = void 0;
|
|
39
39
|
const react_1 = __importStar(require("react"));
|
|
40
|
-
const uni_core_1 = require("@uni-design-system/uni-core");
|
|
41
40
|
const theme_context_1 = __importDefault(require("./theme.context"));
|
|
41
|
+
const theme_hook_1 = require("./theme.hook");
|
|
42
42
|
const STORAGE_KEY = 'THEME_ID';
|
|
43
43
|
const ThemeProvider = ({ children, themeId, themes }) => {
|
|
44
|
-
const [_themeId, setThemeId] = (0,
|
|
44
|
+
const [_themeId, setThemeId] = (0, theme_hook_1.useSwitchTheme)(themeId);
|
|
45
45
|
(0, react_1.useEffect)(() => {
|
|
46
46
|
(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
47
47
|
const id = localStorage.getItem(STORAGE_KEY);
|
|
48
|
-
|
|
49
|
-
setThemeId(id);
|
|
50
|
-
}
|
|
51
|
-
else {
|
|
52
|
-
setThemeId(uni_core_1.DefaultThemeId);
|
|
53
|
-
}
|
|
48
|
+
setThemeId(id || themeId);
|
|
54
49
|
}))();
|
|
55
|
-
}, []);
|
|
56
|
-
return (react_1.default.createElement(theme_context_1.default.Provider, { value: { themeId, themes } }, _themeId ? children : null));
|
|
50
|
+
}, [themeId]);
|
|
51
|
+
return (react_1.default.createElement(theme_context_1.default.Provider, { value: { themeId: _themeId, themes } }, _themeId ? children : null));
|
|
57
52
|
};
|
|
58
53
|
exports.ThemeProvider = ThemeProvider;
|
|
59
54
|
/*export function withTheme(Component: ({children, theme, themes }: (any & ThemeProps)) => JSX.Element) {
|
|
@@ -1,13 +1,26 @@
|
|
|
1
|
-
import React from 'react';
|
|
1
|
+
import React, { useContext, useState } from 'react';
|
|
2
2
|
import ThemeContext from './theme.context';
|
|
3
|
-
import { BaseTheme } from '@uni-design-system/uni-core';
|
|
4
|
-
|
|
5
|
-
const
|
|
6
|
-
|
|
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
|
+
};
|
|
8
|
+
export const useTheme = () => {
|
|
9
|
+
const themeProps = useContext(ThemeContext);
|
|
10
|
+
const theme = findTheme(themeProps);
|
|
7
11
|
if (process.env.NODE_ENV !== 'production') {
|
|
8
12
|
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
9
13
|
React.useDebugValue(theme);
|
|
10
14
|
}
|
|
11
15
|
// return theme || LightTheme;
|
|
12
|
-
return theme
|
|
13
|
-
}
|
|
16
|
+
return theme;
|
|
17
|
+
};
|
|
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];
|
|
26
|
+
};
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { Theme } from '@uni-design-system/uni-core';
|
|
3
3
|
interface ThemeProviderProps {
|
|
4
|
-
themeId
|
|
5
|
-
themes
|
|
4
|
+
themeId?: string;
|
|
5
|
+
themes?: Record<string, Theme>;
|
|
6
6
|
children?: React.ReactChild;
|
|
7
7
|
}
|
|
8
8
|
export declare const ThemeProvider: ({ children, themeId, themes }: ThemeProviderProps) => JSX.Element;
|
|
@@ -7,24 +7,19 @@ 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, {
|
|
11
|
-
import { DefaultThemeId } from '@uni-design-system/uni-core';
|
|
10
|
+
import React, { useEffect } from 'react';
|
|
12
11
|
import ThemeContext from './theme.context';
|
|
12
|
+
import { useSwitchTheme } from './theme.hook';
|
|
13
13
|
const STORAGE_KEY = 'THEME_ID';
|
|
14
14
|
export const ThemeProvider = ({ children, themeId, themes }) => {
|
|
15
|
-
const [_themeId, setThemeId] =
|
|
15
|
+
const [_themeId, setThemeId] = useSwitchTheme(themeId);
|
|
16
16
|
useEffect(() => {
|
|
17
17
|
(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
18
18
|
const id = localStorage.getItem(STORAGE_KEY);
|
|
19
|
-
|
|
20
|
-
setThemeId(id);
|
|
21
|
-
}
|
|
22
|
-
else {
|
|
23
|
-
setThemeId(DefaultThemeId);
|
|
24
|
-
}
|
|
19
|
+
setThemeId(id || themeId);
|
|
25
20
|
}))();
|
|
26
|
-
}, []);
|
|
27
|
-
return (React.createElement(ThemeContext.Provider, { value: { themeId, themes } }, _themeId ? children : null));
|
|
21
|
+
}, [themeId]);
|
|
22
|
+
return (React.createElement(ThemeContext.Provider, { value: { themeId: _themeId, themes } }, _themeId ? children : null));
|
|
28
23
|
};
|
|
29
24
|
/*export function withTheme(Component: ({children, theme, themes }: (any & ThemeProps)) => JSX.Element) {
|
|
30
25
|
|