@brand-map/primitives 0.0.0-broken.0
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/.changeset/README.md +8 -0
- package/.changeset/config.json +11 -0
- package/.oxfmtrc.json +35 -0
- package/.oxlintrc.json +166 -0
- package/README.md +78 -0
- package/bun.lock +904 -0
- package/mise.toml +3 -0
- package/package.json +61 -0
- package/src/accordion/accordion.tsx +189 -0
- package/src/accordion/accordion.web.tsx +282 -0
- package/src/accordion/index.ts +2 -0
- package/src/accordion/types.ts +44 -0
- package/src/alert-dialog/alert-dialog.tsx +238 -0
- package/src/alert-dialog/alert-dialog.web.tsx +260 -0
- package/src/alert-dialog/index.ts +2 -0
- package/src/alert-dialog/types.ts +81 -0
- package/src/aspect-ratio/aspect-ratio.tsx +27 -0
- package/src/aspect-ratio/index.ts +1 -0
- package/src/avatar/avatar.tsx +122 -0
- package/src/avatar/index.ts +2 -0
- package/src/avatar/types.ts +20 -0
- package/src/checkbox/checkbox.tsx +95 -0
- package/src/checkbox/checkbox.web.tsx +111 -0
- package/src/checkbox/index.ts +2 -0
- package/src/checkbox/types.ts +14 -0
- package/src/collapsible/collapsible.tsx +98 -0
- package/src/collapsible/collapsible.web.tsx +149 -0
- package/src/collapsible/index.ts +2 -0
- package/src/collapsible/types.ts +23 -0
- package/src/context-menu/context-menu.tsx +616 -0
- package/src/context-menu/context-menu.web.tsx +560 -0
- package/src/context-menu/index.ts +2 -0
- package/src/context-menu/types.ts +136 -0
- package/src/dialog/dialog.tsx +286 -0
- package/src/dialog/dialog.web.tsx +215 -0
- package/src/dialog/index.ts +2 -0
- package/src/dialog/types.ts +92 -0
- package/src/dropdown-menu/dropdown-menu.tsx +575 -0
- package/src/dropdown-menu/dropdown-menu.web.tsx +565 -0
- package/src/dropdown-menu/index.ts +2 -0
- package/src/dropdown-menu/types.ts +121 -0
- package/src/hooks/index.ts +4 -0
- package/src/hooks/use-Isomorphic-layout-effect.tsx +12 -0
- package/src/hooks/use-augmented-ref.tsx +25 -0
- package/src/hooks/use-controllable-state.tsx +70 -0
- package/src/hooks/use-relative-position.tsx +175 -0
- package/src/hover-card/hover-card.tsx +255 -0
- package/src/hover-card/hover-card.web.tsx +161 -0
- package/src/hover-card/index.ts +2 -0
- package/src/hover-card/types.ts +56 -0
- package/src/label/index.ts +2 -0
- package/src/label/label.tsx +36 -0
- package/src/label/label.web.tsx +38 -0
- package/src/label/types.ts +24 -0
- package/src/menubar/index.ts +2 -0
- package/src/menubar/menubar.tsx +602 -0
- package/src/menubar/menubar.web.tsx +575 -0
- package/src/menubar/types.ts +126 -0
- package/src/navigation-menu/index.ts +2 -0
- package/src/navigation-menu/navigation-menu.tsx +302 -0
- package/src/navigation-menu/navigation-menu.web.tsx +259 -0
- package/src/navigation-menu/types.ts +85 -0
- package/src/popover/index.ts +2 -0
- package/src/popover/popover.tsx +279 -0
- package/src/popover/popover.web.tsx +217 -0
- package/src/popover/types.ts +44 -0
- package/src/portal/index.ts +1 -0
- package/src/portal/portal.tsx +56 -0
- package/src/progress/index.ts +2 -0
- package/src/progress/progress.tsx +59 -0
- package/src/progress/progress.web.tsx +46 -0
- package/src/progress/types.ts +14 -0
- package/src/radio-group/index.ts +2 -0
- package/src/radio-group/radio-group.tsx +106 -0
- package/src/radio-group/radio-group.web.tsx +85 -0
- package/src/radio-group/types.ts +24 -0
- package/src/select/index.ts +2 -0
- package/src/select/select.tsx +447 -0
- package/src/select/select.web.tsx +368 -0
- package/src/select/types.ts +145 -0
- package/src/separator/index.ts +2 -0
- package/src/separator/separator.tsx +21 -0
- package/src/separator/types.ts +10 -0
- package/src/slider/index.ts +2 -0
- package/src/slider/slider.tsx +77 -0
- package/src/slider/slider.web.tsx +75 -0
- package/src/slider/types.ts +39 -0
- package/src/slot/index.ts +1 -0
- package/src/slot/slot.tsx +224 -0
- package/src/switch/index.ts +2 -0
- package/src/switch/switch.tsx +49 -0
- package/src/switch/switch.web.tsx +60 -0
- package/src/switch/types.ts +19 -0
- package/src/table/index.ts +1 -0
- package/src/table/table.tsx +121 -0
- package/src/tabs/index.ts +2 -0
- package/src/tabs/tabs.tsx +120 -0
- package/src/tabs/tabs.web.tsx +106 -0
- package/src/tabs/types.ts +37 -0
- package/src/toast/index.ts +2 -0
- package/src/toast/toast.tsx +124 -0
- package/src/toast/types.ts +20 -0
- package/src/toggle/index.ts +2 -0
- package/src/toggle/toggle.tsx +35 -0
- package/src/toggle/toggle.web.tsx +36 -0
- package/src/toggle/types.ts +11 -0
- package/src/toggle-group/index.ts +2 -0
- package/src/toggle-group/toggle-group.tsx +100 -0
- package/src/toggle-group/toggle-group.web.tsx +103 -0
- package/src/toggle-group/types.ts +46 -0
- package/src/toolbar/index.ts +2 -0
- package/src/toolbar/toolbar.tsx +141 -0
- package/src/toolbar/toolbar.web.tsx +158 -0
- package/src/toolbar/types.ts +64 -0
- package/src/tooltip/index.ts +2 -0
- package/src/tooltip/tooltip.tsx +261 -0
- package/src/tooltip/tooltip.web.tsx +175 -0
- package/src/tooltip/types.ts +61 -0
- package/src/types/index.ts +141 -0
- package/src/utils/index.ts +69 -0
- package/tsconfig.json +23 -0
|
@@ -0,0 +1,286 @@
|
|
|
1
|
+
import { createContext, forwardRef, useId, useContext, useEffect } from "react";
|
|
2
|
+
import { BackHandler, GestureResponderEvent, Pressable, Text, View } from "react-native";
|
|
3
|
+
|
|
4
|
+
import { useControllableState } from "../hooks";
|
|
5
|
+
import { Portal as BrandMapPrimitivesPortal } from "../portal";
|
|
6
|
+
import * as Slot from "../slot";
|
|
7
|
+
import { RenderViewProps } from "../types";
|
|
8
|
+
|
|
9
|
+
import type {
|
|
10
|
+
CloseProps,
|
|
11
|
+
CloseRef,
|
|
12
|
+
ContentProps,
|
|
13
|
+
ContentRef,
|
|
14
|
+
DescriptionProps,
|
|
15
|
+
DescriptionRef,
|
|
16
|
+
BackdropProps,
|
|
17
|
+
BackdropRef,
|
|
18
|
+
PortalProps,
|
|
19
|
+
RootContext,
|
|
20
|
+
RootProps,
|
|
21
|
+
TitleProps,
|
|
22
|
+
TitleRef,
|
|
23
|
+
TriggerProps,
|
|
24
|
+
TriggerRef,
|
|
25
|
+
} from "./types";
|
|
26
|
+
|
|
27
|
+
const DialogContext = createContext<(RootContext & { nativeID: string }) | null>(null);
|
|
28
|
+
|
|
29
|
+
function useRootContext() {
|
|
30
|
+
const context = useContext(DialogContext);
|
|
31
|
+
if (!context) {
|
|
32
|
+
throw new Error("Dialog compound components cannot be rendered outside the Dialog component");
|
|
33
|
+
}
|
|
34
|
+
return context;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const Root = ({ open: openProp, defaultOpen, onOpenChange: onOpenChangeProp, children }: RootProps) => {
|
|
38
|
+
const nativeID = useId();
|
|
39
|
+
|
|
40
|
+
const [open = false, onOpenChange] = useControllableState({
|
|
41
|
+
prop: openProp,
|
|
42
|
+
defaultProp: defaultOpen,
|
|
43
|
+
onChange: onOpenChangeProp,
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
return <DialogContext.Provider value={{ open, onOpenChange, nativeID }}>{children}</DialogContext.Provider>;
|
|
47
|
+
};
|
|
48
|
+
Root.displayName = "RootNativeDialog";
|
|
49
|
+
|
|
50
|
+
const Popup = ({ render, ref, ...props }: RenderViewProps) => {
|
|
51
|
+
if (render) {
|
|
52
|
+
return (
|
|
53
|
+
<Slot.View
|
|
54
|
+
render={render}
|
|
55
|
+
ref={ref}
|
|
56
|
+
{...props}
|
|
57
|
+
/>
|
|
58
|
+
);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
return (
|
|
62
|
+
<View
|
|
63
|
+
ref={ref}
|
|
64
|
+
{...props}
|
|
65
|
+
/>
|
|
66
|
+
);
|
|
67
|
+
};
|
|
68
|
+
Popup.displayName = "PopupNativeDialog";
|
|
69
|
+
|
|
70
|
+
const Trigger = forwardRef<TriggerRef, TriggerProps>(({ onPress: onPressProp, disabled = false, ...props }, ref) => {
|
|
71
|
+
const { open, onOpenChange } = useRootContext();
|
|
72
|
+
|
|
73
|
+
function onPress(ev: GestureResponderEvent) {
|
|
74
|
+
if (disabled) return;
|
|
75
|
+
const newValue = !open;
|
|
76
|
+
onOpenChange(newValue);
|
|
77
|
+
onPressProp?.(ev);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
if (render) {
|
|
81
|
+
return (
|
|
82
|
+
<Slot.Pressable
|
|
83
|
+
render={render}
|
|
84
|
+
ref={ref}
|
|
85
|
+
aria-disabled={disabled ?? undefined}
|
|
86
|
+
role="button"
|
|
87
|
+
onPress={onPress}
|
|
88
|
+
disabled={disabled ?? undefined}
|
|
89
|
+
{...props}
|
|
90
|
+
/>
|
|
91
|
+
);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
return (
|
|
95
|
+
<Pressable
|
|
96
|
+
ref={ref}
|
|
97
|
+
aria-disabled={disabled ?? undefined}
|
|
98
|
+
role="button"
|
|
99
|
+
onPress={onPress}
|
|
100
|
+
disabled={disabled ?? undefined}
|
|
101
|
+
{...props}
|
|
102
|
+
/>
|
|
103
|
+
);
|
|
104
|
+
});
|
|
105
|
+
Trigger.displayName = "TriggerNativeDialog";
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* @warning when using a custom `<PortalHost />`, you might have to adjust the Content's sideOffset to account for nav elements like headers.
|
|
109
|
+
*/
|
|
110
|
+
function Portal({ keepMounted, hostName, children }: PortalProps) {
|
|
111
|
+
const rootContext = useRootContext();
|
|
112
|
+
|
|
113
|
+
if (!keepMounted) {
|
|
114
|
+
if (!rootContext.open) {
|
|
115
|
+
return null;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
return (
|
|
120
|
+
<BrandMapPrimitivesPortal
|
|
121
|
+
hostName={hostName}
|
|
122
|
+
name={`${rootContext.nativeID}-portal`}
|
|
123
|
+
>
|
|
124
|
+
<DialogContext.Provider value={rootContext}>{children}</DialogContext.Provider>
|
|
125
|
+
</BrandMapPrimitivesPortal>
|
|
126
|
+
);
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
const Backdrop = forwardRef<BackdropRef, BackdropProps>(({ keepMounted, closeOnPress = true, onPress: OnPressProp, ...props }, ref) => {
|
|
130
|
+
const { open, onOpenChange } = useRootContext();
|
|
131
|
+
|
|
132
|
+
function onPress(ev: GestureResponderEvent) {
|
|
133
|
+
if (closeOnPress) {
|
|
134
|
+
onOpenChange(!open);
|
|
135
|
+
}
|
|
136
|
+
OnPressProp?.(ev);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
if (!keepMounted) {
|
|
140
|
+
if (!open) {
|
|
141
|
+
return null;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
if (render) {
|
|
146
|
+
return (
|
|
147
|
+
<Slot.Pressable
|
|
148
|
+
render={render}
|
|
149
|
+
ref={ref}
|
|
150
|
+
onPress={onPress}
|
|
151
|
+
{...props}
|
|
152
|
+
/>
|
|
153
|
+
);
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
return (
|
|
157
|
+
<Pressable
|
|
158
|
+
ref={ref}
|
|
159
|
+
onPress={onPress}
|
|
160
|
+
{...props}
|
|
161
|
+
/>
|
|
162
|
+
);
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
Backdrop.displayName = "BackdropNativeDialog";
|
|
166
|
+
|
|
167
|
+
const Content = forwardRef<ContentRef, ContentProps>(({ keepMounted, ...props }, ref) => {
|
|
168
|
+
const { open, nativeID, onOpenChange } = useRootContext();
|
|
169
|
+
|
|
170
|
+
useEffect(() => {
|
|
171
|
+
const backHandler = BackHandler.addEventListener("hardwareBackPress", () => {
|
|
172
|
+
onOpenChange(false);
|
|
173
|
+
return true;
|
|
174
|
+
});
|
|
175
|
+
|
|
176
|
+
return () => {
|
|
177
|
+
backHandler.remove();
|
|
178
|
+
};
|
|
179
|
+
}, []);
|
|
180
|
+
|
|
181
|
+
if (!keepMounted) {
|
|
182
|
+
if (!open) {
|
|
183
|
+
return null;
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
if (render) {
|
|
188
|
+
return (
|
|
189
|
+
<Slot.Pressable
|
|
190
|
+
render={render}
|
|
191
|
+
ref={ref}
|
|
192
|
+
role="dialog"
|
|
193
|
+
nativeID={nativeID}
|
|
194
|
+
aria-labelledby={`${nativeID}_label`}
|
|
195
|
+
aria-describedby={`${nativeID}_desc`}
|
|
196
|
+
aria-modal={true}
|
|
197
|
+
onStartShouldSetResponder={onStartShouldSetResponder}
|
|
198
|
+
{...props}
|
|
199
|
+
/>
|
|
200
|
+
);
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
return (
|
|
204
|
+
<View
|
|
205
|
+
ref={ref}
|
|
206
|
+
role="dialog"
|
|
207
|
+
nativeID={nativeID}
|
|
208
|
+
aria-labelledby={`${nativeID}_label`}
|
|
209
|
+
aria-describedby={`${nativeID}_desc`}
|
|
210
|
+
aria-modal={true}
|
|
211
|
+
onStartShouldSetResponder={onStartShouldSetResponder}
|
|
212
|
+
{...props}
|
|
213
|
+
/>
|
|
214
|
+
);
|
|
215
|
+
});
|
|
216
|
+
|
|
217
|
+
Content.displayName = "ContentNativeDialog";
|
|
218
|
+
|
|
219
|
+
const Close = forwardRef<CloseRef, CloseProps>(({ onPress: onPressProp, disabled = false, ...props }, ref) => {
|
|
220
|
+
const { onOpenChange } = useRootContext();
|
|
221
|
+
|
|
222
|
+
function onPress(event: GestureResponderEvent) {
|
|
223
|
+
if (disabled) return;
|
|
224
|
+
onOpenChange(false);
|
|
225
|
+
onPressProp?.(event);
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
if (render) {
|
|
229
|
+
return (
|
|
230
|
+
<Slot.Pressable
|
|
231
|
+
ref={ref}
|
|
232
|
+
aria-disabled={disabled ?? undefined}
|
|
233
|
+
role="button"
|
|
234
|
+
onPress={onPress}
|
|
235
|
+
disabled={disabled ?? undefined}
|
|
236
|
+
{...props}
|
|
237
|
+
/>
|
|
238
|
+
);
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
return (
|
|
242
|
+
<Pressable
|
|
243
|
+
ref={ref}
|
|
244
|
+
aria-disabled={disabled ?? undefined}
|
|
245
|
+
role="button"
|
|
246
|
+
onPress={onPress}
|
|
247
|
+
disabled={disabled ?? undefined}
|
|
248
|
+
{...props}
|
|
249
|
+
/>
|
|
250
|
+
);
|
|
251
|
+
});
|
|
252
|
+
|
|
253
|
+
Close.displayName = "CloseNativeDialog";
|
|
254
|
+
|
|
255
|
+
const Title = forwardRef<TitleRef, TitleProps>((props, ref) => {
|
|
256
|
+
const { nativeID } = useRootContext();
|
|
257
|
+
return (
|
|
258
|
+
<Text
|
|
259
|
+
ref={ref}
|
|
260
|
+
role="heading"
|
|
261
|
+
nativeID={`${nativeID}_label`}
|
|
262
|
+
{...props}
|
|
263
|
+
/>
|
|
264
|
+
);
|
|
265
|
+
});
|
|
266
|
+
|
|
267
|
+
Title.displayName = "TitleNativeDialog";
|
|
268
|
+
|
|
269
|
+
const Description = forwardRef<DescriptionRef, DescriptionProps>((props, ref) => {
|
|
270
|
+
const { nativeID } = useRootContext();
|
|
271
|
+
return (
|
|
272
|
+
<Text
|
|
273
|
+
ref={ref}
|
|
274
|
+
nativeID={`${nativeID}_desc`}
|
|
275
|
+
{...props}
|
|
276
|
+
/>
|
|
277
|
+
);
|
|
278
|
+
});
|
|
279
|
+
|
|
280
|
+
Description.displayName = "DescriptionNativeDialog";
|
|
281
|
+
|
|
282
|
+
export { Close, Content, Description, Backdrop, Portal, Root, Title, Trigger, useRootContext };
|
|
283
|
+
|
|
284
|
+
function onStartShouldSetResponder() {
|
|
285
|
+
return true;
|
|
286
|
+
}
|
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
// // @ts-nocheck
|
|
2
|
+
|
|
3
|
+
// import * as Dialog from "@radix-ui/react-dialog";
|
|
4
|
+
// import * as React from "react";
|
|
5
|
+
// import { Pressable, Text, View, type GestureResponderEvent } from "react-native";
|
|
6
|
+
|
|
7
|
+
// import { useAugmentedRef, useControllableState, useIsomorphicLayoutEffect } from "../hooks";
|
|
8
|
+
// import * as Slot from "../slot";
|
|
9
|
+
|
|
10
|
+
// import type {
|
|
11
|
+
// CloseProps,
|
|
12
|
+
// CloseRef,
|
|
13
|
+
// ContentProps,
|
|
14
|
+
// ContentRef,
|
|
15
|
+
// DescriptionProps,
|
|
16
|
+
// DescriptionRef,
|
|
17
|
+
// BackdropProps,
|
|
18
|
+
// BackdropRef,
|
|
19
|
+
// PortalProps,
|
|
20
|
+
// RootContext,
|
|
21
|
+
// RootProps,
|
|
22
|
+
// RootRef,
|
|
23
|
+
// TitleProps,
|
|
24
|
+
// TitleRef,
|
|
25
|
+
// TriggerProps,
|
|
26
|
+
// TriggerRef,
|
|
27
|
+
// } from "./types";
|
|
28
|
+
|
|
29
|
+
// const DialogContext = React.createContext<RootContext | null>(null);
|
|
30
|
+
|
|
31
|
+
// const Root = React.forwardRef<RootRef, RootProps>(({ open: openProp, defaultOpen, onOpenChange: onOpenChangeProp, ...viewProps }, ref) => {
|
|
32
|
+
// const [open = false, onOpenChange] = useControllableState({
|
|
33
|
+
// prop: openProp,
|
|
34
|
+
// defaultProp: defaultOpen,
|
|
35
|
+
// onChange: onOpenChangeProp,
|
|
36
|
+
// });
|
|
37
|
+
//
|
|
38
|
+
// return (
|
|
39
|
+
// <DialogContext.Provider value={{ open, onOpenChange }}>
|
|
40
|
+
// <Dialog.Root
|
|
41
|
+
// open={open}
|
|
42
|
+
// defaultOpen={defaultOpen}
|
|
43
|
+
// onOpenChange={onOpenChange}
|
|
44
|
+
// >
|
|
45
|
+
// <Component
|
|
46
|
+
// ref={ref}
|
|
47
|
+
// {...viewProps}
|
|
48
|
+
// />
|
|
49
|
+
// </Dialog.Root>
|
|
50
|
+
// </DialogContext.Provider>
|
|
51
|
+
// );
|
|
52
|
+
// });
|
|
53
|
+
|
|
54
|
+
// Root.displayName = "RootWebDialog";
|
|
55
|
+
|
|
56
|
+
// function useRootContext() {
|
|
57
|
+
// const context = React.useContext(DialogContext);
|
|
58
|
+
// if (!context) {
|
|
59
|
+
// throw new Error("Dialog compound components cannot be rendered outside the Dialog component");
|
|
60
|
+
// }
|
|
61
|
+
// return context;
|
|
62
|
+
// }
|
|
63
|
+
|
|
64
|
+
// const Trigger = React.forwardRef<TriggerRef, TriggerProps>(({ onPress: onPressProp, role: _role, disabled, ...props }, ref) => {
|
|
65
|
+
// const augmentedRef = useAugmentedRef({ ref });
|
|
66
|
+
// const { onOpenChange, open } = useRootContext();
|
|
67
|
+
// function onPress(ev: GestureResponderEvent) {
|
|
68
|
+
// if (onPressProp) {
|
|
69
|
+
// onPressProp(ev);
|
|
70
|
+
// }
|
|
71
|
+
// onOpenChange(!open);
|
|
72
|
+
// }
|
|
73
|
+
|
|
74
|
+
// useIsomorphicLayoutEffect(() => {
|
|
75
|
+
// if (augmentedRef.current) {
|
|
76
|
+
// const augRef = augmentedRef.current as unknown as HTMLButtonElement;
|
|
77
|
+
// augRef.dataset.state = open ? "open" : "closed";
|
|
78
|
+
// augRef.type = "button";
|
|
79
|
+
// }
|
|
80
|
+
// }, [open]);
|
|
81
|
+
|
|
82
|
+
//
|
|
83
|
+
// return (
|
|
84
|
+
// <Dialog.Trigger
|
|
85
|
+
// disabled={disabled ?? undefined}
|
|
86
|
+
// render
|
|
87
|
+
// >
|
|
88
|
+
// <Component
|
|
89
|
+
// ref={augmentedRef}
|
|
90
|
+
// onPress={onPress}
|
|
91
|
+
// role="button"
|
|
92
|
+
// disabled={disabled}
|
|
93
|
+
// {...props}
|
|
94
|
+
// />
|
|
95
|
+
// </Dialog.Trigger>
|
|
96
|
+
// );
|
|
97
|
+
// });
|
|
98
|
+
|
|
99
|
+
// Trigger.displayName = "TriggerWebDialog";
|
|
100
|
+
|
|
101
|
+
// function Portal({ keepMounted, container, children }: PortalProps) {
|
|
102
|
+
// return (
|
|
103
|
+
// <Dialog.Portal
|
|
104
|
+
// keepMounted={keepMounted}
|
|
105
|
+
// children={children}
|
|
106
|
+
// container={container}
|
|
107
|
+
// />
|
|
108
|
+
// );
|
|
109
|
+
// }
|
|
110
|
+
|
|
111
|
+
// const Backdrop = React.forwardRef<BackdropRef, BackdropProps>(({ keepMounted, ...props }, ref) => {
|
|
112
|
+
//
|
|
113
|
+
// return (
|
|
114
|
+
// <Dialog.Backdrop keepMounted={keepMounted}>
|
|
115
|
+
// <Component
|
|
116
|
+
// ref={ref}
|
|
117
|
+
// {...props}
|
|
118
|
+
// />
|
|
119
|
+
// </Dialog.Backdrop>
|
|
120
|
+
// );
|
|
121
|
+
// });
|
|
122
|
+
|
|
123
|
+
// Backdrop.displayName = "BackdropWebDialog";
|
|
124
|
+
|
|
125
|
+
// const Content = React.forwardRef<ContentRef, ContentProps>(
|
|
126
|
+
// ({ render, keepMounted, onOpenAutoFocus, onCloseAutoFocus, onEscapeKeyDown, onInteractOutside, onPointerDownOutside, ...props }, ref) => {
|
|
127
|
+
//
|
|
128
|
+
// return (
|
|
129
|
+
// <Dialog.Content
|
|
130
|
+
// onOpenAutoFocus={onOpenAutoFocus}
|
|
131
|
+
// onCloseAutoFocus={onCloseAutoFocus}
|
|
132
|
+
// onEscapeKeyDown={onEscapeKeyDown}
|
|
133
|
+
// onInteractOutside={onInteractOutside}
|
|
134
|
+
// onPointerDownOutside={onPointerDownOutside}
|
|
135
|
+
// keepMounted={keepMounted}
|
|
136
|
+
// >
|
|
137
|
+
// <Component
|
|
138
|
+
// ref={ref}
|
|
139
|
+
// {...props}
|
|
140
|
+
// />
|
|
141
|
+
// </Dialog.Content>
|
|
142
|
+
// );
|
|
143
|
+
// },
|
|
144
|
+
// );
|
|
145
|
+
|
|
146
|
+
// Content.displayName = "ContentWebDialog";
|
|
147
|
+
|
|
148
|
+
// const Close = React.forwardRef<CloseRef, CloseProps>(({ onPress: onPressProp, disabled, ...props }, ref) => {
|
|
149
|
+
// const augmentedRef = useAugmentedRef({ ref });
|
|
150
|
+
// const { onOpenChange, open } = useRootContext();
|
|
151
|
+
|
|
152
|
+
// function onPress(ev: GestureResponderEvent) {
|
|
153
|
+
// if (onPressProp) {
|
|
154
|
+
// onPressProp(ev);
|
|
155
|
+
// }
|
|
156
|
+
// onOpenChange(!open);
|
|
157
|
+
// }
|
|
158
|
+
|
|
159
|
+
// useIsomorphicLayoutEffect(() => {
|
|
160
|
+
// if (augmentedRef.current) {
|
|
161
|
+
// const augRef = augmentedRef.current as unknown as HTMLButtonElement;
|
|
162
|
+
// augRef.type = "button";
|
|
163
|
+
// }
|
|
164
|
+
// }, []);
|
|
165
|
+
|
|
166
|
+
//
|
|
167
|
+
// return (
|
|
168
|
+
// <>
|
|
169
|
+
// <Dialog.Close
|
|
170
|
+
// disabled={disabled ?? undefined}
|
|
171
|
+
// render
|
|
172
|
+
// >
|
|
173
|
+
// <Component
|
|
174
|
+
// ref={augmentedRef}
|
|
175
|
+
// onPress={onPress}
|
|
176
|
+
// role="button"
|
|
177
|
+
// disabled={disabled}
|
|
178
|
+
// {...props}
|
|
179
|
+
// />
|
|
180
|
+
// </Dialog.Close>
|
|
181
|
+
// </>
|
|
182
|
+
// );
|
|
183
|
+
// });
|
|
184
|
+
|
|
185
|
+
// Close.displayName = "CloseWebDialog";
|
|
186
|
+
|
|
187
|
+
// const Title = React.forwardRef<TitleRef, TitleProps>(({ ...props }, ref) => {
|
|
188
|
+
//
|
|
189
|
+
// return (
|
|
190
|
+
// <Dialog.Title render>
|
|
191
|
+
// <Component
|
|
192
|
+
// ref={ref}
|
|
193
|
+
// {...props}
|
|
194
|
+
// />
|
|
195
|
+
// </Dialog.Title>
|
|
196
|
+
// );
|
|
197
|
+
// });
|
|
198
|
+
|
|
199
|
+
// Title.displayName = "TitleWebDialog";
|
|
200
|
+
|
|
201
|
+
// const Description = React.forwardRef<DescriptionRef, DescriptionProps>(({ ...props }, ref) => {
|
|
202
|
+
//
|
|
203
|
+
// return (
|
|
204
|
+
// <Dialog.Description render>
|
|
205
|
+
// <Component
|
|
206
|
+
// ref={ref}
|
|
207
|
+
// {...props}
|
|
208
|
+
// />
|
|
209
|
+
// </Dialog.Description>
|
|
210
|
+
// );
|
|
211
|
+
// });
|
|
212
|
+
|
|
213
|
+
// Description.displayName = "DescriptionWebDialog";
|
|
214
|
+
|
|
215
|
+
// export { Close, Content, Description, Backdrop, Portal, Root, Title, Trigger, useRootContext };
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import type { KeepMountable, PressableRef, RenderPressableProps, RenderTextProps, RenderViewProps, TextRef, ViewRef } from "../types";
|
|
2
|
+
|
|
3
|
+
type RootContext = {
|
|
4
|
+
open: boolean;
|
|
5
|
+
onOpenChange: (value: boolean) => void;
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
type RootProps = React.PropsWithChildren & {
|
|
9
|
+
open?: boolean;
|
|
10
|
+
defaultOpen?: boolean;
|
|
11
|
+
onOpenChange?: (value: boolean) => void;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
interface PortalProps extends KeepMountable {
|
|
15
|
+
children: React.ReactNode;
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* @platform: NATIVE ONLY
|
|
19
|
+
*/
|
|
20
|
+
hostName?: string;
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* @platform: WEB ONLY
|
|
24
|
+
*/
|
|
25
|
+
container?: HTMLElement | null | undefined;
|
|
26
|
+
}
|
|
27
|
+
type BackdropProps = KeepMountable &
|
|
28
|
+
RenderPressableProps & {
|
|
29
|
+
/**
|
|
30
|
+
* @platform: NATIVE ONLY - default: true
|
|
31
|
+
*/
|
|
32
|
+
closeOnPress?: boolean;
|
|
33
|
+
};
|
|
34
|
+
type ContentProps = KeepMountable &
|
|
35
|
+
RenderViewProps & {
|
|
36
|
+
/**
|
|
37
|
+
* @platform: WEB ONLY
|
|
38
|
+
*/
|
|
39
|
+
onOpenAutoFocus?: (ev: Event) => void;
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* @platform: WEB ONLY
|
|
43
|
+
*/
|
|
44
|
+
onCloseAutoFocus?: (ev: Event) => void;
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* @platform: WEB ONLY
|
|
48
|
+
*/
|
|
49
|
+
onEscapeKeyDown?: (ev: Event) => void;
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* @platform: WEB ONLY
|
|
53
|
+
*/
|
|
54
|
+
onInteractOutside?: (ev: Event) => void;
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* @platform: WEB ONLY
|
|
58
|
+
*/
|
|
59
|
+
onPointerDownOutside?: (ev: Event) => void;
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
type TriggerProps = RenderPressableProps;
|
|
63
|
+
type CloseProps = RenderPressableProps;
|
|
64
|
+
type TitleProps = RenderTextProps;
|
|
65
|
+
type DescriptionProps = RenderTextProps;
|
|
66
|
+
|
|
67
|
+
type CloseRef = PressableRef;
|
|
68
|
+
type ContentRef = ViewRef;
|
|
69
|
+
type DescriptionRef = TextRef;
|
|
70
|
+
type BackdropRef = PressableRef;
|
|
71
|
+
type RootRef = ViewRef;
|
|
72
|
+
type TitleRef = TextRef;
|
|
73
|
+
type TriggerRef = PressableRef;
|
|
74
|
+
|
|
75
|
+
export type {
|
|
76
|
+
CloseProps,
|
|
77
|
+
CloseRef,
|
|
78
|
+
ContentProps,
|
|
79
|
+
ContentRef,
|
|
80
|
+
DescriptionProps,
|
|
81
|
+
DescriptionRef,
|
|
82
|
+
BackdropProps,
|
|
83
|
+
BackdropRef,
|
|
84
|
+
PortalProps,
|
|
85
|
+
RootContext,
|
|
86
|
+
RootProps,
|
|
87
|
+
RootRef,
|
|
88
|
+
TitleProps,
|
|
89
|
+
TitleRef,
|
|
90
|
+
TriggerProps,
|
|
91
|
+
TriggerRef,
|
|
92
|
+
};
|