react-simple-modal-provider
Simple Modal Manager for React Projects
Installation
$ npm install react-simple-modal-provider
$ yarn add react-simple-modal-provider
Examples
Pass unique ID to the id props. It is, then, used to load modals.
Keeping eye on the four required props of the "Modal" module, you should create a modal in the child area.
Register a modal array through the "value" props of the "ModalProvider" module and wrap it around the application.
"useModal" takes the modal ID as an argument and provides the open, close function of the modal.
It is recommended to name variables using destructuring assignment.
API
Modal Module
- Essential props
Prop | Type | Default | Description |
---|---|---|---|
id | string | - | Identifier for a modal |
consumer | children props | - | Components to use modals for |
isOpen | boolean state | - | Returned by useModalState hooks |
setOpen | state function | - | Returned by useModalState hooks |
- Optional props
Prop | Type | Default | Description |
---|---|---|---|
asyncOpen | async function | - | Called when modal opened |
draggable | boolean | false | Drag usable |
allowClickOutside | boolean | true | Allow click outside |
spinner | false | JSX | Built-in spinner | Async loading spinner |
spinnerColor | string | #93dbe9 | Built-in spinner color |
overlayColor | string | rgba(0, 0, 0, 0.6) | Overlay color |
backgroundColor | string | transparent | Modal background color |
animation | object | - | Open/Close animation |
duration | number | 0 | Animation duration |
vertical | number | 0 | Vertical position (px) |
horizontal | number | 0 | Horizontal position (px) |
width | number | 0 | Modal width (px) |
height | number | 0 | Modal height (px) |
radius | number | 0 | Border radius (px) |
Async
A spinner is built-in. If you don't want to, specify false in "spinner" props.
Custom spinners in "JSX" format can also be specified.
Animation
- Built-in animation
- Import "modalAnimation" module and pass the value to the animation props.
- scaleUp
- slideDown
- slideUp
- Custom animation examples
top, bottom, left, right type cannot be used.