2.2.0 • Published 9 months ago

@detrenasama/modal-hooker v2.2.0

Weekly downloads
-
License
MIT
Repository
-
Last release
9 months ago

@detrenasama/modal-hooker

NPM version

Control your modals with hook

Install

$ npm install @detrenasama/modal-hooker

Usage

Create modal component (wrapper)

Next props will be passed to component:

modal ... content of wrapper. Just draw it in render as {modal} \ isOpening ... current state. Use for animations (styles) \ isClosing ... current state. Use for animations (styles) \ closeModal ... callback for closing this modal

Pass it to ModalContainer for using as default container.

Pass to hook for using it when needed.

useModal(MyModal, {}, ModalWrapper)

Insert ModalContainer component into your Application

If your modal can contain links, put it into your Router component Provide default modal, that will be used as modal wrapper

<ModalContainer defaultModalComponent="ModalWrapper" />

Create modal content component

Instance of this content will be passed as modal prop into your wrapper

function MyModal({title, onClose}) {
    return <div>
        <h3>{title}</h3>
        <button onClick={onClose}>Close</button>
    </div>
}

Use modal hook in component where you need to show modal

function MyPageOrSomething() {
    const [openModal, closeModal] = useModal(MyModal, {
        title: "My title",
        onClose: () => {
            closeModal()
        }
    })
    
    return <div>
        <button onClick={openModal}>Open modal</button>
    </div>
}

Or use it from non-component functions (version >= 2.2.0)

import {declare, open, close} from '@detrenasama/modal-hooker';
function someErrorHandler(error) {
    const modalId = declare(ErrorModal, {
        error: error,
        onClose: () => {
            close(modalId)
        }
    })
    
    open(modalId)
}

License

MIT

2.2.0

9 months ago

2.1.2

1 year ago

2.1.1

1 year ago

2.1.0

1 year ago

2.0.3

1 year ago

2.0.2

1 year ago

2.0.5

1 year ago

2.0.4

1 year ago

2.0.7

1 year ago

2.0.6

1 year ago

2.0.9

1 year ago

2.0.8

1 year ago

2.0.1

1 year ago

2.0.0

1 year ago

1.2.0

1 year ago

1.1.3

1 year ago

1.1.1

1 year ago

1.1.0

1 year ago

1.0.9

1 year ago

1.0.8

1 year ago

1.0.7

1 year ago

1.0.6

1 year ago

1.0.5

1 year ago

1.0.4

1 year ago

1.0.3

1 year ago

1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago