@uni-design-system/uni-react 0.0.15 → 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.
- package/dist/cjs/core/text/text.component.js +1 -1
- package/dist/cjs/core/theme/index.d.ts +9 -2
- package/dist/cjs/core/theme/index.js +5 -16
- package/dist/cjs/core/theme/theme.context.d.ts +7 -2
- package/dist/cjs/core/theme/theme.context.js +6 -1
- package/dist/cjs/core/theme/theme.hook.d.ts +4 -1
- package/dist/cjs/core/theme/theme.hook.js +40 -7
- package/dist/cjs/core/theme/theme.provider.d.ts +2 -2
- package/dist/cjs/core/theme/theme.provider.js +3 -9
- package/dist/cjs/index.d.ts +1 -0
- package/dist/cjs/index.js +1 -0
- package/dist/cjs/utils/index.d.ts +1 -0
- package/dist/cjs/utils/index.js +17 -0
- package/dist/cjs/utils/storage-manager.d.ts +7 -0
- package/dist/cjs/utils/storage-manager.js +49 -0
- package/dist/esm/core/text/text.component.js +1 -1
- package/dist/esm/core/theme/index.d.ts +9 -2
- package/dist/esm/core/theme/index.js +3 -2
- package/dist/esm/core/theme/theme.context.d.ts +7 -2
- package/dist/esm/core/theme/theme.context.js +6 -1
- package/dist/esm/core/theme/theme.hook.d.ts +4 -1
- package/dist/esm/core/theme/theme.hook.js +15 -6
- package/dist/esm/core/theme/theme.provider.d.ts +2 -2
- package/dist/esm/core/theme/theme.provider.js +4 -10
- package/dist/esm/index.d.ts +1 -0
- package/dist/esm/index.js +1 -0
- package/dist/esm/utils/index.d.ts +1 -0
- package/dist/esm/utils/index.js +1 -0
- package/dist/esm/utils/storage-manager.d.ts +7 -0
- package/dist/esm/utils/storage-manager.js +44 -0
- package/package.json +3 -2
|
@@ -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
|
-
|
|
2
|
-
|
|
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
|
|
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
|
-
|
|
18
|
-
|
|
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 {
|
|
3
|
-
|
|
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
|
|
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,20 +1,53 @@
|
|
|
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 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]);
|
|
13
37
|
if (process.env.NODE_ENV !== 'production') {
|
|
14
38
|
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
15
39
|
react_1.default.useDebugValue(theme);
|
|
16
40
|
}
|
|
41
|
+
(0, react_1.useEffect)(() => {
|
|
42
|
+
console.log(themeId);
|
|
43
|
+
theme = themes && themeId ? themes[themeId] : uni_core_1.BaseTheme;
|
|
44
|
+
}, [themeId]);
|
|
17
45
|
// return theme || LightTheme;
|
|
18
|
-
return theme
|
|
19
|
-
}
|
|
46
|
+
return theme;
|
|
47
|
+
};
|
|
20
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,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,7 +37,6 @@ 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"));
|
|
42
41
|
const STORAGE_KEY = 'THEME_ID';
|
|
43
42
|
const ThemeProvider = ({ children, themeId, themes }) => {
|
|
@@ -45,15 +44,10 @@ const ThemeProvider = ({ children, themeId, themes }) => {
|
|
|
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
|
-
|
|
49
|
-
setThemeId(id);
|
|
50
|
-
}
|
|
51
|
-
else {
|
|
52
|
-
setThemeId(uni_core_1.DefaultThemeId);
|
|
53
|
-
}
|
|
47
|
+
setThemeId(id || themeId);
|
|
54
48
|
}))();
|
|
55
|
-
}, []);
|
|
56
|
-
return (react_1.default.createElement(theme_context_1.default.Provider, { value: { themeId, themes } }, _themeId ? children : null));
|
|
49
|
+
}, [themeId]);
|
|
50
|
+
return (react_1.default.createElement(theme_context_1.default.Provider, { value: { themeId: _themeId, themes, switchTheme: setThemeId } }, _themeId ? children : null));
|
|
57
51
|
};
|
|
58
52
|
exports.ThemeProvider = ThemeProvider;
|
|
59
53
|
/*export function withTheme(Component: ({children, theme, themes }: (any & ThemeProps)) => JSX.Element) {
|
package/dist/cjs/index.d.ts
CHANGED
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
|
-
|
|
2
|
-
|
|
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
|
-
|
|
2
|
-
|
|
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 {
|
|
3
|
-
|
|
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
|
-
|
|
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,13 +1,22 @@
|
|
|
1
|
-
import React from 'react';
|
|
1
|
+
import React, { useContext, useEffect } from 'react';
|
|
2
2
|
import ThemeContext from './theme.context';
|
|
3
3
|
import { BaseTheme } from '@uni-design-system/uni-core';
|
|
4
|
-
export
|
|
5
|
-
const
|
|
6
|
-
|
|
4
|
+
export const useTheme = () => {
|
|
5
|
+
const { themeId, themes } = useContext(ThemeContext);
|
|
6
|
+
let theme = themes && themeId ? themes[themeId] : BaseTheme;
|
|
7
|
+
useEffect(() => { }, [themeId]);
|
|
7
8
|
if (process.env.NODE_ENV !== 'production') {
|
|
8
9
|
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
9
10
|
React.useDebugValue(theme);
|
|
10
11
|
}
|
|
12
|
+
useEffect(() => {
|
|
13
|
+
console.log(themeId);
|
|
14
|
+
theme = themes && themeId ? themes[themeId] : BaseTheme;
|
|
15
|
+
}, [themeId]);
|
|
11
16
|
// return theme || LightTheme;
|
|
12
|
-
return theme
|
|
13
|
-
}
|
|
17
|
+
return theme;
|
|
18
|
+
};
|
|
19
|
+
export const useSwitchTheme = () => {
|
|
20
|
+
const { switchTheme } = useContext(ThemeContext);
|
|
21
|
+
return { switchTheme };
|
|
22
|
+
};
|
|
@@ -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,8 +7,7 @@ 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, useState } from 'react';
|
|
12
11
|
import ThemeContext from './theme.context';
|
|
13
12
|
const STORAGE_KEY = 'THEME_ID';
|
|
14
13
|
export const ThemeProvider = ({ children, themeId, themes }) => {
|
|
@@ -16,15 +15,10 @@ export const ThemeProvider = ({ children, themeId, themes }) => {
|
|
|
16
15
|
useEffect(() => {
|
|
17
16
|
(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
18
17
|
const id = localStorage.getItem(STORAGE_KEY);
|
|
19
|
-
|
|
20
|
-
setThemeId(id);
|
|
21
|
-
}
|
|
22
|
-
else {
|
|
23
|
-
setThemeId(DefaultThemeId);
|
|
24
|
-
}
|
|
18
|
+
setThemeId(id || themeId);
|
|
25
19
|
}))();
|
|
26
|
-
}, []);
|
|
27
|
-
return (React.createElement(ThemeContext.Provider, { value: { themeId, themes } }, _themeId ? children : null));
|
|
20
|
+
}, [themeId]);
|
|
21
|
+
return (React.createElement(ThemeContext.Provider, { value: { themeId: _themeId, themes, switchTheme: setThemeId } }, _themeId ? children : null));
|
|
28
22
|
};
|
|
29
23
|
/*export function withTheme(Component: ({children, theme, themes }: (any & ThemeProps)) => JSX.Element) {
|
|
30
24
|
|
package/dist/esm/index.d.ts
CHANGED
package/dist/esm/index.js
CHANGED
|
@@ -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.
|
|
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.
|
|
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"
|