@particle-network/ui-shared 0.4.1-beta.4 → 0.4.1-beta.6
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/hooks/index.d.ts +3 -0
- package/dist/hooks/index.js +3 -0
- package/dist/hooks/use-color-scheme.d.ts +5 -0
- package/dist/hooks/use-color-scheme.js +14 -0
- package/dist/hooks/use-theme-color.d.ts +1 -0
- package/dist/hooks/use-theme-color.js +6 -0
- package/dist/hooks/use-theme-store.d.ts +46 -0
- package/dist/hooks/use-theme-store.js +36 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/theme-data.js +2 -1
- package/package.json +3 -3
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { useMemo } from "react";
|
|
2
|
+
import { useThemeStore } from "./use-theme-store.js";
|
|
3
|
+
const useColorScheme = ()=>{
|
|
4
|
+
const { colorScheme } = useThemeStore((state)=>state.theme);
|
|
5
|
+
const scheme = useMemo(()=>({
|
|
6
|
+
colorScheme,
|
|
7
|
+
isDark: 'dark' === colorScheme,
|
|
8
|
+
isLight: 'light' === colorScheme
|
|
9
|
+
}), [
|
|
10
|
+
colorScheme
|
|
11
|
+
]);
|
|
12
|
+
return scheme;
|
|
13
|
+
};
|
|
14
|
+
export { useColorScheme };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const useThemeColor: () => Record<import("..").ThemeColorVariable, string>;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import type { ThemeItemType } from '../theme-data';
|
|
2
|
+
export type FontLoadStatus = 'idle' | 'loading' | 'success' | 'error';
|
|
3
|
+
interface State {
|
|
4
|
+
/**
|
|
5
|
+
* 保存的主题
|
|
6
|
+
*/
|
|
7
|
+
theme: ThemeItemType;
|
|
8
|
+
/**
|
|
9
|
+
* 保存的自定义主题配置(当切换到其他主题时保存,切回 custom 时恢复)
|
|
10
|
+
*/
|
|
11
|
+
customTheme: ThemeItemType;
|
|
12
|
+
/**
|
|
13
|
+
* 保存的字体链接
|
|
14
|
+
*/
|
|
15
|
+
fontUrl: string;
|
|
16
|
+
/**
|
|
17
|
+
* 应用的字体名称
|
|
18
|
+
*/
|
|
19
|
+
fontName: string;
|
|
20
|
+
/**
|
|
21
|
+
* 字体加载状态
|
|
22
|
+
*/
|
|
23
|
+
fontLoadStatus: FontLoadStatus;
|
|
24
|
+
}
|
|
25
|
+
interface Actions {
|
|
26
|
+
setTheme: (theme: ThemeItemType) => void;
|
|
27
|
+
setCustomTheme: (customTheme: ThemeItemType) => void;
|
|
28
|
+
setFontUrl: (fontUrl: string) => void;
|
|
29
|
+
setFontLoadStatus: (status: FontLoadStatus) => void;
|
|
30
|
+
setFontName: (name: string) => void;
|
|
31
|
+
}
|
|
32
|
+
type ThemeStore = State & Actions;
|
|
33
|
+
export declare const useThemeStore: import("zustand").UseBoundStore<Omit<import("zustand").StoreApi<ThemeStore>, "setState" | "persist"> & {
|
|
34
|
+
setState(partial: ThemeStore | Partial<ThemeStore> | ((state: ThemeStore) => ThemeStore | Partial<ThemeStore>), replace?: false | undefined): unknown;
|
|
35
|
+
setState(state: ThemeStore | ((state: ThemeStore) => ThemeStore), replace: true): unknown;
|
|
36
|
+
persist: {
|
|
37
|
+
setOptions: (options: Partial<import("zustand/middleware").PersistOptions<ThemeStore, unknown, unknown>>) => void;
|
|
38
|
+
clearStorage: () => void;
|
|
39
|
+
rehydrate: () => Promise<void> | void;
|
|
40
|
+
hasHydrated: () => boolean;
|
|
41
|
+
onHydrate: (fn: (state: ThemeStore) => void) => () => void;
|
|
42
|
+
onFinishHydration: (fn: (state: ThemeStore) => void) => () => void;
|
|
43
|
+
getOptions: () => Partial<import("zustand/middleware").PersistOptions<ThemeStore, unknown, unknown>>;
|
|
44
|
+
};
|
|
45
|
+
}>;
|
|
46
|
+
export {};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { create } from "zustand";
|
|
2
|
+
import { createJSONStorage, persist } from "zustand/middleware";
|
|
3
|
+
import { CustomTheme, UXDarkTheme } from "../theme-data.js";
|
|
4
|
+
const useThemeStore = create()(persist((set)=>({
|
|
5
|
+
theme: UXDarkTheme,
|
|
6
|
+
customTheme: CustomTheme,
|
|
7
|
+
fontUrl: '',
|
|
8
|
+
fontName: '',
|
|
9
|
+
fontLoadStatus: 'idle',
|
|
10
|
+
setTheme: (theme)=>set({
|
|
11
|
+
theme
|
|
12
|
+
}),
|
|
13
|
+
setCustomTheme: (customTheme)=>set({
|
|
14
|
+
customTheme
|
|
15
|
+
}),
|
|
16
|
+
setFontUrl: (fontUrl)=>set({
|
|
17
|
+
fontUrl
|
|
18
|
+
}),
|
|
19
|
+
setFontLoadStatus: (fontLoadStatus)=>set({
|
|
20
|
+
fontLoadStatus
|
|
21
|
+
}),
|
|
22
|
+
setFontName: (fontName)=>set({
|
|
23
|
+
fontName
|
|
24
|
+
})
|
|
25
|
+
}), {
|
|
26
|
+
name: 'ux-preference-theme',
|
|
27
|
+
version: 2,
|
|
28
|
+
storage: createJSONStorage(()=>'undefined' != typeof window ? window.localStorage : {}),
|
|
29
|
+
partialize: (state)=>({
|
|
30
|
+
theme: state.theme,
|
|
31
|
+
customTheme: state.customTheme,
|
|
32
|
+
fontName: state.fontName,
|
|
33
|
+
fontUrl: state.fontUrl
|
|
34
|
+
})
|
|
35
|
+
}));
|
|
36
|
+
export { useThemeStore };
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
package/dist/theme-data.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@particle-network/ui-shared",
|
|
3
|
-
"version": "0.4.1-beta.
|
|
3
|
+
"version": "0.4.1-beta.6",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"react-native": "./dist/index.js",
|
|
@@ -44,8 +44,8 @@
|
|
|
44
44
|
"@rsbuild/plugin-react": "^1.3.5",
|
|
45
45
|
"@rslib/core": "^0.12.3",
|
|
46
46
|
"@types/react": "^19.1.10",
|
|
47
|
-
"@particle-network/
|
|
48
|
-
"@particle-network/
|
|
47
|
+
"@particle-network/lintstaged-config": "0.1.0",
|
|
48
|
+
"@particle-network/eslint-config": "0.3.0"
|
|
49
49
|
},
|
|
50
50
|
"scripts": {
|
|
51
51
|
"build": "rslib build",
|