@gv-tech/ui-native 2.22.0 → 2.22.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.
- package/dist/dropdown-menu.d.ts.map +1 -1
- package/dist/hooks/use-theme.d.ts +49 -0
- package/dist/hooks/use-theme.d.ts.map +1 -0
- package/dist/hooks/use-theme.test.d.ts +2 -0
- package/dist/hooks/use-theme.test.d.ts.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.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.mjs +409 -396
- package/package.json +1 -1
- package/src/dropdown-menu.tsx +2 -1
- package/src/hooks/use-theme.ts +18 -0
- package/src/index.ts +1 -0
- package/src/theme-toggle.tsx +10 -9
package/package.json
CHANGED
package/src/dropdown-menu.tsx
CHANGED
|
@@ -77,10 +77,11 @@ DropdownMenuContent.displayName = 'DropdownMenuContent';
|
|
|
77
77
|
export const DropdownMenuItem = React.forwardRef<
|
|
78
78
|
React.ElementRef<typeof DropdownMenuPrimitive.Item>,
|
|
79
79
|
DropdownMenuItemBaseProps
|
|
80
|
-
>(({ className, children, inset, ...props }, ref) => {
|
|
80
|
+
>(({ className, children, inset, onSelect, ...props }, ref) => {
|
|
81
81
|
return (
|
|
82
82
|
<DropdownMenuPrimitive.Item
|
|
83
83
|
ref={ref}
|
|
84
|
+
onPress={() => onSelect?.(new Event('select'))}
|
|
84
85
|
className={cn(
|
|
85
86
|
'focus:bg-accent focus:text-accent-foreground active:bg-accent active:text-accent-foreground relative flex flex-row items-center rounded-sm px-2 py-1.5 text-sm outline-none',
|
|
86
87
|
inset && 'pl-8',
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { theme as designTokens } from '@gv-tech/design-tokens';
|
|
2
|
+
import { useColorScheme } from 'nativewind';
|
|
3
|
+
|
|
4
|
+
export function useTheme() {
|
|
5
|
+
const { colorScheme, setColorScheme } = useColorScheme();
|
|
6
|
+
|
|
7
|
+
const resolvedTheme = colorScheme as 'light' | 'dark';
|
|
8
|
+
|
|
9
|
+
// Default to light theme tokens if resolvedTheme is dark or invalid
|
|
10
|
+
const activeTokens = resolvedTheme === 'dark' ? designTokens.dark : designTokens.light;
|
|
11
|
+
|
|
12
|
+
return {
|
|
13
|
+
theme: colorScheme,
|
|
14
|
+
setTheme: setColorScheme,
|
|
15
|
+
resolvedTheme,
|
|
16
|
+
tokens: activeTokens,
|
|
17
|
+
};
|
|
18
|
+
}
|
package/src/index.ts
CHANGED
package/src/theme-toggle.tsx
CHANGED
|
@@ -1,28 +1,29 @@
|
|
|
1
1
|
import { ThemeToggleBaseProps } from '@gv-tech/ui-core';
|
|
2
2
|
import { Moon, Sun, SunMoon } from 'lucide-react-native';
|
|
3
|
-
import { useColorScheme } from 'nativewind';
|
|
4
3
|
import { View } from 'react-native';
|
|
5
4
|
import { Button } from './button';
|
|
6
5
|
import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger } from './dropdown-menu';
|
|
6
|
+
import { useTheme } from './hooks/use-theme';
|
|
7
7
|
import { cn } from './lib/utils';
|
|
8
8
|
import { Text } from './text';
|
|
9
9
|
|
|
10
10
|
export type ThemeToggleProps = ThemeToggleBaseProps;
|
|
11
11
|
|
|
12
12
|
export function ThemeToggle({ variant = 'binary', onThemeChange, customTheme, className }: ThemeToggleProps) {
|
|
13
|
-
const {
|
|
13
|
+
const { theme, setTheme, resolvedTheme } = useTheme();
|
|
14
14
|
|
|
15
|
-
const currentTheme = (customTheme ??
|
|
15
|
+
const currentTheme = (customTheme ?? theme) as 'light' | 'dark' | 'system';
|
|
16
16
|
|
|
17
|
-
// Determine
|
|
18
|
-
const
|
|
17
|
+
// Determine the effective theme for icon rendering
|
|
18
|
+
const effectiveTheme = customTheme ? customTheme : resolvedTheme;
|
|
19
|
+
const isDark = effectiveTheme === 'dark';
|
|
19
20
|
const isSystem = currentTheme === 'system';
|
|
20
21
|
|
|
21
22
|
const handleThemeChange = (newTheme: 'light' | 'dark' | 'system') => {
|
|
22
23
|
if (onThemeChange) {
|
|
23
24
|
onThemeChange(newTheme);
|
|
24
25
|
} else {
|
|
25
|
-
|
|
26
|
+
setTheme(newTheme);
|
|
26
27
|
}
|
|
27
28
|
};
|
|
28
29
|
|
|
@@ -61,15 +62,15 @@ export function ThemeToggle({ variant = 'binary', onThemeChange, customTheme, cl
|
|
|
61
62
|
</Button>
|
|
62
63
|
</DropdownMenuTrigger>
|
|
63
64
|
<DropdownMenuContent align="end">
|
|
64
|
-
<DropdownMenuItem
|
|
65
|
+
<DropdownMenuItem onSelect={() => handleThemeChange('light')}>
|
|
65
66
|
<Sun size={14} className="text-foreground mr-2" />
|
|
66
67
|
<Text>Light</Text>
|
|
67
68
|
</DropdownMenuItem>
|
|
68
|
-
<DropdownMenuItem
|
|
69
|
+
<DropdownMenuItem onSelect={() => handleThemeChange('dark')}>
|
|
69
70
|
<Moon size={14} className="text-foreground mr-2" />
|
|
70
71
|
<Text>Dark</Text>
|
|
71
72
|
</DropdownMenuItem>
|
|
72
|
-
<DropdownMenuItem
|
|
73
|
+
<DropdownMenuItem onSelect={() => handleThemeChange('system')}>
|
|
73
74
|
<SunMoon size={14} className="text-foreground mr-2" />
|
|
74
75
|
<Text>System</Text>
|
|
75
76
|
</DropdownMenuItem>
|