@tallyui/primitives 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +1370 -0
- package/dist/index.js +3954 -0
- package/package.json +47 -0
- package/src/__tests__/accordion.test.tsx +370 -0
- package/src/__tests__/alert-dialog.test.tsx +127 -0
- package/src/__tests__/animated.test.tsx +184 -0
- package/src/__tests__/checkbox.test.tsx +90 -0
- package/src/__tests__/collapsible.test.tsx +149 -0
- package/src/__tests__/combobox.test.tsx +292 -0
- package/src/__tests__/context-menu.test.tsx +226 -0
- package/src/__tests__/dialog.test.tsx +81 -0
- package/src/__tests__/dropdown-menu.test.tsx +119 -0
- package/src/__tests__/hooks.test.tsx +46 -0
- package/src/__tests__/hover-card.test.tsx +77 -0
- package/src/__tests__/image.test.tsx +53 -0
- package/src/__tests__/label.test.tsx +50 -0
- package/src/__tests__/list.test.tsx +63 -0
- package/src/__tests__/popover.test.tsx +63 -0
- package/src/__tests__/portal.test.tsx +66 -0
- package/src/__tests__/progress.test.tsx +70 -0
- package/src/__tests__/radio-group.test.tsx +164 -0
- package/src/__tests__/select.test.tsx +76 -0
- package/src/__tests__/separator.test.tsx +37 -0
- package/src/__tests__/slider.test.tsx +124 -0
- package/src/__tests__/slot.test.tsx +56 -0
- package/src/__tests__/switch.test.tsx +70 -0
- package/src/__tests__/table.test.tsx +172 -0
- package/src/__tests__/tabs.test.tsx +67 -0
- package/src/__tests__/text.test.tsx +59 -0
- package/src/__tests__/toast.test.tsx +137 -0
- package/src/__tests__/toggle-group.test.tsx +167 -0
- package/src/__tests__/toggle.test.tsx +60 -0
- package/src/__tests__/tooltip.test.tsx +77 -0
- package/src/__tests__/types.test-d.ts +106 -0
- package/src/__tests__/utils.test.ts +47 -0
- package/src/accordion/accordion.tsx +232 -0
- package/src/accordion/index.ts +12 -0
- package/src/accordion/types.ts +56 -0
- package/src/alert-dialog/alert-dialog.tsx +296 -0
- package/src/alert-dialog/index.ts +25 -0
- package/src/alert-dialog/types.ts +50 -0
- package/src/animated/index.ts +3 -0
- package/src/animated/presence.tsx +27 -0
- package/src/animated/types.ts +36 -0
- package/src/animated/use-presence.ts +44 -0
- package/src/checkbox/checkbox.tsx +106 -0
- package/src/checkbox/index.ts +2 -0
- package/src/checkbox/types.ts +19 -0
- package/src/collapsible/collapsible.tsx +135 -0
- package/src/collapsible/index.ts +2 -0
- package/src/collapsible/types.ts +25 -0
- package/src/combobox/combobox.tsx +325 -0
- package/src/combobox/index.ts +24 -0
- package/src/combobox/types.ts +84 -0
- package/src/context-menu/context-menu.tsx +654 -0
- package/src/context-menu/index.ts +40 -0
- package/src/context-menu/types.ts +117 -0
- package/src/dialog/dialog.tsx +260 -0
- package/src/dialog/index.ts +23 -0
- package/src/dialog/types.ts +47 -0
- package/src/dropdown-menu/dropdown-menu.tsx +654 -0
- package/src/dropdown-menu/index.ts +40 -0
- package/src/dropdown-menu/types.ts +117 -0
- package/src/hooks/index.ts +6 -0
- package/src/hooks/use-augmented-ref.ts +32 -0
- package/src/hooks/use-controllable-state.ts +87 -0
- package/src/hooks/use-relative-position.ts +253 -0
- package/src/hooks/use-relative-position.web.ts +9 -0
- package/src/hover-card/hover-card.tsx +271 -0
- package/src/hover-card/index.ts +17 -0
- package/src/hover-card/types.ts +50 -0
- package/src/image/image.tsx +29 -0
- package/src/image/index.ts +2 -0
- package/src/image/types.ts +10 -0
- package/src/index.ts +38 -0
- package/src/label/index.ts +2 -0
- package/src/label/label.tsx +45 -0
- package/src/label/types.ts +11 -0
- package/src/list/index.ts +2 -0
- package/src/list/list.tsx +54 -0
- package/src/list/types.ts +14 -0
- package/src/popover/index.ts +19 -0
- package/src/popover/popover.tsx +314 -0
- package/src/popover/types.ts +51 -0
- package/src/portal.tsx +60 -0
- package/src/progress/index.ts +2 -0
- package/src/progress/progress.tsx +92 -0
- package/src/progress/types.ts +16 -0
- package/src/radio-group/index.ts +2 -0
- package/src/radio-group/radio-group.tsx +160 -0
- package/src/radio-group/types.ts +31 -0
- package/src/select/index.ts +34 -0
- package/src/select/select.tsx +465 -0
- package/src/select/types.ts +112 -0
- package/src/separator/index.ts +2 -0
- package/src/separator/separator.tsx +32 -0
- package/src/separator/types.ts +8 -0
- package/src/slider/index.ts +2 -0
- package/src/slider/slider.tsx +139 -0
- package/src/slider/types.ts +35 -0
- package/src/slot.tsx +160 -0
- package/src/switch/index.ts +2 -0
- package/src/switch/switch.tsx +92 -0
- package/src/switch/types.ts +18 -0
- package/src/table/index.ts +12 -0
- package/src/table/table.tsx +160 -0
- package/src/table/types.ts +30 -0
- package/src/tabs/index.ts +15 -0
- package/src/tabs/tabs.tsx +140 -0
- package/src/tabs/types.ts +36 -0
- package/src/text/index.ts +2 -0
- package/src/text/text.tsx +40 -0
- package/src/text/types.ts +5 -0
- package/src/toast/index.ts +2 -0
- package/src/toast/toast.tsx +189 -0
- package/src/toast/types.ts +35 -0
- package/src/toggle/index.ts +2 -0
- package/src/toggle/toggle.tsx +59 -0
- package/src/toggle/types.ts +11 -0
- package/src/toggle-group/index.ts +2 -0
- package/src/toggle-group/toggle-group.tsx +123 -0
- package/src/toggle-group/types.ts +36 -0
- package/src/tooltip/index.ts +17 -0
- package/src/tooltip/tooltip.tsx +272 -0
- package/src/tooltip/types.ts +49 -0
- package/src/types.ts +129 -0
- package/src/uniwind-env.d.ts +31 -0
- package/src/utils.ts +67 -0
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { Pressable, View, type GestureResponderEvent } from 'react-native';
|
|
3
|
+
import { useControllableState } from '../hooks';
|
|
4
|
+
import { Slot } from '../slot';
|
|
5
|
+
import type { RootProps, TriggerProps, ContentProps, RootContext as RootContextType } from './types';
|
|
6
|
+
|
|
7
|
+
// ---------------------------------------------------------------------------
|
|
8
|
+
// Context
|
|
9
|
+
// ---------------------------------------------------------------------------
|
|
10
|
+
|
|
11
|
+
const RootContext = React.createContext<RootContextType | null>(null);
|
|
12
|
+
|
|
13
|
+
function useRootContext(): RootContextType {
|
|
14
|
+
const context = React.useContext(RootContext);
|
|
15
|
+
if (!context) {
|
|
16
|
+
throw new Error(
|
|
17
|
+
'Collapsible compound components cannot be rendered outside the Collapsible.Root component'
|
|
18
|
+
);
|
|
19
|
+
}
|
|
20
|
+
return context;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
// ---------------------------------------------------------------------------
|
|
24
|
+
// Root
|
|
25
|
+
// ---------------------------------------------------------------------------
|
|
26
|
+
|
|
27
|
+
const Root = React.forwardRef<View, RootProps>(function Root(
|
|
28
|
+
{
|
|
29
|
+
asChild,
|
|
30
|
+
open: openProp,
|
|
31
|
+
defaultOpen,
|
|
32
|
+
onOpenChange: onOpenChangeProp,
|
|
33
|
+
disabled = false,
|
|
34
|
+
...props
|
|
35
|
+
},
|
|
36
|
+
ref
|
|
37
|
+
) {
|
|
38
|
+
const [open = false, setOpen] = useControllableState({
|
|
39
|
+
prop: openProp,
|
|
40
|
+
defaultProp: defaultOpen,
|
|
41
|
+
onChange: onOpenChangeProp,
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
const onOpenChange = React.useCallback(
|
|
45
|
+
(value: boolean) => {
|
|
46
|
+
setOpen(value);
|
|
47
|
+
},
|
|
48
|
+
[setOpen]
|
|
49
|
+
);
|
|
50
|
+
|
|
51
|
+
const Component = asChild ? Slot : View;
|
|
52
|
+
|
|
53
|
+
return (
|
|
54
|
+
<RootContext.Provider value={{ open, disabled, onOpenChange }}>
|
|
55
|
+
<Component
|
|
56
|
+
ref={ref}
|
|
57
|
+
aria-disabled={disabled || undefined}
|
|
58
|
+
{...props}
|
|
59
|
+
/>
|
|
60
|
+
</RootContext.Provider>
|
|
61
|
+
);
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
Root.displayName = 'CollapsibleRoot';
|
|
65
|
+
|
|
66
|
+
// ---------------------------------------------------------------------------
|
|
67
|
+
// Trigger
|
|
68
|
+
// ---------------------------------------------------------------------------
|
|
69
|
+
|
|
70
|
+
const Trigger = React.forwardRef<View, TriggerProps>(function Trigger(
|
|
71
|
+
{ asChild, onPress: onPressProp, disabled: disabledProp, ...props },
|
|
72
|
+
ref
|
|
73
|
+
) {
|
|
74
|
+
const { open, disabled: rootDisabled, onOpenChange } = useRootContext();
|
|
75
|
+
|
|
76
|
+
const isDisabled = rootDisabled || disabledProp;
|
|
77
|
+
|
|
78
|
+
const onPress = React.useCallback(
|
|
79
|
+
(ev: GestureResponderEvent) => {
|
|
80
|
+
if (isDisabled) return;
|
|
81
|
+
onOpenChange(!open);
|
|
82
|
+
onPressProp?.(ev);
|
|
83
|
+
},
|
|
84
|
+
[isDisabled, open, onOpenChange, onPressProp]
|
|
85
|
+
);
|
|
86
|
+
|
|
87
|
+
const Component = asChild ? Slot : Pressable;
|
|
88
|
+
|
|
89
|
+
return (
|
|
90
|
+
<Component
|
|
91
|
+
ref={ref}
|
|
92
|
+
role="button"
|
|
93
|
+
aria-expanded={open}
|
|
94
|
+
aria-disabled={isDisabled || undefined}
|
|
95
|
+
onPress={onPress}
|
|
96
|
+
disabled={isDisabled || undefined}
|
|
97
|
+
{...props}
|
|
98
|
+
/>
|
|
99
|
+
);
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
Trigger.displayName = 'CollapsibleTrigger';
|
|
103
|
+
|
|
104
|
+
// ---------------------------------------------------------------------------
|
|
105
|
+
// Content
|
|
106
|
+
// ---------------------------------------------------------------------------
|
|
107
|
+
|
|
108
|
+
const Content = React.forwardRef<View, ContentProps>(function Content(
|
|
109
|
+
{ asChild, forceMount, ...props },
|
|
110
|
+
ref
|
|
111
|
+
) {
|
|
112
|
+
const { open } = useRootContext();
|
|
113
|
+
|
|
114
|
+
if (!forceMount && !open) {
|
|
115
|
+
return null;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
const Component = asChild ? Slot : View;
|
|
119
|
+
|
|
120
|
+
return (
|
|
121
|
+
<Component
|
|
122
|
+
ref={ref}
|
|
123
|
+
role="region"
|
|
124
|
+
{...props}
|
|
125
|
+
/>
|
|
126
|
+
);
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
Content.displayName = 'CollapsibleContent';
|
|
130
|
+
|
|
131
|
+
// ---------------------------------------------------------------------------
|
|
132
|
+
// Exports
|
|
133
|
+
// ---------------------------------------------------------------------------
|
|
134
|
+
|
|
135
|
+
export { Root, Trigger, Content, useRootContext };
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { ForceMountable, SlottablePressableProps, SlottableViewProps, PressableRef, ViewRef } from '../types';
|
|
2
|
+
|
|
3
|
+
interface RootProps extends SlottableViewProps {
|
|
4
|
+
open?: boolean;
|
|
5
|
+
defaultOpen?: boolean;
|
|
6
|
+
onOpenChange?: (open: boolean) => void;
|
|
7
|
+
disabled?: boolean;
|
|
8
|
+
ref?: ViewRef;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
interface TriggerProps extends SlottablePressableProps {
|
|
12
|
+
ref?: PressableRef;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
interface ContentProps extends SlottableViewProps, ForceMountable {
|
|
16
|
+
ref?: ViewRef;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
interface RootContext {
|
|
20
|
+
open: boolean;
|
|
21
|
+
disabled: boolean;
|
|
22
|
+
onOpenChange: (open: boolean) => void;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export type { RootProps, TriggerProps, ContentProps, RootContext };
|
|
@@ -0,0 +1,325 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import {
|
|
3
|
+
Pressable,
|
|
4
|
+
Text,
|
|
5
|
+
TextInput,
|
|
6
|
+
View,
|
|
7
|
+
type GestureResponderEvent,
|
|
8
|
+
type NativeSyntheticEvent,
|
|
9
|
+
type TextInputChangeEventData,
|
|
10
|
+
} from 'react-native';
|
|
11
|
+
import { useControllableState } from '../hooks';
|
|
12
|
+
import { Portal as RNPortal } from '../portal';
|
|
13
|
+
import { Slot } from '../slot';
|
|
14
|
+
import type {
|
|
15
|
+
ContentProps,
|
|
16
|
+
EmptyProps,
|
|
17
|
+
InputProps,
|
|
18
|
+
ItemProps,
|
|
19
|
+
ItemTextProps,
|
|
20
|
+
Option,
|
|
21
|
+
PortalProps,
|
|
22
|
+
RootContext as RootContextType,
|
|
23
|
+
RootProps,
|
|
24
|
+
TriggerProps,
|
|
25
|
+
} from './types';
|
|
26
|
+
|
|
27
|
+
// ---------------------------------------------------------------------------
|
|
28
|
+
// Root context
|
|
29
|
+
// ---------------------------------------------------------------------------
|
|
30
|
+
|
|
31
|
+
const RootContext = React.createContext<RootContextType | null>(null);
|
|
32
|
+
|
|
33
|
+
function useRootContext(): RootContextType {
|
|
34
|
+
const context = React.useContext(RootContext);
|
|
35
|
+
if (!context) {
|
|
36
|
+
throw new Error(
|
|
37
|
+
'Combobox compound components cannot be rendered outside the Combobox.Root component'
|
|
38
|
+
);
|
|
39
|
+
}
|
|
40
|
+
return context;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// ---------------------------------------------------------------------------
|
|
44
|
+
// Item context
|
|
45
|
+
// ---------------------------------------------------------------------------
|
|
46
|
+
|
|
47
|
+
interface ItemContextType {
|
|
48
|
+
itemValue: string;
|
|
49
|
+
label: string;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
const ItemContext = React.createContext<ItemContextType | null>(null);
|
|
53
|
+
|
|
54
|
+
function useItemContext(): ItemContextType {
|
|
55
|
+
const context = React.useContext(ItemContext);
|
|
56
|
+
if (!context) {
|
|
57
|
+
throw new Error(
|
|
58
|
+
'Combobox.Item compound components cannot be rendered outside a Combobox.Item component'
|
|
59
|
+
);
|
|
60
|
+
}
|
|
61
|
+
return context;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// ---------------------------------------------------------------------------
|
|
65
|
+
// Root
|
|
66
|
+
// ---------------------------------------------------------------------------
|
|
67
|
+
|
|
68
|
+
function Root({
|
|
69
|
+
value: valueProp,
|
|
70
|
+
defaultValue,
|
|
71
|
+
onValueChange: onValueChangeProp,
|
|
72
|
+
open: openProp,
|
|
73
|
+
defaultOpen,
|
|
74
|
+
onOpenChange: onOpenChangeProp,
|
|
75
|
+
searchValue: searchValueProp,
|
|
76
|
+
onSearchValueChange: onSearchValueChangeProp,
|
|
77
|
+
children,
|
|
78
|
+
}: RootProps) {
|
|
79
|
+
const nativeID = React.useId();
|
|
80
|
+
|
|
81
|
+
const [value, onValueChange] = useControllableState<Option | undefined>({
|
|
82
|
+
prop: valueProp,
|
|
83
|
+
defaultProp: defaultValue,
|
|
84
|
+
onChange: onValueChangeProp,
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
const [open = false, onOpenChange] = useControllableState({
|
|
88
|
+
prop: openProp,
|
|
89
|
+
defaultProp: defaultOpen,
|
|
90
|
+
onChange: onOpenChangeProp,
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
const [searchValue = '', onSearchValueChange] = useControllableState({
|
|
94
|
+
prop: searchValueProp,
|
|
95
|
+
defaultProp: '',
|
|
96
|
+
onChange: onSearchValueChangeProp,
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
return (
|
|
100
|
+
<RootContext.Provider
|
|
101
|
+
value={{
|
|
102
|
+
value,
|
|
103
|
+
onValueChange: onValueChange as (option: Option | undefined) => void,
|
|
104
|
+
open,
|
|
105
|
+
onOpenChange,
|
|
106
|
+
searchValue,
|
|
107
|
+
onSearchValueChange: onSearchValueChange as (search: string) => void,
|
|
108
|
+
nativeID,
|
|
109
|
+
}}
|
|
110
|
+
>
|
|
111
|
+
{children}
|
|
112
|
+
</RootContext.Provider>
|
|
113
|
+
);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
Root.displayName = 'ComboboxRoot';
|
|
117
|
+
|
|
118
|
+
// ---------------------------------------------------------------------------
|
|
119
|
+
// Input
|
|
120
|
+
// ---------------------------------------------------------------------------
|
|
121
|
+
|
|
122
|
+
const Input = React.forwardRef<View, InputProps>(function Input(
|
|
123
|
+
{ asChild, placeholder, ...props },
|
|
124
|
+
ref
|
|
125
|
+
) {
|
|
126
|
+
const { open, onOpenChange, searchValue, onSearchValueChange } = useRootContext();
|
|
127
|
+
|
|
128
|
+
const onChange = React.useCallback(
|
|
129
|
+
(ev: NativeSyntheticEvent<TextInputChangeEventData>) => {
|
|
130
|
+
onSearchValueChange(ev.nativeEvent.text);
|
|
131
|
+
if (!open) {
|
|
132
|
+
onOpenChange(true);
|
|
133
|
+
}
|
|
134
|
+
},
|
|
135
|
+
[onSearchValueChange, onOpenChange, open]
|
|
136
|
+
);
|
|
137
|
+
|
|
138
|
+
const onFocus = React.useCallback(() => {
|
|
139
|
+
if (!open) {
|
|
140
|
+
onOpenChange(true);
|
|
141
|
+
}
|
|
142
|
+
}, [onOpenChange, open]);
|
|
143
|
+
|
|
144
|
+
const Component = asChild ? Slot : TextInput;
|
|
145
|
+
|
|
146
|
+
return (
|
|
147
|
+
<Component
|
|
148
|
+
ref={ref}
|
|
149
|
+
role="combobox"
|
|
150
|
+
aria-expanded={open}
|
|
151
|
+
aria-autocomplete="list"
|
|
152
|
+
placeholder={placeholder}
|
|
153
|
+
value={searchValue}
|
|
154
|
+
onChange={onChange}
|
|
155
|
+
onFocus={onFocus}
|
|
156
|
+
{...props}
|
|
157
|
+
/>
|
|
158
|
+
);
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
Input.displayName = 'ComboboxInput';
|
|
162
|
+
|
|
163
|
+
// ---------------------------------------------------------------------------
|
|
164
|
+
// Trigger
|
|
165
|
+
// ---------------------------------------------------------------------------
|
|
166
|
+
|
|
167
|
+
const Trigger = React.forwardRef<View, TriggerProps>(function Trigger(
|
|
168
|
+
{ asChild, onPress: onPressProp, ...props },
|
|
169
|
+
ref
|
|
170
|
+
) {
|
|
171
|
+
const { open, onOpenChange } = useRootContext();
|
|
172
|
+
|
|
173
|
+
const onPress = React.useCallback(
|
|
174
|
+
(ev: GestureResponderEvent) => {
|
|
175
|
+
onOpenChange(!open);
|
|
176
|
+
onPressProp?.(ev);
|
|
177
|
+
},
|
|
178
|
+
[onOpenChange, onPressProp, open]
|
|
179
|
+
);
|
|
180
|
+
|
|
181
|
+
const Component = asChild ? Slot : Pressable;
|
|
182
|
+
|
|
183
|
+
return (
|
|
184
|
+
<Component
|
|
185
|
+
ref={ref}
|
|
186
|
+
role="button"
|
|
187
|
+
aria-expanded={open}
|
|
188
|
+
onPress={onPress}
|
|
189
|
+
{...props}
|
|
190
|
+
/>
|
|
191
|
+
);
|
|
192
|
+
});
|
|
193
|
+
|
|
194
|
+
Trigger.displayName = 'ComboboxTrigger';
|
|
195
|
+
|
|
196
|
+
// ---------------------------------------------------------------------------
|
|
197
|
+
// Portal
|
|
198
|
+
// ---------------------------------------------------------------------------
|
|
199
|
+
|
|
200
|
+
function Portal({ forceMount, hostName, children }: PortalProps) {
|
|
201
|
+
const rootValue = useRootContext();
|
|
202
|
+
|
|
203
|
+
if (!forceMount && !rootValue.open) {
|
|
204
|
+
return null;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
return (
|
|
208
|
+
<RNPortal hostName={hostName} name={`${rootValue.nativeID}_portal`}>
|
|
209
|
+
<RootContext.Provider value={rootValue}>{children}</RootContext.Provider>
|
|
210
|
+
</RNPortal>
|
|
211
|
+
);
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
Portal.displayName = 'ComboboxPortal';
|
|
215
|
+
|
|
216
|
+
// ---------------------------------------------------------------------------
|
|
217
|
+
// Content
|
|
218
|
+
// ---------------------------------------------------------------------------
|
|
219
|
+
|
|
220
|
+
const Content = React.forwardRef<View, ContentProps>(function Content(
|
|
221
|
+
{ asChild, forceMount, ...props },
|
|
222
|
+
ref
|
|
223
|
+
) {
|
|
224
|
+
const { open } = useRootContext();
|
|
225
|
+
|
|
226
|
+
if (!forceMount && !open) {
|
|
227
|
+
return null;
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
const Component = asChild ? Slot : View;
|
|
231
|
+
|
|
232
|
+
return <Component ref={ref} role="listbox" {...props} />;
|
|
233
|
+
});
|
|
234
|
+
|
|
235
|
+
Content.displayName = 'ComboboxContent';
|
|
236
|
+
|
|
237
|
+
// ---------------------------------------------------------------------------
|
|
238
|
+
// Item
|
|
239
|
+
// ---------------------------------------------------------------------------
|
|
240
|
+
|
|
241
|
+
const Item = React.forwardRef<View, ItemProps>(function Item(
|
|
242
|
+
{ asChild, value: itemValue, label, onPress: onPressProp, ...props },
|
|
243
|
+
ref
|
|
244
|
+
) {
|
|
245
|
+
const { value, onValueChange, onOpenChange, onSearchValueChange } = useRootContext();
|
|
246
|
+
|
|
247
|
+
const isSelected = value?.value === itemValue;
|
|
248
|
+
|
|
249
|
+
const onPress = React.useCallback(
|
|
250
|
+
(ev: GestureResponderEvent) => {
|
|
251
|
+
onValueChange({ value: itemValue, label });
|
|
252
|
+
onOpenChange(false);
|
|
253
|
+
onSearchValueChange('');
|
|
254
|
+
onPressProp?.(ev);
|
|
255
|
+
},
|
|
256
|
+
[itemValue, label, onOpenChange, onPressProp, onSearchValueChange, onValueChange]
|
|
257
|
+
);
|
|
258
|
+
|
|
259
|
+
const Component = asChild ? Slot : Pressable;
|
|
260
|
+
|
|
261
|
+
return (
|
|
262
|
+
<ItemContext.Provider value={{ itemValue, label }}>
|
|
263
|
+
<Component
|
|
264
|
+
ref={ref}
|
|
265
|
+
role="option"
|
|
266
|
+
aria-selected={isSelected}
|
|
267
|
+
onPress={onPress}
|
|
268
|
+
{...props}
|
|
269
|
+
/>
|
|
270
|
+
</ItemContext.Provider>
|
|
271
|
+
);
|
|
272
|
+
});
|
|
273
|
+
|
|
274
|
+
Item.displayName = 'ComboboxItem';
|
|
275
|
+
|
|
276
|
+
// ---------------------------------------------------------------------------
|
|
277
|
+
// ItemText
|
|
278
|
+
// ---------------------------------------------------------------------------
|
|
279
|
+
|
|
280
|
+
const ItemText = React.forwardRef<Text, ItemTextProps>(function ItemText(
|
|
281
|
+
{ asChild, ...props },
|
|
282
|
+
ref
|
|
283
|
+
) {
|
|
284
|
+
const { label } = useItemContext();
|
|
285
|
+
const Component = asChild ? Slot : Text;
|
|
286
|
+
|
|
287
|
+
return (
|
|
288
|
+
<Component ref={ref} {...props}>
|
|
289
|
+
{label}
|
|
290
|
+
</Component>
|
|
291
|
+
);
|
|
292
|
+
});
|
|
293
|
+
|
|
294
|
+
ItemText.displayName = 'ComboboxItemText';
|
|
295
|
+
|
|
296
|
+
// ---------------------------------------------------------------------------
|
|
297
|
+
// Empty
|
|
298
|
+
// ---------------------------------------------------------------------------
|
|
299
|
+
|
|
300
|
+
const Empty = React.forwardRef<View, EmptyProps>(function Empty(
|
|
301
|
+
{ asChild, ...props },
|
|
302
|
+
ref
|
|
303
|
+
) {
|
|
304
|
+
const Component = asChild ? Slot : View;
|
|
305
|
+
|
|
306
|
+
return <Component ref={ref} {...props} />;
|
|
307
|
+
});
|
|
308
|
+
|
|
309
|
+
Empty.displayName = 'ComboboxEmpty';
|
|
310
|
+
|
|
311
|
+
// ---------------------------------------------------------------------------
|
|
312
|
+
// Exports
|
|
313
|
+
// ---------------------------------------------------------------------------
|
|
314
|
+
|
|
315
|
+
export {
|
|
316
|
+
Content,
|
|
317
|
+
Empty,
|
|
318
|
+
Input,
|
|
319
|
+
Item,
|
|
320
|
+
ItemText,
|
|
321
|
+
Portal,
|
|
322
|
+
Root,
|
|
323
|
+
Trigger,
|
|
324
|
+
useRootContext,
|
|
325
|
+
};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export {
|
|
2
|
+
Root,
|
|
3
|
+
Input,
|
|
4
|
+
Trigger,
|
|
5
|
+
Portal,
|
|
6
|
+
Content,
|
|
7
|
+
Item,
|
|
8
|
+
ItemText,
|
|
9
|
+
Empty,
|
|
10
|
+
useRootContext,
|
|
11
|
+
} from './combobox';
|
|
12
|
+
|
|
13
|
+
export type {
|
|
14
|
+
RootProps,
|
|
15
|
+
InputProps,
|
|
16
|
+
TriggerProps,
|
|
17
|
+
PortalProps,
|
|
18
|
+
ContentProps,
|
|
19
|
+
ItemProps,
|
|
20
|
+
ItemTextProps,
|
|
21
|
+
EmptyProps,
|
|
22
|
+
RootContext,
|
|
23
|
+
Option,
|
|
24
|
+
} from './types';
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
ForceMountable,
|
|
3
|
+
SlottablePressableProps,
|
|
4
|
+
SlottableTextProps,
|
|
5
|
+
SlottableViewProps,
|
|
6
|
+
} from '../types';
|
|
7
|
+
|
|
8
|
+
// ---------------------------------------------------------------------------
|
|
9
|
+
// Option type
|
|
10
|
+
// ---------------------------------------------------------------------------
|
|
11
|
+
|
|
12
|
+
interface Option {
|
|
13
|
+
value: string;
|
|
14
|
+
label: string;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
// ---------------------------------------------------------------------------
|
|
18
|
+
// Context types
|
|
19
|
+
// ---------------------------------------------------------------------------
|
|
20
|
+
|
|
21
|
+
interface RootContext {
|
|
22
|
+
value: Option | undefined;
|
|
23
|
+
onValueChange: (value: Option | undefined) => void;
|
|
24
|
+
open: boolean;
|
|
25
|
+
onOpenChange: (open: boolean) => void;
|
|
26
|
+
searchValue: string;
|
|
27
|
+
onSearchValueChange: (search: string) => void;
|
|
28
|
+
nativeID: string;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// ---------------------------------------------------------------------------
|
|
32
|
+
// Component props
|
|
33
|
+
// ---------------------------------------------------------------------------
|
|
34
|
+
|
|
35
|
+
interface RootProps {
|
|
36
|
+
value?: Option | undefined;
|
|
37
|
+
defaultValue?: Option | undefined;
|
|
38
|
+
onValueChange?: (value: Option | undefined) => void;
|
|
39
|
+
open?: boolean;
|
|
40
|
+
defaultOpen?: boolean;
|
|
41
|
+
onOpenChange?: (open: boolean) => void;
|
|
42
|
+
searchValue?: string;
|
|
43
|
+
onSearchValueChange?: (search: string) => void;
|
|
44
|
+
children?: React.ReactNode;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
interface InputProps extends SlottableViewProps {
|
|
48
|
+
placeholder?: string;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
interface TriggerProps extends SlottablePressableProps {}
|
|
52
|
+
|
|
53
|
+
interface PortalProps extends ForceMountable {
|
|
54
|
+
hostName?: string;
|
|
55
|
+
children?: React.ReactNode;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
interface ContentProps extends SlottableViewProps, ForceMountable {}
|
|
59
|
+
|
|
60
|
+
interface ItemProps extends SlottablePressableProps {
|
|
61
|
+
value: string;
|
|
62
|
+
label: string;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
interface ItemTextProps extends SlottableTextProps {}
|
|
66
|
+
|
|
67
|
+
interface EmptyProps extends SlottableViewProps {}
|
|
68
|
+
|
|
69
|
+
// ---------------------------------------------------------------------------
|
|
70
|
+
// Exports
|
|
71
|
+
// ---------------------------------------------------------------------------
|
|
72
|
+
|
|
73
|
+
export type {
|
|
74
|
+
ContentProps,
|
|
75
|
+
EmptyProps,
|
|
76
|
+
InputProps,
|
|
77
|
+
ItemProps,
|
|
78
|
+
ItemTextProps,
|
|
79
|
+
Option,
|
|
80
|
+
PortalProps,
|
|
81
|
+
RootContext,
|
|
82
|
+
RootProps,
|
|
83
|
+
TriggerProps,
|
|
84
|
+
};
|