@brand-map/primitives 0.0.0-broken.0 → 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/tsconfig.json +1 -0
- 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
package/src/switch/types.ts
CHANGED
|
@@ -1,19 +1,40 @@
|
|
|
1
1
|
import type { PressableRef, RenderPressableProps, RenderViewProps, ViewRef } from "../types";
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
export interface SwitchRootState {
|
|
4
|
+
/**
|
|
5
|
+
* Whether the switch is currently active.
|
|
6
|
+
*/
|
|
7
|
+
checked: boolean;
|
|
8
|
+
/**
|
|
9
|
+
* Whether the component should ignore user interaction.
|
|
10
|
+
*/
|
|
11
|
+
disabled: boolean;
|
|
12
|
+
/**
|
|
13
|
+
* Whether the user should be unable to activate or deactivate the switch.
|
|
14
|
+
*/
|
|
15
|
+
readOnly: boolean;
|
|
16
|
+
/**
|
|
17
|
+
* Whether the user must activate the switch before submitting a form.
|
|
18
|
+
*/
|
|
19
|
+
required: boolean;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
type SwitchRootProps = RenderPressableProps<SwitchRootState> & {
|
|
4
23
|
checked: boolean;
|
|
5
24
|
onCheckedChange: (checked: boolean) => void;
|
|
6
25
|
disabled?: boolean;
|
|
26
|
+
readOnly?: boolean;
|
|
27
|
+
required?: boolean;
|
|
7
28
|
|
|
8
29
|
/**
|
|
9
30
|
* @platform: WEB ONLY
|
|
10
31
|
*/
|
|
11
|
-
onKeyDown?: (
|
|
32
|
+
onKeyDown?: (event: React.KeyboardEvent) => void;
|
|
12
33
|
};
|
|
13
34
|
|
|
14
|
-
type
|
|
35
|
+
type SwitchThumbProps = RenderViewProps<SwitchRootState>;
|
|
15
36
|
|
|
16
|
-
type
|
|
17
|
-
type
|
|
37
|
+
type SwitchRootRef = PressableRef;
|
|
38
|
+
type SwitchThumbRef = ViewRef;
|
|
18
39
|
|
|
19
|
-
export type {
|
|
40
|
+
export type { SwitchRootProps, SwitchRootRef, SwitchThumbProps, SwitchThumbRef };
|
package/src/table/table.tsx
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { forwardRef, Component } from "react";
|
|
2
2
|
import { Pressable, View } from "react-native";
|
|
3
3
|
|
|
4
|
-
import * as
|
|
4
|
+
import * as Render from "../render";
|
|
5
5
|
import type { PressableRef, RenderPressableProps, RenderViewProps, ViewRef } from "../types";
|
|
6
6
|
|
|
7
7
|
type RootProps = RenderViewProps;
|
|
8
8
|
type RootRef = ViewRef;
|
|
9
9
|
|
|
10
|
-
const Root =
|
|
10
|
+
const Root = forwardRef<RootRef, RootProps>(({ ...props }, ref) => {
|
|
11
11
|
return (
|
|
12
12
|
<Component
|
|
13
13
|
role="table"
|
|
@@ -21,7 +21,7 @@ Root.displayName = "RootTable";
|
|
|
21
21
|
type HeaderProps = RenderViewProps;
|
|
22
22
|
type HeaderRef = ViewRef;
|
|
23
23
|
|
|
24
|
-
const Header =
|
|
24
|
+
const Header = forwardRef<HeaderRef, HeaderProps>(({ ...props }, ref) => {
|
|
25
25
|
return (
|
|
26
26
|
<Component
|
|
27
27
|
role="rowheader"
|
|
@@ -35,7 +35,7 @@ Header.displayName = "HeaderTable";
|
|
|
35
35
|
type RowProps = RenderPressableProps;
|
|
36
36
|
type RowRef = PressableRef;
|
|
37
37
|
|
|
38
|
-
const Row =
|
|
38
|
+
const Row = forwardRef<RowRef, RowProps>(({ ...props }, ref) => {
|
|
39
39
|
return (
|
|
40
40
|
<Component
|
|
41
41
|
ref={ref}
|
|
@@ -49,7 +49,7 @@ Row.displayName = "RowTable";
|
|
|
49
49
|
type HeadProps = RenderViewProps;
|
|
50
50
|
type HeadRef = ViewRef;
|
|
51
51
|
|
|
52
|
-
const Head =
|
|
52
|
+
const Head = forwardRef<HeadRef, HeadProps>(({ ...props }, ref) => {
|
|
53
53
|
return (
|
|
54
54
|
<Component
|
|
55
55
|
ref={ref}
|
|
@@ -63,7 +63,7 @@ Head.displayName = "HeadTable";
|
|
|
63
63
|
type BodyProps = RenderViewProps;
|
|
64
64
|
type BodyRef = ViewRef;
|
|
65
65
|
|
|
66
|
-
const Body =
|
|
66
|
+
const Body = forwardRef<BodyRef, BodyProps>(({ ...props }, ref) => {
|
|
67
67
|
return (
|
|
68
68
|
<Component
|
|
69
69
|
ref={ref}
|
|
@@ -77,7 +77,7 @@ Body.displayName = "BodyTable";
|
|
|
77
77
|
type CellProps = RenderViewProps;
|
|
78
78
|
type CellRef = ViewRef;
|
|
79
79
|
|
|
80
|
-
const Cell =
|
|
80
|
+
const Cell = forwardRef<CellRef, CellProps>(({ ...props }, ref) => {
|
|
81
81
|
return (
|
|
82
82
|
<Component
|
|
83
83
|
ref={ref}
|
|
@@ -91,7 +91,7 @@ Cell.displayName = "CellTable";
|
|
|
91
91
|
type FooterProps = RenderViewProps;
|
|
92
92
|
type FooterRef = ViewRef;
|
|
93
93
|
|
|
94
|
-
const Footer =
|
|
94
|
+
const Footer = forwardRef<FooterRef, FooterProps>(({ ...props }, ref) => {
|
|
95
95
|
return (
|
|
96
96
|
<Component
|
|
97
97
|
ref={ref}
|
package/src/tabs/tabs.tsx
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { createContext, forwardRef, useId, useContext } from "react";
|
|
2
2
|
import { Pressable, View, type GestureResponderEvent } from "react-native";
|
|
3
3
|
|
|
4
|
-
import * as
|
|
4
|
+
import * as Render from "../render";
|
|
5
5
|
|
|
6
6
|
import type { ContentProps, ContentRef, ListProps, ListRef, RootProps, RootRef, TriggerProps, TriggerRef } from "./types";
|
|
7
7
|
|
|
@@ -9,11 +9,11 @@ interface RootContext extends RootProps {
|
|
|
9
9
|
nativeID: string;
|
|
10
10
|
}
|
|
11
11
|
|
|
12
|
-
const TabsContext =
|
|
12
|
+
const TabsContext = createContext<RootContext | null>(null);
|
|
13
13
|
|
|
14
|
-
const Root =
|
|
14
|
+
const Root = forwardRef<RootRef, RootProps>(
|
|
15
15
|
({ render, value, onValueChange, orientation: _orientation, dir: _dir, activationMode: _activationMode, ...viewProps }, ref) => {
|
|
16
|
-
const nativeID =
|
|
16
|
+
const nativeID = useId();
|
|
17
17
|
|
|
18
18
|
return (
|
|
19
19
|
<TabsContext.Provider
|
|
@@ -35,14 +35,14 @@ const Root = React.forwardRef<RootRef, RootProps>(
|
|
|
35
35
|
Root.displayName = "RootNativeTabs";
|
|
36
36
|
|
|
37
37
|
function useRootContext() {
|
|
38
|
-
const context =
|
|
38
|
+
const context = useContext(TabsContext);
|
|
39
39
|
if (!context) {
|
|
40
40
|
throw new Error("Tabs compound components cannot be rendered outside the Tabs component");
|
|
41
41
|
}
|
|
42
42
|
return context;
|
|
43
43
|
}
|
|
44
44
|
|
|
45
|
-
const List =
|
|
45
|
+
const List = forwardRef<ListRef, ListProps>(({ ...props }, ref) => {
|
|
46
46
|
return (
|
|
47
47
|
<Component
|
|
48
48
|
ref={ref}
|
|
@@ -54,15 +54,15 @@ const List = React.forwardRef<ListRef, ListProps>(({ ...props }, ref) => {
|
|
|
54
54
|
|
|
55
55
|
List.displayName = "ListNativeTabs";
|
|
56
56
|
|
|
57
|
-
const TriggerContext =
|
|
57
|
+
const TriggerContext = createContext<{ value: string } | null>(null);
|
|
58
58
|
|
|
59
|
-
const Trigger =
|
|
59
|
+
const Trigger = forwardRef<TriggerRef, TriggerProps>(({ onPress: onPressProp, disabled, value: tabValue, ...props }, ref) => {
|
|
60
60
|
const { onValueChange, value: rootValue, nativeID } = useRootContext();
|
|
61
61
|
|
|
62
|
-
function onPress(
|
|
62
|
+
function onPress(event: GestureResponderEvent) {
|
|
63
63
|
if (disabled) return;
|
|
64
64
|
onValueChange(tabValue);
|
|
65
|
-
onPressProp?.(
|
|
65
|
+
onPressProp?.(event);
|
|
66
66
|
}
|
|
67
67
|
|
|
68
68
|
return (
|
|
@@ -88,14 +88,14 @@ const Trigger = React.forwardRef<TriggerRef, TriggerProps>(({ onPress: onPressPr
|
|
|
88
88
|
Trigger.displayName = "TriggerNativeTabs";
|
|
89
89
|
|
|
90
90
|
function useTriggerContext() {
|
|
91
|
-
const context =
|
|
91
|
+
const context = useContext(TriggerContext);
|
|
92
92
|
if (!context) {
|
|
93
93
|
throw new Error("Tabs.Trigger compound components cannot be rendered outside the Tabs.Trigger component");
|
|
94
94
|
}
|
|
95
95
|
return context;
|
|
96
96
|
}
|
|
97
97
|
|
|
98
|
-
const Content =
|
|
98
|
+
const Content = forwardRef<ContentRef, ContentProps>(({ keepMounted, value: tabValue, ...props }, ref) => {
|
|
99
99
|
const { value: rootValue, nativeID } = useRootContext();
|
|
100
100
|
|
|
101
101
|
if (!keepMounted) {
|
package/src/tabs/tabs.web.tsx
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
// import * as Tabs from "@radix-ui/react-tabs";
|
|
2
|
-
//
|
|
2
|
+
//
|
|
3
3
|
// import { Pressable, View } from "react-native";
|
|
4
4
|
|
|
5
|
-
// import * as
|
|
5
|
+
// import * as Render from "../render";
|
|
6
6
|
|
|
7
7
|
// import type { ContentProps, ContentRef, ListProps, ListRef, RootProps, RootRef, TriggerProps, TriggerRef } from "./types";
|
|
8
8
|
|
|
9
|
-
// const TabsContext =
|
|
10
|
-
// const Root =
|
|
9
|
+
// const TabsContext = createContext<RootProps | null>(null);
|
|
10
|
+
// const Root = forwardRef<RootRef, RootProps>(({ value, onValueChange, orientation, dir, activationMode, ...viewProps }, ref) => {
|
|
11
11
|
//
|
|
12
12
|
// return (
|
|
13
13
|
// <TabsContext.Provider
|
|
@@ -36,14 +36,14 @@
|
|
|
36
36
|
// Root.displayName = "RootWebTabs";
|
|
37
37
|
|
|
38
38
|
// function useRootContext() {
|
|
39
|
-
// const context =
|
|
39
|
+
// const context = useContext(TabsContext);
|
|
40
40
|
// if (!context) {
|
|
41
41
|
// throw new Error("Tabs compound components cannot be rendered outside the Tabs component");
|
|
42
42
|
// }
|
|
43
43
|
// return context;
|
|
44
44
|
// }
|
|
45
45
|
|
|
46
|
-
// const List =
|
|
46
|
+
// const List = forwardRef<ListRef, ListProps>(({ ...props }, ref) => {
|
|
47
47
|
//
|
|
48
48
|
// return (
|
|
49
49
|
// <Tabs.List render>
|
|
@@ -57,8 +57,8 @@
|
|
|
57
57
|
|
|
58
58
|
// List.displayName = "ListWebTabs";
|
|
59
59
|
|
|
60
|
-
// const TriggerContext =
|
|
61
|
-
// const Trigger =
|
|
60
|
+
// const TriggerContext = createContext<{ value: string } | null>(null);
|
|
61
|
+
// const Trigger = forwardRef<TriggerRef, TriggerProps>(({ value: tabValue, ...props }, ref) => {
|
|
62
62
|
//
|
|
63
63
|
// return (
|
|
64
64
|
// <TriggerContext.Provider value={{ value: tabValue }}>
|
|
@@ -78,14 +78,14 @@
|
|
|
78
78
|
// Trigger.displayName = "TriggerWebTabs";
|
|
79
79
|
|
|
80
80
|
// function useTriggerContext() {
|
|
81
|
-
// const context =
|
|
81
|
+
// const context = useContext(TriggerContext);
|
|
82
82
|
// if (!context) {
|
|
83
83
|
// throw new Error("Tabs.Trigger compound components cannot be rendered outside the Tabs.Trigger component");
|
|
84
84
|
// }
|
|
85
85
|
// return context;
|
|
86
86
|
// }
|
|
87
87
|
|
|
88
|
-
// const Content =
|
|
88
|
+
// const Content = forwardRef<ContentRef, ContentProps>(({ keepMounted, value, tabIndex = -1, ...props }, ref) => {
|
|
89
89
|
//
|
|
90
90
|
// return (
|
|
91
91
|
// <Tabs.Content
|
package/src/toast/toast.tsx
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { createContext, forwardRef, useId, useContext } from "react";
|
|
2
2
|
import { Pressable, Text, View, type GestureResponderEvent } from "react-native";
|
|
3
3
|
|
|
4
|
-
import * as
|
|
4
|
+
import * as Render from "../render";
|
|
5
5
|
|
|
6
6
|
import type { ActionProps, ActionRef, CloseProps, CloseRef, DescriptionProps, DescriptionRef, RootProps, RootRef, TitleProps, TitleRef } from "./types";
|
|
7
7
|
|
|
8
8
|
interface RootContext extends RootProps {
|
|
9
9
|
nativeID: string;
|
|
10
10
|
}
|
|
11
|
-
const ToastContext =
|
|
11
|
+
const ToastContext = createContext<RootContext | null>(null);
|
|
12
12
|
|
|
13
|
-
const Root =
|
|
14
|
-
const nativeID =
|
|
13
|
+
const Root = forwardRef<RootRef, RootProps>(({ type = "foreground", open, onOpenChange, ...viewProps }, ref) => {
|
|
14
|
+
const nativeID = useId();
|
|
15
15
|
|
|
16
16
|
if (!open) {
|
|
17
17
|
return null;
|
|
@@ -39,20 +39,20 @@ const Root = React.forwardRef<RootRef, RootProps>(({ type = "foreground", open,
|
|
|
39
39
|
Root.displayName = "RootToast";
|
|
40
40
|
|
|
41
41
|
function useToastContext() {
|
|
42
|
-
const context =
|
|
42
|
+
const context = useContext(ToastContext);
|
|
43
43
|
if (!context) {
|
|
44
44
|
throw new Error("Toast compound components cannot be rendered outside the Toast component");
|
|
45
45
|
}
|
|
46
46
|
return context;
|
|
47
47
|
}
|
|
48
48
|
|
|
49
|
-
const Close =
|
|
49
|
+
const Close = forwardRef<CloseRef, CloseProps>(({ onPress: onPressProp, disabled = false, ...props }, ref) => {
|
|
50
50
|
const { onOpenChange } = useToastContext();
|
|
51
51
|
|
|
52
|
-
function onPress(
|
|
52
|
+
function onPress(event: GestureResponderEvent) {
|
|
53
53
|
if (disabled) return;
|
|
54
54
|
onOpenChange(false);
|
|
55
|
-
onPressProp?.(
|
|
55
|
+
onPressProp?.(event);
|
|
56
56
|
}
|
|
57
57
|
|
|
58
58
|
return (
|
|
@@ -69,13 +69,13 @@ const Close = React.forwardRef<CloseRef, CloseProps>(({ onPress: onPressProp, di
|
|
|
69
69
|
|
|
70
70
|
Close.displayName = "CloseToast";
|
|
71
71
|
|
|
72
|
-
const Action =
|
|
72
|
+
const Action = forwardRef<ActionRef, ActionProps>(({ onPress: onPressProp, disabled = false, ...props }, ref) => {
|
|
73
73
|
const { onOpenChange } = useToastContext();
|
|
74
74
|
|
|
75
|
-
function onPress(
|
|
75
|
+
function onPress(event: GestureResponderEvent) {
|
|
76
76
|
if (disabled) return;
|
|
77
77
|
onOpenChange(false);
|
|
78
|
-
onPressProp?.(
|
|
78
|
+
onPressProp?.(event);
|
|
79
79
|
}
|
|
80
80
|
|
|
81
81
|
return (
|
|
@@ -92,7 +92,7 @@ const Action = React.forwardRef<ActionRef, ActionProps>(({ onPress: onPressProp,
|
|
|
92
92
|
|
|
93
93
|
Action.displayName = "ActionToast";
|
|
94
94
|
|
|
95
|
-
const Title =
|
|
95
|
+
const Title = forwardRef<TitleRef, TitleProps>(({ ...props }, ref) => {
|
|
96
96
|
const { nativeID } = useToastContext();
|
|
97
97
|
|
|
98
98
|
return (
|
|
@@ -107,7 +107,7 @@ const Title = React.forwardRef<TitleRef, TitleProps>(({ ...props }, ref) => {
|
|
|
107
107
|
|
|
108
108
|
Title.displayName = "TitleToast";
|
|
109
109
|
|
|
110
|
-
const Description =
|
|
110
|
+
const Description = forwardRef<DescriptionRef, DescriptionProps>(({ ...props }, ref) => {
|
|
111
111
|
const { nativeID } = useToastContext();
|
|
112
112
|
|
|
113
113
|
return (
|
package/src/toggle/toggle.tsx
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { forwardRef } from "react";
|
|
2
2
|
import { Pressable, type GestureResponderEvent } from "react-native";
|
|
3
3
|
|
|
4
|
-
import * as
|
|
4
|
+
import * as Render from "../render";
|
|
5
5
|
|
|
6
6
|
import type { RootProps, RootRef } from "./types";
|
|
7
7
|
|
|
8
|
-
const Root =
|
|
9
|
-
function onPress(
|
|
8
|
+
const Root = forwardRef<RootRef, RootProps>(({ pressed, onPressedChange, disabled, onPress: onPressProp, ...props }, ref) => {
|
|
9
|
+
function onPress(event: GestureResponderEvent) {
|
|
10
10
|
if (disabled) return;
|
|
11
11
|
const newValue = !pressed;
|
|
12
12
|
onPressedChange(newValue);
|
|
13
|
-
onPressProp?.(
|
|
13
|
+
onPressProp?.(event);
|
|
14
14
|
}
|
|
15
15
|
|
|
16
16
|
return (
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
// import * as Toggle from "@radix-ui/react-toggle";
|
|
2
|
-
//
|
|
2
|
+
//
|
|
3
3
|
// import { Pressable, type GestureResponderEvent } from "react-native";
|
|
4
4
|
|
|
5
|
-
// import * as
|
|
5
|
+
// import * as Render from "../render";
|
|
6
6
|
|
|
7
7
|
// import type { RootProps, RootRef } from "./types";
|
|
8
8
|
|
|
9
|
-
// const Root =
|
|
10
|
-
// function onPress(
|
|
11
|
-
// onPressProp?.(
|
|
9
|
+
// const Root = forwardRef<RootRef, RootProps>(({ pressed, onPressedChange, disabled, onPress: onPressProp, ...props }, ref) => {
|
|
10
|
+
// function onPress(event: GestureResponderEvent) {
|
|
11
|
+
// onPressProp?.(event);
|
|
12
12
|
// onPressedChange(!pressed);
|
|
13
13
|
// }
|
|
14
14
|
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { createContext, forwardRef, useContext } from "react";
|
|
2
2
|
import { Pressable, View, type GestureResponderEvent } from "react-native";
|
|
3
3
|
|
|
4
|
-
import * as
|
|
4
|
+
import * as Render from "../render";
|
|
5
5
|
import { ToggleGroupUtils } from "../utils";
|
|
6
6
|
|
|
7
7
|
import type { ItemProps, ItemRef, RootProps, RootRef } from "./types";
|
|
8
8
|
|
|
9
|
-
const ToggleGroupContext =
|
|
9
|
+
const ToggleGroupContext = createContext<RootProps | null>(null);
|
|
10
10
|
|
|
11
|
-
const Root =
|
|
11
|
+
const Root = forwardRef<RootRef, RootProps>(
|
|
12
12
|
(
|
|
13
13
|
{ render, type, value, onValueChange, disabled = false, rovingFocus: _rovingFocus, orientation: _orientation, dir: _dir, loop: _loop, ...viewProps },
|
|
14
14
|
ref,
|
|
@@ -37,20 +37,20 @@ const Root = React.forwardRef<RootRef, RootProps>(
|
|
|
37
37
|
Root.displayName = "RootToggleGroup";
|
|
38
38
|
|
|
39
39
|
function useRootContext() {
|
|
40
|
-
const context =
|
|
40
|
+
const context = useContext(ToggleGroupContext);
|
|
41
41
|
if (!context) {
|
|
42
42
|
throw new Error("ToggleGroup compound components cannot be rendered outside the ToggleGroup component");
|
|
43
43
|
}
|
|
44
44
|
return context;
|
|
45
45
|
}
|
|
46
46
|
|
|
47
|
-
const ItemContext =
|
|
47
|
+
const ItemContext = createContext<ItemProps | null>(null);
|
|
48
48
|
|
|
49
|
-
const Item =
|
|
50
|
-
// const id =
|
|
49
|
+
const Item = forwardRef<ItemRef, ItemProps>(({ value: itemValue, disabled: disabledProp = false, onPress: onPressProp, ...props }, ref) => {
|
|
50
|
+
// const id = useId();
|
|
51
51
|
const { type, disabled, value, onValueChange } = useRootContext();
|
|
52
52
|
|
|
53
|
-
function onPress(
|
|
53
|
+
function onPress(event: GestureResponderEvent) {
|
|
54
54
|
if (disabled || disabledProp) return;
|
|
55
55
|
if (type === "single") {
|
|
56
56
|
onValueChange(ToggleGroupUtils.getNewSingleValue(value, itemValue));
|
|
@@ -58,7 +58,7 @@ const Item = React.forwardRef<ItemRef, ItemProps>(({ value: itemValue, disabled:
|
|
|
58
58
|
if (type === "multiple") {
|
|
59
59
|
onValueChange(ToggleGroupUtils.getNewMultipleValue(value, itemValue));
|
|
60
60
|
}
|
|
61
|
-
onPressProp?.(
|
|
61
|
+
onPressProp?.(event);
|
|
62
62
|
}
|
|
63
63
|
|
|
64
64
|
const isChecked = type === "single" ? ToggleGroupUtils.getIsSelected(value, itemValue) : undefined;
|
|
@@ -88,7 +88,7 @@ const Item = React.forwardRef<ItemRef, ItemProps>(({ value: itemValue, disabled:
|
|
|
88
88
|
Item.displayName = "ItemToggleGroup";
|
|
89
89
|
|
|
90
90
|
function useItemContext() {
|
|
91
|
-
const context =
|
|
91
|
+
const context = useContext(ItemContext);
|
|
92
92
|
if (!context) {
|
|
93
93
|
throw new Error("ToggleGroupItem compound components cannot be rendered outside the ToggleGroupItem component");
|
|
94
94
|
}
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
// import * as ToggleGroup from "@radix-ui/react-toggle-group";
|
|
2
|
-
//
|
|
2
|
+
//
|
|
3
3
|
// import { Pressable, View, type GestureResponderEvent } from "react-native";
|
|
4
4
|
|
|
5
|
-
// import * as
|
|
5
|
+
// import * as Render from "../render";
|
|
6
6
|
// import { ToggleGroupUtils } from "../utils";
|
|
7
7
|
|
|
8
8
|
// import type { ItemProps, ItemRef, RootProps, RootRef } from "./types";
|
|
9
9
|
|
|
10
|
-
// const ToggleGroupContext =
|
|
10
|
+
// const ToggleGroupContext = createContext<RootProps | null>(null);
|
|
11
11
|
|
|
12
|
-
// const Root =
|
|
12
|
+
// const Root = forwardRef<RootRef, RootProps>(
|
|
13
13
|
// ({ render, type, value, onValueChange, disabled = false, rovingFocus, orientation, dir, loop, ...viewProps }, ref) => {
|
|
14
14
|
//
|
|
15
15
|
// return (
|
|
@@ -47,20 +47,20 @@
|
|
|
47
47
|
// Root.displayName = "RootToggleGroup";
|
|
48
48
|
|
|
49
49
|
// function useRootContext() {
|
|
50
|
-
// const context =
|
|
50
|
+
// const context = useContext(ToggleGroupContext);
|
|
51
51
|
// if (!context) {
|
|
52
52
|
// throw new Error("ToggleGroup compound components cannot be rendered outside the ToggleGroup component");
|
|
53
53
|
// }
|
|
54
54
|
// return context;
|
|
55
55
|
// }
|
|
56
56
|
|
|
57
|
-
// const ItemContext =
|
|
57
|
+
// const ItemContext = createContext<ItemProps | null>(null);
|
|
58
58
|
|
|
59
|
-
// const Item =
|
|
59
|
+
// const Item = forwardRef<ItemRef, ItemProps>(({ value: itemValue, disabled: disabledProp = false, onPress: onPressProp, ...props }, ref) => {
|
|
60
60
|
// const { type, disabled, value, onValueChange } = useRootContext();
|
|
61
61
|
|
|
62
|
-
// function onPress(
|
|
63
|
-
// onPressProp?.(
|
|
62
|
+
// function onPress(event: GestureResponderEvent) {
|
|
63
|
+
// onPressProp?.(event);
|
|
64
64
|
// if (type === "single") {
|
|
65
65
|
// onValueChange(ToggleGroupUtils.getNewSingleValue(value, itemValue));
|
|
66
66
|
// }
|
|
@@ -91,7 +91,7 @@
|
|
|
91
91
|
// Item.displayName = "ItemToggleGroup";
|
|
92
92
|
|
|
93
93
|
// function useItemContext() {
|
|
94
|
-
// const context =
|
|
94
|
+
// const context = useContext(ItemContext);
|
|
95
95
|
// if (!context) {
|
|
96
96
|
// throw new Error("ToggleGroupItem compound components cannot be rendered outside the ToggleGroupItem component");
|
|
97
97
|
// }
|
package/src/toolbar/toolbar.tsx
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { forwardRef, createContext, useContext } from "react";
|
|
2
2
|
import { Pressable, View, type GestureResponderEvent } from "react-native";
|
|
3
3
|
|
|
4
|
-
import * as
|
|
4
|
+
import * as Render from "../render";
|
|
5
5
|
import { ToggleGroupUtils } from "../utils";
|
|
6
6
|
|
|
7
7
|
import type {
|
|
@@ -19,7 +19,7 @@ import type {
|
|
|
19
19
|
ToggleItemRef,
|
|
20
20
|
} from "./types";
|
|
21
21
|
|
|
22
|
-
const Root =
|
|
22
|
+
const Root = forwardRef<RootRef, RootProps>(({ orientation: _orientation, dir: _dir, loop: _loop, ...props }, ref) => {
|
|
23
23
|
return (
|
|
24
24
|
<Component
|
|
25
25
|
ref={ref}
|
|
@@ -31,9 +31,9 @@ const Root = React.forwardRef<RootRef, RootProps>(({ orientation: _orientation,
|
|
|
31
31
|
|
|
32
32
|
Root.displayName = "RootNativeToolbar";
|
|
33
33
|
|
|
34
|
-
const ToggleGroupContext =
|
|
34
|
+
const ToggleGroupContext = createContext<ToggleGroupProps | null>(null);
|
|
35
35
|
|
|
36
|
-
const ToggleGroup =
|
|
36
|
+
const ToggleGroup = forwardRef<ToggleGroupRef, ToggleGroupProps>(({ type, value, onValueChange, disabled = false, ...viewProps }, ref) => {
|
|
37
37
|
return (
|
|
38
38
|
<ToggleGroupContext.Provider
|
|
39
39
|
value={
|
|
@@ -57,18 +57,18 @@ const ToggleGroup = React.forwardRef<ToggleGroupRef, ToggleGroupProps>(({ type,
|
|
|
57
57
|
ToggleGroup.displayName = "ToggleGroupNativeToolbar";
|
|
58
58
|
|
|
59
59
|
function useToggleGroupContext() {
|
|
60
|
-
const context =
|
|
60
|
+
const context = useContext(ToggleGroupContext);
|
|
61
61
|
if (!context) {
|
|
62
62
|
throw new Error("ToggleGroup compound components cannot be rendered outside the ToggleGroup component");
|
|
63
63
|
}
|
|
64
64
|
return context;
|
|
65
65
|
}
|
|
66
66
|
|
|
67
|
-
const ToggleItem =
|
|
67
|
+
const ToggleItem = forwardRef<ToggleItemRef, ToggleItemProps>(
|
|
68
68
|
({ render, value: itemValue, disabled: disabledProp = false, onPress: onPressProp, ...props }, ref) => {
|
|
69
69
|
const { type, disabled, value, onValueChange } = useToggleGroupContext();
|
|
70
70
|
|
|
71
|
-
function onPress(
|
|
71
|
+
function onPress(event: GestureResponderEvent) {
|
|
72
72
|
if (disabled || disabledProp) return;
|
|
73
73
|
if (type === "single") {
|
|
74
74
|
onValueChange(ToggleGroupUtils.getNewSingleValue(value, itemValue));
|
|
@@ -76,7 +76,7 @@ const ToggleItem = React.forwardRef<ToggleItemRef, ToggleItemProps>(
|
|
|
76
76
|
if (type === "multiple") {
|
|
77
77
|
onValueChange(ToggleGroupUtils.getNewMultipleValue(value, itemValue));
|
|
78
78
|
}
|
|
79
|
-
onPressProp?.(
|
|
79
|
+
onPressProp?.(event);
|
|
80
80
|
}
|
|
81
81
|
|
|
82
82
|
const isChecked = type === "single" ? ToggleGroupUtils.getIsSelected(value, itemValue) : undefined;
|
|
@@ -104,7 +104,7 @@ const ToggleItem = React.forwardRef<ToggleItemRef, ToggleItemProps>(
|
|
|
104
104
|
|
|
105
105
|
ToggleItem.displayName = "ToggleItemNativeToolbar";
|
|
106
106
|
|
|
107
|
-
const Separator =
|
|
107
|
+
const Separator = forwardRef<SeparatorRef, SeparatorProps>(({ ...props }, ref) => {
|
|
108
108
|
return (
|
|
109
109
|
<Component
|
|
110
110
|
role={"separator"}
|
|
@@ -116,7 +116,7 @@ const Separator = React.forwardRef<SeparatorRef, SeparatorProps>(({ ...props },
|
|
|
116
116
|
|
|
117
117
|
Separator.displayName = "SeparatorNativeToolbar";
|
|
118
118
|
|
|
119
|
-
const Link =
|
|
119
|
+
const Link = forwardRef<LinkRef, LinkProps>(({ ...props }, ref) => {
|
|
120
120
|
return (
|
|
121
121
|
<Component
|
|
122
122
|
ref={ref}
|
|
@@ -128,7 +128,7 @@ const Link = React.forwardRef<LinkRef, LinkProps>(({ ...props }, ref) => {
|
|
|
128
128
|
|
|
129
129
|
Link.displayName = "LinkNativeToolbar";
|
|
130
130
|
|
|
131
|
-
const Button =
|
|
131
|
+
const Button = forwardRef<ButtonRef, ButtonProps>(({ ...props }, ref) => {
|
|
132
132
|
return (
|
|
133
133
|
<Component
|
|
134
134
|
ref={ref}
|