fsk-design-system 1.2.0 → 1.2.1
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.
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { default as React } from 'react';
|
|
2
|
+
import { Theme } from './theme.types';
|
|
3
|
+
export type ThemeContextValue = {
|
|
4
|
+
theme: Theme;
|
|
5
|
+
changeTheme: (newTheme: Theme) => void;
|
|
6
|
+
};
|
|
7
|
+
export declare const ThemeContext: React.Context<ThemeContextValue | undefined>;
|
|
8
|
+
type Props = React.PropsWithChildren<{
|
|
9
|
+
forcedTheme?: Theme;
|
|
10
|
+
}>;
|
|
11
|
+
export declare const ThemeProviderContext: (props: Props) => import("@emotion/react/jsx-runtime").JSX.Element;
|
|
12
|
+
export {};
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { jsx as h } from "@emotion/react/jsx-runtime";
|
|
2
|
+
import s from "react";
|
|
3
|
+
const g = s.createContext(void 0), k = (r) => {
|
|
4
|
+
const {
|
|
5
|
+
forcedTheme: t,
|
|
6
|
+
children: f
|
|
7
|
+
} = r, [m, l] = s.useState(() => t || v()), n = (e, a = !0) => {
|
|
8
|
+
const o = document.documentElement;
|
|
9
|
+
o.classList.add(d), o.dataset.theme = e, a && l(e), requestAnimationFrame(() => {
|
|
10
|
+
o.classList.remove(d);
|
|
11
|
+
});
|
|
12
|
+
}, u = (e) => {
|
|
13
|
+
t || (localStorage.setItem(c, e), n(e, !1));
|
|
14
|
+
};
|
|
15
|
+
return s.useEffect(() => {
|
|
16
|
+
if (n(m, !1), t) return;
|
|
17
|
+
const e = (a) => {
|
|
18
|
+
const {
|
|
19
|
+
key: o,
|
|
20
|
+
newValue: i
|
|
21
|
+
} = a;
|
|
22
|
+
o === c && (i === "light" || i === "dark") && n(i);
|
|
23
|
+
};
|
|
24
|
+
return window.addEventListener("storage", e), () => window.removeEventListener("storage", e);
|
|
25
|
+
}, []), s.useEffect(() => {
|
|
26
|
+
t && n(t);
|
|
27
|
+
}, [t]), /* @__PURE__ */ h(g.Provider, { value: {
|
|
28
|
+
theme: m,
|
|
29
|
+
changeTheme: u
|
|
30
|
+
}, children: f });
|
|
31
|
+
}, v = () => {
|
|
32
|
+
if (typeof window > "u") return "light";
|
|
33
|
+
const r = localStorage.getItem(c);
|
|
34
|
+
return r || (window.matchMedia("(prefers-color-scheme: dark)").matches ? "dark" : "light");
|
|
35
|
+
}, c = "fsk-design-system-theme", d = "no-theme-transition";
|
|
36
|
+
export {
|
|
37
|
+
g as ThemeContext,
|
|
38
|
+
k as ThemeProviderContext
|
|
39
|
+
};
|
|
@@ -1,31 +1,33 @@
|
|
|
1
1
|
import { jsx as e } from "@emotion/react/jsx-runtime";
|
|
2
|
-
import { ConfigProvider as
|
|
3
|
-
import
|
|
2
|
+
import { ConfigProvider as t, App as i } from "antd";
|
|
3
|
+
import n from "antd/es/locale/ru_RU";
|
|
4
4
|
import c from "dayjs";
|
|
5
5
|
import "dayjs/locale/ru.js";
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
6
|
+
import { ThemeProviderContext as d } from "./theme.context.js";
|
|
7
|
+
import { themedTokens as h, commonTokens as s } from "./theme.tokens.js";
|
|
8
|
+
import { useTheme as p } from "./useTheme.js";
|
|
8
9
|
c.locale("ru");
|
|
9
|
-
const g = (
|
|
10
|
+
const g = (r) => {
|
|
10
11
|
const {
|
|
11
|
-
children:
|
|
12
|
-
forcedTheme: m,
|
|
13
|
-
...t
|
|
14
|
-
} = o, {
|
|
15
|
-
theme: i
|
|
16
|
-
} = f({
|
|
12
|
+
children: o,
|
|
17
13
|
forcedTheme: m
|
|
18
|
-
}
|
|
19
|
-
return /* @__PURE__ */ e(
|
|
14
|
+
} = r;
|
|
15
|
+
return /* @__PURE__ */ e(d, { forcedTheme: m, children: /* @__PURE__ */ e(l, { children: o }) });
|
|
16
|
+
}, l = (r) => {
|
|
17
|
+
const {
|
|
18
|
+
children: o
|
|
19
|
+
} = r, {
|
|
20
|
+
theme: m
|
|
21
|
+
} = p();
|
|
22
|
+
return /* @__PURE__ */ e(t, { locale: n, wave: {
|
|
20
23
|
disabled: !0
|
|
21
24
|
}, theme: {
|
|
22
|
-
...t,
|
|
23
25
|
cssVar: !0,
|
|
24
26
|
token: {
|
|
25
|
-
...
|
|
26
|
-
...h[
|
|
27
|
+
...s,
|
|
28
|
+
...h[m || "light"]
|
|
27
29
|
}
|
|
28
|
-
}, children: /* @__PURE__ */ e(
|
|
30
|
+
}, children: /* @__PURE__ */ e(i, { children: o }) });
|
|
29
31
|
};
|
|
30
32
|
export {
|
|
31
33
|
g as ThemeProvider
|
package/dist/theme/useTheme.d.ts
CHANGED
|
@@ -1,9 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
forcedTheme?: Theme;
|
|
4
|
-
};
|
|
5
|
-
export declare const useTheme: (props?: Props) => {
|
|
6
|
-
theme: Theme;
|
|
7
|
-
changeTheme: (newTheme: Theme) => void;
|
|
8
|
-
};
|
|
9
|
-
export {};
|
|
1
|
+
import { ThemeContextValue } from './theme.context';
|
|
2
|
+
export declare const useTheme: () => ThemeContextValue;
|
package/dist/theme/useTheme.js
CHANGED
|
@@ -1,36 +1,10 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
r.classList.add(d), r.dataset.theme = e, a && f(e), requestAnimationFrame(() => {
|
|
8
|
-
r.classList.remove(d);
|
|
9
|
-
});
|
|
10
|
-
}, u = (e) => {
|
|
11
|
-
t || (localStorage.setItem(c, e), n(e));
|
|
12
|
-
};
|
|
13
|
-
return i.useEffect(() => {
|
|
14
|
-
if (n(m, !1), t) return;
|
|
15
|
-
const e = (a) => {
|
|
16
|
-
const {
|
|
17
|
-
key: r,
|
|
18
|
-
newValue: s
|
|
19
|
-
} = a;
|
|
20
|
-
r !== c || !s || (s === "light" || s === "dark") && n(s);
|
|
21
|
-
};
|
|
22
|
-
return window.addEventListener("storage", e), () => window.removeEventListener("storage", e);
|
|
23
|
-
}, []), i.useEffect(() => {
|
|
24
|
-
t && n(t);
|
|
25
|
-
}, [t]), {
|
|
26
|
-
theme: m,
|
|
27
|
-
changeTheme: u
|
|
28
|
-
};
|
|
29
|
-
}, d = "no-theme-transition", c = "fsk-design-system-theme", l = () => {
|
|
30
|
-
if (typeof window > "u") return "light";
|
|
31
|
-
const o = localStorage.getItem(c);
|
|
32
|
-
return o || (window.matchMedia("(prefers-color-scheme: dark)").matches ? "dark" : "light");
|
|
1
|
+
import t from "react";
|
|
2
|
+
import { ThemeContext as o } from "./theme.context.js";
|
|
3
|
+
const n = () => {
|
|
4
|
+
const e = t.useContext(o);
|
|
5
|
+
if (!e) throw new Error("useTheme must be used inside ThemeProviderContext");
|
|
6
|
+
return e;
|
|
33
7
|
};
|
|
34
8
|
export {
|
|
35
|
-
|
|
9
|
+
n as useTheme
|
|
36
10
|
};
|