@uni-design-system/uni-react 0.0.17 → 0.0.18
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 +1 -1
- package/dist/cjs/components/switch/switch.component.d.ts +1 -1
- package/dist/cjs/core/background/background.component.d.ts +11 -5
- package/dist/cjs/core/background/background.component.js +13 -11
- package/dist/cjs/core/background/index.d.ts +1 -0
- package/dist/cjs/core/background/index.js +17 -0
- package/dist/cjs/core/index.d.ts +1 -0
- package/dist/cjs/core/index.js +1 -0
- package/dist/esm/components/switch/switch.component.d.ts +1 -1
- package/dist/esm/core/background/background.component.d.ts +11 -5
- package/dist/esm/core/background/background.component.js +12 -10
- package/dist/esm/core/background/index.d.ts +1 -0
- package/dist/esm/core/background/index.js +1 -0
- package/dist/esm/core/index.d.ts +1 -0
- package/dist/esm/core/index.js +1 -0
- package/package.json +1 -1
- package/dist/cjs/core/theme/theme.context.d.ts +0 -9
- package/dist/cjs/core/theme/theme.context.js +0 -16
- package/dist/cjs/core/theme/theme.hook.d.ts +0 -5
- package/dist/cjs/core/theme/theme.hook.js +0 -53
- package/dist/cjs/core/theme/theme.provider.d.ts +0 -9
- package/dist/cjs/core/theme/theme.provider.js +0 -73
- package/dist/esm/core/theme/theme.context.d.ts +0 -9
- package/dist/esm/core/theme/theme.context.js +0 -11
- package/dist/esm/core/theme/theme.hook.d.ts +0 -5
- package/dist/esm/core/theme/theme.hook.js +0 -22
- package/dist/esm/core/theme/theme.provider.d.ts +0 -9
- package/dist/esm/core/theme/theme.provider.js +0 -43
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
<p align="center">
|
|
2
2
|
<a href="https://uni-design-system.github.io/uni-react/" target="_blank">
|
|
3
|
-
<img src="
|
|
3
|
+
<img src="https://github.com/uni-design-system/uni-react/raw/v0.0.17/.github/uni-logo.png" alt="UNI Design System">
|
|
4
4
|
</a>
|
|
5
5
|
</p>
|
|
6
6
|
|
|
@@ -1,9 +1,15 @@
|
|
|
1
1
|
import { ReactNode } from 'react';
|
|
2
2
|
import { Property } from 'csstype';
|
|
3
|
-
interface BackgroundProps {
|
|
3
|
+
export interface BackgroundProps {
|
|
4
|
+
className?: string;
|
|
4
5
|
children?: ReactNode;
|
|
5
|
-
image?: Property.BackgroundImage
|
|
6
|
-
|
|
6
|
+
image?: Property.BackgroundImage;
|
|
7
|
+
imageUrl?: string;
|
|
8
|
+
gradiant?: Property.BackgroundImage;
|
|
9
|
+
position?: Property.BackgroundPosition;
|
|
10
|
+
size?: Property.BackgroundSize;
|
|
11
|
+
attachment?: 'fixed' | 'local' | 'scroll';
|
|
12
|
+
minHeight?: Property.MinHeight;
|
|
13
|
+
color?: string;
|
|
7
14
|
}
|
|
8
|
-
export declare const Background: ({ children, image, gradiant }: BackgroundProps) => JSX.Element;
|
|
9
|
-
export {};
|
|
15
|
+
export declare const Background: ({ children, image, imageUrl, gradiant, position, size, attachment, className, minHeight, color, }: BackgroundProps) => JSX.Element;
|
|
@@ -5,16 +5,18 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.Background = void 0;
|
|
7
7
|
const react_1 = __importDefault(require("react"));
|
|
8
|
-
const
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
exports.Background = Background;
|
|
15
|
-
function BackgroundStyle({ image, gradiant, theme }) {
|
|
16
|
-
return {
|
|
17
|
-
backgroundColor: theme.colors.background,
|
|
8
|
+
const Background = ({ children, image, imageUrl, gradiant, position, size, attachment, className, minHeight, color, }) => {
|
|
9
|
+
if (!!imageUrl) {
|
|
10
|
+
image = `url(${imageUrl})`;
|
|
11
|
+
}
|
|
12
|
+
const style = {
|
|
13
|
+
backgroundColor: color,
|
|
18
14
|
backgroundImage: image || gradiant,
|
|
15
|
+
backgroundPosition: position,
|
|
16
|
+
backgroundSize: size,
|
|
17
|
+
minHeight,
|
|
18
|
+
backgroundAttachment: attachment,
|
|
19
19
|
};
|
|
20
|
-
}
|
|
20
|
+
return (react_1.default.createElement("div", { className: className, style: style }, children));
|
|
21
|
+
};
|
|
22
|
+
exports.Background = Background;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './background.component';
|
|
@@ -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("./background.component"), exports);
|
package/dist/cjs/core/index.d.ts
CHANGED
package/dist/cjs/core/index.js
CHANGED
|
@@ -14,6 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./background"), exports);
|
|
17
18
|
__exportStar(require("./border"), exports);
|
|
18
19
|
__exportStar(require("./container"), exports);
|
|
19
20
|
__exportStar(require("./flex"), exports);
|
|
@@ -1,9 +1,15 @@
|
|
|
1
1
|
import { ReactNode } from 'react';
|
|
2
2
|
import { Property } from 'csstype';
|
|
3
|
-
interface BackgroundProps {
|
|
3
|
+
export interface BackgroundProps {
|
|
4
|
+
className?: string;
|
|
4
5
|
children?: ReactNode;
|
|
5
|
-
image?: Property.BackgroundImage
|
|
6
|
-
|
|
6
|
+
image?: Property.BackgroundImage;
|
|
7
|
+
imageUrl?: string;
|
|
8
|
+
gradiant?: Property.BackgroundImage;
|
|
9
|
+
position?: Property.BackgroundPosition;
|
|
10
|
+
size?: Property.BackgroundSize;
|
|
11
|
+
attachment?: 'fixed' | 'local' | 'scroll';
|
|
12
|
+
minHeight?: Property.MinHeight;
|
|
13
|
+
color?: string;
|
|
7
14
|
}
|
|
8
|
-
export declare const Background: ({ children, image, gradiant }: BackgroundProps) => JSX.Element;
|
|
9
|
-
export {};
|
|
15
|
+
export declare const Background: ({ children, image, imageUrl, gradiant, position, size, attachment, className, minHeight, color, }: BackgroundProps) => JSX.Element;
|
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
function BackgroundStyle({ image, gradiant, theme }) {
|
|
9
|
-
return {
|
|
10
|
-
backgroundColor: theme.colors.background,
|
|
2
|
+
export const Background = ({ children, image, imageUrl, gradiant, position, size, attachment, className, minHeight, color, }) => {
|
|
3
|
+
if (!!imageUrl) {
|
|
4
|
+
image = `url(${imageUrl})`;
|
|
5
|
+
}
|
|
6
|
+
const style = {
|
|
7
|
+
backgroundColor: color,
|
|
11
8
|
backgroundImage: image || gradiant,
|
|
9
|
+
backgroundPosition: position,
|
|
10
|
+
backgroundSize: size,
|
|
11
|
+
minHeight,
|
|
12
|
+
backgroundAttachment: attachment,
|
|
12
13
|
};
|
|
13
|
-
}
|
|
14
|
+
return (React.createElement("div", { className: className, style: style }, children));
|
|
15
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './background.component';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './background.component';
|
package/dist/esm/core/index.d.ts
CHANGED
package/dist/esm/core/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
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>;
|
|
9
|
-
export default ThemeContext;
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const react_1 = __importDefault(require("react"));
|
|
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
|
-
});
|
|
13
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
14
|
-
ThemeContext.displayName = 'ThemeContext';
|
|
15
|
-
}
|
|
16
|
-
exports.default = ThemeContext;
|
|
@@ -1,53 +0,0 @@
|
|
|
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
|
-
};
|
|
25
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
-
};
|
|
28
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
-
exports.useSwitchTheme = exports.useTheme = void 0;
|
|
30
|
-
const react_1 = __importStar(require("react"));
|
|
31
|
-
const theme_context_1 = __importDefault(require("./theme.context"));
|
|
32
|
-
const uni_core_1 = require("@uni-design-system/uni-core");
|
|
33
|
-
const useTheme = () => {
|
|
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]);
|
|
37
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
38
|
-
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
39
|
-
react_1.default.useDebugValue(theme);
|
|
40
|
-
}
|
|
41
|
-
(0, react_1.useEffect)(() => {
|
|
42
|
-
console.log(themeId);
|
|
43
|
-
theme = themes && themeId ? themes[themeId] : uni_core_1.BaseTheme;
|
|
44
|
-
}, [themeId]);
|
|
45
|
-
// return theme || LightTheme;
|
|
46
|
-
return theme;
|
|
47
|
-
};
|
|
48
|
-
exports.useTheme = useTheme;
|
|
49
|
-
const useSwitchTheme = () => {
|
|
50
|
-
const { switchTheme } = (0, react_1.useContext)(theme_context_1.default);
|
|
51
|
-
return { switchTheme };
|
|
52
|
-
};
|
|
53
|
-
exports.useSwitchTheme = useSwitchTheme;
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { Theme } from '@uni-design-system/uni-core';
|
|
3
|
-
interface ThemeProviderProps {
|
|
4
|
-
themeId?: string;
|
|
5
|
-
themes?: Record<string, Theme>;
|
|
6
|
-
children?: React.ReactChild;
|
|
7
|
-
}
|
|
8
|
-
export declare const ThemeProvider: ({ children, themeId, themes }: ThemeProviderProps) => JSX.Element;
|
|
9
|
-
export {};
|
|
@@ -1,73 +0,0 @@
|
|
|
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
|
-
};
|
|
25
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
26
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
27
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
28
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
29
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
30
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
31
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
32
|
-
});
|
|
33
|
-
};
|
|
34
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
35
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
36
|
-
};
|
|
37
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
38
|
-
exports.ThemeProvider = void 0;
|
|
39
|
-
const react_1 = __importStar(require("react"));
|
|
40
|
-
const theme_context_1 = __importDefault(require("./theme.context"));
|
|
41
|
-
const STORAGE_KEY = 'THEME_ID';
|
|
42
|
-
const ThemeProvider = ({ children, themeId, themes }) => {
|
|
43
|
-
const [_themeId, setThemeId] = (0, react_1.useState)(themeId);
|
|
44
|
-
(0, react_1.useEffect)(() => {
|
|
45
|
-
(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
46
|
-
const id = localStorage.getItem(STORAGE_KEY);
|
|
47
|
-
setThemeId(id || themeId);
|
|
48
|
-
}))();
|
|
49
|
-
}, [themeId]);
|
|
50
|
-
return (react_1.default.createElement(theme_context_1.default.Provider, { value: { themeId: _themeId, themes, switchTheme: setThemeId } }, _themeId ? children : null));
|
|
51
|
-
};
|
|
52
|
-
exports.ThemeProvider = ThemeProvider;
|
|
53
|
-
/*export function withTheme(Component: ({children, theme, themes }: (any & ThemeProps)) => JSX.Element) {
|
|
54
|
-
|
|
55
|
-
return (props: JSX.IntrinsicAttributes) => {
|
|
56
|
-
const { themeId, setThemeId } = useContext(ThemeContext);
|
|
57
|
-
|
|
58
|
-
const getTheme = (themeId: string) => themes[themeId];
|
|
59
|
-
const setTheme = (themeId: string) => {
|
|
60
|
-
localStorage.setItem(STORAGE_KEY, themeId);
|
|
61
|
-
setThemeId(themeId);
|
|
62
|
-
};
|
|
63
|
-
|
|
64
|
-
return (
|
|
65
|
-
<Component
|
|
66
|
-
{...props}
|
|
67
|
-
themes={Themes}
|
|
68
|
-
theme={getTheme(themeId)}
|
|
69
|
-
setTheme={setTheme}
|
|
70
|
-
/>
|
|
71
|
-
);
|
|
72
|
-
};
|
|
73
|
-
}*/
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
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>;
|
|
9
|
-
export default ThemeContext;
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { LightTheme } from '@uni-design-system/uni-core';
|
|
3
|
-
const ThemeContext = React.createContext({
|
|
4
|
-
themeId: 'LightTheme',
|
|
5
|
-
themes: { LightTheme },
|
|
6
|
-
switchTheme: () => { },
|
|
7
|
-
});
|
|
8
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
9
|
-
ThemeContext.displayName = 'ThemeContext';
|
|
10
|
-
}
|
|
11
|
-
export default ThemeContext;
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import React, { useContext, useEffect } from 'react';
|
|
2
|
-
import ThemeContext from './theme.context';
|
|
3
|
-
import { BaseTheme } from '@uni-design-system/uni-core';
|
|
4
|
-
export const useTheme = () => {
|
|
5
|
-
const { themeId, themes } = useContext(ThemeContext);
|
|
6
|
-
let theme = themes && themeId ? themes[themeId] : BaseTheme;
|
|
7
|
-
useEffect(() => { }, [themeId]);
|
|
8
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
9
|
-
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
10
|
-
React.useDebugValue(theme);
|
|
11
|
-
}
|
|
12
|
-
useEffect(() => {
|
|
13
|
-
console.log(themeId);
|
|
14
|
-
theme = themes && themeId ? themes[themeId] : BaseTheme;
|
|
15
|
-
}, [themeId]);
|
|
16
|
-
// return theme || LightTheme;
|
|
17
|
-
return theme;
|
|
18
|
-
};
|
|
19
|
-
export const useSwitchTheme = () => {
|
|
20
|
-
const { switchTheme } = useContext(ThemeContext);
|
|
21
|
-
return { switchTheme };
|
|
22
|
-
};
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { Theme } from '@uni-design-system/uni-core';
|
|
3
|
-
interface ThemeProviderProps {
|
|
4
|
-
themeId?: string;
|
|
5
|
-
themes?: Record<string, Theme>;
|
|
6
|
-
children?: React.ReactChild;
|
|
7
|
-
}
|
|
8
|
-
export declare const ThemeProvider: ({ children, themeId, themes }: ThemeProviderProps) => JSX.Element;
|
|
9
|
-
export {};
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
|
-
import React, { useEffect, useState } from 'react';
|
|
11
|
-
import ThemeContext from './theme.context';
|
|
12
|
-
const STORAGE_KEY = 'THEME_ID';
|
|
13
|
-
export const ThemeProvider = ({ children, themeId, themes }) => {
|
|
14
|
-
const [_themeId, setThemeId] = useState(themeId);
|
|
15
|
-
useEffect(() => {
|
|
16
|
-
(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
17
|
-
const id = localStorage.getItem(STORAGE_KEY);
|
|
18
|
-
setThemeId(id || themeId);
|
|
19
|
-
}))();
|
|
20
|
-
}, [themeId]);
|
|
21
|
-
return (React.createElement(ThemeContext.Provider, { value: { themeId: _themeId, themes, switchTheme: setThemeId } }, _themeId ? children : null));
|
|
22
|
-
};
|
|
23
|
-
/*export function withTheme(Component: ({children, theme, themes }: (any & ThemeProps)) => JSX.Element) {
|
|
24
|
-
|
|
25
|
-
return (props: JSX.IntrinsicAttributes) => {
|
|
26
|
-
const { themeId, setThemeId } = useContext(ThemeContext);
|
|
27
|
-
|
|
28
|
-
const getTheme = (themeId: string) => themes[themeId];
|
|
29
|
-
const setTheme = (themeId: string) => {
|
|
30
|
-
localStorage.setItem(STORAGE_KEY, themeId);
|
|
31
|
-
setThemeId(themeId);
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
return (
|
|
35
|
-
<Component
|
|
36
|
-
{...props}
|
|
37
|
-
themes={Themes}
|
|
38
|
-
theme={getTheme(themeId)}
|
|
39
|
-
setTheme={setTheme}
|
|
40
|
-
/>
|
|
41
|
-
);
|
|
42
|
-
};
|
|
43
|
-
}*/
|