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 🙏

© 2026 – Pkg Stats / Ryan Hefner

alexandretoullec-react-ts-modal

v0.0.4

Published

React custom Modal component

Readme

Installation

Please use Visual Studio Code as IDE for better compatibility

You can use Node V16 or higher version to install this component.

To install, you can use npm, yarn or pnpm.

$ npm install alexandretoullec-react-ts-modal
$ yarn add alexandretoullec-react-ts-modal
$ pnpm add alexandretoullec-react-ts-modal

documentation

To use the modal, you will need to import the custom hook useModal() along with the modal component itself. The only required props are isOpen and closeModal, which indicates whether the modal should be displayed, and a function to close the modal. The following is an example of using the modal specifying all the possible props:

import { Modal, useModal } from 'julie-react-ts-modal'

function App() {

const { isOpen, openModal, closeModal, handleEscClose } = useModal()

const onAfterCloseFunction = () => { console.log('Modal closed') }

return (

<button onClick={() => openModal()}>

<Modal

isOpen={

isOpen

/* State variable (boolean) stored in the useModal hook, describing if the modal should be shown or not.*/}

closeModal={

closeModal

/* Function to close the modal from the useModal hook*/}

modalVisible={

'visible'

/* String (default: 'visible') className of the modal when it is visible (controls opacity and visibility)*/}

showClose={

true

/* Boolean (default: true) indicating if the close button is displayed*/}

closeText={

'Close'

/* String (default: 'Close') containing the text displayed in the close button */}

handleEscClose={

handleEscClose

/* Function closing the modal by pressing the escape key*/}

clickOverlayClose={

true

/* Boolean (default: true) indicating if the modal can be closed by clicking on the overlay*/}

onAfterClose={

onAfterCloseFunction

/* Function (default: null) to be executed after the modal has been closed*/}

afterCloseEventDelay={

500

/* Number (default: 0) indicating the delay in ms before the onAfterClose function is executed*/}

modalClass={

'modalClassName'

/*String (default: undefined) additional className for the modal div*/}

overlayClass={

'overlayClassName'

/*String (default: undefined) additional className for the modal overlay div*/}

modalTitle={

'Modal Title'

/* String (default: undefined) containing the title of the modal*/}

textContent={

'Example text content'

/* String (default: undefined) containing the text to be displayted inside the modal content div*/}

htmlContent={

'<div>Insert HTML</div>'

/* String (default: null) containing some HTML content to be displayed in the modal content div*/}

ChildComponent={

<ChildComponent props={'componentProps'} />

/* React Component (default: null) to be displayed inside the modal content div*/}

animationClass={

'fade'

/* String (default: 'fade') className to be applied to the modal when it is opened or closed*/}

animationDuration={

'0.3s'

/* String (default: '0.3s') duration of the open/close animation*/}

showSpinner={

true

/* Boolean (default: false) indicating if a spinner should be displayed while the modal is opening*/}

customSpinner={

'<div>Loading...</div>'

/* String (default: undefined) containing some HTML content to be displayed as a custom spinner*/}

spinnerDuration={

2000

/* Number (default: 1000) in ms indicating the duration during which the spinner is displayed before the modal content appears*/}

/>

)

}

Example

Here is a simple example of the modal being used in an app.

import React from 'react'
import ReactDOM from 'react-dom/client'
import { Modal, useModal } from 'alexandretoullec-react-ts-modal'
import 'alexandretoullec-react-ts-modal/dist/index.css' // if you are using Next, place this import in your _app.js or _app.ts file.

function App() {
  // if you only need one modal, use this hook
  const { isOpen, openModal, closeModal, handleEscClose } = useModal()

  // if you need more than one modal, you need to use different names for the hooks.
  // for example, if you have a confirmation modal and a modal with a form, you can do this:
  const {
    isOpen: isOpenForm,
    openModal: openModalForm,
    closeModal: closeModalForm,
    handleEscClose: handleEscCloseForm
  } = useModal()
  const {
    isOpen: isOpenConfirm,
    openModal: openModalConfirm,
    closeModal: closeModalConfirm,
    handleEscClose: handleEscCloseConfirm
  } = useModal()

  return (
    <div>
      <button onClick={() => openModal()}>
      {/*in the case of multiple modals, use your custom name for the function:
      <button onClick={() => openModalConfirm()}>
      <button onClick={() => openModalForm()}>*/}
      <Modal
        isOpen={isOpen} {/* use custom name for multiple modals*/}
        closeModal={closeModal} {/* use custom name for multiple modals*/}
        handleEscClose={handleEscClose} {/* use custom name for multiple modals*/}
        modalTitle={"My custom modal"}
        textContent={"Lorem ipsum dolor sit amet"}
      />
    </div>
  );
}

const root = ReactDOM.createRoot(document.getElementById('root') as HTMLElement)
root.render(
  <React.StrictMode>
    <App />
  </React.StrictMode>
)