1.0.0 • Published 3 years ago

react-popover-lite v1.0.0

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

react-popover-lite

A simple popover React higher-order component with zero dependencies, TypeScript support.

This popover is implemented using React Portal.

Install

yarn add react-popover-lite

or

npm install react-popover-lite --save

Examples

Demo

import React, { useState } from "react";
import Popover from "react-popover-lite";

...

const [isOpen, setOpen] = useState(false);

<Popover
  isOpen={isOpen}
  position="bottom"
  onClickOutside={() => setOpen(false)}
  content={
    <div
      style={{
        border: "1px solid black",
        padding: 10,
        width: 200,
        marginTop: 10,
      }}
    >
      this is the popover content
    </div>
  }
>
  <button onClick={() => setOpen(!isOpen)}>click here!</button>
</Popover>

API

PropsTypeRequiredDescriptionDefault
childrenReactNodeA React child which the popover's position will follow
isOpenBooleanShow/hide popoverfalse
onClickOutsideFunction: () => voidHandle event when user clicking outside of the popover
contentReactNodePopover content
zIndexNumberPopover content100
position'top' | 'right'| 'bottom'| 'left'| 'topLeft'| 'topRight'| 'bottomLeft' | 'bottomRight' | 'leftTop' | 'leftBottom' | 'rightTop' | 'rightBottom'Popover position'bottom'