mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-13 04:48:53 +00:00
68 lines
1.5 KiB
TypeScript
68 lines
1.5 KiB
TypeScript
import type { PopperUnstyledProps } from '@mui/base/PopperUnstyled';
|
|
import Grow from '@mui/material/Grow';
|
|
import type { CSSProperties, PropsWithChildren } from 'react';
|
|
import { useState } from 'react';
|
|
|
|
import { PopperArrow } from './PopoverArrow';
|
|
import { BasicStyledPopper } from './Popper';
|
|
import { PopperWrapper } from './styles';
|
|
|
|
export type PurePopperProps = {
|
|
zIndex?: CSSProperties['zIndex'];
|
|
|
|
offset?: [number, number];
|
|
|
|
showArrow?: boolean;
|
|
} & PopperUnstyledProps &
|
|
PropsWithChildren;
|
|
|
|
export const PurePopper = (props: PurePopperProps) => {
|
|
const {
|
|
children,
|
|
zIndex,
|
|
offset,
|
|
showArrow = false,
|
|
modifiers = [],
|
|
placement,
|
|
...otherProps
|
|
} = props;
|
|
const [arrowRef, setArrowRef] = useState<HTMLElement | null>();
|
|
|
|
// @ts-ignore
|
|
return (
|
|
<BasicStyledPopper
|
|
zIndex={zIndex}
|
|
transition
|
|
modifiers={[
|
|
{
|
|
name: 'offset',
|
|
options: {
|
|
offset,
|
|
},
|
|
},
|
|
{
|
|
name: 'arrow',
|
|
enabled: showArrow,
|
|
options: {
|
|
element: arrowRef,
|
|
},
|
|
},
|
|
...modifiers,
|
|
]}
|
|
placement={placement}
|
|
{...otherProps}
|
|
>
|
|
{({ TransitionProps }) => (
|
|
<Grow {...TransitionProps}>
|
|
<PopperWrapper>
|
|
{showArrow && (
|
|
<PopperArrow placement={placement} ref={setArrowRef} />
|
|
)}
|
|
{children}
|
|
</PopperWrapper>
|
|
</Grow>
|
|
)}
|
|
</BasicStyledPopper>
|
|
);
|
|
};
|