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

react-modal-observer

Package Overview
Dependencies
Maintainers
0
Versions
19
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-modal-observer

Package to handle modals in react with javascript observer pattern.

latest
Source
npmnpm
Version
0.9.69
Version published
Weekly downloads
1
Maintainers
0
Weekly downloads
 
Created
Source

React Modal Observer

React modal observer allows you to create a modal from anywhere without using context and passing down props to the component, with just a function!

Installation

$ npm install --save react-modal-observer
$ yarn add react-modal-observer

Features

  • It works with lazy loading
  • You can pass down props to the modal component
  • Typescript support: It will infer the props of the modal component
  • You can set default styles for the modal container and overwrite them in the addModal function
  • You can set a custom animation for the modal
  • You can set a spinner component to show while the modal is loading

Usage

import React from 'react'
import { Modals, addModal } from 'react-modal-observer'

export default function App() {
  const handleOpen = () => {
    addModal(TestModal, { description: 'This is a test modal' }, { backgroundColor: 'green' })
  }

  return (
    <>
      <main>
        <button onClick={handleOpen}>Open Modal</button>
      </main>

      <Modals
        backgroundColor="rgba(0, 0, 0, 0.5)"
        duration={250} // miliseconds
        /* NOTE: You can't use `animationType` at the same time as `customAnimation`. */
        animationType="fade" // 'none' | 'fade' | 'fade-with-scale' | 'slide-left' | 'slide-right'
        noScroll={true} // Prevents html scrolling when the modal is open
        timingFunction="ease"
        Spinner={<div className='spinner' />} // Component to show while the modal is loading
        customAnimation={
          parentClassName: 'page-center' // .page-center: { justify-content: center }
          classNames: {
            enter: 'custom-enter',
            enterActive: 'custom-enter-active',
            exit: 'custom-exit',
            exitActive: 'custom-exit-active',
          }
        }
      />
    </>
  )
}

const TestModal = ({ description, closeModal }) => {
  return (
    <div>
      <button onClick={closeModal}>Close Modal</button>
      <h1>Test Modal</h1>
      {description}
    </div>
  )
}

FAQs

Package last updated on 28 Feb 2025

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