feat: add tooltip & popover

This commit is contained in:
QiShaoXuan
2022-10-17 18:01:09 +08:00
parent 7eb1bbb5e9
commit 73d7709e54
10 changed files with 671 additions and 3 deletions

View File

@@ -0,0 +1,62 @@
import { type CSSProperties, type PropsWithChildren } from 'react';
import { PopoverContainer } from './Container';
import { Popper, type PopperProps } from '../popper';
import { useTheme } from '@/styles';
import type { PopperPlacementType, TooltipProps } from '@mui/material';
import type { PopoverDirection } from './interface';
export const placementToContainerDirection: Record<
PopperPlacementType,
PopoverDirection
> = {
top: 'none',
'top-start': 'left-bottom',
'top-end': 'right-bottom',
right: 'none',
'right-start': 'left-top',
'right-end': 'left-bottom',
bottom: 'none',
'bottom-start': 'left-top',
'bottom-end': 'right-top',
left: 'none',
'left-start': 'right-top',
'left-end': 'right-bottom',
auto: 'none',
'auto-start': 'none',
'auto-end': 'none',
};
const useTooltipStyle = (): CSSProperties => {
const theme = useTheme();
return {};
// return {
// backgroundColor: theme.affine.palette.icons,
// color: theme.affine.palette.white,
// ...theme.affine.typography.tooltip,
// padding: '4px 8px',
// };
};
export const Tooltip = (
props: PropsWithChildren<PopperProps & Omit<TooltipProps, 'title'>>
) => {
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>
}
/>
);
};