1.0.6 • Published 2 years ago

@jdthornton/modalprovider v1.0.6

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

@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>
  )
}