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-clean-modal

v0.2.2

Published

<h1 align="center"> <br> <a href="https://github.com/audreydiez/react-clean-modal/blob/main/src/assets/logo_modal.svg"> <img src="https://github.com/audreydiez/react-clean-modal/blob/main/src/assets/logo_modal.svg" alt="react-clean-modal" width="200">

Downloads

30

Readme

Live examples

You can see code examples here. You can see live demo here.

Key Features

  • Modal Portal: insert your own content inside the modal
  • Custom buttons: Use array with your buttons (event handling available)
  • Custom footer: add a footer with your button and align them
  • Close: with icon on top, on overlay click or/and on mouse scroll
  • Animations: Overlay fade-in and modal show-up
  • Custom props: add aria-label, data-testid, and custom css classes

How To Use

To use the modal plugin:

# in your project root terminal
$ npm i react-clean-modal

Contributing/Fork : you'll need Git and Node.js (which comes with npm) installed on your computer. From your command line:

# Install dependencies
$ npm install

# Run the app
$ npm run start

Documentation

Import Modal component and the hook useModal. Props isVisible and hide are required.

import React from 'react'
import { Modal, useModal } from 'react-clean-modal'

function App() {
    const { isShowing: showModal, toggle: toggleModal } = useModal()
    return (
        <>
            <button type="button" className="btn" onClick={toggleModal}>
                Open me!
            </button>

            <Modal isVisible={showModal} hide={toggleModal}>
                // Your content
                <h1>Title</h1>
                <div>Content</div>
                <button type="button" className="btn-clean-modal" onClick={toggleModal}>
                    Close me!
                </button>
            </Modal>
        </>
    )
}

Custom footer

You can pass an array with button (custom classes, content and event function) to display a modal footer.

import React from 'react'
import { Modal, useModal } from 'react-clean-modal'

function App() {
    const { isShowing: showModal, toggle: toggleModal } = useModal()

    const customEvent = () => {
        alert('Ah')
    }
    const arrayOfBtn = [
        {
            text: 'Close modal',
            className: 'btn-clean-modal'
        },
        {
            text: 'Alert me!',
            className: 'btn-clean-modal',
            eventHandling: customEvent
        }
    ]
    return (
        <>
            <button type="button" className="btn" onClick={toggleModal}>
                Open me!
            </button>

            <ReactCleanModal
                isVisible={showModal}
                hide={toggleModal}
                customFooter={arrayOfBtn}
                customFooterAlign={'left'}>
                // Your content
                <h1>Title</h1>
                <div>Content</div>
            </ReactCleanModal>
        </>
    )
}

Waiting with spinner

You can show a spinner when you waiting for async function. the modal toggle will hide spinner automatically. In your function, launch spinner, get data and launch modal.

import React from 'react'
import { Modal, useModal } from 'react-clean-modal'

function App() {
    const {
        isShowing: showModal,
        toggle: toggleModal,
        isShowingSpinner: showSpinner,
        toggleSpinner: toggleSpinner
    } = useModal()

    const launchModalTimer = () => {
        toggleSpinner()

        setTimeout(() => {
            toggleClassicModal()
        }, 3000)
    }

    return (
        <>
            <button type="button" className="btn" onClick={launchModalTimer}>
                Open me!
            </button>

            <ReactCleanModal isVisible={showModal} hide={toggleModal} showSpinner={showSpinner}>
                // Your content
                <h1>Title</h1>
                <div>Content</div>
            </ReactCleanModal>
        </>
    )
}

All props

| Prop | Type | Required? | Default | Description | | ------------------- | ------------ | ------------ | -------------------- | ------------------------------------------------------------------------------------- | | isVisible | boolean | required | false | Event handler for modal (custom hook). | | hide | function | required | Hook to toggle modal | Event handler for modal (custom hook). | | animations | boolean | optional | false | true: fade-in and show-up animation. | | ariaLabelledBy | string | optional | - | ariaLabelledBy={'aria-label'} set in the modal container, linked with your own title. | | closeOnOverlayClick | boolean | optional | false | true: Modal will close on overlay click. | | closeOnScroll | boolean | optional | false | true: Modal will close on mouse scroll. | | closeOnTop | boolean | optional | false | true: Icon on right top displayed for close modal. | | customClass | string | optional | - | Add a custom class to all HTML class attributes for override styles. | | customFooter | Array.Object | optional | - | Add your buttons with proper event to the modal footer. | | customFooterAlign | string | optional | 'center' | Align your buttons array ('left', 'center','right'). | | testId | string | optional | - | Add data-testid attribute to the modal container for tests. | | showSpinner | boolean | optional | false | Update modal display with custom hook. See example above. |

Credits

This software uses the following open source packages:

Contribute

You want to contribute ?

You can read this: CONTRIBUTING.md. Contributors wanted :)

Contact

Audrey Diez - @Linkedin - [email protected]