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