@primer/react 0.0.0-20260224184654 → 0.0.0-20260224210043
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/CHANGELOG.md +1 -1
- package/dist/ActionList/Item.d.ts.map +1 -1
- package/dist/ActionList/Item.js +94 -142
- package/dist/TooltipV2/Tooltip.d.ts +11 -0
- package/dist/TooltipV2/Tooltip.d.ts.map +1 -1
- package/dist/TooltipV2/Tooltip.js +117 -104
- package/dist/TooltipV2/Tooltip.module.css.js +2 -2
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Item.d.ts","sourceRoot":"","sources":["../../src/ActionList/Item.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAiB,MAAM,OAAO,CAAA;AAqBrC,KAAK,sBAAsB,GAAG;IAC5B,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,CAAA;CAC3B,CAAA;
|
|
1
|
+
{"version":3,"file":"Item.d.ts","sourceRoot":"","sources":["../../src/ActionList/Item.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAiB,MAAM,OAAO,CAAA;AAqBrC,KAAK,sBAAsB,GAAG;IAC5B,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,CAAA;CAC3B,CAAA;AA0BD,eAAO,MAAM,OAAO,EAAE,KAAK,CAAC,EAAE,CAAC,sBAAsB,CAEpD,CAAA;AAkTD,QAAA,MAAM,IAAI,IA1Ra,EAAE,SAAS,KAAK,CAAC,WAAW;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA6RjD,CAAA;AAEF,OAAO,EAAC,IAAI,EAAC,CAAA"}
|
package/dist/ActionList/Item.js
CHANGED
|
@@ -15,10 +15,45 @@ import VisuallyHidden from '../_VisuallyHidden.js';
|
|
|
15
15
|
import classes from './ActionList.module.css.js';
|
|
16
16
|
import { clsx } from 'clsx';
|
|
17
17
|
import { fixedForwardRef } from '../utils/modern-polymorphic.js';
|
|
18
|
-
import
|
|
19
|
-
import { getAnchoredPosition } from '@primer/behaviors';
|
|
18
|
+
import { TooltipContext, Tooltip } from '../TooltipV2/Tooltip.js';
|
|
20
19
|
import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
|
|
21
20
|
|
|
21
|
+
/**
|
|
22
|
+
* Stable wrapper that keeps Tooltip in the tree for button-semantic items
|
|
23
|
+
* to avoid remount cycles when truncation state changes.
|
|
24
|
+
* For non-button-semantic items, renders children directly.
|
|
25
|
+
*/
|
|
26
|
+
function ConditionalTooltip(t0) {
|
|
27
|
+
const $ = c(4);
|
|
28
|
+
const {
|
|
29
|
+
text,
|
|
30
|
+
enabled,
|
|
31
|
+
children
|
|
32
|
+
} = t0;
|
|
33
|
+
if (!enabled) {
|
|
34
|
+
return children;
|
|
35
|
+
}
|
|
36
|
+
const t1 = text || "";
|
|
37
|
+
const t2 = !text;
|
|
38
|
+
let t3;
|
|
39
|
+
if ($[0] !== children || $[1] !== t1 || $[2] !== t2) {
|
|
40
|
+
t3 = /*#__PURE__*/jsx(Tooltip, {
|
|
41
|
+
text: t1,
|
|
42
|
+
direction: "e",
|
|
43
|
+
delay: "medium",
|
|
44
|
+
_privateDisableTooltip: t2,
|
|
45
|
+
_privateRenderBeforeTrigger: true,
|
|
46
|
+
children: children
|
|
47
|
+
});
|
|
48
|
+
$[0] = children;
|
|
49
|
+
$[1] = t1;
|
|
50
|
+
$[2] = t2;
|
|
51
|
+
$[3] = t3;
|
|
52
|
+
} else {
|
|
53
|
+
t3 = $[3];
|
|
54
|
+
}
|
|
55
|
+
return t3;
|
|
56
|
+
}
|
|
22
57
|
const SubItem = t0 => {
|
|
23
58
|
const $ = c(2);
|
|
24
59
|
const {
|
|
@@ -218,60 +253,9 @@ const UnwrappedItem = ({
|
|
|
218
253
|
const labelId = `${itemId}--label`;
|
|
219
254
|
const inlineDescriptionId = `${itemId}--inline-description`;
|
|
220
255
|
const blockDescriptionId = `${itemId}--block-description`;
|
|
221
|
-
const truncationTooltipId = `${itemId}--truncation-tooltip`;
|
|
222
256
|
const trailingVisualId = `${itemId}--trailing-visual`;
|
|
223
257
|
const inactiveWarningId = inactive && !showInactiveIndicator ? `${itemId}--warning-message` : undefined;
|
|
224
258
|
const [truncatedText, setTruncatedText] = React.useState(undefined);
|
|
225
|
-
const truncationTooltipRef = React.useRef(null);
|
|
226
|
-
const truncationTooltipOpenTimeoutRef = React.useRef(null);
|
|
227
|
-
const lastTriggerRef = React.useRef(null);
|
|
228
|
-
React.useEffect(() => {
|
|
229
|
-
if (truncationTooltipRef.current) {
|
|
230
|
-
truncationTooltipRef.current.setAttribute('popover', 'auto');
|
|
231
|
-
}
|
|
232
|
-
}, []);
|
|
233
|
-
React.useEffect(() => {
|
|
234
|
-
return () => {
|
|
235
|
-
if (truncationTooltipOpenTimeoutRef.current) {
|
|
236
|
-
window.clearTimeout(truncationTooltipOpenTimeoutRef.current);
|
|
237
|
-
}
|
|
238
|
-
};
|
|
239
|
-
}, []);
|
|
240
|
-
const showTruncationTooltip = React.useCallback(trigger => {
|
|
241
|
-
const tooltip = truncationTooltipRef.current;
|
|
242
|
-
if (!tooltip || !truncatedText) return;
|
|
243
|
-
lastTriggerRef.current = trigger;
|
|
244
|
-
try {
|
|
245
|
-
if (!tooltip.matches(':popover-open')) {
|
|
246
|
-
tooltip.showPopover();
|
|
247
|
-
const {
|
|
248
|
-
top,
|
|
249
|
-
left
|
|
250
|
-
} = getAnchoredPosition(tooltip, trigger, {
|
|
251
|
-
side: 'outside-right',
|
|
252
|
-
align: 'center'
|
|
253
|
-
});
|
|
254
|
-
tooltip.style.top = `${top}px`;
|
|
255
|
-
tooltip.style.left = `${left}px`;
|
|
256
|
-
}
|
|
257
|
-
} catch {
|
|
258
|
-
// Ignore browsers/environments that don't support :popover-open or popover API
|
|
259
|
-
}
|
|
260
|
-
}, [truncatedText]);
|
|
261
|
-
const hideTruncationTooltip = React.useCallback(() => {
|
|
262
|
-
if (truncationTooltipOpenTimeoutRef.current) {
|
|
263
|
-
window.clearTimeout(truncationTooltipOpenTimeoutRef.current);
|
|
264
|
-
truncationTooltipOpenTimeoutRef.current = null;
|
|
265
|
-
}
|
|
266
|
-
try {
|
|
267
|
-
var _truncationTooltipRef;
|
|
268
|
-
if ((_truncationTooltipRef = truncationTooltipRef.current) !== null && _truncationTooltipRef !== void 0 && _truncationTooltipRef.matches(':popover-open')) {
|
|
269
|
-
truncationTooltipRef.current.hidePopover();
|
|
270
|
-
}
|
|
271
|
-
} catch {
|
|
272
|
-
// Ignore browsers/environments that don't support :popover-open or popover API
|
|
273
|
-
}
|
|
274
|
-
}, []);
|
|
275
259
|
const DefaultItemWrapper = listSemantics ? DivItemContainerNoBox : ButtonItemContainerNoBox;
|
|
276
260
|
const ItemWrapper = _PrivateItemWrapper || DefaultItemWrapper;
|
|
277
261
|
|
|
@@ -293,7 +277,7 @@ const UnwrappedItem = ({
|
|
|
293
277
|
'data-loading': loading && !inactive ? true : undefined,
|
|
294
278
|
tabIndex: focusable ? undefined : 0,
|
|
295
279
|
'aria-labelledby': `${labelId} ${slots.trailingVisual ? trailingVisualId : ''}`,
|
|
296
|
-
'aria-describedby': [slots.description && descriptionVariant === 'block' ? blockDescriptionId : undefined, slots.description && descriptionVariant === 'inline' ? inlineDescriptionId : undefined,
|
|
280
|
+
'aria-describedby': [slots.description && descriptionVariant === 'block' ? blockDescriptionId : undefined, slots.description && descriptionVariant === 'inline' ? inlineDescriptionId : undefined, inactiveWarningId !== null && inactiveWarningId !== void 0 ? inactiveWarningId : undefined].filter(String).join(' ').trim() || undefined,
|
|
297
281
|
...(includeSelectionAttribute && {
|
|
298
282
|
[itemSelectionAttribute]: selected
|
|
299
283
|
}),
|
|
@@ -315,28 +299,6 @@ const UnwrappedItem = ({
|
|
|
315
299
|
...props,
|
|
316
300
|
ref: forwardedRef
|
|
317
301
|
};
|
|
318
|
-
const truncationTooltipTriggerHandlers = buttonSemantics ? {
|
|
319
|
-
onFocus: event_2 => {
|
|
320
|
-
try {
|
|
321
|
-
if (!event_2.target.matches(':focus-visible')) return;
|
|
322
|
-
} catch {
|
|
323
|
-
// jsdom does not support :focus-visible yet
|
|
324
|
-
}
|
|
325
|
-
showTruncationTooltip(event_2.currentTarget);
|
|
326
|
-
},
|
|
327
|
-
onBlur: () => {
|
|
328
|
-
hideTruncationTooltip();
|
|
329
|
-
},
|
|
330
|
-
onMouseOverCapture: event_3 => {
|
|
331
|
-
const trigger_0 = event_3.currentTarget;
|
|
332
|
-
truncationTooltipOpenTimeoutRef.current = window.setTimeout(() => {
|
|
333
|
-
showTruncationTooltip(trigger_0);
|
|
334
|
-
}, 400);
|
|
335
|
-
},
|
|
336
|
-
onMouseLeave: () => {
|
|
337
|
-
hideTruncationTooltip();
|
|
338
|
-
}
|
|
339
|
-
} : {};
|
|
340
302
|
return /*#__PURE__*/jsx(ItemContext.Provider, {
|
|
341
303
|
value: {
|
|
342
304
|
variant,
|
|
@@ -358,72 +320,62 @@ const UnwrappedItem = ({
|
|
|
358
320
|
"data-has-subitem": slots.subItem ? true : undefined,
|
|
359
321
|
"data-has-description": slots.description ? true : false,
|
|
360
322
|
className: clsx(classes.ActionListItem, className),
|
|
361
|
-
children: [
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
children: trailingVisual
|
|
418
|
-
}),
|
|
419
|
-
// If the item is inactive, but it's not in an overlay (e.g. ActionMenu, SelectPanel),
|
|
420
|
-
// render the inactive warning message directly in the item.
|
|
421
|
-
!showInactiveIndicator && inactiveText ? /*#__PURE__*/jsx("span", {
|
|
422
|
-
className: classes.InactiveWarning,
|
|
423
|
-
id: inactiveWarningId,
|
|
424
|
-
children: inactiveText
|
|
425
|
-
}) : null]
|
|
426
|
-
})]
|
|
323
|
+
children: [/*#__PURE__*/jsx(ConditionalTooltip, {
|
|
324
|
+
text: truncatedText,
|
|
325
|
+
enabled: buttonSemantics,
|
|
326
|
+
children: /*#__PURE__*/jsx(ItemWrapper, {
|
|
327
|
+
...wrapperProps,
|
|
328
|
+
className: classes.ActionListContent,
|
|
329
|
+
"data-size": size
|
|
330
|
+
// @ts-ignore: ItemWrapper is polymorphic and the ref type depends on the rendered element ('button' or 'li')
|
|
331
|
+
,
|
|
332
|
+
ref: forwardedRef,
|
|
333
|
+
children: /*#__PURE__*/jsxs(TooltipContext.Provider, {
|
|
334
|
+
value: {},
|
|
335
|
+
children: [/*#__PURE__*/jsx("span", {
|
|
336
|
+
className: classes.Spacer
|
|
337
|
+
}), /*#__PURE__*/jsx(Selection, {
|
|
338
|
+
selected: selected,
|
|
339
|
+
className: classes.LeadingAction
|
|
340
|
+
}), /*#__PURE__*/jsx(VisualOrIndicator, {
|
|
341
|
+
inactiveText: showInactiveIndicator ? inactiveText : undefined,
|
|
342
|
+
itemHasLeadingVisual: Boolean(slots.leadingVisual),
|
|
343
|
+
labelId: labelId,
|
|
344
|
+
loading: loading,
|
|
345
|
+
position: "leading",
|
|
346
|
+
children: slots.leadingVisual
|
|
347
|
+
}), /*#__PURE__*/jsxs("span", {
|
|
348
|
+
className: classes.ActionListSubContent,
|
|
349
|
+
"data-component": "ActionList.Item--DividerContainer",
|
|
350
|
+
children: [/*#__PURE__*/jsxs(ConditionalWrapper, {
|
|
351
|
+
if: !!slots.description,
|
|
352
|
+
className: classes.ItemDescriptionWrap,
|
|
353
|
+
"data-description-variant": descriptionVariant,
|
|
354
|
+
children: [/*#__PURE__*/jsxs("span", {
|
|
355
|
+
id: labelId,
|
|
356
|
+
className: classes.ItemLabel,
|
|
357
|
+
children: [childrenWithoutSlots, loading === true && !inactive && /*#__PURE__*/jsx(VisuallyHidden, {
|
|
358
|
+
children: "Loading"
|
|
359
|
+
})]
|
|
360
|
+
}), slots.description]
|
|
361
|
+
}), /*#__PURE__*/jsx(VisualOrIndicator, {
|
|
362
|
+
inactiveText: showInactiveIndicator ? inactiveText : undefined,
|
|
363
|
+
itemHasLeadingVisual: Boolean(slots.leadingVisual),
|
|
364
|
+
labelId: labelId,
|
|
365
|
+
loading: loading,
|
|
366
|
+
position: "trailing",
|
|
367
|
+
children: trailingVisual
|
|
368
|
+
}),
|
|
369
|
+
// If the item is inactive, but it's not in an overlay (e.g. ActionMenu, SelectPanel),
|
|
370
|
+
// render the inactive warning message directly in the item.
|
|
371
|
+
!showInactiveIndicator && inactiveText ? /*#__PURE__*/jsx("span", {
|
|
372
|
+
className: classes.InactiveWarning,
|
|
373
|
+
id: inactiveWarningId,
|
|
374
|
+
children: inactiveText
|
|
375
|
+
}) : null]
|
|
376
|
+
})]
|
|
377
|
+
})
|
|
378
|
+
})
|
|
427
379
|
}), !inactive && !loading && !menuContext && Boolean(slots.trailingAction) && slots.trailingAction, slots.subItem]
|
|
428
380
|
})
|
|
429
381
|
});
|
|
@@ -24,6 +24,17 @@ export type TooltipProps = React.PropsWithChildren<{
|
|
|
24
24
|
* @default false
|
|
25
25
|
*/
|
|
26
26
|
_privateDisableTooltip?: boolean;
|
|
27
|
+
/**
|
|
28
|
+
* Private API for use internally only. Renders the tooltip popover element before
|
|
29
|
+
* the trigger in the DOM instead of after it.
|
|
30
|
+
*
|
|
31
|
+
* This is used by ActionList items to ensure the tooltip's popover `<span>` does not
|
|
32
|
+
* sit between the ActionListContent and its adjacent SubGroup sibling, which would
|
|
33
|
+
* break CSS adjacent sibling (`+`) selectors used for expand/collapse.
|
|
34
|
+
*
|
|
35
|
+
* @default false
|
|
36
|
+
*/
|
|
37
|
+
_privateRenderBeforeTrigger?: boolean;
|
|
27
38
|
}> & React.HTMLAttributes<HTMLElement>;
|
|
28
39
|
export declare const TooltipContext: React.Context<{
|
|
29
40
|
tooltipId?: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Tooltip.d.ts","sourceRoot":"","sources":["../../src/TooltipV2/Tooltip.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAiD,KAAK,yBAAyB,EAAC,MAAM,OAAO,CAAA;AAS3G,OAAO,EAAoD,KAAK,mBAAmB,EAAC,MAAM,mBAAmB,CAAA;AAG7G,OAAO,KAAK,EAAC,UAAU,EAAC,MAAM,gBAAgB,CAAA;AAE9C,MAAM,MAAM,gBAAgB,GAAG,IAAI,GAAG,GAAG,GAAG,IAAI,GAAG,GAAG,GAAG,IAAI,GAAG,GAAG,GAAG,IAAI,GAAG,GAAG,CAAA;AAChF,MAAM,MAAM,YAAY,GAAG,KAAK,CAAC,iBAAiB,CAAC;IACjD,SAAS,CAAC,EAAE,gBAAgB,CAAA;IAC5B,IAAI,EAAE,MAAM,CAAA;IACZ,IAAI,CAAC,EAAE,OAAO,GAAG,aAAa,CAAA;IAC9B,cAAc,CAAC,EAAE,mBAAmB,CAAC,MAAM,CAAC,CAAA;IAC5C;;;;;OAKG;IACH,KAAK,CAAC,EAAE,OAAO,GAAG,QAAQ,GAAG,MAAM,CAAA;IACnC;;;;;;;;OAQG;IACH,sBAAsB,CAAC,EAAE,OAAO,CAAA;
|
|
1
|
+
{"version":3,"file":"Tooltip.d.ts","sourceRoot":"","sources":["../../src/TooltipV2/Tooltip.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAiD,KAAK,yBAAyB,EAAC,MAAM,OAAO,CAAA;AAS3G,OAAO,EAAoD,KAAK,mBAAmB,EAAC,MAAM,mBAAmB,CAAA;AAG7G,OAAO,KAAK,EAAC,UAAU,EAAC,MAAM,gBAAgB,CAAA;AAE9C,MAAM,MAAM,gBAAgB,GAAG,IAAI,GAAG,GAAG,GAAG,IAAI,GAAG,GAAG,GAAG,IAAI,GAAG,GAAG,GAAG,IAAI,GAAG,GAAG,CAAA;AAChF,MAAM,MAAM,YAAY,GAAG,KAAK,CAAC,iBAAiB,CAAC;IACjD,SAAS,CAAC,EAAE,gBAAgB,CAAA;IAC5B,IAAI,EAAE,MAAM,CAAA;IACZ,IAAI,CAAC,EAAE,OAAO,GAAG,aAAa,CAAA;IAC9B,cAAc,CAAC,EAAE,mBAAmB,CAAC,MAAM,CAAC,CAAA;IAC5C;;;;;OAKG;IACH,KAAK,CAAC,EAAE,OAAO,GAAG,QAAQ,GAAG,MAAM,CAAA;IACnC;;;;;;;;OAQG;IACH,sBAAsB,CAAC,EAAE,OAAO,CAAA;IAChC;;;;;;;;;OASG;IACH,2BAA2B,CAAC,EAAE,OAAO,CAAA;CACtC,CAAC,GACA,KAAK,CAAC,cAAc,CAAC,WAAW,CAAC,CAAA;AAiEnC,eAAO,MAAM,cAAc;gBAAoC,MAAM;EAAM,CAAA;AAE3E,eAAO,MAAM,OAAO,EAAE,yBAAyB,CAC7C,KAAK,CAAC,eAAe,CAAC,YAAY,CAAC,GAAG,KAAK,CAAC,aAAa,CAAC,WAAW,CAAC,CACvE,GACC,UAuSD,CAAA"}
|
|
@@ -4,7 +4,7 @@ import { warning } from '../utils/warning.js';
|
|
|
4
4
|
import { getAnchoredPosition } from '@primer/behaviors';
|
|
5
5
|
import { isSupported, apply } from '@oddbird/popover-polyfill/fn';
|
|
6
6
|
import { clsx } from 'clsx';
|
|
7
|
-
import
|
|
7
|
+
import classes from './Tooltip.module.css.js';
|
|
8
8
|
import VisuallyHidden from '../_VisuallyHidden.js';
|
|
9
9
|
import useSafeTimeout from '../hooks/useSafeTimeout.js';
|
|
10
10
|
import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
|
|
@@ -86,6 +86,7 @@ const Tooltip = /*#__PURE__*/React.forwardRef(({
|
|
|
86
86
|
keybindingHint,
|
|
87
87
|
delay = 'short',
|
|
88
88
|
_privateDisableTooltip = false,
|
|
89
|
+
_privateRenderBeforeTrigger = false,
|
|
89
90
|
...rest
|
|
90
91
|
}, forwardedRef) => {
|
|
91
92
|
const tooltipId = useId(id);
|
|
@@ -196,112 +197,124 @@ const Tooltip = /*#__PURE__*/React.forwardRef(({
|
|
|
196
197
|
}, [isPopoverOpen]);
|
|
197
198
|
const isMacOS = useIsMacOS();
|
|
198
199
|
const hasAriaLabel = 'aria-label' in rest;
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
200
|
+
const tooltipPopover = /*#__PURE__*/jsx("span", {
|
|
201
|
+
className: clsx(className, classes.Tooltip),
|
|
202
|
+
ref: tooltipElRef,
|
|
203
|
+
"data-direction": calculatedDirection,
|
|
204
|
+
...rest,
|
|
205
|
+
// Only need tooltip role if the tooltip is a description for supplementary information
|
|
206
|
+
role: type === 'description' ? 'tooltip' : undefined
|
|
207
|
+
// stop AT from announcing the tooltip twice: when it is a label type it will be announced with "aria-labelledby",when it is a description type it will be announced with "aria-describedby"
|
|
208
|
+
,
|
|
209
|
+
"aria-hidden": true
|
|
210
|
+
// mouse leave and enter on the tooltip itself is needed to keep the tooltip open when the mouse is over the tooltip
|
|
211
|
+
,
|
|
212
|
+
onMouseEnter: openTooltip,
|
|
213
|
+
onMouseLeave: closeTooltip
|
|
214
|
+
// If there is an aria-label prop, always assign the ID to the parent so the accessible label can be overridden
|
|
215
|
+
,
|
|
216
|
+
id: hasAriaLabel || !keybindingHint ? tooltipId : undefined,
|
|
217
|
+
children: keybindingHint ? /*#__PURE__*/jsxs(Fragment, {
|
|
218
|
+
children: [/*#__PURE__*/jsxs("span", {
|
|
219
|
+
id: hasAriaLabel ? undefined : tooltipId,
|
|
220
|
+
children: [text, /*#__PURE__*/jsxs(VisuallyHidden, {
|
|
221
|
+
children: ["(", getAccessibleKeybindingHintString(keybindingHint, isMacOS), ")"]
|
|
222
|
+
})]
|
|
223
|
+
}), /*#__PURE__*/jsx("span", {
|
|
224
|
+
className: clsx(classes.KeybindingHintContainer, text && classes.HasTextBefore),
|
|
225
|
+
"aria-hidden": true,
|
|
226
|
+
children: /*#__PURE__*/jsx(KeybindingHint, {
|
|
227
|
+
keys: keybindingHint,
|
|
228
|
+
format: "condensed",
|
|
229
|
+
variant: "onEmphasis",
|
|
230
|
+
size: "small"
|
|
231
|
+
})
|
|
232
|
+
})]
|
|
233
|
+
}) : text
|
|
234
|
+
});
|
|
235
|
+
const triggerElement = /*#__PURE__*/React.isValidElement(child) &&
|
|
236
|
+
/*#__PURE__*/
|
|
237
|
+
// eslint-disable-next-line react-hooks/refs
|
|
238
|
+
React.cloneElement(child, {
|
|
239
|
+
// @ts-expect-error it needs a non nullable ref
|
|
240
|
+
ref: triggerRef,
|
|
241
|
+
// If it is a type description, we use tooltip to describe the trigger
|
|
242
|
+
'aria-describedby': (() => {
|
|
243
|
+
// If tooltip is not a description type, keep the original aria-describedby
|
|
244
|
+
if (type !== 'description') {
|
|
245
|
+
return child.props['aria-describedby'];
|
|
246
|
+
}
|
|
214
247
|
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
248
|
+
// When the tooltip is disabled, don't add its ID to aria-describedby
|
|
249
|
+
// to avoid an empty string polluting the accessible description
|
|
250
|
+
if (_privateDisableTooltip) {
|
|
251
|
+
return child.props['aria-describedby'];
|
|
252
|
+
}
|
|
220
253
|
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
onBlur: event => {
|
|
227
|
-
var _child$props$onBlur, _child$props;
|
|
228
|
-
closeTooltip();
|
|
229
|
-
(_child$props$onBlur = (_child$props = child.props).onBlur) === null || _child$props$onBlur === void 0 ? void 0 : _child$props$onBlur.call(_child$props, event);
|
|
230
|
-
},
|
|
231
|
-
onTouchEnd: event => {
|
|
232
|
-
var _child$props$onTouchE, _child$props2;
|
|
233
|
-
(_child$props$onTouchE = (_child$props2 = child.props).onTouchEnd) === null || _child$props$onTouchE === void 0 ? void 0 : _child$props$onTouchE.call(_child$props2, event);
|
|
254
|
+
// If tooltip is a description type, append our tooltipId
|
|
255
|
+
const existingDescribedBy = child.props['aria-describedby'];
|
|
256
|
+
if (existingDescribedBy) {
|
|
257
|
+
return `${existingDescribedBy} ${tooltipId}`;
|
|
258
|
+
}
|
|
234
259
|
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
}), /*#__PURE__*/jsx("span", {
|
|
294
|
-
className: clsx(tooltipClasses.KeybindingHintContainer, text && tooltipClasses.HasTextBefore),
|
|
295
|
-
"aria-hidden": true,
|
|
296
|
-
children: /*#__PURE__*/jsx(KeybindingHint, {
|
|
297
|
-
keys: keybindingHint,
|
|
298
|
-
format: "condensed",
|
|
299
|
-
variant: "onEmphasis",
|
|
300
|
-
size: "small"
|
|
301
|
-
})
|
|
302
|
-
})]
|
|
303
|
-
}) : text
|
|
304
|
-
})]
|
|
260
|
+
// If no existing aria-describedby, use our tooltipId
|
|
261
|
+
return tooltipId;
|
|
262
|
+
})(),
|
|
263
|
+
// If it is a label type, we use tooltip to label the trigger
|
|
264
|
+
'aria-labelledby': type === 'label' ? tooltipId : child.props['aria-labelledby'],
|
|
265
|
+
onBlur: event => {
|
|
266
|
+
var _child$props$onBlur, _child$props;
|
|
267
|
+
closeTooltip();
|
|
268
|
+
(_child$props$onBlur = (_child$props = child.props).onBlur) === null || _child$props$onBlur === void 0 ? void 0 : _child$props$onBlur.call(_child$props, event);
|
|
269
|
+
},
|
|
270
|
+
onTouchEnd: event => {
|
|
271
|
+
var _child$props$onTouchE, _child$props2;
|
|
272
|
+
(_child$props$onTouchE = (_child$props2 = child.props).onTouchEnd) === null || _child$props$onTouchE === void 0 ? void 0 : _child$props$onTouchE.call(_child$props2, event);
|
|
273
|
+
|
|
274
|
+
// Hide tooltips on tap to essentially disable them on touch devices;
|
|
275
|
+
// this still allows viewing the tooltip on tap-and-hold
|
|
276
|
+
safeSetTimeout(() => closeTooltip(), 10);
|
|
277
|
+
},
|
|
278
|
+
onFocus: event => {
|
|
279
|
+
var _child$props$onFocus, _child$props3;
|
|
280
|
+
// only show tooltip on :focus-visible, not on :focus
|
|
281
|
+
try {
|
|
282
|
+
if (!event.target.matches(':focus-visible')) return;
|
|
283
|
+
} catch (_error) {
|
|
284
|
+
// jsdom (jest) does not support `:focus-visible` yet and would throw an error
|
|
285
|
+
// https://github.com/jsdom/jsdom/issues/3426
|
|
286
|
+
}
|
|
287
|
+
openTooltip();
|
|
288
|
+
(_child$props$onFocus = (_child$props3 = child.props).onFocus) === null || _child$props$onFocus === void 0 ? void 0 : _child$props$onFocus.call(_child$props3, event);
|
|
289
|
+
},
|
|
290
|
+
onMouseOverCapture: event => {
|
|
291
|
+
const delayTime = delayTimeMap[delay] || 50;
|
|
292
|
+
// We use a `capture` event to ensure this is called first before
|
|
293
|
+
// events that might cancel the opening timeout (like `onTouchEnd`)
|
|
294
|
+
// show tooltip after mouse has been hovering for the specified delay time
|
|
295
|
+
// (prevent showing tooltip when mouse is just passing through)
|
|
296
|
+
openTimeoutRef.current = safeSetTimeout(() => {
|
|
297
|
+
var _child$props$onMouseE, _child$props4;
|
|
298
|
+
// if the mouse is already moved out, do not show the tooltip
|
|
299
|
+
if (!openTimeoutRef.current) return;
|
|
300
|
+
openTooltip();
|
|
301
|
+
(_child$props$onMouseE = (_child$props4 = child.props).onMouseEnter) === null || _child$props$onMouseE === void 0 ? void 0 : _child$props$onMouseE.call(_child$props4, event);
|
|
302
|
+
}, delayTime);
|
|
303
|
+
},
|
|
304
|
+
onMouseLeave: event => {
|
|
305
|
+
var _child$props$onMouseL, _child$props5;
|
|
306
|
+
closeTooltip();
|
|
307
|
+
(_child$props$onMouseL = (_child$props5 = child.props).onMouseLeave) === null || _child$props$onMouseL === void 0 ? void 0 : _child$props$onMouseL.call(_child$props5, event);
|
|
308
|
+
}
|
|
309
|
+
});
|
|
310
|
+
return /*#__PURE__*/jsx(TooltipContext.Provider, {
|
|
311
|
+
value: value,
|
|
312
|
+
children: /*#__PURE__*/jsx(Fragment, {
|
|
313
|
+
children: _privateRenderBeforeTrigger ? /*#__PURE__*/jsxs(Fragment, {
|
|
314
|
+
children: [tooltipPopover, triggerElement]
|
|
315
|
+
}) : /*#__PURE__*/jsxs(Fragment, {
|
|
316
|
+
children: [triggerElement, tooltipPopover]
|
|
317
|
+
})
|
|
305
318
|
})
|
|
306
319
|
});
|
|
307
320
|
});
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import './Tooltip-5a80d7b2.css';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var classes = {"Tooltip":"prc-TooltipV2-Tooltip-tLeuB","tooltip-appear":"prc-TooltipV2-tooltip-appear-xyBco","KeybindingHintContainer":"prc-TooltipV2-KeybindingHintContainer-Ymj-3","HasTextBefore":"prc-TooltipV2-HasTextBefore-fdOXj"};
|
|
4
4
|
|
|
5
|
-
export {
|
|
5
|
+
export { classes as default };
|
package/package.json
CHANGED