@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,290 +0,0 @@
|
|
|
1
|
-
import { useAugmentedRef, useRelativePosition, type LayoutPosition } from '@rnr/hooks';
|
|
2
|
-
import { Portal as RNPPortal } from '@rnr/portal';
|
|
3
|
-
import * as Slot from '@rnr/slot';
|
|
4
|
-
import type {
|
|
5
|
-
PositionedContentProps,
|
|
6
|
-
PressableRef,
|
|
7
|
-
SlottablePressableProps,
|
|
8
|
-
SlottableViewProps,
|
|
9
|
-
ViewRef,
|
|
10
|
-
} from '@rnr/types';
|
|
11
|
-
import * as React from 'react';
|
|
12
|
-
import {
|
|
13
|
-
BackHandler,
|
|
14
|
-
Pressable,
|
|
15
|
-
View,
|
|
16
|
-
type GestureResponderEvent,
|
|
17
|
-
type LayoutChangeEvent,
|
|
18
|
-
type LayoutRectangle,
|
|
19
|
-
} from 'react-native';
|
|
20
|
-
import type { PopoverOverlayProps, PopoverPortalProps, PopoverTriggerRef } from './types';
|
|
21
|
-
|
|
22
|
-
interface IRootContext {
|
|
23
|
-
open: boolean;
|
|
24
|
-
onOpenChange: (open: boolean) => void;
|
|
25
|
-
triggerPosition: LayoutPosition | null;
|
|
26
|
-
setTriggerPosition: (triggerPosition: LayoutPosition | null) => void;
|
|
27
|
-
contentLayout: LayoutRectangle | null;
|
|
28
|
-
setContentLayout: (contentLayout: LayoutRectangle | null) => void;
|
|
29
|
-
nativeID: string;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
const RootContext = React.createContext<IRootContext | null>(null);
|
|
33
|
-
|
|
34
|
-
const Root = React.forwardRef<
|
|
35
|
-
ViewRef,
|
|
36
|
-
SlottableViewProps & { onOpenChange?: (open: boolean) => void }
|
|
37
|
-
>(({ asChild, onOpenChange: onOpenChangeProp, ...viewProps }, ref) => {
|
|
38
|
-
const nativeID = React.useId();
|
|
39
|
-
const [triggerPosition, setTriggerPosition] = React.useState<LayoutPosition | null>(null);
|
|
40
|
-
const [contentLayout, setContentLayout] = React.useState<LayoutRectangle | null>(null);
|
|
41
|
-
const [open, setOpen] = React.useState(false);
|
|
42
|
-
|
|
43
|
-
function onOpenChange(value: boolean) {
|
|
44
|
-
setOpen(value);
|
|
45
|
-
onOpenChangeProp?.(value);
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
const Component = asChild ? Slot.View : View;
|
|
49
|
-
return (
|
|
50
|
-
<RootContext.Provider
|
|
51
|
-
value={{
|
|
52
|
-
open,
|
|
53
|
-
onOpenChange,
|
|
54
|
-
contentLayout,
|
|
55
|
-
nativeID,
|
|
56
|
-
setContentLayout,
|
|
57
|
-
setTriggerPosition,
|
|
58
|
-
triggerPosition,
|
|
59
|
-
}}
|
|
60
|
-
>
|
|
61
|
-
<Component ref={ref} {...viewProps} />
|
|
62
|
-
</RootContext.Provider>
|
|
63
|
-
);
|
|
64
|
-
});
|
|
65
|
-
|
|
66
|
-
Root.displayName = 'RootNativePopover';
|
|
67
|
-
|
|
68
|
-
function useRootContext() {
|
|
69
|
-
const context = React.useContext(RootContext);
|
|
70
|
-
if (!context) {
|
|
71
|
-
throw new Error('Popover compound components cannot be rendered outside the Popover component');
|
|
72
|
-
}
|
|
73
|
-
return context;
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
const Trigger = React.forwardRef<PopoverTriggerRef, SlottablePressableProps>(
|
|
77
|
-
({ asChild, onPress: onPressProp, disabled = false, ...props }, ref) => {
|
|
78
|
-
const { onOpenChange, setTriggerPosition } = useRootContext();
|
|
79
|
-
|
|
80
|
-
const augmentedRef = useAugmentedRef({
|
|
81
|
-
ref,
|
|
82
|
-
methods: {
|
|
83
|
-
open: () => {
|
|
84
|
-
onOpenChange(true);
|
|
85
|
-
augmentedRef.current?.measure((_x, _y, width, height, pageX, pageY) => {
|
|
86
|
-
setTriggerPosition({ width, pageX, pageY: pageY, height });
|
|
87
|
-
});
|
|
88
|
-
},
|
|
89
|
-
close: () => {
|
|
90
|
-
setTriggerPosition(null);
|
|
91
|
-
onOpenChange(false);
|
|
92
|
-
},
|
|
93
|
-
},
|
|
94
|
-
});
|
|
95
|
-
|
|
96
|
-
function onPress(ev: GestureResponderEvent) {
|
|
97
|
-
if (disabled) return;
|
|
98
|
-
augmentedRef.current?.measure((_x, _y, width, height, pageX, pageY) => {
|
|
99
|
-
setTriggerPosition({ width, pageX, pageY: pageY, height });
|
|
100
|
-
});
|
|
101
|
-
onOpenChange(!open);
|
|
102
|
-
onPressProp?.(ev);
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
const Component = asChild ? Slot.Pressable : Pressable;
|
|
106
|
-
return (
|
|
107
|
-
<Component
|
|
108
|
-
ref={augmentedRef}
|
|
109
|
-
aria-disabled={disabled ?? undefined}
|
|
110
|
-
role='button'
|
|
111
|
-
onPress={onPress}
|
|
112
|
-
disabled={disabled ?? undefined}
|
|
113
|
-
{...props}
|
|
114
|
-
/>
|
|
115
|
-
);
|
|
116
|
-
}
|
|
117
|
-
);
|
|
118
|
-
|
|
119
|
-
Trigger.displayName = 'TriggerNativePopover';
|
|
120
|
-
|
|
121
|
-
/**
|
|
122
|
-
* @warning when using a custom `<PortalHost />`, you might have to adjust the Content's sideOffset to account for nav elements like headers.
|
|
123
|
-
*/
|
|
124
|
-
function Portal({ forceMount, hostName, children }: PopoverPortalProps) {
|
|
125
|
-
const value = useRootContext();
|
|
126
|
-
|
|
127
|
-
if (!value.triggerPosition) {
|
|
128
|
-
return null;
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
if (!forceMount) {
|
|
132
|
-
if (!value.open) {
|
|
133
|
-
return null;
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
return (
|
|
138
|
-
<RNPPortal hostName={hostName} name={`${value.nativeID}_portal`}>
|
|
139
|
-
<RootContext.Provider value={value}>{children}</RootContext.Provider>
|
|
140
|
-
</RNPPortal>
|
|
141
|
-
);
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
const Overlay = React.forwardRef<PressableRef, SlottablePressableProps & PopoverOverlayProps>(
|
|
145
|
-
({ asChild, forceMount, onPress: OnPressProp, closeOnPress = true, ...props }, ref) => {
|
|
146
|
-
const { open, onOpenChange, setTriggerPosition, setContentLayout } = useRootContext();
|
|
147
|
-
|
|
148
|
-
function onPress(ev: GestureResponderEvent) {
|
|
149
|
-
if (closeOnPress) {
|
|
150
|
-
setTriggerPosition(null);
|
|
151
|
-
setContentLayout(null);
|
|
152
|
-
onOpenChange(false);
|
|
153
|
-
}
|
|
154
|
-
OnPressProp?.(ev);
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
if (!forceMount) {
|
|
158
|
-
if (!open) {
|
|
159
|
-
return null;
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
const Component = asChild ? Slot.Pressable : Pressable;
|
|
164
|
-
return <Component ref={ref} onPress={onPress} {...props} />;
|
|
165
|
-
}
|
|
166
|
-
);
|
|
167
|
-
|
|
168
|
-
Overlay.displayName = 'OverlayNativePopover';
|
|
169
|
-
|
|
170
|
-
/**
|
|
171
|
-
* @info `position`, `top`, `left`, and `maxWidth` style properties are controlled internally. Opt out of this behavior by setting `disablePositioningStyle` to `true`.
|
|
172
|
-
*/
|
|
173
|
-
const Content = React.forwardRef<ViewRef, SlottableViewProps & PositionedContentProps>(
|
|
174
|
-
(
|
|
175
|
-
{
|
|
176
|
-
asChild = false,
|
|
177
|
-
forceMount,
|
|
178
|
-
align = 'start',
|
|
179
|
-
side = 'bottom',
|
|
180
|
-
sideOffset = 0,
|
|
181
|
-
alignOffset = 0,
|
|
182
|
-
avoidCollisions = true,
|
|
183
|
-
onLayout: onLayoutProp,
|
|
184
|
-
insets,
|
|
185
|
-
style,
|
|
186
|
-
disablePositioningStyle,
|
|
187
|
-
...props
|
|
188
|
-
},
|
|
189
|
-
ref
|
|
190
|
-
) => {
|
|
191
|
-
const {
|
|
192
|
-
open,
|
|
193
|
-
onOpenChange,
|
|
194
|
-
contentLayout,
|
|
195
|
-
nativeID,
|
|
196
|
-
setContentLayout,
|
|
197
|
-
setTriggerPosition,
|
|
198
|
-
triggerPosition,
|
|
199
|
-
} = useRootContext();
|
|
200
|
-
|
|
201
|
-
React.useEffect(() => {
|
|
202
|
-
const backHandler = BackHandler.addEventListener('hardwareBackPress', () => {
|
|
203
|
-
setTriggerPosition(null);
|
|
204
|
-
setContentLayout(null);
|
|
205
|
-
onOpenChange(false);
|
|
206
|
-
return true;
|
|
207
|
-
});
|
|
208
|
-
|
|
209
|
-
return () => {
|
|
210
|
-
setContentLayout(null);
|
|
211
|
-
backHandler.remove();
|
|
212
|
-
};
|
|
213
|
-
}, []);
|
|
214
|
-
|
|
215
|
-
const positionStyle = useRelativePosition({
|
|
216
|
-
align,
|
|
217
|
-
avoidCollisions,
|
|
218
|
-
triggerPosition,
|
|
219
|
-
contentLayout,
|
|
220
|
-
alignOffset,
|
|
221
|
-
insets,
|
|
222
|
-
sideOffset,
|
|
223
|
-
side,
|
|
224
|
-
disablePositioningStyle,
|
|
225
|
-
});
|
|
226
|
-
|
|
227
|
-
function onLayout(event: LayoutChangeEvent) {
|
|
228
|
-
setContentLayout(event.nativeEvent.layout);
|
|
229
|
-
onLayoutProp?.(event);
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
if (!forceMount) {
|
|
233
|
-
if (!open) {
|
|
234
|
-
return null;
|
|
235
|
-
}
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
const Component = asChild ? Slot.View : View;
|
|
239
|
-
return (
|
|
240
|
-
<Component
|
|
241
|
-
ref={ref}
|
|
242
|
-
role='dialog'
|
|
243
|
-
nativeID={nativeID}
|
|
244
|
-
aria-modal={true}
|
|
245
|
-
style={[positionStyle, style]}
|
|
246
|
-
onLayout={onLayout}
|
|
247
|
-
onStartShouldSetResponder={onStartShouldSetResponder}
|
|
248
|
-
{...props}
|
|
249
|
-
/>
|
|
250
|
-
);
|
|
251
|
-
}
|
|
252
|
-
);
|
|
253
|
-
|
|
254
|
-
Content.displayName = 'ContentNativePopover';
|
|
255
|
-
|
|
256
|
-
const Close = React.forwardRef<PressableRef, SlottablePressableProps>(
|
|
257
|
-
({ asChild, onPress: onPressProp, disabled = false, ...props }, ref) => {
|
|
258
|
-
const { onOpenChange, setContentLayout, setTriggerPosition } = useRootContext();
|
|
259
|
-
|
|
260
|
-
function onPress(ev: GestureResponderEvent) {
|
|
261
|
-
if (disabled) return;
|
|
262
|
-
setTriggerPosition(null);
|
|
263
|
-
setContentLayout(null);
|
|
264
|
-
onOpenChange(false);
|
|
265
|
-
onPressProp?.(ev);
|
|
266
|
-
}
|
|
267
|
-
|
|
268
|
-
const Component = asChild ? Slot.Pressable : Pressable;
|
|
269
|
-
return (
|
|
270
|
-
<Component
|
|
271
|
-
ref={ref}
|
|
272
|
-
aria-disabled={disabled ?? undefined}
|
|
273
|
-
role='button'
|
|
274
|
-
onPress={onPress}
|
|
275
|
-
disabled={disabled ?? undefined}
|
|
276
|
-
{...props}
|
|
277
|
-
/>
|
|
278
|
-
);
|
|
279
|
-
}
|
|
280
|
-
);
|
|
281
|
-
|
|
282
|
-
Close.displayName = 'CloseNativePopover';
|
|
283
|
-
|
|
284
|
-
export { Close, Content, Overlay, Portal, Root, Trigger, useRootContext };
|
|
285
|
-
|
|
286
|
-
export type { PopoverTriggerRef };
|
|
287
|
-
|
|
288
|
-
function onStartShouldSetResponder() {
|
|
289
|
-
return true;
|
|
290
|
-
}
|
|
@@ -1,191 +0,0 @@
|
|
|
1
|
-
import * as Popover from '@radix-ui/react-popover';
|
|
2
|
-
import { useAugmentedRef } from '@rnr/hooks';
|
|
3
|
-
import * as Slot from '@rnr/slot';
|
|
4
|
-
import type {
|
|
5
|
-
PositionedContentProps,
|
|
6
|
-
PressableRef,
|
|
7
|
-
SlottablePressableProps,
|
|
8
|
-
SlottableViewProps,
|
|
9
|
-
ViewRef,
|
|
10
|
-
} from '@rnr/types';
|
|
11
|
-
import * as React from 'react';
|
|
12
|
-
import { Pressable, View, type GestureResponderEvent } from 'react-native';
|
|
13
|
-
import type { PopoverOverlayProps, PopoverPortalProps, PopoverTriggerRef } from './types';
|
|
14
|
-
|
|
15
|
-
const RootContext = React.createContext<{
|
|
16
|
-
open: boolean;
|
|
17
|
-
onOpenChange: (open: boolean) => void;
|
|
18
|
-
} | null>(null);
|
|
19
|
-
|
|
20
|
-
const Root = React.forwardRef<
|
|
21
|
-
ViewRef,
|
|
22
|
-
SlottableViewProps & { onOpenChange?: (open: boolean) => void }
|
|
23
|
-
>(({ asChild, onOpenChange: onOpenChangeProp, ...viewProps }, ref) => {
|
|
24
|
-
const [open, setOpen] = React.useState(false);
|
|
25
|
-
|
|
26
|
-
function onOpenChange(value: boolean) {
|
|
27
|
-
setOpen(value);
|
|
28
|
-
onOpenChangeProp?.(value);
|
|
29
|
-
}
|
|
30
|
-
const Component = asChild ? Slot.View : View;
|
|
31
|
-
return (
|
|
32
|
-
<RootContext.Provider value={{ open, onOpenChange }}>
|
|
33
|
-
<Popover.Root open={open} onOpenChange={onOpenChange}>
|
|
34
|
-
<Component ref={ref} {...viewProps} />
|
|
35
|
-
</Popover.Root>
|
|
36
|
-
</RootContext.Provider>
|
|
37
|
-
);
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
Root.displayName = 'RootWebPopover';
|
|
41
|
-
|
|
42
|
-
function useRootContext() {
|
|
43
|
-
const context = React.useContext(RootContext);
|
|
44
|
-
if (!context) {
|
|
45
|
-
throw new Error('Popover compound components cannot be rendered outside the Popover component');
|
|
46
|
-
}
|
|
47
|
-
return context;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
const Trigger = React.forwardRef<PopoverTriggerRef, SlottablePressableProps>(
|
|
51
|
-
({ asChild, onPress: onPressProp, role: _role, disabled, ...props }, ref) => {
|
|
52
|
-
const { onOpenChange, open } = useRootContext();
|
|
53
|
-
const augmentedRef = useAugmentedRef({
|
|
54
|
-
ref,
|
|
55
|
-
methods: {
|
|
56
|
-
open() {
|
|
57
|
-
onOpenChange(true);
|
|
58
|
-
},
|
|
59
|
-
close() {
|
|
60
|
-
onOpenChange(false);
|
|
61
|
-
},
|
|
62
|
-
},
|
|
63
|
-
});
|
|
64
|
-
function onPress(ev: GestureResponderEvent) {
|
|
65
|
-
if (onPressProp) {
|
|
66
|
-
onPressProp(ev);
|
|
67
|
-
}
|
|
68
|
-
onOpenChange(!open);
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
React.useLayoutEffect(() => {
|
|
72
|
-
if (augmentedRef.current) {
|
|
73
|
-
const augRef = augmentedRef.current as unknown as HTMLButtonElement;
|
|
74
|
-
augRef.dataset.state = open ? 'open' : 'closed';
|
|
75
|
-
augRef.type = 'button';
|
|
76
|
-
}
|
|
77
|
-
}, [open]);
|
|
78
|
-
|
|
79
|
-
const Component = asChild ? Slot.Pressable : Pressable;
|
|
80
|
-
return (
|
|
81
|
-
<Popover.Trigger disabled={disabled ?? undefined} asChild>
|
|
82
|
-
<Component
|
|
83
|
-
ref={augmentedRef}
|
|
84
|
-
onPress={onPress}
|
|
85
|
-
role='button'
|
|
86
|
-
disabled={disabled}
|
|
87
|
-
{...props}
|
|
88
|
-
/>
|
|
89
|
-
</Popover.Trigger>
|
|
90
|
-
);
|
|
91
|
-
}
|
|
92
|
-
);
|
|
93
|
-
|
|
94
|
-
Trigger.displayName = 'TriggerWebPopover';
|
|
95
|
-
|
|
96
|
-
function Portal({ forceMount, container, children }: PopoverPortalProps) {
|
|
97
|
-
return <Popover.Portal forceMount={forceMount} children={children} container={container} />;
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
const Overlay = React.forwardRef<PressableRef, SlottablePressableProps & PopoverOverlayProps>(
|
|
101
|
-
({ asChild, forceMount, ...props }, ref) => {
|
|
102
|
-
const Component = asChild ? Slot.Pressable : Pressable;
|
|
103
|
-
return <Component ref={ref} {...props} />;
|
|
104
|
-
}
|
|
105
|
-
);
|
|
106
|
-
|
|
107
|
-
Overlay.displayName = 'OverlayWebPopover';
|
|
108
|
-
|
|
109
|
-
const Content = React.forwardRef<ViewRef, SlottableViewProps & PositionedContentProps>(
|
|
110
|
-
(
|
|
111
|
-
{
|
|
112
|
-
asChild = false,
|
|
113
|
-
forceMount,
|
|
114
|
-
align = 'start',
|
|
115
|
-
side = 'bottom',
|
|
116
|
-
sideOffset = 0,
|
|
117
|
-
alignOffset = 0,
|
|
118
|
-
avoidCollisions = true,
|
|
119
|
-
insets: _insets,
|
|
120
|
-
disablePositioningStyle: _disablePositioningStyle,
|
|
121
|
-
onCloseAutoFocus,
|
|
122
|
-
onEscapeKeyDown,
|
|
123
|
-
onInteractOutside,
|
|
124
|
-
onPointerDownOutside,
|
|
125
|
-
...props
|
|
126
|
-
},
|
|
127
|
-
ref
|
|
128
|
-
) => {
|
|
129
|
-
const Component = asChild ? Slot.View : View;
|
|
130
|
-
return (
|
|
131
|
-
<Popover.Content
|
|
132
|
-
onCloseAutoFocus={onCloseAutoFocus}
|
|
133
|
-
onEscapeKeyDown={onEscapeKeyDown}
|
|
134
|
-
onInteractOutside={onInteractOutside}
|
|
135
|
-
onPointerDownOutside={onPointerDownOutside}
|
|
136
|
-
forceMount={forceMount}
|
|
137
|
-
align={align}
|
|
138
|
-
side={side}
|
|
139
|
-
sideOffset={sideOffset}
|
|
140
|
-
alignOffset={alignOffset}
|
|
141
|
-
avoidCollisions={avoidCollisions}
|
|
142
|
-
>
|
|
143
|
-
<Component ref={ref} {...props} />
|
|
144
|
-
</Popover.Content>
|
|
145
|
-
);
|
|
146
|
-
}
|
|
147
|
-
);
|
|
148
|
-
|
|
149
|
-
Content.displayName = 'ContentWebPopover';
|
|
150
|
-
|
|
151
|
-
const Close = React.forwardRef<PressableRef, SlottablePressableProps>(
|
|
152
|
-
({ asChild, onPress: onPressProp, disabled, ...props }, ref) => {
|
|
153
|
-
const augmentedRef = useAugmentedRef({ ref });
|
|
154
|
-
const { onOpenChange, open } = useRootContext();
|
|
155
|
-
|
|
156
|
-
function onPress(ev: GestureResponderEvent) {
|
|
157
|
-
if (onPressProp) {
|
|
158
|
-
onPressProp(ev);
|
|
159
|
-
}
|
|
160
|
-
onOpenChange(!open);
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
React.useLayoutEffect(() => {
|
|
164
|
-
if (augmentedRef.current) {
|
|
165
|
-
const augRef = augmentedRef.current as unknown as HTMLButtonElement;
|
|
166
|
-
augRef.type = 'button';
|
|
167
|
-
}
|
|
168
|
-
}, []);
|
|
169
|
-
|
|
170
|
-
const Component = asChild ? Slot.Pressable : Pressable;
|
|
171
|
-
return (
|
|
172
|
-
<>
|
|
173
|
-
<Popover.Close disabled={disabled ?? undefined} asChild>
|
|
174
|
-
<Component
|
|
175
|
-
ref={augmentedRef}
|
|
176
|
-
onPress={onPress}
|
|
177
|
-
role='button'
|
|
178
|
-
disabled={disabled}
|
|
179
|
-
{...props}
|
|
180
|
-
/>
|
|
181
|
-
</Popover.Close>
|
|
182
|
-
</>
|
|
183
|
-
);
|
|
184
|
-
}
|
|
185
|
-
);
|
|
186
|
-
|
|
187
|
-
Close.displayName = 'CloseWebPopover';
|
|
188
|
-
|
|
189
|
-
export { Close, Content, Overlay, Portal, Root, Trigger, useRootContext };
|
|
190
|
-
|
|
191
|
-
export type { PopoverTriggerRef };
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import type { ForceMountable, PressableRef } from '@rnr/types';
|
|
2
|
-
|
|
3
|
-
interface PopoverPortalProps extends ForceMountable {
|
|
4
|
-
children: React.ReactNode;
|
|
5
|
-
/**
|
|
6
|
-
* Platform: NATIVE ONLY
|
|
7
|
-
*/
|
|
8
|
-
hostName?: string;
|
|
9
|
-
/**
|
|
10
|
-
* Platform: WEB ONLY
|
|
11
|
-
*/
|
|
12
|
-
container?: HTMLElement | null | undefined;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
interface PopoverOverlayProps extends ForceMountable {
|
|
16
|
-
closeOnPress?: boolean;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
interface PopoverTriggerRef extends PressableRef {
|
|
20
|
-
open: () => void;
|
|
21
|
-
close: () => void;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
export type { PopoverOverlayProps, PopoverPortalProps, PopoverTriggerRef };
|
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
import * as React from 'react';
|
|
2
|
-
import { Platform, type View, type ViewStyle } from 'react-native';
|
|
3
|
-
import { create } from 'zustand';
|
|
4
|
-
|
|
5
|
-
const DEFAULT_PORTAL_HOST = 'INTERNAL_PRIMITIVE_DEFAULT_HOST_NAME';
|
|
6
|
-
|
|
7
|
-
type PortalMap = Map<string, React.ReactNode>;
|
|
8
|
-
type PortalHostMap = Map<string, PortalMap>;
|
|
9
|
-
|
|
10
|
-
const usePortal = create<{ map: PortalHostMap }>(() => ({
|
|
11
|
-
map: new Map<string, PortalMap>().set(DEFAULT_PORTAL_HOST, new Map<string, React.ReactNode>()),
|
|
12
|
-
}));
|
|
13
|
-
|
|
14
|
-
const updatePortal = (hostName: string, name: string, children: React.ReactNode) => {
|
|
15
|
-
usePortal.setState((prev) => {
|
|
16
|
-
const next = new Map(prev.map);
|
|
17
|
-
const portal = next.get(hostName) ?? new Map<string, React.ReactNode>();
|
|
18
|
-
portal.set(name, children);
|
|
19
|
-
next.set(hostName, portal);
|
|
20
|
-
return { map: next };
|
|
21
|
-
});
|
|
22
|
-
};
|
|
23
|
-
const removePortal = (hostName: string, name: string) => {
|
|
24
|
-
usePortal.setState((prev) => {
|
|
25
|
-
const next = new Map(prev.map);
|
|
26
|
-
const portal = next.get(hostName) ?? new Map<string, React.ReactNode>();
|
|
27
|
-
portal.delete(name);
|
|
28
|
-
next.set(hostName, portal);
|
|
29
|
-
return { map: next };
|
|
30
|
-
});
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
export function PortalHost({ name = DEFAULT_PORTAL_HOST }: { name?: string }) {
|
|
34
|
-
const portalMap = usePortal((state) => state.map).get(name) ?? new Map<string, React.ReactNode>();
|
|
35
|
-
if (portalMap.size === 0) return null;
|
|
36
|
-
return <>{Array.from(portalMap.values())}</>;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
export function Portal({
|
|
40
|
-
name,
|
|
41
|
-
hostName = DEFAULT_PORTAL_HOST,
|
|
42
|
-
children,
|
|
43
|
-
}: {
|
|
44
|
-
name: string;
|
|
45
|
-
hostName?: string;
|
|
46
|
-
children: React.ReactNode;
|
|
47
|
-
}) {
|
|
48
|
-
React.useEffect(() => {
|
|
49
|
-
updatePortal(hostName, name, children);
|
|
50
|
-
}, [hostName, name, children]);
|
|
51
|
-
|
|
52
|
-
React.useEffect(() => {
|
|
53
|
-
return () => {
|
|
54
|
-
removePortal(hostName, name);
|
|
55
|
-
};
|
|
56
|
-
}, [hostName, name]);
|
|
57
|
-
|
|
58
|
-
return null;
|
|
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
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './progress';
|
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
import * as React from 'react';
|
|
2
|
-
import { View } from 'react-native';
|
|
3
|
-
import * as Slot from '@rnr/slot';
|
|
4
|
-
import type { SlottableViewProps, ViewRef } from '@rnr/types';
|
|
5
|
-
import type { ProgressRootProps } from './types';
|
|
6
|
-
|
|
7
|
-
// This project uses code from WorkOS/Radix Primitives.
|
|
8
|
-
// The code is licensed under the MIT License.
|
|
9
|
-
// https://github.com/radix-ui/primitives/tree/main
|
|
10
|
-
|
|
11
|
-
const DEFAULT_MAX = 100;
|
|
12
|
-
|
|
13
|
-
const Root = React.forwardRef<ViewRef, SlottableViewProps & ProgressRootProps>(
|
|
14
|
-
(
|
|
15
|
-
{ asChild, value: valueProp, max: maxProp, getValueLabel = defaultGetValueLabel, ...props },
|
|
16
|
-
ref
|
|
17
|
-
) => {
|
|
18
|
-
const max = maxProp ?? DEFAULT_MAX;
|
|
19
|
-
const value = isValidValueNumber(valueProp, max) ? valueProp : 0;
|
|
20
|
-
|
|
21
|
-
const Component = asChild ? Slot.View : View;
|
|
22
|
-
return (
|
|
23
|
-
<Component
|
|
24
|
-
role='progressbar'
|
|
25
|
-
ref={ref}
|
|
26
|
-
aria-valuemax={max}
|
|
27
|
-
aria-valuemin={0}
|
|
28
|
-
aria-valuenow={value}
|
|
29
|
-
aria-valuetext={getValueLabel(value, max)}
|
|
30
|
-
accessibilityValue={{
|
|
31
|
-
min: 0,
|
|
32
|
-
max,
|
|
33
|
-
now: value,
|
|
34
|
-
text: getValueLabel(value, max),
|
|
35
|
-
}}
|
|
36
|
-
{...props}
|
|
37
|
-
/>
|
|
38
|
-
);
|
|
39
|
-
}
|
|
40
|
-
);
|
|
41
|
-
|
|
42
|
-
Root.displayName = 'RootProgress';
|
|
43
|
-
|
|
44
|
-
const Indicator = React.forwardRef<ViewRef, SlottableViewProps>(({ asChild, ...props }, ref) => {
|
|
45
|
-
const Component = asChild ? Slot.View : View;
|
|
46
|
-
return <Component ref={ref} role='presentation' {...props} />;
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
Indicator.displayName = 'IndicatorProgress';
|
|
50
|
-
|
|
51
|
-
export { Indicator, Root };
|
|
52
|
-
|
|
53
|
-
function defaultGetValueLabel(value: number, max: number) {
|
|
54
|
-
return `${Math.round((value / max) * 100)}%`;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
function isValidValueNumber(value: any, max: number): value is number {
|
|
58
|
-
return typeof value === 'number' && !isNaN(value) && value <= max && value >= 0;
|
|
59
|
-
}
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import * as Progress from '@radix-ui/react-progress';
|
|
2
|
-
import * as React from 'react';
|
|
3
|
-
import { View } from 'react-native';
|
|
4
|
-
import * as Slot from '@rnr/slot';
|
|
5
|
-
import type { SlottableViewProps, ViewRef } from '@rnr/types';
|
|
6
|
-
import type { ProgressRootProps } from './types';
|
|
7
|
-
|
|
8
|
-
const ProgressContext = React.createContext<ProgressRootProps | null>(null);
|
|
9
|
-
|
|
10
|
-
const Root = React.forwardRef<ViewRef, SlottableViewProps & ProgressRootProps>(
|
|
11
|
-
({ asChild, value, max, getValueLabel, ...props }, ref) => {
|
|
12
|
-
const Component = asChild ? Slot.View : View;
|
|
13
|
-
return (
|
|
14
|
-
<ProgressContext.Provider value={{ value, max }}>
|
|
15
|
-
<Progress.Root value={value} max={max} getValueLabel={getValueLabel} asChild>
|
|
16
|
-
<Component ref={ref} {...props} />
|
|
17
|
-
</Progress.Root>
|
|
18
|
-
</ProgressContext.Provider>
|
|
19
|
-
);
|
|
20
|
-
}
|
|
21
|
-
);
|
|
22
|
-
|
|
23
|
-
Root.displayName = 'RootProgress';
|
|
24
|
-
|
|
25
|
-
const Indicator = React.forwardRef<ViewRef, SlottableViewProps>(({ asChild, ...props }, ref) => {
|
|
26
|
-
const Component = asChild ? Slot.View : View;
|
|
27
|
-
return (
|
|
28
|
-
<Progress.Indicator asChild>
|
|
29
|
-
<Component ref={ref} {...props} />
|
|
30
|
-
</Progress.Indicator>
|
|
31
|
-
);
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
Indicator.displayName = 'IndicatorProgress';
|
|
35
|
-
|
|
36
|
-
export { Indicator, Root };
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './radio-group';
|