musae 1.0.27-beta.37 → 1.0.27-beta.39
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.
|
@@ -112,13 +112,7 @@ var PALETTE = {
|
|
|
112
112
|
* @description
|
|
113
113
|
* theme context
|
|
114
114
|
*/
|
|
115
|
-
var Context = /*#__PURE__*/React.createContext(
|
|
116
|
-
colors: colorRole.toColorRoles(PALETTE, "light"),
|
|
117
|
-
mode: "light",
|
|
118
|
-
toggle: function toggle() {
|
|
119
|
-
return void 0;
|
|
120
|
-
}
|
|
121
|
-
});
|
|
115
|
+
var Context = /*#__PURE__*/React.createContext(null);
|
|
122
116
|
/**
|
|
123
117
|
* @author murukal
|
|
124
118
|
*
|
|
@@ -129,7 +123,11 @@ var Context = /*#__PURE__*/React.createContext({
|
|
|
129
123
|
* set the preset theme for musae ui component
|
|
130
124
|
*/
|
|
131
125
|
var useTheme = function useTheme() {
|
|
132
|
-
|
|
126
|
+
var context = React.useContext(Context);
|
|
127
|
+
if (!context) {
|
|
128
|
+
throw new Error("useTheme must be used within a ThemeProvider");
|
|
129
|
+
}
|
|
130
|
+
return context;
|
|
133
131
|
};
|
|
134
132
|
/**
|
|
135
133
|
* @description
|
|
@@ -178,6 +176,7 @@ var useSwitchable = function useSwitchable(_ref) {
|
|
|
178
176
|
document.documentElement.attributeStyleMap.set("--color-light", theme.palette.neutral[100]);
|
|
179
177
|
document.documentElement.attributeStyleMap.set("--color-dark", theme.palette.neutral[0]);
|
|
180
178
|
new rxjs.Observable(function (subscriber) {
|
|
179
|
+
subscriber.next(mode);
|
|
181
180
|
trigger.current = subscriber;
|
|
182
181
|
}).pipe(rxjs.distinctUntilChanged()).subscribe({
|
|
183
182
|
next: repaint
|
|
@@ -5,7 +5,7 @@ export declare const PALETTE: Readonly<Palette>;
|
|
|
5
5
|
* @description
|
|
6
6
|
* theme context
|
|
7
7
|
*/
|
|
8
|
-
export declare const Context: import("react").Context<ContextValue>;
|
|
8
|
+
export declare const Context: import("react").Context<ContextValue | null>;
|
|
9
9
|
/**
|
|
10
10
|
* @author murukal
|
|
11
11
|
*
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import _toConsumableArray from '@babel/runtime/helpers/toConsumableArray';
|
|
2
2
|
import _slicedToArray from '@babel/runtime/helpers/slicedToArray';
|
|
3
|
-
import {
|
|
3
|
+
import { useContext, createContext, useState, useRef, useMemo } from 'react';
|
|
4
4
|
import { toColorRoles } from '../../utils/color-role.mjs';
|
|
5
5
|
import { useEvent, useMounted, isFunction } from '@aiszlab/relax';
|
|
6
6
|
import { normalize } from '@aiszlab/relax/class-name';
|
|
@@ -110,13 +110,7 @@ var PALETTE = {
|
|
|
110
110
|
* @description
|
|
111
111
|
* theme context
|
|
112
112
|
*/
|
|
113
|
-
var Context = /*#__PURE__*/createContext(
|
|
114
|
-
colors: toColorRoles(PALETTE, "light"),
|
|
115
|
-
mode: "light",
|
|
116
|
-
toggle: function toggle() {
|
|
117
|
-
return void 0;
|
|
118
|
-
}
|
|
119
|
-
});
|
|
113
|
+
var Context = /*#__PURE__*/createContext(null);
|
|
120
114
|
/**
|
|
121
115
|
* @author murukal
|
|
122
116
|
*
|
|
@@ -127,7 +121,11 @@ var Context = /*#__PURE__*/createContext({
|
|
|
127
121
|
* set the preset theme for musae ui component
|
|
128
122
|
*/
|
|
129
123
|
var useTheme = function useTheme() {
|
|
130
|
-
|
|
124
|
+
var context = useContext(Context);
|
|
125
|
+
if (!context) {
|
|
126
|
+
throw new Error("useTheme must be used within a ThemeProvider");
|
|
127
|
+
}
|
|
128
|
+
return context;
|
|
131
129
|
};
|
|
132
130
|
/**
|
|
133
131
|
* @description
|
|
@@ -176,6 +174,7 @@ var useSwitchable = function useSwitchable(_ref) {
|
|
|
176
174
|
document.documentElement.attributeStyleMap.set("--color-light", theme.palette.neutral[100]);
|
|
177
175
|
document.documentElement.attributeStyleMap.set("--color-dark", theme.palette.neutral[0]);
|
|
178
176
|
new Observable(function (subscriber) {
|
|
177
|
+
subscriber.next(mode);
|
|
179
178
|
trigger.current = subscriber;
|
|
180
179
|
}).pipe(distinctUntilChanged()).subscribe({
|
|
181
180
|
next: repaint
|
package/dist/types/theme.d.ts
CHANGED
|
@@ -64,9 +64,9 @@ export interface ContextValue {
|
|
|
64
64
|
*/
|
|
65
65
|
mode: Mode;
|
|
66
66
|
/**
|
|
67
|
-
* @
|
|
68
|
-
* toggle theme mode,
|
|
67
|
+
* @zh 切换主题模式,返回更新后的模式
|
|
68
|
+
* @en toggle theme mode, returns the updated mode
|
|
69
69
|
*/
|
|
70
|
-
toggle: (event?: MouseEvent) =>
|
|
70
|
+
toggle: (event?: MouseEvent) => Mode;
|
|
71
71
|
}
|
|
72
72
|
export {};
|