@brand-map/primitives 0.0.0-broken.1 → 0.0.0-broken.2
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/package.json +2 -9
- package/src/accordion/accordion.tsx +17 -17
- package/src/accordion/accordion.web.tsx +13 -13
- package/src/alert-dialog/alert-dialog.tsx +28 -28
- package/src/alert-dialog/alert-dialog.web.tsx +18 -18
- package/src/alert-dialog/types.ts +3 -3
- package/src/aspect-ratio/aspect-ratio.tsx +3 -3
- package/src/avatar/avatar.tsx +10 -10
- package/src/avatar/types.ts +2 -2
- package/src/checkbox/checkbox.tsx +9 -9
- package/src/checkbox/checkbox.web.tsx +8 -8
- package/src/collapsible/collapsible.tsx +33 -35
- package/src/collapsible/collapsible.web.tsx +9 -9
- package/src/context-menu/context-menu.tsx +45 -45
- package/src/context-menu/context-menu.web.tsx +44 -44
- package/src/dialog/dialog.tsx +11 -11
- package/src/dialog/dialog.web.tsx +15 -15
- package/src/dialog/types.ts +5 -5
- package/src/dropdown-menu/dropdown-menu.tsx +43 -43
- package/src/dropdown-menu/dropdown-menu.web.tsx +45 -45
- package/src/hooks/use-Isomorphic-layout-effect.tsx +1 -2
- package/src/hooks/use-relative-position.tsx +2 -2
- package/src/hover-card/hover-card.tsx +40 -42
- package/src/hover-card/hover-card.web.tsx +9 -9
- package/src/label/label.tsx +3 -4
- package/src/label/label.web.tsx +5 -5
- package/src/menubar/menubar.tsx +45 -45
- package/src/menubar/menubar.web.tsx +47 -47
- package/src/navigation-menu/navigation-menu.tsx +23 -23
- package/src/navigation-menu/navigation-menu.web.tsx +26 -26
- package/src/popover/popover.tsx +20 -20
- package/src/popover/popover.web.tsx +14 -14
- package/src/progress/progress.tsx +4 -4
- package/src/progress/progress.web.tsx +5 -5
- package/src/radio-group/radio-group.tsx +11 -11
- package/src/radio-group/radio-group.web.tsx +9 -9
- package/src/render/index.ts +1 -0
- package/src/{slot/slot.tsx → render/render.tsx} +26 -27
- package/src/select/select.tsx +28 -28
- package/src/select/select.web.tsx +22 -22
- package/src/separator/separator.tsx +3 -3
- package/src/slider/slider.tsx +8 -8
- package/src/slider/slider.web.tsx +6 -6
- package/src/switch/switch.context.ts +16 -0
- package/src/switch/switch.tsx +68 -38
- package/src/switch/switch.web.tsx +9 -9
- package/src/switch/types.ts +27 -6
- package/src/table/table.tsx +9 -9
- package/src/tabs/tabs.tsx +13 -13
- package/src/tabs/tabs.web.tsx +10 -10
- package/src/toast/toast.tsx +14 -14
- package/src/toggle/toggle.tsx +5 -5
- package/src/toggle/toggle.web.tsx +5 -5
- package/src/toggle-group/toggle-group.tsx +11 -11
- package/src/toggle-group/toggle-group.web.tsx +10 -10
- package/src/toolbar/toolbar.tsx +12 -12
- package/src/toolbar/toolbar.web.tsx +12 -12
- package/src/tooltip/tooltip.tsx +17 -17
- package/src/tooltip/tooltip.web.tsx +11 -11
- package/src/types/index.ts +5 -15
- package/.changeset/README.md +0 -8
- package/.changeset/config.json +0 -11
- package/.oxfmtrc.json +0 -35
- package/.oxlintrc.json +0 -166
- package/README.md +0 -78
- package/bun.lock +0 -904
- package/mise.toml +0 -3
- package/src/slot/index.ts +0 -1
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { createContext, forwardRef, useContext, useEffect, useId, useState } from "react";
|
|
2
2
|
import { BackHandler, Pressable, View, type GestureResponderEvent, type LayoutChangeEvent, type LayoutRectangle } from "react-native";
|
|
3
3
|
|
|
4
4
|
import { useAugmentedRef, useRelativePosition, type LayoutPosition } from "../hooks";
|
|
5
5
|
import { Portal as RNPPortal } from "../portal";
|
|
6
|
-
import * as
|
|
6
|
+
import * as Render from "../render";
|
|
7
7
|
|
|
8
8
|
import type {
|
|
9
9
|
ContentProps,
|
|
@@ -28,52 +28,50 @@ interface RootContextInterface extends SharedRootContext {
|
|
|
28
28
|
nativeID: string;
|
|
29
29
|
}
|
|
30
30
|
|
|
31
|
-
const RootContext =
|
|
31
|
+
const RootContext = createContext<RootContextInterface | null>(null);
|
|
32
32
|
|
|
33
|
-
const Root =
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
const [open, setOpen] = React.useState(false);
|
|
33
|
+
const Root = forwardRef<RootRef, RootProps>(({ render, openDelay: _openDelay, closeDelay: _closeDelay, onOpenChange: onOpenChangeProp, ...viewProps }, ref) => {
|
|
34
|
+
const nativeID = useId();
|
|
35
|
+
const [triggerPosition, setTriggerPosition] = useState<LayoutPosition | null>(null);
|
|
36
|
+
const [contentLayout, setContentLayout] = useState<LayoutRectangle | null>(null);
|
|
37
|
+
const [open, setOpen] = useState(false);
|
|
39
38
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
39
|
+
function onOpenChange(value: boolean) {
|
|
40
|
+
setOpen(value);
|
|
41
|
+
onOpenChangeProp?.(value);
|
|
42
|
+
}
|
|
44
43
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
);
|
|
44
|
+
return (
|
|
45
|
+
<RootContext.Provider
|
|
46
|
+
value={{
|
|
47
|
+
open,
|
|
48
|
+
onOpenChange,
|
|
49
|
+
contentLayout,
|
|
50
|
+
nativeID,
|
|
51
|
+
setContentLayout,
|
|
52
|
+
setTriggerPosition,
|
|
53
|
+
triggerPosition,
|
|
54
|
+
}}
|
|
55
|
+
>
|
|
56
|
+
<Component
|
|
57
|
+
ref={ref}
|
|
58
|
+
{...viewProps}
|
|
59
|
+
/>
|
|
60
|
+
</RootContext.Provider>
|
|
61
|
+
);
|
|
62
|
+
});
|
|
65
63
|
|
|
66
64
|
Root.displayName = "RootNativeHoverCard";
|
|
67
65
|
|
|
68
66
|
function useRootContext() {
|
|
69
|
-
const context =
|
|
67
|
+
const context = useContext(RootContext);
|
|
70
68
|
if (!context) {
|
|
71
69
|
throw new Error("HoverCard compound components cannot be rendered outside the HoverCard component");
|
|
72
70
|
}
|
|
73
71
|
return context;
|
|
74
72
|
}
|
|
75
73
|
|
|
76
|
-
const Trigger =
|
|
74
|
+
const Trigger = forwardRef<TriggerRef, TriggerProps>(({ onPress: onPressProp, disabled = false, ...props }, ref) => {
|
|
77
75
|
const { open, onOpenChange, setTriggerPosition } = useRootContext();
|
|
78
76
|
|
|
79
77
|
const augmentedRef = useAugmentedRef({
|
|
@@ -92,14 +90,14 @@ const Trigger = React.forwardRef<TriggerRef, TriggerProps>(({ onPress: onPressPr
|
|
|
92
90
|
},
|
|
93
91
|
});
|
|
94
92
|
|
|
95
|
-
function onPress(
|
|
93
|
+
function onPress(event: GestureResponderEvent) {
|
|
96
94
|
if (disabled) return;
|
|
97
95
|
augmentedRef.current?.measure((_x, _y, width, height, pageX, pageY) => {
|
|
98
96
|
setTriggerPosition({ width, pageX, pageY: pageY, height });
|
|
99
97
|
});
|
|
100
98
|
|
|
101
99
|
onOpenChange(!open);
|
|
102
|
-
onPressProp?.(
|
|
100
|
+
onPressProp?.(event);
|
|
103
101
|
}
|
|
104
102
|
|
|
105
103
|
return (
|
|
@@ -142,16 +140,16 @@ function Portal({ keepMounted, hostName, children }: PortalProps) {
|
|
|
142
140
|
);
|
|
143
141
|
}
|
|
144
142
|
|
|
145
|
-
const Backdrop =
|
|
143
|
+
const Backdrop = forwardRef<BackdropRef, BackdropProps>(({ keepMounted, onPress: onPressProp, closeOnPress = true, ...props }, ref) => {
|
|
146
144
|
const { open, onOpenChange, setTriggerPosition, setContentLayout } = useRootContext();
|
|
147
145
|
|
|
148
|
-
function onPress(
|
|
146
|
+
function onPress(event: GestureResponderEvent) {
|
|
149
147
|
if (closeOnPress) {
|
|
150
148
|
setTriggerPosition(null);
|
|
151
149
|
setContentLayout(null);
|
|
152
150
|
onOpenChange(false);
|
|
153
151
|
}
|
|
154
|
-
|
|
152
|
+
onPressProp?.(event);
|
|
155
153
|
}
|
|
156
154
|
|
|
157
155
|
if (!keepMounted) {
|
|
@@ -174,7 +172,7 @@ Backdrop.displayName = "BackdropNativeHoverCard";
|
|
|
174
172
|
/**
|
|
175
173
|
* @info `position`, `top`, `left`, and `maxWidth` style properties are controlled internally. Opt out of this behavior by setting `disablePositioningStyle` to `true`.
|
|
176
174
|
*/
|
|
177
|
-
const Content =
|
|
175
|
+
const Content = forwardRef<ContentRef, ContentProps>(
|
|
178
176
|
(
|
|
179
177
|
{
|
|
180
178
|
render = false,
|
|
@@ -194,7 +192,7 @@ const Content = React.forwardRef<ContentRef, ContentProps>(
|
|
|
194
192
|
) => {
|
|
195
193
|
const { open, onOpenChange, contentLayout, nativeID, setContentLayout, setTriggerPosition, triggerPosition } = useRootContext();
|
|
196
194
|
|
|
197
|
-
|
|
195
|
+
useEffect(() => {
|
|
198
196
|
const backHandler = BackHandler.addEventListener("hardwareBackPress", () => {
|
|
199
197
|
setTriggerPosition(null);
|
|
200
198
|
setContentLayout(null);
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
// import * as HoverCard from "@radix-ui/react-hover-card";
|
|
2
|
-
//
|
|
2
|
+
//
|
|
3
3
|
// import { Pressable, View } from "react-native";
|
|
4
4
|
|
|
5
5
|
// import { useAugmentedRef } from "../hooks";
|
|
6
|
-
// import * as
|
|
6
|
+
// import * as Render from "../render";
|
|
7
7
|
|
|
8
8
|
// import type {
|
|
9
9
|
// ContentProps,
|
|
@@ -18,10 +18,10 @@
|
|
|
18
18
|
// TriggerRef,
|
|
19
19
|
// } from "./types";
|
|
20
20
|
|
|
21
|
-
// const HoverCardContext =
|
|
21
|
+
// const HoverCardContext = createContext<SharedRootContext | null>(null);
|
|
22
22
|
|
|
23
|
-
// const Root =
|
|
24
|
-
// const [open, setOpen] =
|
|
23
|
+
// const Root = forwardRef<RootRef, RootProps>(({ openDelay, closeDelay, onOpenChange: onOpenChangeProp, ...viewProps }, ref) => {
|
|
24
|
+
// const [open, setOpen] = useState(false);
|
|
25
25
|
|
|
26
26
|
// function onOpenChange(value: boolean) {
|
|
27
27
|
// setOpen(value);
|
|
@@ -49,14 +49,14 @@
|
|
|
49
49
|
// Root.displayName = "RootWebHoverCard";
|
|
50
50
|
|
|
51
51
|
// function useRootContext() {
|
|
52
|
-
// const context =
|
|
52
|
+
// const context = useContext(HoverCardContext);
|
|
53
53
|
// if (!context) {
|
|
54
54
|
// throw new Error("HoverCard compound components cannot be rendered outside the HoverCard component");
|
|
55
55
|
// }
|
|
56
56
|
// return context;
|
|
57
57
|
// }
|
|
58
58
|
|
|
59
|
-
// const Trigger =
|
|
59
|
+
// const Trigger = forwardRef<TriggerRef, TriggerProps>(({ ...props }, ref) => {
|
|
60
60
|
// const { onOpenChange } = useRootContext();
|
|
61
61
|
// const augmentedRef = useAugmentedRef({
|
|
62
62
|
// ref,
|
|
@@ -93,7 +93,7 @@
|
|
|
93
93
|
// );
|
|
94
94
|
// }
|
|
95
95
|
|
|
96
|
-
// const Backdrop =
|
|
96
|
+
// const Backdrop = forwardRef<BackdropRef, BackdropProps>(({ ...props }, ref) => {
|
|
97
97
|
//
|
|
98
98
|
// return (
|
|
99
99
|
// <Component
|
|
@@ -105,7 +105,7 @@
|
|
|
105
105
|
|
|
106
106
|
// Backdrop.displayName = "BackdropWebHoverCard";
|
|
107
107
|
|
|
108
|
-
// const Content =
|
|
108
|
+
// const Content = forwardRef<ContentRef, ContentProps>(
|
|
109
109
|
// (
|
|
110
110
|
// {
|
|
111
111
|
// render = false,
|
package/src/label/label.tsx
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
|
-
import * as React from "react";
|
|
2
1
|
import { Pressable, Text as ReactNativeText } from "react-native";
|
|
3
2
|
|
|
4
|
-
import * as
|
|
3
|
+
import * as Render from "../render";
|
|
5
4
|
|
|
6
5
|
import type { RootProps, TextProps } from "./types";
|
|
7
6
|
|
|
8
7
|
const Root = ({ render, ...props }: RootProps) => {
|
|
9
8
|
if (render) {
|
|
10
9
|
return (
|
|
11
|
-
<
|
|
10
|
+
<Render.Pressable
|
|
12
11
|
render={render}
|
|
13
12
|
{...props}
|
|
14
13
|
/>
|
|
@@ -22,7 +21,7 @@ Root.displayName = "RootNativeLabel";
|
|
|
22
21
|
const Text = ({ render, ...props }: TextProps) => {
|
|
23
22
|
if (render) {
|
|
24
23
|
return (
|
|
25
|
-
<
|
|
24
|
+
<Render.Text
|
|
26
25
|
render={render}
|
|
27
26
|
{...props}
|
|
28
27
|
/>
|
package/src/label/label.web.tsx
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
// import * as Label from "@radix-ui/react-label";
|
|
2
|
-
//
|
|
2
|
+
//
|
|
3
3
|
// import { Pressable, Text as RNText } from "react-native";
|
|
4
4
|
|
|
5
|
-
// import * as
|
|
5
|
+
// import * as Render from "../render";
|
|
6
6
|
|
|
7
7
|
// import type { RootProps, RootRef, TextProps, TextRef } from "./types";
|
|
8
8
|
|
|
9
|
-
// const Root =
|
|
9
|
+
// const Root = forwardRef<RootRef, RootProps>(({ tabIndex = -1, ...props }, ref) => {
|
|
10
10
|
//
|
|
11
11
|
// return (
|
|
12
12
|
// <Component
|
|
@@ -18,8 +18,8 @@
|
|
|
18
18
|
// });
|
|
19
19
|
// Root.displayName = "RootWebLabel";
|
|
20
20
|
|
|
21
|
-
// const Text =
|
|
22
|
-
// const Component = render ?
|
|
21
|
+
// const Text = forwardRef<TextRef, TextProps>(({ nativeID, htmlFor, ...props }, ref) => {
|
|
22
|
+
// const Component = render ? Render.Text : RNText;
|
|
23
23
|
// return (
|
|
24
24
|
// <Label.Root
|
|
25
25
|
// render={!htmlFor}
|
package/src/menubar/menubar.tsx
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { createContext, forwardRef, useId, useState, useContext, useEffect } from "react";
|
|
2
2
|
import { BackHandler, Pressable, Text, View, type GestureResponderEvent, type LayoutChangeEvent, type LayoutRectangle } from "react-native";
|
|
3
3
|
|
|
4
4
|
import { useAugmentedRef, useControllableState, useRelativePosition, type LayoutPosition } from "../hooks";
|
|
5
5
|
import { Portal as RNPPortal } from "../portal";
|
|
6
|
-
import * as
|
|
6
|
+
import * as Render from "../render";
|
|
7
7
|
|
|
8
8
|
import type {
|
|
9
9
|
CheckboxItemProps,
|
|
@@ -49,12 +49,12 @@ interface IMenuContext extends RootProps {
|
|
|
49
49
|
nativeID: string;
|
|
50
50
|
}
|
|
51
51
|
|
|
52
|
-
const RootContext =
|
|
52
|
+
const RootContext = createContext<IMenuContext | null>(null);
|
|
53
53
|
|
|
54
|
-
const Root =
|
|
55
|
-
const nativeID =
|
|
56
|
-
const [triggerPosition, setTriggerPosition] =
|
|
57
|
-
const [contentLayout, setContentLayout] =
|
|
54
|
+
const Root = forwardRef<RootRef, RootProps>(({ value, onValueChange, ...viewProps }, ref) => {
|
|
55
|
+
const nativeID = useId();
|
|
56
|
+
const [triggerPosition, setTriggerPosition] = useState<LayoutPosition | null>(null);
|
|
57
|
+
const [contentLayout, setContentLayout] = useState<LayoutRectangle | null>(null);
|
|
58
58
|
|
|
59
59
|
return (
|
|
60
60
|
<RootContext.Provider
|
|
@@ -79,16 +79,16 @@ const Root = React.forwardRef<RootRef, RootProps>(({ value, onValueChange, ...vi
|
|
|
79
79
|
Root.displayName = "RootMenubar";
|
|
80
80
|
|
|
81
81
|
function useRootContext() {
|
|
82
|
-
const context =
|
|
82
|
+
const context = useContext(RootContext);
|
|
83
83
|
if (!context) {
|
|
84
84
|
throw new Error("Menubar compound components cannot be rendered outside the Menubar component");
|
|
85
85
|
}
|
|
86
86
|
return context;
|
|
87
87
|
}
|
|
88
88
|
|
|
89
|
-
const MenuContext =
|
|
89
|
+
const MenuContext = createContext<MenuProps | null>(null);
|
|
90
90
|
|
|
91
|
-
const Menu =
|
|
91
|
+
const Menu = forwardRef<MenuRef, MenuProps>(({ value, ...viewProps }, ref) => {
|
|
92
92
|
return (
|
|
93
93
|
<MenuContext.Provider
|
|
94
94
|
value={{
|
|
@@ -107,26 +107,26 @@ const Menu = React.forwardRef<MenuRef, MenuProps>(({ value, ...viewProps }, ref)
|
|
|
107
107
|
Menu.displayName = "MenuMenubar";
|
|
108
108
|
|
|
109
109
|
function useMenuContext() {
|
|
110
|
-
const context =
|
|
110
|
+
const context = useContext(MenuContext);
|
|
111
111
|
if (!context) {
|
|
112
112
|
throw new Error("Menubar compound components cannot be rendered outside the Menubar component");
|
|
113
113
|
}
|
|
114
114
|
return context;
|
|
115
115
|
}
|
|
116
116
|
|
|
117
|
-
const Trigger =
|
|
117
|
+
const Trigger = forwardRef<TriggerRef, TriggerProps>(({ onPress: onPressProp, disabled = false, ...props }, ref) => {
|
|
118
118
|
const triggerRef = useAugmentedRef({ ref });
|
|
119
119
|
const { value, onValueChange, setTriggerPosition } = useRootContext();
|
|
120
120
|
const { value: menuValue } = useMenuContext();
|
|
121
121
|
|
|
122
|
-
function onPress(
|
|
122
|
+
function onPress(event: GestureResponderEvent) {
|
|
123
123
|
if (disabled) return;
|
|
124
124
|
triggerRef.current?.measure((_x, _y, width, height, pageX, pageY) => {
|
|
125
125
|
setTriggerPosition({ width, pageX, pageY, height });
|
|
126
126
|
});
|
|
127
127
|
|
|
128
128
|
onValueChange(menuValue === value ? undefined : menuValue);
|
|
129
|
-
onPressProp?.(
|
|
129
|
+
onPressProp?.(event);
|
|
130
130
|
}
|
|
131
131
|
|
|
132
132
|
return (
|
|
@@ -181,16 +181,16 @@ function Portal({ keepMounted, hostName, children }: PortalProps) {
|
|
|
181
181
|
);
|
|
182
182
|
}
|
|
183
183
|
|
|
184
|
-
const Backdrop =
|
|
184
|
+
const Backdrop = forwardRef<BackdropRef, BackdropProps>(({ keepMounted, onPress: onPressProp, closeOnPress = true, ...props }, ref) => {
|
|
185
185
|
const { value, onValueChange, setContentLayout, setTriggerPosition } = useRootContext();
|
|
186
186
|
|
|
187
|
-
function onPress(
|
|
187
|
+
function onPress(event: GestureResponderEvent) {
|
|
188
188
|
if (closeOnPress) {
|
|
189
189
|
setTriggerPosition(null);
|
|
190
190
|
setContentLayout(null);
|
|
191
191
|
onValueChange(undefined);
|
|
192
192
|
}
|
|
193
|
-
|
|
193
|
+
onPressProp?.(event);
|
|
194
194
|
}
|
|
195
195
|
|
|
196
196
|
if (!keepMounted) {
|
|
@@ -213,7 +213,7 @@ Backdrop.displayName = "BackdropMenubar";
|
|
|
213
213
|
/**
|
|
214
214
|
* @info `position`, `top`, `left`, and `maxWidth` style properties are controlled internally. Opt out of this behavior by setting `disablePositioningStyle` to `true`.
|
|
215
215
|
*/
|
|
216
|
-
const Content =
|
|
216
|
+
const Content = forwardRef<ContentRef, ContentProps>(
|
|
217
217
|
(
|
|
218
218
|
{
|
|
219
219
|
render = false,
|
|
@@ -234,7 +234,7 @@ const Content = React.forwardRef<ContentRef, ContentProps>(
|
|
|
234
234
|
const { value, onValueChange, triggerPosition, contentLayout, setContentLayout, nativeID, setTriggerPosition } = useRootContext();
|
|
235
235
|
const { value: menuValue } = useMenuContext();
|
|
236
236
|
|
|
237
|
-
|
|
237
|
+
useEffect(() => {
|
|
238
238
|
const backHandler = BackHandler.addEventListener("hardwareBackPress", () => {
|
|
239
239
|
setTriggerPosition(null);
|
|
240
240
|
setContentLayout(null);
|
|
@@ -288,16 +288,16 @@ const Content = React.forwardRef<ContentRef, ContentProps>(
|
|
|
288
288
|
|
|
289
289
|
Content.displayName = "ContentMenubar";
|
|
290
290
|
|
|
291
|
-
const Item =
|
|
291
|
+
const Item = forwardRef<ItemRef, ItemProps>(({ textValue, onPress: onPressProp, disabled = false, closeOnPress = true, ...props }, ref) => {
|
|
292
292
|
const { onValueChange, setContentLayout, setTriggerPosition } = useRootContext();
|
|
293
293
|
|
|
294
|
-
function onPress(
|
|
294
|
+
function onPress(event: GestureResponderEvent) {
|
|
295
295
|
if (closeOnPress) {
|
|
296
296
|
setTriggerPosition(null);
|
|
297
297
|
setContentLayout(null);
|
|
298
298
|
onValueChange(undefined);
|
|
299
299
|
}
|
|
300
|
-
onPressProp?.(
|
|
300
|
+
onPressProp?.(event);
|
|
301
301
|
}
|
|
302
302
|
|
|
303
303
|
return (
|
|
@@ -316,7 +316,7 @@ const Item = React.forwardRef<ItemRef, ItemProps>(({ textValue, onPress: onPress
|
|
|
316
316
|
|
|
317
317
|
Item.displayName = "ItemMenubar";
|
|
318
318
|
|
|
319
|
-
const Group =
|
|
319
|
+
const Group = forwardRef<GroupRef, GroupProps>(({ ...props }, ref) => {
|
|
320
320
|
return (
|
|
321
321
|
<Component
|
|
322
322
|
ref={ref}
|
|
@@ -328,7 +328,7 @@ const Group = React.forwardRef<GroupRef, GroupProps>(({ ...props }, ref) => {
|
|
|
328
328
|
|
|
329
329
|
Group.displayName = "GroupMenubar";
|
|
330
330
|
|
|
331
|
-
const Label =
|
|
331
|
+
const Label = forwardRef<LabelRef, LabelProps>(({ ...props }, ref) => {
|
|
332
332
|
return (
|
|
333
333
|
<Component
|
|
334
334
|
ref={ref}
|
|
@@ -346,20 +346,20 @@ type FormItemContext =
|
|
|
346
346
|
onValueChange: (value: string) => void;
|
|
347
347
|
};
|
|
348
348
|
|
|
349
|
-
const FormItemContext =
|
|
349
|
+
const FormItemContext = createContext<FormItemContext | null>(null);
|
|
350
350
|
|
|
351
|
-
const CheckboxItem =
|
|
351
|
+
const CheckboxItem = forwardRef<CheckboxItemRef, CheckboxItemProps>(
|
|
352
352
|
({ render, checked, onCheckedChange, textValue, onPress: onPressProp, closeOnPress = true, disabled = false, ...props }, ref) => {
|
|
353
353
|
const { onValueChange, setTriggerPosition, setContentLayout } = useRootContext();
|
|
354
354
|
|
|
355
|
-
function onPress(
|
|
355
|
+
function onPress(event: GestureResponderEvent) {
|
|
356
356
|
onCheckedChange(!checked);
|
|
357
357
|
if (closeOnPress) {
|
|
358
358
|
setTriggerPosition(null);
|
|
359
359
|
setContentLayout(null);
|
|
360
360
|
onValueChange(undefined);
|
|
361
361
|
}
|
|
362
|
-
onPressProp?.(
|
|
362
|
+
onPressProp?.(event);
|
|
363
363
|
}
|
|
364
364
|
|
|
365
365
|
return (
|
|
@@ -383,14 +383,14 @@ const CheckboxItem = React.forwardRef<CheckboxItemRef, CheckboxItemProps>(
|
|
|
383
383
|
CheckboxItem.displayName = "CheckboxItemMenubar";
|
|
384
384
|
|
|
385
385
|
function useFormItemContext() {
|
|
386
|
-
const context =
|
|
386
|
+
const context = useContext(FormItemContext);
|
|
387
387
|
if (!context) {
|
|
388
388
|
throw new Error("CheckboxItem or RadioItem compound components cannot be rendered outside of a CheckboxItem or RadioItem component");
|
|
389
389
|
}
|
|
390
390
|
return context;
|
|
391
391
|
}
|
|
392
392
|
|
|
393
|
-
const RadioGroup =
|
|
393
|
+
const RadioGroup = forwardRef<RadioGroupRef, RadioGroupProps>(({ value, onValueChange, ...props }, ref) => {
|
|
394
394
|
return (
|
|
395
395
|
<FormItemContext.Provider value={{ value, onValueChange }}>
|
|
396
396
|
<Component
|
|
@@ -408,21 +408,21 @@ type BothFormItemContext = Exclude<FormItemContext, { checked: boolean }> & {
|
|
|
408
408
|
checked: boolean;
|
|
409
409
|
};
|
|
410
410
|
|
|
411
|
-
const RadioItemContext =
|
|
411
|
+
const RadioItemContext = createContext({} as { itemValue: string });
|
|
412
412
|
|
|
413
|
-
const RadioItem =
|
|
413
|
+
const RadioItem = forwardRef<RadioItemRef, RadioItemProps>(
|
|
414
414
|
({ render, value: itemValue, textValue, onPress: onPressProp, disabled = false, closeOnPress = true, ...props }, ref) => {
|
|
415
415
|
const { onValueChange: onRootValueChange, setTriggerPosition, setContentLayout } = useRootContext();
|
|
416
416
|
|
|
417
417
|
const { value, onValueChange } = useFormItemContext() as BothFormItemContext;
|
|
418
|
-
function onPress(
|
|
418
|
+
function onPress(event: GestureResponderEvent) {
|
|
419
419
|
onValueChange(itemValue);
|
|
420
420
|
if (closeOnPress) {
|
|
421
421
|
setTriggerPosition(null);
|
|
422
422
|
setContentLayout(null);
|
|
423
423
|
onRootValueChange(undefined);
|
|
424
424
|
}
|
|
425
|
-
onPressProp?.(
|
|
425
|
+
onPressProp?.(event);
|
|
426
426
|
}
|
|
427
427
|
|
|
428
428
|
return (
|
|
@@ -448,10 +448,10 @@ const RadioItem = React.forwardRef<RadioItemRef, RadioItemProps>(
|
|
|
448
448
|
RadioItem.displayName = "RadioItemMenubar";
|
|
449
449
|
|
|
450
450
|
function useItemIndicatorContext() {
|
|
451
|
-
return
|
|
451
|
+
return useContext(RadioItemContext);
|
|
452
452
|
}
|
|
453
453
|
|
|
454
|
-
const ItemIndicator =
|
|
454
|
+
const ItemIndicator = forwardRef<ItemIndicatorRef, ItemIndicatorProps>(({ keepMounted, ...props }, ref) => {
|
|
455
455
|
const { itemValue } = useItemIndicatorContext();
|
|
456
456
|
const { checked, value } = useFormItemContext() as BothFormItemContext;
|
|
457
457
|
|
|
@@ -475,7 +475,7 @@ const ItemIndicator = React.forwardRef<ItemIndicatorRef, ItemIndicatorProps>(({
|
|
|
475
475
|
|
|
476
476
|
ItemIndicator.displayName = "ItemIndicatorMenubar";
|
|
477
477
|
|
|
478
|
-
const Separator =
|
|
478
|
+
const Separator = forwardRef<SeparatorRef, SeparatorProps>(({ decorative, ...props }, ref) => {
|
|
479
479
|
return (
|
|
480
480
|
<Component
|
|
481
481
|
role={decorative ? "presentation" : "separator"}
|
|
@@ -487,14 +487,14 @@ const Separator = React.forwardRef<SeparatorRef, SeparatorProps>(({ decorative,
|
|
|
487
487
|
|
|
488
488
|
Separator.displayName = "SeparatorMenubar";
|
|
489
489
|
|
|
490
|
-
const SubContext =
|
|
490
|
+
const SubContext = createContext<{
|
|
491
491
|
nativeID: string;
|
|
492
492
|
open: boolean;
|
|
493
493
|
onOpenChange: (value: boolean) => void;
|
|
494
494
|
} | null>(null);
|
|
495
495
|
|
|
496
|
-
const Sub =
|
|
497
|
-
const nativeID =
|
|
496
|
+
const Sub = forwardRef<SubRef, SubProps>(({ defaultOpen, open: openProp, onOpenChange: onOpenChangeProp, ...props }, ref) => {
|
|
497
|
+
const nativeID = useId();
|
|
498
498
|
const [open = false, onOpenChange] = useControllableState({
|
|
499
499
|
prop: openProp,
|
|
500
500
|
defaultProp: defaultOpen,
|
|
@@ -520,19 +520,19 @@ const Sub = React.forwardRef<SubRef, SubProps>(({ defaultOpen, open: openProp, o
|
|
|
520
520
|
Sub.displayName = "SubMenubar";
|
|
521
521
|
|
|
522
522
|
function useSubContext() {
|
|
523
|
-
const context =
|
|
523
|
+
const context = useContext(SubContext);
|
|
524
524
|
if (!context) {
|
|
525
525
|
throw new Error("Sub compound components cannot be rendered outside of a Sub component");
|
|
526
526
|
}
|
|
527
527
|
return context;
|
|
528
528
|
}
|
|
529
529
|
|
|
530
|
-
const SubTrigger =
|
|
530
|
+
const SubTrigger = forwardRef<SubTriggerRef, SubTriggerProps>(({ textValue, onPress: onPressProp, disabled = false, ...props }, ref) => {
|
|
531
531
|
const { nativeID, open, onOpenChange } = useSubContext();
|
|
532
532
|
|
|
533
|
-
function onPress(
|
|
533
|
+
function onPress(event: GestureResponderEvent) {
|
|
534
534
|
onOpenChange(!open);
|
|
535
|
-
onPressProp?.(
|
|
535
|
+
onPressProp?.(event);
|
|
536
536
|
}
|
|
537
537
|
|
|
538
538
|
return (
|
|
@@ -553,7 +553,7 @@ const SubTrigger = React.forwardRef<SubTriggerRef, SubTriggerProps>(({ textValue
|
|
|
553
553
|
|
|
554
554
|
SubTrigger.displayName = "SubTriggerMenubar";
|
|
555
555
|
|
|
556
|
-
const SubContent =
|
|
556
|
+
const SubContent = forwardRef<SubContentRef, SubContentProps>(({ render = false, keepMounted, ...props }, ref) => {
|
|
557
557
|
const { open, nativeID } = useSubContext();
|
|
558
558
|
|
|
559
559
|
if (!keepMounted) {
|