Modal
A dialog component for displaying content that requires user interaction
Installation
The Modal component is part of the ReacUI library. Install the package to use it in your project.
Import
Import the Modal component into your React component.
Basic Modal
A basic modal with a title, content, and action buttons.
Modal Sizes
Modals come in different sizes to fit your content needs.
Modal Positioning
Control the vertical position of your modals to create different visual effects.
Animations
Add smooth animations to your modals for a better user experience.
Forms in Modals
Modals are perfect for containing forms that require user input.
Customization
Customize the modal with different styles and content.
Accessibility
The Modal component implements best practices for accessibility, including keyboard navigation, focus management, and ARIA attributes.
API Reference
The following props are available for the Modal component.
| Component | Prop | Type | Default | Description |
|---|---|---|---|---|
| Modal | isOpen | boolean | false | Controls whether the modal is displayed |
| onClose | function | required | Function called when the modal should close | |
| children | ReactNode | required | Content to display inside the modal | |
| title | string | - | Optional title for the modal | |
| size | string | 'md' | Size of the modal: 'sm', 'md', 'lg', 'xl', 'full' | |
| position | string | 'center' | Vertical position of the modal: 'center', 'top' | |
| animation | string | 'none' | Animation style: 'none', 'fade', 'scale', 'slide-up' | |
| initialFocus | RefObject | - | Ref to the element that should receive focus when the modal opens | |
| closeButton | boolean | false | Whether to show a close button in the top-right corner | |
| closeOnEsc | boolean | true | Whether to close the modal when the Escape key is pressed | |
| closeOnOverlayClick | boolean | true | Whether to close the modal when clicking the overlay | |
| className | string | '' | Additional CSS classes for the modal container | |
| contentClassName | string | '' | Additional CSS classes for the modal content | |
| overlayClassName | string | '' | Additional CSS classes for the modal overlay | |
| Modal.Body | className | string | '' | Additional CSS classes for the modal body |
| Modal.Header | className | string | '' | Additional CSS classes for the modal header |
| Modal.Footer | className | string | '' | Additional CSS classes for the modal footer |
| Modal.Button | variant | string | 'primary' | Button variant: 'primary', 'secondary', 'danger', 'custom' |
| onClick | function | - | Function called when the button is clicked | |
| className | string | '' | Additional CSS classes for the button |