UNPKG

6.9 kBTypeScriptView Raw
1import * as React from 'react';
2import { MUIStyledCommonProps, SxProps } from '@mui/system';
3import { PopperProps } from '@mui/material/Popper';
4import { InternalStandardProps as StandardProps, Theme } from '..';
5import { TransitionProps } from '../transitions/transition';
6import { TooltipClasses } from './tooltipClasses';
7
8export interface TooltipComponentsPropsOverrides {}
9
10export interface TooltipProps extends StandardProps<React.HTMLAttributes<HTMLDivElement>, 'title'> {
11 /**
12 * If `true`, adds an arrow to the tooltip.
13 * @default false
14 */
15 arrow?: boolean;
16 /**
17 * Tooltip reference element.
18 */
19 children: React.ReactElement<unknown, any>;
20 /**
21 * Override or extend the styles applied to the component.
22 */
23 classes?: Partial<TooltipClasses>;
24 /**
25 * The components used for each slot inside.
26 *
27 * @deprecated use the `slots` prop instead. This prop will be removed in v7. [How to migrate](https://mui.com/material-ui/migration/migrating-from-deprecated-apis/).
28 *
29 * @default {}
30 */
31 components?: {
32 Popper?: React.ElementType<PopperProps>;
33 Transition?: React.ElementType;
34 Tooltip?: React.ElementType;
35 Arrow?: React.ElementType;
36 };
37 /**
38 * The extra props for the slot components.
39 * You can override the existing props or add new ones.
40 *
41 * @deprecated use the `slotProps` prop instead. This prop will be removed in v7. [How to migrate](https://mui.com/material-ui/migration/migrating-from-deprecated-apis/).
42 *
43 * @default {}
44 */
45 componentsProps?: {
46 popper?: Partial<PopperProps> & TooltipComponentsPropsOverrides;
47 transition?: TransitionProps & TooltipComponentsPropsOverrides;
48 tooltip?: React.HTMLProps<HTMLDivElement> &
49 MUIStyledCommonProps &
50 TooltipComponentsPropsOverrides;
51 arrow?: React.HTMLProps<HTMLSpanElement> &
52 MUIStyledCommonProps &
53 TooltipComponentsPropsOverrides;
54 };
55 /**
56 * Set to `true` if the `title` acts as an accessible description.
57 * By default the `title` acts as an accessible label for the child.
58 * @default false
59 */
60 describeChild?: boolean;
61 /**
62 * Do not respond to focus-visible events.
63 * @default false
64 */
65 disableFocusListener?: boolean;
66 /**
67 * Do not respond to hover events.
68 * @default false
69 */
70 disableHoverListener?: boolean;
71 /**
72 * Makes a tooltip not interactive, i.e. it will close when the user
73 * hovers over the tooltip before the `leaveDelay` is expired.
74 * @default false
75 */
76 disableInteractive?: boolean;
77 /**
78 * Do not respond to long press touch events.
79 * @default false
80 */
81 disableTouchListener?: boolean;
82 /**
83 * The number of milliseconds to wait before showing the tooltip.
84 * This prop won't impact the enter touch delay (`enterTouchDelay`).
85 * @default 100
86 */
87 enterDelay?: number;
88 /**
89 * The number of milliseconds to wait before showing the tooltip when one was already recently opened.
90 * @default 0
91 */
92 enterNextDelay?: number;
93 /**
94 * The number of milliseconds a user must touch the element before showing the tooltip.
95 * @default 700
96 */
97 enterTouchDelay?: number;
98 /**
99 * If `true`, the tooltip follow the cursor over the wrapped element.
100 * @default false
101 */
102 followCursor?: boolean;
103 /**
104 * This prop is used to help implement the accessibility logic.
105 * If you don't provide this prop. It falls back to a randomly generated id.
106 */
107 id?: string;
108 /**
109 * The number of milliseconds to wait before hiding the tooltip.
110 * This prop won't impact the leave touch delay (`leaveTouchDelay`).
111 * @default 0
112 */
113 leaveDelay?: number;
114 /**
115 * The number of milliseconds after the user stops touching an element before hiding the tooltip.
116 * @default 1500
117 */
118 leaveTouchDelay?: number;
119 /**
120 * Callback fired when the component requests to be closed.
121 *
122 * @param {React.SyntheticEvent} event The event source of the callback.
123 */
124 onClose?: (event: React.SyntheticEvent | Event) => void;
125 /**
126 * Callback fired when the component requests to be open.
127 *
128 * @param {React.SyntheticEvent} event The event source of the callback.
129 */
130 onOpen?: (event: React.SyntheticEvent) => void;
131 /**
132 * If `true`, the component is shown.
133 */
134 open?: boolean;
135 /**
136 * Tooltip placement.
137 * @default 'bottom'
138 */
139 placement?:
140 | 'bottom-end'
141 | 'bottom-start'
142 | 'bottom'
143 | 'left-end'
144 | 'left-start'
145 | 'left'
146 | 'right-end'
147 | 'right-start'
148 | 'right'
149 | 'top-end'
150 | 'top-start'
151 | 'top';
152 /**
153 * The component used for the popper.
154 * @default Popper
155 */
156 PopperComponent?: React.JSXElementConstructor<PopperProps>;
157 /**
158 * Props applied to the [`Popper`](https://mui.com/material-ui/api/popper/) element.
159 * @default {}
160 */
161 PopperProps?: Partial<PopperProps>;
162 /**
163 * The extra props for the slot components.
164 * You can override the existing props or add new ones.
165 *
166 * This prop is an alias for the `componentsProps` prop, which will be deprecated in the future.
167 *
168 * @default {}
169 */
170 slotProps?: {
171 popper?: Partial<PopperProps> & TooltipComponentsPropsOverrides;
172 transition?: TransitionProps & TooltipComponentsPropsOverrides;
173 tooltip?: React.HTMLProps<HTMLDivElement> &
174 MUIStyledCommonProps<Theme> &
175 TooltipComponentsPropsOverrides;
176 arrow?: React.HTMLProps<HTMLSpanElement> &
177 MUIStyledCommonProps<Theme> &
178 TooltipComponentsPropsOverrides;
179 };
180 /**
181 * The components used for each slot inside.
182 *
183 * This prop is an alias for the `components` prop, which will be deprecated in the future.
184 *
185 * @default {}
186 */
187 slots?: {
188 popper?: React.ElementType<PopperProps>;
189 transition?: React.ElementType;
190 tooltip?: React.ElementType;
191 arrow?: React.ElementType;
192 };
193 /**
194 * The system prop that allows defining system overrides as well as additional CSS styles.
195 */
196 sx?: SxProps<Theme>;
197 /**
198 * Tooltip title. Zero-length titles string, undefined, null and false are never displayed.
199 */
200 title: React.ReactNode;
201 /**
202 * The component used for the transition.
203 * [Follow this guide](https://mui.com/material-ui/transitions/#transitioncomponent-prop) to learn more about the requirements for this component.
204 * @default Grow
205 */
206 TransitionComponent?: React.JSXElementConstructor<
207 TransitionProps & { children: React.ReactElement<unknown, any> }
208 >;
209 /**
210 * Props applied to the transition element.
211 * By default, the element is based on this [`Transition`](https://reactcommunity.org/react-transition-group/transition/) component.
212 */
213 TransitionProps?: TransitionProps;
214}
215
216/**
217 *
218 * Demos:
219 *
220 * - [Tooltip](https://mui.com/material-ui/react-tooltip/)
221 *
222 * API:
223 *
224 * - [Tooltip API](https://mui.com/material-ui/api/tooltip/)
225 */
226export default function Tooltip(props: TooltipProps): React.JSX.Element;