0.1.5 • Published 1 year ago
Share package React Overlay Modal A minimalistic, super lightweight and accessible React modal library that offers
robust type safety. This headless solution gives you full flexibility to
integrate your own content and styles without worrying about z-index or complex
configurations.
Features No dependencies other than React. Fully accessible with proper ARIA attributes. Lightweight and headless (no pre-applied styles). Typescript support for type safety. Minimal configuration with support for custom styling. Demo View the Demo
Install npm i react-overlay-modalWrap the root app with ModalProvider import { StrictMode } from "react"
import { createRoot } from "react-dom/client"
import App from "./App.tsx"
import { ModalProvider } from "react-overlay-modal"
createRoot(document.getElementById("root")!).render(
<StrictMode>
<ModalProvider>
<App />
</ModalProvider>
</StrictMode>,
)Usage import { useModal } from "react-overlay-modal"
function ModalContent() {
const { closeModal } = useModal()
return (
<div>
<h2>✨ Welcome to Cool Modal!</h2>
<button
onClick={closeModal}
className="btn secondary"
>
✨ Close Modal
</button>
</div>
)
}
export default function Page() {
const { showModal } = useModal()
return (
<button
className="btn primary"
onClick={() => showModal({
content: <ModalContent />,
size: "md"
})}
>
✨ Open Cool Modal
</button>
)
}API Props Property Type Default Value Description sizeModalSize "md" Specifies the size of the modal (see ModalSize). disableOutsideClickboolean false If true, disables clicking outside the modal to close it. contentReactElement The content to display inside the modal. classNamestring undefined Pass class to handle the overlay style. bodyPropsModalBodyProps undefined See body props for more details (see ModalBodyProps)
Modal Size Value Description smSmall modal size. mdMedium modal size. (default) lgLarge modal size. xlExtra-large modal size. 2xlDouble extra-large modal size. 3xlTriple extra-large modal size. fullFullscreen modal.
Modal Body Props Property Description classNameOptional string for CSS class name aria-labelledbyOptional string to reference labeling element(s) aria-describedbyOptional string to reference describing element(s) aria-hiddenOptional boolean to hide from assistive tech aria-liveOptional region updates announcement: "off", "polite", or "assertive" aria-modalOptional boolean indicating if element is modal aria-roleOptional string defining element's ARIA role tabIndexOptional number for tab order roleOptional string defining element's role onKeyDownOptional keyboard event handler onFocusOptional focus event handler idOptional string identifier styleOptional React CSS properties object onClickOptional mouse click event handler