fix(ui): tooltip style #505

This commit is contained in:
alt1o
2022-07-28 16:54:28 +08:00
parent 1dfb241eee
commit b5d2d063a5
2 changed files with 16 additions and 10 deletions

View File

@@ -4,7 +4,7 @@ import { type PopperHandler, Popper } from '../popper';
import { PopoverContainer } from './container'; import { PopoverContainer } from './container';
import type { PopoverProps, PopoverDirection } from './interface'; import type { PopoverProps, PopoverDirection } from './interface';
const placementToContainerDirection: Record< export const placementToContainerDirection: Record<
PopperPlacementType, PopperPlacementType,
PopoverDirection PopoverDirection
> = { > = {

View File

@@ -1,10 +1,6 @@
import React, { import { forwardRef, type PropsWithChildren, type CSSProperties } from 'react';
forwardRef,
type PropsWithChildren,
type CSSProperties,
useState,
} from 'react';
import { type PopperHandler, type PopperProps, Popper } from '../popper'; import { type PopperHandler, type PopperProps, Popper } from '../popper';
import { PopoverContainer, placementToContainerDirection } from '../popover';
import type { TooltipProps } from './interface'; import type { TooltipProps } from './interface';
import { useTheme } from '../theme'; import { useTheme } from '../theme';
@@ -15,7 +11,6 @@ const useTooltipStyle = (): CSSProperties => {
color: theme.affine.palette.white, color: theme.affine.palette.white,
...theme.affine.typography.tooltip, ...theme.affine.typography.tooltip,
padding: '4px 8px', padding: '4px 8px',
borderRadius: theme.shape.borderRadius,
}; };
}; };
@@ -23,14 +18,25 @@ export const Tooltip = forwardRef<
PopperHandler, PopperHandler,
PropsWithChildren<PopperProps & TooltipProps> PropsWithChildren<PopperProps & TooltipProps>
>((props, ref) => { >((props, ref) => {
const { content, placement = 'top-start' } = props;
const style = useTooltipStyle(); const style = useTooltipStyle();
// 如果没有内容,则永远隐藏
const visibleProp = content ? {} : { visible: false };
return ( return (
<Popper <Popper
ref={ref} ref={ref}
popoverStyle={style} {...visibleProp}
placement="top" placement="top"
showArrow
{...props} {...props}
showArrow={false}
content={
<PopoverContainer
style={style}
direction={placementToContainerDirection[placement]}
>
{content}
</PopoverContainer>
}
/> />
); );
}); });