0.2.1 • Published 10 months ago

use-html-dialog v0.2.1

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

use-html-dialog

Simple, tiny React hook for working with native HTML dialogs. Optionally resets user agent dialog styles and closes on backdrop click when used in modal mode.

Installation

npm i use-html-dialog

Usage

const { showModal, props, close } = useHtmlDialog()

return (
	<>
		<button onClick={showModal}>Open modal</button>

		<dialog {...props}>
			This is a modal dialog.
			<button onClick={close}>Close modal</button>
		</dialog>
	</>
)

API

Options

The hook takes an options object as an optional argument. The following options are available:

OptionTypeDefaultDescription
resetStylesbooleantrueWhether to reset default user agent dialog styles.
closeOnOutsideClickbooleantrueWhether to close the dialog when the backdrop is clicked. Only applies when showModal is used.

Example:

const dialog = useHtmlDialog({
	resetStyles: false,
	closeOnOutsideClick: false,
})

Hook Return

The hook returns an object with the following properties:

PropertyTypeDescription
showfunctionShows the dialog.
showModalfunctionShows the dialog as a modal.
closefunctionCloses the dialog.
propsobjectProps to spread on the dialog element.
isOpenbooleanWhether the dialog is open.
refobjectRef to the dialog element, in case you need it (you probably don't).

License

MIT

0.2.1

10 months ago

0.2.0

10 months ago

0.1.2

10 months ago

0.1.1

10 months ago

0.1.0

10 months ago

0.0.11

10 months ago

0.0.10

10 months ago

0.0.9

10 months ago

0.0.8

10 months ago

0.0.7

10 months ago

0.0.6

10 months ago

0.0.5

10 months ago

0.0.4

10 months ago

0.0.3

10 months ago

0.0.2

10 months ago

0.0.1

10 months ago