@react-native-reusables/cli 0.0.18 → 0.1.1
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/README.md +2 -37
- package/__generated/components/ui/accordion.tsx +30 -32
- package/__generated/components/ui/alert-dialog.tsx +19 -26
- package/__generated/components/ui/aspect-ratio.tsx +1 -1
- package/__generated/components/ui/avatar.tsx +31 -34
- package/__generated/components/ui/badge.tsx +2 -2
- package/__generated/components/ui/button.tsx +2 -5
- package/__generated/components/ui/card.tsx +39 -51
- package/__generated/components/ui/checkbox.tsx +25 -27
- package/__generated/components/ui/collapsible.tsx +1 -1
- package/__generated/components/ui/context-menu.tsx +28 -31
- package/__generated/components/ui/dialog.tsx +40 -43
- package/__generated/components/ui/dropdown-menu.tsx +27 -22
- package/__generated/components/ui/hover-card.tsx +3 -3
- package/__generated/components/ui/input.tsx +17 -18
- package/__generated/components/ui/label.tsx +21 -22
- package/__generated/components/ui/menubar.tsx +45 -47
- package/__generated/components/ui/navigation-menu.tsx +19 -17
- package/__generated/components/ui/popover.tsx +4 -4
- package/__generated/components/ui/progress.tsx +15 -11
- package/__generated/components/ui/radio-group.tsx +27 -29
- package/__generated/components/ui/select.tsx +55 -65
- package/__generated/components/ui/separator.tsx +16 -17
- package/__generated/components/ui/switch.tsx +59 -61
- package/__generated/components/ui/table.tsx +69 -76
- package/__generated/components/ui/tabs.tsx +49 -52
- package/__generated/components/ui/text.tsx +2 -2
- package/__generated/components/ui/textarea.tsx +20 -21
- package/__generated/components/ui/toggle-group.tsx +5 -7
- package/__generated/components/ui/toggle.tsx +4 -4
- package/__generated/components/ui/tooltip.tsx +4 -5
- package/__generated/components/ui/typography.tsx +2 -2
- package/dist/index.js +3 -3
- package/dist/index.js.map +1 -1
- package/package.json +2 -34
- package/__generated/components/primitives/accordion/accordion.tsx +0 -216
- package/__generated/components/primitives/accordion/accordion.web.tsx +0 -295
- package/__generated/components/primitives/accordion/index.ts +0 -1
- package/__generated/components/primitives/accordion/types.ts +0 -45
- package/__generated/components/primitives/alert-dialog/alert-dialog.tsx +0 -237
- package/__generated/components/primitives/alert-dialog/alert-dialog.web.tsx +0 -256
- package/__generated/components/primitives/alert-dialog/index.ts +0 -1
- package/__generated/components/primitives/alert-dialog/types.ts +0 -48
- package/__generated/components/primitives/aspect-ratio.tsx +0 -23
- package/__generated/components/primitives/avatar/index.tsx +0 -95
- package/__generated/components/primitives/avatar/types.ts +0 -10
- package/__generated/components/primitives/checkbox/checkbox.tsx +0 -101
- package/__generated/components/primitives/checkbox/checkbox.web.tsx +0 -114
- package/__generated/components/primitives/checkbox/index.ts +0 -1
- package/__generated/components/primitives/checkbox/types.ts +0 -11
- package/__generated/components/primitives/collapsible/collapsible.tsx +0 -119
- package/__generated/components/primitives/collapsible/collapsible.web.tsx +0 -157
- package/__generated/components/primitives/collapsible/index.ts +0 -1
- package/__generated/components/primitives/collapsible/types.ts +0 -18
- package/__generated/components/primitives/context-menu/context-menu.tsx +0 -648
- package/__generated/components/primitives/context-menu/context-menu.web.tsx +0 -533
- package/__generated/components/primitives/context-menu/index.ts +0 -1
- package/__generated/components/primitives/context-menu/types.ts +0 -90
- package/__generated/components/primitives/dialog/dialog.tsx +0 -211
- package/__generated/components/primitives/dialog/dialog.web.tsx +0 -197
- package/__generated/components/primitives/dialog/index.ts +0 -1
- package/__generated/components/primitives/dialog/types.ts +0 -60
- package/__generated/components/primitives/dropdown-menu/dropdown-menu.tsx +0 -608
- package/__generated/components/primitives/dropdown-menu/dropdown-menu.web.tsx +0 -550
- package/__generated/components/primitives/dropdown-menu/index.ts +0 -1
- package/__generated/components/primitives/dropdown-menu/types.ts +0 -72
- package/__generated/components/primitives/hooks/index.ts +0 -3
- package/__generated/components/primitives/hooks/useAugmentedRef.tsx +0 -29
- package/__generated/components/primitives/hooks/useControllableState.tsx +0 -75
- package/__generated/components/primitives/hooks/useRelativePosition.tsx +0 -227
- package/__generated/components/primitives/hover-card/hover-card.tsx +0 -279
- package/__generated/components/primitives/hover-card/hover-card.web.tsx +0 -150
- package/__generated/components/primitives/hover-card/index.ts +0 -1
- package/__generated/components/primitives/hover-card/types.ts +0 -51
- package/__generated/components/primitives/label/index.ts +0 -1
- package/__generated/components/primitives/label/label.tsx +0 -31
- package/__generated/components/primitives/label/label.web.tsx +0 -36
- package/__generated/components/primitives/label/types.ts +0 -15
- package/__generated/components/primitives/menubar/index.ts +0 -1
- package/__generated/components/primitives/menubar/menubar.tsx +0 -622
- package/__generated/components/primitives/menubar/menubar.web.tsx +0 -548
- package/__generated/components/primitives/menubar/types.ts +0 -77
- package/__generated/components/primitives/navigation-menu/index.ts +0 -1
- package/__generated/components/primitives/navigation-menu/navigation-menu.tsx +0 -315
- package/__generated/components/primitives/navigation-menu/navigation-menu.web.tsx +0 -264
- package/__generated/components/primitives/navigation-menu/types.ts +0 -49
- package/__generated/components/primitives/popover/index.ts +0 -1
- package/__generated/components/primitives/popover/popover.tsx +0 -290
- package/__generated/components/primitives/popover/popover.web.tsx +0 -191
- package/__generated/components/primitives/popover/types.ts +0 -24
- package/__generated/components/primitives/portal.tsx +0 -82
- package/__generated/components/primitives/progress/index.ts +0 -1
- package/__generated/components/primitives/progress/progress.tsx +0 -59
- package/__generated/components/primitives/progress/progress.web.tsx +0 -36
- package/__generated/components/primitives/progress/types.ts +0 -7
- package/__generated/components/primitives/radio-group/index.ts +0 -1
- package/__generated/components/primitives/radio-group/radio-group.tsx +0 -116
- package/__generated/components/primitives/radio-group/radio-group.web.tsx +0 -78
- package/__generated/components/primitives/radio-group/types.ts +0 -15
- package/__generated/components/primitives/select/index.ts +0 -1
- package/__generated/components/primitives/select/select.tsx +0 -466
- package/__generated/components/primitives/select/select.web.tsx +0 -332
- package/__generated/components/primitives/select/types.ts +0 -89
- package/__generated/components/primitives/separator/index.tsx +0 -23
- package/__generated/components/primitives/separator/types.ts +0 -6
- package/__generated/components/primitives/slider/index.ts +0 -1
- package/__generated/components/primitives/slider/slider.tsx +0 -89
- package/__generated/components/primitives/slider/slider.web.tsx +0 -67
- package/__generated/components/primitives/slider/types.ts +0 -24
- package/__generated/components/primitives/slot.tsx +0 -187
- package/__generated/components/primitives/switch/index.ts +0 -1
- package/__generated/components/primitives/switch/switch.tsx +0 -65
- package/__generated/components/primitives/switch/switch.web.tsx +0 -67
- package/__generated/components/primitives/switch/types.ts +0 -11
- package/__generated/components/primitives/table.tsx +0 -55
- package/__generated/components/primitives/tabs/index.ts +0 -1
- package/__generated/components/primitives/tabs/tabs.tsx +0 -133
- package/__generated/components/primitives/tabs/tabs.web.tsx +0 -97
- package/__generated/components/primitives/tabs/types.ts +0 -24
- package/__generated/components/primitives/toast/index.tsx +0 -128
- package/__generated/components/primitives/toast/types.ts +0 -7
- package/__generated/components/primitives/toggle/index.ts +0 -1
- package/__generated/components/primitives/toggle/toggle.tsx +0 -37
- package/__generated/components/primitives/toggle/toggle.web.tsx +0 -26
- package/__generated/components/primitives/toggle/types.ts +0 -7
- package/__generated/components/primitives/toggle-group/index.ts +0 -1
- package/__generated/components/primitives/toggle-group/toggle-group.tsx +0 -125
- package/__generated/components/primitives/toggle-group/toggle-group.web.tsx +0 -124
- package/__generated/components/primitives/toggle-group/types.ts +0 -37
- package/__generated/components/primitives/toolbar/index.ts +0 -1
- package/__generated/components/primitives/toolbar/toolbar.tsx +0 -125
- package/__generated/components/primitives/toolbar/toolbar.web.tsx +0 -129
- package/__generated/components/primitives/toolbar/types.ts +0 -39
- package/__generated/components/primitives/tooltip/index.ts +0 -1
- package/__generated/components/primitives/tooltip/tooltip.tsx +0 -277
- package/__generated/components/primitives/tooltip/tooltip.web.tsx +0 -181
- package/__generated/components/primitives/tooltip/types.ts +0 -42
- package/__generated/components/primitives/types.ts +0 -105
- package/__generated/components/primitives/utils.ts +0 -61
|
@@ -1,128 +0,0 @@
|
|
|
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 };
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './toggle';
|
|
@@ -1,37 +0,0 @@
|
|
|
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 };
|
|
@@ -1,26 +0,0 @@
|
|
|
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 };
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './toggle-group';
|
|
@@ -1,125 +0,0 @@
|
|
|
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 };
|
|
@@ -1,124 +0,0 @@
|
|
|
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 };
|
|
@@ -1,37 +0,0 @@
|
|
|
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 };
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './toolbar';
|
|
@@ -1,125 +0,0 @@
|
|
|
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 };
|