@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,106 @@
|
|
|
1
|
+
// import * as Tabs from "@radix-ui/react-tabs";
|
|
2
|
+
// import * as React from "react";
|
|
3
|
+
// import { Pressable, View } from "react-native";
|
|
4
|
+
|
|
5
|
+
// import * as Slot from "../slot";
|
|
6
|
+
|
|
7
|
+
// import type { ContentProps, ContentRef, ListProps, ListRef, RootProps, RootRef, TriggerProps, TriggerRef } from "./types";
|
|
8
|
+
|
|
9
|
+
// const TabsContext = React.createContext<RootProps | null>(null);
|
|
10
|
+
// const Root = React.forwardRef<RootRef, RootProps>(({ value, onValueChange, orientation, dir, activationMode, ...viewProps }, ref) => {
|
|
11
|
+
//
|
|
12
|
+
// return (
|
|
13
|
+
// <TabsContext.Provider
|
|
14
|
+
// value={{
|
|
15
|
+
// value,
|
|
16
|
+
// onValueChange,
|
|
17
|
+
// }}
|
|
18
|
+
// >
|
|
19
|
+
// <Tabs.Root
|
|
20
|
+
// value={value}
|
|
21
|
+
// onValueChange={onValueChange}
|
|
22
|
+
// orientation={orientation}
|
|
23
|
+
// dir={dir}
|
|
24
|
+
// activationMode={activationMode}
|
|
25
|
+
// render
|
|
26
|
+
// >
|
|
27
|
+
// <Component
|
|
28
|
+
// ref={ref}
|
|
29
|
+
// {...viewProps}
|
|
30
|
+
// />
|
|
31
|
+
// </Tabs.Root>
|
|
32
|
+
// </TabsContext.Provider>
|
|
33
|
+
// );
|
|
34
|
+
// });
|
|
35
|
+
|
|
36
|
+
// Root.displayName = "RootWebTabs";
|
|
37
|
+
|
|
38
|
+
// function useRootContext() {
|
|
39
|
+
// const context = React.useContext(TabsContext);
|
|
40
|
+
// if (!context) {
|
|
41
|
+
// throw new Error("Tabs compound components cannot be rendered outside the Tabs component");
|
|
42
|
+
// }
|
|
43
|
+
// return context;
|
|
44
|
+
// }
|
|
45
|
+
|
|
46
|
+
// const List = React.forwardRef<ListRef, ListProps>(({ ...props }, ref) => {
|
|
47
|
+
//
|
|
48
|
+
// return (
|
|
49
|
+
// <Tabs.List render>
|
|
50
|
+
// <Component
|
|
51
|
+
// ref={ref}
|
|
52
|
+
// {...props}
|
|
53
|
+
// />
|
|
54
|
+
// </Tabs.List>
|
|
55
|
+
// );
|
|
56
|
+
// });
|
|
57
|
+
|
|
58
|
+
// List.displayName = "ListWebTabs";
|
|
59
|
+
|
|
60
|
+
// const TriggerContext = React.createContext<{ value: string } | null>(null);
|
|
61
|
+
// const Trigger = React.forwardRef<TriggerRef, TriggerProps>(({ value: tabValue, ...props }, ref) => {
|
|
62
|
+
//
|
|
63
|
+
// return (
|
|
64
|
+
// <TriggerContext.Provider value={{ value: tabValue }}>
|
|
65
|
+
// <Tabs.Trigger
|
|
66
|
+
// value={tabValue}
|
|
67
|
+
// render
|
|
68
|
+
// >
|
|
69
|
+
// <Component
|
|
70
|
+
// ref={ref}
|
|
71
|
+
// {...props}
|
|
72
|
+
// />
|
|
73
|
+
// </Tabs.Trigger>
|
|
74
|
+
// </TriggerContext.Provider>
|
|
75
|
+
// );
|
|
76
|
+
// });
|
|
77
|
+
|
|
78
|
+
// Trigger.displayName = "TriggerWebTabs";
|
|
79
|
+
|
|
80
|
+
// function useTriggerContext() {
|
|
81
|
+
// const context = React.useContext(TriggerContext);
|
|
82
|
+
// if (!context) {
|
|
83
|
+
// throw new Error("Tabs.Trigger compound components cannot be rendered outside the Tabs.Trigger component");
|
|
84
|
+
// }
|
|
85
|
+
// return context;
|
|
86
|
+
// }
|
|
87
|
+
|
|
88
|
+
// const Content = React.forwardRef<ContentRef, ContentProps>(({ keepMounted, value, tabIndex = -1, ...props }, ref) => {
|
|
89
|
+
//
|
|
90
|
+
// return (
|
|
91
|
+
// <Tabs.Content
|
|
92
|
+
// value={value}
|
|
93
|
+
// render
|
|
94
|
+
// >
|
|
95
|
+
// <Component
|
|
96
|
+
// ref={ref}
|
|
97
|
+
// {...props}
|
|
98
|
+
// tabIndex={tabIndex}
|
|
99
|
+
// />
|
|
100
|
+
// </Tabs.Content>
|
|
101
|
+
// );
|
|
102
|
+
// });
|
|
103
|
+
|
|
104
|
+
// Content.displayName = "ContentWebTabs";
|
|
105
|
+
|
|
106
|
+
// export { Content, List, Root, Trigger, useRootContext, useTriggerContext };
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { KeepMountable, PressableRef, RenderPressableProps, RenderViewProps, ViewRef } from "../types";
|
|
2
|
+
|
|
3
|
+
type RootProps = RenderViewProps & {
|
|
4
|
+
value: string;
|
|
5
|
+
onValueChange: (value: string) => void;
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* @platform: WEB ONLY
|
|
9
|
+
*/
|
|
10
|
+
orientation?: "horizontal" | "vertical";
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* @platform: WEB ONLY
|
|
14
|
+
*/
|
|
15
|
+
dir?: "ltr" | "rtl";
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* @platform: WEB ONLY
|
|
19
|
+
*/
|
|
20
|
+
activationMode?: "automatic" | "manual";
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
type ListProps = RenderViewProps;
|
|
24
|
+
type TriggerProps = RenderPressableProps & {
|
|
25
|
+
value: string;
|
|
26
|
+
};
|
|
27
|
+
type ContentProps = RenderViewProps &
|
|
28
|
+
KeepMountable & {
|
|
29
|
+
value: string;
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
type RootRef = ViewRef;
|
|
33
|
+
type ListRef = ViewRef;
|
|
34
|
+
type TriggerRef = PressableRef;
|
|
35
|
+
type ContentRef = ViewRef;
|
|
36
|
+
|
|
37
|
+
export type { ContentProps, ContentRef, ListProps, ListRef, RootProps, RootRef, TriggerProps, TriggerRef };
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { Pressable, Text, View, type GestureResponderEvent } from "react-native";
|
|
3
|
+
|
|
4
|
+
import * as Slot from "../slot";
|
|
5
|
+
|
|
6
|
+
import type { ActionProps, ActionRef, CloseProps, CloseRef, DescriptionProps, DescriptionRef, RootProps, RootRef, TitleProps, TitleRef } from "./types";
|
|
7
|
+
|
|
8
|
+
interface RootContext extends RootProps {
|
|
9
|
+
nativeID: string;
|
|
10
|
+
}
|
|
11
|
+
const ToastContext = React.createContext<RootContext | null>(null);
|
|
12
|
+
|
|
13
|
+
const Root = React.forwardRef<RootRef, RootProps>(({ type = "foreground", open, onOpenChange, ...viewProps }, ref) => {
|
|
14
|
+
const nativeID = React.useId();
|
|
15
|
+
|
|
16
|
+
if (!open) {
|
|
17
|
+
return null;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
return (
|
|
21
|
+
<ToastContext.Provider
|
|
22
|
+
value={{
|
|
23
|
+
open,
|
|
24
|
+
onOpenChange,
|
|
25
|
+
type,
|
|
26
|
+
nativeID,
|
|
27
|
+
}}
|
|
28
|
+
>
|
|
29
|
+
<Component
|
|
30
|
+
ref={ref}
|
|
31
|
+
role="status"
|
|
32
|
+
aria-live={type === "foreground" ? "assertive" : "polite"}
|
|
33
|
+
{...viewProps}
|
|
34
|
+
/>
|
|
35
|
+
</ToastContext.Provider>
|
|
36
|
+
);
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
Root.displayName = "RootToast";
|
|
40
|
+
|
|
41
|
+
function useToastContext() {
|
|
42
|
+
const context = React.useContext(ToastContext);
|
|
43
|
+
if (!context) {
|
|
44
|
+
throw new Error("Toast compound components cannot be rendered outside the Toast component");
|
|
45
|
+
}
|
|
46
|
+
return context;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const Close = React.forwardRef<CloseRef, CloseProps>(({ onPress: onPressProp, disabled = false, ...props }, ref) => {
|
|
50
|
+
const { onOpenChange } = useToastContext();
|
|
51
|
+
|
|
52
|
+
function onPress(ev: GestureResponderEvent) {
|
|
53
|
+
if (disabled) return;
|
|
54
|
+
onOpenChange(false);
|
|
55
|
+
onPressProp?.(ev);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
return (
|
|
59
|
+
<Component
|
|
60
|
+
ref={ref}
|
|
61
|
+
aria-disabled={disabled ?? undefined}
|
|
62
|
+
role="button"
|
|
63
|
+
onPress={onPress}
|
|
64
|
+
disabled={disabled ?? undefined}
|
|
65
|
+
{...props}
|
|
66
|
+
/>
|
|
67
|
+
);
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
Close.displayName = "CloseToast";
|
|
71
|
+
|
|
72
|
+
const Action = React.forwardRef<ActionRef, ActionProps>(({ onPress: onPressProp, disabled = false, ...props }, ref) => {
|
|
73
|
+
const { onOpenChange } = useToastContext();
|
|
74
|
+
|
|
75
|
+
function onPress(ev: GestureResponderEvent) {
|
|
76
|
+
if (disabled) return;
|
|
77
|
+
onOpenChange(false);
|
|
78
|
+
onPressProp?.(ev);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
return (
|
|
82
|
+
<Component
|
|
83
|
+
ref={ref}
|
|
84
|
+
aria-disabled={disabled ?? undefined}
|
|
85
|
+
role="button"
|
|
86
|
+
onPress={onPress}
|
|
87
|
+
disabled={disabled ?? undefined}
|
|
88
|
+
{...props}
|
|
89
|
+
/>
|
|
90
|
+
);
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
Action.displayName = "ActionToast";
|
|
94
|
+
|
|
95
|
+
const Title = React.forwardRef<TitleRef, TitleProps>(({ ...props }, ref) => {
|
|
96
|
+
const { nativeID } = useToastContext();
|
|
97
|
+
|
|
98
|
+
return (
|
|
99
|
+
<Component
|
|
100
|
+
ref={ref}
|
|
101
|
+
role="heading"
|
|
102
|
+
nativeID={`${nativeID}_label`}
|
|
103
|
+
{...props}
|
|
104
|
+
/>
|
|
105
|
+
);
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
Title.displayName = "TitleToast";
|
|
109
|
+
|
|
110
|
+
const Description = React.forwardRef<DescriptionRef, DescriptionProps>(({ ...props }, ref) => {
|
|
111
|
+
const { nativeID } = useToastContext();
|
|
112
|
+
|
|
113
|
+
return (
|
|
114
|
+
<Component
|
|
115
|
+
ref={ref}
|
|
116
|
+
nativeID={`${nativeID}_desc`}
|
|
117
|
+
{...props}
|
|
118
|
+
/>
|
|
119
|
+
);
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
Description.displayName = "DescriptionToast";
|
|
123
|
+
|
|
124
|
+
export { Action, Close, Description, Root, Title };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { PressableRef, RenderPressableProps, RenderTextProps, RenderViewProps, TextRef, ViewRef } from "../types";
|
|
2
|
+
|
|
3
|
+
type RootProps = RenderViewProps & {
|
|
4
|
+
open: boolean;
|
|
5
|
+
onOpenChange: (value: boolean) => void;
|
|
6
|
+
type?: "foreground" | "background";
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
type CloseProps = RenderPressableProps;
|
|
10
|
+
type ActionProps = RenderPressableProps;
|
|
11
|
+
type TitleProps = RenderTextProps;
|
|
12
|
+
type DescriptionProps = RenderTextProps;
|
|
13
|
+
|
|
14
|
+
type RootRef = ViewRef;
|
|
15
|
+
type CloseRef = PressableRef;
|
|
16
|
+
type ActionRef = PressableRef;
|
|
17
|
+
type TitleRef = TextRef;
|
|
18
|
+
type DescriptionRef = TextRef;
|
|
19
|
+
|
|
20
|
+
export type { ActionProps, ActionRef, CloseProps, CloseRef, DescriptionProps, DescriptionRef, RootProps, RootRef, TitleProps, TitleRef };
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { Pressable, type GestureResponderEvent } from "react-native";
|
|
3
|
+
|
|
4
|
+
import * as Slot from "../slot";
|
|
5
|
+
|
|
6
|
+
import type { RootProps, RootRef } from "./types";
|
|
7
|
+
|
|
8
|
+
const Root = React.forwardRef<RootRef, RootProps>(({ pressed, onPressedChange, disabled, onPress: onPressProp, ...props }, ref) => {
|
|
9
|
+
function onPress(ev: GestureResponderEvent) {
|
|
10
|
+
if (disabled) return;
|
|
11
|
+
const newValue = !pressed;
|
|
12
|
+
onPressedChange(newValue);
|
|
13
|
+
onPressProp?.(ev);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
return (
|
|
17
|
+
<Component
|
|
18
|
+
ref={ref}
|
|
19
|
+
aria-disabled={disabled}
|
|
20
|
+
role="switch"
|
|
21
|
+
aria-selected={pressed}
|
|
22
|
+
onPress={onPress}
|
|
23
|
+
accessibilityState={{
|
|
24
|
+
selected: pressed,
|
|
25
|
+
disabled,
|
|
26
|
+
}}
|
|
27
|
+
disabled={disabled}
|
|
28
|
+
{...props}
|
|
29
|
+
/>
|
|
30
|
+
);
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
Root.displayName = "RootNativeToggle";
|
|
34
|
+
|
|
35
|
+
export { Root };
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
// import * as Toggle from "@radix-ui/react-toggle";
|
|
2
|
+
// import * as React from "react";
|
|
3
|
+
// import { Pressable, type GestureResponderEvent } from "react-native";
|
|
4
|
+
|
|
5
|
+
// import * as Slot from "../slot";
|
|
6
|
+
|
|
7
|
+
// import type { RootProps, RootRef } from "./types";
|
|
8
|
+
|
|
9
|
+
// const Root = React.forwardRef<RootRef, RootProps>(({ pressed, onPressedChange, disabled, onPress: onPressProp, ...props }, ref) => {
|
|
10
|
+
// function onPress(ev: GestureResponderEvent) {
|
|
11
|
+
// onPressProp?.(ev);
|
|
12
|
+
// onPressedChange(!pressed);
|
|
13
|
+
// }
|
|
14
|
+
|
|
15
|
+
//
|
|
16
|
+
// return (
|
|
17
|
+
// <Toggle.Root
|
|
18
|
+
// pressed={pressed}
|
|
19
|
+
// onPressedChange={onPressedChange}
|
|
20
|
+
// disabled={disabled}
|
|
21
|
+
// render
|
|
22
|
+
// >
|
|
23
|
+
// <Component
|
|
24
|
+
// ref={ref}
|
|
25
|
+
// onPress={onPress}
|
|
26
|
+
// disabled={disabled}
|
|
27
|
+
// role="button"
|
|
28
|
+
// {...props}
|
|
29
|
+
// />
|
|
30
|
+
// </Toggle.Root>
|
|
31
|
+
// );
|
|
32
|
+
// });
|
|
33
|
+
|
|
34
|
+
// Root.displayName = "RootWebToggle";
|
|
35
|
+
|
|
36
|
+
// export { Root };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { PressableRef, RenderPressableProps } from "../types";
|
|
2
|
+
|
|
3
|
+
type RootProps = RenderPressableProps & {
|
|
4
|
+
pressed: boolean;
|
|
5
|
+
onPressedChange: (pressed: boolean) => void;
|
|
6
|
+
disabled?: boolean;
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
type RootRef = PressableRef;
|
|
10
|
+
|
|
11
|
+
export type { RootProps, RootRef };
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { Pressable, View, type GestureResponderEvent } from "react-native";
|
|
3
|
+
|
|
4
|
+
import * as Slot from "../slot";
|
|
5
|
+
import { ToggleGroupUtils } from "../utils";
|
|
6
|
+
|
|
7
|
+
import type { ItemProps, ItemRef, RootProps, RootRef } from "./types";
|
|
8
|
+
|
|
9
|
+
const ToggleGroupContext = React.createContext<RootProps | null>(null);
|
|
10
|
+
|
|
11
|
+
const Root = React.forwardRef<RootRef, RootProps>(
|
|
12
|
+
(
|
|
13
|
+
{ render, type, value, onValueChange, disabled = false, rovingFocus: _rovingFocus, orientation: _orientation, dir: _dir, loop: _loop, ...viewProps },
|
|
14
|
+
ref,
|
|
15
|
+
) => {
|
|
16
|
+
return (
|
|
17
|
+
<ToggleGroupContext.Provider
|
|
18
|
+
value={
|
|
19
|
+
{
|
|
20
|
+
type,
|
|
21
|
+
value,
|
|
22
|
+
disabled,
|
|
23
|
+
onValueChange,
|
|
24
|
+
} as RootProps
|
|
25
|
+
}
|
|
26
|
+
>
|
|
27
|
+
<Component
|
|
28
|
+
ref={ref}
|
|
29
|
+
role="group"
|
|
30
|
+
{...viewProps}
|
|
31
|
+
/>
|
|
32
|
+
</ToggleGroupContext.Provider>
|
|
33
|
+
);
|
|
34
|
+
},
|
|
35
|
+
);
|
|
36
|
+
|
|
37
|
+
Root.displayName = "RootToggleGroup";
|
|
38
|
+
|
|
39
|
+
function useRootContext() {
|
|
40
|
+
const context = React.useContext(ToggleGroupContext);
|
|
41
|
+
if (!context) {
|
|
42
|
+
throw new Error("ToggleGroup compound components cannot be rendered outside the ToggleGroup component");
|
|
43
|
+
}
|
|
44
|
+
return context;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const ItemContext = React.createContext<ItemProps | null>(null);
|
|
48
|
+
|
|
49
|
+
const Item = React.forwardRef<ItemRef, ItemProps>(({ value: itemValue, disabled: disabledProp = false, onPress: onPressProp, ...props }, ref) => {
|
|
50
|
+
// const id = React.useId();
|
|
51
|
+
const { type, disabled, value, onValueChange } = useRootContext();
|
|
52
|
+
|
|
53
|
+
function onPress(ev: GestureResponderEvent) {
|
|
54
|
+
if (disabled || disabledProp) return;
|
|
55
|
+
if (type === "single") {
|
|
56
|
+
onValueChange(ToggleGroupUtils.getNewSingleValue(value, itemValue));
|
|
57
|
+
}
|
|
58
|
+
if (type === "multiple") {
|
|
59
|
+
onValueChange(ToggleGroupUtils.getNewMultipleValue(value, itemValue));
|
|
60
|
+
}
|
|
61
|
+
onPressProp?.(ev);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const isChecked = type === "single" ? ToggleGroupUtils.getIsSelected(value, itemValue) : undefined;
|
|
65
|
+
const isSelected = type === "multiple" ? ToggleGroupUtils.getIsSelected(value, itemValue) : undefined;
|
|
66
|
+
|
|
67
|
+
return (
|
|
68
|
+
<ItemContext.Provider value={{ value: itemValue }}>
|
|
69
|
+
<Component
|
|
70
|
+
ref={ref}
|
|
71
|
+
aria-disabled={disabled}
|
|
72
|
+
role={type === "single" ? "radio" : "checkbox"}
|
|
73
|
+
onPress={onPress}
|
|
74
|
+
aria-checked={isChecked}
|
|
75
|
+
aria-selected={isSelected}
|
|
76
|
+
disabled={(disabled || disabledProp) ?? false}
|
|
77
|
+
accessibilityState={{
|
|
78
|
+
disabled: (disabled || disabledProp) ?? false,
|
|
79
|
+
checked: isChecked,
|
|
80
|
+
selected: isSelected,
|
|
81
|
+
}}
|
|
82
|
+
{...props}
|
|
83
|
+
/>
|
|
84
|
+
</ItemContext.Provider>
|
|
85
|
+
);
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
Item.displayName = "ItemToggleGroup";
|
|
89
|
+
|
|
90
|
+
function useItemContext() {
|
|
91
|
+
const context = React.useContext(ItemContext);
|
|
92
|
+
if (!context) {
|
|
93
|
+
throw new Error("ToggleGroupItem compound components cannot be rendered outside the ToggleGroupItem component");
|
|
94
|
+
}
|
|
95
|
+
return context;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
const utils = ToggleGroupUtils;
|
|
99
|
+
|
|
100
|
+
export { Item, Root, useItemContext, useRootContext, utils };
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
// import * as ToggleGroup from "@radix-ui/react-toggle-group";
|
|
2
|
+
// import * as React from "react";
|
|
3
|
+
// import { Pressable, View, type GestureResponderEvent } from "react-native";
|
|
4
|
+
|
|
5
|
+
// import * as Slot from "../slot";
|
|
6
|
+
// import { ToggleGroupUtils } from "../utils";
|
|
7
|
+
|
|
8
|
+
// import type { ItemProps, ItemRef, RootProps, RootRef } from "./types";
|
|
9
|
+
|
|
10
|
+
// const ToggleGroupContext = React.createContext<RootProps | null>(null);
|
|
11
|
+
|
|
12
|
+
// const Root = React.forwardRef<RootRef, RootProps>(
|
|
13
|
+
// ({ render, type, value, onValueChange, disabled = false, rovingFocus, orientation, dir, loop, ...viewProps }, ref) => {
|
|
14
|
+
//
|
|
15
|
+
// return (
|
|
16
|
+
// <ToggleGroupContext.Provider
|
|
17
|
+
// value={
|
|
18
|
+
// {
|
|
19
|
+
// type,
|
|
20
|
+
// value,
|
|
21
|
+
// disabled,
|
|
22
|
+
// onValueChange,
|
|
23
|
+
// } as RootProps
|
|
24
|
+
// }
|
|
25
|
+
// >
|
|
26
|
+
// <ToggleGroup.Root
|
|
27
|
+
// type={type as any}
|
|
28
|
+
// value={value as any}
|
|
29
|
+
// onValueChange={onValueChange as any}
|
|
30
|
+
// disabled={disabled}
|
|
31
|
+
// rovingFocus={rovingFocus}
|
|
32
|
+
// orientation={orientation}
|
|
33
|
+
// dir={dir}
|
|
34
|
+
// loop={loop}
|
|
35
|
+
// render
|
|
36
|
+
// >
|
|
37
|
+
// <Component
|
|
38
|
+
// ref={ref}
|
|
39
|
+
// {...viewProps}
|
|
40
|
+
// />
|
|
41
|
+
// </ToggleGroup.Root>
|
|
42
|
+
// </ToggleGroupContext.Provider>
|
|
43
|
+
// );
|
|
44
|
+
// },
|
|
45
|
+
// );
|
|
46
|
+
|
|
47
|
+
// Root.displayName = "RootToggleGroup";
|
|
48
|
+
|
|
49
|
+
// function useRootContext() {
|
|
50
|
+
// const context = React.useContext(ToggleGroupContext);
|
|
51
|
+
// if (!context) {
|
|
52
|
+
// throw new Error("ToggleGroup compound components cannot be rendered outside the ToggleGroup component");
|
|
53
|
+
// }
|
|
54
|
+
// return context;
|
|
55
|
+
// }
|
|
56
|
+
|
|
57
|
+
// const ItemContext = React.createContext<ItemProps | null>(null);
|
|
58
|
+
|
|
59
|
+
// const Item = React.forwardRef<ItemRef, ItemProps>(({ value: itemValue, disabled: disabledProp = false, onPress: onPressProp, ...props }, ref) => {
|
|
60
|
+
// const { type, disabled, value, onValueChange } = useRootContext();
|
|
61
|
+
|
|
62
|
+
// function onPress(ev: GestureResponderEvent) {
|
|
63
|
+
// onPressProp?.(ev);
|
|
64
|
+
// if (type === "single") {
|
|
65
|
+
// onValueChange(ToggleGroupUtils.getNewSingleValue(value, itemValue));
|
|
66
|
+
// }
|
|
67
|
+
// if (type === "multiple") {
|
|
68
|
+
// onValueChange(ToggleGroupUtils.getNewMultipleValue(value, itemValue));
|
|
69
|
+
// }
|
|
70
|
+
// }
|
|
71
|
+
|
|
72
|
+
//
|
|
73
|
+
// return (
|
|
74
|
+
// <ItemContext.Provider value={{ value: itemValue }}>
|
|
75
|
+
// <ToggleGroup.Item
|
|
76
|
+
// value={itemValue}
|
|
77
|
+
// render
|
|
78
|
+
// >
|
|
79
|
+
// <Component
|
|
80
|
+
// ref={ref}
|
|
81
|
+
// onPress={onPress}
|
|
82
|
+
// disabled={disabled || disabledProp}
|
|
83
|
+
// role="button"
|
|
84
|
+
// {...props}
|
|
85
|
+
// />
|
|
86
|
+
// </ToggleGroup.Item>
|
|
87
|
+
// </ItemContext.Provider>
|
|
88
|
+
// );
|
|
89
|
+
// });
|
|
90
|
+
|
|
91
|
+
// Item.displayName = "ItemToggleGroup";
|
|
92
|
+
|
|
93
|
+
// function useItemContext() {
|
|
94
|
+
// const context = React.useContext(ItemContext);
|
|
95
|
+
// if (!context) {
|
|
96
|
+
// throw new Error("ToggleGroupItem compound components cannot be rendered outside the ToggleGroupItem component");
|
|
97
|
+
// }
|
|
98
|
+
// return context;
|
|
99
|
+
// }
|
|
100
|
+
|
|
101
|
+
// const utils = ToggleGroupUtils;
|
|
102
|
+
|
|
103
|
+
// export { Item, Root, useItemContext, useRootContext, utils };
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { PressableRef, RenderPressableProps, RenderViewProps, ViewRef } from "../types";
|
|
2
|
+
|
|
3
|
+
type SingleRootProps = {
|
|
4
|
+
type: "single";
|
|
5
|
+
value: string | undefined;
|
|
6
|
+
onValueChange: (val: string | undefined) => void;
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
type MultipleRootProps = {
|
|
10
|
+
type: "multiple";
|
|
11
|
+
value: string[];
|
|
12
|
+
onValueChange: (val: string[]) => void;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
type RootProps = (SingleRootProps | MultipleRootProps) & {
|
|
16
|
+
disabled?: boolean;
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* @platform: WEB ONLY
|
|
20
|
+
*/
|
|
21
|
+
rovingFocus?: boolean;
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* @platform: WEB ONLY
|
|
25
|
+
*/
|
|
26
|
+
orientation?: "horizontal" | "vertical";
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* @platform: WEB ONLY
|
|
30
|
+
*/
|
|
31
|
+
dir?: "ltr" | "rtl";
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* @platform: WEB ONLY
|
|
35
|
+
*/
|
|
36
|
+
loop?: boolean;
|
|
37
|
+
} & RenderViewProps;
|
|
38
|
+
|
|
39
|
+
type ItemProps = RenderPressableProps & {
|
|
40
|
+
value: string;
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
type RootRef = ViewRef;
|
|
44
|
+
type ItemRef = PressableRef;
|
|
45
|
+
|
|
46
|
+
export type { ItemProps, ItemRef, RootProps, RootRef };
|