@gv-tech/ui-native 2.25.0 → 2.25.2
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/hooks/use-theme.d.ts +0 -1
- package/dist/hooks/use-theme.d.ts.map +1 -1
- package/dist/theme-provider.d.ts +5 -3
- package/dist/theme-provider.d.ts.map +1 -1
- package/dist/theme-toggle.d.ts.map +1 -1
- package/dist/ui-native.cjs +2 -2
- package/dist/ui-native.esm.js +926 -926
- package/package.json +1 -1
- package/src/hooks/use-theme.ts +2 -3
- package/src/theme-provider.tsx +20 -5
- package/src/theme-toggle.tsx +12 -7
package/package.json
CHANGED
package/src/hooks/use-theme.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { theme as designTokens } from '@gv-tech/design-tokens';
|
|
2
|
-
import { useColorScheme } from '
|
|
2
|
+
import { useColorScheme } from 'react-native';
|
|
3
3
|
|
|
4
4
|
export function useTheme() {
|
|
5
|
-
const
|
|
5
|
+
const colorScheme = useColorScheme();
|
|
6
6
|
|
|
7
7
|
const resolvedTheme = colorScheme as 'light' | 'dark';
|
|
8
8
|
|
|
@@ -11,7 +11,6 @@ export function useTheme() {
|
|
|
11
11
|
|
|
12
12
|
return {
|
|
13
13
|
theme: colorScheme,
|
|
14
|
-
setTheme: setColorScheme,
|
|
15
14
|
resolvedTheme,
|
|
16
15
|
tokens: activeTokens,
|
|
17
16
|
};
|
package/src/theme-provider.tsx
CHANGED
|
@@ -1,9 +1,24 @@
|
|
|
1
|
-
import { useColorScheme } from 'nativewind';
|
|
2
1
|
import * as React from 'react';
|
|
3
|
-
import { View } from 'react-native';
|
|
2
|
+
import { View, ViewProps } from 'react-native';
|
|
3
|
+
import { useTheme } from './hooks/use-theme';
|
|
4
4
|
import { cn } from './lib/utils';
|
|
5
5
|
|
|
6
|
-
export
|
|
7
|
-
|
|
8
|
-
|
|
6
|
+
export interface ThemeProviderProps extends ViewProps {
|
|
7
|
+
children: React.ReactNode;
|
|
8
|
+
[key: string]: unknown;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export function ThemeProvider({ children, className, style, ...props }: ThemeProviderProps) {
|
|
12
|
+
const { theme, tokens } = useTheme();
|
|
13
|
+
const isDark = theme === 'dark';
|
|
14
|
+
|
|
15
|
+
return (
|
|
16
|
+
<View
|
|
17
|
+
className={cn('flex-1', isDark ? 'dark' : '', className)}
|
|
18
|
+
style={[{ backgroundColor: tokens.background }, style]}
|
|
19
|
+
{...props}
|
|
20
|
+
>
|
|
21
|
+
{children}
|
|
22
|
+
</View>
|
|
23
|
+
);
|
|
9
24
|
}
|
package/src/theme-toggle.tsx
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ThemeToggleBaseProps } from '@gv-tech/ui-core';
|
|
2
2
|
import { Moon, Sun, SunMoon } from 'lucide-react-native';
|
|
3
|
-
import { View } from 'react-native';
|
|
3
|
+
import { Appearance, View } from 'react-native';
|
|
4
4
|
import { Button } from './button';
|
|
5
5
|
import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger } from './dropdown-menu';
|
|
6
6
|
import { useTheme } from './hooks/use-theme';
|
|
@@ -15,12 +15,12 @@ iconWithClassName(SunMoon);
|
|
|
15
15
|
export type ThemeToggleProps = ThemeToggleBaseProps;
|
|
16
16
|
|
|
17
17
|
export function ThemeToggle({ variant = 'binary', onThemeChange, customTheme, className }: ThemeToggleProps) {
|
|
18
|
-
const { theme,
|
|
18
|
+
const { theme, resolvedTheme } = useTheme();
|
|
19
19
|
|
|
20
20
|
const currentTheme = (customTheme ?? theme) as 'light' | 'dark' | 'system';
|
|
21
21
|
|
|
22
22
|
// Determine the effective theme for icon rendering
|
|
23
|
-
const effectiveTheme = customTheme
|
|
23
|
+
const effectiveTheme = customTheme === 'system' || !customTheme ? resolvedTheme : customTheme;
|
|
24
24
|
const isDark = effectiveTheme === 'dark';
|
|
25
25
|
const isSystem = currentTheme === 'system';
|
|
26
26
|
|
|
@@ -28,7 +28,12 @@ export function ThemeToggle({ variant = 'binary', onThemeChange, customTheme, cl
|
|
|
28
28
|
if (onThemeChange) {
|
|
29
29
|
onThemeChange(newTheme);
|
|
30
30
|
} else {
|
|
31
|
-
|
|
31
|
+
if (newTheme === 'system') {
|
|
32
|
+
// @ts-expect-error React Native Appearance.setColorScheme accepts null to reset to system theme
|
|
33
|
+
Appearance.setColorScheme(null);
|
|
34
|
+
} else {
|
|
35
|
+
Appearance.setColorScheme(newTheme);
|
|
36
|
+
}
|
|
32
37
|
}
|
|
33
38
|
};
|
|
34
39
|
|
|
@@ -37,7 +42,7 @@ export function ThemeToggle({ variant = 'binary', onThemeChange, customTheme, cl
|
|
|
37
42
|
<View
|
|
38
43
|
className={cn(
|
|
39
44
|
'items-center justify-center transition-all',
|
|
40
|
-
!isSystem && !isDark ? '
|
|
45
|
+
!isSystem && !isDark ? 'rotate-0 opacity-100' : 'absolute -rotate-90 opacity-0',
|
|
41
46
|
)}
|
|
42
47
|
>
|
|
43
48
|
<Sun size={18} className="text-foreground" />
|
|
@@ -45,7 +50,7 @@ export function ThemeToggle({ variant = 'binary', onThemeChange, customTheme, cl
|
|
|
45
50
|
<View
|
|
46
51
|
className={cn(
|
|
47
52
|
'items-center justify-center transition-all',
|
|
48
|
-
!isSystem && isDark ? '
|
|
53
|
+
!isSystem && isDark ? 'rotate-0 opacity-100' : 'absolute rotate-90 opacity-0',
|
|
49
54
|
)}
|
|
50
55
|
>
|
|
51
56
|
<Moon size={18} className="text-foreground" />
|
|
@@ -53,7 +58,7 @@ export function ThemeToggle({ variant = 'binary', onThemeChange, customTheme, cl
|
|
|
53
58
|
<View
|
|
54
59
|
className={cn(
|
|
55
60
|
'items-center justify-center transition-all',
|
|
56
|
-
isSystem ? '
|
|
61
|
+
isSystem ? 'rotate-0 opacity-100' : 'absolute rotate-90 opacity-0',
|
|
57
62
|
)}
|
|
58
63
|
>
|
|
59
64
|
<SunMoon size={18} className="text-foreground" />
|