1.0.9 • Published 1 year ago

@florian_/react-simple-modal v1.0.9

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

React Simple Modal

About the project

This Modal component was initially created to meet a specific need in a personal project. However, aware of the value of component reusability, I designed it with the intention of making it adaptable and easily integrated into other projects.

Built with

React 18 Tailwind CSS Vite.js

Getting Started

Prerequisites

You need a package manager and React 17 or later.

  • npm

    npm install npm@latest -g
  • pnpm

    npm install -g pnpm

    Please refer to this documentation for more information.

Installation

npm

npm i @florian_/react-simple-modal

pnpm

pnpm add @florian_/react-simple-modal

Usage / Examples

The Modal component simply needs a state to indicate whether the modal window should be displayed or not, and a function to manage its closure.

import {
	Modal,
	ModalContent,
	ModalHeader,
	ModalTitle,
	ModalDescription,
	ModalClose,
	ModalFooter,
} from "@florian_/react-simple-modal";

function App() {
	const [isOpen, setIsOpen] = useState(false);

	const handleModal = () => setIsOpen(!isOpen);

	return (
		<>
			<button onClick={handleModal}>open</button>

			<Modal open={isOpen} onClose={handleModal}>
				<ModalContent>
					<ModalHeader>
						<ModalTitle>Login</ModalTitle>
						<ModalDescription>
							Lorem ipsum dolor sit amet consectetur adipisicing
							elit.
						</ModalDescription>
					</ModalHeader>

					<p>
						Lorem ipsum dolor sit amet consectetur, adipisicing
						elit. Quaerat explicabo dolor repellendus sed esse
						voluptatum velit. Voluptate at veniam corrupti nihil a
						aliquam omnis magnam, vitae aut expedita, earum illo!
					</p>

					<ModalFooter>
						<ModalClose>Close</ModalClose>
					</ModalFooter>
				</ModalContent>
			</Modal>
		</>
	);
}

export default App;

Props

NameRequiredDefaultTypeExample
openyes-booleanClick
onCloseyes-function => voidClick
onOpenChangenoundefinedfunction(isOpen: boolean) => voidClick
onCreatenoundefinedfunction => voidClick
autoFocusnotruebooleanClick
restoreFocusnotruebooleanClick
classNamenoundefinedstring

Props Examples

open

open the controlled open state of the dialog.

<Modal open={true}>...</Modal>

autoFocus

autoFocus focus the first focusable element in the modal.

<Modal open autoFocus>
	...
</Modal>

restoreFocus

restoreFocus restores focus on base element after closing modal.

<Modal open restoreFocus>
	...
</Modal>

onOpenChange

onOpenChange trigger when the open state of the dialog changes.

<Modal onOpenChange={(isOpen) => console.log(isOpen))}>...</Modal>

onClose

onClose triggers when the modal window closes.

<Modal onClose={() => console.log("onClose")}>...</Modal>

onCreate

onCreate trigger when component is create.

<Modal onCreate={() => console.log("onCreate")}>...</Modal>
1.0.9

1 year ago

1.0.8

1 year ago

1.0.7

1 year ago

1.0.6

2 years ago

1.0.5

2 years ago

1.0.4

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago

0.0.5

2 years ago

1.0.3

2 years ago

0.0.4

2 years ago

0.0.3

2 years ago

0.0.2

2 years ago

0.0.1

2 years ago