1.1.1 ā€¢ Published 2 months ago

react-swipe-modal v1.1.1

Weekly downloads
-
License
MIT
Repository
github
Last release
2 months ago

React-Swipe-Modal

šŸŒ€ A swipeable modal for the browser, just like on your smartphone.

Features

  • Swipe or tap to close
  • Completely customizable appearance
  • Different closing triggers and behaviours
  • Display a react component inside the modal
  • onShow and onClose hooks

Demo

Try it out right here!

Installation

npm i react-swipe-modal

Usage

import { useRef } from 'react';
import SwipeModal, { SwipeModalRef } from 'react-swipe-modal';

const App = () => {
    const modalRef = useRef<SwipeModalRef>(null);
    
    const showModal = () => modalRef.current?.show();

    return (
        <SwipeModal ref={modalRef}>
            Put anything inside here!
        </SwipeModal>
    );
};

Props

NameTypeDefault valueDescription
childrenReactNode\ReactNode[]requiredThe content to be rendered inside the modal.
Styling
animationDurationnumber300The duration of the modal's opening and closing animation in milliseconds.
backdropOpacitynumber0.3The opacity of the modal's backdrop.
barColorstring'dimgrey'The color of the bar at the top of the modal.
borderRadiusstring'1.2rem'The border radius of the modal.
hideBarbooleanfalseSet to true to hide the bar at the top of the modal.
maxWidthstring'100vw'The maximum width of the modal.
modalColorstring'black'The background color of the modal.
Functionality
closeTrigger'swipe'|'height''swipe'The trigger to close the modal.'swipe' means that modal will close when modal was swiped down faster than closeTriggerSpeed.'height' means that modal will close when height of modal is less than closeTriggerPercentage.
closeTriggerPercentagenumber50The height in percent that triggers the modal to close when using the closeTrigger 'height'.
closeTriggerSpeednumber500The swipe speed in px/s that triggers the modal to close when using the closeTrigger 'swipe'.
disableSwipebooleanfalseSet to true if you don't want to allow swiping.
swipeOnlyFromBarbooleanfalseSet to true if you want to allow swiping only from the bar.
Additional Styling
backdropStyleViewStyle|ViewStyle[]Additional styles to be applied to the backdrop.
barStyleViewStyle|ViewStyle[]Additional styles to be applied to the modal.
modalStyleViewStyle|ViewStyle[]Additional styles to be applied to the modals.
Callbacks
onShow() => voidA callback function that will be triggered when the modal is shown.
onHide() => voidA callback function that will be triggered when the modal is closed.

Public Methods

NameDescription
show()Shows the modal.
close()Closes the modal.

Contribute

Show your ā¤ļø and support by giving a ā­. Any suggestions are welcome!

You can find more from me on my homepage manuelpickl.com.

License

Licensed under MIT

1.1.1

2 months ago

1.1.0

2 months ago

1.0.1

2 months ago

1.0.0

2 months ago

0.2.3

2 months ago

0.2.2

2 months ago

0.2.1

2 months ago

0.2.0

2 months ago

0.1.0

2 months ago

0.0.3

2 months ago

0.0.2

2 months ago

0.0.1

2 months ago