1.0.6 • Published 11 months ago

modal-dialog-react-component v1.0.6

Weekly downloads
-
License
MIT
Repository
github
Last release
11 months ago

modal-dialog-react-component

A React component for a modal made with dialog html element

NPM JavaScript Style Guide

Install

npm install --save modal-dialog-react-component

Usage

Where you want to use the modal, import the component and use it like this:

import { useEffect } from 'react'

import Modal from 'modal-dialog-react-component'
import 'modal-dialog-react-component/dist/index.css'

class Example extends Component {
  render() {
    const [isModalOpen, setIsModalOpen] = useState(false) // state to control the modal
    return (
      <Modal isOpen={isModalOpen} setIsOpen={setIsModalOpen}>
        {' '}
        {Children}{' '}
      </Modal>
    )
  }
}

Then use setIsModalOpen(true) to open the modal. It can be used in a button onClick event for example, or when your form is submited.

Example

import React from 'react'
import Modal from 'modal-dialog-react-component'
import { useState } from 'react'
import 'modal-dialog-react-component/dist/index.css'
import 'modal-dialog-react-component/dist/modal.css'
const App = () => {
  const [isModalOpen, setIsModalOpen] = useState(false)
  const handleClick = () => {
    setIsModalOpen(true)
  }
  return (
    <>
      <p>App</p>
      <button onClick={handleClick}>Ouvrir la modal</button>
      <Modal isOpen={isModalOpen} setIsOpen={setIsModalOpen}>
        <p>Modal</p>
      </Modal>
    </>
  )
}

export default App

License

MIT © VB2095

1.0.6

11 months ago

1.0.5

11 months ago

1.0.4

11 months ago

1.0.3

11 months ago

1.0.2

11 months ago

1.0.1

11 months ago

1.0.0

11 months ago

0.0.1

6 years ago