@arcblock/ux 2.13.20 → 2.13.23
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/lib/Config/config-provider.d.ts +6 -23
- package/lib/Config/config-provider.js +19 -80
- package/lib/Config/theme-mode-toggle.js +2 -2
- package/lib/DIDConnect/did-connect-container.d.ts +23 -0
- package/lib/DIDConnect/did-connect-container.js +270 -0
- package/lib/DIDConnect/did-connect-footer.d.ts +3 -1
- package/lib/DIDConnect/did-connect-footer.js +5 -3
- package/lib/DIDConnect/index.d.ts +1 -0
- package/lib/DIDConnect/index.js +2 -1
- package/lib/NavMenu/images/payment-kit.png +0 -0
- package/lib/NavMenu/products.js +30 -4
- package/lib/NavMenu/style.js +2 -1
- package/lib/PhoneInput/index.js +2 -1
- package/lib/SessionUser/components/quick-login-item.js +4 -4
- package/lib/SessionUser/components/un-login.js +6 -5
- package/lib/SharedBridge/index.js +8 -8
- package/lib/SharedBridge/need-storage-access-api-dialog.d.ts +1 -2
- package/lib/SharedBridge/need-storage-access-api-dialog.js +2 -23
- package/lib/Theme/index.d.ts +1 -0
- package/lib/Theme/index.js +1 -0
- package/lib/Theme/theme-provider.d.ts +27 -12
- package/lib/Theme/theme-provider.js +123 -16
- package/lib/Theme/theme.d.ts +5 -4
- package/lib/Theme/theme.js +6 -5
- package/package.json +6 -6
- package/src/Config/config-provider.tsx +21 -103
- package/src/Config/theme-mode-toggle.tsx +2 -2
- package/src/DIDConnect/did-connect-container.tsx +320 -0
- package/src/DIDConnect/did-connect-footer.tsx +25 -19
- package/src/DIDConnect/index.ts +1 -0
- package/src/NavMenu/images/payment-kit.png +0 -0
- package/src/NavMenu/products.tsx +21 -4
- package/src/NavMenu/style.ts +2 -1
- package/src/PhoneInput/index.tsx +2 -1
- package/src/SessionUser/components/quick-login-item.tsx +3 -3
- package/src/SessionUser/components/un-login.tsx +5 -4
- package/src/SessionUser/components/user-info.tsx +1 -1
- package/src/SharedBridge/index.tsx +4 -12
- package/src/SharedBridge/need-storage-access-api-dialog.tsx +1 -23
- package/src/Theme/index.ts +1 -0
- package/src/Theme/theme-provider.tsx +144 -16
- package/src/Theme/theme.ts +8 -9
@@ -150,7 +150,7 @@ export default function UnLogin({
|
|
150
150
|
maxWidth: '90vw',
|
151
151
|
borderColor: 'divider',
|
152
152
|
border: '0 !important',
|
153
|
-
boxShadow:
|
153
|
+
boxShadow: 4
|
154
154
|
},
|
155
155
|
children: [/*#__PURE__*/_jsxs(Box, {
|
156
156
|
sx: {
|
@@ -158,7 +158,8 @@ export default function UnLogin({
|
|
158
158
|
alignItems: 'center',
|
159
159
|
gap: 1,
|
160
160
|
p: 2,
|
161
|
-
borderBottom: '1px solid
|
161
|
+
borderBottom: '1px solid',
|
162
|
+
borderColor: 'divider'
|
162
163
|
},
|
163
164
|
children: [loginAppLogo && !currentState.loadAppLogoError ? /*#__PURE__*/_jsx("img", {
|
164
165
|
src: loginAppLogo,
|
@@ -205,8 +206,9 @@ export default function UnLogin({
|
|
205
206
|
overflow: 'hidden',
|
206
207
|
position: 'relative',
|
207
208
|
p: 0,
|
209
|
+
bgcolor: 'background.paper',
|
208
210
|
'&:hover': {
|
209
|
-
|
211
|
+
bgcolor: `${palette.action.hover} !important`
|
210
212
|
}
|
211
213
|
},
|
212
214
|
onClick: () => {
|
@@ -227,8 +229,7 @@ export default function UnLogin({
|
|
227
229
|
}, userSessionItem.id), index < currentState.userSessions.length - 1 ? /*#__PURE__*/_jsx(Divider, {
|
228
230
|
sx: {
|
229
231
|
mx: 2,
|
230
|
-
my: '0px !important'
|
231
|
-
borderColor: '#e4e4e7'
|
232
|
+
my: '0px !important'
|
232
233
|
}
|
233
234
|
}, `${userSessionItem.id}-divider`) : null]
|
234
235
|
}, `${userSessionItem.id}-root`);
|
@@ -6,7 +6,7 @@ import { useMemoizedFn, useReactive } from 'ahooks';
|
|
6
6
|
import { mergeSx } from '../Util/style';
|
7
7
|
import { callIframe, getCallbackAction } from '../Util/iframe';
|
8
8
|
import NeedStorageAccessApiDialog from './need-storage-access-api-dialog';
|
9
|
-
import {
|
9
|
+
import { DIDConnectContainer } from '../DIDConnect';
|
10
10
|
const SharedBridge = /*#__PURE__*/memo(function SharedBridge({
|
11
11
|
src,
|
12
12
|
onClick,
|
@@ -67,7 +67,6 @@ const SharedBridge = /*#__PURE__*/memo(function SharedBridge({
|
|
67
67
|
};
|
68
68
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
69
69
|
}, [onClick, dataId, targetIframeRef?.current]);
|
70
|
-
const DialogComponent = withUxTheme(withContainer(NeedStorageAccessApiDialog));
|
71
70
|
const handleLoad = useMemoizedFn(() => {
|
72
71
|
callIframe(targetIframeRef.current, 'hasStorageAccess').then(({
|
73
72
|
value
|
@@ -89,14 +88,15 @@ const SharedBridge = /*#__PURE__*/memo(function SharedBridge({
|
|
89
88
|
return null;
|
90
89
|
}
|
91
90
|
return /*#__PURE__*/_jsxs(_Fragment, {
|
92
|
-
children: [/*#__PURE__*/_jsx(
|
91
|
+
children: [/*#__PURE__*/_jsx(DIDConnectContainer, {
|
93
92
|
popup: true,
|
94
|
-
|
95
|
-
blocklet: window.blocklet,
|
93
|
+
hideCloseButton: true,
|
96
94
|
open: currentState.open,
|
97
|
-
|
98
|
-
|
99
|
-
|
95
|
+
children: /*#__PURE__*/_jsx(NeedStorageAccessApiDialog, {
|
96
|
+
locale: locale,
|
97
|
+
origin: currentState.origin,
|
98
|
+
host: currentState.host
|
99
|
+
})
|
100
100
|
}), /*#__PURE__*/_jsx(Box, {
|
101
101
|
...rest,
|
102
102
|
component: "iframe",
|
@@ -1,7 +1,6 @@
|
|
1
1
|
import { Locale } from '../type';
|
2
|
-
export default function NeedStorageAccessApiDialog({ locale, origin, host,
|
2
|
+
export default function NeedStorageAccessApiDialog({ locale, origin, host, }: {
|
3
3
|
locale?: Locale;
|
4
4
|
origin: string;
|
5
5
|
host: string;
|
6
|
-
setColor: (color: string) => void;
|
7
6
|
}): import("react/jsx-runtime").JSX.Element;
|
@@ -5,12 +5,8 @@ import externalLinkIcon from '@iconify-icons/tabler/external-link';
|
|
5
5
|
import lockOutlineIcon from '@iconify-icons/material-symbols/lock-outline';
|
6
6
|
import checkCircleIcon from '@iconify-icons/material-symbols/check-circle';
|
7
7
|
import rocketLaunchRoundedIcon from '@iconify-icons/material-symbols/rocket-launch-rounded';
|
8
|
-
import {
|
9
|
-
import { useEffect } from 'react';
|
10
|
-
import { getDIDMotifInfo } from '@arcblock/did-motif';
|
8
|
+
import { useMemoizedFn } from 'ahooks';
|
11
9
|
import { translate } from '../Locale/util';
|
12
|
-
import { getDIDColor, isEthereumDid } from '../Util';
|
13
|
-
import { DIDConnectFooter } from '../DIDConnect';
|
14
10
|
const translations = {
|
15
11
|
en: {
|
16
12
|
allow: 'Allow',
|
@@ -64,25 +60,11 @@ const translations = {
|
|
64
60
|
export default function NeedStorageAccessApiDialog({
|
65
61
|
locale = 'en',
|
66
62
|
origin,
|
67
|
-
host
|
68
|
-
setColor
|
63
|
+
host
|
69
64
|
}) {
|
70
65
|
const t = useMemoizedFn((key, data = {}) => {
|
71
66
|
return translate(translations, key, locale, 'en', data);
|
72
67
|
});
|
73
|
-
const currentAppColor = useCreation(() => {
|
74
|
-
const did = window.blocklet.appPid;
|
75
|
-
const isEthDid = isEthereumDid(did);
|
76
|
-
const didMotifInfo = isEthDid ? undefined : getDIDMotifInfo(did);
|
77
|
-
if (isEthDid) {
|
78
|
-
return getDIDColor(did);
|
79
|
-
}
|
80
|
-
return didMotifInfo.color;
|
81
|
-
}, []);
|
82
|
-
useEffect(() => {
|
83
|
-
setColor(currentAppColor);
|
84
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
85
|
-
}, [currentAppColor]);
|
86
68
|
return /*#__PURE__*/_jsxs(Box, {
|
87
69
|
sx: {
|
88
70
|
backgroundColor: 'background.default',
|
@@ -94,7 +76,6 @@ export default function NeedStorageAccessApiDialog({
|
|
94
76
|
transition: 'width 0.2s ease-in-out',
|
95
77
|
margin: 'auto',
|
96
78
|
p: 3,
|
97
|
-
pb: 0,
|
98
79
|
gap: 2
|
99
80
|
},
|
100
81
|
children: [/*#__PURE__*/_jsxs(Typography, {
|
@@ -205,8 +186,6 @@ export default function NeedStorageAccessApiDialog({
|
|
205
186
|
color: "grey.700",
|
206
187
|
children: t('dataUsage')
|
207
188
|
})]
|
208
|
-
}), /*#__PURE__*/_jsx(DIDConnectFooter, {
|
209
|
-
currentAppColor: currentAppColor
|
210
189
|
})]
|
211
190
|
});
|
212
191
|
}
|
package/lib/Theme/index.d.ts
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
import type { CreateMUIStyled, Theme } from '@mui/material';
|
2
2
|
import { useTheme } from '@mui/material';
|
3
3
|
export * from './theme';
|
4
|
+
export * from './theme-provider';
|
4
5
|
export { default as ThemeProvider } from './theme-provider';
|
5
6
|
export { useTheme };
|
6
7
|
export declare const styled: CreateMUIStyled<Theme>;
|
package/lib/Theme/index.js
CHANGED
@@ -1,28 +1,43 @@
|
|
1
1
|
import PropTypes from 'prop-types';
|
2
|
+
import { PaletteMode } from '@mui/material';
|
2
3
|
import { Theme } from '@mui/material/styles';
|
3
|
-
|
4
|
+
/** 颜色模式上下文类型 */
|
5
|
+
export interface ColorSchemeContextType {
|
6
|
+
mode: PaletteMode;
|
7
|
+
toggleMode: () => void;
|
8
|
+
prefer?: Prefer;
|
9
|
+
}
|
10
|
+
export declare const ColorSchemeContext: import("react").Context<ColorSchemeContextType>;
|
11
|
+
export declare function useColorScheme(): ColorSchemeContextType;
|
12
|
+
export type UxTheme = Partial<Theme> | ((outerTheme: Partial<Theme>) => Theme);
|
13
|
+
export type Prefer = 'light' | 'dark' | 'system';
|
14
|
+
interface BaseThemeProviderProps {
|
4
15
|
children?: React.ReactNode;
|
5
|
-
theme
|
16
|
+
theme?: UxTheme;
|
6
17
|
injectFirst?: boolean;
|
7
18
|
/** 指定一个类名,DarkSchemeStyles 只会作用于带有该类的元素及其后代 */
|
8
19
|
darkSchemeClass?: string;
|
9
20
|
}
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
21
|
+
interface ColorSchemeProviderProps extends BaseThemeProviderProps {
|
22
|
+
prefer?: Prefer;
|
23
|
+
disableBlockletTheme?: boolean;
|
24
|
+
}
|
25
|
+
export interface ThemeProviderProps extends ColorSchemeProviderProps {
|
26
|
+
/** 下列情况会启用 ColorScheme 功能(让 theme 支持明暗模式切换)
|
27
|
+
* 1. 显示打开 enableColorScheme
|
28
|
+
* 2. 显示设置 prefer
|
29
|
+
* 3. 顶层 ThemeProvider
|
30
|
+
*/
|
31
|
+
enableColorScheme?: boolean;
|
32
|
+
}
|
33
|
+
declare function ThemeProvider({ children, prefer, enableColorScheme, ...props }: ThemeProviderProps): import("react/jsx-runtime").JSX.Element;
|
14
34
|
declare namespace ThemeProvider {
|
15
35
|
var propTypes: {
|
16
36
|
children: PropTypes.Requireable<any>;
|
17
37
|
theme: PropTypes.Requireable<any>;
|
18
38
|
injectFirst: PropTypes.Requireable<boolean>;
|
19
39
|
darkSchemeClass: PropTypes.Requireable<string>;
|
20
|
-
|
21
|
-
var defaultProps: {
|
22
|
-
children: null;
|
23
|
-
theme: Theme;
|
24
|
-
injectFirst: boolean;
|
25
|
-
darkSchemeClass: string;
|
40
|
+
enableColorScheme: PropTypes.Requireable<boolean>;
|
26
41
|
};
|
27
42
|
}
|
28
43
|
export default ThemeProvider;
|
@@ -1,11 +1,39 @@
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
2
|
+
import { createContext, useCallback, useContext, useEffect, useMemo, useState } from 'react';
|
2
3
|
import PropTypes from 'prop-types';
|
3
4
|
import { GlobalStyles } from '@mui/material';
|
4
5
|
import { ThemeProvider as MuiThemeProvider, useTheme } from '@mui/material/styles';
|
5
6
|
import StyledEngineProvider from '@mui/material/StyledEngineProvider';
|
6
7
|
import CssBaseline from '@mui/material/CssBaseline';
|
7
|
-
import
|
8
|
+
import set from 'lodash/set';
|
9
|
+
import { BLOCKLET_THEME_PREFER_KEY } from '@blocklet/theme';
|
10
|
+
import { createTheme, getDefaultThemePrefer, isTheme, lazyThemeConfig } from './theme';
|
8
11
|
const defaultTheme = createTheme();
|
12
|
+
|
13
|
+
/** 颜色模式上下文类型 */
|
14
|
+
|
15
|
+
export const ColorSchemeContext = /*#__PURE__*/createContext({});
|
16
|
+
export function useColorScheme() {
|
17
|
+
return useContext(ColorSchemeContext);
|
18
|
+
}
|
19
|
+
|
20
|
+
/** 根据偏好获取颜色模式 */
|
21
|
+
const resolveMode = prefer => {
|
22
|
+
if (prefer) {
|
23
|
+
if (prefer === 'system') {
|
24
|
+
// 取系统默认
|
25
|
+
return getDefaultThemePrefer({
|
26
|
+
theme: {
|
27
|
+
prefer: 'system'
|
28
|
+
}
|
29
|
+
});
|
30
|
+
}
|
31
|
+
return prefer;
|
32
|
+
}
|
33
|
+
return getDefaultThemePrefer();
|
34
|
+
};
|
35
|
+
|
36
|
+
/** 深色模式全局样式 */
|
9
37
|
function DarkSchemeStyles({
|
10
38
|
className
|
11
39
|
}) {
|
@@ -55,22 +83,26 @@ function DarkSchemeStyles({
|
|
55
83
|
}
|
56
84
|
return null;
|
57
85
|
}
|
58
|
-
/**
|
59
|
-
|
60
|
-
*/
|
61
|
-
export default function ThemeProvider({
|
86
|
+
/** 基础的 theme provider, 可以为 webapp/blocklet 快捷的配置好 mui theme provider */
|
87
|
+
function BaseThemeProvider({
|
62
88
|
children,
|
63
|
-
theme,
|
64
|
-
injectFirst,
|
65
|
-
darkSchemeClass
|
89
|
+
theme = defaultTheme,
|
90
|
+
injectFirst = true,
|
91
|
+
darkSchemeClass = ''
|
66
92
|
}) {
|
93
|
+
const _theme = useMemo(() => {
|
94
|
+
if (isTheme(theme)) return theme;
|
95
|
+
|
96
|
+
// 是 ThemeOptions 则创建一个 theme
|
97
|
+
return createTheme(theme);
|
98
|
+
}, [theme]);
|
67
99
|
return (
|
68
100
|
/*#__PURE__*/
|
69
101
|
// injectFirst 会影响 makeStyles 自定义样式和 mui styles 覆盖问题
|
70
102
|
_jsx(StyledEngineProvider, {
|
71
103
|
injectFirst: injectFirst,
|
72
104
|
children: /*#__PURE__*/_jsxs(MuiThemeProvider, {
|
73
|
-
theme:
|
105
|
+
theme: _theme,
|
74
106
|
children: [/*#__PURE__*/_jsx(CssBaseline, {}), /*#__PURE__*/_jsx(DarkSchemeStyles, {
|
75
107
|
className: darkSchemeClass
|
76
108
|
}), children]
|
@@ -78,15 +110,90 @@ export default function ThemeProvider({
|
|
78
110
|
})
|
79
111
|
);
|
80
112
|
}
|
113
|
+
/** 带颜色模式切换功能的 theme provider */
|
114
|
+
function ColorSchemeProvider({
|
115
|
+
children,
|
116
|
+
theme: themeInput,
|
117
|
+
prefer,
|
118
|
+
disableBlockletTheme = false,
|
119
|
+
...rest
|
120
|
+
}) {
|
121
|
+
const [mode, setMode] = useState(() => resolveMode(prefer));
|
122
|
+
const _themeInput = useMemo(() => {
|
123
|
+
let result = {};
|
124
|
+
const getThemeConfig = lazyThemeConfig(mode);
|
125
|
+
if (themeInput) {
|
126
|
+
if (typeof themeInput === 'function') {
|
127
|
+
result = {
|
128
|
+
...themeInput(getThemeConfig())
|
129
|
+
};
|
130
|
+
} else {
|
131
|
+
result = {
|
132
|
+
...themeInput
|
133
|
+
};
|
134
|
+
}
|
135
|
+
}
|
136
|
+
set(result, 'palette.mode', mode);
|
137
|
+
set(result, 'mode', mode);
|
138
|
+
return result;
|
139
|
+
}, [mode, themeInput]);
|
140
|
+
const theme = useMemo(() => {
|
141
|
+
return createTheme({
|
142
|
+
..._themeInput,
|
143
|
+
disableBlockletTheme
|
144
|
+
});
|
145
|
+
}, [_themeInput, disableBlockletTheme]);
|
146
|
+
|
147
|
+
// 切换明/暗模式
|
148
|
+
const toggleMode = useCallback(() => {
|
149
|
+
const newMode = mode === 'light' ? 'dark' : 'light';
|
150
|
+
setMode(newMode);
|
151
|
+
localStorage.setItem(BLOCKLET_THEME_PREFER_KEY, newMode);
|
152
|
+
}, [mode, setMode]);
|
153
|
+
const colorSchemeValue = useMemo(() => ({
|
154
|
+
mode,
|
155
|
+
toggleMode,
|
156
|
+
prefer
|
157
|
+
}), [mode, prefer, toggleMode]);
|
158
|
+
useEffect(() => {
|
159
|
+
if (prefer) {
|
160
|
+
setMode(resolveMode(prefer));
|
161
|
+
}
|
162
|
+
}, [prefer, setMode]);
|
163
|
+
return /*#__PURE__*/_jsx(ColorSchemeContext.Provider, {
|
164
|
+
value: colorSchemeValue,
|
165
|
+
children: /*#__PURE__*/_jsx(BaseThemeProvider, {
|
166
|
+
theme: theme,
|
167
|
+
...rest,
|
168
|
+
children: children
|
169
|
+
})
|
170
|
+
});
|
171
|
+
}
|
172
|
+
export default function ThemeProvider({
|
173
|
+
children,
|
174
|
+
prefer,
|
175
|
+
enableColorScheme = false,
|
176
|
+
...props
|
177
|
+
}) {
|
178
|
+
const {
|
179
|
+
toggleMode
|
180
|
+
} = useColorScheme();
|
181
|
+
if (enableColorScheme || prefer || !toggleMode) {
|
182
|
+
return /*#__PURE__*/_jsx(ColorSchemeProvider, {
|
183
|
+
prefer: prefer,
|
184
|
+
...props,
|
185
|
+
children: children
|
186
|
+
});
|
187
|
+
}
|
188
|
+
return /*#__PURE__*/_jsx(BaseThemeProvider, {
|
189
|
+
...props,
|
190
|
+
children: children
|
191
|
+
});
|
192
|
+
}
|
81
193
|
ThemeProvider.propTypes = {
|
82
194
|
children: PropTypes.any,
|
83
195
|
theme: PropTypes.any,
|
84
196
|
injectFirst: PropTypes.bool,
|
85
|
-
darkSchemeClass: PropTypes.string
|
86
|
-
|
87
|
-
ThemeProvider.defaultProps = {
|
88
|
-
children: null,
|
89
|
-
theme: defaultTheme,
|
90
|
-
injectFirst: true,
|
91
|
-
darkSchemeClass: ''
|
197
|
+
darkSchemeClass: PropTypes.string,
|
198
|
+
enableColorScheme: PropTypes.bool
|
92
199
|
};
|
package/lib/Theme/theme.d.ts
CHANGED
@@ -7,6 +7,8 @@ import '@fontsource/roboto/latin-700.css';
|
|
7
7
|
import '@fontsource/roboto/latin-ext-400.css';
|
8
8
|
import '@fontsource/roboto/latin-ext-500.css';
|
9
9
|
import '@fontsource/roboto/latin-ext-700.css';
|
10
|
+
/** 是否是 MUI Theme 对象 */
|
11
|
+
export declare function isTheme(obj: any): obj is Theme;
|
10
12
|
export declare function collectFontFamilies(obj?: {
|
11
13
|
fontFamily?: string;
|
12
14
|
}, fontSet?: Set<string>): Set<string>;
|
@@ -20,8 +22,7 @@ export declare function createDefaultThemeOptions(mode?: PaletteMode): ThemeOpti
|
|
20
22
|
export interface UserThemeOptions extends ThemeOptions {
|
21
23
|
disableBlockletTheme?: boolean;
|
22
24
|
}
|
23
|
-
export
|
24
|
-
export declare
|
25
|
-
export declare const
|
26
|
-
export declare const createTheme: (...args: Array<UserThemeOptions | ((config: ThemeConfig) => UserThemeOptions)>) => Theme;
|
25
|
+
export declare function lazyThemeConfig(mode: PaletteMode): () => Partial<Theme>;
|
26
|
+
export declare const create: (...args: Array<UserThemeOptions | ((config: Partial<Theme>) => UserThemeOptions)>) => Theme;
|
27
|
+
export declare const createTheme: (...args: Array<UserThemeOptions | ((config: Partial<Theme>) => UserThemeOptions)>) => Theme;
|
27
28
|
export { deepmerge };
|
package/lib/Theme/theme.js
CHANGED
@@ -3,7 +3,6 @@
|
|
3
3
|
|
4
4
|
import { createTheme as _createTheme, responsiveFontSizes } from '@mui/material/styles';
|
5
5
|
import { deepmerge } from '@mui/utils';
|
6
|
-
import pick from 'lodash/pick';
|
7
6
|
import webfontloader from 'webfontloader';
|
8
7
|
import { BLOCKLET_THEME_LIGHT, BLOCKLET_THEME_DARK, DEFAULT_FONTS, BLOCKLET_THEME_PREFER_KEY } from '@blocklet/theme';
|
9
8
|
import { cleanedObj, deepmergeAll } from '../Util';
|
@@ -16,6 +15,11 @@ import '@fontsource/roboto/latin-ext-400.css';
|
|
16
15
|
import '@fontsource/roboto/latin-ext-500.css';
|
17
16
|
import '@fontsource/roboto/latin-ext-700.css';
|
18
17
|
|
18
|
+
/** 是否是 MUI Theme 对象 */
|
19
|
+
export function isTheme(obj) {
|
20
|
+
return obj && typeof obj === 'object' && obj.palette && typeof obj.palette.getContrastText === 'function';
|
21
|
+
}
|
22
|
+
|
19
23
|
// 收集字体配置
|
20
24
|
export function collectFontFamilies(obj, fontSet = new Set()) {
|
21
25
|
if (!obj || typeof obj !== 'object') return fontSet;
|
@@ -90,15 +94,12 @@ export function createDefaultThemeOptions(mode = 'light') {
|
|
90
94
|
}
|
91
95
|
return BLOCKLET_THEME_LIGHT;
|
92
96
|
}
|
93
|
-
|
94
97
|
// 用于获取 Blocklet Theme 配置,便于用户创建自定义主题
|
95
|
-
|
96
98
|
export function lazyThemeConfig(mode) {
|
97
|
-
const fields = ['palette'];
|
98
99
|
let config = null;
|
99
100
|
return () => {
|
100
101
|
if (config) return config;
|
101
|
-
config = deepmerge(
|
102
|
+
config = deepmerge(createDefaultThemeOptions(mode), window.blocklet?.theme?.[mode] ?? {});
|
102
103
|
return config;
|
103
104
|
};
|
104
105
|
}
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@arcblock/ux",
|
3
|
-
"version": "2.13.
|
3
|
+
"version": "2.13.23",
|
4
4
|
"description": "Common used react components for arcblock products",
|
5
5
|
"keywords": [
|
6
6
|
"react",
|
@@ -71,14 +71,14 @@
|
|
71
71
|
"react": ">=18.2.0",
|
72
72
|
"react-router-dom": ">=6.22.3"
|
73
73
|
},
|
74
|
-
"gitHead": "
|
74
|
+
"gitHead": "6811ffbc6804b08140d05f031ac715b643240e75",
|
75
75
|
"dependencies": {
|
76
76
|
"@arcblock/did-motif": "^1.1.13",
|
77
|
-
"@arcblock/icons": "^2.13.
|
78
|
-
"@arcblock/nft-display": "^2.13.
|
79
|
-
"@arcblock/react-hooks": "^2.13.
|
77
|
+
"@arcblock/icons": "^2.13.23",
|
78
|
+
"@arcblock/nft-display": "^2.13.23",
|
79
|
+
"@arcblock/react-hooks": "^2.13.23",
|
80
80
|
"@babel/plugin-syntax-dynamic-import": "^7.8.3",
|
81
|
-
"@blocklet/theme": "^2.13.
|
81
|
+
"@blocklet/theme": "^2.13.23",
|
82
82
|
"@fontsource/roboto": "~5.1.1",
|
83
83
|
"@fontsource/ubuntu-mono": "^5.0.18",
|
84
84
|
"@iconify-icons/logos": "^1.2.36",
|
@@ -1,49 +1,10 @@
|
|
1
|
-
import {
|
2
|
-
import { ThemeOptions, type PaletteMode } from '@mui/material';
|
3
|
-
import { BLOCKLET_THEME_PREFER_KEY } from '@blocklet/theme';
|
4
|
-
import set from 'lodash/set';
|
5
|
-
import { ThemeProvider as EmotionThemeProvider } from '@emotion/react';
|
1
|
+
import { type ReactNode } from 'react';
|
6
2
|
import { LocaleProvider, LocaleProviderProps, useLocaleContext } from '../Locale/context';
|
7
|
-
import ThemeProvider, { ThemeProviderProps } from '../Theme/theme-provider';
|
8
|
-
import {
|
9
|
-
createTheme,
|
10
|
-
getDefaultThemePrefer,
|
11
|
-
lazyThemeConfig,
|
12
|
-
useTheme,
|
13
|
-
type UserThemeOptions,
|
14
|
-
type ThemeConfig,
|
15
|
-
} from '../Theme';
|
3
|
+
import ThemeProvider, { type ThemeProviderProps, useColorScheme } from '../Theme/theme-provider';
|
4
|
+
import { useTheme } from '../Theme';
|
16
5
|
|
17
|
-
|
18
|
-
|
19
|
-
export interface ConfigContextType {
|
20
|
-
mode: PaletteMode;
|
21
|
-
prefer?: Prefer;
|
22
|
-
themeOptions: UserThemeOptions;
|
23
|
-
toggleMode: () => void;
|
24
|
-
}
|
25
|
-
|
26
|
-
const resolveMode = (prefer?: Prefer): PaletteMode => {
|
27
|
-
if (prefer) {
|
28
|
-
if (prefer === 'system') {
|
29
|
-
// 取系统默认
|
30
|
-
return getDefaultThemePrefer({ theme: { prefer: 'system' } });
|
31
|
-
}
|
32
|
-
return prefer;
|
33
|
-
}
|
34
|
-
|
35
|
-
return getDefaultThemePrefer();
|
36
|
-
};
|
37
|
-
|
38
|
-
const ConfigContext = createContext<ConfigContextType>({} as ConfigContextType);
|
39
|
-
|
40
|
-
export interface ConfigProviderProps
|
41
|
-
extends Omit<LocaleProviderProps, 'translations'>,
|
42
|
-
Omit<ThemeProviderProps, 'theme'> {
|
6
|
+
export interface ConfigProviderProps extends Omit<LocaleProviderProps, 'translations'>, ThemeProviderProps {
|
43
7
|
children: ReactNode;
|
44
|
-
prefer?: Prefer;
|
45
|
-
theme?: UserThemeOptions | ((config: ThemeConfig) => UserThemeOptions);
|
46
|
-
disableBlockletTheme?: boolean;
|
47
8
|
translations?: Record<string, any>;
|
48
9
|
}
|
49
10
|
|
@@ -52,91 +13,48 @@ export interface ConfigProviderProps
|
|
52
13
|
*/
|
53
14
|
export function ConfigProvider({
|
54
15
|
children,
|
55
|
-
// theme
|
16
|
+
// theme provider
|
17
|
+
theme,
|
18
|
+
injectFirst,
|
19
|
+
darkSchemeClass,
|
56
20
|
prefer,
|
57
|
-
theme: themeOptions,
|
58
21
|
disableBlockletTheme = false,
|
59
|
-
|
60
|
-
// locale
|
22
|
+
enableColorScheme,
|
23
|
+
// locale provider
|
61
24
|
locale,
|
62
25
|
fallbackLocale,
|
63
26
|
translations = {},
|
64
27
|
languages,
|
65
28
|
onLoadingTranslation,
|
66
29
|
}: ConfigProviderProps) {
|
67
|
-
const [mode, setMode] = useState<PaletteMode>(() => resolveMode(prefer));
|
68
|
-
|
69
|
-
const _themeOptions = useMemo(() => {
|
70
|
-
let result: ThemeOptions = {};
|
71
|
-
const getThemeConfig = lazyThemeConfig(mode);
|
72
|
-
|
73
|
-
if (themeOptions) {
|
74
|
-
if (typeof themeOptions === 'function') {
|
75
|
-
result = themeOptions(getThemeConfig());
|
76
|
-
} else {
|
77
|
-
result = { ...themeOptions };
|
78
|
-
}
|
79
|
-
}
|
80
|
-
|
81
|
-
set(result, 'palette.mode', mode);
|
82
|
-
set(result, 'mode', mode);
|
83
|
-
|
84
|
-
return result;
|
85
|
-
}, [mode, themeOptions]);
|
86
|
-
|
87
|
-
const theme = useMemo(() => {
|
88
|
-
return createTheme({ ..._themeOptions, disableBlockletTheme });
|
89
|
-
}, [_themeOptions, disableBlockletTheme]);
|
90
|
-
|
91
|
-
const toggleMode = useCallback(() => {
|
92
|
-
const newMode = mode === 'light' ? 'dark' : 'light';
|
93
|
-
setMode(newMode);
|
94
|
-
localStorage.setItem(BLOCKLET_THEME_PREFER_KEY, newMode);
|
95
|
-
}, [mode, setMode]);
|
96
|
-
|
97
|
-
const config = useMemo(
|
98
|
-
() => ({
|
99
|
-
mode,
|
100
|
-
themeOptions: _themeOptions,
|
101
|
-
toggleMode,
|
102
|
-
prefer,
|
103
|
-
}),
|
104
|
-
[mode, prefer, _themeOptions, toggleMode]
|
105
|
-
);
|
106
|
-
|
107
|
-
// change prefer manually
|
108
|
-
useEffect(() => {
|
109
|
-
if (prefer) {
|
110
|
-
setMode(resolveMode(prefer));
|
111
|
-
}
|
112
|
-
}, [prefer, setMode]);
|
113
|
-
|
114
30
|
return (
|
115
|
-
<
|
31
|
+
<ThemeProvider
|
32
|
+
theme={theme}
|
33
|
+
injectFirst={injectFirst}
|
34
|
+
darkSchemeClass={darkSchemeClass}
|
35
|
+
prefer={prefer}
|
36
|
+
disableBlockletTheme={disableBlockletTheme}
|
37
|
+
enableColorScheme={enableColorScheme}>
|
116
38
|
<LocaleProvider
|
117
39
|
locale={locale}
|
118
40
|
fallbackLocale={fallbackLocale}
|
119
41
|
translations={translations}
|
120
42
|
onLoadingTranslation={onLoadingTranslation}
|
121
43
|
languages={languages}>
|
122
|
-
|
123
|
-
<EmotionThemeProvider theme={theme}>{children}</EmotionThemeProvider>
|
124
|
-
</ThemeProvider>
|
44
|
+
{children}
|
125
45
|
</LocaleProvider>
|
126
|
-
</
|
46
|
+
</ThemeProvider>
|
127
47
|
);
|
128
48
|
}
|
129
49
|
|
130
50
|
export function useConfig() {
|
131
51
|
const theme = useTheme();
|
132
52
|
const localeCtx = useLocaleContext();
|
133
|
-
const
|
53
|
+
const colorSchemeCtx = useColorScheme();
|
134
54
|
|
135
55
|
return {
|
136
56
|
theme,
|
137
57
|
...localeCtx,
|
138
|
-
...
|
58
|
+
...colorSchemeCtx,
|
139
59
|
};
|
140
60
|
}
|
141
|
-
|
142
|
-
ConfigProvider.useConfig = useConfig;
|
@@ -1,10 +1,10 @@
|
|
1
1
|
import { IconButton } from '@mui/material';
|
2
2
|
import LightModeOutlinedIcon from '@mui/icons-material/LightModeOutlined';
|
3
3
|
import Brightness2OutlinedIcon from '@mui/icons-material/Brightness2Outlined';
|
4
|
-
import {
|
4
|
+
import { useColorScheme } from '../Theme/theme-provider';
|
5
5
|
|
6
6
|
export default function ThemeModeToggle() {
|
7
|
-
const { mode, toggleMode, prefer } =
|
7
|
+
const { mode, toggleMode, prefer } = useColorScheme();
|
8
8
|
|
9
9
|
if (!toggleMode) {
|
10
10
|
if (process.env.NODE_ENV !== 'production') {
|