wil-react-modal
v1.5.2
Published
Modal Component For React
Downloads
5
Readme
Wil React Modal
Modal Component For React
Installation
npm
npm install wil-react-modal --save
yarn
yarn add wil-react-modal
Example
1. Basic
2. Open Modal from other file and send payload
3. Animation
4. Placement
5. Fullscreen
6. Nested
7. Auto visible
8. Open modal and auto close modal after 5s
9. Router Modal
import React from "react";
import Modal from "wil-react-modal";
class App extends React.Component {
render() {
return (
<div>
<button
onClick={() => {
Modal.open("basic", {
payload: { name: "Wil React Modal", author: "Wiloke" }
})
}}
>Modal Basic</button>
<Modal
displayName="basic"
animationType="zoom"
onOpen={payload => {
// payload: { name: "Wil React Modal", author: "Wiloke" }
console.log(payload);
}}
>
<div style={{ backgroundColor: "#fff", padding: 30 }}>
<h2>Modal Basic</h2>
<button onClick={() => Modal.close("basic")}>Close</button>
</div>
</Modal>
</div>
)
}
API
| Prop | Type | Default | Description |
| :--------- | :-------: | :-----: | :----------- |
| displayName | string
| - | Modal name |
| placement | "center", "top", "right", "bottom", "left"
| center
| The position of the modal relative to the screen |
| animationDuration | number
| 300
| Modal animation duration ( milliseconds ) |
| animationType | "none", "fade", "fadeUp", "fadeDown", "fadeLeft", "fadeRight", "slideUp", "slideDown", "slideLeft", "slideRight", "zoom"
| none
| animation for modal |
| underlayEnabled | boolean
| true
| On / off modal underlay |
| underlayColor | string
| rgba(0, 0, 0, 0.5)
| Set color for modal underlay |
| fullScreen | boolean
| false
| Content width 100% height 100% |
| scrollTarget | string
| window
| Toggle the scroll bar of the element. Example scrollTarget value: window, #root, ... |
| scrollTargetEnabled | boolean
| false
| Allow toggle scroll bar |
| openTimeout | boolean
| false
| Open modal timeout (second) |
| autoCloseTimeout | boolean
| false
| Close modal timeout (second) |
| children | React.Node or (({ payload: any, countDown: number }) => React.Node)
| - | ReactNode or Function return ReactNode (payload received from method open and countDown from prop autoCloseTimeout) |
| onOpen | (payload: any) => void
| - | Callback executed when modal open. Payload received from method open |
| onOpenEnd | (payload: any) => void
| - | Callback executed when modal open stop. Payload received from method open |
| onCloseEnd | () => void
| - | Callback executed when modal close |
| isVisible | boolean
| - | Set on / off modal. This attribute is needed when you want to open modal at the beginning without taking action |
| modalContainerClassName | string
| - | ClassName for Modal |
| modalContainerStyle | Object
| - | Style for Modal |
Methods
| Method | Params | Description |
| :--------- | :-------: | :----------- |
| open | displayName, { historyPushTitle, historyPushUrl, payload }
| Open modal with prop displayName
. You can using historyPushTitle
and historyPushUrl
for Modal Router and send data with payload
( historyPushUrl
could be http://localhost:3000/foo.html
or /foo.html
or foo.html
. Example: Router Modal ) |
| close | displayName
| Close modal with prop displayName Modal.close("displayName") |