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

@nitatemic/reactmodal

v1.0.12

Published

React Modal

Downloads

3

Readme

@nitatemic/reactmodal

npm version

A simple modal component for React.

Installation

You can install the package using npm or yarn:

npm install @nitatemic/reactmodal

or

yarn add @nitatemic/reactmodal

Usage

import React, { useState } from 'react';
import Modal from '@nitatemic/reactmodal';

const App = () => {
    const [modalOpen, setModalOpen] = useState(false);

    const openModal = () => {
        setModalOpen(true);
    };

    const closeModal = () => {
        setModalOpen(false);
    };
    /* If you want to close the modal when the user clicks outside of it, you can use the following code: */
    useEffect(() => {
        const handleOutsideClick = (event) => {
            if (event.target.classList.contains('modal-overlay')) {
                closeModal();
            }
        };

        if (modalOpen) {
            document.addEventListener('click', handleOutsideClick);
        }

        return () => {
            document.removeEventListener('click', handleOutsideClick);
        };
    }, [modalOpen]);

    /* End of code to close the modal when the user clicks outside of it */
    
    return (
        <div>
            <button onClick={openModal}>Open Modal</button>
            {modalOpen && (
                <Modal isOpen={modalOpen} onClose={closeModal} displayCross={true}>
                    <h2 className="title-modal">Modal content</h2>
                    <p className="content-modal">This is the content of the modal.</p>
                </Modal>
            )}
        </div>
    );
};

export default App;

Open in StackBlitz

Styling

The Modal component provides a default styling, but you can customize it to fit your application's design. Here is the default CSS that you can override:

.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-background {
    background-color: #fff;
    border-radius: 4px;
    padding: 20px;
    max-width: 400px;
    max-height: 80vh;
    overflow-y: auto;
}

.modal-cross {
    position: absolute;
    top: 10px;
    right: 10px;
    background: none;
    border: none;
    font-size: 24px;
    cursor: pointer;
}

Props

The Modal component accepts the following props:

  • isOpen (boolean): Determines whether the modal is open or closed.
  • onClose (function): Callback function to be executed when the modal is closed.
  • displayCross (boolean): Determines whether to display the cross icon to close the modal. (If you prefer to use your own close button, set this to false.

License

This project is licensed under the MIT License - see the LICENSE file for details.