mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-07-11 07:06:28 +08:00
41 lines
1.2 KiB
TypeScript
41 lines
1.2 KiB
TypeScript
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';
|
|
|
|
const useTooltipStyle = (): CSSProperties => {
|
|
const theme = useTheme();
|
|
return {
|
|
backgroundColor: theme.affine.palette.icons,
|
|
color: theme.affine.palette.white,
|
|
...theme.affine.typography.tooltip,
|
|
padding: '4px 8px',
|
|
};
|
|
};
|
|
|
|
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
|
|
{...visibleProp}
|
|
placement="top"
|
|
{...props}
|
|
showArrow={false}
|
|
content={
|
|
<PopoverContainer
|
|
style={style}
|
|
direction={placementToContainerDirection[placement]}
|
|
>
|
|
{content}
|
|
</PopoverContainer>
|
|
}
|
|
/>
|
|
);
|
|
};
|