@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,116 +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
|
-
ForceMountable,
|
|
6
|
-
PressableRef,
|
|
7
|
-
SlottablePressableProps,
|
|
8
|
-
SlottableViewProps,
|
|
9
|
-
ViewRef,
|
|
10
|
-
} from '@rnr/types';
|
|
11
|
-
import type { RadioGroupItemProps, RadioGroupRootProps } from './types';
|
|
12
|
-
|
|
13
|
-
const RadioGroupContext = React.createContext<RadioGroupRootProps | null>(null);
|
|
14
|
-
|
|
15
|
-
const Root = React.forwardRef<ViewRef, SlottableViewProps & RadioGroupRootProps>(
|
|
16
|
-
({ asChild, value, onValueChange, disabled = false, ...viewProps }, ref) => {
|
|
17
|
-
const Component = asChild ? Slot.View : View;
|
|
18
|
-
return (
|
|
19
|
-
<RadioGroupContext.Provider
|
|
20
|
-
value={{
|
|
21
|
-
value,
|
|
22
|
-
disabled,
|
|
23
|
-
onValueChange,
|
|
24
|
-
}}
|
|
25
|
-
>
|
|
26
|
-
<Component ref={ref} role='radiogroup' {...viewProps} />
|
|
27
|
-
</RadioGroupContext.Provider>
|
|
28
|
-
);
|
|
29
|
-
}
|
|
30
|
-
);
|
|
31
|
-
|
|
32
|
-
Root.displayName = 'RootRadioGroup';
|
|
33
|
-
|
|
34
|
-
function useRadioGroupContext() {
|
|
35
|
-
const context = React.useContext(RadioGroupContext);
|
|
36
|
-
if (!context) {
|
|
37
|
-
throw new Error(
|
|
38
|
-
'RadioGroup compound components cannot be rendered outside the RadioGroup component'
|
|
39
|
-
);
|
|
40
|
-
}
|
|
41
|
-
return context;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
interface RadioItemContext {
|
|
45
|
-
itemValue: string | undefined;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
const RadioItemContext = React.createContext<RadioItemContext | null>(null);
|
|
49
|
-
|
|
50
|
-
const Item = React.forwardRef<PressableRef, SlottablePressableProps & RadioGroupItemProps>(
|
|
51
|
-
(
|
|
52
|
-
{ asChild, value: itemValue, disabled: disabledProp = false, onPress: onPressProp, ...props },
|
|
53
|
-
ref
|
|
54
|
-
) => {
|
|
55
|
-
const { disabled, value, onValueChange } = useRadioGroupContext();
|
|
56
|
-
|
|
57
|
-
function onPress(ev: GestureResponderEvent) {
|
|
58
|
-
if (disabled || disabledProp) return;
|
|
59
|
-
onValueChange(itemValue);
|
|
60
|
-
onPressProp?.(ev);
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
const Component = asChild ? Slot.Pressable : Pressable;
|
|
64
|
-
return (
|
|
65
|
-
<RadioItemContext.Provider
|
|
66
|
-
value={{
|
|
67
|
-
itemValue: itemValue,
|
|
68
|
-
}}
|
|
69
|
-
>
|
|
70
|
-
<Component
|
|
71
|
-
ref={ref}
|
|
72
|
-
role='radio'
|
|
73
|
-
onPress={onPress}
|
|
74
|
-
aria-checked={value === itemValue}
|
|
75
|
-
disabled={(disabled || disabledProp) ?? false}
|
|
76
|
-
accessibilityState={{
|
|
77
|
-
disabled: (disabled || disabledProp) ?? false,
|
|
78
|
-
checked: value === itemValue,
|
|
79
|
-
}}
|
|
80
|
-
{...props}
|
|
81
|
-
/>
|
|
82
|
-
</RadioItemContext.Provider>
|
|
83
|
-
);
|
|
84
|
-
}
|
|
85
|
-
);
|
|
86
|
-
|
|
87
|
-
Item.displayName = 'ItemRadioGroup';
|
|
88
|
-
|
|
89
|
-
function useRadioItemContext() {
|
|
90
|
-
const context = React.useContext(RadioItemContext);
|
|
91
|
-
if (!context) {
|
|
92
|
-
throw new Error(
|
|
93
|
-
'RadioItem compound components cannot be rendered outside the RadioItem component'
|
|
94
|
-
);
|
|
95
|
-
}
|
|
96
|
-
return context;
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
const Indicator = React.forwardRef<ViewRef, SlottableViewProps & ForceMountable>(
|
|
100
|
-
({ asChild, forceMount, ...props }, ref) => {
|
|
101
|
-
const { value } = useRadioGroupContext();
|
|
102
|
-
const { itemValue } = useRadioItemContext();
|
|
103
|
-
|
|
104
|
-
if (!forceMount) {
|
|
105
|
-
if (value !== itemValue) {
|
|
106
|
-
return null;
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
const Component = asChild ? Slot.View : View;
|
|
110
|
-
return <Component ref={ref} role='presentation' {...props} />;
|
|
111
|
-
}
|
|
112
|
-
);
|
|
113
|
-
|
|
114
|
-
Indicator.displayName = 'IndicatorRadioGroup';
|
|
115
|
-
|
|
116
|
-
export { Indicator, Item, Root };
|
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
import * as RadioGroup from '@radix-ui/react-radio-group';
|
|
2
|
-
import * as React from 'react';
|
|
3
|
-
import { GestureResponderEvent, Pressable, View } from 'react-native';
|
|
4
|
-
import * as Slot from '@rnr/slot';
|
|
5
|
-
import type {
|
|
6
|
-
ForceMountable,
|
|
7
|
-
PressableRef,
|
|
8
|
-
SlottablePressableProps,
|
|
9
|
-
SlottableViewProps,
|
|
10
|
-
ViewRef,
|
|
11
|
-
} from '@rnr/types';
|
|
12
|
-
import type { RadioGroupItemProps, RadioGroupRootProps } from './types';
|
|
13
|
-
const RadioGroupContext = React.createContext<RadioGroupRootProps | null>(null);
|
|
14
|
-
const Root = React.forwardRef<ViewRef, SlottableViewProps & RadioGroupRootProps>(
|
|
15
|
-
({ asChild, value, onValueChange, disabled = false, ...viewProps }, ref) => {
|
|
16
|
-
const Component = asChild ? Slot.View : View;
|
|
17
|
-
return (
|
|
18
|
-
<RadioGroupContext.Provider
|
|
19
|
-
value={{
|
|
20
|
-
value,
|
|
21
|
-
disabled,
|
|
22
|
-
onValueChange,
|
|
23
|
-
}}
|
|
24
|
-
>
|
|
25
|
-
<RadioGroup.Root value={value} onValueChange={onValueChange} disabled={disabled} asChild>
|
|
26
|
-
<Component ref={ref} {...viewProps} />
|
|
27
|
-
</RadioGroup.Root>
|
|
28
|
-
</RadioGroupContext.Provider>
|
|
29
|
-
);
|
|
30
|
-
}
|
|
31
|
-
);
|
|
32
|
-
|
|
33
|
-
Root.displayName = 'RootRadioGroup';
|
|
34
|
-
function useRadioGroupContext() {
|
|
35
|
-
const context = React.useContext(RadioGroupContext);
|
|
36
|
-
if (!context) {
|
|
37
|
-
throw new Error(
|
|
38
|
-
'RadioGroup compound components cannot be rendered outside the RadioGroup component'
|
|
39
|
-
);
|
|
40
|
-
}
|
|
41
|
-
return context;
|
|
42
|
-
}
|
|
43
|
-
const Item = React.forwardRef<PressableRef, SlottablePressableProps & RadioGroupItemProps>(
|
|
44
|
-
({ asChild, value, onPress: onPressProps, ...props }, ref) => {
|
|
45
|
-
const { onValueChange } = useRadioGroupContext();
|
|
46
|
-
|
|
47
|
-
function onPress(ev: GestureResponderEvent) {
|
|
48
|
-
if (onPressProps) {
|
|
49
|
-
onPressProps(ev);
|
|
50
|
-
}
|
|
51
|
-
onValueChange(value);
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
const Component = asChild ? Slot.Pressable : Pressable;
|
|
55
|
-
return (
|
|
56
|
-
<RadioGroup.Item value={value} asChild>
|
|
57
|
-
<Component ref={ref} onPress={onPress} {...props} />
|
|
58
|
-
</RadioGroup.Item>
|
|
59
|
-
);
|
|
60
|
-
}
|
|
61
|
-
);
|
|
62
|
-
|
|
63
|
-
Item.displayName = 'ItemRadioGroup';
|
|
64
|
-
|
|
65
|
-
const Indicator = React.forwardRef<ViewRef, SlottableViewProps & ForceMountable>(
|
|
66
|
-
({ asChild, forceMount, ...props }, ref) => {
|
|
67
|
-
const Component = asChild ? Slot.View : View;
|
|
68
|
-
return (
|
|
69
|
-
<RadioGroup.Indicator asChild>
|
|
70
|
-
<Component ref={ref} {...props} />
|
|
71
|
-
</RadioGroup.Indicator>
|
|
72
|
-
);
|
|
73
|
-
}
|
|
74
|
-
);
|
|
75
|
-
|
|
76
|
-
Indicator.displayName = 'IndicatorRadioGroup';
|
|
77
|
-
|
|
78
|
-
export { Indicator, Item, Root };
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
interface RadioGroupRootProps {
|
|
2
|
-
value: string | undefined;
|
|
3
|
-
onValueChange: (val: string) => void;
|
|
4
|
-
disabled?: boolean;
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
interface RadioGroupItemProps {
|
|
8
|
-
value: string;
|
|
9
|
-
/**
|
|
10
|
-
* nativeID of the label element that describes this radio group item
|
|
11
|
-
*/
|
|
12
|
-
'aria-labelledby': string;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export type { RadioGroupRootProps, RadioGroupItemProps };
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './select';
|
|
@@ -1,466 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
useAugmentedRef,
|
|
3
|
-
useControllableState,
|
|
4
|
-
useRelativePosition,
|
|
5
|
-
type LayoutPosition,
|
|
6
|
-
} from '@rnr/hooks';
|
|
7
|
-
import { Portal as RNPPortal } from '@rnr/portal';
|
|
8
|
-
import * as Slot from '@rnr/slot';
|
|
9
|
-
import type {
|
|
10
|
-
ForceMountable,
|
|
11
|
-
PositionedContentProps,
|
|
12
|
-
PressableRef,
|
|
13
|
-
SlottablePressableProps,
|
|
14
|
-
SlottableTextProps,
|
|
15
|
-
SlottableViewProps,
|
|
16
|
-
TextRef,
|
|
17
|
-
ViewRef,
|
|
18
|
-
} from '@rnr/types';
|
|
19
|
-
import * as React from 'react';
|
|
20
|
-
import {
|
|
21
|
-
BackHandler,
|
|
22
|
-
Pressable,
|
|
23
|
-
Text,
|
|
24
|
-
View,
|
|
25
|
-
type GestureResponderEvent,
|
|
26
|
-
type LayoutChangeEvent,
|
|
27
|
-
type LayoutRectangle,
|
|
28
|
-
} from 'react-native';
|
|
29
|
-
import type {
|
|
30
|
-
RootContext,
|
|
31
|
-
SelectContentProps,
|
|
32
|
-
SelectItemProps,
|
|
33
|
-
SelectOverlayProps,
|
|
34
|
-
SelectPortalProps,
|
|
35
|
-
SelectRootProps,
|
|
36
|
-
SelectSeparatorProps,
|
|
37
|
-
SelectTriggerRef,
|
|
38
|
-
SelectValueProps,
|
|
39
|
-
} from './types';
|
|
40
|
-
|
|
41
|
-
interface IRootContext extends RootContext {
|
|
42
|
-
open: boolean;
|
|
43
|
-
onOpenChange: (open: boolean) => void;
|
|
44
|
-
triggerPosition: LayoutPosition | null;
|
|
45
|
-
setTriggerPosition: (triggerPosition: LayoutPosition | null) => void;
|
|
46
|
-
contentLayout: LayoutRectangle | null;
|
|
47
|
-
setContentLayout: (contentLayout: LayoutRectangle | null) => void;
|
|
48
|
-
nativeID: string;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
const RootContext = React.createContext<IRootContext | null>(null);
|
|
52
|
-
|
|
53
|
-
const Root = React.forwardRef<ViewRef, SlottableViewProps & SelectRootProps>(
|
|
54
|
-
(
|
|
55
|
-
{
|
|
56
|
-
asChild,
|
|
57
|
-
value: valueProp,
|
|
58
|
-
defaultValue,
|
|
59
|
-
onValueChange: onValueChangeProp,
|
|
60
|
-
onOpenChange: onOpenChangeProp,
|
|
61
|
-
disabled,
|
|
62
|
-
...viewProps
|
|
63
|
-
},
|
|
64
|
-
ref
|
|
65
|
-
) => {
|
|
66
|
-
const nativeID = React.useId();
|
|
67
|
-
const [value, onValueChange] = useControllableState({
|
|
68
|
-
prop: valueProp,
|
|
69
|
-
defaultProp: defaultValue,
|
|
70
|
-
onChange: onValueChangeProp,
|
|
71
|
-
});
|
|
72
|
-
const [triggerPosition, setTriggerPosition] = React.useState<LayoutPosition | null>(null);
|
|
73
|
-
const [contentLayout, setContentLayout] = React.useState<LayoutRectangle | null>(null);
|
|
74
|
-
const [open, setOpen] = React.useState(false);
|
|
75
|
-
|
|
76
|
-
function onOpenChange(value: boolean) {
|
|
77
|
-
setOpen(value);
|
|
78
|
-
onOpenChangeProp?.(value);
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
const Component = asChild ? Slot.View : View;
|
|
82
|
-
return (
|
|
83
|
-
<RootContext.Provider
|
|
84
|
-
value={{
|
|
85
|
-
value,
|
|
86
|
-
onValueChange,
|
|
87
|
-
open,
|
|
88
|
-
onOpenChange,
|
|
89
|
-
disabled,
|
|
90
|
-
contentLayout,
|
|
91
|
-
nativeID,
|
|
92
|
-
setContentLayout,
|
|
93
|
-
setTriggerPosition,
|
|
94
|
-
triggerPosition,
|
|
95
|
-
}}
|
|
96
|
-
>
|
|
97
|
-
<Component ref={ref} {...viewProps} />
|
|
98
|
-
</RootContext.Provider>
|
|
99
|
-
);
|
|
100
|
-
}
|
|
101
|
-
);
|
|
102
|
-
|
|
103
|
-
Root.displayName = 'RootNativeSelect';
|
|
104
|
-
|
|
105
|
-
function useRootContext() {
|
|
106
|
-
const context = React.useContext(RootContext);
|
|
107
|
-
if (!context) {
|
|
108
|
-
throw new Error('Select compound components cannot be rendered outside the Select component');
|
|
109
|
-
}
|
|
110
|
-
return context;
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
const Trigger = React.forwardRef<SelectTriggerRef, SlottablePressableProps>(
|
|
114
|
-
({ asChild, onPress: onPressProp, disabled = false, ...props }, ref) => {
|
|
115
|
-
const { open, onOpenChange, disabled: disabledRoot, setTriggerPosition } = useRootContext();
|
|
116
|
-
|
|
117
|
-
const augmentedRef = useAugmentedRef({
|
|
118
|
-
ref,
|
|
119
|
-
methods: {
|
|
120
|
-
open: () => {
|
|
121
|
-
onOpenChange(true);
|
|
122
|
-
augmentedRef.current?.measure((_x, _y, width, height, pageX, pageY) => {
|
|
123
|
-
setTriggerPosition({ width, pageX, pageY: pageY, height });
|
|
124
|
-
});
|
|
125
|
-
},
|
|
126
|
-
close: () => {
|
|
127
|
-
setTriggerPosition(null);
|
|
128
|
-
onOpenChange(false);
|
|
129
|
-
},
|
|
130
|
-
},
|
|
131
|
-
});
|
|
132
|
-
|
|
133
|
-
function onPress(ev: GestureResponderEvent) {
|
|
134
|
-
if (disabled) return;
|
|
135
|
-
augmentedRef.current?.measure((_x, _y, width, height, pageX, pageY) => {
|
|
136
|
-
setTriggerPosition({ width, pageX, pageY: pageY, height });
|
|
137
|
-
});
|
|
138
|
-
onOpenChange(!open);
|
|
139
|
-
onPressProp?.(ev);
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
const Component = asChild ? Slot.Pressable : Pressable;
|
|
143
|
-
return (
|
|
144
|
-
<Component
|
|
145
|
-
ref={augmentedRef}
|
|
146
|
-
aria-disabled={disabled ?? undefined}
|
|
147
|
-
role='combobox'
|
|
148
|
-
onPress={onPress}
|
|
149
|
-
disabled={disabled ?? disabledRoot}
|
|
150
|
-
aria-expanded={open}
|
|
151
|
-
{...props}
|
|
152
|
-
/>
|
|
153
|
-
);
|
|
154
|
-
}
|
|
155
|
-
);
|
|
156
|
-
|
|
157
|
-
Trigger.displayName = 'TriggerNativeSelect';
|
|
158
|
-
|
|
159
|
-
const Value = React.forwardRef<TextRef, SlottableTextProps & SelectValueProps>(
|
|
160
|
-
({ asChild, placeholder, ...props }, ref) => {
|
|
161
|
-
const { value } = useRootContext();
|
|
162
|
-
const Component = asChild ? Slot.Text : Text;
|
|
163
|
-
return (
|
|
164
|
-
<Component ref={ref} {...props}>
|
|
165
|
-
{value?.label ?? placeholder}
|
|
166
|
-
</Component>
|
|
167
|
-
);
|
|
168
|
-
}
|
|
169
|
-
);
|
|
170
|
-
|
|
171
|
-
Value.displayName = 'ValueNativeSelect';
|
|
172
|
-
|
|
173
|
-
/**
|
|
174
|
-
* @warning when using a custom `<PortalHost />`, you might have to adjust the Content's sideOffset.
|
|
175
|
-
*/
|
|
176
|
-
function Portal({ forceMount, hostName, children }: SelectPortalProps) {
|
|
177
|
-
const value = useRootContext();
|
|
178
|
-
|
|
179
|
-
if (!value.triggerPosition) {
|
|
180
|
-
return null;
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
if (!forceMount) {
|
|
184
|
-
if (!value.open) {
|
|
185
|
-
return null;
|
|
186
|
-
}
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
return (
|
|
190
|
-
<RNPPortal hostName={hostName} name={`${value.nativeID}_portal`}>
|
|
191
|
-
<RootContext.Provider value={value}>{children}</RootContext.Provider>
|
|
192
|
-
</RNPPortal>
|
|
193
|
-
);
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
const Overlay = React.forwardRef<PressableRef, SlottablePressableProps & SelectOverlayProps>(
|
|
197
|
-
({ asChild, forceMount, onPress: OnPressProp, closeOnPress = true, ...props }, ref) => {
|
|
198
|
-
const { open, onOpenChange, setTriggerPosition, setContentLayout } = useRootContext();
|
|
199
|
-
|
|
200
|
-
function onPress(ev: GestureResponderEvent) {
|
|
201
|
-
if (closeOnPress) {
|
|
202
|
-
setTriggerPosition(null);
|
|
203
|
-
setContentLayout(null);
|
|
204
|
-
onOpenChange(false);
|
|
205
|
-
}
|
|
206
|
-
OnPressProp?.(ev);
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
if (!forceMount) {
|
|
210
|
-
if (!open) {
|
|
211
|
-
return null;
|
|
212
|
-
}
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
const Component = asChild ? Slot.Pressable : Pressable;
|
|
216
|
-
return <Component ref={ref} onPress={onPress} {...props} />;
|
|
217
|
-
}
|
|
218
|
-
);
|
|
219
|
-
|
|
220
|
-
Overlay.displayName = 'OverlayNativeSelect';
|
|
221
|
-
|
|
222
|
-
/**
|
|
223
|
-
* @info `position`, `top`, `left`, and `maxWidth` style properties are controlled internally. Opt out of this behavior by setting `disablePositioningStyle` to `true`.
|
|
224
|
-
*/
|
|
225
|
-
const Content = React.forwardRef<
|
|
226
|
-
ViewRef,
|
|
227
|
-
SlottableViewProps & PositionedContentProps & SelectContentProps
|
|
228
|
-
>(
|
|
229
|
-
(
|
|
230
|
-
{
|
|
231
|
-
asChild = false,
|
|
232
|
-
forceMount,
|
|
233
|
-
align = 'start',
|
|
234
|
-
side = 'bottom',
|
|
235
|
-
sideOffset = 0,
|
|
236
|
-
alignOffset = 0,
|
|
237
|
-
avoidCollisions = true,
|
|
238
|
-
onLayout: onLayoutProp,
|
|
239
|
-
insets,
|
|
240
|
-
style,
|
|
241
|
-
disablePositioningStyle,
|
|
242
|
-
position: _position,
|
|
243
|
-
...props
|
|
244
|
-
},
|
|
245
|
-
ref
|
|
246
|
-
) => {
|
|
247
|
-
const {
|
|
248
|
-
open,
|
|
249
|
-
onOpenChange,
|
|
250
|
-
contentLayout,
|
|
251
|
-
nativeID,
|
|
252
|
-
triggerPosition,
|
|
253
|
-
setContentLayout,
|
|
254
|
-
setTriggerPosition,
|
|
255
|
-
} = useRootContext();
|
|
256
|
-
|
|
257
|
-
React.useEffect(() => {
|
|
258
|
-
const backHandler = BackHandler.addEventListener('hardwareBackPress', () => {
|
|
259
|
-
setTriggerPosition(null);
|
|
260
|
-
setContentLayout(null);
|
|
261
|
-
onOpenChange(false);
|
|
262
|
-
return true;
|
|
263
|
-
});
|
|
264
|
-
|
|
265
|
-
return () => {
|
|
266
|
-
setContentLayout(null);
|
|
267
|
-
backHandler.remove();
|
|
268
|
-
};
|
|
269
|
-
}, []);
|
|
270
|
-
|
|
271
|
-
const positionStyle = useRelativePosition({
|
|
272
|
-
align,
|
|
273
|
-
avoidCollisions,
|
|
274
|
-
triggerPosition,
|
|
275
|
-
contentLayout,
|
|
276
|
-
alignOffset,
|
|
277
|
-
insets,
|
|
278
|
-
sideOffset,
|
|
279
|
-
side,
|
|
280
|
-
disablePositioningStyle,
|
|
281
|
-
});
|
|
282
|
-
|
|
283
|
-
function onLayout(event: LayoutChangeEvent) {
|
|
284
|
-
setContentLayout(event.nativeEvent.layout);
|
|
285
|
-
onLayoutProp?.(event);
|
|
286
|
-
}
|
|
287
|
-
|
|
288
|
-
if (!forceMount) {
|
|
289
|
-
if (!open) {
|
|
290
|
-
return null;
|
|
291
|
-
}
|
|
292
|
-
}
|
|
293
|
-
|
|
294
|
-
const Component = asChild ? Slot.View : View;
|
|
295
|
-
return (
|
|
296
|
-
<Component
|
|
297
|
-
ref={ref}
|
|
298
|
-
role='list'
|
|
299
|
-
nativeID={nativeID}
|
|
300
|
-
aria-modal={true}
|
|
301
|
-
style={[positionStyle, style]}
|
|
302
|
-
onLayout={onLayout}
|
|
303
|
-
onStartShouldSetResponder={onStartShouldSetResponder}
|
|
304
|
-
{...props}
|
|
305
|
-
/>
|
|
306
|
-
);
|
|
307
|
-
}
|
|
308
|
-
);
|
|
309
|
-
|
|
310
|
-
Content.displayName = 'ContentNativeSelect';
|
|
311
|
-
|
|
312
|
-
const ItemContext = React.createContext<{
|
|
313
|
-
itemValue: string;
|
|
314
|
-
label: string;
|
|
315
|
-
} | null>(null);
|
|
316
|
-
|
|
317
|
-
const Item = React.forwardRef<PressableRef, SlottablePressableProps & SelectItemProps>(
|
|
318
|
-
(
|
|
319
|
-
{
|
|
320
|
-
asChild,
|
|
321
|
-
value: itemValue,
|
|
322
|
-
label,
|
|
323
|
-
onPress: onPressProp,
|
|
324
|
-
disabled = false,
|
|
325
|
-
closeOnPress = true,
|
|
326
|
-
...props
|
|
327
|
-
},
|
|
328
|
-
ref
|
|
329
|
-
) => {
|
|
330
|
-
const { onOpenChange, value, onValueChange, setTriggerPosition, setContentLayout } =
|
|
331
|
-
useRootContext();
|
|
332
|
-
function onPress(ev: GestureResponderEvent) {
|
|
333
|
-
if (closeOnPress) {
|
|
334
|
-
setTriggerPosition(null);
|
|
335
|
-
setContentLayout(null);
|
|
336
|
-
onOpenChange(false);
|
|
337
|
-
}
|
|
338
|
-
|
|
339
|
-
onValueChange({ value: itemValue, label });
|
|
340
|
-
onPressProp?.(ev);
|
|
341
|
-
}
|
|
342
|
-
|
|
343
|
-
const Component = asChild ? Slot.Pressable : Pressable;
|
|
344
|
-
return (
|
|
345
|
-
<ItemContext.Provider value={{ itemValue, label }}>
|
|
346
|
-
<Component
|
|
347
|
-
ref={ref}
|
|
348
|
-
role='option'
|
|
349
|
-
onPress={onPress}
|
|
350
|
-
disabled={disabled}
|
|
351
|
-
aria-checked={value?.value === itemValue}
|
|
352
|
-
aria-valuetext={label}
|
|
353
|
-
aria-disabled={!!disabled}
|
|
354
|
-
accessibilityState={{
|
|
355
|
-
disabled: !!disabled,
|
|
356
|
-
checked: value?.value === itemValue,
|
|
357
|
-
}}
|
|
358
|
-
{...props}
|
|
359
|
-
/>
|
|
360
|
-
</ItemContext.Provider>
|
|
361
|
-
);
|
|
362
|
-
}
|
|
363
|
-
);
|
|
364
|
-
|
|
365
|
-
Item.displayName = 'ItemNativeSelect';
|
|
366
|
-
|
|
367
|
-
function useItemContext() {
|
|
368
|
-
const context = React.useContext(ItemContext);
|
|
369
|
-
if (!context) {
|
|
370
|
-
throw new Error('Item compound components cannot be rendered outside of an Item component');
|
|
371
|
-
}
|
|
372
|
-
return context;
|
|
373
|
-
}
|
|
374
|
-
|
|
375
|
-
const ItemText = React.forwardRef<TextRef, Omit<SlottableTextProps, 'children'>>(
|
|
376
|
-
({ asChild, ...props }, ref) => {
|
|
377
|
-
const { label } = useItemContext();
|
|
378
|
-
|
|
379
|
-
const Component = asChild ? Slot.Text : Text;
|
|
380
|
-
return (
|
|
381
|
-
<Component ref={ref} {...props}>
|
|
382
|
-
{label}
|
|
383
|
-
</Component>
|
|
384
|
-
);
|
|
385
|
-
}
|
|
386
|
-
);
|
|
387
|
-
|
|
388
|
-
ItemText.displayName = 'ItemTextNativeSelect';
|
|
389
|
-
|
|
390
|
-
const ItemIndicator = React.forwardRef<ViewRef, SlottableViewProps & ForceMountable>(
|
|
391
|
-
({ asChild, forceMount, ...props }, ref) => {
|
|
392
|
-
const { itemValue } = useItemContext();
|
|
393
|
-
const { value } = useRootContext();
|
|
394
|
-
|
|
395
|
-
if (!forceMount) {
|
|
396
|
-
if (value?.value !== itemValue) {
|
|
397
|
-
return null;
|
|
398
|
-
}
|
|
399
|
-
}
|
|
400
|
-
const Component = asChild ? Slot.View : View;
|
|
401
|
-
return <Component ref={ref} role='presentation' {...props} />;
|
|
402
|
-
}
|
|
403
|
-
);
|
|
404
|
-
|
|
405
|
-
ItemIndicator.displayName = 'ItemIndicatorNativeSelect';
|
|
406
|
-
|
|
407
|
-
const Group = React.forwardRef<ViewRef, SlottableViewProps>(({ asChild, ...props }, ref) => {
|
|
408
|
-
const Component = asChild ? Slot.View : View;
|
|
409
|
-
return <Component ref={ref} role='group' {...props} />;
|
|
410
|
-
});
|
|
411
|
-
|
|
412
|
-
Group.displayName = 'GroupNativeSelect';
|
|
413
|
-
|
|
414
|
-
const Label = React.forwardRef<TextRef, SlottableTextProps>(({ asChild, ...props }, ref) => {
|
|
415
|
-
const Component = asChild ? Slot.Text : Text;
|
|
416
|
-
return <Component ref={ref} {...props} />;
|
|
417
|
-
});
|
|
418
|
-
|
|
419
|
-
Label.displayName = 'LabelNativeSelect';
|
|
420
|
-
|
|
421
|
-
const Separator = React.forwardRef<ViewRef, SlottableViewProps & SelectSeparatorProps>(
|
|
422
|
-
({ asChild, decorative, ...props }, ref) => {
|
|
423
|
-
const Component = asChild ? Slot.View : View;
|
|
424
|
-
return <Component role={decorative ? 'presentation' : 'separator'} ref={ref} {...props} />;
|
|
425
|
-
}
|
|
426
|
-
);
|
|
427
|
-
|
|
428
|
-
Separator.displayName = 'SeparatorNativeSelect';
|
|
429
|
-
|
|
430
|
-
const ScrollUpButton = ({ children }: { children?: React.ReactNode; className?: string }) => {
|
|
431
|
-
return children;
|
|
432
|
-
};
|
|
433
|
-
|
|
434
|
-
const ScrollDownButton = ({ children }: { children?: React.ReactNode; className?: string }) => {
|
|
435
|
-
return children;
|
|
436
|
-
};
|
|
437
|
-
|
|
438
|
-
const Viewport = ({ children }: { children?: React.ReactNode; className?: string }) => {
|
|
439
|
-
return children;
|
|
440
|
-
};
|
|
441
|
-
|
|
442
|
-
export {
|
|
443
|
-
Content,
|
|
444
|
-
Group,
|
|
445
|
-
Item,
|
|
446
|
-
ItemIndicator,
|
|
447
|
-
ItemText,
|
|
448
|
-
Label,
|
|
449
|
-
Overlay,
|
|
450
|
-
Portal,
|
|
451
|
-
Root,
|
|
452
|
-
ScrollDownButton,
|
|
453
|
-
ScrollUpButton,
|
|
454
|
-
Separator,
|
|
455
|
-
Trigger,
|
|
456
|
-
Value,
|
|
457
|
-
Viewport,
|
|
458
|
-
useItemContext,
|
|
459
|
-
useRootContext,
|
|
460
|
-
};
|
|
461
|
-
|
|
462
|
-
export type { Option, SelectTriggerRef } from './types';
|
|
463
|
-
|
|
464
|
-
function onStartShouldSetResponder() {
|
|
465
|
-
return true;
|
|
466
|
-
}
|