Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: update inner to body #489

Merged
merged 1 commit into from
Dec 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,8 @@ Online demo: <https://react-component.github.io/tooltip/demo>
| align | object | | align config of tooltip. Please ref demo for usage example |
| showArrow | boolean \| object | false | whether to show arrow of tooltip |
| zIndex | number | | config popup tooltip zIndex |
| classNames | classNames?: { root?: string; inner?: string;}; | | Semantic DOM class |
| styles | styles?: {root?: React.CSSProperties;inner?: React.CSSProperties;}; | | Semantic DOM styles |
| classNames | classNames?: { root?: string; body?: string;}; | | Semantic DOM class |
| styles | styles?: {root?: React.CSSProperties;body?: React.CSSProperties;}; | | Semantic DOM styles |

## Important Note

Expand Down
6 changes: 3 additions & 3 deletions src/Popup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,17 @@ export interface ContentProps {
overlayInnerStyle?: React.CSSProperties;
className?: string;
style?: React.CSSProperties;
innerClassName?: string;
bodyClassName?: string;
}

export default function Popup(props: ContentProps) {
const { children, prefixCls, id, overlayInnerStyle: innerStyle, innerClassName, className, style } =
const { children, prefixCls, id, overlayInnerStyle: innerStyle, bodyClassName, className, style } =
props;

return (
<div className={classNames(`${prefixCls}-content`, className)} style={style}>
<div
className={classNames(`${prefixCls}-inner`, innerClassName)}
className={classNames(`${prefixCls}-inner`, bodyClassName)}
id={id}
role="tooltip"
style={innerStyle}
Expand Down
10 changes: 5 additions & 5 deletions src/Tooltip.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export interface TooltipProps
showArrow?: boolean | ArrowType;
arrowContent?: React.ReactNode;
id?: string;
/** @deprecated Please use `styles={{ inner: {} }}` */
/** @deprecated Please use `styles={{ body: {} }}` */
overlayInnerStyle?: React.CSSProperties;
zIndex?: number;
styles?: TooltipStyles;
Expand All @@ -52,12 +52,12 @@ export interface TooltipProps

export interface TooltipStyles {
root?: React.CSSProperties;
inner?: React.CSSProperties;
body?: React.CSSProperties;
}

export interface TooltipClassNames {
root?: string;
inner?: string;
body?: string;
}

export interface TooltipRef extends TriggerRef {}
Expand Down Expand Up @@ -104,8 +104,8 @@ const Tooltip = (props: TooltipProps, ref: React.Ref<TooltipRef>) => {
key="content"
prefixCls={prefixCls}
id={id}
innerClassName={tooltipClassNames?.inner}
overlayInnerStyle={{ ...overlayInnerStyle, ...tooltipStyles?.inner }}
bodyClassName={tooltipClassNames?.body}
overlayInnerStyle={{ ...overlayInnerStyle, ...tooltipStyles?.body }}
>
{overlay}
</Popup>
Expand Down
10 changes: 5 additions & 5 deletions tests/index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -253,12 +253,12 @@ describe('rc-tooltip', () => {
});
it('should apply custom styles to Tooltip', () => {
const customClassNames = {
inner: 'custom-inner',
body: 'custom-body',
root: 'custom-root',
};

const customStyles = {
inner: { color: 'red' },
body: { color: 'red' },
root: { backgroundColor: 'blue' },
};

Expand All @@ -269,14 +269,14 @@ describe('rc-tooltip', () => {
);

const tooltipElement = container.querySelector('.rc-tooltip') as HTMLElement;
const tooltipInnerElement = container.querySelector('.rc-tooltip-inner') as HTMLElement;
const tooltipBodyElement = container.querySelector('.rc-tooltip-inner') as HTMLElement;

// 验证 classNames
expect(tooltipElement.classList).toContain('custom-root');
expect(tooltipInnerElement.classList).toContain('custom-inner');
expect(tooltipBodyElement.classList).toContain('custom-body');

// 验证 styles
expect(tooltipElement.style.backgroundColor).toBe('blue');
expect(tooltipInnerElement.style.color).toBe('red');
expect(tooltipBodyElement.style.color).toBe('red');
});
});
Loading