@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,560 @@
|
|
|
1
|
+
// import * as ContextMenu from "@radix-ui/react-context-menu";
|
|
2
|
+
// import * as React from "react";
|
|
3
|
+
// import { GestureResponderEvent, Pressable, Text, View } from "react-native";
|
|
4
|
+
|
|
5
|
+
// import { useAugmentedRef, useControllableState, useIsomorphicLayoutEffect } from "../hooks";
|
|
6
|
+
// import * as Slot from "../slot";
|
|
7
|
+
// import { EmptyGestureResponderEvent } from "../utils";
|
|
8
|
+
|
|
9
|
+
// import type {
|
|
10
|
+
// CheckboxItemProps,
|
|
11
|
+
// CheckboxItemRef,
|
|
12
|
+
// ContentProps,
|
|
13
|
+
// ContentRef,
|
|
14
|
+
// GroupProps,
|
|
15
|
+
// GroupRef,
|
|
16
|
+
// ItemIndicatorProps,
|
|
17
|
+
// ItemIndicatorRef,
|
|
18
|
+
// ItemProps,
|
|
19
|
+
// ItemRef,
|
|
20
|
+
// LabelProps,
|
|
21
|
+
// LabelRef,
|
|
22
|
+
// BackdropProps,
|
|
23
|
+
// BackdropRef,
|
|
24
|
+
// PortalProps,
|
|
25
|
+
// RadioGroupProps,
|
|
26
|
+
// RadioGroupRef,
|
|
27
|
+
// RadioItemProps,
|
|
28
|
+
// RadioItemRef,
|
|
29
|
+
// RootProps,
|
|
30
|
+
// RootRef,
|
|
31
|
+
// SeparatorProps,
|
|
32
|
+
// SeparatorRef,
|
|
33
|
+
// SubContentProps,
|
|
34
|
+
// SubContentRef,
|
|
35
|
+
// SubProps,
|
|
36
|
+
// SubRef,
|
|
37
|
+
// SubTriggerProps,
|
|
38
|
+
// SubTriggerRef,
|
|
39
|
+
// TriggerProps,
|
|
40
|
+
// TriggerRef,
|
|
41
|
+
// } from "./types";
|
|
42
|
+
|
|
43
|
+
// const ContextMenuContext = React.createContext<{
|
|
44
|
+
// open: boolean;
|
|
45
|
+
// onOpenChange: (open: boolean) => void;
|
|
46
|
+
// } | null>(null);
|
|
47
|
+
|
|
48
|
+
// const Root = React.forwardRef<RootRef, RootProps>(({ onOpenChange: onOpenChangeProp, ...viewProps }, ref) => {
|
|
49
|
+
// const [open, setOpen] = React.useState(false);
|
|
50
|
+
|
|
51
|
+
// function onOpenChange(value: boolean) {
|
|
52
|
+
// setOpen(value);
|
|
53
|
+
// onOpenChangeProp?.(value);
|
|
54
|
+
// }
|
|
55
|
+
|
|
56
|
+
//
|
|
57
|
+
// return (
|
|
58
|
+
// <ContextMenuContext.Provider value={{ open, onOpenChange }}>
|
|
59
|
+
// <ContextMenu.Root onOpenChange={onOpenChange}>
|
|
60
|
+
// <Component
|
|
61
|
+
// ref={ref}
|
|
62
|
+
// {...viewProps}
|
|
63
|
+
// />
|
|
64
|
+
// </ContextMenu.Root>
|
|
65
|
+
// </ContextMenuContext.Provider>
|
|
66
|
+
// );
|
|
67
|
+
// });
|
|
68
|
+
|
|
69
|
+
// Root.displayName = "RootWebContextMenu";
|
|
70
|
+
|
|
71
|
+
// function useRootContext() {
|
|
72
|
+
// const context = React.useContext(ContextMenuContext);
|
|
73
|
+
// if (!context) {
|
|
74
|
+
// throw new Error("ContextMenu compound components cannot be rendered outside the ContextMenu component");
|
|
75
|
+
// }
|
|
76
|
+
// return context;
|
|
77
|
+
// }
|
|
78
|
+
|
|
79
|
+
// const Trigger = React.forwardRef<TriggerRef, TriggerProps>(({ disabled = false, ...props }, ref) => {
|
|
80
|
+
// const { open } = useRootContext();
|
|
81
|
+
// const augmentedRef = useAugmentedRef({
|
|
82
|
+
// ref,
|
|
83
|
+
// methods: {
|
|
84
|
+
// open() {
|
|
85
|
+
// console.warn("Warning: `open()` is only for Native platforms");
|
|
86
|
+
// },
|
|
87
|
+
// close() {
|
|
88
|
+
// console.warn("Warning: `close()` is only for Native platforms");
|
|
89
|
+
// },
|
|
90
|
+
// },
|
|
91
|
+
// });
|
|
92
|
+
|
|
93
|
+
// useIsomorphicLayoutEffect(() => {
|
|
94
|
+
// if (augmentedRef.current) {
|
|
95
|
+
// const augRef = augmentedRef.current as unknown as HTMLDivElement;
|
|
96
|
+
// augRef.dataset.state = open ? "open" : "closed";
|
|
97
|
+
// }
|
|
98
|
+
// }, [open]);
|
|
99
|
+
|
|
100
|
+
// useIsomorphicLayoutEffect(() => {
|
|
101
|
+
// if (augmentedRef.current) {
|
|
102
|
+
// const augRef = augmentedRef.current as unknown as HTMLDivElement;
|
|
103
|
+
// if (disabled) {
|
|
104
|
+
// augRef.dataset.disabled = "true";
|
|
105
|
+
// } else {
|
|
106
|
+
// augRef.dataset.disabled = undefined;
|
|
107
|
+
// }
|
|
108
|
+
// }
|
|
109
|
+
// }, [disabled]);
|
|
110
|
+
|
|
111
|
+
//
|
|
112
|
+
// return (
|
|
113
|
+
// <ContextMenu.Trigger
|
|
114
|
+
// disabled={disabled ?? undefined}
|
|
115
|
+
// render
|
|
116
|
+
// >
|
|
117
|
+
// <Component
|
|
118
|
+
// ref={augmentedRef}
|
|
119
|
+
// disabled={disabled}
|
|
120
|
+
// {...props}
|
|
121
|
+
// />
|
|
122
|
+
// </ContextMenu.Trigger>
|
|
123
|
+
// );
|
|
124
|
+
// });
|
|
125
|
+
|
|
126
|
+
// Trigger.displayName = "TriggerWebContextMenu";
|
|
127
|
+
|
|
128
|
+
// function Portal({ keepMounted, container, children }: PortalProps) {
|
|
129
|
+
// return (
|
|
130
|
+
// <ContextMenu.Portal
|
|
131
|
+
// keepMounted={keepMounted}
|
|
132
|
+
// container={container}
|
|
133
|
+
// children={children}
|
|
134
|
+
// />
|
|
135
|
+
// );
|
|
136
|
+
// }
|
|
137
|
+
|
|
138
|
+
// const Backdrop = React.forwardRef<BackdropRef, BackdropProps>(({ ...props }, ref) => {
|
|
139
|
+
//
|
|
140
|
+
// return (
|
|
141
|
+
// <Component
|
|
142
|
+
// ref={ref}
|
|
143
|
+
// {...props}
|
|
144
|
+
// />
|
|
145
|
+
// );
|
|
146
|
+
// });
|
|
147
|
+
|
|
148
|
+
// Backdrop.displayName = "BackdropWebContextMenu";
|
|
149
|
+
|
|
150
|
+
// const ContextMenuContentContext = React.createContext<{
|
|
151
|
+
// close: () => void;
|
|
152
|
+
// } | null>(null);
|
|
153
|
+
|
|
154
|
+
// const Content = React.forwardRef<ContentRef, ContentProps>(
|
|
155
|
+
// (
|
|
156
|
+
// {
|
|
157
|
+
// render = false,
|
|
158
|
+
// keepMounted,
|
|
159
|
+
// align: _align,
|
|
160
|
+
// side: _side,
|
|
161
|
+
// sideOffset: _sideOffset,
|
|
162
|
+
// alignOffset = 0,
|
|
163
|
+
// avoidCollisions = true,
|
|
164
|
+
// insets,
|
|
165
|
+
// loop = true,
|
|
166
|
+
// onCloseAutoFocus,
|
|
167
|
+
// onEscapeKeyDown,
|
|
168
|
+
// onPointerDownOutside,
|
|
169
|
+
// onFocusOutside,
|
|
170
|
+
// onInteractOutside,
|
|
171
|
+
// collisionBoundary,
|
|
172
|
+
// sticky,
|
|
173
|
+
// hideWhenDetached,
|
|
174
|
+
// ...props
|
|
175
|
+
// },
|
|
176
|
+
// ref,
|
|
177
|
+
// ) => {
|
|
178
|
+
// const itemRef = React.useRef<HTMLDivElement>(null);
|
|
179
|
+
|
|
180
|
+
// function close() {
|
|
181
|
+
// itemRef.current?.click();
|
|
182
|
+
// }
|
|
183
|
+
|
|
184
|
+
//
|
|
185
|
+
// return (
|
|
186
|
+
// <ContextMenuContentContext.Provider value={{ close }}>
|
|
187
|
+
// <ContextMenu.Content
|
|
188
|
+
// keepMounted={keepMounted}
|
|
189
|
+
// alignOffset={alignOffset}
|
|
190
|
+
// avoidCollisions={avoidCollisions}
|
|
191
|
+
// collisionPadding={insets}
|
|
192
|
+
// loop={loop}
|
|
193
|
+
// onCloseAutoFocus={onCloseAutoFocus}
|
|
194
|
+
// onEscapeKeyDown={onEscapeKeyDown}
|
|
195
|
+
// onPointerDownOutside={onPointerDownOutside}
|
|
196
|
+
// onFocusOutside={onFocusOutside}
|
|
197
|
+
// onInteractOutside={onInteractOutside}
|
|
198
|
+
// collisionBoundary={collisionBoundary}
|
|
199
|
+
// sticky={sticky}
|
|
200
|
+
// hideWhenDetached={hideWhenDetached}
|
|
201
|
+
// >
|
|
202
|
+
// <Component
|
|
203
|
+
// ref={ref}
|
|
204
|
+
// {...props}
|
|
205
|
+
// />
|
|
206
|
+
// <ContextMenu.Item
|
|
207
|
+
// ref={itemRef}
|
|
208
|
+
// aria-hidden
|
|
209
|
+
// style={{ position: "fixed", top: 0, left: 0, zIndex: -999999999 }}
|
|
210
|
+
// aria-disabled
|
|
211
|
+
// tabIndex={-1}
|
|
212
|
+
// hidden
|
|
213
|
+
// />
|
|
214
|
+
// </ContextMenu.Content>
|
|
215
|
+
// </ContextMenuContentContext.Provider>
|
|
216
|
+
// );
|
|
217
|
+
// },
|
|
218
|
+
// );
|
|
219
|
+
|
|
220
|
+
// Content.displayName = "ContentWebContextMenu";
|
|
221
|
+
|
|
222
|
+
// function useContextMenuContentContext() {
|
|
223
|
+
// const context = React.useContext(ContextMenuContentContext);
|
|
224
|
+
// if (!context) {
|
|
225
|
+
// throw new Error("ContextMenu compound components cannot be rendered outside the ContextMenu component");
|
|
226
|
+
// }
|
|
227
|
+
// return context;
|
|
228
|
+
// }
|
|
229
|
+
|
|
230
|
+
// const Item = React.forwardRef<ItemRef, ItemProps>(({ textValue, closeOnPress = true, onPress: onPressProp, ...props }, ref) => {
|
|
231
|
+
// const { close } = useContextMenuContentContext();
|
|
232
|
+
|
|
233
|
+
// function onKeyDown(ev: React.KeyboardEvent) {
|
|
234
|
+
// if (ev.key === "Enter" || ev.key === " ") {
|
|
235
|
+
// onPressProp?.(EmptyGestureResponderEvent);
|
|
236
|
+
// if (closeOnPress) {
|
|
237
|
+
// close();
|
|
238
|
+
// }
|
|
239
|
+
// }
|
|
240
|
+
// }
|
|
241
|
+
|
|
242
|
+
// function onPress(ev: GestureResponderEvent) {
|
|
243
|
+
// onPressProp?.(ev);
|
|
244
|
+
// if (closeOnPress) {
|
|
245
|
+
// close();
|
|
246
|
+
// }
|
|
247
|
+
// }
|
|
248
|
+
|
|
249
|
+
//
|
|
250
|
+
// return (
|
|
251
|
+
// <ContextMenu.Item
|
|
252
|
+
// textValue={textValue}
|
|
253
|
+
// disabled={props.disabled ?? undefined}
|
|
254
|
+
// onSelect={closeOnPress ? undefined : onSelected}
|
|
255
|
+
// render
|
|
256
|
+
// >
|
|
257
|
+
// <Component
|
|
258
|
+
// ref={ref}
|
|
259
|
+
// role="button"
|
|
260
|
+
// onPress={onPress}
|
|
261
|
+
// onKeyDown={onKeyDown}
|
|
262
|
+
// {...props}
|
|
263
|
+
// />
|
|
264
|
+
// </ContextMenu.Item>
|
|
265
|
+
// );
|
|
266
|
+
// });
|
|
267
|
+
|
|
268
|
+
// Item.displayName = "ItemWebContextMenu";
|
|
269
|
+
|
|
270
|
+
// const Group = React.forwardRef<GroupRef, GroupProps>(({ ...props }, ref) => {
|
|
271
|
+
//
|
|
272
|
+
// return (
|
|
273
|
+
// <ContextMenu.Group render>
|
|
274
|
+
// <Component
|
|
275
|
+
// ref={ref}
|
|
276
|
+
// {...props}
|
|
277
|
+
// />
|
|
278
|
+
// </ContextMenu.Group>
|
|
279
|
+
// );
|
|
280
|
+
// });
|
|
281
|
+
|
|
282
|
+
// Group.displayName = "GroupWebContextMenu";
|
|
283
|
+
|
|
284
|
+
// const Label = React.forwardRef<LabelRef, LabelProps>(({ ...props }, ref) => {
|
|
285
|
+
//
|
|
286
|
+
// return (
|
|
287
|
+
// <ContextMenu.Label render>
|
|
288
|
+
// <Component
|
|
289
|
+
// ref={ref}
|
|
290
|
+
// {...props}
|
|
291
|
+
// />
|
|
292
|
+
// </ContextMenu.Label>
|
|
293
|
+
// );
|
|
294
|
+
// });
|
|
295
|
+
|
|
296
|
+
// Label.displayName = "LabelWebContextMenu";
|
|
297
|
+
|
|
298
|
+
// const CheckboxItem = React.forwardRef<CheckboxItemRef, CheckboxItemProps>(
|
|
299
|
+
// ({ render, checked, onCheckedChange, textValue, disabled = false, closeOnPress = true, onPress: onPressProp, onKeyDown: onKeyDownProp, ...props }, ref) => {
|
|
300
|
+
// const { close } = useContextMenuContentContext();
|
|
301
|
+
|
|
302
|
+
// function onKeyDown(ev: React.KeyboardEvent) {
|
|
303
|
+
// onKeyDownProp?.(ev);
|
|
304
|
+
// if (ev.key === "Enter" || ev.key === " ") {
|
|
305
|
+
// onPressProp?.(EmptyGestureResponderEvent);
|
|
306
|
+
// onCheckedChange?.(!checked);
|
|
307
|
+
// if (closeOnPress) {
|
|
308
|
+
// close();
|
|
309
|
+
// }
|
|
310
|
+
// }
|
|
311
|
+
// }
|
|
312
|
+
|
|
313
|
+
// function onPress(ev: GestureResponderEvent) {
|
|
314
|
+
// onPressProp?.(ev);
|
|
315
|
+
// onCheckedChange?.(!checked);
|
|
316
|
+
// if (closeOnPress) {
|
|
317
|
+
// close();
|
|
318
|
+
// }
|
|
319
|
+
// }
|
|
320
|
+
|
|
321
|
+
//
|
|
322
|
+
// return (
|
|
323
|
+
// <ContextMenu.CheckboxItem
|
|
324
|
+
// textValue={textValue}
|
|
325
|
+
// checked={checked}
|
|
326
|
+
// onCheckedChange={onCheckedChange}
|
|
327
|
+
// onSelect={closeOnPress ? undefined : onSelected}
|
|
328
|
+
// disabled={disabled ?? undefined}
|
|
329
|
+
// render
|
|
330
|
+
// >
|
|
331
|
+
// <Component
|
|
332
|
+
// ref={ref}
|
|
333
|
+
// disabled={disabled}
|
|
334
|
+
// // @ts-expect-error web only
|
|
335
|
+
// onKeyDown={onKeyDown}
|
|
336
|
+
// onPress={onPress}
|
|
337
|
+
// role="button"
|
|
338
|
+
// {...props}
|
|
339
|
+
// />
|
|
340
|
+
// </ContextMenu.CheckboxItem>
|
|
341
|
+
// );
|
|
342
|
+
// },
|
|
343
|
+
// );
|
|
344
|
+
|
|
345
|
+
// CheckboxItem.displayName = "CheckboxItemWebContextMenu";
|
|
346
|
+
|
|
347
|
+
// const ContextMenuRadioGroupContext = React.createContext<{
|
|
348
|
+
// value?: string;
|
|
349
|
+
// onValueChange?: (value: string) => void;
|
|
350
|
+
// } | null>(null);
|
|
351
|
+
|
|
352
|
+
// const RadioGroup = React.forwardRef<RadioGroupRef, RadioGroupProps>(({ value, onValueChange, ...props }, ref) => {
|
|
353
|
+
//
|
|
354
|
+
// return (
|
|
355
|
+
// <ContextMenuRadioGroupContext.Provider value={{ value, onValueChange }}>
|
|
356
|
+
// <ContextMenu.RadioGroup
|
|
357
|
+
// value={value}
|
|
358
|
+
// onValueChange={onValueChange}
|
|
359
|
+
// render
|
|
360
|
+
// >
|
|
361
|
+
// <Component
|
|
362
|
+
// ref={ref}
|
|
363
|
+
// {...props}
|
|
364
|
+
// />
|
|
365
|
+
// </ContextMenu.RadioGroup>
|
|
366
|
+
// </ContextMenuRadioGroupContext.Provider>
|
|
367
|
+
// );
|
|
368
|
+
// });
|
|
369
|
+
|
|
370
|
+
// RadioGroup.displayName = "RadioGroupWebContextMenu";
|
|
371
|
+
|
|
372
|
+
// function useContextMenuRadioGroupContext() {
|
|
373
|
+
// const context = React.useContext(ContextMenuRadioGroupContext);
|
|
374
|
+
// if (!context) {
|
|
375
|
+
// throw new Error("ContextMenu compound components cannot be rendered outside the ContextMenu component");
|
|
376
|
+
// }
|
|
377
|
+
// return context;
|
|
378
|
+
// }
|
|
379
|
+
|
|
380
|
+
// const RadioItem = React.forwardRef<RadioItemRef, RadioItemProps>(
|
|
381
|
+
// ({ render, value, textValue, closeOnPress = true, onPress: onPressProp, onKeyDown: onKeyDownProp, ...props }, ref) => {
|
|
382
|
+
// const { onValueChange } = useContextMenuRadioGroupContext();
|
|
383
|
+
// const { close } = useContextMenuContentContext();
|
|
384
|
+
|
|
385
|
+
// function onKeyDown(ev: React.KeyboardEvent) {
|
|
386
|
+
// onKeyDownProp?.(ev);
|
|
387
|
+
// if (ev.key === "Enter" || ev.key === " ") {
|
|
388
|
+
// onValueChange?.(value);
|
|
389
|
+
// onPressProp?.(EmptyGestureResponderEvent);
|
|
390
|
+
// if (closeOnPress) {
|
|
391
|
+
// close();
|
|
392
|
+
// }
|
|
393
|
+
// }
|
|
394
|
+
// }
|
|
395
|
+
|
|
396
|
+
// function onPress(ev: GestureResponderEvent) {
|
|
397
|
+
// onValueChange?.(value);
|
|
398
|
+
// onPressProp?.(ev);
|
|
399
|
+
// if (closeOnPress) {
|
|
400
|
+
// close();
|
|
401
|
+
// }
|
|
402
|
+
// }
|
|
403
|
+
//
|
|
404
|
+
// return (
|
|
405
|
+
// <ContextMenu.RadioItem
|
|
406
|
+
// value={value}
|
|
407
|
+
// textValue={textValue}
|
|
408
|
+
// disabled={props.disabled ?? undefined}
|
|
409
|
+
// onSelect={closeOnPress ? undefined : onSelected}
|
|
410
|
+
// render
|
|
411
|
+
// >
|
|
412
|
+
// <Component
|
|
413
|
+
// ref={ref}
|
|
414
|
+
// // @ts-expect-error web only
|
|
415
|
+
// onKeyDown={onKeyDown}
|
|
416
|
+
// onPress={onPress}
|
|
417
|
+
// {...props}
|
|
418
|
+
// />
|
|
419
|
+
// </ContextMenu.RadioItem>
|
|
420
|
+
// );
|
|
421
|
+
// },
|
|
422
|
+
// );
|
|
423
|
+
|
|
424
|
+
// RadioItem.displayName = "RadioItemWebContextMenu";
|
|
425
|
+
|
|
426
|
+
// const ItemIndicator = React.forwardRef<ItemIndicatorRef, ItemIndicatorProps>(({ keepMounted, ...props }, ref) => {
|
|
427
|
+
//
|
|
428
|
+
// return (
|
|
429
|
+
// <ContextMenu.ItemIndicator
|
|
430
|
+
// keepMounted={keepMounted}
|
|
431
|
+
// render
|
|
432
|
+
// >
|
|
433
|
+
// <Component
|
|
434
|
+
// ref={ref}
|
|
435
|
+
// {...props}
|
|
436
|
+
// />
|
|
437
|
+
// </ContextMenu.ItemIndicator>
|
|
438
|
+
// );
|
|
439
|
+
// });
|
|
440
|
+
|
|
441
|
+
// ItemIndicator.displayName = "ItemIndicatorWebContextMenu";
|
|
442
|
+
|
|
443
|
+
// const Separator = React.forwardRef<SeparatorRef, SeparatorProps>(({ decorative, ...props }, ref) => {
|
|
444
|
+
//
|
|
445
|
+
// return (
|
|
446
|
+
// <ContextMenu.Separator render>
|
|
447
|
+
// <Component
|
|
448
|
+
// ref={ref}
|
|
449
|
+
// {...props}
|
|
450
|
+
// />
|
|
451
|
+
// </ContextMenu.Separator>
|
|
452
|
+
// );
|
|
453
|
+
// });
|
|
454
|
+
|
|
455
|
+
// Separator.displayName = "SeparatorWebContextMenu";
|
|
456
|
+
|
|
457
|
+
// const ContextMenuSubContext = React.createContext<{
|
|
458
|
+
// open: boolean;
|
|
459
|
+
// onOpenChange: (open: boolean) => void;
|
|
460
|
+
// } | null>(null);
|
|
461
|
+
|
|
462
|
+
// const Sub = React.forwardRef<SubRef, SubProps>(({ defaultOpen, open: openProp, onOpenChange: onOpenChangeProp, ...props }, ref) => {
|
|
463
|
+
// const [open = false, onOpenChange] = useControllableState({
|
|
464
|
+
// prop: openProp,
|
|
465
|
+
// defaultProp: defaultOpen,
|
|
466
|
+
// onChange: onOpenChangeProp,
|
|
467
|
+
// });
|
|
468
|
+
|
|
469
|
+
//
|
|
470
|
+
// return (
|
|
471
|
+
// <ContextMenuSubContext.Provider value={{ open, onOpenChange }}>
|
|
472
|
+
// <ContextMenu.Sub
|
|
473
|
+
// open={open}
|
|
474
|
+
// onOpenChange={onOpenChange}
|
|
475
|
+
// >
|
|
476
|
+
// <Component
|
|
477
|
+
// ref={ref}
|
|
478
|
+
// {...props}
|
|
479
|
+
// />
|
|
480
|
+
// </ContextMenu.Sub>
|
|
481
|
+
// </ContextMenuSubContext.Provider>
|
|
482
|
+
// );
|
|
483
|
+
// });
|
|
484
|
+
|
|
485
|
+
// Sub.displayName = "SubWebContextMenu";
|
|
486
|
+
|
|
487
|
+
// function useSubContext() {
|
|
488
|
+
// const context = React.useContext(ContextMenuSubContext);
|
|
489
|
+
// if (!context) {
|
|
490
|
+
// throw new Error("ContextMenu compound components cannot be rendered outside the ContextMenu component");
|
|
491
|
+
// }
|
|
492
|
+
// return context;
|
|
493
|
+
// }
|
|
494
|
+
|
|
495
|
+
// const SubTrigger = React.forwardRef<SubTriggerRef, SubTriggerProps>(({ textValue, disabled = false, onPress: onPressProp, ...props }, ref) => {
|
|
496
|
+
// const { onOpenChange } = useSubContext();
|
|
497
|
+
|
|
498
|
+
// function onPress(ev: GestureResponderEvent) {
|
|
499
|
+
// onOpenChange(true);
|
|
500
|
+
// onPressProp?.(ev);
|
|
501
|
+
// }
|
|
502
|
+
|
|
503
|
+
//
|
|
504
|
+
// return (
|
|
505
|
+
// <ContextMenu.SubTrigger
|
|
506
|
+
// disabled={disabled ?? undefined}
|
|
507
|
+
// textValue={textValue}
|
|
508
|
+
// render
|
|
509
|
+
// >
|
|
510
|
+
// <Component
|
|
511
|
+
// ref={ref}
|
|
512
|
+
// onPress={onPress}
|
|
513
|
+
// {...props}
|
|
514
|
+
// />
|
|
515
|
+
// </ContextMenu.SubTrigger>
|
|
516
|
+
// );
|
|
517
|
+
// });
|
|
518
|
+
|
|
519
|
+
// SubTrigger.displayName = "SubTriggerWebContextMenu";
|
|
520
|
+
|
|
521
|
+
// const SubContent = React.forwardRef<SubContentRef, SubContentProps>(({ render = false, keepMounted, ...props }, ref) => {
|
|
522
|
+
//
|
|
523
|
+
// return (
|
|
524
|
+
// <ContextMenu.Portal>
|
|
525
|
+
// <ContextMenu.SubContent keepMounted={keepMounted}>
|
|
526
|
+
// <Component
|
|
527
|
+
// ref={ref}
|
|
528
|
+
// {...props}
|
|
529
|
+
// />
|
|
530
|
+
// </ContextMenu.SubContent>
|
|
531
|
+
// </ContextMenu.Portal>
|
|
532
|
+
// );
|
|
533
|
+
// });
|
|
534
|
+
|
|
535
|
+
// Content.displayName = "ContentWebContextMenu";
|
|
536
|
+
|
|
537
|
+
// export {
|
|
538
|
+
// CheckboxItem,
|
|
539
|
+
// Content,
|
|
540
|
+
// Group,
|
|
541
|
+
// Item,
|
|
542
|
+
// ItemIndicator,
|
|
543
|
+
// Label,
|
|
544
|
+
// Backdrop,
|
|
545
|
+
// Portal,
|
|
546
|
+
// RadioGroup,
|
|
547
|
+
// RadioItem,
|
|
548
|
+
// Root,
|
|
549
|
+
// Separator,
|
|
550
|
+
// Sub,
|
|
551
|
+
// SubContent,
|
|
552
|
+
// SubTrigger,
|
|
553
|
+
// Trigger,
|
|
554
|
+
// useRootContext,
|
|
555
|
+
// useSubContext,
|
|
556
|
+
// };
|
|
557
|
+
|
|
558
|
+
// function onSelected(ev: Event) {
|
|
559
|
+
// ev.preventDefault();
|
|
560
|
+
// }
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
import { KeepMountable, PositionedContentProps, PressableRef, RenderPressableProps, RenderTextProps, RenderViewProps, TextRef, ViewRef } from "../types";
|
|
2
|
+
|
|
3
|
+
type RootProps = RenderViewProps & {
|
|
4
|
+
onOpenChange?: (open: boolean) => void;
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* @platform: NATIVE ONLY
|
|
8
|
+
*/
|
|
9
|
+
relativeTo?: "longPress" | "trigger";
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
interface PortalProps extends KeepMountable {
|
|
13
|
+
children: React.ReactNode;
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* @platform: NATIVE ONLY
|
|
17
|
+
*/
|
|
18
|
+
hostName?: string;
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* @platform: WEB ONLY
|
|
22
|
+
*/
|
|
23
|
+
container?: HTMLElement | null | undefined;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
type BackdropProps = KeepMountable &
|
|
27
|
+
RenderPressableProps & {
|
|
28
|
+
/**
|
|
29
|
+
* @platform: NATIVE ONLY
|
|
30
|
+
*/
|
|
31
|
+
closeOnPress?: boolean;
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
type ItemProps = RenderPressableProps & {
|
|
35
|
+
textValue?: string;
|
|
36
|
+
closeOnPress?: boolean;
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
type CheckboxItemProps = RenderPressableProps & {
|
|
40
|
+
checked: boolean;
|
|
41
|
+
onCheckedChange: (checked: boolean) => void;
|
|
42
|
+
closeOnPress?: boolean;
|
|
43
|
+
textValue?: string;
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
type RadioGroupProps = RenderViewProps & {
|
|
47
|
+
value: string | undefined;
|
|
48
|
+
onValueChange: (value: string) => void;
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
type RadioItemProps = RenderPressableProps & {
|
|
52
|
+
value: string;
|
|
53
|
+
textValue?: string;
|
|
54
|
+
closeOnPress?: boolean;
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
type SeparatorProps = RenderViewProps & {
|
|
58
|
+
decorative?: boolean;
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
type SubProps = RenderViewProps & {
|
|
62
|
+
defaultOpen?: boolean;
|
|
63
|
+
open?: boolean;
|
|
64
|
+
onOpenChange?: (value: boolean) => void;
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
type SubTriggerProps = RenderPressableProps & {
|
|
68
|
+
textValue?: string;
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
type TriggerProps = RenderPressableProps;
|
|
72
|
+
type ContentProps = RenderViewProps & PositionedContentProps;
|
|
73
|
+
type SubContentProps = RenderPressableProps & KeepMountable;
|
|
74
|
+
type ItemIndicatorProps = RenderViewProps & KeepMountable;
|
|
75
|
+
type GroupProps = RenderViewProps;
|
|
76
|
+
type LabelProps = RenderTextProps;
|
|
77
|
+
|
|
78
|
+
type CheckboxItemRef = PressableRef;
|
|
79
|
+
type ContentRef = ViewRef;
|
|
80
|
+
type GroupRef = ViewRef;
|
|
81
|
+
type ItemIndicatorRef = ViewRef;
|
|
82
|
+
type ItemRef = PressableRef;
|
|
83
|
+
type LabelRef = TextRef;
|
|
84
|
+
type BackdropRef = PressableRef;
|
|
85
|
+
type RadioGroupRef = ViewRef;
|
|
86
|
+
type RadioItemRef = PressableRef;
|
|
87
|
+
type RootRef = ViewRef;
|
|
88
|
+
type SeparatorRef = ViewRef;
|
|
89
|
+
type SubContentRef = PressableRef;
|
|
90
|
+
type SubRef = ViewRef;
|
|
91
|
+
type SubTriggerRef = PressableRef;
|
|
92
|
+
type TriggerRef = PressableRef & {
|
|
93
|
+
/**
|
|
94
|
+
* @platform: NATIVE ONLY
|
|
95
|
+
*/
|
|
96
|
+
open: () => void;
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* @platform: NATIVE ONLY
|
|
100
|
+
*/
|
|
101
|
+
close: () => void;
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
export type {
|
|
105
|
+
CheckboxItemProps,
|
|
106
|
+
CheckboxItemRef,
|
|
107
|
+
ContentProps,
|
|
108
|
+
ContentRef,
|
|
109
|
+
GroupProps,
|
|
110
|
+
GroupRef,
|
|
111
|
+
ItemIndicatorProps,
|
|
112
|
+
ItemIndicatorRef,
|
|
113
|
+
ItemProps,
|
|
114
|
+
ItemRef,
|
|
115
|
+
LabelProps,
|
|
116
|
+
LabelRef,
|
|
117
|
+
BackdropProps,
|
|
118
|
+
BackdropRef,
|
|
119
|
+
PortalProps,
|
|
120
|
+
RadioGroupProps,
|
|
121
|
+
RadioGroupRef,
|
|
122
|
+
RadioItemProps,
|
|
123
|
+
RadioItemRef,
|
|
124
|
+
RootProps,
|
|
125
|
+
RootRef,
|
|
126
|
+
SeparatorProps,
|
|
127
|
+
SeparatorRef,
|
|
128
|
+
SubContentProps,
|
|
129
|
+
SubContentRef,
|
|
130
|
+
SubProps,
|
|
131
|
+
SubRef,
|
|
132
|
+
SubTriggerProps,
|
|
133
|
+
SubTriggerRef,
|
|
134
|
+
TriggerProps,
|
|
135
|
+
TriggerRef,
|
|
136
|
+
};
|