Color Generator

Generate and export Tailwind color patterns.

Brand Colors

primary
secondary

State Colors

info
success
warning
error

Color Picker

Modal Component

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.

Props

PropTypeDefaultDescription
isOpenbooleanfalseControls modal visibility.
onClose() => void-Callback for closing the modal.
titlestring-The title of the modal.
childrenReact.ReactNode-The content inside the modal.
closeOnOutsideClickbooleantrueDetermines if clicking outside should close the modal.
closeOnEscbooleantrueDetermines if pressing Escape should close the modal.
showCloseButtonbooleantrueDetermines if a close button should be displayed.
buttonsReact.ReactNode[][]Allows adding multiple custom action buttons.
classNamestring""Custom styles for the modal container.
overlayClassNamestring""Custom styles for the overlay background.

Usage Example

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;

Accessibility Features

  • The modal is focusable and returns focus to the last active element when closed.
  • The Escape key closes the modal when closeOnEsc is enabled.
  • Clicking outside the modal closes it when closeOnOutsideClick is enabled.
  • Uses aria-modal and aria-labelledby for screen reader compatibility.

Improvements & Considerations

  • Consider trapping focus inside the modal to enhance keyboard navigation.
  • Add aria-describedby for better screen reader support.
  • Optimize event listeners for performance improvements.