@react-native-reusables/cli 0.0.14 → 0.0.15
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/__generated/components/primitives/portal.tsx +27 -12
- package/__generated/components/ui/alert-dialog.tsx +3 -3
- package/__generated/components/ui/context-menu.tsx +4 -3
- package/__generated/components/ui/dialog.tsx +3 -3
- package/__generated/components/ui/dropdown-menu.tsx +4 -3
- package/__generated/components/ui/menubar.tsx +3 -3
- package/__generated/components/ui/navigation-menu.tsx +5 -3
- package/__generated/components/ui/popover.tsx +3 -3
- package/__generated/components/ui/select.tsx +3 -3
- package/__generated/components/ui/tooltip.tsx +3 -3
- package/package.json +1 -1
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
+
import { Platform, type View, type ViewStyle } from 'react-native';
|
|
2
3
|
import { create } from 'zustand';
|
|
3
4
|
|
|
4
5
|
const DEFAULT_PORTAL_HOST = 'INTERNAL_PRIMITIVE_DEFAULT_HOST_NAME';
|
|
@@ -7,17 +8,10 @@ type PortalMap = Map<string, React.ReactNode>;
|
|
|
7
8
|
type PortalHostMap = Map<string, PortalMap>;
|
|
8
9
|
|
|
9
10
|
const usePortal = create<{ map: PortalHostMap }>(() => ({
|
|
10
|
-
map: new Map<string, PortalMap>().set(
|
|
11
|
-
DEFAULT_PORTAL_HOST,
|
|
12
|
-
new Map<string, React.ReactNode>()
|
|
13
|
-
),
|
|
11
|
+
map: new Map<string, PortalMap>().set(DEFAULT_PORTAL_HOST, new Map<string, React.ReactNode>()),
|
|
14
12
|
}));
|
|
15
13
|
|
|
16
|
-
const updatePortal = (
|
|
17
|
-
hostName: string,
|
|
18
|
-
name: string,
|
|
19
|
-
children: React.ReactNode
|
|
20
|
-
) => {
|
|
14
|
+
const updatePortal = (hostName: string, name: string, children: React.ReactNode) => {
|
|
21
15
|
usePortal.setState((prev) => {
|
|
22
16
|
const next = new Map(prev.map);
|
|
23
17
|
const portal = next.get(hostName) ?? new Map<string, React.ReactNode>();
|
|
@@ -37,9 +31,7 @@ const removePortal = (hostName: string, name: string) => {
|
|
|
37
31
|
};
|
|
38
32
|
|
|
39
33
|
export function PortalHost({ name = DEFAULT_PORTAL_HOST }: { name?: string }) {
|
|
40
|
-
const portalMap =
|
|
41
|
-
usePortal((state) => state.map).get(name) ??
|
|
42
|
-
new Map<string, React.ReactNode>();
|
|
34
|
+
const portalMap = usePortal((state) => state.map).get(name) ?? new Map<string, React.ReactNode>();
|
|
43
35
|
if (portalMap.size === 0) return null;
|
|
44
36
|
return <>{Array.from(portalMap.values())}</>;
|
|
45
37
|
}
|
|
@@ -65,3 +57,26 @@ export function Portal({
|
|
|
65
57
|
|
|
66
58
|
return null;
|
|
67
59
|
}
|
|
60
|
+
|
|
61
|
+
const ROOT: ViewStyle = {
|
|
62
|
+
flex: 1,
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
export function useModalPortalRoot() {
|
|
66
|
+
const ref = React.useRef<View>(null);
|
|
67
|
+
const [sideOffset, setSideOffSet] = React.useState(0);
|
|
68
|
+
|
|
69
|
+
const onLayout = React.useCallback(() => {
|
|
70
|
+
if (Platform.OS === 'web') return;
|
|
71
|
+
ref.current?.measure((_x, _y, _width, _height, _pageX, pageY) => {
|
|
72
|
+
setSideOffSet(-pageY);
|
|
73
|
+
});
|
|
74
|
+
}, []);
|
|
75
|
+
|
|
76
|
+
return {
|
|
77
|
+
ref,
|
|
78
|
+
sideOffset,
|
|
79
|
+
onLayout,
|
|
80
|
+
style: ROOT,
|
|
81
|
+
};
|
|
82
|
+
}
|
|
@@ -61,12 +61,12 @@ const AlertDialogOverlay = Platform.select({
|
|
|
61
61
|
|
|
62
62
|
const AlertDialogContent = React.forwardRef<
|
|
63
63
|
React.ElementRef<typeof AlertDialogPrimitive.Content>,
|
|
64
|
-
React.ComponentPropsWithoutRef<typeof AlertDialogPrimitive.Content>
|
|
65
|
-
>(({ className, ...props }, ref) => {
|
|
64
|
+
React.ComponentPropsWithoutRef<typeof AlertDialogPrimitive.Content> & { portalHost?: string }
|
|
65
|
+
>(({ className, portalHost, ...props }, ref) => {
|
|
66
66
|
const { open } = AlertDialogPrimitive.useRootContext();
|
|
67
67
|
|
|
68
68
|
return (
|
|
69
|
-
<AlertDialogPortal>
|
|
69
|
+
<AlertDialogPortal hostName={portalHost}>
|
|
70
70
|
<AlertDialogOverlay>
|
|
71
71
|
<AlertDialogPrimitive.Content
|
|
72
72
|
ref={ref}
|
|
@@ -76,18 +76,19 @@ const ContextMenuContent = React.forwardRef<
|
|
|
76
76
|
React.ComponentPropsWithoutRef<typeof ContextMenuPrimitive.Content> & {
|
|
77
77
|
overlayStyle?: StyleProp<ViewStyle>;
|
|
78
78
|
overlayClassName?: string;
|
|
79
|
+
portalHost?: string;
|
|
79
80
|
}
|
|
80
|
-
>(({ className, overlayClassName, overlayStyle, ...props }, ref) => {
|
|
81
|
+
>(({ className, overlayClassName, overlayStyle, portalHost, ...props }, ref) => {
|
|
81
82
|
const { open } = ContextMenuPrimitive.useRootContext();
|
|
82
83
|
return (
|
|
83
|
-
<ContextMenuPrimitive.Portal>
|
|
84
|
+
<ContextMenuPrimitive.Portal hostName={portalHost}>
|
|
84
85
|
<ContextMenuPrimitive.Overlay
|
|
85
86
|
style={
|
|
86
87
|
overlayStyle
|
|
87
88
|
? StyleSheet.flatten([
|
|
88
89
|
Platform.OS !== 'web' ? StyleSheet.absoluteFill : undefined,
|
|
89
90
|
overlayStyle,
|
|
90
|
-
])
|
|
91
|
+
] as ViewStyle)
|
|
91
92
|
: Platform.OS !== 'web'
|
|
92
93
|
? StyleSheet.absoluteFill
|
|
93
94
|
: undefined
|
|
@@ -61,11 +61,11 @@ const DialogOverlay = Platform.select({
|
|
|
61
61
|
|
|
62
62
|
const DialogContent = React.forwardRef<
|
|
63
63
|
React.ElementRef<typeof DialogPrimitive.Content>,
|
|
64
|
-
React.ComponentPropsWithoutRef<typeof DialogPrimitive.Content>
|
|
65
|
-
>(({ className, children, ...props }, ref) => {
|
|
64
|
+
React.ComponentPropsWithoutRef<typeof DialogPrimitive.Content> & { portalHost?: string }
|
|
65
|
+
>(({ className, children, portalHost, ...props }, ref) => {
|
|
66
66
|
const { open } = DialogPrimitive.useRootContext();
|
|
67
67
|
return (
|
|
68
|
-
<DialogPortal>
|
|
68
|
+
<DialogPortal hostName={portalHost}>
|
|
69
69
|
<DialogOverlay>
|
|
70
70
|
<DialogPrimitive.Content
|
|
71
71
|
ref={ref}
|
|
@@ -76,18 +76,19 @@ const DropdownMenuContent = React.forwardRef<
|
|
|
76
76
|
React.ComponentPropsWithoutRef<typeof DropdownMenuPrimitive.Content> & {
|
|
77
77
|
overlayStyle?: StyleProp<ViewStyle>;
|
|
78
78
|
overlayClassName?: string;
|
|
79
|
+
portalHost?: string;
|
|
79
80
|
}
|
|
80
|
-
>(({ className, overlayClassName, overlayStyle, ...props }, ref) => {
|
|
81
|
+
>(({ className, overlayClassName, overlayStyle, portalHost, ...props }, ref) => {
|
|
81
82
|
const { open } = DropdownMenuPrimitive.useRootContext();
|
|
82
83
|
return (
|
|
83
|
-
<DropdownMenuPrimitive.Portal>
|
|
84
|
+
<DropdownMenuPrimitive.Portal hostName={portalHost}>
|
|
84
85
|
<DropdownMenuPrimitive.Overlay
|
|
85
86
|
style={
|
|
86
87
|
overlayStyle
|
|
87
88
|
? StyleSheet.flatten([
|
|
88
89
|
Platform.OS !== 'web' ? StyleSheet.absoluteFill : undefined,
|
|
89
90
|
overlayStyle,
|
|
90
|
-
])
|
|
91
|
+
] as ViewStyle)
|
|
91
92
|
: Platform.OS !== 'web'
|
|
92
93
|
? StyleSheet.absoluteFill
|
|
93
94
|
: undefined
|
|
@@ -107,12 +107,12 @@ MenubarSubContent.displayName = MenubarPrimitive.SubContent.displayName;
|
|
|
107
107
|
|
|
108
108
|
const MenubarContent = React.forwardRef<
|
|
109
109
|
React.ElementRef<typeof MenubarPrimitive.Content>,
|
|
110
|
-
React.ComponentPropsWithoutRef<typeof MenubarPrimitive.Content>
|
|
111
|
-
>(({ className, ...props }, ref) => {
|
|
110
|
+
React.ComponentPropsWithoutRef<typeof MenubarPrimitive.Content> & { portalHost?: string }
|
|
111
|
+
>(({ className, portalHost, ...props }, ref) => {
|
|
112
112
|
const { value } = MenubarPrimitive.useRootContext();
|
|
113
113
|
const { value: itemValue } = MenubarPrimitive.useMenuContext();
|
|
114
114
|
return (
|
|
115
|
-
<MenubarPrimitive.Portal>
|
|
115
|
+
<MenubarPrimitive.Portal hostName={portalHost}>
|
|
116
116
|
<MenubarPrimitive.Content
|
|
117
117
|
ref={ref}
|
|
118
118
|
className={cn(
|
|
@@ -91,12 +91,14 @@ NavigationMenuTrigger.displayName = NavigationMenuPrimitive.Trigger.displayName;
|
|
|
91
91
|
|
|
92
92
|
const NavigationMenuContent = React.forwardRef<
|
|
93
93
|
React.ElementRef<typeof NavigationMenuPrimitive.Content>,
|
|
94
|
-
React.ComponentPropsWithoutRef<typeof NavigationMenuPrimitive.Content>
|
|
95
|
-
|
|
94
|
+
React.ComponentPropsWithoutRef<typeof NavigationMenuPrimitive.Content> & {
|
|
95
|
+
portalHost?: string;
|
|
96
|
+
}
|
|
97
|
+
>(({ className, children, portalHost, ...props }, ref) => {
|
|
96
98
|
const { value } = NavigationMenuPrimitive.useRootContext();
|
|
97
99
|
const { value: itemValue } = NavigationMenuPrimitive.useItemContext();
|
|
98
100
|
return (
|
|
99
|
-
<NavigationMenuPrimitive.Portal>
|
|
101
|
+
<NavigationMenuPrimitive.Portal hostName={portalHost}>
|
|
100
102
|
<NavigationMenuPrimitive.Content
|
|
101
103
|
ref={ref}
|
|
102
104
|
className={cn(
|
|
@@ -11,10 +11,10 @@ const PopoverTrigger = PopoverPrimitive.Trigger;
|
|
|
11
11
|
|
|
12
12
|
const PopoverContent = React.forwardRef<
|
|
13
13
|
React.ElementRef<typeof PopoverPrimitive.Content>,
|
|
14
|
-
React.ComponentPropsWithoutRef<typeof PopoverPrimitive.Content>
|
|
15
|
-
>(({ className, align = 'center', sideOffset = 4, ...props }, ref) => {
|
|
14
|
+
React.ComponentPropsWithoutRef<typeof PopoverPrimitive.Content> & { portalHost?: string }
|
|
15
|
+
>(({ className, align = 'center', sideOffset = 4, portalHost, ...props }, ref) => {
|
|
16
16
|
return (
|
|
17
|
-
<PopoverPrimitive.Portal>
|
|
17
|
+
<PopoverPrimitive.Portal hostName={portalHost}>
|
|
18
18
|
<PopoverPrimitive.Overlay style={Platform.OS !== 'web' ? StyleSheet.absoluteFill : undefined}>
|
|
19
19
|
<Animated.View entering={FadeIn.duration(200)} exiting={FadeOut}>
|
|
20
20
|
<TextClassContext.Provider value='text-popover-foreground'>
|
|
@@ -74,12 +74,12 @@ const SelectScrollDownButton = ({
|
|
|
74
74
|
|
|
75
75
|
const SelectContent = React.forwardRef<
|
|
76
76
|
React.ElementRef<typeof SelectPrimitive.Content>,
|
|
77
|
-
React.ComponentPropsWithoutRef<typeof SelectPrimitive.Content>
|
|
78
|
-
>(({ className, children, position = 'popper', ...props }, ref) => {
|
|
77
|
+
React.ComponentPropsWithoutRef<typeof SelectPrimitive.Content> & { portalHost?: string }
|
|
78
|
+
>(({ className, children, position = 'popper', portalHost, ...props }, ref) => {
|
|
79
79
|
const { open } = SelectPrimitive.useRootContext();
|
|
80
80
|
|
|
81
81
|
return (
|
|
82
|
-
<SelectPrimitive.Portal>
|
|
82
|
+
<SelectPrimitive.Portal hostName={portalHost}>
|
|
83
83
|
<SelectPrimitive.Overlay style={Platform.OS !== 'web' ? StyleSheet.absoluteFill : undefined}>
|
|
84
84
|
<Animated.View entering={FadeIn} exiting={FadeOut}>
|
|
85
85
|
<SelectPrimitive.Content
|
|
@@ -11,9 +11,9 @@ const TooltipTrigger = TooltipPrimitive.Trigger;
|
|
|
11
11
|
|
|
12
12
|
const TooltipContent = React.forwardRef<
|
|
13
13
|
React.ElementRef<typeof TooltipPrimitive.Content>,
|
|
14
|
-
React.ComponentPropsWithoutRef<typeof TooltipPrimitive.Content>
|
|
15
|
-
>(({ className, sideOffset = 4, ...props }, ref) => (
|
|
16
|
-
<TooltipPrimitive.Portal>
|
|
14
|
+
React.ComponentPropsWithoutRef<typeof TooltipPrimitive.Content> & { portalHost?: string }
|
|
15
|
+
>(({ className, sideOffset = 4, portalHost, ...props }, ref) => (
|
|
16
|
+
<TooltipPrimitive.Portal hostName={portalHost}>
|
|
17
17
|
<TooltipPrimitive.Overlay style={Platform.OS !== 'web' ? StyleSheet.absoluteFill : undefined}>
|
|
18
18
|
<Animated.View entering={FadeIn} exiting={FadeOut}>
|
|
19
19
|
<TextClassContext.Provider value='text-sm native:text-base text-popover-foreground'>
|