@kwiz/fluentui 1.0.96 → 1.0.97

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.
@@ -5,4 +5,5 @@ export * from './hooks';
5
5
  export * from './hooks-events';
6
6
  export * from './use-alerts';
7
7
  export * from './use-editable-control';
8
+ export * from './use-theme';
8
9
  export * from './use-toast';
@@ -5,5 +5,6 @@ export * from './hooks';
5
5
  export * from './hooks-events';
6
6
  export * from './use-alerts';
7
7
  export * from './use-editable-control';
8
+ export * from './use-theme';
8
9
  export * from './use-toast';
9
10
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/helpers/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAC5B,cAAc,kBAAkB,CAAC;AACjC,cAAc,aAAa,CAAC;AAC5B,cAAc,SAAS,CAAC;AACxB,cAAc,gBAAgB,CAAC;AAC/B,cAAc,cAAc,CAAC;AAC7B,cAAc,wBAAwB,CAAC;AACvC,cAAc,aAAa,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/helpers/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAC5B,cAAc,kBAAkB,CAAC;AACjC,cAAc,aAAa,CAAC;AAC5B,cAAc,SAAS,CAAC;AACxB,cAAc,gBAAgB,CAAC;AAC/B,cAAc,cAAc,CAAC;AAC7B,cAAc,wBAAwB,CAAC;AACvC,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC"}
@@ -0,0 +1,7 @@
1
+ export type themeScheme = "light" | "dark";
2
+ export interface iThemeInfo {
3
+ auto: boolean;
4
+ scheme: themeScheme;
5
+ }
6
+ export declare function setThemeInfo(themeInfo: iThemeInfo): void;
7
+ export declare function useTheme(): iThemeInfo;
@@ -0,0 +1,48 @@
1
+ "use client";
2
+ import { deleteCookie, forEach, getCookie, getGlobal, isNullOrUndefined, setCookie } from "@kwiz/common";
3
+ import { useEffect, useId, useState } from "react";
4
+ const $themeCookie = "KWTheme";
5
+ function getDefaultThemeInfo() {
6
+ const themeInfo = { auto: true, scheme: window.matchMedia('(prefers-color-scheme: dark)').matches ? "dark" : "light" };
7
+ return themeInfo;
8
+ }
9
+ function getThemeInfo() {
10
+ let themeInfo = null;
11
+ const cookie = getCookie($themeCookie);
12
+ if (isNullOrUndefined(cookie)) {
13
+ themeInfo = getDefaultThemeInfo();
14
+ }
15
+ else {
16
+ themeInfo = { auto: false, scheme: cookie === "dark" ? "dark" : "light" };
17
+ }
18
+ return themeInfo;
19
+ }
20
+ const globals = getGlobal("g_theme", {
21
+ theme: getThemeInfo(),
22
+ g_update_handlers: {}
23
+ });
24
+ export function setThemeInfo(themeInfo) {
25
+ const newThemeInfo = (themeInfo.auto && isNullOrUndefined(themeInfo.scheme))
26
+ ? getDefaultThemeInfo()
27
+ : themeInfo;
28
+ if (!themeInfo.auto) {
29
+ setCookie($themeCookie, themeInfo.scheme, 365);
30
+ }
31
+ else {
32
+ deleteCookie($themeCookie);
33
+ }
34
+ globals.theme = newThemeInfo;
35
+ forEach(globals.g_update_handlers, (name, value) => value(globals.theme));
36
+ }
37
+ export function useTheme() {
38
+ const [theme, setTheme] = useState(globals.theme);
39
+ const id = useId();
40
+ useEffect(() => {
41
+ globals.g_update_handlers[id] = (newTheme) => { setTheme(newTheme); };
42
+ return () => {
43
+ delete globals.g_update_handlers[id];
44
+ };
45
+ }, [id]);
46
+ return theme;
47
+ }
48
+ //# sourceMappingURL=use-theme.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-theme.js","sourceRoot":"","sources":["../../src/helpers/use-theme.ts"],"names":[],"mappings":"AAAA,YAAY,CAAA;AACZ,OAAO,EAAE,YAAY,EAAE,OAAO,EAAE,SAAS,EAAE,SAAS,EAAe,iBAAiB,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACtH,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE,QAAQ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,CAAC,KAAK,GAAG,YAAY,CAAC;IAC7B,OAAO,CAAC,OAAO,CAAC,iBAAiB,EAAE,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC;AAC9E,CAAC;AAED,MAAM,UAAU,QAAQ;IACpB,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAC,GAAG,QAAQ,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;IAClD,MAAM,EAAE,GAAG,KAAK,EAAE,CAAC;IACnB,SAAS,CAAC,GAAG,EAAE;QACX,OAAO,CAAC,iBAAiB,CAAC,EAAE,CAAC,GAAG,CAAC,QAAQ,EAAE,EAAE,GAAG,QAAQ,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC;QACtE,OAAO,GAAG,EAAE;YACR,OAAO,OAAO,CAAC,iBAAiB,CAAC,EAAE,CAAC,CAAC;QACzC,CAAC,CAAC;IACN,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;IACT,OAAO,KAAK,CAAC;AACjB,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kwiz/fluentui",
3
- "version": "1.0.96",
3
+ "version": "1.0.97",
4
4
  "description": "KWIZ common controls for FluentUI",
5
5
  "module": "dist/index.js",
6
6
  "types": "dist/index.d.ts",