@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,272 @@
|
|
|
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
|
+
'Tooltip compound components cannot be rendered outside the Tooltip.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
|
+
'Tooltip compound components cannot be rendered outside the Tooltip.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 = 'TooltipRoot';
|
|
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 = 'TooltipTrigger';
|
|
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 = 'TooltipPortal';
|
|
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 = 'TooltipOverlay';
|
|
196
|
+
|
|
197
|
+
// ---------------------------------------------------------------------------
|
|
198
|
+
// Content
|
|
199
|
+
// ---------------------------------------------------------------------------
|
|
200
|
+
|
|
201
|
+
const Content = React.forwardRef<View, ContentProps>(function Content(
|
|
202
|
+
{
|
|
203
|
+
asChild,
|
|
204
|
+
forceMount,
|
|
205
|
+
align = 'center',
|
|
206
|
+
side = 'top',
|
|
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
|
+
role="tooltip"
|
|
251
|
+
nativeID={nativeID}
|
|
252
|
+
style={[positionStyle, style]}
|
|
253
|
+
onLayout={onLayout}
|
|
254
|
+
{...props}
|
|
255
|
+
/>
|
|
256
|
+
);
|
|
257
|
+
});
|
|
258
|
+
|
|
259
|
+
Content.displayName = 'TooltipContent';
|
|
260
|
+
|
|
261
|
+
// ---------------------------------------------------------------------------
|
|
262
|
+
// Exports
|
|
263
|
+
// ---------------------------------------------------------------------------
|
|
264
|
+
|
|
265
|
+
export {
|
|
266
|
+
Content,
|
|
267
|
+
Overlay,
|
|
268
|
+
Portal,
|
|
269
|
+
Root,
|
|
270
|
+
Trigger,
|
|
271
|
+
useRootContext,
|
|
272
|
+
};
|
|
@@ -0,0 +1,49 @@
|
|
|
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
|
+
delayDuration?: number;
|
|
13
|
+
children?: React.ReactNode;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
interface TriggerProps extends SlottablePressableProps {}
|
|
17
|
+
|
|
18
|
+
interface PortalProps extends ForceMountable {
|
|
19
|
+
hostName?: string;
|
|
20
|
+
children?: React.ReactNode;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
interface OverlayProps extends SlottablePressableProps, ForceMountable {
|
|
24
|
+
closeOnPress?: boolean;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
interface ContentProps extends SlottableViewProps, PositionedContentProps {}
|
|
28
|
+
|
|
29
|
+
interface RootContext {
|
|
30
|
+
open: boolean;
|
|
31
|
+
onOpenChange: (open: boolean) => void;
|
|
32
|
+
triggerPosition: LayoutPosition | null;
|
|
33
|
+
setTriggerPosition: (position: LayoutPosition | null) => void;
|
|
34
|
+
contentLayout: LayoutRectangle | null;
|
|
35
|
+
setContentLayout: (layout: LayoutRectangle | null) => void;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// Re-export from hooks for convenience
|
|
39
|
+
import type { LayoutPosition } from '../hooks';
|
|
40
|
+
import type { LayoutRectangle } from 'react-native';
|
|
41
|
+
|
|
42
|
+
export type {
|
|
43
|
+
ContentProps,
|
|
44
|
+
OverlayProps,
|
|
45
|
+
PortalProps,
|
|
46
|
+
RootContext,
|
|
47
|
+
RootProps,
|
|
48
|
+
TriggerProps,
|
|
49
|
+
};
|
package/src/types.ts
ADDED
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
Image,
|
|
3
|
+
ImageProps,
|
|
4
|
+
PressableProps,
|
|
5
|
+
Text,
|
|
6
|
+
TextProps,
|
|
7
|
+
View,
|
|
8
|
+
ViewProps,
|
|
9
|
+
ViewStyle,
|
|
10
|
+
} from 'react-native';
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Flattens intersection types into a single object type for better
|
|
14
|
+
* readability in IDE tooltips and error messages.
|
|
15
|
+
*/
|
|
16
|
+
type Prettify<T> = {
|
|
17
|
+
[K in keyof T]: T[K];
|
|
18
|
+
} & {};
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Adds the `asChild` prop to any type. When true, the component merges
|
|
22
|
+
* its props onto its single child element instead of rendering a wrapper.
|
|
23
|
+
*/
|
|
24
|
+
type Slottable<T> = Prettify<T & { asChild?: boolean | undefined }>;
|
|
25
|
+
|
|
26
|
+
// ---------------------------------------------------------------------------
|
|
27
|
+
// Slottable prop types — extend RN props with asChild + ref
|
|
28
|
+
// ---------------------------------------------------------------------------
|
|
29
|
+
|
|
30
|
+
type SlottableViewProps = Slottable<ViewProps> & { ref?: ViewRef };
|
|
31
|
+
|
|
32
|
+
type SlottablePressableProps = Slottable<PressableProps> & {
|
|
33
|
+
ref?: PressableRef;
|
|
34
|
+
/** Platform: WEB ONLY */
|
|
35
|
+
onKeyDown?: (ev: React.KeyboardEvent) => void;
|
|
36
|
+
/** Platform: WEB ONLY */
|
|
37
|
+
onKeyUp?: (ev: React.KeyboardEvent) => void;
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
type SlottableTextProps = Slottable<TextProps> & { ref?: TextRef };
|
|
41
|
+
|
|
42
|
+
type SlottableImageProps = Slottable<ImageProps> & { ref?: ImageRef };
|
|
43
|
+
|
|
44
|
+
// ---------------------------------------------------------------------------
|
|
45
|
+
// Ref types
|
|
46
|
+
// ---------------------------------------------------------------------------
|
|
47
|
+
|
|
48
|
+
type ViewRef = React.RefObject<View | null>;
|
|
49
|
+
type PressableRef = React.RefObject<View | null>;
|
|
50
|
+
type TextRef = React.RefObject<Text | null>;
|
|
51
|
+
type ImageRef = React.RefObject<Image | null>;
|
|
52
|
+
|
|
53
|
+
// ---------------------------------------------------------------------------
|
|
54
|
+
// Positioning & layout
|
|
55
|
+
// ---------------------------------------------------------------------------
|
|
56
|
+
|
|
57
|
+
interface Insets {
|
|
58
|
+
top?: number;
|
|
59
|
+
bottom?: number;
|
|
60
|
+
left?: number;
|
|
61
|
+
right?: number;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
type PointerDownOutsideEvent = CustomEvent<{ originalEvent: PointerEvent }>;
|
|
65
|
+
type FocusOutsideEvent = CustomEvent<{ originalEvent: FocusEvent }>;
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Props shared by positioned overlay content (popovers, dropdown menus,
|
|
69
|
+
* selects, etc.) that need to anchor relative to a trigger.
|
|
70
|
+
*/
|
|
71
|
+
interface PositionedContentProps {
|
|
72
|
+
forceMount?: true | undefined;
|
|
73
|
+
alignOffset?: number;
|
|
74
|
+
insets?: Insets;
|
|
75
|
+
avoidCollisions?: boolean;
|
|
76
|
+
align?: 'start' | 'center' | 'end';
|
|
77
|
+
side?: 'top' | 'bottom';
|
|
78
|
+
sideOffset?: number;
|
|
79
|
+
/** Platform: NATIVE ONLY */
|
|
80
|
+
disablePositioningStyle?: boolean;
|
|
81
|
+
/** Platform: WEB ONLY */
|
|
82
|
+
loop?: boolean;
|
|
83
|
+
/** Platform: WEB ONLY */
|
|
84
|
+
onCloseAutoFocus?: (event: Event) => void;
|
|
85
|
+
/** Platform: WEB ONLY */
|
|
86
|
+
onEscapeKeyDown?: (event: KeyboardEvent) => void;
|
|
87
|
+
/** Platform: WEB ONLY */
|
|
88
|
+
onPointerDownOutside?: (event: PointerDownOutsideEvent) => void;
|
|
89
|
+
/** Platform: WEB ONLY */
|
|
90
|
+
onFocusOutside?: (event: FocusOutsideEvent) => void;
|
|
91
|
+
/** Platform: WEB ONLY */
|
|
92
|
+
onInteractOutside?: (event: PointerDownOutsideEvent | FocusOutsideEvent) => void;
|
|
93
|
+
/** Platform: WEB ONLY */
|
|
94
|
+
collisionBoundary?: Element | null | Array<Element | null>;
|
|
95
|
+
/** Platform: WEB ONLY */
|
|
96
|
+
sticky?: 'partial' | 'always';
|
|
97
|
+
/** Platform: WEB ONLY */
|
|
98
|
+
hideWhenDetached?: boolean;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
// ---------------------------------------------------------------------------
|
|
102
|
+
// Misc
|
|
103
|
+
// ---------------------------------------------------------------------------
|
|
104
|
+
|
|
105
|
+
interface ForceMountable {
|
|
106
|
+
forceMount?: true | undefined;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
// ---------------------------------------------------------------------------
|
|
110
|
+
// Exports
|
|
111
|
+
// ---------------------------------------------------------------------------
|
|
112
|
+
|
|
113
|
+
export type {
|
|
114
|
+
FocusOutsideEvent,
|
|
115
|
+
ForceMountable,
|
|
116
|
+
ImageRef,
|
|
117
|
+
Insets,
|
|
118
|
+
PointerDownOutsideEvent,
|
|
119
|
+
PositionedContentProps,
|
|
120
|
+
PressableRef,
|
|
121
|
+
Prettify,
|
|
122
|
+
Slottable,
|
|
123
|
+
SlottableImageProps,
|
|
124
|
+
SlottablePressableProps,
|
|
125
|
+
SlottableTextProps,
|
|
126
|
+
SlottableViewProps,
|
|
127
|
+
TextRef,
|
|
128
|
+
ViewRef,
|
|
129
|
+
};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Type augmentations for React Native components to support className prop.
|
|
3
|
+
* Uniwind/NativeWind provides these at runtime — this file ensures TypeScript accepts them.
|
|
4
|
+
*/
|
|
5
|
+
import 'react-native';
|
|
6
|
+
|
|
7
|
+
declare module 'react-native' {
|
|
8
|
+
interface ViewProps {
|
|
9
|
+
className?: string;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
interface TextProps {
|
|
13
|
+
className?: string;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
interface ImagePropsBase {
|
|
17
|
+
className?: string;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
interface PressableProps {
|
|
21
|
+
className?: string;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
interface TextInputProps {
|
|
25
|
+
className?: string;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
interface ScrollViewProps {
|
|
29
|
+
contentContainerClassName?: string;
|
|
30
|
+
}
|
|
31
|
+
}
|
package/src/utils.ts
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import type { GestureResponderEvent } from 'react-native';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* State management utilities for toggle groups.
|
|
5
|
+
* Handles single-select and multi-select value toggling.
|
|
6
|
+
*/
|
|
7
|
+
export const toggleGroupUtils = {
|
|
8
|
+
getIsSelected(value: string | string[] | undefined, itemValue: string): boolean {
|
|
9
|
+
if (value === undefined) return false;
|
|
10
|
+
if (typeof value === 'string') return value === itemValue;
|
|
11
|
+
return value.includes(itemValue);
|
|
12
|
+
},
|
|
13
|
+
|
|
14
|
+
getNewSingleValue(
|
|
15
|
+
original: string | string[] | undefined,
|
|
16
|
+
itemValue: string
|
|
17
|
+
): string | undefined {
|
|
18
|
+
if (original === itemValue) return undefined;
|
|
19
|
+
return itemValue;
|
|
20
|
+
},
|
|
21
|
+
|
|
22
|
+
getNewMultipleValue(
|
|
23
|
+
original: string | string[] | undefined,
|
|
24
|
+
itemValue: string
|
|
25
|
+
): string[] {
|
|
26
|
+
if (original === undefined) return [itemValue];
|
|
27
|
+
if (typeof original === 'string') {
|
|
28
|
+
return original === itemValue ? [] : [original, itemValue];
|
|
29
|
+
}
|
|
30
|
+
if (original.includes(itemValue)) {
|
|
31
|
+
return original.filter((v) => v !== itemValue);
|
|
32
|
+
}
|
|
33
|
+
return [...original, itemValue];
|
|
34
|
+
},
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Mock GestureResponderEvent for use when synthesizing events
|
|
39
|
+
* from keyboard interactions or other non-touch sources.
|
|
40
|
+
*/
|
|
41
|
+
export const EmptyGestureResponderEvent: GestureResponderEvent = {
|
|
42
|
+
nativeEvent: {
|
|
43
|
+
changedTouches: [],
|
|
44
|
+
identifier: '0',
|
|
45
|
+
locationX: 0,
|
|
46
|
+
locationY: 0,
|
|
47
|
+
pageX: 0,
|
|
48
|
+
pageY: 0,
|
|
49
|
+
target: '0',
|
|
50
|
+
timestamp: 0,
|
|
51
|
+
touches: [],
|
|
52
|
+
},
|
|
53
|
+
bubbles: false,
|
|
54
|
+
cancelable: false,
|
|
55
|
+
currentTarget: {} as any,
|
|
56
|
+
defaultPrevented: false,
|
|
57
|
+
eventPhase: 0,
|
|
58
|
+
persist: () => {},
|
|
59
|
+
isDefaultPrevented: () => false,
|
|
60
|
+
isPropagationStopped: () => false,
|
|
61
|
+
isTrusted: false,
|
|
62
|
+
preventDefault: () => {},
|
|
63
|
+
stopPropagation: () => {},
|
|
64
|
+
target: {} as any,
|
|
65
|
+
timeStamp: 0,
|
|
66
|
+
type: '',
|
|
67
|
+
};
|