New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

native-popover-react

Package Overview
Dependencies
Maintainers
0
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

native-popover-react

Native HTML popover in the form of a React component

latest
npmnpm
Version
1.1.1
Version published
Maintainers
0
Created
Source

native-popover-react

Utilize the native web Popover API in React

import { NativePopover } from "native-popover-react";

function App() {
  return (
    <NativePopover
      trigger={(props) => (
        <button {...props}>Open tooltip</button>
      )}
      popover={(props) => (
        <div {...props} className="my-popover">
          Popover content
        </div>
      )}
    />
  );
}

Controls

import {
  NativePopover,
  usePopoverControls,
} from "native-popover-react";

function App() {
  const popover = usePopoverControls<HTMLDivElement>();

  return (
    <div>
      <button onClick={popover.toggle}>
        {popover.isOpen ? "Close popover" : "Open popover"}
      </button>
      <NativePopover
        control={popover.control}
        popover={(props) => (
          <div {...props} className="my-popover">
            Popover content
          </div>
        )}
      />
    </div>
  );
}

Closing popover

You can close the popover using usePopoverControls, or by utilizing the second argument in the popover prop to create a close button:

<NativePopover
  trigger={(props) => <button {...props}>Toggle</button>}
  popover={(props, closeProps) => (
    <div {...props} className="my-popover">
      Popover content
      <button {...closeProps}>X</button>
    </div>
  )}
/>

Anchoring

[!WARNING]
Experimental: This might not be supported in all modern browsers yet.

Enable an anchor between trigger and popover.

import { NativePopover } from "native-popover-react";

function App() {
  return (
    <div>
      <NativePopover
        anchor={{
          top: "bottom", // top of popover aligned to bottom of trigger
          left: "right", // left of popover aligned to right of trigger
        }}
        trigger={(props) => <button {...props}>Toggle</button>}
        popover={(props) => (
          <div {...props}>Popover content</div>
        )}
      />
    </div>
  );
}

FAQs

Package last updated on 23 Sep 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts