@particle-network/ui-shared 0.4.1-beta.5 → 0.4.1-beta.7
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 +2 -0
- package/dist/index.js +2 -0
- package/dist/utils.d.ts +4 -0
- package/dist/utils.js +13 -0
- package/package.json +1 -1
|
@@ -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/utils.d.ts
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export declare function objectEntries<T extends object>(obj: T): [keyof T & string, T[keyof T & string]][];
|
|
2
|
+
export declare function objectKeys<T extends object>(obj: T): (keyof T & string)[];
|
|
3
|
+
export declare function objectValues<T extends object>(obj: T): T[keyof T & string][];
|
|
4
|
+
export declare function objectFromEntries<T extends object>(entries: [keyof T & string, T[keyof T & string]][]): T;
|
package/dist/utils.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
function objectEntries(obj) {
|
|
2
|
+
return Object.entries(obj);
|
|
3
|
+
}
|
|
4
|
+
function objectKeys(obj) {
|
|
5
|
+
return Object.keys(obj);
|
|
6
|
+
}
|
|
7
|
+
function objectValues(obj) {
|
|
8
|
+
return Object.values(obj);
|
|
9
|
+
}
|
|
10
|
+
function objectFromEntries(entries) {
|
|
11
|
+
return Object.fromEntries(entries);
|
|
12
|
+
}
|
|
13
|
+
export { objectEntries, objectFromEntries, objectKeys, objectValues };
|