@reacted/use-popper
v1.0.5
Published
基于popperjs的弹层hook
Downloads
6
Readme
@reacted/use-popper
基于 popper.js 的 自定义 React hooks,方便用来显示弹层
API
// targetRef是用来定位的参考点,比如点击一个按钮
// placement, 位置规则
const { show, setShow, mountNode } = usePopper({
targetRef,
placement,
});
if (show) createPortal(<Popup />, mountNode);
return null;
targetRef
定位参考元素,可以是一个 htmlelement, 也可以是一个 virtualElment
virtualElement
type VirtualElement = {|
getBoundingClientRect: () => ClientRect | DOMRect,
contextElement?: Element,
|};
contextElement
contextElement is an optional property that describes the DOM context of the virtual element. This is necessary if getBoundingClientRect is derived from a real DOM element, and that element is within a different scrolling container context to the popper element.