1.0.0 โ€ข Published 5 months ago

@oragie/react-modal-lib v1.0.0

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

๐Ÿงฉ react-modal-lib

A simple, reusable, and accessible modal component for React.

Inspired by jquery-modal, rebuilt for the modern React ecosystem.


๐Ÿ“ฆ Installation

npm install react-modal-lib

๐Ÿš€ Usage

import React, { useState } from "react";
import { Modal } from "react-modal-lib";

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

  return (
    <>
      <button onClick={() => setIsOpen(true)}>Open modal</button>

      <Modal isOpen={isOpen} onClose={() => setIsOpen(false)}>
        <h2>Hello ๐Ÿ‘‹</h2>
        <p>This is the content of the modal.</p>
      </Modal>
    </>
  );
}

๐Ÿ›  Props

' | Prop | Type | Default | Description | | --------------------- | ------------ | ------- | ----------------------------------------- | | isOpen | boolean | โ€” | Controls whether the modal is open | | onClose | () => void | โ€” | Called when the modal should close | | children | ReactNode | โ€” | Modal content | | closeOnOverlayClick | boolean | true | Close the modal when clicking the overlay | | closeOnEscape | boolean | true | Close the modal when pressing Escape | | showCloseButton | boolean | true | Show the "ร—" close button |

'


๐ŸŽจ Styling

The modal uses its own internal Modal.css, but you can override styles via classnames:

.modal-overlay {
  ...;
}
.modal-content {
  ...;
}
.modal-close {
  ...;
}

Make sure to import the CSS:

import "react-modal-lib/dist/style.css";

Or include it via bundler (already included if you use Vite).


๐Ÿงช Local Testing

To test this library locally:

# In the library folder
npm run build
npm link

# In your React app
npm link react-modal-lib

๐Ÿ“„ License

MIT โ€” free to use and modify.