@app-elements/modal

4.0.3 • Public • Published

Modal

Simple modals. Comes with basic overlay styling, animation, and a <Modals /> Component for dynamically rendering the correct Modal.

Installation

npm install --save @app-elements/modal

Usage

First, you need to have a root dom node to render modals into. So inside your <body> add <div id='modals' />.

Then, you need to define at least one modal. The only requirement is that the top-level element for your Component needs to be <Modal />:

import Modal from '@app-elements/modal'

const ExampleModal = () =>
  <Modal>
    <h1>Example Modal</h1>
  </Modal>

export default ExampleModal

Now, you need to nest your ExampleModal in a <Modals /> instance:

import { Modals } from '@app-elements/modal'
import ExampleModal from '/modals/example-modal'

const MainApp = () =>
  <div>
    <Router routes={routes} />
    <Modals>
      <ExampleModal />
    </Modals>
  </div>

You can nest as many modals as you wish under a <Modals /> instance, and Modals will figure out which, if any, of the modals it should render.

To show a modal, set the name in the global state:

import { setState } from '/store'

// 'ExampleModal' matches up with the name of the modal variable.
setState({ modal: 'ExampleModal' })
// For example, `const AnotherModal = () => <Modal>/* ... */</Modal>`
// could be opened by calling `setState({ modal: 'AnotherModal' })`

<Modal /> Props

Prop Type Default Description
className String None A class name to be added on the .modal-container div
hideClose Boolean false Should the modal render without a 'x' close button?
children Array None The elements to display when the Modal is open.

<Modals /> Props

Prop Type Default Description
children Array None The modals to display to potentially display if their name matches modal key on the global store.

Versions

Current Tags

VersionDownloads (Last 7 Days)Tag
4.0.32latest

Version History

VersionDownloads (Last 7 Days)Published
4.0.32
4.0.21
4.0.10
4.0.00
4.0.0-alpha.00
3.1.10
3.1.01
3.0.01
2.3.01
2.2.20
2.2.10
2.2.00
2.1.00
2.0.30
2.0.20
2.0.10
2.0.00
1.1.01
1.0.80
1.0.70
1.0.60
1.0.50
1.0.40
1.0.20
1.0.12
1.0.00

Package Sidebar

Install

npm i @app-elements/modal

Weekly Downloads

9

Version

4.0.3

License

ISC

Unpacked Size

49 kB

Total Files

13

Last publish

Collaborators

  • coryschadt
  • trustfall
  • adriaanwm
  • staydecent