npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

react-overlay-provider

v1.0.4

Published

`react-overlay-manager` is a flexible and lightweight solution for managing modals, drawers, and other overlay components in React applications. It is built on top of Ant Design but can be easily extended to support other overlay types.

Downloads

155

Readme

React Overlay Manager

react-overlay-manager is a flexible and lightweight solution for managing modals, drawers, and other overlay components in React applications. It is built on top of Ant Design but can be easily extended to support other overlay types.

Key Features

  • Centralized Overlay Management:
    Manage all overlays in a single place. No need to handle state or visibility of each overlay individually in your components.

  • UI Library Agnostic:
    The overlay system works independently of the UI library used in your project. While this readme uses Ant Design (with Modal and Drawer), you can easily integrate it with Material UI, Tailwind, or any other UI framework.

  • Minimal Re-Renders & Side Effects:
    By reducing unnecessary re-renders, the package ensures high performance, even with multiple overlays. Side effects are contained within the overlays, preventing them from affecting other parts of the application.

  • Simple API:
    Use the useOverlay hook to open or close overlays easily, while customizing their behavior with simple configuration options.

  • Scalable & Customizable:
    Add, update, or remove overlays with minimal effort. Each overlay is highly configurable, and the solution scales effortlessly with your application's needs.

  • Error Handling:
    Robust error handling ensures the system doesn’t break if an overlay handler is missing or an error occurs, making it more reliable for production environments.

Installation

Install the package using npm or yarn:

npm install react-overlay-manager

Setup

Wrap your application in the OverlayProvider and define the overlays you want to use. Each overlay is defined with a unique overlayName and a corresponding React component.

import { Drawer, Modal } from 'antd';
import { OverlayProvider } from 'react-overlay-manager';

const App = () => {
  return (
    <OverlayProvider
      overlays={[
        {
          overlayName: 'modal',
          Overlay: ({ open, Element, config }) => (
            <Modal open={open} {...config}>
              <Element />
            </Modal>
          ),
        },
        {
          overlayName: 'drawer',
          Overlay: ({ open, Element, config }) => (
            <Drawer open={open} {...config}>
              <Element />
            </Drawer>
          ),
        },
      ]}
    >
      {/* UI */}
    </OverlayProvider>
  );
};

Usage

Use the useOverlay hook to control overlays dynamically. The open function allows you to open a specific overlay with a custom element and configuration, while the close function closes it.

import { DrawerProps, ModalProps } from 'antd';
import { OverlayProvider } from 'react-overlay-manager';

const SomeElement = ({ fname }: { fname: string }) => {
  return <div>Hello, {fname}!</div>;
};


const HomePage = () => {
  const { open, close } = useOverlay();

  return (
    <div>

      <button
        onClick={() => {
          open<ModalProps>('modal', <SomeElement fname="John" />, {
            closable: true,
            onCancel: () => close('modal'),
            width: 700,
          });
        }}
      >
        Open Large Modal
      </button>

      <button
        onClick={() => {
          open<ModalProps>('modal', <SomeElement fname="John" />, {
            closable: true,
            onCancel: () => close('modal'),
            width: 400,
          });
        }}
      >
        Open Small Modal
      </button>

      <button
        onClick={() => {
          open<DrawerProps>('drawer', <SomeElement fname="John" />, {
            closable: true,
            width: 300,
          });
        }}
      >
        Open Drawer
      </button>

    </div>
  );
};

In this example, I have used Ant Design to demonstrate how to implement overlays such as modals and drawers. However, the solution is highly flexible and can be extended to support other UI libraries, such as Material UI or any other UI library of your choice. You can easily swap the components (e.g., Modal or Drawer) with equivalent ones from your preferred UI library by updating the Overlay components within the OverlayProvider. The core logic remains the same, allowing you to seamlessly integrate with different UI frameworks while keeping the overlay management centralized.