@react-native-reusables/cli 0.0.8 → 0.0.10
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/dist/generated/components/primitives/accordion/accordion.tsx +216 -0
- package/dist/generated/components/primitives/accordion/accordion.web.tsx +295 -0
- package/dist/generated/components/primitives/accordion/index.ts +1 -0
- package/dist/generated/components/primitives/accordion/types.ts +45 -0
- package/dist/generated/components/primitives/alert-dialog/alert-dialog.tsx +237 -0
- package/dist/generated/components/primitives/alert-dialog/alert-dialog.web.tsx +256 -0
- package/dist/generated/components/primitives/alert-dialog/index.ts +1 -0
- package/dist/generated/components/primitives/alert-dialog/types.ts +48 -0
- package/dist/generated/components/primitives/aspect-ratio.tsx +23 -0
- package/dist/generated/components/primitives/avatar/ types.ts +10 -0
- package/dist/generated/components/primitives/avatar/index.tsx +95 -0
- package/dist/generated/components/primitives/checkbox/checkbox.tsx +101 -0
- package/dist/generated/components/primitives/checkbox/checkbox.web.tsx +114 -0
- package/dist/generated/components/primitives/checkbox/index.ts +1 -0
- package/dist/generated/components/primitives/checkbox/types.ts +11 -0
- package/dist/generated/components/primitives/collapsible/collapsible.tsx +119 -0
- package/dist/generated/components/primitives/collapsible/collapsible.web.tsx +157 -0
- package/dist/generated/components/primitives/collapsible/index.ts +1 -0
- package/dist/generated/components/primitives/collapsible/types.ts +18 -0
- package/dist/generated/components/primitives/context-menu/context-menu.tsx +626 -0
- package/dist/generated/components/primitives/context-menu/context-menu.web.tsx +504 -0
- package/dist/generated/components/primitives/context-menu/index.ts +1 -0
- package/dist/generated/components/primitives/context-menu/types.ts +82 -0
- package/dist/generated/components/primitives/dialog/dialog.tsx +211 -0
- package/dist/generated/components/primitives/dialog/dialog.web.tsx +197 -0
- package/dist/generated/components/primitives/dialog/index.ts +1 -0
- package/dist/generated/components/primitives/dialog/types.ts +60 -0
- package/dist/generated/components/primitives/dropdown-menu/dropdown-menu.tsx +584 -0
- package/dist/generated/components/primitives/dropdown-menu/dropdown-menu.web.tsx +521 -0
- package/dist/generated/components/primitives/dropdown-menu/index.ts +1 -0
- package/dist/generated/components/primitives/dropdown-menu/types.ts +71 -0
- package/dist/generated/components/primitives/hooks/index.ts +3 -0
- package/dist/generated/components/primitives/hooks/useAugmentedRef.tsx +29 -0
- package/dist/generated/components/primitives/hooks/useControllableState.tsx +75 -0
- package/dist/generated/components/primitives/hooks/useRelativePosition.tsx +227 -0
- package/dist/generated/components/primitives/hover-card/hover-card.tsx +271 -0
- package/dist/generated/components/primitives/hover-card/hover-card.web.tsx +145 -0
- package/dist/generated/components/primitives/hover-card/index.ts +1 -0
- package/dist/generated/components/primitives/hover-card/types.ts +42 -0
- package/dist/generated/components/primitives/label/index.ts +1 -0
- package/dist/generated/components/primitives/label/label.tsx +31 -0
- package/dist/generated/components/primitives/label/label.web.tsx +36 -0
- package/dist/generated/components/primitives/label/types.ts +15 -0
- package/dist/generated/components/primitives/menubar/index.ts +1 -0
- package/dist/generated/components/primitives/menubar/menubar.tsx +624 -0
- package/dist/generated/components/primitives/menubar/menubar.web.tsx +543 -0
- package/dist/generated/components/primitives/menubar/types.ts +76 -0
- package/dist/generated/components/primitives/navigation-menu/index.ts +1 -0
- package/dist/generated/components/primitives/navigation-menu/navigation-menu.tsx +315 -0
- package/dist/generated/components/primitives/navigation-menu/navigation-menu.web.tsx +264 -0
- package/dist/generated/components/primitives/navigation-menu/types.ts +49 -0
- package/dist/generated/components/primitives/popover/index.ts +1 -0
- package/dist/generated/components/primitives/popover/popover.tsx +286 -0
- package/dist/generated/components/primitives/popover/popover.web.tsx +179 -0
- package/dist/generated/components/primitives/popover/types.ts +30 -0
- package/dist/generated/components/primitives/portal.tsx +67 -0
- package/dist/generated/components/primitives/progress/index.ts +1 -0
- package/dist/generated/components/primitives/progress/progress.tsx +59 -0
- package/dist/generated/components/primitives/progress/progress.web.tsx +36 -0
- package/dist/generated/components/primitives/progress/types.ts +7 -0
- package/dist/generated/components/primitives/radio-group/index.ts +1 -0
- package/dist/generated/components/primitives/radio-group/radio-group.tsx +116 -0
- package/dist/generated/components/primitives/radio-group/radio-group.web.tsx +78 -0
- package/dist/generated/components/primitives/radio-group/types.ts +15 -0
- package/dist/generated/components/primitives/select/index.ts +1 -0
- package/dist/generated/components/primitives/select/select.tsx +455 -0
- package/dist/generated/components/primitives/select/select.web.tsx +319 -0
- package/dist/generated/components/primitives/select/types.ts +87 -0
- package/dist/generated/components/primitives/separator/ types.ts +6 -0
- package/dist/generated/components/primitives/separator/index.tsx +23 -0
- package/dist/generated/components/primitives/slider/index.ts +1 -0
- package/dist/generated/components/primitives/slider/slider.tsx +89 -0
- package/dist/generated/components/primitives/slider/slider.web.tsx +67 -0
- package/dist/generated/components/primitives/slider/types.ts +24 -0
- package/dist/generated/components/primitives/slot.tsx +187 -0
- package/dist/generated/components/primitives/switch/index.ts +1 -0
- package/dist/generated/components/primitives/switch/switch.tsx +65 -0
- package/dist/generated/components/primitives/switch/switch.web.tsx +67 -0
- package/dist/generated/components/primitives/switch/types.ts +11 -0
- package/dist/generated/components/primitives/table.tsx +55 -0
- package/dist/generated/components/primitives/tabs/index.ts +1 -0
- package/dist/generated/components/primitives/tabs/tabs.tsx +133 -0
- package/dist/generated/components/primitives/tabs/tabs.web.tsx +97 -0
- package/dist/generated/components/primitives/tabs/types.ts +24 -0
- package/dist/generated/components/primitives/toast/ types.ts +7 -0
- package/dist/generated/components/primitives/toast/index.tsx +128 -0
- package/dist/generated/components/primitives/toggle/index.ts +1 -0
- package/dist/generated/components/primitives/toggle/toggle.tsx +37 -0
- package/dist/generated/components/primitives/toggle/toggle.web.tsx +26 -0
- package/dist/generated/components/primitives/toggle/types.ts +7 -0
- package/dist/generated/components/primitives/toggle-group/index.ts +1 -0
- package/dist/generated/components/primitives/toggle-group/toggle-group.tsx +125 -0
- package/dist/generated/components/primitives/toggle-group/toggle-group.web.tsx +124 -0
- package/dist/generated/components/primitives/toggle-group/types.ts +37 -0
- package/dist/generated/components/primitives/toolbar/index.ts +1 -0
- package/dist/generated/components/primitives/toolbar/toolbar.tsx +125 -0
- package/dist/generated/components/primitives/toolbar/toolbar.web.tsx +129 -0
- package/dist/generated/components/primitives/toolbar/types.ts +39 -0
- package/dist/generated/components/primitives/tooltip/index.ts +1 -0
- package/dist/generated/components/primitives/tooltip/tooltip.tsx +271 -0
- package/dist/generated/components/primitives/tooltip/tooltip.web.tsx +167 -0
- package/dist/generated/components/primitives/tooltip/types.ts +44 -0
- package/dist/generated/components/primitives/types.ts +105 -0
- package/dist/generated/components/primitives/utils.ts +61 -0
- package/dist/generated/components/ui/accordion.tsx +127 -0
- package/dist/generated/components/ui/alert-dialog.tsx +167 -0
- package/dist/generated/components/ui/aspect-ratio.tsx +5 -0
- package/dist/generated/components/ui/avatar.tsx +44 -0
- package/dist/generated/components/ui/badge.tsx +51 -0
- package/dist/generated/components/ui/button.tsx +88 -0
- package/dist/generated/components/ui/card.tsx +67 -0
- package/dist/generated/components/ui/checkbox.tsx +34 -0
- package/dist/generated/components/ui/collapsible.tsx +9 -0
- package/dist/generated/components/ui/context-menu.tsx +244 -0
- package/dist/generated/components/ui/dialog.tsx +150 -0
- package/dist/generated/components/ui/dropdown-menu.tsx +244 -0
- package/dist/generated/components/ui/hover-card.tsx +45 -0
- package/dist/generated/components/ui/input.tsx +26 -0
- package/dist/generated/components/ui/label.tsx +28 -0
- package/dist/generated/components/ui/menubar.tsx +260 -0
- package/dist/generated/components/ui/navigation-menu.tsx +177 -0
- package/dist/generated/components/ui/popover.tsx +39 -0
- package/dist/generated/components/ui/radio-group.tsx +38 -0
- package/dist/generated/components/ui/select.tsx +181 -0
- package/dist/generated/components/ui/separator.tsx +23 -0
- package/dist/generated/components/ui/skeleton.tsx +39 -0
- package/dist/generated/components/ui/switch.tsx +97 -0
- package/dist/generated/components/ui/table.tsx +99 -0
- package/dist/generated/components/ui/tabs.tsx +65 -0
- package/dist/generated/components/ui/text.tsx +24 -0
- package/dist/generated/components/ui/textarea.tsx +28 -0
- package/dist/generated/components/ui/toggle-group.tsx +86 -0
- package/dist/generated/components/ui/toggle.tsx +85 -0
- package/dist/generated/components/ui/tooltip.tsx +36 -0
- package/dist/generated/components/ui/typography.tsx +204 -0
- package/package.json +8 -8
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { Pressable, Text, View, type GestureResponderEvent } from 'react-native';
|
|
3
|
+
import * as Slot from '@rnr/slot';
|
|
4
|
+
import type {
|
|
5
|
+
PressableRef,
|
|
6
|
+
SlottablePressableProps,
|
|
7
|
+
SlottableTextProps,
|
|
8
|
+
SlottableViewProps,
|
|
9
|
+
TextRef,
|
|
10
|
+
ViewRef,
|
|
11
|
+
} from '@rnr/types';
|
|
12
|
+
import type { ToastRootProps } from './types';
|
|
13
|
+
|
|
14
|
+
interface RootContext extends ToastRootProps {
|
|
15
|
+
nativeID: string;
|
|
16
|
+
}
|
|
17
|
+
const ToastContext = React.createContext<RootContext | null>(null);
|
|
18
|
+
|
|
19
|
+
const Root = React.forwardRef<ViewRef, SlottableViewProps & ToastRootProps>(
|
|
20
|
+
({ asChild, type = 'foreground', open, onOpenChange, ...viewProps }, ref) => {
|
|
21
|
+
const nativeID = React.useId();
|
|
22
|
+
|
|
23
|
+
if (!open) {
|
|
24
|
+
return null;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const Component = asChild ? Slot.View : View;
|
|
28
|
+
return (
|
|
29
|
+
<ToastContext.Provider
|
|
30
|
+
value={{
|
|
31
|
+
open,
|
|
32
|
+
onOpenChange,
|
|
33
|
+
type,
|
|
34
|
+
nativeID,
|
|
35
|
+
}}
|
|
36
|
+
>
|
|
37
|
+
<Component
|
|
38
|
+
ref={ref}
|
|
39
|
+
role='status'
|
|
40
|
+
aria-live={type === 'foreground' ? 'assertive' : 'polite'}
|
|
41
|
+
{...viewProps}
|
|
42
|
+
/>
|
|
43
|
+
</ToastContext.Provider>
|
|
44
|
+
);
|
|
45
|
+
}
|
|
46
|
+
);
|
|
47
|
+
|
|
48
|
+
Root.displayName = 'RootToast';
|
|
49
|
+
|
|
50
|
+
function useToastContext() {
|
|
51
|
+
const context = React.useContext(ToastContext);
|
|
52
|
+
if (!context) {
|
|
53
|
+
throw new Error('Toast compound components cannot be rendered outside the Toast component');
|
|
54
|
+
}
|
|
55
|
+
return context;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
const Close = React.forwardRef<PressableRef, SlottablePressableProps>(
|
|
59
|
+
({ asChild, onPress: onPressProp, disabled = false, ...props }, ref) => {
|
|
60
|
+
const { onOpenChange } = useToastContext();
|
|
61
|
+
|
|
62
|
+
function onPress(ev: GestureResponderEvent) {
|
|
63
|
+
if (disabled) return;
|
|
64
|
+
onOpenChange(false);
|
|
65
|
+
onPressProp?.(ev);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
const Component = asChild ? Slot.Pressable : Pressable;
|
|
69
|
+
return (
|
|
70
|
+
<Component
|
|
71
|
+
ref={ref}
|
|
72
|
+
aria-disabled={disabled ?? undefined}
|
|
73
|
+
role='button'
|
|
74
|
+
onPress={onPress}
|
|
75
|
+
disabled={disabled ?? undefined}
|
|
76
|
+
{...props}
|
|
77
|
+
/>
|
|
78
|
+
);
|
|
79
|
+
}
|
|
80
|
+
);
|
|
81
|
+
|
|
82
|
+
Close.displayName = 'CloseToast';
|
|
83
|
+
|
|
84
|
+
const Action = React.forwardRef<PressableRef, SlottablePressableProps>(
|
|
85
|
+
({ asChild, onPress: onPressProp, disabled = false, ...props }, ref) => {
|
|
86
|
+
const { onOpenChange } = useToastContext();
|
|
87
|
+
|
|
88
|
+
function onPress(ev: GestureResponderEvent) {
|
|
89
|
+
if (disabled) return;
|
|
90
|
+
onOpenChange(false);
|
|
91
|
+
onPressProp?.(ev);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
const Component = asChild ? Slot.Pressable : Pressable;
|
|
95
|
+
return (
|
|
96
|
+
<Component
|
|
97
|
+
ref={ref}
|
|
98
|
+
aria-disabled={disabled ?? undefined}
|
|
99
|
+
role='button'
|
|
100
|
+
onPress={onPress}
|
|
101
|
+
disabled={disabled ?? undefined}
|
|
102
|
+
{...props}
|
|
103
|
+
/>
|
|
104
|
+
);
|
|
105
|
+
}
|
|
106
|
+
);
|
|
107
|
+
|
|
108
|
+
Action.displayName = 'ActionToast';
|
|
109
|
+
|
|
110
|
+
const Title = React.forwardRef<TextRef, SlottableTextProps>(({ asChild, ...props }, ref) => {
|
|
111
|
+
const { nativeID } = useToastContext();
|
|
112
|
+
|
|
113
|
+
const Component = asChild ? Slot.Text : Text;
|
|
114
|
+
return <Component ref={ref} role='heading' nativeID={`${nativeID}_label`} {...props} />;
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
Title.displayName = 'TitleToast';
|
|
118
|
+
|
|
119
|
+
const Description = React.forwardRef<TextRef, SlottableTextProps>(({ asChild, ...props }, ref) => {
|
|
120
|
+
const { nativeID } = useToastContext();
|
|
121
|
+
|
|
122
|
+
const Component = asChild ? Slot.Text : Text;
|
|
123
|
+
return <Component ref={ref} nativeID={`${nativeID}_desc`} {...props} />;
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
Description.displayName = 'DescriptionToast';
|
|
127
|
+
|
|
128
|
+
export { Action, Close, Description, Root, Title };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './toggle';
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { Pressable, type GestureResponderEvent } from 'react-native';
|
|
3
|
+
import * as Slot from '@rnr/slot';
|
|
4
|
+
import type { PressableRef, SlottablePressableProps } from '@rnr/types';
|
|
5
|
+
import type { ToggleRootProps } from './types';
|
|
6
|
+
|
|
7
|
+
const Root = React.forwardRef<PressableRef, SlottablePressableProps & ToggleRootProps>(
|
|
8
|
+
({ asChild, 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
|
+
const Component = asChild ? Slot.Pressable : Pressable;
|
|
17
|
+
return (
|
|
18
|
+
<Component
|
|
19
|
+
ref={ref}
|
|
20
|
+
aria-disabled={disabled}
|
|
21
|
+
role='switch'
|
|
22
|
+
aria-selected={pressed}
|
|
23
|
+
onPress={onPress}
|
|
24
|
+
accessibilityState={{
|
|
25
|
+
selected: pressed,
|
|
26
|
+
disabled,
|
|
27
|
+
}}
|
|
28
|
+
disabled={disabled}
|
|
29
|
+
{...props}
|
|
30
|
+
/>
|
|
31
|
+
);
|
|
32
|
+
}
|
|
33
|
+
);
|
|
34
|
+
|
|
35
|
+
Root.displayName = 'RootNativeToggle';
|
|
36
|
+
|
|
37
|
+
export { Root };
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import * as Toggle from '@radix-ui/react-toggle';
|
|
2
|
+
import * as React from 'react';
|
|
3
|
+
import { Pressable, type GestureResponderEvent } from 'react-native';
|
|
4
|
+
import * as Slot from '@rnr/slot';
|
|
5
|
+
import type { PressableRef, SlottablePressableProps } from '@rnr/types';
|
|
6
|
+
import type { ToggleRootProps } from './types';
|
|
7
|
+
|
|
8
|
+
const Root = React.forwardRef<PressableRef, SlottablePressableProps & ToggleRootProps>(
|
|
9
|
+
({ asChild, pressed, onPressedChange, disabled, onPress: onPressProp, ...props }, ref) => {
|
|
10
|
+
function onPress(ev: GestureResponderEvent) {
|
|
11
|
+
onPressProp?.(ev);
|
|
12
|
+
onPressedChange(!pressed);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
const Component = asChild ? Slot.Pressable : Pressable;
|
|
16
|
+
return (
|
|
17
|
+
<Toggle.Root pressed={pressed} onPressedChange={onPressedChange} disabled={disabled} asChild>
|
|
18
|
+
<Component ref={ref} onPress={onPress} disabled={disabled} role='button' {...props} />
|
|
19
|
+
</Toggle.Root>
|
|
20
|
+
);
|
|
21
|
+
}
|
|
22
|
+
);
|
|
23
|
+
|
|
24
|
+
Root.displayName = 'RootWebToggle';
|
|
25
|
+
|
|
26
|
+
export { Root };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './toggle-group';
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { Pressable, View, type GestureResponderEvent } from 'react-native';
|
|
3
|
+
import * as Slot from '@rnr/slot';
|
|
4
|
+
import type {
|
|
5
|
+
PressableRef,
|
|
6
|
+
SlottablePressableProps,
|
|
7
|
+
SlottableViewProps,
|
|
8
|
+
ViewRef,
|
|
9
|
+
} from '@rnr/types';
|
|
10
|
+
import { ToggleGroupUtils } from '@rnr/utils';
|
|
11
|
+
import type { ToggleGroupItemProps, ToggleGroupRootProps } from './types';
|
|
12
|
+
|
|
13
|
+
const ToggleGroupContext = React.createContext<ToggleGroupRootProps | null>(null);
|
|
14
|
+
|
|
15
|
+
const Root = React.forwardRef<ViewRef, SlottableViewProps & ToggleGroupRootProps>(
|
|
16
|
+
(
|
|
17
|
+
{
|
|
18
|
+
asChild,
|
|
19
|
+
type,
|
|
20
|
+
value,
|
|
21
|
+
onValueChange,
|
|
22
|
+
disabled = false,
|
|
23
|
+
rovingFocus: _rovingFocus,
|
|
24
|
+
orientation: _orientation,
|
|
25
|
+
dir: _dir,
|
|
26
|
+
loop: _loop,
|
|
27
|
+
...viewProps
|
|
28
|
+
},
|
|
29
|
+
ref
|
|
30
|
+
) => {
|
|
31
|
+
const Component = asChild ? Slot.View : View;
|
|
32
|
+
return (
|
|
33
|
+
<ToggleGroupContext.Provider
|
|
34
|
+
value={
|
|
35
|
+
{
|
|
36
|
+
type,
|
|
37
|
+
value,
|
|
38
|
+
disabled,
|
|
39
|
+
onValueChange,
|
|
40
|
+
} as ToggleGroupRootProps
|
|
41
|
+
}
|
|
42
|
+
>
|
|
43
|
+
<Component ref={ref} role='group' {...viewProps} />
|
|
44
|
+
</ToggleGroupContext.Provider>
|
|
45
|
+
);
|
|
46
|
+
}
|
|
47
|
+
);
|
|
48
|
+
|
|
49
|
+
Root.displayName = 'RootToggleGroup';
|
|
50
|
+
|
|
51
|
+
function useRootContext() {
|
|
52
|
+
const context = React.useContext(ToggleGroupContext);
|
|
53
|
+
if (!context) {
|
|
54
|
+
throw new Error(
|
|
55
|
+
'ToggleGroup compound components cannot be rendered outside the ToggleGroup component'
|
|
56
|
+
);
|
|
57
|
+
}
|
|
58
|
+
return context;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
const ItemContext = React.createContext<ToggleGroupItemProps | null>(null);
|
|
62
|
+
|
|
63
|
+
const Item = React.forwardRef<PressableRef, SlottablePressableProps & ToggleGroupItemProps>(
|
|
64
|
+
(
|
|
65
|
+
{ asChild, value: itemValue, disabled: disabledProp = false, onPress: onPressProp, ...props },
|
|
66
|
+
ref
|
|
67
|
+
) => {
|
|
68
|
+
const id = React.useId();
|
|
69
|
+
const { type, disabled, value, onValueChange } = useRootContext();
|
|
70
|
+
|
|
71
|
+
function onPress(ev: GestureResponderEvent) {
|
|
72
|
+
if (disabled || disabledProp) return;
|
|
73
|
+
if (type === 'single') {
|
|
74
|
+
onValueChange(ToggleGroupUtils.getNewSingleValue(value, itemValue));
|
|
75
|
+
}
|
|
76
|
+
if (type === 'multiple') {
|
|
77
|
+
onValueChange(ToggleGroupUtils.getNewMultipleValue(value, itemValue));
|
|
78
|
+
}
|
|
79
|
+
onPressProp?.(ev);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
const isChecked =
|
|
83
|
+
type === 'single' ? ToggleGroupUtils.getIsSelected(value, itemValue) : undefined;
|
|
84
|
+
const isSelected =
|
|
85
|
+
type === 'multiple' ? ToggleGroupUtils.getIsSelected(value, itemValue) : undefined;
|
|
86
|
+
|
|
87
|
+
const Component = asChild ? Slot.Pressable : Pressable;
|
|
88
|
+
return (
|
|
89
|
+
<ItemContext.Provider value={{ value: itemValue }}>
|
|
90
|
+
<Component
|
|
91
|
+
ref={ref}
|
|
92
|
+
key={`${id}-item-${value}`}
|
|
93
|
+
aria-disabled={disabled}
|
|
94
|
+
role={type === 'single' ? 'radio' : 'checkbox'}
|
|
95
|
+
onPress={onPress}
|
|
96
|
+
aria-checked={isChecked}
|
|
97
|
+
aria-selected={isSelected}
|
|
98
|
+
disabled={(disabled || disabledProp) ?? false}
|
|
99
|
+
accessibilityState={{
|
|
100
|
+
disabled: (disabled || disabledProp) ?? false,
|
|
101
|
+
checked: isChecked,
|
|
102
|
+
selected: isSelected,
|
|
103
|
+
}}
|
|
104
|
+
{...props}
|
|
105
|
+
/>
|
|
106
|
+
</ItemContext.Provider>
|
|
107
|
+
);
|
|
108
|
+
}
|
|
109
|
+
);
|
|
110
|
+
|
|
111
|
+
Item.displayName = 'ItemToggleGroup';
|
|
112
|
+
|
|
113
|
+
function useItemContext() {
|
|
114
|
+
const context = React.useContext(ItemContext);
|
|
115
|
+
if (!context) {
|
|
116
|
+
throw new Error(
|
|
117
|
+
'ToggleGroupItem compound components cannot be rendered outside the ToggleGroupItem component'
|
|
118
|
+
);
|
|
119
|
+
}
|
|
120
|
+
return context;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
const utils = ToggleGroupUtils;
|
|
124
|
+
|
|
125
|
+
export { Item, Root, useItemContext, useRootContext, utils };
|
|
@@ -0,0 +1,124 @@
|
|
|
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
|
+
import * as Slot from '@rnr/slot';
|
|
5
|
+
import type {
|
|
6
|
+
PressableRef,
|
|
7
|
+
SlottablePressableProps,
|
|
8
|
+
SlottableViewProps,
|
|
9
|
+
ViewRef,
|
|
10
|
+
} from '@rnr/types';
|
|
11
|
+
import { ToggleGroupUtils } from '@rnr/utils';
|
|
12
|
+
import type { ToggleGroupItemProps, ToggleGroupRootProps } from './types';
|
|
13
|
+
|
|
14
|
+
const ToggleGroupContext = React.createContext<ToggleGroupRootProps | null>(null);
|
|
15
|
+
|
|
16
|
+
const Root = React.forwardRef<ViewRef, SlottableViewProps & ToggleGroupRootProps>(
|
|
17
|
+
(
|
|
18
|
+
{
|
|
19
|
+
asChild,
|
|
20
|
+
type,
|
|
21
|
+
value,
|
|
22
|
+
onValueChange,
|
|
23
|
+
disabled = false,
|
|
24
|
+
rovingFocus,
|
|
25
|
+
orientation,
|
|
26
|
+
dir,
|
|
27
|
+
loop,
|
|
28
|
+
...viewProps
|
|
29
|
+
},
|
|
30
|
+
ref
|
|
31
|
+
) => {
|
|
32
|
+
const Component = asChild ? Slot.View : View;
|
|
33
|
+
return (
|
|
34
|
+
<ToggleGroupContext.Provider
|
|
35
|
+
value={
|
|
36
|
+
{
|
|
37
|
+
type,
|
|
38
|
+
value,
|
|
39
|
+
disabled,
|
|
40
|
+
onValueChange,
|
|
41
|
+
} as ToggleGroupRootProps
|
|
42
|
+
}
|
|
43
|
+
>
|
|
44
|
+
<ToggleGroup.Root
|
|
45
|
+
type={type as any}
|
|
46
|
+
value={value as any}
|
|
47
|
+
onValueChange={onValueChange as any}
|
|
48
|
+
disabled={disabled}
|
|
49
|
+
rovingFocus={rovingFocus}
|
|
50
|
+
orientation={orientation}
|
|
51
|
+
dir={dir}
|
|
52
|
+
loop={loop}
|
|
53
|
+
asChild
|
|
54
|
+
>
|
|
55
|
+
<Component ref={ref} {...viewProps} />
|
|
56
|
+
</ToggleGroup.Root>
|
|
57
|
+
</ToggleGroupContext.Provider>
|
|
58
|
+
);
|
|
59
|
+
}
|
|
60
|
+
);
|
|
61
|
+
|
|
62
|
+
Root.displayName = 'RootToggleGroup';
|
|
63
|
+
|
|
64
|
+
function useRootContext() {
|
|
65
|
+
const context = React.useContext(ToggleGroupContext);
|
|
66
|
+
if (!context) {
|
|
67
|
+
throw new Error(
|
|
68
|
+
'ToggleGroup compound components cannot be rendered outside the ToggleGroup component'
|
|
69
|
+
);
|
|
70
|
+
}
|
|
71
|
+
return context;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
const ItemContext = React.createContext<ToggleGroupItemProps | null>(null);
|
|
75
|
+
|
|
76
|
+
const Item = React.forwardRef<PressableRef, SlottablePressableProps & ToggleGroupItemProps>(
|
|
77
|
+
(
|
|
78
|
+
{ asChild, value: itemValue, disabled: disabledProp = false, onPress: onPressProp, ...props },
|
|
79
|
+
ref
|
|
80
|
+
) => {
|
|
81
|
+
const { type, disabled, value, onValueChange } = useRootContext();
|
|
82
|
+
|
|
83
|
+
function onPress(ev: GestureResponderEvent) {
|
|
84
|
+
onPressProp?.(ev);
|
|
85
|
+
if (type === 'single') {
|
|
86
|
+
onValueChange(ToggleGroupUtils.getNewSingleValue(value, itemValue));
|
|
87
|
+
}
|
|
88
|
+
if (type === 'multiple') {
|
|
89
|
+
onValueChange(ToggleGroupUtils.getNewMultipleValue(value, itemValue));
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
const Component = asChild ? Slot.Pressable : Pressable;
|
|
94
|
+
return (
|
|
95
|
+
<ItemContext.Provider value={{ value: itemValue }}>
|
|
96
|
+
<ToggleGroup.Item value={itemValue} asChild>
|
|
97
|
+
<Component
|
|
98
|
+
ref={ref}
|
|
99
|
+
onPress={onPress}
|
|
100
|
+
disabled={disabled || disabledProp}
|
|
101
|
+
role='button'
|
|
102
|
+
{...props}
|
|
103
|
+
/>
|
|
104
|
+
</ToggleGroup.Item>
|
|
105
|
+
</ItemContext.Provider>
|
|
106
|
+
);
|
|
107
|
+
}
|
|
108
|
+
);
|
|
109
|
+
|
|
110
|
+
Item.displayName = 'ItemToggleGroup';
|
|
111
|
+
|
|
112
|
+
function useItemContext() {
|
|
113
|
+
const context = React.useContext(ItemContext);
|
|
114
|
+
if (!context) {
|
|
115
|
+
throw new Error(
|
|
116
|
+
'ToggleGroupItem compound components cannot be rendered outside the ToggleGroupItem component'
|
|
117
|
+
);
|
|
118
|
+
}
|
|
119
|
+
return context;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
const utils = ToggleGroupUtils;
|
|
123
|
+
|
|
124
|
+
export { Item, Root, useItemContext, useRootContext, utils };
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
type SingleRootProps = {
|
|
2
|
+
type: 'single';
|
|
3
|
+
value: string | undefined;
|
|
4
|
+
onValueChange: (val: string | undefined) => void;
|
|
5
|
+
};
|
|
6
|
+
|
|
7
|
+
type MultipleRootProps = {
|
|
8
|
+
type: 'multiple';
|
|
9
|
+
value: string[];
|
|
10
|
+
onValueChange: (val: string[]) => void;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
type ToggleGroupRootProps = (SingleRootProps | MultipleRootProps) & {
|
|
14
|
+
disabled?: boolean;
|
|
15
|
+
/**
|
|
16
|
+
* Platform: WEB ONLY
|
|
17
|
+
*/
|
|
18
|
+
rovingFocus?: boolean;
|
|
19
|
+
/**
|
|
20
|
+
* Platform: WEB ONLY
|
|
21
|
+
*/
|
|
22
|
+
orientation?: 'horizontal' | 'vertical';
|
|
23
|
+
/**
|
|
24
|
+
* Platform: WEB ONLY
|
|
25
|
+
*/
|
|
26
|
+
dir?: 'ltr' | 'rtl';
|
|
27
|
+
/**
|
|
28
|
+
* Platform: WEB ONLY
|
|
29
|
+
*/
|
|
30
|
+
loop?: boolean;
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
interface ToggleGroupItemProps {
|
|
34
|
+
value: string;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export type { ToggleGroupRootProps, ToggleGroupItemProps };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './toolbar';
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { Pressable, View, type GestureResponderEvent } from 'react-native';
|
|
3
|
+
import * as Slot from '@rnr/slot';
|
|
4
|
+
import type {
|
|
5
|
+
PressableRef,
|
|
6
|
+
SlottablePressableProps,
|
|
7
|
+
SlottableViewProps,
|
|
8
|
+
ViewRef,
|
|
9
|
+
} from '@rnr/types';
|
|
10
|
+
import { ToggleGroupUtils } from '@rnr/utils';
|
|
11
|
+
import type { ToolbarRootProps, ToolbarToggleGroupProps, ToolbarToggleItem } from './types';
|
|
12
|
+
|
|
13
|
+
const Root = React.forwardRef<ViewRef, SlottableViewProps & ToolbarRootProps>(
|
|
14
|
+
({ asChild, orientation: _orientation, dir: _dir, loop: _loop, ...props }, ref) => {
|
|
15
|
+
const Component = asChild ? Slot.View : View;
|
|
16
|
+
return <Component ref={ref} role='toolbar' {...props} />;
|
|
17
|
+
}
|
|
18
|
+
);
|
|
19
|
+
|
|
20
|
+
Root.displayName = 'RootNativeToolbar';
|
|
21
|
+
|
|
22
|
+
const ToggleGroupContext = React.createContext<ToolbarToggleGroupProps | null>(null);
|
|
23
|
+
|
|
24
|
+
const ToggleGroup = React.forwardRef<ViewRef, SlottableViewProps & ToolbarToggleGroupProps>(
|
|
25
|
+
({ asChild, type, value, onValueChange, disabled = false, ...viewProps }, ref) => {
|
|
26
|
+
const Component = asChild ? Slot.View : View;
|
|
27
|
+
return (
|
|
28
|
+
<ToggleGroupContext.Provider
|
|
29
|
+
value={
|
|
30
|
+
{
|
|
31
|
+
type,
|
|
32
|
+
value,
|
|
33
|
+
disabled,
|
|
34
|
+
onValueChange,
|
|
35
|
+
} as ToolbarToggleGroupProps
|
|
36
|
+
}
|
|
37
|
+
>
|
|
38
|
+
<Component ref={ref} role='group' {...viewProps} />
|
|
39
|
+
</ToggleGroupContext.Provider>
|
|
40
|
+
);
|
|
41
|
+
}
|
|
42
|
+
);
|
|
43
|
+
|
|
44
|
+
ToggleGroup.displayName = 'ToggleGroupNativeToolbar';
|
|
45
|
+
|
|
46
|
+
function useToggleGroupContext() {
|
|
47
|
+
const context = React.useContext(ToggleGroupContext);
|
|
48
|
+
if (!context) {
|
|
49
|
+
throw new Error(
|
|
50
|
+
'ToggleGroup compound components cannot be rendered outside the ToggleGroup component'
|
|
51
|
+
);
|
|
52
|
+
}
|
|
53
|
+
return context;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const ToggleItem = React.forwardRef<PressableRef, SlottablePressableProps & ToolbarToggleItem>(
|
|
57
|
+
(
|
|
58
|
+
{ asChild, value: itemValue, disabled: disabledProp = false, onPress: onPressProp, ...props },
|
|
59
|
+
ref
|
|
60
|
+
) => {
|
|
61
|
+
const { type, disabled, value, onValueChange } = useToggleGroupContext();
|
|
62
|
+
|
|
63
|
+
function onPress(ev: GestureResponderEvent) {
|
|
64
|
+
if (disabled || disabledProp) return;
|
|
65
|
+
if (type === 'single') {
|
|
66
|
+
onValueChange(ToggleGroupUtils.getNewSingleValue(value, itemValue));
|
|
67
|
+
}
|
|
68
|
+
if (type === 'multiple') {
|
|
69
|
+
onValueChange(ToggleGroupUtils.getNewMultipleValue(value, itemValue));
|
|
70
|
+
}
|
|
71
|
+
onPressProp?.(ev);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
const isChecked =
|
|
75
|
+
type === 'single' ? ToggleGroupUtils.getIsSelected(value, itemValue) : undefined;
|
|
76
|
+
const isSelected =
|
|
77
|
+
type === 'multiple' ? ToggleGroupUtils.getIsSelected(value, itemValue) : undefined;
|
|
78
|
+
|
|
79
|
+
const Component = asChild ? Slot.Pressable : Pressable;
|
|
80
|
+
return (
|
|
81
|
+
<Component
|
|
82
|
+
ref={ref}
|
|
83
|
+
aria-disabled={disabled}
|
|
84
|
+
role={type === 'single' ? 'radio' : 'checkbox'}
|
|
85
|
+
onPress={onPress}
|
|
86
|
+
aria-checked={isChecked}
|
|
87
|
+
aria-selected={isSelected}
|
|
88
|
+
disabled={(disabled || disabledProp) ?? false}
|
|
89
|
+
accessibilityState={{
|
|
90
|
+
disabled: (disabled || disabledProp) ?? false,
|
|
91
|
+
checked: isChecked,
|
|
92
|
+
selected: isSelected,
|
|
93
|
+
}}
|
|
94
|
+
{...props}
|
|
95
|
+
/>
|
|
96
|
+
);
|
|
97
|
+
}
|
|
98
|
+
);
|
|
99
|
+
|
|
100
|
+
ToggleItem.displayName = 'ToggleItemNativeToolbar';
|
|
101
|
+
|
|
102
|
+
const Separator = React.forwardRef<ViewRef, SlottableViewProps>(({ asChild, ...props }, ref) => {
|
|
103
|
+
const Component = asChild ? Slot.View : View;
|
|
104
|
+
return <Component role={'separator'} ref={ref} {...props} />;
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
Separator.displayName = 'SeparatorNativeToolbar';
|
|
108
|
+
|
|
109
|
+
const Link = React.forwardRef<PressableRef, SlottablePressableProps>(
|
|
110
|
+
({ asChild, ...props }, ref) => {
|
|
111
|
+
const Component = asChild ? Slot.Pressable : Pressable;
|
|
112
|
+
return <Component ref={ref} role='link' {...props} />;
|
|
113
|
+
}
|
|
114
|
+
);
|
|
115
|
+
|
|
116
|
+
Link.displayName = 'LinkNativeToolbar';
|
|
117
|
+
|
|
118
|
+
const Button = React.forwardRef<PressableRef, SlottablePressableProps>(
|
|
119
|
+
({ asChild, ...props }, ref) => {
|
|
120
|
+
const Component = asChild ? Slot.Pressable : Pressable;
|
|
121
|
+
return <Component ref={ref} role='button' {...props} />;
|
|
122
|
+
}
|
|
123
|
+
);
|
|
124
|
+
|
|
125
|
+
export { Button, Link, Root, Separator, ToggleGroup, ToggleItem };
|