2.0.7 • Published 6 years ago

react-modal-construction-kit v2.0.7

Weekly downloads
5
License
MIT
Repository
github
Last release
6 years ago

NPM

React Modal Construction Kit

A highly extensible Modal library.

Demo

mikevercoelen.github.io/react-modal-construction-kit

Installation

npm install react-modal-construction-kit --save

Example

import React, { Component } from 'react'
import { Modal, Overlay } from 'react-modal-construction-kit'

export default class App extends Component {
  state = {
    isModalVisible: false
  }

  onBtnOpenModalClick = () => {
    this.setState({
      isModalVisible: true
    })
  }

  close = () => {
    this.setState({ isModalVisible: false })
  }

  render () {
    const { isModalVisible } = this.state

    return (
      <div>
        <Modal
          onClickOutside={this.close}
          onClosed={this.close}
          isOpen={isModalVisible}>
          <p>
            A super minimal Modal
          </p>
        </Modal>
        <Overlay
          isVisible={isModalVisible} />
        <button
          onClick={this.onBtnOpenModalClick}>
          Open modal
        </button>
      </div>
    )
  }
}

Modal

The modal component is a fully customizable modal, requires no styling and is already animated out of the box.

PropertyTypeDefaultDescription
isOpenbooleanfalseOpen or close modal's state
autoFocusboolean-autofocus the component on mount
zIndexnumber750z-index value
rolestring"dialog"HTML5 role
childrenReact Node-The content of the modal
onOpenedfunction-Called on when the Transitions triggers 'onOpened'
onClosedfunction-Called on when the Transitions triggers 'onClosed'
onEnterfunction-Called on componentDidMount
onExitfunction-Called on componentWillUnmount
onEnteredfunction(node, isAppearing)--
onExitedfunction(node)--
classNamestring-Adds a class names to component root
dialogClassNamestring-Adds a class name to dialog
contentClassNamestring-Adds a class name to content
hasEscapeClosebooleantrueIf enabled, escape keydown will trigger onClosed
hasOutsideClickClosebooleantrueIf enabled, clicking outside of the modal (i.e. on the overlay) will trigger onClosed
transitionDurationnumber300Duration of the animation

Overlay

The Modal component does not have an overlay by default, the reason for this is: what if you have multiple modals open? You should only have ONE overlay. It's animated and also requires no styling, it just works ;)

import { Overlay } from 'react-modal-construction-kit'
PropertyTypeDefaultDescription
isVisiblebooleanfalseShows or hides the overlay
zIndexnumber500z-index value
classNamestring-A className applied to the overlay
opacitynumber0.7The opacity value when the overlay is fully visible
transitionDurationnumber150The duration of the transition
onClickfunction(event)-onClick handler, when using a modal you don't need this, use Modal.onClickOutside

License

MIT Licensed. Copyright (c) Mike Vercoelen 2018.

2.0.7

6 years ago

2.0.6

6 years ago

2.0.5

6 years ago

2.0.4

6 years ago

2.0.3

6 years ago

2.0.2

6 years ago

2.0.1

6 years ago

2.0.0

6 years ago

1.0.5

6 years ago

1.0.4

6 years ago

1.0.3

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago