usmangurowa / rcal

A React click away listener component.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

React Click Away Listener (rcal)

npm version

license

A simple react click away listener component for React applications.

Installation

Install the package using npm:

npm install @usmangurowa/rcal

Install the package using yarn:

yarn add @usmangurowa/rcal

Usage

Here's a basic example of how to use @usmangurowa/rcal:

import React from "react";
import ClickAwayListener from "@usmangurowa/rcal";

const App = () => {
  const [open, setOpen] = React.useState(false);
  return (
    <ClickAwayListener as={"ul"} onClickAway={() => setOpen(false)}>
      {/* Your component  */}
    </ClickAwayListener>
  );
};

export default App;

API

ClickAwayListener

The ClickAwayListener component listen to click events outside of it.

Props:

  • as (optional): element to render as ul, div, button, e.t.c.
  • onClickAway: function to trigger when clicked outside is detected.
  • ...props : all other props like className, style, e.t.c.

Contributing

Contributions are welcome! Feel free to open an issue or submit a pull request.

About

A React click away listener component.


Languages

Language:TypeScript 100.0%