Generate and export Tailwind color patterns.
A reusable and accessible modal component in React with customizable props.
The Modal
component is a reusable, accessible, and customizable modal dialog for React applications.
Prop | Type | Default | Description |
---|---|---|---|
isOpen | boolean | false | Controls modal visibility. |
onClose | () => void | - | Callback for closing the modal. |
title | string | - | The title of the modal. |
children | React.ReactNode | - | The content inside the modal. |
closeOnOutsideClick | boolean | true | Determines if clicking outside should close the modal. |
closeOnEsc | boolean | true | Determines if pressing Escape should close the modal. |
showCloseButton | boolean | true | Determines if a close button should be displayed. |
buttons | React.ReactNode[] | [] | Allows adding multiple custom action buttons. |
className | string | "" | Custom styles for the modal container. |
overlayClassName | string | "" | Custom styles for the overlay background. |
import React, { useState } from "react";
import Modal from "./Modal";
const App = () => {
const [isOpen, setIsOpen] = useState(false);
return (
<div>
<button onClick={() => setIsOpen(true)}>Open Modal</button>
<Modal
isOpen={isOpen}
onClose={() => setIsOpen(false)}
title="Example Modal"
buttons={[<button onClick={() => setIsOpen(false)}>Close</button>]}
>
<p>This is a simple modal example.</p>
</Modal>
</div>
);
};
export default App;
Escape
key closes the modal when closeOnEsc
is enabled.closeOnOutsideClick
is enabled.aria-modal
and aria-labelledby
for screen reader compatibility.aria-describedby
for better screen reader support.