This component library is inspired from Jesse Couch's Animated Modal codepen.
yarn add @dorbus/react-animated-modal
npm install @dorbus/react-animated-modal
To use Animated Modal in your application, first import AnimatedModal
, AnimatedModalObject
, ModalAnimation
and AnimatedModalFrame
.
Create a Ref object using useRef
and pass it to the AnimatedModal
Component.
const ref = useRef<AnimatedModalObject>(null);
<AnimatedModal ref={ref} />
// Open modal
ref.current?.OpenModal()
// Open modal with animation
ref.current?.OpenModal(ModalAnimation.Reveal)
ref.current?.CloseModal()
For now, the library supports seven different animations:
- Unfold:
ModalAnimation.Unfold
- Reveal:
ModalAnimation.Reveal
- Uncover:
ModalAnimation.Uncover
- Flash:
ModalAnimation.Flash
- Slide:
ModalAnimation.Slide
- BlowUp:
ModalAnimation.BlowUp
- Sketch:
ModalAnimation.Sketch
Use animation prop to enable different animations, by default the animation is of type Unfold.
<AnimatedModal
ref={ref}
animation={ModalAnimation.Unfold}/>
Component | Prop | Type | Description | Default |
---|---|---|---|---|
AnimatedModal | startOpen | boolean |
State open state of the modal in start | false |
animation | ModalAnimation |
Different modal animations | ModalAnimation.Unfold |
|
closeOnBackgroundClick | boolean |
Whether the modal should close on background click | true |
|
backgroundStyle | CSS |
Pass custom background styles | - | |
modalStyle | CSS |
Pass custom modal styles | - |
Code and documentation Copyright (c) ISC © 2022 Dorbus.