@tallyui/primitives 3.18.0 → 3.19.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 +10 -1
- package/dist/index.js +119 -9
- package/package.json +1 -1
- package/src/tooltip/tooltip.tsx +145 -9
- package/src/tooltip/types.ts +6 -1
package/dist/index.d.ts
CHANGED
|
@@ -1216,10 +1216,13 @@ interface RootProps$3 {
|
|
|
1216
1216
|
open?: boolean;
|
|
1217
1217
|
defaultOpen?: boolean;
|
|
1218
1218
|
onOpenChange?: (open: boolean) => void;
|
|
1219
|
+
/** Delay in ms between the pointer entering the trigger and the tooltip opening. Defaults to `0`. */
|
|
1219
1220
|
delayDuration?: number;
|
|
1220
1221
|
children?: React.ReactNode;
|
|
1221
1222
|
}
|
|
1222
1223
|
interface TriggerProps$1 extends SlottablePressableProps {
|
|
1224
|
+
/** Toggle the tooltip on press as well, for a trigger that does nothing else. */
|
|
1225
|
+
openOnPress?: boolean;
|
|
1223
1226
|
}
|
|
1224
1227
|
interface PortalProps$1 extends ForceMountable {
|
|
1225
1228
|
hostName?: string;
|
|
@@ -1233,6 +1236,7 @@ interface ContentProps$1 extends SlottableViewProps, PositionedContentProps {
|
|
|
1233
1236
|
interface RootContext$2 {
|
|
1234
1237
|
open: boolean;
|
|
1235
1238
|
onOpenChange: (open: boolean) => void;
|
|
1239
|
+
delayDuration: number;
|
|
1236
1240
|
triggerPosition: LayoutPosition | null;
|
|
1237
1241
|
setTriggerPosition: (position: LayoutPosition | null) => void;
|
|
1238
1242
|
contentLayout: LayoutRectangle | null;
|
|
@@ -1240,10 +1244,15 @@ interface RootContext$2 {
|
|
|
1240
1244
|
}
|
|
1241
1245
|
|
|
1242
1246
|
declare function useRootContext$2(): RootContext$2;
|
|
1243
|
-
declare function Root$3({ open: openProp, defaultOpen, onOpenChange: onOpenChangeProp, children }: RootProps$3): react_jsx_runtime.JSX.Element;
|
|
1247
|
+
declare function Root$3({ open: openProp, defaultOpen, onOpenChange: onOpenChangeProp, delayDuration, children, }: RootProps$3): react_jsx_runtime.JSX.Element;
|
|
1244
1248
|
declare namespace Root$3 {
|
|
1245
1249
|
var displayName: string;
|
|
1246
1250
|
}
|
|
1251
|
+
/**
|
|
1252
|
+
* Opens on hover (after `delayDuration`) and on focus no press caused; closes on leave and blur.
|
|
1253
|
+
* A press only closes it unless `openOnPress` is set, which touch (no hover) needs to open it.
|
|
1254
|
+
* `onLongPress` is left to the caller: binding it makes react-native-web drop a slow press.
|
|
1255
|
+
*/
|
|
1247
1256
|
declare const Trigger$1: React$1.ForwardRefExoticComponent<Omit<TriggerProps$1, "ref"> & React$1.RefAttributes<View>>;
|
|
1248
1257
|
declare function Portal$1({ forceMount, hostName, children }: PortalProps$1): react_jsx_runtime.JSX.Element | null;
|
|
1249
1258
|
declare namespace Portal$1 {
|
package/dist/index.js
CHANGED
|
@@ -3604,7 +3604,13 @@ function useRootContext19() {
|
|
|
3604
3604
|
}
|
|
3605
3605
|
return context;
|
|
3606
3606
|
}
|
|
3607
|
-
function Root35({
|
|
3607
|
+
function Root35({
|
|
3608
|
+
open: openProp,
|
|
3609
|
+
defaultOpen,
|
|
3610
|
+
onOpenChange: onOpenChangeProp,
|
|
3611
|
+
delayDuration = 0,
|
|
3612
|
+
children
|
|
3613
|
+
}) {
|
|
3608
3614
|
const nativeID = React28.useId();
|
|
3609
3615
|
const [open = false, onOpenChange] = useControllableState({
|
|
3610
3616
|
prop: openProp,
|
|
@@ -3619,6 +3625,7 @@ function Root35({ open: openProp, defaultOpen, onOpenChange: onOpenChangeProp, c
|
|
|
3619
3625
|
value: {
|
|
3620
3626
|
open,
|
|
3621
3627
|
onOpenChange,
|
|
3628
|
+
delayDuration,
|
|
3622
3629
|
triggerPosition,
|
|
3623
3630
|
setTriggerPosition,
|
|
3624
3631
|
contentLayout,
|
|
@@ -3629,8 +3636,27 @@ function Root35({ open: openProp, defaultOpen, onOpenChange: onOpenChangeProp, c
|
|
|
3629
3636
|
) });
|
|
3630
3637
|
}
|
|
3631
3638
|
Root35.displayName = "TooltipRoot";
|
|
3632
|
-
var Trigger21 = React28.forwardRef(function Trigger22({
|
|
3633
|
-
|
|
3639
|
+
var Trigger21 = React28.forwardRef(function Trigger22({
|
|
3640
|
+
asChild,
|
|
3641
|
+
openOnPress = false,
|
|
3642
|
+
onPress: onPressProp,
|
|
3643
|
+
onPressOut: onPressOutProp,
|
|
3644
|
+
onPointerDown: onPointerDownProp,
|
|
3645
|
+
onPointerUp: onPointerUpProp,
|
|
3646
|
+
onHoverIn: onHoverInProp,
|
|
3647
|
+
onHoverOut: onHoverOutProp,
|
|
3648
|
+
onFocus: onFocusProp,
|
|
3649
|
+
onBlur: onBlurProp,
|
|
3650
|
+
disabled,
|
|
3651
|
+
...props
|
|
3652
|
+
}, ref) {
|
|
3653
|
+
const { open, onOpenChange, delayDuration, setTriggerPosition } = useRootContext19();
|
|
3654
|
+
const delayTimer = React28.useRef(null);
|
|
3655
|
+
const clearDelay = React28.useCallback(() => {
|
|
3656
|
+
if (delayTimer.current !== null) clearTimeout(delayTimer.current);
|
|
3657
|
+
delayTimer.current = null;
|
|
3658
|
+
}, []);
|
|
3659
|
+
React28.useEffect(() => clearDelay, [clearDelay]);
|
|
3634
3660
|
const augmentedRef = useAugmentedRef({
|
|
3635
3661
|
ref,
|
|
3636
3662
|
methods: {
|
|
@@ -3646,16 +3672,93 @@ var Trigger21 = React28.forwardRef(function Trigger22({ asChild, onPress: onPres
|
|
|
3646
3672
|
}
|
|
3647
3673
|
}
|
|
3648
3674
|
});
|
|
3675
|
+
const show = React28.useCallback(() => {
|
|
3676
|
+
clearDelay();
|
|
3677
|
+
if (disabled) return;
|
|
3678
|
+
augmentedRef.current?.measure?.((_x, _y, width, height, pageX, pageY) => {
|
|
3679
|
+
setTriggerPosition({ width, pageX, pageY, height });
|
|
3680
|
+
});
|
|
3681
|
+
onOpenChange(true);
|
|
3682
|
+
}, [augmentedRef, clearDelay, disabled, onOpenChange, setTriggerPosition]);
|
|
3683
|
+
const hide = React28.useCallback(() => {
|
|
3684
|
+
if (!open) return;
|
|
3685
|
+
setTriggerPosition(null);
|
|
3686
|
+
onOpenChange(false);
|
|
3687
|
+
}, [onOpenChange, open, setTriggerPosition]);
|
|
3688
|
+
const handleHoverIn = (ev) => {
|
|
3689
|
+
clearDelay();
|
|
3690
|
+
if (delayDuration > 0) {
|
|
3691
|
+
delayTimer.current = setTimeout(show, delayDuration);
|
|
3692
|
+
} else {
|
|
3693
|
+
show();
|
|
3694
|
+
}
|
|
3695
|
+
onHoverInProp?.(ev);
|
|
3696
|
+
};
|
|
3697
|
+
const handleHoverOut = (ev) => {
|
|
3698
|
+
clearDelay();
|
|
3699
|
+
hide();
|
|
3700
|
+
onHoverOutProp?.(ev);
|
|
3701
|
+
};
|
|
3702
|
+
const hoverHandlers = React28.useRef({ handleHoverIn, handleHoverOut });
|
|
3703
|
+
React28.useLayoutEffect(() => {
|
|
3704
|
+
hoverHandlers.current = { handleHoverIn, handleHoverOut };
|
|
3705
|
+
});
|
|
3706
|
+
const onHoverIn = React28.useCallback(
|
|
3707
|
+
(ev) => hoverHandlers.current.handleHoverIn(ev),
|
|
3708
|
+
[]
|
|
3709
|
+
);
|
|
3710
|
+
const onHoverOut = React28.useCallback(
|
|
3711
|
+
(ev) => hoverHandlers.current.handleHoverOut(ev),
|
|
3712
|
+
[]
|
|
3713
|
+
);
|
|
3714
|
+
const pressing = React28.useRef(false);
|
|
3715
|
+
const onPointerDown = React28.useCallback(
|
|
3716
|
+
(ev) => {
|
|
3717
|
+
pressing.current = true;
|
|
3718
|
+
onPointerDownProp?.(ev);
|
|
3719
|
+
},
|
|
3720
|
+
[onPointerDownProp]
|
|
3721
|
+
);
|
|
3722
|
+
const onPointerUp = React28.useCallback(
|
|
3723
|
+
(ev) => {
|
|
3724
|
+
pressing.current = false;
|
|
3725
|
+
onPointerUpProp?.(ev);
|
|
3726
|
+
},
|
|
3727
|
+
[onPointerUpProp]
|
|
3728
|
+
);
|
|
3729
|
+
const onPressOut = React28.useCallback(
|
|
3730
|
+
(ev) => {
|
|
3731
|
+
pressing.current = false;
|
|
3732
|
+
onPressOutProp?.(ev);
|
|
3733
|
+
},
|
|
3734
|
+
[onPressOutProp]
|
|
3735
|
+
);
|
|
3736
|
+
const onFocus = React28.useCallback(
|
|
3737
|
+
(ev) => {
|
|
3738
|
+
if (!pressing.current) show();
|
|
3739
|
+
onFocusProp?.(ev);
|
|
3740
|
+
},
|
|
3741
|
+
[onFocusProp, show]
|
|
3742
|
+
);
|
|
3743
|
+
const onBlur = React28.useCallback(
|
|
3744
|
+
(ev) => {
|
|
3745
|
+
pressing.current = false;
|
|
3746
|
+
hide();
|
|
3747
|
+
onBlurProp?.(ev);
|
|
3748
|
+
},
|
|
3749
|
+
[hide, onBlurProp]
|
|
3750
|
+
);
|
|
3649
3751
|
const onPress = React28.useCallback(
|
|
3650
3752
|
(ev) => {
|
|
3651
|
-
|
|
3652
|
-
|
|
3653
|
-
|
|
3654
|
-
}
|
|
3655
|
-
|
|
3753
|
+
clearDelay();
|
|
3754
|
+
if (openOnPress && !open) {
|
|
3755
|
+
show();
|
|
3756
|
+
} else {
|
|
3757
|
+
hide();
|
|
3758
|
+
}
|
|
3656
3759
|
onPressProp?.(ev);
|
|
3657
3760
|
},
|
|
3658
|
-
[
|
|
3761
|
+
[clearDelay, hide, onPressProp, open, openOnPress, show]
|
|
3659
3762
|
);
|
|
3660
3763
|
const Component = asChild ? Slot : Pressable18;
|
|
3661
3764
|
return /* @__PURE__ */ jsx26(
|
|
@@ -3665,6 +3768,13 @@ var Trigger21 = React28.forwardRef(function Trigger22({ asChild, onPress: onPres
|
|
|
3665
3768
|
role: "button",
|
|
3666
3769
|
"aria-disabled": disabled || void 0,
|
|
3667
3770
|
onPress,
|
|
3771
|
+
onPressOut,
|
|
3772
|
+
onPointerDown,
|
|
3773
|
+
onPointerUp,
|
|
3774
|
+
onHoverIn,
|
|
3775
|
+
onHoverOut,
|
|
3776
|
+
onFocus,
|
|
3777
|
+
onBlur,
|
|
3668
3778
|
disabled: disabled || void 0,
|
|
3669
3779
|
...props
|
|
3670
3780
|
}
|
package/package.json
CHANGED
package/src/tooltip/tooltip.tsx
CHANGED
|
@@ -54,7 +54,13 @@ function useRootContext(): RootContextType {
|
|
|
54
54
|
// Root
|
|
55
55
|
// ---------------------------------------------------------------------------
|
|
56
56
|
|
|
57
|
-
function Root({
|
|
57
|
+
function Root({
|
|
58
|
+
open: openProp,
|
|
59
|
+
defaultOpen,
|
|
60
|
+
onOpenChange: onOpenChangeProp,
|
|
61
|
+
delayDuration = 0,
|
|
62
|
+
children,
|
|
63
|
+
}: RootProps) {
|
|
58
64
|
const nativeID = React.useId();
|
|
59
65
|
const [open = false, onOpenChange] = useControllableState({
|
|
60
66
|
prop: openProp,
|
|
@@ -70,6 +76,7 @@ function Root({ open: openProp, defaultOpen, onOpenChange: onOpenChangeProp, chi
|
|
|
70
76
|
value={{
|
|
71
77
|
open,
|
|
72
78
|
onOpenChange,
|
|
79
|
+
delayDuration,
|
|
73
80
|
triggerPosition,
|
|
74
81
|
setTriggerPosition,
|
|
75
82
|
contentLayout,
|
|
@@ -88,11 +95,41 @@ Root.displayName = 'TooltipRoot';
|
|
|
88
95
|
// Trigger
|
|
89
96
|
// ---------------------------------------------------------------------------
|
|
90
97
|
|
|
98
|
+
type HandlerEvent<K extends keyof TriggerProps> =
|
|
99
|
+
Parameters<Extract<TriggerProps[K], (...args: never[]) => unknown>>[0];
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* Opens on hover (after `delayDuration`) and on focus no press caused; closes on leave and blur.
|
|
103
|
+
* A press only closes it unless `openOnPress` is set, which touch (no hover) needs to open it.
|
|
104
|
+
* `onLongPress` is left to the caller: binding it makes react-native-web drop a slow press.
|
|
105
|
+
*/
|
|
91
106
|
const Trigger = React.forwardRef<View, TriggerProps>(function Trigger(
|
|
92
|
-
{
|
|
107
|
+
{
|
|
108
|
+
asChild,
|
|
109
|
+
openOnPress = false,
|
|
110
|
+
onPress: onPressProp,
|
|
111
|
+
onPressOut: onPressOutProp,
|
|
112
|
+
onPointerDown: onPointerDownProp,
|
|
113
|
+
onPointerUp: onPointerUpProp,
|
|
114
|
+
onHoverIn: onHoverInProp,
|
|
115
|
+
onHoverOut: onHoverOutProp,
|
|
116
|
+
onFocus: onFocusProp,
|
|
117
|
+
onBlur: onBlurProp,
|
|
118
|
+
disabled,
|
|
119
|
+
...props
|
|
120
|
+
},
|
|
93
121
|
ref
|
|
94
122
|
) {
|
|
95
|
-
const { open, onOpenChange, setTriggerPosition } = useRootContext();
|
|
123
|
+
const { open, onOpenChange, delayDuration, setTriggerPosition } = useRootContext();
|
|
124
|
+
const delayTimer = React.useRef<ReturnType<typeof setTimeout> | null>(null);
|
|
125
|
+
|
|
126
|
+
const clearDelay = React.useCallback(() => {
|
|
127
|
+
if (delayTimer.current !== null) clearTimeout(delayTimer.current);
|
|
128
|
+
delayTimer.current = null;
|
|
129
|
+
}, []);
|
|
130
|
+
|
|
131
|
+
// A hover delay still pending at unmount must not open, or report opening, a gone tooltip.
|
|
132
|
+
React.useEffect(() => clearDelay, [clearDelay]);
|
|
96
133
|
|
|
97
134
|
const augmentedRef = useAugmentedRef<View>({
|
|
98
135
|
ref,
|
|
@@ -110,16 +147,108 @@ const Trigger = React.forwardRef<View, TriggerProps>(function Trigger(
|
|
|
110
147
|
},
|
|
111
148
|
});
|
|
112
149
|
|
|
150
|
+
const show = React.useCallback(() => {
|
|
151
|
+
clearDelay();
|
|
152
|
+
if (disabled) return;
|
|
153
|
+
augmentedRef.current?.measure?.((_x, _y, width, height, pageX, pageY) => {
|
|
154
|
+
setTriggerPosition({ width, pageX, pageY, height });
|
|
155
|
+
});
|
|
156
|
+
onOpenChange(true);
|
|
157
|
+
}, [augmentedRef, clearDelay, disabled, onOpenChange, setTriggerPosition]);
|
|
158
|
+
|
|
159
|
+
const hide = React.useCallback(() => {
|
|
160
|
+
if (!open) return;
|
|
161
|
+
setTriggerPosition(null);
|
|
162
|
+
onOpenChange(false);
|
|
163
|
+
}, [onOpenChange, open, setTriggerPosition]);
|
|
164
|
+
|
|
165
|
+
const handleHoverIn = (ev: HandlerEvent<'onHoverIn'>) => {
|
|
166
|
+
clearDelay();
|
|
167
|
+
if (delayDuration > 0) {
|
|
168
|
+
delayTimer.current = setTimeout(show, delayDuration);
|
|
169
|
+
} else {
|
|
170
|
+
show();
|
|
171
|
+
}
|
|
172
|
+
onHoverInProp?.(ev);
|
|
173
|
+
};
|
|
174
|
+
|
|
175
|
+
const handleHoverOut = (ev: HandlerEvent<'onHoverOut'>) => {
|
|
176
|
+
clearDelay();
|
|
177
|
+
hide();
|
|
178
|
+
onHoverOutProp?.(ev);
|
|
179
|
+
};
|
|
180
|
+
|
|
181
|
+
// react-native-web's Pressable binds its pointerleave listener when the hover starts, so the
|
|
182
|
+
// handlers it gets must read the latest render, not the one the hover began in (open === false).
|
|
183
|
+
const hoverHandlers = React.useRef({ handleHoverIn, handleHoverOut });
|
|
184
|
+
React.useLayoutEffect(() => {
|
|
185
|
+
hoverHandlers.current = { handleHoverIn, handleHoverOut };
|
|
186
|
+
});
|
|
187
|
+
const onHoverIn = React.useCallback(
|
|
188
|
+
(ev: HandlerEvent<'onHoverIn'>) => hoverHandlers.current.handleHoverIn(ev),
|
|
189
|
+
[]
|
|
190
|
+
);
|
|
191
|
+
const onHoverOut = React.useCallback(
|
|
192
|
+
(ev: HandlerEvent<'onHoverOut'>) => hoverHandlers.current.handleHoverOut(ev),
|
|
193
|
+
[]
|
|
194
|
+
);
|
|
195
|
+
|
|
196
|
+
// A mouse press focuses the trigger before onPressIn fires; pointerdown comes first, so mark it.
|
|
197
|
+
const pressing = React.useRef(false);
|
|
198
|
+
|
|
199
|
+
const onPointerDown = React.useCallback(
|
|
200
|
+
(ev: HandlerEvent<'onPointerDown'>) => {
|
|
201
|
+
pressing.current = true;
|
|
202
|
+
onPointerDownProp?.(ev);
|
|
203
|
+
},
|
|
204
|
+
[onPointerDownProp]
|
|
205
|
+
);
|
|
206
|
+
|
|
207
|
+
const onPointerUp = React.useCallback(
|
|
208
|
+
(ev: HandlerEvent<'onPointerUp'>) => {
|
|
209
|
+
pressing.current = false;
|
|
210
|
+
onPointerUpProp?.(ev);
|
|
211
|
+
},
|
|
212
|
+
[onPointerUpProp]
|
|
213
|
+
);
|
|
214
|
+
|
|
215
|
+
const onPressOut = React.useCallback(
|
|
216
|
+
(ev: GestureResponderEvent) => {
|
|
217
|
+
pressing.current = false;
|
|
218
|
+
onPressOutProp?.(ev);
|
|
219
|
+
},
|
|
220
|
+
[onPressOutProp]
|
|
221
|
+
);
|
|
222
|
+
|
|
223
|
+
const onFocus = React.useCallback(
|
|
224
|
+
(ev: HandlerEvent<'onFocus'>) => {
|
|
225
|
+
if (!pressing.current) show();
|
|
226
|
+
onFocusProp?.(ev);
|
|
227
|
+
},
|
|
228
|
+
[onFocusProp, show]
|
|
229
|
+
);
|
|
230
|
+
|
|
231
|
+
const onBlur = React.useCallback(
|
|
232
|
+
(ev: HandlerEvent<'onBlur'>) => {
|
|
233
|
+
pressing.current = false; // a press cancelled without pointerup or onPressOut ends here
|
|
234
|
+
hide();
|
|
235
|
+
onBlurProp?.(ev);
|
|
236
|
+
},
|
|
237
|
+
[hide, onBlurProp]
|
|
238
|
+
);
|
|
239
|
+
|
|
113
240
|
const onPress = React.useCallback(
|
|
114
241
|
(ev: GestureResponderEvent) => {
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
242
|
+
// A press during the hover delay cancels it: a press never opens without openOnPress.
|
|
243
|
+
clearDelay();
|
|
244
|
+
if (openOnPress && !open) {
|
|
245
|
+
show();
|
|
246
|
+
} else {
|
|
247
|
+
hide();
|
|
248
|
+
}
|
|
120
249
|
onPressProp?.(ev);
|
|
121
250
|
},
|
|
122
|
-
[
|
|
251
|
+
[clearDelay, hide, onPressProp, open, openOnPress, show]
|
|
123
252
|
);
|
|
124
253
|
|
|
125
254
|
const Component = asChild ? Slot : Pressable;
|
|
@@ -130,6 +259,13 @@ const Trigger = React.forwardRef<View, TriggerProps>(function Trigger(
|
|
|
130
259
|
role="button"
|
|
131
260
|
aria-disabled={disabled || undefined}
|
|
132
261
|
onPress={onPress}
|
|
262
|
+
onPressOut={onPressOut}
|
|
263
|
+
onPointerDown={onPointerDown}
|
|
264
|
+
onPointerUp={onPointerUp}
|
|
265
|
+
onHoverIn={onHoverIn}
|
|
266
|
+
onHoverOut={onHoverOut}
|
|
267
|
+
onFocus={onFocus}
|
|
268
|
+
onBlur={onBlur}
|
|
133
269
|
disabled={disabled || undefined}
|
|
134
270
|
{...props}
|
|
135
271
|
/>
|
package/src/tooltip/types.ts
CHANGED
|
@@ -9,11 +9,15 @@ interface RootProps {
|
|
|
9
9
|
open?: boolean;
|
|
10
10
|
defaultOpen?: boolean;
|
|
11
11
|
onOpenChange?: (open: boolean) => void;
|
|
12
|
+
/** Delay in ms between the pointer entering the trigger and the tooltip opening. Defaults to `0`. */
|
|
12
13
|
delayDuration?: number;
|
|
13
14
|
children?: React.ReactNode;
|
|
14
15
|
}
|
|
15
16
|
|
|
16
|
-
interface TriggerProps extends SlottablePressableProps {
|
|
17
|
+
interface TriggerProps extends SlottablePressableProps {
|
|
18
|
+
/** Toggle the tooltip on press as well, for a trigger that does nothing else. */
|
|
19
|
+
openOnPress?: boolean;
|
|
20
|
+
}
|
|
17
21
|
|
|
18
22
|
interface PortalProps extends ForceMountable {
|
|
19
23
|
hostName?: string;
|
|
@@ -29,6 +33,7 @@ interface ContentProps extends SlottableViewProps, PositionedContentProps {}
|
|
|
29
33
|
interface RootContext {
|
|
30
34
|
open: boolean;
|
|
31
35
|
onOpenChange: (open: boolean) => void;
|
|
36
|
+
delayDuration: number;
|
|
32
37
|
triggerPosition: LayoutPosition | null;
|
|
33
38
|
setTriggerPosition: (position: LayoutPosition | null) => void;
|
|
34
39
|
contentLayout: LayoutRectangle | null;
|