Skip to content

Commit

Permalink
feat(Tooltip): be able to change max width
Browse files Browse the repository at this point in the history
  • Loading branch information
talkor committed Dec 11, 2024
1 parent 14a51b0 commit e893dd4
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions packages/core/src/components/Tooltip/Tooltip.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint-disable react/jsx-props-no-spreading */
import { camelCase, isFunction } from "lodash-es";
import cx from "classnames";
import React, { CSSProperties, isValidElement, PureComponent, ReactElement } from "react";
import React, { CSSProperties, isValidElement, PureComponent, ReactElement, useMemo } from "react";
import { Modifier } from "react-popper";
import Dialog from "../Dialog/Dialog";
import { DialogAnimationType, DialogTriggerEvent } from "../Dialog/Dialog.types";
Expand Down Expand Up @@ -128,6 +128,10 @@ interface TooltipBaseProps extends VibeComponentProps {
* The icon of the tooltip next to the title
*/
icon?: SubIcon;
/**
* Sets the max width of the Tooltip, defaults to 240px
*/
maxWidth?: number;
}
// When last tooltip was shown in the last 1.5 second - the next tooltip will be shown immediately
const IMMEDIATE_SHOW_THRESHOLD_MS = 1500;
Expand Down Expand Up @@ -174,7 +178,7 @@ export default class Tooltip extends PureComponent<TooltipProps> {
}

renderTooltipContent() {
const { theme, content, className, style, title, image, icon } = this.props;
const { theme, content, className, style, maxWidth, title, image, icon } = this.props;
if (!content) {
// don't render empty tooltip
return null;
Expand All @@ -196,7 +200,10 @@ export default class Tooltip extends PureComponent<TooltipProps> {
}

return (
<div style={style} className={cx(styles.tooltip, getStyle(styles, camelCase(theme)), className)}>
<div
style={{ ...style, "--tooltip-max-width": `${maxWidth}px` } as CSSProperties}
className={cx(styles.tooltip, getStyle(styles, camelCase(theme)), className)}
>
{image && <img className={styles.image} src={image} alt="" />}
<div className={cx(styles.content)}>
{title && (
Expand Down

0 comments on commit e893dd4

Please sign in to comment.