Socket
Socket
Sign inDemoInstall

pop-modal

Package Overview
Dependencies
6
Maintainers
1
Versions
19
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    pop-modal

A simple react popup modal


Version published
Weekly downloads
29
increased by107.14%
Maintainers
1
Install size
545 kB
Created
Weekly downloads
 

Readme

Source

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.

PropNameTypeDescriptionDefaultRequired
onClosefunctionAn callback function that will be called once the modal has been closed.Nullfalse
onOpenfunctionAn callback function that will be called once the modal has been opened.Nullfalse
openMsnumberTimeout in ms for modal opening.1000false
closeMsnumberTimeout in ms for modal closing.500false
showBtnbooleanDisplay close button or no.truefalse
btnClassNamestringClose button's className.'fa fa-close'false
outsideClickClosebooleanOption to close modal if there is an click outside of it's container.falsefalse
defaultOpenbooleanUsed 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.falsefalse

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 )

FAQs

Last updated on 13 Nov 2018

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc