@jdthornton/modalprovider
TypeScript icon, indicating that this package has built-in type declarations

1.0.6 • Public • Published

@jdthornton/modalprovider

npm (scoped) npm bundle size (minified)

React modal context provider with hooks for easy usability.

Install

$ npm install @jdthornton/modalprovider

Usage

import ModalProvider, { createModal, useModalHandlers } from "@jdthornton/modalprovider";
import Modal from "@jdthornton/animated-modal";
import '@jdthornton/animated-modal/styles.css';

function ModalButton({ modalKey, children }){
  const { open } = useModalHandlers(modalKey)
  return(
    <button onClick={open} type="button">{children}</button>
  )
}

function WelcomeModal({ modalKey }){
  const modal = createModal(modalKey);

  return(
    <AnimatedModal isOpen={modal.isOpen} close={modal.close}>
      Welcome
    </AnimatedModal>
  )
}

function App(){

  return(
    <ModalProvider>
      <ModalButton modalKey="welcome">Open</ModalButton>
      <WelcomeModal modalKey="welcome" />
    </ModalProvider>
  )
}

/@jdthornton/modalprovider/

    Package Sidebar

    Install

    npm i @jdthornton/modalprovider

    Weekly Downloads

    0

    Version

    1.0.6

    License

    MIT

    Unpacked Size

    22.3 kB

    Total Files

    29

    Last publish

    Collaborators

    • jdthornton