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

pop-modal

v1.1.5-a

Published

A simple react popup modal

Downloads

82

Readme

pop-modal

A simple adaptive React Popup Modal. Also works fine with server side rendering of React.

demo

Demo on heroku

instalation

using npm

  npm install pop-modal ---save

Pop-Modal is a wrapper for React Components. It passes as props 2 methods for opening and closing modal: 'openPopup' and 'closePopup' and the 'Modal' itself.

const { openPopup, closePopup, Modal } = this.props

to render something inside the modal just wrapp it inside Modal prop of Component.

  render () {
    const { Modal } = this.props
    return (
        <Modal>
            <h1>Hello from Pop Modal</h1>
        </Modal>
    )
}

usage

To add Modal to a React Component you must pass the Component that will receive modal's props.

import WithModal from 'pop-modal'

export default WithModal( YourComponent )

configuring modal

To configure Modal's behaviour you can pass props to it.

Below is a table of props it accepts.

| PropName | Type | Description | Default | Required | | -------- |----- | ----------- | ------- | -------- | | onClose | function | An callback function that will be called once the modal has been closed. | Null | false | | onOpen | function | An callback function that will be called once the modal has been opened. | Null | false | | openMs | number | Timeout in ms for modal opening. | 1000 | false | | closeMs | number | Timeout in ms for modal closing. | 500 | false | | showBtn | boolean | Display close button or no. | true | false | | btnClassName | string | Close button's className. | 'fa fa-close' | false | | outsideClickClose | boolean | Option to close modal if there is an click outside of it's container. | false | false | | defaultOpen | boolean | Used to render modal in open stage, skipping opening stage. It can be used for Server Side Rendering when you need the modal to be open from the start. | false | false |

Example:

  const { Modal } = this.props
  ...
  return (
    <Modal onClose={ () => { console.log('closed') } } openMs={ 1000 } closeMs={ 1000 }>
      <h1>Hello</h1>
    </Modal>
  )

opening and closing

The react component that is wrapped in pop-modal gets two props for closing and opening: openPopup and closePopup, openPopup can take an initial stage to be opened in. Example:

    this.props.openPopup() // Opens the popup

css

You can find the css required by the modal in the 'pop-modal/dist/modal.css' file in your node_modules. It's very likely that you will need to do some adjustments to this css file so it's better to just copy it from here and edit it the way you need it.

The modal itself has four transition classes: closed > opening > open > closing. So you can customize the transition of the modal.

import 'pop-modal/dist/modal.css'

usage example ( from demo )

using decorators

import React, { Component } from 'react'
import WithModal from 'pop-modal'

@WithModal

export default class Page extends Component {
    render () {
        const { openPopup, Modal } = this.props
        return (
            <div className='container text-center'>
                <h1>Pop Modal Demo</h1>
                <button className='btn btn-primary' type='button' onClick={
                    () => { openPopup() }
                }>Open modal</button>
                <Modal outsideClickClose>
                    <h1>Hello from Pop Modal</h1>
                </Modal>
            </div>
        )
    }
}

using ES6

import React, { Component } from 'react'
import WithModal from 'pop-modal'

class Page extends Component {
    render () {
        const { openPopup, Modal } = this.props
        return (
            <div className='container text-center'>
                <h1>Pop Modal Demo</h1>
                <button className='btn btn-primary' type='button' onClick={
                    () => { openPopup() }
                }>Open modal</button>
                <Modal outsideClickClose>
                    <h1>Hello from Pop Modal</h1>
                </Modal>
            </div>
        )
    }
}

export default WithModal( Page )