@kbach/react 0.2.4 → 0.2.5

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/index.d.mts CHANGED
@@ -145,17 +145,16 @@ interface ThemeProviderProps {
145
145
  /** Initial mode. Falls back to persisted value, then 'system'. */
146
146
  defaultMode?: ThemeMode;
147
147
  /**
148
- * Explicit color scheme override for native with `defaultMode="system"`.
148
+ * System color scheme for native `defaultMode="system"`.
149
149
  *
150
- * On some Android devices the system scheme is not detected on startup
151
- * (the `appearanceChanged` event only fires on *changes*, not on launch when
152
- * the device was already dark). Pass `useColorScheme()` from `react-native`
153
- * here to guarantee correct detection:
150
+ * Pass the value of `useColorScheme()` from `react-native`. When importing
151
+ * `ThemeProvider` from `@kbach/native` this is handled automatically.
154
152
  *
153
+ * @example
155
154
  * ```tsx
156
155
  * import { useColorScheme } from 'react-native';
157
- * const scheme = useColorScheme();
158
- * <ThemeProvider defaultMode="system" colorScheme={scheme}>…</ThemeProvider>
156
+ * const colorScheme = useColorScheme();
157
+ * <ThemeProvider defaultMode="system" colorScheme={colorScheme}>…</ThemeProvider>
159
158
  * ```
160
159
  */
161
160
  colorScheme?: 'light' | 'dark' | null;
@@ -164,7 +163,7 @@ interface ThemeProviderProps {
164
163
  /** Disable persistence to localStorage */
165
164
  disablePersistence?: boolean;
166
165
  }
167
- declare function ThemeProvider({ children, defaultMode, colorScheme: colorSchemeProp, config: configOverride, disablePersistence, }: ThemeProviderProps): React__default.JSX.Element;
166
+ declare function ThemeProvider({ children, defaultMode, colorScheme, config: configOverride, disablePersistence, }: ThemeProviderProps): React__default.JSX.Element;
168
167
 
169
168
  type ToggleVariant = 'button' | 'switch' | 'icon-button';
170
169
  interface ThemeToggleProps {
package/dist/index.d.ts CHANGED
@@ -145,17 +145,16 @@ interface ThemeProviderProps {
145
145
  /** Initial mode. Falls back to persisted value, then 'system'. */
146
146
  defaultMode?: ThemeMode;
147
147
  /**
148
- * Explicit color scheme override for native with `defaultMode="system"`.
148
+ * System color scheme for native `defaultMode="system"`.
149
149
  *
150
- * On some Android devices the system scheme is not detected on startup
151
- * (the `appearanceChanged` event only fires on *changes*, not on launch when
152
- * the device was already dark). Pass `useColorScheme()` from `react-native`
153
- * here to guarantee correct detection:
150
+ * Pass the value of `useColorScheme()` from `react-native`. When importing
151
+ * `ThemeProvider` from `@kbach/native` this is handled automatically.
154
152
  *
153
+ * @example
155
154
  * ```tsx
156
155
  * import { useColorScheme } from 'react-native';
157
- * const scheme = useColorScheme();
158
- * <ThemeProvider defaultMode="system" colorScheme={scheme}>…</ThemeProvider>
156
+ * const colorScheme = useColorScheme();
157
+ * <ThemeProvider defaultMode="system" colorScheme={colorScheme}>…</ThemeProvider>
159
158
  * ```
160
159
  */
161
160
  colorScheme?: 'light' | 'dark' | null;
@@ -164,7 +163,7 @@ interface ThemeProviderProps {
164
163
  /** Disable persistence to localStorage */
165
164
  disablePersistence?: boolean;
166
165
  }
167
- declare function ThemeProvider({ children, defaultMode, colorScheme: colorSchemeProp, config: configOverride, disablePersistence, }: ThemeProviderProps): React__default.JSX.Element;
166
+ declare function ThemeProvider({ children, defaultMode, colorScheme, config: configOverride, disablePersistence, }: ThemeProviderProps): React__default.JSX.Element;
168
167
 
169
168
  type ToggleVariant = 'button' | 'switch' | 'icon-button';
170
169
  interface ThemeToggleProps {
package/dist/index.js CHANGED
@@ -2065,11 +2065,6 @@ function subscribeGlobalDarkMode(callback) {
2065
2065
 
2066
2066
  // src/ThemeProvider.tsx
2067
2067
  var import_jsx_runtime = require("react/jsx-runtime");
2068
- var _useColorScheme;
2069
- try {
2070
- ({ useColorScheme: _useColorScheme } = require("react-native"));
2071
- } catch {
2072
- }
2073
2068
  var STORAGE_KEY = "kbach-theme";
2074
2069
  function loadPersistedMode() {
2075
2070
  try {
@@ -2098,23 +2093,20 @@ function applyWebTheme(resolvedMode, strategy) {
2098
2093
  function ThemeProvider({
2099
2094
  children,
2100
2095
  defaultMode = "system",
2101
- colorScheme: colorSchemeProp,
2096
+ colorScheme,
2102
2097
  config: configOverride,
2103
2098
  disablePersistence = false
2104
2099
  }) {
2105
2100
  const [resolvedConfig, setResolvedConfig] = (0, import_react2.useState)(
2106
2101
  () => configOverride ? buildConfig(configOverride) : getConfig()
2107
2102
  );
2108
- const [nativeSchemeFallback, setNativeSchemeFallback] = (0, import_react2.useState)(null);
2109
- const hookScheme = _useColorScheme?.();
2110
- const nativeScheme = colorSchemeProp !== void 0 ? colorSchemeProp ?? null : hookScheme ?? nativeSchemeFallback;
2111
2103
  const [webScheme, setWebScheme] = (0, import_react2.useState)(() => {
2112
2104
  if (isWeb && typeof window !== "undefined") {
2113
2105
  return window.matchMedia?.("(prefers-color-scheme: dark)").matches ? "dark" : "light";
2114
2106
  }
2115
2107
  return "light";
2116
2108
  });
2117
- const systemScheme = isWeb ? webScheme : nativeScheme === "dark" ? "dark" : "light";
2109
+ const systemScheme = isWeb ? webScheme : colorScheme === "dark" ? "dark" : "light";
2118
2110
  const [mode, _setMode] = (0, import_react2.useState)(() => {
2119
2111
  if (!disablePersistence) {
2120
2112
  const persisted = loadPersistedMode();
@@ -2132,18 +2124,6 @@ function ThemeProvider({
2132
2124
  const resolvedMode = mode === "system" ? systemScheme : mode;
2133
2125
  const isDark = resolvedMode === "dark";
2134
2126
  syncGlobalDarkMode(isDark);
2135
- (0, import_react2.useEffect)(() => {
2136
- if (isWeb) return;
2137
- try {
2138
- const { TurboModuleRegistry } = require("react-native");
2139
- const native = TurboModuleRegistry?.get?.("Appearance");
2140
- const scheme = native?.getColorScheme?.();
2141
- if (scheme === "dark" || scheme === "light") {
2142
- setNativeSchemeFallback(scheme);
2143
- }
2144
- } catch {
2145
- }
2146
- }, []);
2147
2127
  (0, import_react2.useEffect)(() => {
2148
2128
  applyWebTheme(resolvedMode, resolvedConfig.darkMode);
2149
2129
  setGlobalDarkMode(isDark);
package/dist/index.mjs CHANGED
@@ -39,11 +39,6 @@ import {
39
39
  useState
40
40
  } from "react";
41
41
  import { jsx } from "react/jsx-runtime";
42
- var _useColorScheme;
43
- try {
44
- ({ useColorScheme: _useColorScheme } = __require("react-native"));
45
- } catch {
46
- }
47
42
  var STORAGE_KEY = "kbach-theme";
48
43
  function loadPersistedMode() {
49
44
  try {
@@ -72,23 +67,20 @@ function applyWebTheme(resolvedMode, strategy) {
72
67
  function ThemeProvider({
73
68
  children,
74
69
  defaultMode = "system",
75
- colorScheme: colorSchemeProp,
70
+ colorScheme,
76
71
  config: configOverride,
77
72
  disablePersistence = false
78
73
  }) {
79
74
  const [resolvedConfig, setResolvedConfig] = useState(
80
75
  () => configOverride ? buildConfig(configOverride) : getConfig()
81
76
  );
82
- const [nativeSchemeFallback, setNativeSchemeFallback] = useState(null);
83
- const hookScheme = _useColorScheme?.();
84
- const nativeScheme = colorSchemeProp !== void 0 ? colorSchemeProp ?? null : hookScheme ?? nativeSchemeFallback;
85
77
  const [webScheme, setWebScheme] = useState(() => {
86
78
  if (isWeb && typeof window !== "undefined") {
87
79
  return window.matchMedia?.("(prefers-color-scheme: dark)").matches ? "dark" : "light";
88
80
  }
89
81
  return "light";
90
82
  });
91
- const systemScheme = isWeb ? webScheme : nativeScheme === "dark" ? "dark" : "light";
83
+ const systemScheme = isWeb ? webScheme : colorScheme === "dark" ? "dark" : "light";
92
84
  const [mode, _setMode] = useState(() => {
93
85
  if (!disablePersistence) {
94
86
  const persisted = loadPersistedMode();
@@ -106,18 +98,6 @@ function ThemeProvider({
106
98
  const resolvedMode = mode === "system" ? systemScheme : mode;
107
99
  const isDark = resolvedMode === "dark";
108
100
  syncGlobalDarkMode(isDark);
109
- useEffect(() => {
110
- if (isWeb) return;
111
- try {
112
- const { TurboModuleRegistry } = __require("react-native");
113
- const native = TurboModuleRegistry?.get?.("Appearance");
114
- const scheme = native?.getColorScheme?.();
115
- if (scheme === "dark" || scheme === "light") {
116
- setNativeSchemeFallback(scheme);
117
- }
118
- } catch {
119
- }
120
- }, []);
121
101
  useEffect(() => {
122
102
  applyWebTheme(resolvedMode, resolvedConfig.darkMode);
123
103
  setGlobalDarkMode(isDark);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kbach/react",
3
- "version": "0.2.4",
3
+ "version": "0.2.5",
4
4
  "description": "React / React Native components and hooks for the Kbach framework",
5
5
  "source": "./src/index.ts",
6
6
  "main": "./dist/index.js",