@kbach/react-native 1.0.0-beta.20 → 1.0.0-beta.22
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/README.md +72 -13
- package/android/src/main/jniLibs/arm64-v8a/libkbach_core_engine.so +0 -0
- package/android/src/main/jniLibs/x86_64/libkbach_core_engine.so +0 -0
- package/dist/chunk-AG7ZQ2K4.mjs +552 -0
- package/dist/{chunk-MJWWZJMH.mjs → chunk-OS7EPBH5.mjs} +1 -1
- package/dist/{chunk-45GOGUHJ.mjs → chunk-TS2EEVOE.mjs} +1 -1
- package/dist/dynamicTokens.d.ts +5 -4
- package/dist/index.d.ts +1 -1
- package/dist/index.js +177 -9
- package/dist/index.web.d.ts +1 -1
- package/dist/index.web.js +28 -3
- package/dist/index.web.mjs +29 -4
- package/dist/jsx-dev-runtime.js +370 -156
- package/dist/jsx-dev-runtime.web.js +3 -4
- package/dist/jsx-dev-runtime.web.mjs +3 -3
- package/dist/jsx-runtime.js +360 -146
- package/dist/jsx-runtime.web.js +1 -1
- package/dist/jsx-runtime.web.mjs +2 -2
- package/dist/{useDynamicToken-Dr15c88t.d.ts → useDynamicToken-DAHQob1u.d.ts} +37 -6
- package/package.json +1 -1
- package/dist/chunk-OGFB3OXS.mjs +0 -552
package/dist/index.web.mjs
CHANGED
|
@@ -9,13 +9,13 @@ import {
|
|
|
9
9
|
subscribeDynamicTokens,
|
|
10
10
|
subscribeGlobalDarkMode,
|
|
11
11
|
toggleGlobalDarkMode
|
|
12
|
-
} from "./chunk-
|
|
12
|
+
} from "./chunk-TS2EEVOE.mjs";
|
|
13
13
|
import {
|
|
14
14
|
defaultTheme,
|
|
15
15
|
getTheme,
|
|
16
16
|
resolveClassName,
|
|
17
17
|
setTheme
|
|
18
|
-
} from "./chunk-
|
|
18
|
+
} from "./chunk-AG7ZQ2K4.mjs";
|
|
19
19
|
|
|
20
20
|
// src/config.ts
|
|
21
21
|
function parseHexRgb(hex) {
|
|
@@ -94,9 +94,13 @@ function useTheme() {
|
|
|
94
94
|
// src/ThemeProvider.tsx
|
|
95
95
|
import { useEffect, useRef } from "react";
|
|
96
96
|
import { Fragment, jsx } from "react/jsx-runtime";
|
|
97
|
+
var PERSIST_STORAGE_KEY = "kbach-theme";
|
|
98
|
+
function isThemeMode(value) {
|
|
99
|
+
return value === "light" || value === "dark" || value === "system";
|
|
100
|
+
}
|
|
97
101
|
var mountedProviderCount = 0;
|
|
98
102
|
var warnedMultipleProviders = false;
|
|
99
|
-
function ThemeProvider({ children, defaultMode = "system" }) {
|
|
103
|
+
function ThemeProvider({ children, defaultMode = "system", persist = false }) {
|
|
100
104
|
useEffect(() => {
|
|
101
105
|
mountedProviderCount++;
|
|
102
106
|
if (mountedProviderCount > 1 && !warnedMultipleProviders) {
|
|
@@ -113,8 +117,29 @@ function ThemeProvider({ children, defaultMode = "system" }) {
|
|
|
113
117
|
useEffect(() => {
|
|
114
118
|
if (seeded.current) return;
|
|
115
119
|
seeded.current = true;
|
|
116
|
-
|
|
120
|
+
if (!persist) {
|
|
121
|
+
seedDefaultMode(defaultMode);
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
124
|
+
let cancelled = false;
|
|
125
|
+
persist.getItem(PERSIST_STORAGE_KEY).then((stored) => {
|
|
126
|
+
if (cancelled) return;
|
|
127
|
+
if (isThemeMode(stored)) seedDefaultMode(stored);
|
|
128
|
+
else seedDefaultMode(defaultMode);
|
|
129
|
+
}).catch(() => {
|
|
130
|
+
if (!cancelled) seedDefaultMode(defaultMode);
|
|
131
|
+
});
|
|
132
|
+
return () => {
|
|
133
|
+
cancelled = true;
|
|
134
|
+
};
|
|
117
135
|
}, []);
|
|
136
|
+
useEffect(() => {
|
|
137
|
+
if (!persist) return;
|
|
138
|
+
return subscribeGlobalDarkMode(() => {
|
|
139
|
+
persist.setItem(PERSIST_STORAGE_KEY, getGlobalThemeMode()).catch(() => {
|
|
140
|
+
});
|
|
141
|
+
});
|
|
142
|
+
}, [persist]);
|
|
118
143
|
return /* @__PURE__ */ jsx(Fragment, { children });
|
|
119
144
|
}
|
|
120
145
|
|