@react-native-reusables/cli 0.0.18 → 0.1.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/README.md +2 -37
- package/__generated/components/ui/accordion.tsx +30 -32
- package/__generated/components/ui/alert-dialog.tsx +19 -26
- package/__generated/components/ui/aspect-ratio.tsx +1 -1
- package/__generated/components/ui/avatar.tsx +31 -34
- package/__generated/components/ui/badge.tsx +2 -2
- package/__generated/components/ui/button.tsx +2 -5
- package/__generated/components/ui/card.tsx +39 -51
- package/__generated/components/ui/checkbox.tsx +25 -27
- package/__generated/components/ui/collapsible.tsx +1 -1
- package/__generated/components/ui/context-menu.tsx +28 -31
- package/__generated/components/ui/dialog.tsx +40 -43
- package/__generated/components/ui/dropdown-menu.tsx +27 -22
- package/__generated/components/ui/hover-card.tsx +3 -3
- package/__generated/components/ui/input.tsx +17 -18
- package/__generated/components/ui/label.tsx +21 -22
- package/__generated/components/ui/menubar.tsx +45 -47
- package/__generated/components/ui/navigation-menu.tsx +19 -17
- package/__generated/components/ui/popover.tsx +4 -4
- package/__generated/components/ui/progress.tsx +15 -11
- package/__generated/components/ui/radio-group.tsx +27 -29
- package/__generated/components/ui/select.tsx +55 -65
- package/__generated/components/ui/separator.tsx +16 -17
- package/__generated/components/ui/switch.tsx +59 -61
- package/__generated/components/ui/table.tsx +69 -76
- package/__generated/components/ui/tabs.tsx +49 -52
- package/__generated/components/ui/text.tsx +2 -2
- package/__generated/components/ui/textarea.tsx +20 -21
- package/__generated/components/ui/toggle-group.tsx +5 -7
- package/__generated/components/ui/toggle.tsx +4 -4
- package/__generated/components/ui/tooltip.tsx +4 -5
- package/__generated/components/ui/typography.tsx +2 -2
- package/dist/index.js +3 -3
- package/dist/index.js.map +1 -1
- package/package.json +2 -34
- package/__generated/components/primitives/accordion/accordion.tsx +0 -216
- package/__generated/components/primitives/accordion/accordion.web.tsx +0 -295
- package/__generated/components/primitives/accordion/index.ts +0 -1
- package/__generated/components/primitives/accordion/types.ts +0 -45
- package/__generated/components/primitives/alert-dialog/alert-dialog.tsx +0 -237
- package/__generated/components/primitives/alert-dialog/alert-dialog.web.tsx +0 -256
- package/__generated/components/primitives/alert-dialog/index.ts +0 -1
- package/__generated/components/primitives/alert-dialog/types.ts +0 -48
- package/__generated/components/primitives/aspect-ratio.tsx +0 -23
- package/__generated/components/primitives/avatar/index.tsx +0 -95
- package/__generated/components/primitives/avatar/types.ts +0 -10
- package/__generated/components/primitives/checkbox/checkbox.tsx +0 -101
- package/__generated/components/primitives/checkbox/checkbox.web.tsx +0 -114
- package/__generated/components/primitives/checkbox/index.ts +0 -1
- package/__generated/components/primitives/checkbox/types.ts +0 -11
- package/__generated/components/primitives/collapsible/collapsible.tsx +0 -119
- package/__generated/components/primitives/collapsible/collapsible.web.tsx +0 -157
- package/__generated/components/primitives/collapsible/index.ts +0 -1
- package/__generated/components/primitives/collapsible/types.ts +0 -18
- package/__generated/components/primitives/context-menu/context-menu.tsx +0 -648
- package/__generated/components/primitives/context-menu/context-menu.web.tsx +0 -533
- package/__generated/components/primitives/context-menu/index.ts +0 -1
- package/__generated/components/primitives/context-menu/types.ts +0 -90
- package/__generated/components/primitives/dialog/dialog.tsx +0 -211
- package/__generated/components/primitives/dialog/dialog.web.tsx +0 -197
- package/__generated/components/primitives/dialog/index.ts +0 -1
- package/__generated/components/primitives/dialog/types.ts +0 -60
- package/__generated/components/primitives/dropdown-menu/dropdown-menu.tsx +0 -608
- package/__generated/components/primitives/dropdown-menu/dropdown-menu.web.tsx +0 -550
- package/__generated/components/primitives/dropdown-menu/index.ts +0 -1
- package/__generated/components/primitives/dropdown-menu/types.ts +0 -72
- package/__generated/components/primitives/hooks/index.ts +0 -3
- package/__generated/components/primitives/hooks/useAugmentedRef.tsx +0 -29
- package/__generated/components/primitives/hooks/useControllableState.tsx +0 -75
- package/__generated/components/primitives/hooks/useRelativePosition.tsx +0 -227
- package/__generated/components/primitives/hover-card/hover-card.tsx +0 -279
- package/__generated/components/primitives/hover-card/hover-card.web.tsx +0 -150
- package/__generated/components/primitives/hover-card/index.ts +0 -1
- package/__generated/components/primitives/hover-card/types.ts +0 -51
- package/__generated/components/primitives/label/index.ts +0 -1
- package/__generated/components/primitives/label/label.tsx +0 -31
- package/__generated/components/primitives/label/label.web.tsx +0 -36
- package/__generated/components/primitives/label/types.ts +0 -15
- package/__generated/components/primitives/menubar/index.ts +0 -1
- package/__generated/components/primitives/menubar/menubar.tsx +0 -622
- package/__generated/components/primitives/menubar/menubar.web.tsx +0 -548
- package/__generated/components/primitives/menubar/types.ts +0 -77
- package/__generated/components/primitives/navigation-menu/index.ts +0 -1
- package/__generated/components/primitives/navigation-menu/navigation-menu.tsx +0 -315
- package/__generated/components/primitives/navigation-menu/navigation-menu.web.tsx +0 -264
- package/__generated/components/primitives/navigation-menu/types.ts +0 -49
- package/__generated/components/primitives/popover/index.ts +0 -1
- package/__generated/components/primitives/popover/popover.tsx +0 -290
- package/__generated/components/primitives/popover/popover.web.tsx +0 -191
- package/__generated/components/primitives/popover/types.ts +0 -24
- package/__generated/components/primitives/portal.tsx +0 -82
- package/__generated/components/primitives/progress/index.ts +0 -1
- package/__generated/components/primitives/progress/progress.tsx +0 -59
- package/__generated/components/primitives/progress/progress.web.tsx +0 -36
- package/__generated/components/primitives/progress/types.ts +0 -7
- package/__generated/components/primitives/radio-group/index.ts +0 -1
- package/__generated/components/primitives/radio-group/radio-group.tsx +0 -116
- package/__generated/components/primitives/radio-group/radio-group.web.tsx +0 -78
- package/__generated/components/primitives/radio-group/types.ts +0 -15
- package/__generated/components/primitives/select/index.ts +0 -1
- package/__generated/components/primitives/select/select.tsx +0 -466
- package/__generated/components/primitives/select/select.web.tsx +0 -332
- package/__generated/components/primitives/select/types.ts +0 -89
- package/__generated/components/primitives/separator/index.tsx +0 -23
- package/__generated/components/primitives/separator/types.ts +0 -6
- package/__generated/components/primitives/slider/index.ts +0 -1
- package/__generated/components/primitives/slider/slider.tsx +0 -89
- package/__generated/components/primitives/slider/slider.web.tsx +0 -67
- package/__generated/components/primitives/slider/types.ts +0 -24
- package/__generated/components/primitives/slot.tsx +0 -187
- package/__generated/components/primitives/switch/index.ts +0 -1
- package/__generated/components/primitives/switch/switch.tsx +0 -65
- package/__generated/components/primitives/switch/switch.web.tsx +0 -67
- package/__generated/components/primitives/switch/types.ts +0 -11
- package/__generated/components/primitives/table.tsx +0 -55
- package/__generated/components/primitives/tabs/index.ts +0 -1
- package/__generated/components/primitives/tabs/tabs.tsx +0 -133
- package/__generated/components/primitives/tabs/tabs.web.tsx +0 -97
- package/__generated/components/primitives/tabs/types.ts +0 -24
- package/__generated/components/primitives/toast/index.tsx +0 -128
- package/__generated/components/primitives/toast/types.ts +0 -7
- package/__generated/components/primitives/toggle/index.ts +0 -1
- package/__generated/components/primitives/toggle/toggle.tsx +0 -37
- package/__generated/components/primitives/toggle/toggle.web.tsx +0 -26
- package/__generated/components/primitives/toggle/types.ts +0 -7
- package/__generated/components/primitives/toggle-group/index.ts +0 -1
- package/__generated/components/primitives/toggle-group/toggle-group.tsx +0 -125
- package/__generated/components/primitives/toggle-group/toggle-group.web.tsx +0 -124
- package/__generated/components/primitives/toggle-group/types.ts +0 -37
- package/__generated/components/primitives/toolbar/index.ts +0 -1
- package/__generated/components/primitives/toolbar/toolbar.tsx +0 -125
- package/__generated/components/primitives/toolbar/toolbar.web.tsx +0 -129
- package/__generated/components/primitives/toolbar/types.ts +0 -39
- package/__generated/components/primitives/tooltip/index.ts +0 -1
- package/__generated/components/primitives/tooltip/tooltip.tsx +0 -277
- package/__generated/components/primitives/tooltip/tooltip.web.tsx +0 -181
- package/__generated/components/primitives/tooltip/types.ts +0 -42
- package/__generated/components/primitives/types.ts +0 -105
- package/__generated/components/primitives/utils.ts +0 -61
|
@@ -1,315 +0,0 @@
|
|
|
1
|
-
import * as React from 'react';
|
|
2
|
-
import {
|
|
3
|
-
BackHandler,
|
|
4
|
-
Pressable,
|
|
5
|
-
View,
|
|
6
|
-
type GestureResponderEvent,
|
|
7
|
-
type LayoutChangeEvent,
|
|
8
|
-
type LayoutRectangle,
|
|
9
|
-
} from 'react-native';
|
|
10
|
-
import { useRelativePosition, type LayoutPosition } from '@rnr/hooks';
|
|
11
|
-
import { Portal as RNPPortal } from '@rnr/portal';
|
|
12
|
-
import * as Slot from '@rnr/slot';
|
|
13
|
-
import type {
|
|
14
|
-
PositionedContentProps,
|
|
15
|
-
PressableRef,
|
|
16
|
-
SlottablePressableProps,
|
|
17
|
-
SlottableViewProps,
|
|
18
|
-
ViewRef,
|
|
19
|
-
} from '@rnr/types';
|
|
20
|
-
import type {
|
|
21
|
-
NavigationMenuItemProps,
|
|
22
|
-
NavigationMenuLinkProps,
|
|
23
|
-
NavigationMenuPortalProps,
|
|
24
|
-
NavigationMenuRootProps,
|
|
25
|
-
} from './types';
|
|
26
|
-
|
|
27
|
-
interface INavigationMenuRootContext extends NavigationMenuRootProps {
|
|
28
|
-
triggerPosition: LayoutPosition | null;
|
|
29
|
-
setTriggerPosition: (triggerPosition: LayoutPosition | null) => void;
|
|
30
|
-
contentLayout: LayoutRectangle | null;
|
|
31
|
-
setContentLayout: (contentLayout: LayoutRectangle | null) => void;
|
|
32
|
-
nativeID: string;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
const RootContext = React.createContext<INavigationMenuRootContext | null>(null);
|
|
36
|
-
|
|
37
|
-
const Root = React.forwardRef<ViewRef, SlottableViewProps & NavigationMenuRootProps>(
|
|
38
|
-
({ asChild, value, onValueChange, ...viewProps }, ref) => {
|
|
39
|
-
const nativeID = React.useId();
|
|
40
|
-
const [triggerPosition, setTriggerPosition] = React.useState<LayoutPosition | null>(null);
|
|
41
|
-
const [contentLayout, setContentLayout] = React.useState<LayoutRectangle | null>(null);
|
|
42
|
-
|
|
43
|
-
const Component = asChild ? Slot.View : View;
|
|
44
|
-
return (
|
|
45
|
-
<RootContext.Provider
|
|
46
|
-
value={{
|
|
47
|
-
value,
|
|
48
|
-
onValueChange,
|
|
49
|
-
nativeID,
|
|
50
|
-
contentLayout,
|
|
51
|
-
setContentLayout,
|
|
52
|
-
setTriggerPosition,
|
|
53
|
-
triggerPosition,
|
|
54
|
-
}}
|
|
55
|
-
>
|
|
56
|
-
<Component ref={ref} role='navigation' {...viewProps} />
|
|
57
|
-
</RootContext.Provider>
|
|
58
|
-
);
|
|
59
|
-
}
|
|
60
|
-
);
|
|
61
|
-
|
|
62
|
-
Root.displayName = 'RootNativeNavigationMenu';
|
|
63
|
-
|
|
64
|
-
function useRootContext() {
|
|
65
|
-
const context = React.useContext(RootContext);
|
|
66
|
-
if (!context) {
|
|
67
|
-
throw new Error(
|
|
68
|
-
'NavigationMenu compound components cannot be rendered outside the NavigationMenu component'
|
|
69
|
-
);
|
|
70
|
-
}
|
|
71
|
-
return context;
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
const List = React.forwardRef<ViewRef, SlottableViewProps>(({ asChild, ...viewProps }, ref) => {
|
|
75
|
-
const Component = asChild ? Slot.View : View;
|
|
76
|
-
return <Component ref={ref} role='menubar' {...viewProps} />;
|
|
77
|
-
});
|
|
78
|
-
|
|
79
|
-
List.displayName = 'ListNativeNavigationMenu';
|
|
80
|
-
|
|
81
|
-
const ItemContext = React.createContext<(NavigationMenuItemProps & { nativeID: string }) | null>(
|
|
82
|
-
null
|
|
83
|
-
);
|
|
84
|
-
|
|
85
|
-
const Item = React.forwardRef<ViewRef, SlottableViewProps & NavigationMenuItemProps>(
|
|
86
|
-
({ asChild, value, ...viewProps }, ref) => {
|
|
87
|
-
const nativeID = React.useId();
|
|
88
|
-
|
|
89
|
-
const Component = asChild ? Slot.View : View;
|
|
90
|
-
return (
|
|
91
|
-
<ItemContext.Provider
|
|
92
|
-
value={{
|
|
93
|
-
value,
|
|
94
|
-
nativeID,
|
|
95
|
-
}}
|
|
96
|
-
>
|
|
97
|
-
<Component ref={ref} role='menuitem' {...viewProps} />
|
|
98
|
-
</ItemContext.Provider>
|
|
99
|
-
);
|
|
100
|
-
}
|
|
101
|
-
);
|
|
102
|
-
|
|
103
|
-
Item.displayName = 'ItemNativeNavigationMenu';
|
|
104
|
-
|
|
105
|
-
function useItemContext() {
|
|
106
|
-
const context = React.useContext(ItemContext);
|
|
107
|
-
if (!context) {
|
|
108
|
-
throw new Error(
|
|
109
|
-
'NavigationMenu compound components cannot be rendered outside the NavigationMenu component'
|
|
110
|
-
);
|
|
111
|
-
}
|
|
112
|
-
return context;
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
const Trigger = React.forwardRef<PressableRef, SlottablePressableProps>(
|
|
116
|
-
({ asChild, onPress: onPressProp, disabled = false, ...props }, ref) => {
|
|
117
|
-
const triggerRef = React.useRef<View>(null);
|
|
118
|
-
const { value, onValueChange, setTriggerPosition } = useRootContext();
|
|
119
|
-
const { value: menuValue } = useItemContext();
|
|
120
|
-
|
|
121
|
-
React.useImperativeHandle(
|
|
122
|
-
ref,
|
|
123
|
-
() => {
|
|
124
|
-
if (!triggerRef.current) {
|
|
125
|
-
return new View({});
|
|
126
|
-
}
|
|
127
|
-
return triggerRef.current;
|
|
128
|
-
},
|
|
129
|
-
[triggerRef.current]
|
|
130
|
-
);
|
|
131
|
-
|
|
132
|
-
function onPress(ev: GestureResponderEvent) {
|
|
133
|
-
if (disabled) return;
|
|
134
|
-
triggerRef.current?.measure((_x, _y, width, height, pageX, pageY) => {
|
|
135
|
-
setTriggerPosition({ width, pageX, pageY: pageY, height });
|
|
136
|
-
});
|
|
137
|
-
|
|
138
|
-
onValueChange(menuValue === value ? '' : menuValue);
|
|
139
|
-
onPressProp?.(ev);
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
const Component = asChild ? Slot.Pressable : Pressable;
|
|
143
|
-
return (
|
|
144
|
-
<Component
|
|
145
|
-
ref={triggerRef}
|
|
146
|
-
aria-disabled={disabled ?? undefined}
|
|
147
|
-
role='button'
|
|
148
|
-
onPress={onPress}
|
|
149
|
-
disabled={disabled ?? undefined}
|
|
150
|
-
aria-expanded={value === menuValue}
|
|
151
|
-
{...props}
|
|
152
|
-
/>
|
|
153
|
-
);
|
|
154
|
-
}
|
|
155
|
-
);
|
|
156
|
-
|
|
157
|
-
Trigger.displayName = 'TriggerNativeNavigationMenu';
|
|
158
|
-
|
|
159
|
-
/**
|
|
160
|
-
* @warning when using a custom `<PortalHost />`, you will have to adjust the Content's sideOffset to account for nav elements like headers.
|
|
161
|
-
*/
|
|
162
|
-
function Portal({ forceMount, hostName, children }: NavigationMenuPortalProps) {
|
|
163
|
-
const navigationMenu = useRootContext();
|
|
164
|
-
const item = useItemContext();
|
|
165
|
-
|
|
166
|
-
if (!navigationMenu.triggerPosition) {
|
|
167
|
-
return null;
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
if (!forceMount) {
|
|
171
|
-
if (navigationMenu.value !== item.value) {
|
|
172
|
-
return null;
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
return (
|
|
177
|
-
<RNPPortal hostName={hostName} name={`${navigationMenu.nativeID}_portal_provider`}>
|
|
178
|
-
<RootContext.Provider
|
|
179
|
-
value={navigationMenu}
|
|
180
|
-
key={`RootContext_${navigationMenu.nativeID}_portal_provider`}
|
|
181
|
-
>
|
|
182
|
-
<ItemContext.Provider value={item}>{children}</ItemContext.Provider>
|
|
183
|
-
</RootContext.Provider>
|
|
184
|
-
</RNPPortal>
|
|
185
|
-
);
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
/**
|
|
189
|
-
* @info `position`, `top`, `left`, and `maxWidth` style properties are controlled internally. Opt out of this behavior by setting `disablePositioningStyle` to `true`.
|
|
190
|
-
*/
|
|
191
|
-
const Content = React.forwardRef<ViewRef, SlottableViewProps & PositionedContentProps>(
|
|
192
|
-
(
|
|
193
|
-
{
|
|
194
|
-
asChild = false,
|
|
195
|
-
forceMount,
|
|
196
|
-
align = 'center',
|
|
197
|
-
side = 'bottom',
|
|
198
|
-
sideOffset = 0,
|
|
199
|
-
alignOffset = 0,
|
|
200
|
-
avoidCollisions = true,
|
|
201
|
-
onLayout: onLayoutProp,
|
|
202
|
-
insets,
|
|
203
|
-
style,
|
|
204
|
-
disablePositioningStyle,
|
|
205
|
-
...props
|
|
206
|
-
},
|
|
207
|
-
ref
|
|
208
|
-
) => {
|
|
209
|
-
const {
|
|
210
|
-
value,
|
|
211
|
-
onValueChange,
|
|
212
|
-
triggerPosition,
|
|
213
|
-
setTriggerPosition,
|
|
214
|
-
contentLayout,
|
|
215
|
-
setContentLayout,
|
|
216
|
-
} = useRootContext();
|
|
217
|
-
const { value: menuValue, nativeID } = useItemContext();
|
|
218
|
-
|
|
219
|
-
React.useEffect(() => {
|
|
220
|
-
const backHandler = BackHandler.addEventListener('hardwareBackPress', () => {
|
|
221
|
-
setTriggerPosition(null);
|
|
222
|
-
setContentLayout(null);
|
|
223
|
-
onValueChange('');
|
|
224
|
-
return true;
|
|
225
|
-
});
|
|
226
|
-
|
|
227
|
-
return () => {
|
|
228
|
-
setContentLayout(null);
|
|
229
|
-
backHandler.remove();
|
|
230
|
-
};
|
|
231
|
-
}, []);
|
|
232
|
-
|
|
233
|
-
const positionStyle = useRelativePosition({
|
|
234
|
-
align,
|
|
235
|
-
avoidCollisions,
|
|
236
|
-
triggerPosition,
|
|
237
|
-
contentLayout,
|
|
238
|
-
alignOffset,
|
|
239
|
-
insets,
|
|
240
|
-
sideOffset,
|
|
241
|
-
side,
|
|
242
|
-
disablePositioningStyle,
|
|
243
|
-
});
|
|
244
|
-
|
|
245
|
-
function onLayout(event: LayoutChangeEvent) {
|
|
246
|
-
setContentLayout(event.nativeEvent.layout);
|
|
247
|
-
onLayoutProp?.(event);
|
|
248
|
-
}
|
|
249
|
-
|
|
250
|
-
if (!forceMount) {
|
|
251
|
-
if (value !== menuValue) {
|
|
252
|
-
return null;
|
|
253
|
-
}
|
|
254
|
-
}
|
|
255
|
-
|
|
256
|
-
const Component = asChild ? Slot.View : View;
|
|
257
|
-
return (
|
|
258
|
-
<Component
|
|
259
|
-
ref={ref}
|
|
260
|
-
role='menu'
|
|
261
|
-
nativeID={nativeID}
|
|
262
|
-
aria-modal={true}
|
|
263
|
-
style={[positionStyle, style]}
|
|
264
|
-
onLayout={onLayout}
|
|
265
|
-
onStartShouldSetResponder={onStartShouldSetResponder}
|
|
266
|
-
{...props}
|
|
267
|
-
/>
|
|
268
|
-
);
|
|
269
|
-
}
|
|
270
|
-
);
|
|
271
|
-
|
|
272
|
-
Content.displayName = 'ContentNativeNavigationMenu';
|
|
273
|
-
|
|
274
|
-
const Link = React.forwardRef<PressableRef, SlottablePressableProps & NavigationMenuLinkProps>(
|
|
275
|
-
({ asChild, ...props }, ref) => {
|
|
276
|
-
const Component = asChild ? Slot.Pressable : Pressable;
|
|
277
|
-
return <Component ref={ref} role='link' {...props} />;
|
|
278
|
-
}
|
|
279
|
-
);
|
|
280
|
-
|
|
281
|
-
Link.displayName = 'LinkNativeNavigationMenu';
|
|
282
|
-
|
|
283
|
-
const Viewport = React.forwardRef<
|
|
284
|
-
ViewRef,
|
|
285
|
-
Omit<React.ComponentPropsWithoutRef<typeof View>, 'children'>
|
|
286
|
-
>((props, ref) => {
|
|
287
|
-
return <View ref={ref} {...props} />;
|
|
288
|
-
});
|
|
289
|
-
|
|
290
|
-
Viewport.displayName = 'ViewportNativeNavigationMenu';
|
|
291
|
-
|
|
292
|
-
const Indicator = React.forwardRef<ViewRef, SlottableViewProps>(({ asChild, ...props }, ref) => {
|
|
293
|
-
const Component = asChild ? Slot.View : View;
|
|
294
|
-
return <Component ref={ref} {...props} />;
|
|
295
|
-
});
|
|
296
|
-
|
|
297
|
-
Indicator.displayName = 'IndicatorNativeNavigationMenu';
|
|
298
|
-
|
|
299
|
-
export {
|
|
300
|
-
Content,
|
|
301
|
-
Indicator,
|
|
302
|
-
Item,
|
|
303
|
-
Link,
|
|
304
|
-
List,
|
|
305
|
-
Portal,
|
|
306
|
-
Root,
|
|
307
|
-
Trigger,
|
|
308
|
-
Viewport,
|
|
309
|
-
useItemContext,
|
|
310
|
-
useRootContext,
|
|
311
|
-
};
|
|
312
|
-
|
|
313
|
-
function onStartShouldSetResponder() {
|
|
314
|
-
return true;
|
|
315
|
-
}
|
|
@@ -1,264 +0,0 @@
|
|
|
1
|
-
import * as NavigationMenu from '@radix-ui/react-navigation-menu';
|
|
2
|
-
import * as React from 'react';
|
|
3
|
-
import { GestureResponderEvent, Pressable, View } from 'react-native';
|
|
4
|
-
import { useAugmentedRef } from '@rnr/hooks';
|
|
5
|
-
import * as Slot from '@rnr/slot';
|
|
6
|
-
import type {
|
|
7
|
-
PositionedContentProps,
|
|
8
|
-
PressableRef,
|
|
9
|
-
SlottablePressableProps,
|
|
10
|
-
SlottableViewProps,
|
|
11
|
-
ViewRef,
|
|
12
|
-
} from '@rnr/types';
|
|
13
|
-
import { EmptyGestureResponderEvent } from '@rnr/utils';
|
|
14
|
-
import type {
|
|
15
|
-
NavigationMenuItemProps,
|
|
16
|
-
NavigationMenuLinkProps,
|
|
17
|
-
NavigationMenuPortalProps,
|
|
18
|
-
NavigationMenuRootProps,
|
|
19
|
-
} from './types';
|
|
20
|
-
|
|
21
|
-
const NavigationMenuContext = React.createContext<NavigationMenuRootProps | null>(null);
|
|
22
|
-
|
|
23
|
-
const Root = React.forwardRef<ViewRef, SlottableViewProps & NavigationMenuRootProps>(
|
|
24
|
-
(
|
|
25
|
-
{
|
|
26
|
-
asChild,
|
|
27
|
-
value,
|
|
28
|
-
onValueChange,
|
|
29
|
-
delayDuration,
|
|
30
|
-
skipDelayDuration,
|
|
31
|
-
dir,
|
|
32
|
-
orientation,
|
|
33
|
-
...viewProps
|
|
34
|
-
},
|
|
35
|
-
ref
|
|
36
|
-
) => {
|
|
37
|
-
const Component = asChild ? Slot.View : View;
|
|
38
|
-
return (
|
|
39
|
-
<NavigationMenuContext.Provider value={{ value, onValueChange, orientation }}>
|
|
40
|
-
<NavigationMenu.Root
|
|
41
|
-
value={value}
|
|
42
|
-
onValueChange={onValueChange}
|
|
43
|
-
delayDuration={delayDuration}
|
|
44
|
-
skipDelayDuration={skipDelayDuration}
|
|
45
|
-
dir={dir}
|
|
46
|
-
orientation={orientation}
|
|
47
|
-
>
|
|
48
|
-
<Component ref={ref} {...viewProps} />
|
|
49
|
-
</NavigationMenu.Root>
|
|
50
|
-
</NavigationMenuContext.Provider>
|
|
51
|
-
);
|
|
52
|
-
}
|
|
53
|
-
);
|
|
54
|
-
|
|
55
|
-
Root.displayName = 'RootWebNavigationMenu';
|
|
56
|
-
|
|
57
|
-
function useRootContext() {
|
|
58
|
-
const context = React.useContext(NavigationMenuContext);
|
|
59
|
-
if (!context) {
|
|
60
|
-
throw new Error(
|
|
61
|
-
'NavigationMenu compound components cannot be rendered outside the NavigationMenu component'
|
|
62
|
-
);
|
|
63
|
-
}
|
|
64
|
-
return context;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
const List = React.forwardRef<ViewRef, SlottableViewProps>(({ asChild, ...viewProps }, ref) => {
|
|
68
|
-
const augmentedRef = useAugmentedRef({ ref });
|
|
69
|
-
const { orientation } = useRootContext();
|
|
70
|
-
|
|
71
|
-
React.useLayoutEffect(() => {
|
|
72
|
-
if (augmentedRef.current) {
|
|
73
|
-
const augRef = augmentedRef.current as unknown as HTMLDivElement;
|
|
74
|
-
augRef.dataset.orientation = orientation;
|
|
75
|
-
}
|
|
76
|
-
}, [orientation]);
|
|
77
|
-
|
|
78
|
-
const Component = asChild ? Slot.View : View;
|
|
79
|
-
return (
|
|
80
|
-
<NavigationMenu.List asChild>
|
|
81
|
-
<Component ref={ref} {...viewProps} />
|
|
82
|
-
</NavigationMenu.List>
|
|
83
|
-
);
|
|
84
|
-
});
|
|
85
|
-
|
|
86
|
-
List.displayName = 'ListWebNavigationMenu';
|
|
87
|
-
|
|
88
|
-
const ItemContext = React.createContext<NavigationMenuItemProps | null>(null);
|
|
89
|
-
|
|
90
|
-
const Item = React.forwardRef<ViewRef, SlottableViewProps & NavigationMenuItemProps>(
|
|
91
|
-
({ asChild, value, ...props }, ref) => {
|
|
92
|
-
const Component = asChild ? Slot.View : View;
|
|
93
|
-
return (
|
|
94
|
-
<ItemContext.Provider value={{ value }}>
|
|
95
|
-
<NavigationMenu.Item value={value} asChild>
|
|
96
|
-
<Component ref={ref} {...props} />
|
|
97
|
-
</NavigationMenu.Item>
|
|
98
|
-
</ItemContext.Provider>
|
|
99
|
-
);
|
|
100
|
-
}
|
|
101
|
-
);
|
|
102
|
-
|
|
103
|
-
Item.displayName = 'ItemWebNavigationMenu';
|
|
104
|
-
|
|
105
|
-
function useItemContext() {
|
|
106
|
-
const context = React.useContext(ItemContext);
|
|
107
|
-
if (!context) {
|
|
108
|
-
throw new Error(
|
|
109
|
-
'NavigationMenu compound components cannot be rendered outside the NavigationMenu component'
|
|
110
|
-
);
|
|
111
|
-
}
|
|
112
|
-
return context;
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
const Trigger = React.forwardRef<PressableRef, SlottablePressableProps>(
|
|
116
|
-
(
|
|
117
|
-
{ asChild, onPress: onPressProp, disabled = false, onKeyDown: onKeyDownProp, ...props },
|
|
118
|
-
ref
|
|
119
|
-
) => {
|
|
120
|
-
const { value: rootValue, onValueChange } = useRootContext();
|
|
121
|
-
const { value } = useItemContext();
|
|
122
|
-
function onKeyDown(ev: React.KeyboardEvent) {
|
|
123
|
-
onKeyDownProp?.(ev);
|
|
124
|
-
if (ev.key === ' ') {
|
|
125
|
-
onPressProp?.(EmptyGestureResponderEvent);
|
|
126
|
-
onValueChange(value === rootValue ? '' : value);
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
function onPress(ev: GestureResponderEvent) {
|
|
131
|
-
onPressProp?.(ev);
|
|
132
|
-
onValueChange(value === rootValue ? '' : value);
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
const Component = asChild ? Slot.Pressable : Pressable;
|
|
136
|
-
return (
|
|
137
|
-
<NavigationMenu.Trigger disabled={disabled ?? undefined} asChild>
|
|
138
|
-
<Component
|
|
139
|
-
ref={ref}
|
|
140
|
-
// @ts-expect-error web only
|
|
141
|
-
onKeyDown={onKeyDown}
|
|
142
|
-
onPress={onPress}
|
|
143
|
-
{...props}
|
|
144
|
-
/>
|
|
145
|
-
</NavigationMenu.Trigger>
|
|
146
|
-
);
|
|
147
|
-
}
|
|
148
|
-
);
|
|
149
|
-
|
|
150
|
-
Trigger.displayName = 'TriggerWebNavigationMenu';
|
|
151
|
-
|
|
152
|
-
function Portal({ children }: NavigationMenuPortalProps) {
|
|
153
|
-
return <>{children}</>;
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
const Content = React.forwardRef<ViewRef, SlottableViewProps & PositionedContentProps>(
|
|
157
|
-
(
|
|
158
|
-
{
|
|
159
|
-
asChild = false,
|
|
160
|
-
forceMount,
|
|
161
|
-
align: _align,
|
|
162
|
-
side: _side,
|
|
163
|
-
sideOffset: _sideOffset,
|
|
164
|
-
alignOffset: _alignOffset,
|
|
165
|
-
avoidCollisions: _avoidCollisions,
|
|
166
|
-
onLayout: onLayoutProp,
|
|
167
|
-
insets: _insets,
|
|
168
|
-
disablePositioningStyle: _disablePositioningStyle,
|
|
169
|
-
onEscapeKeyDown,
|
|
170
|
-
onPointerDownOutside,
|
|
171
|
-
onFocusOutside,
|
|
172
|
-
onInteractOutside,
|
|
173
|
-
...props
|
|
174
|
-
},
|
|
175
|
-
ref
|
|
176
|
-
) => {
|
|
177
|
-
const Component = asChild ? Slot.View : View;
|
|
178
|
-
return (
|
|
179
|
-
<NavigationMenu.Content
|
|
180
|
-
forceMount={forceMount}
|
|
181
|
-
onEscapeKeyDown={onEscapeKeyDown}
|
|
182
|
-
onPointerDownOutside={onPointerDownOutside}
|
|
183
|
-
onFocusOutside={onFocusOutside}
|
|
184
|
-
onInteractOutside={onInteractOutside}
|
|
185
|
-
>
|
|
186
|
-
<Component ref={ref} {...props} />
|
|
187
|
-
</NavigationMenu.Content>
|
|
188
|
-
);
|
|
189
|
-
}
|
|
190
|
-
);
|
|
191
|
-
|
|
192
|
-
Content.displayName = 'ContentWebNavigationMenu';
|
|
193
|
-
|
|
194
|
-
const Link = React.forwardRef<PressableRef, SlottablePressableProps & NavigationMenuLinkProps>(
|
|
195
|
-
({ asChild, active, onPress: onPressProp, onKeyDown: onKeyDownProp, ...props }, ref) => {
|
|
196
|
-
const { onValueChange } = useRootContext();
|
|
197
|
-
function onKeyDown(ev: React.KeyboardEvent) {
|
|
198
|
-
onKeyDownProp?.(ev);
|
|
199
|
-
if (ev.key === 'Enter' || ev.key === ' ') {
|
|
200
|
-
onPressProp?.(EmptyGestureResponderEvent);
|
|
201
|
-
onValueChange('');
|
|
202
|
-
}
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
function onPress(ev: GestureResponderEvent) {
|
|
206
|
-
onPressProp?.(ev);
|
|
207
|
-
onValueChange('');
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
const Component = asChild ? Slot.Pressable : Pressable;
|
|
211
|
-
return (
|
|
212
|
-
<NavigationMenu.Link active={active} asChild>
|
|
213
|
-
<Component
|
|
214
|
-
ref={ref}
|
|
215
|
-
role='link'
|
|
216
|
-
// @ts-expect-error web only
|
|
217
|
-
onKeyDown={onKeyDown}
|
|
218
|
-
onPress={onPress}
|
|
219
|
-
{...props}
|
|
220
|
-
/>
|
|
221
|
-
</NavigationMenu.Link>
|
|
222
|
-
);
|
|
223
|
-
}
|
|
224
|
-
);
|
|
225
|
-
|
|
226
|
-
Link.displayName = 'LinkWebNavigationMenu';
|
|
227
|
-
|
|
228
|
-
const Viewport = React.forwardRef<
|
|
229
|
-
ViewRef,
|
|
230
|
-
Omit<React.ComponentPropsWithoutRef<typeof View>, 'children'>
|
|
231
|
-
>((props, ref) => {
|
|
232
|
-
return (
|
|
233
|
-
<Slot.View ref={ref} {...props}>
|
|
234
|
-
<NavigationMenu.Viewport />
|
|
235
|
-
</Slot.View>
|
|
236
|
-
);
|
|
237
|
-
});
|
|
238
|
-
|
|
239
|
-
Viewport.displayName = 'ViewportWebNavigationMenu';
|
|
240
|
-
|
|
241
|
-
const Indicator = React.forwardRef<ViewRef, SlottableViewProps>(({ asChild, ...props }, ref) => {
|
|
242
|
-
const Component = asChild ? Slot.View : View;
|
|
243
|
-
return (
|
|
244
|
-
<NavigationMenu.Indicator asChild>
|
|
245
|
-
<Component ref={ref} {...props} />
|
|
246
|
-
</NavigationMenu.Indicator>
|
|
247
|
-
);
|
|
248
|
-
});
|
|
249
|
-
|
|
250
|
-
Indicator.displayName = 'IndicatorWebNavigationMenu';
|
|
251
|
-
|
|
252
|
-
export {
|
|
253
|
-
Content,
|
|
254
|
-
Indicator,
|
|
255
|
-
Item,
|
|
256
|
-
Link,
|
|
257
|
-
List,
|
|
258
|
-
Portal,
|
|
259
|
-
Root,
|
|
260
|
-
Trigger,
|
|
261
|
-
Viewport,
|
|
262
|
-
useItemContext,
|
|
263
|
-
useRootContext,
|
|
264
|
-
};
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
import type { ForceMountable } from '@rnr/types';
|
|
2
|
-
|
|
3
|
-
interface NavigationMenuRootProps {
|
|
4
|
-
value: string | undefined;
|
|
5
|
-
onValueChange: (value: string | undefined) => void;
|
|
6
|
-
/**
|
|
7
|
-
* Platform: WEB ONLY
|
|
8
|
-
*/
|
|
9
|
-
delayDuration?: number;
|
|
10
|
-
/**
|
|
11
|
-
* Platform: WEB ONLY
|
|
12
|
-
*/
|
|
13
|
-
skipDelayDuration?: number;
|
|
14
|
-
/**
|
|
15
|
-
* Platform: WEB ONLY
|
|
16
|
-
*/
|
|
17
|
-
dir?: 'ltr' | 'rtl';
|
|
18
|
-
/**
|
|
19
|
-
* Platform: WEB ONLY
|
|
20
|
-
*/
|
|
21
|
-
orientation?: 'horizontal' | 'vertical';
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
interface NavigationMenuItemProps {
|
|
25
|
-
value: string | undefined;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
interface NavigationMenuPortalProps extends ForceMountable {
|
|
29
|
-
children: React.ReactNode;
|
|
30
|
-
/**
|
|
31
|
-
* Platform: NATIVE ONLY
|
|
32
|
-
*/
|
|
33
|
-
hostName?: string;
|
|
34
|
-
/**
|
|
35
|
-
* Platform: WEB ONLY
|
|
36
|
-
*/
|
|
37
|
-
container?: HTMLElement | null | undefined;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
interface NavigationMenuLinkProps {
|
|
41
|
-
active?: boolean;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
export type {
|
|
45
|
-
NavigationMenuItemProps,
|
|
46
|
-
NavigationMenuPortalProps,
|
|
47
|
-
NavigationMenuRootProps,
|
|
48
|
-
NavigationMenuLinkProps,
|
|
49
|
-
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './popover';
|