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