Package Exports
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (dynamic-modal) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
dynamic-modal
dynamic-modal
is a TypeScript library for creating reusable modals in React and Next.js applications. It uses JSON objects to configure the modal structure, eliminating the need to write HTML. This approach simplifies modal creation and customization, allowing you to open and close modals using a custom hook.
Requirements
To use dynamic-modal
properly, ensure you have the following dependencies installed:
- React 18
- React-DOM 18
- react-hook-form
- NextUI
Additionally, dynamic-modal
is compatible with Next.js 14.
Installation
Install the library via npm:
npm install dynamic-modal
Setup for Next.js 14
In the main layout of your Next.js application, wrap your app with the NextUIProvider
component to ensure dynamic-modal
functions properly. Here’s an example:
import { NextUIProvider } from '@nextui-org/react';
function MyApp({ Component, pageProps }) {
return (
<NextUIProvider>
<Component {...pageProps} />
</NextUIProvider>
);
}
export default MyApp;
Usage
To control the modal’s open and close states, use the useModalHandler
custom hook and call openModal
whenever you need to display the modal.
import { useModalHandler, DynamicModal } from 'dynamic-modal';
import { Button } from '@nextui-org/react';
function ExampleComponent() {
const { openModal, modalProps } = useModalHandler();
return (
<>
<Button
onClick={() => {
openModal(testModal.default({}, (data) => {
console.log('modal data', data);
}));
}}
>
Open modal
</Button>
<DynamicModal {...modalProps} />
</>
);
}
export default ExampleComponent;
Examples
The examples folder in the repository contains different configuration modes to help you customize your modal.