refactor: refactor popper

This commit is contained in:
QiShaoXuan
2022-08-12 18:49:47 +08:00
parent 82c3d773d6
commit f16bfecab8
8 changed files with 188 additions and 205 deletions
+6 -8
View File
@@ -1,5 +1,5 @@
import { forwardRef, type PropsWithChildren, type CSSProperties } from 'react';
import { type PopperHandler, type PopperProps, Popper } from '../popper';
import { type PropsWithChildren, type CSSProperties } from 'react';
import { type PopperProps, Popper } from '../popper';
import { PopoverContainer, placementToContainerDirection } from '../popover';
import type { TooltipProps } from './interface';
import { useTheme } from '../theme';
@@ -14,17 +14,15 @@ const useTooltipStyle = (): CSSProperties => {
};
};
export const Tooltip = forwardRef<
PopperHandler,
PropsWithChildren<PopperProps & TooltipProps>
>((props, ref) => {
export const Tooltip = (
props: PropsWithChildren<PopperProps & TooltipProps>
) => {
const { content, placement = 'top-start' } = props;
const style = useTooltipStyle();
// If there is no content, hide forever
const visibleProp = content ? {} : { visible: false };
return (
<Popper
ref={ref}
{...visibleProp}
placement="top"
{...props}
@@ -39,4 +37,4 @@ export const Tooltip = forwardRef<
}
/>
);
});
};