@gv-tech/ui-native 2.25.2 → 2.25.3
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 +30 -30
- package/dist/hooks/use-theme.d.ts.map +1 -1
- package/dist/theme-provider.d.ts +9 -1
- 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 +1013 -997
- package/package.json +2 -1
- package/src/dropdown-menu.tsx +18 -0
- package/src/hooks/use-theme.ts +7 -0
- package/src/theme-provider.tsx +36 -12
- package/src/theme-toggle.tsx +7 -4
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gv-tech/ui-native",
|
|
3
|
-
"version": "2.25.
|
|
3
|
+
"version": "2.25.3",
|
|
4
4
|
"description": "React Native implementations of the GV Tech design system components",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -37,6 +37,7 @@
|
|
|
37
37
|
"@gv-tech/design-tokens": "^2.12.0",
|
|
38
38
|
"@gv-tech/ui-core": "^2.12.0",
|
|
39
39
|
"@react-native-community/datetimepicker": "^9.1.0",
|
|
40
|
+
"@radix-ui/react-dropdown-menu": "^2.1.16",
|
|
40
41
|
"@rn-primitives/accordion": "^1.2.0",
|
|
41
42
|
"@rn-primitives/alert-dialog": "^1.2.0",
|
|
42
43
|
"@rn-primitives/aspect-ratio": "^1.2.0",
|
package/src/dropdown-menu.tsx
CHANGED
|
@@ -9,6 +9,7 @@ import type {
|
|
|
9
9
|
DropdownMenuSubContentBaseProps,
|
|
10
10
|
DropdownMenuSubTriggerBaseProps,
|
|
11
11
|
} from '@gv-tech/ui-core';
|
|
12
|
+
import * as RadixDropdownMenu from '@radix-ui/react-dropdown-menu';
|
|
12
13
|
import * as DropdownMenuPrimitive from '@rn-primitives/dropdown-menu';
|
|
13
14
|
import { Check, ChevronRight, Circle } from 'lucide-react-native';
|
|
14
15
|
import * as React from 'react';
|
|
@@ -78,6 +79,23 @@ export const DropdownMenuItem = React.forwardRef<
|
|
|
78
79
|
React.ComponentRef<typeof DropdownMenuPrimitive.Item>,
|
|
79
80
|
DropdownMenuItemBaseProps
|
|
80
81
|
>(({ className, children, inset, onSelect, ...props }, ref) => {
|
|
82
|
+
if (Platform.OS === 'web') {
|
|
83
|
+
return (
|
|
84
|
+
<RadixDropdownMenu.Item
|
|
85
|
+
ref={ref as React.Ref<HTMLDivElement>}
|
|
86
|
+
onSelect={onSelect}
|
|
87
|
+
className={cn(
|
|
88
|
+
'focus:bg-accent focus:text-accent-foreground active:bg-accent active:text-accent-foreground relative flex cursor-default flex-row items-center rounded-sm px-2 py-1.5 text-sm outline-none select-none',
|
|
89
|
+
inset && 'pl-8',
|
|
90
|
+
className,
|
|
91
|
+
)}
|
|
92
|
+
{...props}
|
|
93
|
+
>
|
|
94
|
+
{children}
|
|
95
|
+
</RadixDropdownMenu.Item>
|
|
96
|
+
);
|
|
97
|
+
}
|
|
98
|
+
|
|
81
99
|
return (
|
|
82
100
|
<DropdownMenuPrimitive.Item
|
|
83
101
|
ref={ref}
|
package/src/hooks/use-theme.ts
CHANGED
|
@@ -1,7 +1,14 @@
|
|
|
1
1
|
import { theme as designTokens } from '@gv-tech/design-tokens';
|
|
2
|
+
import * as React from 'react';
|
|
2
3
|
import { useColorScheme } from 'react-native';
|
|
4
|
+
import { ThemeContext } from '../theme-provider';
|
|
3
5
|
|
|
4
6
|
export function useTheme() {
|
|
7
|
+
const context = React.useContext(ThemeContext);
|
|
8
|
+
if (context) {
|
|
9
|
+
return context;
|
|
10
|
+
}
|
|
11
|
+
|
|
5
12
|
const colorScheme = useColorScheme();
|
|
6
13
|
|
|
7
14
|
const resolvedTheme = colorScheme as 'light' | 'dark';
|
package/src/theme-provider.tsx
CHANGED
|
@@ -1,24 +1,48 @@
|
|
|
1
|
+
import { theme as designTokens } from '@gv-tech/design-tokens';
|
|
1
2
|
import * as React from 'react';
|
|
2
|
-
import { View, ViewProps } from 'react-native';
|
|
3
|
-
import { useTheme } from './hooks/use-theme';
|
|
3
|
+
import { useColorScheme, View, ViewProps } from 'react-native';
|
|
4
4
|
import { cn } from './lib/utils';
|
|
5
5
|
|
|
6
|
+
export interface ThemeContextValue {
|
|
7
|
+
theme: 'light' | 'dark' | 'system';
|
|
8
|
+
resolvedTheme: 'light' | 'dark';
|
|
9
|
+
tokens: typeof designTokens.light | typeof designTokens.dark;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export const ThemeContext = React.createContext<ThemeContextValue | null>(null);
|
|
13
|
+
|
|
6
14
|
export interface ThemeProviderProps extends ViewProps {
|
|
7
15
|
children: React.ReactNode;
|
|
16
|
+
value?: 'light' | 'dark' | 'system';
|
|
8
17
|
[key: string]: unknown;
|
|
9
18
|
}
|
|
10
19
|
|
|
11
|
-
export function ThemeProvider({ children, className, style, ...props }: ThemeProviderProps) {
|
|
12
|
-
const
|
|
13
|
-
const
|
|
20
|
+
export function ThemeProvider({ children, className, style, value, ...props }: ThemeProviderProps) {
|
|
21
|
+
const systemScheme = useColorScheme();
|
|
22
|
+
const theme = value || 'system';
|
|
23
|
+
const resolvedTheme = theme === 'system' ? (systemScheme === 'dark' ? 'dark' : 'light') : theme;
|
|
24
|
+
const tokens = resolvedTheme === 'dark' ? designTokens.dark : designTokens.light;
|
|
25
|
+
|
|
26
|
+
const isDark = resolvedTheme === 'dark';
|
|
27
|
+
|
|
28
|
+
const contextValue = React.useMemo<ThemeContextValue>(
|
|
29
|
+
() => ({
|
|
30
|
+
theme,
|
|
31
|
+
resolvedTheme,
|
|
32
|
+
tokens,
|
|
33
|
+
}),
|
|
34
|
+
[theme, resolvedTheme, tokens],
|
|
35
|
+
);
|
|
14
36
|
|
|
15
37
|
return (
|
|
16
|
-
<
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
38
|
+
<ThemeContext.Provider value={contextValue}>
|
|
39
|
+
<View
|
|
40
|
+
className={cn('flex-1', isDark ? 'dark' : '', className)}
|
|
41
|
+
style={[{ backgroundColor: tokens.background }, style]}
|
|
42
|
+
{...props}
|
|
43
|
+
>
|
|
44
|
+
{children}
|
|
45
|
+
</View>
|
|
46
|
+
</ThemeContext.Provider>
|
|
23
47
|
);
|
|
24
48
|
}
|
package/src/theme-toggle.tsx
CHANGED
|
@@ -69,10 +69,13 @@ export function ThemeToggle({ variant = 'binary', onThemeChange, customTheme, cl
|
|
|
69
69
|
if (variant === 'ternary') {
|
|
70
70
|
return (
|
|
71
71
|
<DropdownMenu>
|
|
72
|
-
<DropdownMenuTrigger
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
72
|
+
<DropdownMenuTrigger
|
|
73
|
+
className={cn(
|
|
74
|
+
'relative h-9 w-9 flex-row items-center justify-center rounded-md bg-transparent transition-colors active:opacity-80',
|
|
75
|
+
className,
|
|
76
|
+
)}
|
|
77
|
+
>
|
|
78
|
+
<IconToggle />
|
|
76
79
|
</DropdownMenuTrigger>
|
|
77
80
|
<DropdownMenuContent align="end">
|
|
78
81
|
<DropdownMenuItem onSelect={() => handleThemeChange('light')}>
|