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

v1.0.5

Published

Responsive and customizable modal with fade effect

Downloads

3

Readme

React Fade Modal

Responsive react modal with fade in-out effect included without any external libraries.

works with: React >= 16.8

Motivation

Most famous react modals refers to real DOM. This modal is 100% purely made using virtual DOM instead. Also, you can customize the UI based on your needs without worrying about css conflicts, thanks to the :where css pseudo-class and module.css. Not less important, extreme small size.

Getting Started

You can install the module via npm or yarn:

npm install react-fade-modal
yarn add react-fade-modal

Demo

Live Demo

Usage

Basic example

import {Modal} from 'react-fade-modal'

function App() {
    const [isOpen, setIsOpen] = useState(false)
    return (
       <div>
           <p>
               <div>Basic example</div>
               <button onClick={() => setIsOpen(true)}>click to open modal</button>
               {isOpen &&
                   <Modal
                       title={"Title"}
                       setIsOpen={setIsOpen}>
                       <div>
                           <p>Modal content.</p>
                       </div>
                   </Modal>
               }
           </p>      
       </div>
    );
}

Note that Modal does not accept an isOpen prop. You must put the component into a conditional wrap, so it will be unmounted and mounted every time the condition change.

ModalProvider Example

Sometimes, Modal does not render well when you are using in a complex nested DOM component.

In this case, it's better to use ModalProvider in order to ensure that the Modal is on top of the DOM and the graphic does not change:

import {ModalProvider} from 'react-fade-modal'

function App() {
    return (
        <ModalProvider>
            <Panel/>
        </ModalProvider>
    );
}

In this example, App.js render <Panel/> only. Let's call useModalContext:

import {useModalContext} from 'react-fade-modal'

const Panel = () => {
    const {showModal} = useModalContext()
    return <p>
        {items.map(item =>
            <Button onClick={() => {
                showModal({
                    title: 'Custom title',
                    children: <div>You can pass any component. This is the Item {item}</div>,
                    closeOnClickOutside: false
                })
            }}>
                item {item}
            </Button>)}
    </p>
}

Note that I could also call the context inside any child of <Panel/>, that's how the context work basically.

showModal is a function that accept any Modal props. You can pass props as object properties as shown in the example above.

More examples available on demo/src/App.tsx

Props

|Name|Type|Default|Description| |:--|:--:|:-----:|:----------| |setIsOpen|Function|required|Show the modal. Accept 1 boolean value| |transitionDurationInMs|number|200|Transition duration in milliseconds. Used for fade in-out the Modal| |title|string|''|Title of the Modal| |children|ReactNode|undefined|Any JSX Component| |closeOnClickOutside|boolean|true|If true, the Modal will closed when you click outside| |containerCss|string|''|Optional CSS Classes applied to Modal container. A grey background layer will be shown as default| |modalCss|string|''|Optional CSS classes applied to the Modal itself| |modalStyle|CSSProperties|{}|Optional style applied to the Modal itself| |titleCss|string|''|Optional CSS classes applied to the title| |contentCss|string|''|Optional CSS classes applied to the children| |closeIconCss|string|''|Optional CSS classes applied to the close icon| |showCloseIcon|boolean|true|If true, it will be rendered the default close icon| |customCloseIcon|ReactElement|undefined|If not undefined, this component will be rendered instead of the default close icon|

No CSS Conflicts

Every css classes used in this component are written into module.css file and wrapped into :where pseudo-class, which gives them 0 specificity, so you can override current css properties through your custom css classes. More about :where pseudo-class, Specificity and the :where exception More about css modules

Project Structure

The project includes a demo folder initialized with Create React App.

When you run the command build from first-level package.json, a dist and a lib folder will be generated.

The lib folder will be placed automatically into the demo project.

You can move into demo directory and start project from its own package.json script, just like any other Create React App.

Questions

🐛 Did you find any bugs? Cool! Report it in "issues" section under the label "bug" and I'll check it.

🚀 Do you have any questions or feature request? Nice! Write it into "issues" section under the label "enhancement" and I'll check it.

⭐ Did you find this package useful and meet your requirements? Great! Consider to put a ⭐ into the GitHub project!

License

MIT