Skip to content

Commit

Permalink
feat(react/tooltip): allow tooltip title to render custom element
Browse files Browse the repository at this point in the history
  • Loading branch information
travor20814 committed Jan 5, 2024
1 parent 4515e08 commit 7d3c0bb
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
21 changes: 20 additions & 1 deletion packages/react/src/Tooltip/Tooltip.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,26 @@ export const Basic = () => (
/>
)}
</Tooltip>
<Tooltip
title={(
<div style={{ display: 'flex', flexFlow: 'column' }}>
<span>Custom Element</span>
<Icon icon={InfoCircleFilledIcon} size={14} />
</div>
)}
options={{
placement: 'top-start',
}}
>
{({ onMouseEnter, onMouseLeave }) => (
<Icon
color="primary"
icon={InfoCircleFilledIcon}
onMouseEnter={onMouseEnter}
onMouseLeave={onMouseLeave}
/>
)}
</Tooltip>
<Tooltip
title="預設文字"
options={{
Expand Down Expand Up @@ -115,4 +135,3 @@ export const Placement = () => {
</div>
);
};

5 changes: 3 additions & 2 deletions packages/react/src/Tooltip/Tooltip.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
ReactElement,
MouseEventHandler,
useRef,
ReactNode,
} from 'react';
import { tooltipClasses as classes } from '@mezzanine-ui/core/tooltip';
import { StrictModifiers } from '@popperjs/core';
Expand All @@ -18,7 +19,7 @@ const offsetModifier: StrictModifiers = {
},
};

export interface TooltipProps extends Omit<PopperProps, 'children'> {
export interface TooltipProps extends Omit<PopperProps, 'children' | 'title'> {
/**
* child function that can receive events
*/
Expand All @@ -34,7 +35,7 @@ export interface TooltipProps extends Omit<PopperProps, 'children'> {
/**
* title of tooltip
*/
title?: string;
title?: ReactNode;
}

/**
Expand Down

0 comments on commit 7d3c0bb

Please sign in to comment.