0.1.22 • Published 1 year ago
rc-global-modal v0.1.22
rc global modal
manage modal using global state in react project
Try it out with Storybook
Table of Contents
Installation
npm i rc-global-modal
Features
- Open and close modal from anywhere in the app(inside
ModalProvider
) - Custom CSS style for modal and overlay
- Ref for modal container and overlay
- Choose animation type and duration for modal
Props
Props | Types | Required | Default | Description |
---|---|---|---|---|
children | React.FC | ✅ | component that will be displayed inside modal | |
id | string \| number | ✅ | unique id for modal | |
closeOnOverlayClick | boolean | ❌ | true | close modal when overlay is clicked |
modalContainerClassName | string | ❌ | class name for modal container | |
overlayClassName | string | ❌ | class name for overlay | |
modalContainerStyle | React.CSSProperties | ❌ | custom style for modal container | |
overlayStyle | React.CSSProperties | ❌ | custom style for overlay | |
closeOnEsc | boolean | ❌ | true | close modal when esc key is pressed |
modalContainerRef | React.RefObject | ❌ | ref for modal container | |
overlayRef | React.RefObject | ❌ | ref for overlay | |
animationType | 'fade' \| 'slideUp' \| 'slideDown' \| 'slideLeft' \| 'slideRight' \| 'zoom' | ❌ | fade | animation type for modal |
animationDuration | number | ❌ | 300 | animation duration for modal |
Usage
- Wrap your app with
ModalProvider
component
import { ModalProvider } from 'rc-global-modal';
function App() {
return (
<ModalProvider>
<Home />
</ModalProvider>
);
}
- Use
Modal
component to display modal(must be insideModalProvider
)
import { Modal } from 'rc-global-modal';
const Home = () => {
return (
<Modal id={1}>
<h1>IdOneModal</h1>
</Modal>
);
};
- Use
openModal
andcloseModal
function to open and close modal(must be insideModalProvider
)
import { Modal, useModal } from 'rc-global-modal';
const Home = () => {
const { openModal, closeModal } = useModal();
return (
<div>
<button onClick={() => openModal(1)}>open Id One modal</button>
<Modal id={1}>
<h1>IdOneModal</h1>
<button onClick={closeModal}>close modal</button>
</Modal>
</div>
);
};
Examples
import { Modal, useModal } from 'rc-global-modal';
const Home = () => {
const { openModal, closeModal } = useModal();
return (
<div>
<button onClick={() => openModal(1)}>open Id One modal</button>
<button onClick={() => openModal(2)}>open Id Two modal</button>
<Modal id={1}>
<h1>IdOneModal</h1>
<button onClick={closeModal}>close modal</button>
</Modal>
<Modal id={2}>
<h1>IdTwoModal</h1>
<button onClick={closeModal}>close modal</button>
</Modal>
</div>
);
};
export default Home;
License
MIT
0.1.21
1 year ago
0.1.22
1 year ago
0.1.20
1 year ago
0.1.18
1 year ago
0.1.19
1 year ago
0.1.17
1 year ago
0.1.14
1 year ago
0.1.15
1 year ago
0.1.16
1 year ago
0.1.10
1 year ago
0.1.11
1 year ago
0.1.12
1 year ago
0.1.13
1 year ago
0.1.8
1 year ago
0.1.7
1 year ago
0.1.9
1 year ago
0.1.6
1 year ago
0.1.2
2 years ago
0.1.4
2 years ago
0.1.3
2 years ago
0.1.5
2 years ago
0.1.0
2 years ago
0.1.1
2 years ago
0.0.9
2 years ago
0.0.8
2 years ago
0.0.5
2 years ago
0.0.4
2 years ago
0.0.7
2 years ago
0.0.6
2 years ago
0.0.3
2 years ago
0.0.2
2 years ago
0.0.1
2 years ago
0.0.0
2 years ago