@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,271 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import {
|
|
3
|
+
Pressable,
|
|
4
|
+
View,
|
|
5
|
+
type GestureResponderEvent,
|
|
6
|
+
type LayoutChangeEvent,
|
|
7
|
+
type LayoutRectangle,
|
|
8
|
+
} from 'react-native';
|
|
9
|
+
import { useAugmentedRef, useControllableState, useRelativePosition, type LayoutPosition } from '../hooks';
|
|
10
|
+
import { Portal as RNPortal } from '../portal';
|
|
11
|
+
import { Slot } from '../slot';
|
|
12
|
+
import type {
|
|
13
|
+
ContentProps,
|
|
14
|
+
OverlayProps,
|
|
15
|
+
PortalProps,
|
|
16
|
+
RootContext as RootContextType,
|
|
17
|
+
RootProps,
|
|
18
|
+
TriggerProps,
|
|
19
|
+
} from './types';
|
|
20
|
+
|
|
21
|
+
// ---------------------------------------------------------------------------
|
|
22
|
+
// Internal context (nativeID for aria linkage)
|
|
23
|
+
// ---------------------------------------------------------------------------
|
|
24
|
+
|
|
25
|
+
const InternalContext = React.createContext<{ nativeID: string } | null>(null);
|
|
26
|
+
|
|
27
|
+
function useInternalContext() {
|
|
28
|
+
const context = React.useContext(InternalContext);
|
|
29
|
+
if (!context) {
|
|
30
|
+
throw new Error(
|
|
31
|
+
'HoverCard compound components cannot be rendered outside the HoverCard.Root component'
|
|
32
|
+
);
|
|
33
|
+
}
|
|
34
|
+
return context;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// ---------------------------------------------------------------------------
|
|
38
|
+
// Root context (open state + positioning data)
|
|
39
|
+
// ---------------------------------------------------------------------------
|
|
40
|
+
|
|
41
|
+
const RootContext = React.createContext<RootContextType | null>(null);
|
|
42
|
+
|
|
43
|
+
function useRootContext(): RootContextType {
|
|
44
|
+
const context = React.useContext(RootContext);
|
|
45
|
+
if (!context) {
|
|
46
|
+
throw new Error(
|
|
47
|
+
'HoverCard compound components cannot be rendered outside the HoverCard.Root component'
|
|
48
|
+
);
|
|
49
|
+
}
|
|
50
|
+
return context;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// ---------------------------------------------------------------------------
|
|
54
|
+
// Root
|
|
55
|
+
// ---------------------------------------------------------------------------
|
|
56
|
+
|
|
57
|
+
function Root({ open: openProp, defaultOpen, onOpenChange: onOpenChangeProp, children }: RootProps) {
|
|
58
|
+
const nativeID = React.useId();
|
|
59
|
+
const [open = false, onOpenChange] = useControllableState({
|
|
60
|
+
prop: openProp,
|
|
61
|
+
defaultProp: defaultOpen,
|
|
62
|
+
onChange: onOpenChangeProp,
|
|
63
|
+
});
|
|
64
|
+
const [triggerPosition, setTriggerPosition] = React.useState<LayoutPosition | null>(null);
|
|
65
|
+
const [contentLayout, setContentLayout] = React.useState<LayoutRectangle | null>(null);
|
|
66
|
+
|
|
67
|
+
return (
|
|
68
|
+
<InternalContext.Provider value={{ nativeID }}>
|
|
69
|
+
<RootContext.Provider
|
|
70
|
+
value={{
|
|
71
|
+
open,
|
|
72
|
+
onOpenChange,
|
|
73
|
+
triggerPosition,
|
|
74
|
+
setTriggerPosition,
|
|
75
|
+
contentLayout,
|
|
76
|
+
setContentLayout,
|
|
77
|
+
}}
|
|
78
|
+
>
|
|
79
|
+
{children}
|
|
80
|
+
</RootContext.Provider>
|
|
81
|
+
</InternalContext.Provider>
|
|
82
|
+
);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
Root.displayName = 'HoverCardRoot';
|
|
86
|
+
|
|
87
|
+
// ---------------------------------------------------------------------------
|
|
88
|
+
// Trigger
|
|
89
|
+
// ---------------------------------------------------------------------------
|
|
90
|
+
|
|
91
|
+
const Trigger = React.forwardRef<View, TriggerProps>(function Trigger(
|
|
92
|
+
{ asChild, onPress: onPressProp, disabled, ...props },
|
|
93
|
+
ref
|
|
94
|
+
) {
|
|
95
|
+
const { open, onOpenChange, setTriggerPosition } = useRootContext();
|
|
96
|
+
|
|
97
|
+
const augmentedRef = useAugmentedRef<View>({
|
|
98
|
+
ref,
|
|
99
|
+
methods: {
|
|
100
|
+
open: () => {
|
|
101
|
+
onOpenChange(true);
|
|
102
|
+
augmentedRef.current?.measure?.((_x, _y, width, height, pageX, pageY) => {
|
|
103
|
+
setTriggerPosition({ width, pageX, pageY, height });
|
|
104
|
+
});
|
|
105
|
+
},
|
|
106
|
+
close: () => {
|
|
107
|
+
setTriggerPosition(null);
|
|
108
|
+
onOpenChange(false);
|
|
109
|
+
},
|
|
110
|
+
},
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
const onPress = React.useCallback(
|
|
114
|
+
(ev: GestureResponderEvent) => {
|
|
115
|
+
if (disabled) return;
|
|
116
|
+
augmentedRef.current?.measure?.((_x, _y, width, height, pageX, pageY) => {
|
|
117
|
+
setTriggerPosition({ width, pageX, pageY, height });
|
|
118
|
+
});
|
|
119
|
+
onOpenChange(!open);
|
|
120
|
+
onPressProp?.(ev);
|
|
121
|
+
},
|
|
122
|
+
[augmentedRef, disabled, onOpenChange, onPressProp, open, setTriggerPosition]
|
|
123
|
+
);
|
|
124
|
+
|
|
125
|
+
const Component = asChild ? Slot : Pressable;
|
|
126
|
+
|
|
127
|
+
return (
|
|
128
|
+
<Component
|
|
129
|
+
ref={augmentedRef}
|
|
130
|
+
role="button"
|
|
131
|
+
aria-disabled={disabled || undefined}
|
|
132
|
+
onPress={onPress}
|
|
133
|
+
disabled={disabled || undefined}
|
|
134
|
+
{...props}
|
|
135
|
+
/>
|
|
136
|
+
);
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
Trigger.displayName = 'HoverCardTrigger';
|
|
140
|
+
|
|
141
|
+
// ---------------------------------------------------------------------------
|
|
142
|
+
// Portal
|
|
143
|
+
// ---------------------------------------------------------------------------
|
|
144
|
+
|
|
145
|
+
function Portal({ forceMount, hostName, children }: PortalProps) {
|
|
146
|
+
const internalValue = useInternalContext();
|
|
147
|
+
const rootValue = useRootContext();
|
|
148
|
+
|
|
149
|
+
if (!forceMount && !rootValue.open) {
|
|
150
|
+
return null;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
return (
|
|
154
|
+
<RNPortal hostName={hostName} name={`${internalValue.nativeID}_portal`}>
|
|
155
|
+
<InternalContext.Provider value={internalValue}>
|
|
156
|
+
<RootContext.Provider value={rootValue}>{children}</RootContext.Provider>
|
|
157
|
+
</InternalContext.Provider>
|
|
158
|
+
</RNPortal>
|
|
159
|
+
);
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
Portal.displayName = 'HoverCardPortal';
|
|
163
|
+
|
|
164
|
+
// ---------------------------------------------------------------------------
|
|
165
|
+
// Overlay
|
|
166
|
+
// ---------------------------------------------------------------------------
|
|
167
|
+
|
|
168
|
+
const Overlay = React.forwardRef<View, OverlayProps>(function Overlay(
|
|
169
|
+
{ asChild, forceMount, onPress: onPressProp, closeOnPress = true, ...props },
|
|
170
|
+
ref
|
|
171
|
+
) {
|
|
172
|
+
const { open, onOpenChange, setTriggerPosition, setContentLayout } = useRootContext();
|
|
173
|
+
|
|
174
|
+
const onPress = React.useCallback(
|
|
175
|
+
(ev: GestureResponderEvent) => {
|
|
176
|
+
if (closeOnPress) {
|
|
177
|
+
setTriggerPosition(null);
|
|
178
|
+
setContentLayout(null);
|
|
179
|
+
onOpenChange(false);
|
|
180
|
+
}
|
|
181
|
+
onPressProp?.(ev);
|
|
182
|
+
},
|
|
183
|
+
[closeOnPress, onOpenChange, onPressProp, setContentLayout, setTriggerPosition]
|
|
184
|
+
);
|
|
185
|
+
|
|
186
|
+
if (!forceMount && !open) {
|
|
187
|
+
return null;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
const Component = asChild ? Slot : Pressable;
|
|
191
|
+
|
|
192
|
+
return <Component ref={ref} onPress={onPress} {...props} />;
|
|
193
|
+
});
|
|
194
|
+
|
|
195
|
+
Overlay.displayName = 'HoverCardOverlay';
|
|
196
|
+
|
|
197
|
+
// ---------------------------------------------------------------------------
|
|
198
|
+
// Content
|
|
199
|
+
// ---------------------------------------------------------------------------
|
|
200
|
+
|
|
201
|
+
const Content = React.forwardRef<View, ContentProps>(function Content(
|
|
202
|
+
{
|
|
203
|
+
asChild,
|
|
204
|
+
forceMount,
|
|
205
|
+
align = 'start',
|
|
206
|
+
side = 'bottom',
|
|
207
|
+
sideOffset = 0,
|
|
208
|
+
alignOffset = 0,
|
|
209
|
+
avoidCollisions = true,
|
|
210
|
+
insets,
|
|
211
|
+
style,
|
|
212
|
+
disablePositioningStyle,
|
|
213
|
+
onLayout: onLayoutProp,
|
|
214
|
+
...props
|
|
215
|
+
},
|
|
216
|
+
ref
|
|
217
|
+
) {
|
|
218
|
+
const { open, triggerPosition, contentLayout, setContentLayout } = useRootContext();
|
|
219
|
+
const { nativeID } = useInternalContext();
|
|
220
|
+
|
|
221
|
+
const positionStyle = useRelativePosition({
|
|
222
|
+
align,
|
|
223
|
+
avoidCollisions,
|
|
224
|
+
triggerPosition,
|
|
225
|
+
contentLayout,
|
|
226
|
+
alignOffset,
|
|
227
|
+
insets,
|
|
228
|
+
sideOffset,
|
|
229
|
+
side,
|
|
230
|
+
disablePositioningStyle,
|
|
231
|
+
});
|
|
232
|
+
|
|
233
|
+
const onLayout = React.useCallback(
|
|
234
|
+
(event: LayoutChangeEvent) => {
|
|
235
|
+
setContentLayout(event.nativeEvent.layout);
|
|
236
|
+
onLayoutProp?.(event);
|
|
237
|
+
},
|
|
238
|
+
[onLayoutProp, setContentLayout]
|
|
239
|
+
);
|
|
240
|
+
|
|
241
|
+
if (!forceMount && !open) {
|
|
242
|
+
return null;
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
const Component = asChild ? Slot : View;
|
|
246
|
+
|
|
247
|
+
return (
|
|
248
|
+
<Component
|
|
249
|
+
ref={ref}
|
|
250
|
+
nativeID={nativeID}
|
|
251
|
+
style={[positionStyle, style]}
|
|
252
|
+
onLayout={onLayout}
|
|
253
|
+
{...props}
|
|
254
|
+
/>
|
|
255
|
+
);
|
|
256
|
+
});
|
|
257
|
+
|
|
258
|
+
Content.displayName = 'HoverCardContent';
|
|
259
|
+
|
|
260
|
+
// ---------------------------------------------------------------------------
|
|
261
|
+
// Exports
|
|
262
|
+
// ---------------------------------------------------------------------------
|
|
263
|
+
|
|
264
|
+
export {
|
|
265
|
+
Content,
|
|
266
|
+
Overlay,
|
|
267
|
+
Portal,
|
|
268
|
+
Root,
|
|
269
|
+
Trigger,
|
|
270
|
+
useRootContext,
|
|
271
|
+
};
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
ForceMountable,
|
|
3
|
+
PositionedContentProps,
|
|
4
|
+
SlottablePressableProps,
|
|
5
|
+
SlottableViewProps,
|
|
6
|
+
} from '../types';
|
|
7
|
+
|
|
8
|
+
interface RootProps {
|
|
9
|
+
open?: boolean;
|
|
10
|
+
defaultOpen?: boolean;
|
|
11
|
+
onOpenChange?: (open: boolean) => void;
|
|
12
|
+
openDelay?: number;
|
|
13
|
+
closeDelay?: number;
|
|
14
|
+
children?: React.ReactNode;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
interface TriggerProps extends SlottablePressableProps {}
|
|
18
|
+
|
|
19
|
+
interface PortalProps extends ForceMountable {
|
|
20
|
+
hostName?: string;
|
|
21
|
+
children?: React.ReactNode;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
interface OverlayProps extends SlottablePressableProps, ForceMountable {
|
|
25
|
+
closeOnPress?: boolean;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
interface ContentProps extends SlottableViewProps, PositionedContentProps {}
|
|
29
|
+
|
|
30
|
+
interface RootContext {
|
|
31
|
+
open: boolean;
|
|
32
|
+
onOpenChange: (open: boolean) => void;
|
|
33
|
+
triggerPosition: LayoutPosition | null;
|
|
34
|
+
setTriggerPosition: (position: LayoutPosition | null) => void;
|
|
35
|
+
contentLayout: LayoutRectangle | null;
|
|
36
|
+
setContentLayout: (layout: LayoutRectangle | null) => void;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// Re-export from hooks for convenience
|
|
40
|
+
import type { LayoutPosition } from '../hooks';
|
|
41
|
+
import type { LayoutRectangle } from 'react-native';
|
|
42
|
+
|
|
43
|
+
export type {
|
|
44
|
+
ContentProps,
|
|
45
|
+
OverlayProps,
|
|
46
|
+
PortalProps,
|
|
47
|
+
RootContext,
|
|
48
|
+
RootProps,
|
|
49
|
+
TriggerProps,
|
|
50
|
+
};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { Image as RNImage } from 'react-native';
|
|
3
|
+
import type { ImageRootProps, ContentFit } from './types';
|
|
4
|
+
|
|
5
|
+
const contentFitToResizeMode: Record<ContentFit, string> = {
|
|
6
|
+
cover: 'cover',
|
|
7
|
+
contain: 'contain',
|
|
8
|
+
fill: 'stretch',
|
|
9
|
+
none: 'center',
|
|
10
|
+
'scale-down': 'contain',
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
export const Root = React.forwardRef<RNImage, ImageRootProps>(
|
|
14
|
+
({ source, alt, placeholder, contentFit = 'cover', style, ...props }, ref) => {
|
|
15
|
+
return (
|
|
16
|
+
<RNImage
|
|
17
|
+
ref={ref}
|
|
18
|
+
source={source}
|
|
19
|
+
accessibilityLabel={alt}
|
|
20
|
+
alt={alt}
|
|
21
|
+
resizeMode={contentFitToResizeMode[contentFit] as any}
|
|
22
|
+
defaultSource={placeholder as any}
|
|
23
|
+
style={style}
|
|
24
|
+
{...props}
|
|
25
|
+
/>
|
|
26
|
+
);
|
|
27
|
+
}
|
|
28
|
+
);
|
|
29
|
+
Root.displayName = 'ImageRoot';
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { ImageProps as RNImageProps, ImageSourcePropType } from 'react-native';
|
|
2
|
+
|
|
3
|
+
export type ContentFit = 'cover' | 'contain' | 'fill' | 'none' | 'scale-down';
|
|
4
|
+
|
|
5
|
+
export interface ImageRootProps extends Omit<RNImageProps, 'resizeMode'> {
|
|
6
|
+
source: ImageSourcePropType;
|
|
7
|
+
alt?: string;
|
|
8
|
+
placeholder?: ImageSourcePropType;
|
|
9
|
+
contentFit?: ContentFit;
|
|
10
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/// <reference path="./uniwind-env.d.ts" />
|
|
2
|
+
// @tallyui/primitives
|
|
3
|
+
// Headless, accessible, cross-platform UI primitives
|
|
4
|
+
|
|
5
|
+
export * from './types';
|
|
6
|
+
export { Slot, composeRefs, mergeProps } from './slot';
|
|
7
|
+
export { useControllableState, useAugmentedRef, useRelativePosition } from './hooks';
|
|
8
|
+
export type { LayoutPosition } from './hooks';
|
|
9
|
+
export { Portal, PortalHost } from './portal';
|
|
10
|
+
export { toggleGroupUtils, EmptyGestureResponderEvent } from './utils';
|
|
11
|
+
export * as Animated from './animated';
|
|
12
|
+
export * as AlertDialog from './alert-dialog';
|
|
13
|
+
export * as Dialog from './dialog';
|
|
14
|
+
export * as Popover from './popover';
|
|
15
|
+
export * as Select from './select';
|
|
16
|
+
export * as Tabs from './tabs';
|
|
17
|
+
export * as ContextMenu from './context-menu';
|
|
18
|
+
export * as DropdownMenu from './dropdown-menu';
|
|
19
|
+
export * as List from './list';
|
|
20
|
+
export * as Image from './image';
|
|
21
|
+
export * as Label from './label';
|
|
22
|
+
export * as Separator from './separator';
|
|
23
|
+
export * as Combobox from './combobox';
|
|
24
|
+
export * as Checkbox from './checkbox';
|
|
25
|
+
export * as Switch from './switch';
|
|
26
|
+
export * as Progress from './progress';
|
|
27
|
+
export * as Toggle from './toggle';
|
|
28
|
+
export * as RadioGroup from './radio-group';
|
|
29
|
+
export * as ToggleGroup from './toggle-group';
|
|
30
|
+
export * as Collapsible from './collapsible';
|
|
31
|
+
export * as Accordion from './accordion';
|
|
32
|
+
export * as Slider from './slider';
|
|
33
|
+
export * as Toast from './toast';
|
|
34
|
+
export * as Tooltip from './tooltip';
|
|
35
|
+
export * as HoverCard from './hover-card';
|
|
36
|
+
export * as Table from './table';
|
|
37
|
+
export * as Text from './text';
|
|
38
|
+
export { TextClassContext } from './text';
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { Text } from 'react-native';
|
|
3
|
+
import { Slot } from '../slot';
|
|
4
|
+
import type { RootContext as RootContextType, RootProps } from './types';
|
|
5
|
+
|
|
6
|
+
// ---------------------------------------------------------------------------
|
|
7
|
+
// Context
|
|
8
|
+
// ---------------------------------------------------------------------------
|
|
9
|
+
|
|
10
|
+
const RootContext = React.createContext<RootContextType | null>(null);
|
|
11
|
+
|
|
12
|
+
function useRootContext(): RootContextType {
|
|
13
|
+
const context = React.useContext(RootContext);
|
|
14
|
+
if (!context) {
|
|
15
|
+
throw new Error(
|
|
16
|
+
'Label compound components cannot be rendered outside the Label.Root component'
|
|
17
|
+
);
|
|
18
|
+
}
|
|
19
|
+
return context;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
// ---------------------------------------------------------------------------
|
|
23
|
+
// Root
|
|
24
|
+
// ---------------------------------------------------------------------------
|
|
25
|
+
|
|
26
|
+
const Root = React.forwardRef<Text, RootProps>(function Root(
|
|
27
|
+
{ asChild, nativeID, ...props },
|
|
28
|
+
ref
|
|
29
|
+
) {
|
|
30
|
+
const Component = asChild ? Slot : Text;
|
|
31
|
+
|
|
32
|
+
return (
|
|
33
|
+
<RootContext.Provider value={{ nativeID }}>
|
|
34
|
+
<Component ref={ref} nativeID={nativeID} {...props} />
|
|
35
|
+
</RootContext.Provider>
|
|
36
|
+
);
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
Root.displayName = 'LabelRoot';
|
|
40
|
+
|
|
41
|
+
// ---------------------------------------------------------------------------
|
|
42
|
+
// Exports
|
|
43
|
+
// ---------------------------------------------------------------------------
|
|
44
|
+
|
|
45
|
+
export { Root, useRootContext };
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { FlatList, View } from 'react-native';
|
|
3
|
+
import type { ListRootProps, ListItemProps } from './types';
|
|
4
|
+
|
|
5
|
+
const ItemContext = React.createContext<{ item: unknown; index: number } | null>(null);
|
|
6
|
+
|
|
7
|
+
export function useItemContext() {
|
|
8
|
+
const context = React.useContext(ItemContext);
|
|
9
|
+
if (!context) {
|
|
10
|
+
throw new Error('useItemContext must be used within a List.Item');
|
|
11
|
+
}
|
|
12
|
+
return context;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
function RootInner<T>(
|
|
16
|
+
{ data, renderItem, keyExtractor, estimatedItemSize, ...props }: ListRootProps<T>,
|
|
17
|
+
ref: React.Ref<FlatList<T>>
|
|
18
|
+
) {
|
|
19
|
+
return (
|
|
20
|
+
<FlatList
|
|
21
|
+
ref={ref}
|
|
22
|
+
data={data}
|
|
23
|
+
keyExtractor={keyExtractor}
|
|
24
|
+
getItemLayout={
|
|
25
|
+
estimatedItemSize
|
|
26
|
+
? (_, index) => ({
|
|
27
|
+
length: estimatedItemSize,
|
|
28
|
+
offset: estimatedItemSize * index,
|
|
29
|
+
index,
|
|
30
|
+
})
|
|
31
|
+
: undefined
|
|
32
|
+
}
|
|
33
|
+
renderItem={({ item, index }) => (
|
|
34
|
+
<ItemContext.Provider value={{ item, index }}>
|
|
35
|
+
{renderItem({ item, index })}
|
|
36
|
+
</ItemContext.Provider>
|
|
37
|
+
)}
|
|
38
|
+
{...props}
|
|
39
|
+
/>
|
|
40
|
+
);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export const Root = React.forwardRef(RootInner) as <T>(
|
|
44
|
+
props: ListRootProps<T> & { ref?: React.Ref<FlatList<T>> }
|
|
45
|
+
) => React.ReactElement | null;
|
|
46
|
+
|
|
47
|
+
export const Item = React.forwardRef<View, ListItemProps>(
|
|
48
|
+
({ children, ...props }, ref) => (
|
|
49
|
+
<View ref={ref} {...props}>
|
|
50
|
+
{children}
|
|
51
|
+
</View>
|
|
52
|
+
)
|
|
53
|
+
);
|
|
54
|
+
Item.displayName = 'ListItem';
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { FlatListProps, ViewProps } from 'react-native';
|
|
2
|
+
|
|
3
|
+
interface ListRootProps<T> extends Omit<FlatListProps<T>, 'renderItem'> {
|
|
4
|
+
data: T[];
|
|
5
|
+
renderItem: (info: { item: T; index: number }) => React.ReactElement;
|
|
6
|
+
estimatedItemSize?: number;
|
|
7
|
+
keyExtractor?: (item: T, index: number) => string;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
interface ListItemProps extends ViewProps {
|
|
11
|
+
children?: React.ReactNode;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export type { ListRootProps, ListItemProps };
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export {
|
|
2
|
+
Root,
|
|
3
|
+
Trigger,
|
|
4
|
+
Portal,
|
|
5
|
+
Overlay,
|
|
6
|
+
Content,
|
|
7
|
+
Close,
|
|
8
|
+
useRootContext,
|
|
9
|
+
} from './popover';
|
|
10
|
+
|
|
11
|
+
export type {
|
|
12
|
+
RootProps,
|
|
13
|
+
TriggerProps,
|
|
14
|
+
PortalProps,
|
|
15
|
+
OverlayProps,
|
|
16
|
+
ContentProps,
|
|
17
|
+
CloseProps,
|
|
18
|
+
RootContext,
|
|
19
|
+
} from './types';
|