1 | 'use client';
|
2 |
|
3 | import * as React from 'react';
|
4 | import PropTypes from 'prop-types';
|
5 | import clsx from 'clsx';
|
6 | import useTimeout, { Timeout } from '@mui/utils/useTimeout';
|
7 | import elementAcceptingRef from '@mui/utils/elementAcceptingRef';
|
8 | import composeClasses from '@mui/utils/composeClasses';
|
9 | import { alpha } from '@mui/system/colorManipulator';
|
10 | import { useRtl } from '@mui/system/RtlProvider';
|
11 | import isFocusVisible from '@mui/utils/isFocusVisible';
|
12 | import appendOwnerState from '@mui/utils/appendOwnerState';
|
13 | import getReactElementRef from '@mui/utils/getReactElementRef';
|
14 | import { styled, useTheme } from "../zero-styled/index.js";
|
15 | import memoTheme from "../utils/memoTheme.js";
|
16 | import { useDefaultProps } from "../DefaultPropsProvider/index.js";
|
17 | import capitalize from "../utils/capitalize.js";
|
18 | import Grow from "../Grow/index.js";
|
19 | import Popper from "../Popper/index.js";
|
20 | import useEventCallback from "../utils/useEventCallback.js";
|
21 | import useForkRef from "../utils/useForkRef.js";
|
22 | import useId from "../utils/useId.js";
|
23 | import useControlled from "../utils/useControlled.js";
|
24 | import tooltipClasses, { getTooltipUtilityClass } from "./tooltipClasses.js";
|
25 | import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
26 | function round(value) {
|
27 | return Math.round(value * 1e5) / 1e5;
|
28 | }
|
29 | const useUtilityClasses = ownerState => {
|
30 | const {
|
31 | classes,
|
32 | disableInteractive,
|
33 | arrow,
|
34 | touch,
|
35 | placement
|
36 | } = ownerState;
|
37 | const slots = {
|
38 | popper: ['popper', !disableInteractive && 'popperInteractive', arrow && 'popperArrow'],
|
39 | tooltip: ['tooltip', arrow && 'tooltipArrow', touch && 'touch', `tooltipPlacement${capitalize(placement.split('-')[0])}`],
|
40 | arrow: ['arrow']
|
41 | };
|
42 | return composeClasses(slots, getTooltipUtilityClass, classes);
|
43 | };
|
44 | const TooltipPopper = styled(Popper, {
|
45 | name: 'MuiTooltip',
|
46 | slot: 'Popper',
|
47 | overridesResolver: (props, styles) => {
|
48 | const {
|
49 | ownerState
|
50 | } = props;
|
51 | return [styles.popper, !ownerState.disableInteractive && styles.popperInteractive, ownerState.arrow && styles.popperArrow, !ownerState.open && styles.popperClose];
|
52 | }
|
53 | })(memoTheme(({
|
54 | theme
|
55 | }) => ({
|
56 | zIndex: (theme.vars || theme).zIndex.tooltip,
|
57 | pointerEvents: 'none',
|
58 | variants: [{
|
59 | props: ({
|
60 | ownerState
|
61 | }) => !ownerState.disableInteractive,
|
62 | style: {
|
63 | pointerEvents: 'auto'
|
64 | }
|
65 | }, {
|
66 | props: ({
|
67 | open
|
68 | }) => !open,
|
69 | style: {
|
70 | pointerEvents: 'none'
|
71 | }
|
72 | }, {
|
73 | props: ({
|
74 | ownerState
|
75 | }) => ownerState.arrow,
|
76 | style: {
|
77 | [`&[data-popper-placement*="bottom"] .${tooltipClasses.arrow}`]: {
|
78 | top: 0,
|
79 | marginTop: '-0.71em',
|
80 | '&::before': {
|
81 | transformOrigin: '0 100%'
|
82 | }
|
83 | },
|
84 | [`&[data-popper-placement*="top"] .${tooltipClasses.arrow}`]: {
|
85 | bottom: 0,
|
86 | marginBottom: '-0.71em',
|
87 | '&::before': {
|
88 | transformOrigin: '100% 0'
|
89 | }
|
90 | },
|
91 | [`&[data-popper-placement*="right"] .${tooltipClasses.arrow}`]: {
|
92 | height: '1em',
|
93 | width: '0.71em',
|
94 | '&::before': {
|
95 | transformOrigin: '100% 100%'
|
96 | }
|
97 | },
|
98 | [`&[data-popper-placement*="left"] .${tooltipClasses.arrow}`]: {
|
99 | height: '1em',
|
100 | width: '0.71em',
|
101 | '&::before': {
|
102 | transformOrigin: '0 0'
|
103 | }
|
104 | }
|
105 | }
|
106 | }, {
|
107 | props: ({
|
108 | ownerState
|
109 | }) => ownerState.arrow && !ownerState.isRtl,
|
110 | style: {
|
111 | [`&[data-popper-placement*="right"] .${tooltipClasses.arrow}`]: {
|
112 | left: 0,
|
113 | marginLeft: '-0.71em'
|
114 | }
|
115 | }
|
116 | }, {
|
117 | props: ({
|
118 | ownerState
|
119 | }) => ownerState.arrow && !!ownerState.isRtl,
|
120 | style: {
|
121 | [`&[data-popper-placement*="right"] .${tooltipClasses.arrow}`]: {
|
122 | right: 0,
|
123 | marginRight: '-0.71em'
|
124 | }
|
125 | }
|
126 | }, {
|
127 | props: ({
|
128 | ownerState
|
129 | }) => ownerState.arrow && !ownerState.isRtl,
|
130 | style: {
|
131 | [`&[data-popper-placement*="left"] .${tooltipClasses.arrow}`]: {
|
132 | right: 0,
|
133 | marginRight: '-0.71em'
|
134 | }
|
135 | }
|
136 | }, {
|
137 | props: ({
|
138 | ownerState
|
139 | }) => ownerState.arrow && !!ownerState.isRtl,
|
140 | style: {
|
141 | [`&[data-popper-placement*="left"] .${tooltipClasses.arrow}`]: {
|
142 | left: 0,
|
143 | marginLeft: '-0.71em'
|
144 | }
|
145 | }
|
146 | }]
|
147 | })));
|
148 | const TooltipTooltip = styled('div', {
|
149 | name: 'MuiTooltip',
|
150 | slot: 'Tooltip',
|
151 | overridesResolver: (props, styles) => {
|
152 | const {
|
153 | ownerState
|
154 | } = props;
|
155 | return [styles.tooltip, ownerState.touch && styles.touch, ownerState.arrow && styles.tooltipArrow, styles[`tooltipPlacement${capitalize(ownerState.placement.split('-')[0])}`]];
|
156 | }
|
157 | })(memoTheme(({
|
158 | theme
|
159 | }) => ({
|
160 | backgroundColor: theme.vars ? theme.vars.palette.Tooltip.bg : alpha(theme.palette.grey[700], 0.92),
|
161 | borderRadius: (theme.vars || theme).shape.borderRadius,
|
162 | color: (theme.vars || theme).palette.common.white,
|
163 | fontFamily: theme.typography.fontFamily,
|
164 | padding: '4px 8px',
|
165 | fontSize: theme.typography.pxToRem(11),
|
166 | maxWidth: 300,
|
167 | margin: 2,
|
168 | wordWrap: 'break-word',
|
169 | fontWeight: theme.typography.fontWeightMedium,
|
170 | [`.${tooltipClasses.popper}[data-popper-placement*="left"] &`]: {
|
171 | transformOrigin: 'right center'
|
172 | },
|
173 | [`.${tooltipClasses.popper}[data-popper-placement*="right"] &`]: {
|
174 | transformOrigin: 'left center'
|
175 | },
|
176 | [`.${tooltipClasses.popper}[data-popper-placement*="top"] &`]: {
|
177 | transformOrigin: 'center bottom',
|
178 | marginBottom: '14px'
|
179 | },
|
180 | [`.${tooltipClasses.popper}[data-popper-placement*="bottom"] &`]: {
|
181 | transformOrigin: 'center top',
|
182 | marginTop: '14px'
|
183 | },
|
184 | variants: [{
|
185 | props: ({
|
186 | ownerState
|
187 | }) => ownerState.arrow,
|
188 | style: {
|
189 | position: 'relative',
|
190 | margin: 0
|
191 | }
|
192 | }, {
|
193 | props: ({
|
194 | ownerState
|
195 | }) => ownerState.touch,
|
196 | style: {
|
197 | padding: '8px 16px',
|
198 | fontSize: theme.typography.pxToRem(14),
|
199 | lineHeight: `${round(16 / 14)}em`,
|
200 | fontWeight: theme.typography.fontWeightRegular
|
201 | }
|
202 | }, {
|
203 | props: ({
|
204 | ownerState
|
205 | }) => !ownerState.isRtl,
|
206 | style: {
|
207 | [`.${tooltipClasses.popper}[data-popper-placement*="left"] &`]: {
|
208 | marginRight: '14px'
|
209 | },
|
210 | [`.${tooltipClasses.popper}[data-popper-placement*="right"] &`]: {
|
211 | marginLeft: '14px'
|
212 | }
|
213 | }
|
214 | }, {
|
215 | props: ({
|
216 | ownerState
|
217 | }) => !ownerState.isRtl && ownerState.touch,
|
218 | style: {
|
219 | [`.${tooltipClasses.popper}[data-popper-placement*="left"] &`]: {
|
220 | marginRight: '24px'
|
221 | },
|
222 | [`.${tooltipClasses.popper}[data-popper-placement*="right"] &`]: {
|
223 | marginLeft: '24px'
|
224 | }
|
225 | }
|
226 | }, {
|
227 | props: ({
|
228 | ownerState
|
229 | }) => !!ownerState.isRtl,
|
230 | style: {
|
231 | [`.${tooltipClasses.popper}[data-popper-placement*="left"] &`]: {
|
232 | marginLeft: '14px'
|
233 | },
|
234 | [`.${tooltipClasses.popper}[data-popper-placement*="right"] &`]: {
|
235 | marginRight: '14px'
|
236 | }
|
237 | }
|
238 | }, {
|
239 | props: ({
|
240 | ownerState
|
241 | }) => !!ownerState.isRtl && ownerState.touch,
|
242 | style: {
|
243 | [`.${tooltipClasses.popper}[data-popper-placement*="left"] &`]: {
|
244 | marginLeft: '24px'
|
245 | },
|
246 | [`.${tooltipClasses.popper}[data-popper-placement*="right"] &`]: {
|
247 | marginRight: '24px'
|
248 | }
|
249 | }
|
250 | }, {
|
251 | props: ({
|
252 | ownerState
|
253 | }) => ownerState.touch,
|
254 | style: {
|
255 | [`.${tooltipClasses.popper}[data-popper-placement*="top"] &`]: {
|
256 | marginBottom: '24px'
|
257 | }
|
258 | }
|
259 | }, {
|
260 | props: ({
|
261 | ownerState
|
262 | }) => ownerState.touch,
|
263 | style: {
|
264 | [`.${tooltipClasses.popper}[data-popper-placement*="bottom"] &`]: {
|
265 | marginTop: '24px'
|
266 | }
|
267 | }
|
268 | }]
|
269 | })));
|
270 | const TooltipArrow = styled('span', {
|
271 | name: 'MuiTooltip',
|
272 | slot: 'Arrow',
|
273 | overridesResolver: (props, styles) => styles.arrow
|
274 | })(memoTheme(({
|
275 | theme
|
276 | }) => ({
|
277 | overflow: 'hidden',
|
278 | position: 'absolute',
|
279 | width: '1em',
|
280 | height: '0.71em' ,
|
281 | boxSizing: 'border-box',
|
282 | color: theme.vars ? theme.vars.palette.Tooltip.bg : alpha(theme.palette.grey[700], 0.9),
|
283 | '&::before': {
|
284 | content: '""',
|
285 | margin: 'auto',
|
286 | display: 'block',
|
287 | width: '100%',
|
288 | height: '100%',
|
289 | backgroundColor: 'currentColor',
|
290 | transform: 'rotate(45deg)'
|
291 | }
|
292 | })));
|
293 | let hystersisOpen = false;
|
294 | const hystersisTimer = new Timeout();
|
295 | let cursorPosition = {
|
296 | x: 0,
|
297 | y: 0
|
298 | };
|
299 | export function testReset() {
|
300 | hystersisOpen = false;
|
301 | hystersisTimer.clear();
|
302 | }
|
303 | function composeEventHandler(handler, eventHandler) {
|
304 | return (event, ...params) => {
|
305 | if (eventHandler) {
|
306 | eventHandler(event, ...params);
|
307 | }
|
308 | handler(event, ...params);
|
309 | };
|
310 | }
|
311 |
|
312 |
|
313 | const Tooltip = React.forwardRef(function Tooltip(inProps, ref) {
|
314 | const props = useDefaultProps({
|
315 | props: inProps,
|
316 | name: 'MuiTooltip'
|
317 | });
|
318 | const {
|
319 | arrow = false,
|
320 | children: childrenProp,
|
321 | classes: classesProp,
|
322 | components = {},
|
323 | componentsProps = {},
|
324 | describeChild = false,
|
325 | disableFocusListener = false,
|
326 | disableHoverListener = false,
|
327 | disableInteractive: disableInteractiveProp = false,
|
328 | disableTouchListener = false,
|
329 | enterDelay = 100,
|
330 | enterNextDelay = 0,
|
331 | enterTouchDelay = 700,
|
332 | followCursor = false,
|
333 | id: idProp,
|
334 | leaveDelay = 0,
|
335 | leaveTouchDelay = 1500,
|
336 | onClose,
|
337 | onOpen,
|
338 | open: openProp,
|
339 | placement = 'bottom',
|
340 | PopperComponent: PopperComponentProp,
|
341 | PopperProps = {},
|
342 | slotProps = {},
|
343 | slots = {},
|
344 | title,
|
345 | TransitionComponent: TransitionComponentProp = Grow,
|
346 | TransitionProps,
|
347 | ...other
|
348 | } = props;
|
349 |
|
350 |
|
351 | const children = React.isValidElement(childrenProp) ? childrenProp : _jsx("span", {
|
352 | children: childrenProp
|
353 | });
|
354 | const theme = useTheme();
|
355 | const isRtl = useRtl();
|
356 | const [childNode, setChildNode] = React.useState();
|
357 | const [arrowRef, setArrowRef] = React.useState(null);
|
358 | const ignoreNonTouchEvents = React.useRef(false);
|
359 | const disableInteractive = disableInteractiveProp || followCursor;
|
360 | const closeTimer = useTimeout();
|
361 | const enterTimer = useTimeout();
|
362 | const leaveTimer = useTimeout();
|
363 | const touchTimer = useTimeout();
|
364 | const [openState, setOpenState] = useControlled({
|
365 | controlled: openProp,
|
366 | default: false,
|
367 | name: 'Tooltip',
|
368 | state: 'open'
|
369 | });
|
370 | let open = openState;
|
371 | if (process.env.NODE_ENV !== 'production') {
|
372 |
|
373 |
|
374 | const {
|
375 | current: isControlled
|
376 | } = React.useRef(openProp !== undefined);
|
377 |
|
378 |
|
379 |
|
380 | React.useEffect(() => {
|
381 | if (childNode && childNode.disabled && !isControlled && title !== '' && childNode.tagName.toLowerCase() === 'button') {
|
382 | console.error(['MUI: You are providing a disabled `button` child to the Tooltip component.', 'A disabled element does not fire events.', "Tooltip needs to listen to the child element's events to display the title.", '', 'Add a simple wrapper element, such as a `span`.'].join('\n'));
|
383 | }
|
384 | }, [title, childNode, isControlled]);
|
385 | }
|
386 | const id = useId(idProp);
|
387 | const prevUserSelect = React.useRef();
|
388 | const stopTouchInteraction = useEventCallback(() => {
|
389 | if (prevUserSelect.current !== undefined) {
|
390 | document.body.style.WebkitUserSelect = prevUserSelect.current;
|
391 | prevUserSelect.current = undefined;
|
392 | }
|
393 | touchTimer.clear();
|
394 | });
|
395 | React.useEffect(() => stopTouchInteraction, [stopTouchInteraction]);
|
396 | const handleOpen = event => {
|
397 | hystersisTimer.clear();
|
398 | hystersisOpen = true;
|
399 |
|
400 |
|
401 |
|
402 |
|
403 | setOpenState(true);
|
404 | if (onOpen && !open) {
|
405 | onOpen(event);
|
406 | }
|
407 | };
|
408 | const handleClose = useEventCallback(
|
409 | |
410 |
|
411 |
|
412 | event => {
|
413 | hystersisTimer.start(800 + leaveDelay, () => {
|
414 | hystersisOpen = false;
|
415 | });
|
416 | setOpenState(false);
|
417 | if (onClose && open) {
|
418 | onClose(event);
|
419 | }
|
420 | closeTimer.start(theme.transitions.duration.shortest, () => {
|
421 | ignoreNonTouchEvents.current = false;
|
422 | });
|
423 | });
|
424 | const handleMouseOver = event => {
|
425 | if (ignoreNonTouchEvents.current && event.type !== 'touchstart') {
|
426 | return;
|
427 | }
|
428 |
|
429 |
|
430 |
|
431 |
|
432 | if (childNode) {
|
433 | childNode.removeAttribute('title');
|
434 | }
|
435 | enterTimer.clear();
|
436 | leaveTimer.clear();
|
437 | if (enterDelay || hystersisOpen && enterNextDelay) {
|
438 | enterTimer.start(hystersisOpen ? enterNextDelay : enterDelay, () => {
|
439 | handleOpen(event);
|
440 | });
|
441 | } else {
|
442 | handleOpen(event);
|
443 | }
|
444 | };
|
445 | const handleMouseLeave = event => {
|
446 | enterTimer.clear();
|
447 | leaveTimer.start(leaveDelay, () => {
|
448 | handleClose(event);
|
449 | });
|
450 | };
|
451 | const [, setChildIsFocusVisible] = React.useState(false);
|
452 | const handleBlur = event => {
|
453 | if (!isFocusVisible(event.target)) {
|
454 | setChildIsFocusVisible(false);
|
455 | handleMouseLeave(event);
|
456 | }
|
457 | };
|
458 | const handleFocus = event => {
|
459 |
|
460 |
|
461 |
|
462 | if (!childNode) {
|
463 | setChildNode(event.currentTarget);
|
464 | }
|
465 | if (isFocusVisible(event.target)) {
|
466 | setChildIsFocusVisible(true);
|
467 | handleMouseOver(event);
|
468 | }
|
469 | };
|
470 | const detectTouchStart = event => {
|
471 | ignoreNonTouchEvents.current = true;
|
472 | const childrenProps = children.props;
|
473 | if (childrenProps.onTouchStart) {
|
474 | childrenProps.onTouchStart(event);
|
475 | }
|
476 | };
|
477 | const handleTouchStart = event => {
|
478 | detectTouchStart(event);
|
479 | leaveTimer.clear();
|
480 | closeTimer.clear();
|
481 | stopTouchInteraction();
|
482 | prevUserSelect.current = document.body.style.WebkitUserSelect;
|
483 |
|
484 | document.body.style.WebkitUserSelect = 'none';
|
485 | touchTimer.start(enterTouchDelay, () => {
|
486 | document.body.style.WebkitUserSelect = prevUserSelect.current;
|
487 | handleMouseOver(event);
|
488 | });
|
489 | };
|
490 | const handleTouchEnd = event => {
|
491 | if (children.props.onTouchEnd) {
|
492 | children.props.onTouchEnd(event);
|
493 | }
|
494 | stopTouchInteraction();
|
495 | leaveTimer.start(leaveTouchDelay, () => {
|
496 | handleClose(event);
|
497 | });
|
498 | };
|
499 | React.useEffect(() => {
|
500 | if (!open) {
|
501 | return undefined;
|
502 | }
|
503 |
|
504 | |
505 |
|
506 |
|
507 | function handleKeyDown(nativeEvent) {
|
508 | if (nativeEvent.key === 'Escape') {
|
509 | handleClose(nativeEvent);
|
510 | }
|
511 | }
|
512 | document.addEventListener('keydown', handleKeyDown);
|
513 | return () => {
|
514 | document.removeEventListener('keydown', handleKeyDown);
|
515 | };
|
516 | }, [handleClose, open]);
|
517 | const handleRef = useForkRef(getReactElementRef(children), setChildNode, ref);
|
518 |
|
519 |
|
520 |
|
521 | if (!title && title !== 0) {
|
522 | open = false;
|
523 | }
|
524 | const popperRef = React.useRef();
|
525 | const handleMouseMove = event => {
|
526 | const childrenProps = children.props;
|
527 | if (childrenProps.onMouseMove) {
|
528 | childrenProps.onMouseMove(event);
|
529 | }
|
530 | cursorPosition = {
|
531 | x: event.clientX,
|
532 | y: event.clientY
|
533 | };
|
534 | if (popperRef.current) {
|
535 | popperRef.current.update();
|
536 | }
|
537 | };
|
538 | const nameOrDescProps = {};
|
539 | const titleIsString = typeof title === 'string';
|
540 | if (describeChild) {
|
541 | nameOrDescProps.title = !open && titleIsString && !disableHoverListener ? title : null;
|
542 | nameOrDescProps['aria-describedby'] = open ? id : null;
|
543 | } else {
|
544 | nameOrDescProps['aria-label'] = titleIsString ? title : null;
|
545 | nameOrDescProps['aria-labelledby'] = open && !titleIsString ? id : null;
|
546 | }
|
547 | const childrenProps = {
|
548 | ...nameOrDescProps,
|
549 | ...other,
|
550 | ...children.props,
|
551 | className: clsx(other.className, children.props.className),
|
552 | onTouchStart: detectTouchStart,
|
553 | ref: handleRef,
|
554 | ...(followCursor ? {
|
555 | onMouseMove: handleMouseMove
|
556 | } : {})
|
557 | };
|
558 | if (process.env.NODE_ENV !== 'production') {
|
559 | childrenProps['data-mui-internal-clone-element'] = true;
|
560 |
|
561 |
|
562 |
|
563 | React.useEffect(() => {
|
564 | if (childNode && !childNode.getAttribute('data-mui-internal-clone-element')) {
|
565 | console.error(['MUI: The `children` component of the Tooltip is not forwarding its props correctly.', 'Please make sure that props are spread on the same element that the ref is applied to.'].join('\n'));
|
566 | }
|
567 | }, [childNode]);
|
568 | }
|
569 | const interactiveWrapperListeners = {};
|
570 | if (!disableTouchListener) {
|
571 | childrenProps.onTouchStart = handleTouchStart;
|
572 | childrenProps.onTouchEnd = handleTouchEnd;
|
573 | }
|
574 | if (!disableHoverListener) {
|
575 | childrenProps.onMouseOver = composeEventHandler(handleMouseOver, childrenProps.onMouseOver);
|
576 | childrenProps.onMouseLeave = composeEventHandler(handleMouseLeave, childrenProps.onMouseLeave);
|
577 | if (!disableInteractive) {
|
578 | interactiveWrapperListeners.onMouseOver = handleMouseOver;
|
579 | interactiveWrapperListeners.onMouseLeave = handleMouseLeave;
|
580 | }
|
581 | }
|
582 | if (!disableFocusListener) {
|
583 | childrenProps.onFocus = composeEventHandler(handleFocus, childrenProps.onFocus);
|
584 | childrenProps.onBlur = composeEventHandler(handleBlur, childrenProps.onBlur);
|
585 | if (!disableInteractive) {
|
586 | interactiveWrapperListeners.onFocus = handleFocus;
|
587 | interactiveWrapperListeners.onBlur = handleBlur;
|
588 | }
|
589 | }
|
590 | if (process.env.NODE_ENV !== 'production') {
|
591 | if (children.props.title) {
|
592 | console.error(['MUI: You have provided a `title` prop to the child of <Tooltip />.', `Remove this title prop \`${children.props.title}\` or the Tooltip component.`].join('\n'));
|
593 | }
|
594 | }
|
595 | const popperOptions = React.useMemo(() => {
|
596 | let tooltipModifiers = [{
|
597 | name: 'arrow',
|
598 | enabled: Boolean(arrowRef),
|
599 | options: {
|
600 | element: arrowRef,
|
601 | padding: 4
|
602 | }
|
603 | }];
|
604 | if (PopperProps.popperOptions?.modifiers) {
|
605 | tooltipModifiers = tooltipModifiers.concat(PopperProps.popperOptions.modifiers);
|
606 | }
|
607 | return {
|
608 | ...PopperProps.popperOptions,
|
609 | modifiers: tooltipModifiers
|
610 | };
|
611 | }, [arrowRef, PopperProps]);
|
612 | const ownerState = {
|
613 | ...props,
|
614 | isRtl,
|
615 | arrow,
|
616 | disableInteractive,
|
617 | placement,
|
618 | PopperComponentProp,
|
619 | touch: ignoreNonTouchEvents.current
|
620 | };
|
621 | const classes = useUtilityClasses(ownerState);
|
622 | const PopperComponent = slots.popper ?? components.Popper ?? TooltipPopper;
|
623 | const TransitionComponent = slots.transition ?? components.Transition ?? TransitionComponentProp ?? Grow;
|
624 | const TooltipComponent = slots.tooltip ?? components.Tooltip ?? TooltipTooltip;
|
625 | const ArrowComponent = slots.arrow ?? components.Arrow ?? TooltipArrow;
|
626 | const popperProps = appendOwnerState(PopperComponent, {
|
627 | ...PopperProps,
|
628 | ...(slotProps.popper ?? componentsProps.popper),
|
629 | className: clsx(classes.popper, PopperProps?.className, (slotProps.popper ?? componentsProps.popper)?.className)
|
630 | }, ownerState);
|
631 | const transitionProps = appendOwnerState(TransitionComponent, {
|
632 | ...TransitionProps,
|
633 | ...(slotProps.transition ?? componentsProps.transition)
|
634 | }, ownerState);
|
635 | const tooltipProps = appendOwnerState(TooltipComponent, {
|
636 | ...(slotProps.tooltip ?? componentsProps.tooltip),
|
637 | className: clsx(classes.tooltip, (slotProps.tooltip ?? componentsProps.tooltip)?.className)
|
638 | }, ownerState);
|
639 | const tooltipArrowProps = appendOwnerState(ArrowComponent, {
|
640 | ...(slotProps.arrow ?? componentsProps.arrow),
|
641 | className: clsx(classes.arrow, (slotProps.arrow ?? componentsProps.arrow)?.className)
|
642 | }, ownerState);
|
643 | return _jsxs(React.Fragment, {
|
644 | children: [React.cloneElement(children, childrenProps), _jsx(PopperComponent, {
|
645 | as: PopperComponentProp ?? Popper,
|
646 | placement: placement,
|
647 | anchorEl: followCursor ? {
|
648 | getBoundingClientRect: () => ({
|
649 | top: cursorPosition.y,
|
650 | left: cursorPosition.x,
|
651 | right: cursorPosition.x,
|
652 | bottom: cursorPosition.y,
|
653 | width: 0,
|
654 | height: 0
|
655 | })
|
656 | } : childNode,
|
657 | popperRef: popperRef,
|
658 | open: childNode ? open : false,
|
659 | id: id,
|
660 | transition: true,
|
661 | ...interactiveWrapperListeners,
|
662 | ...popperProps,
|
663 | popperOptions: popperOptions,
|
664 | children: ({
|
665 | TransitionProps: TransitionPropsInner
|
666 | }) => _jsx(TransitionComponent, {
|
667 | timeout: theme.transitions.duration.shorter,
|
668 | ...TransitionPropsInner,
|
669 | ...transitionProps,
|
670 | children: _jsxs(TooltipComponent, {
|
671 | ...tooltipProps,
|
672 | children: [title, arrow ? _jsx(ArrowComponent, {
|
673 | ...tooltipArrowProps,
|
674 | ref: setArrowRef
|
675 | }) : null]
|
676 | })
|
677 | })
|
678 | })]
|
679 | });
|
680 | });
|
681 | process.env.NODE_ENV !== "production" ? Tooltip.propTypes = {
|
682 |
|
683 |
|
684 |
|
685 |
|
686 | |
687 |
|
688 |
|
689 |
|
690 | arrow: PropTypes.bool,
|
691 | |
692 |
|
693 |
|
694 | children: elementAcceptingRef.isRequired,
|
695 | |
696 |
|
697 |
|
698 | classes: PropTypes.object,
|
699 | |
700 |
|
701 |
|
702 | className: PropTypes.string,
|
703 | |
704 |
|
705 |
|
706 |
|
707 |
|
708 |
|
709 |
|
710 | components: PropTypes.shape({
|
711 | Arrow: PropTypes.elementType,
|
712 | Popper: PropTypes.elementType,
|
713 | Tooltip: PropTypes.elementType,
|
714 | Transition: PropTypes.elementType
|
715 | }),
|
716 | |
717 |
|
718 |
|
719 |
|
720 |
|
721 |
|
722 |
|
723 |
|
724 | componentsProps: PropTypes.shape({
|
725 | arrow: PropTypes.object,
|
726 | popper: PropTypes.object,
|
727 | tooltip: PropTypes.object,
|
728 | transition: PropTypes.object
|
729 | }),
|
730 | |
731 |
|
732 |
|
733 |
|
734 |
|
735 | describeChild: PropTypes.bool,
|
736 | |
737 |
|
738 |
|
739 |
|
740 | disableFocusListener: PropTypes.bool,
|
741 | |
742 |
|
743 |
|
744 |
|
745 | disableHoverListener: PropTypes.bool,
|
746 | |
747 |
|
748 |
|
749 |
|
750 |
|
751 | disableInteractive: PropTypes.bool,
|
752 | |
753 |
|
754 |
|
755 |
|
756 | disableTouchListener: PropTypes.bool,
|
757 | |
758 |
|
759 |
|
760 |
|
761 |
|
762 | enterDelay: PropTypes.number,
|
763 | |
764 |
|
765 |
|
766 |
|
767 | enterNextDelay: PropTypes.number,
|
768 | |
769 |
|
770 |
|
771 |
|
772 | enterTouchDelay: PropTypes.number,
|
773 | |
774 |
|
775 |
|
776 |
|
777 | followCursor: PropTypes.bool,
|
778 | |
779 |
|
780 |
|
781 |
|
782 | id: PropTypes.string,
|
783 | |
784 |
|
785 |
|
786 |
|
787 |
|
788 | leaveDelay: PropTypes.number,
|
789 | |
790 |
|
791 |
|
792 |
|
793 | leaveTouchDelay: PropTypes.number,
|
794 | |
795 |
|
796 |
|
797 |
|
798 |
|
799 | onClose: PropTypes.func,
|
800 | |
801 |
|
802 |
|
803 |
|
804 |
|
805 | onOpen: PropTypes.func,
|
806 | |
807 |
|
808 |
|
809 | open: PropTypes.bool,
|
810 | |
811 |
|
812 |
|
813 |
|
814 | placement: PropTypes.oneOf(['bottom-end', 'bottom-start', 'bottom', 'left-end', 'left-start', 'left', 'right-end', 'right-start', 'right', 'top-end', 'top-start', 'top']),
|
815 | |
816 |
|
817 |
|
818 |
|
819 | PopperComponent: PropTypes.elementType,
|
820 | |
821 |
|
822 |
|
823 |
|
824 | PopperProps: PropTypes.object,
|
825 | |
826 |
|
827 |
|
828 |
|
829 |
|
830 |
|
831 |
|
832 |
|
833 | slotProps: PropTypes.shape({
|
834 | arrow: PropTypes.object,
|
835 | popper: PropTypes.object,
|
836 | tooltip: PropTypes.object,
|
837 | transition: PropTypes.object
|
838 | }),
|
839 | |
840 |
|
841 |
|
842 |
|
843 |
|
844 |
|
845 |
|
846 | slots: PropTypes.shape({
|
847 | arrow: PropTypes.elementType,
|
848 | popper: PropTypes.elementType,
|
849 | tooltip: PropTypes.elementType,
|
850 | transition: PropTypes.elementType
|
851 | }),
|
852 | |
853 |
|
854 |
|
855 | sx: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.func, PropTypes.object, PropTypes.bool])), PropTypes.func, PropTypes.object]),
|
856 | |
857 |
|
858 |
|
859 | title: PropTypes.node,
|
860 | |
861 |
|
862 |
|
863 |
|
864 |
|
865 | TransitionComponent: PropTypes.elementType,
|
866 | |
867 |
|
868 |
|
869 |
|
870 | TransitionProps: PropTypes.object
|
871 | } : void 0;
|
872 | export default Tooltip; |
\ | No newline at end of file |