1.1.6 • Published 6 months ago

react-slide-drawer v1.1.6

Weekly downloads
-
License
ISC
Repository
-
Last release
6 months ago

React Slide Drawer

React Slide Drawer is a customizable, responsive and user-friendly drawer component for React, inspired by React Native Navigation. It supports multiple drawer types and smooth animations, making it perfect for implementing side navigation drawers. The front drawer type is especially optimized for mobile use, providing a traditional overlay-style drawer that slides over the content, while other types cater to both mobile and desktop needs.

Demo

Check out the demo here: React Slide Drawer Demo

Features

  • Multiple Drawer Types: Choose between slide, front, and back animations for different drawer behaviors.
  • Customizable Positioning: Easily position the drawer to slide in from either the left or right.
  • Full-Screen Option: Although the drawer can be used relative to any element or div, enabling the forceFullScreen prop makes it occupy the full screen when the parent is relatively positioned.
  • Backdrop Close: Optionally enable or disable the backdrop that closes the drawer when clicked.

Drawer Types

  • front: A traditional drawer that covers the screen with an overlay behind it.
  • slide: Both the screen and the drawer slide simultaneously to reveal the drawer.
  • back: The drawer is revealed behind the screen (Note: This feature is not currently supported).

Installation

You can install react-slide-drawer via npm or yarn:

npm install react-slide-drawer
# or
yarn add react-slide-drawer

Usage

import { useState } from "react";
import { SlideDrawer } from "react-slide-drawer";

const App = () => {
    const [showDrawer, setShowDrawer] = useState(false);

    return (
        <div style={styles.container}>
            <button 
                onClick={() => setShowDrawer(!showDrawer)}
                style={styles.button}
                onMouseOver={(e) => e.target.style.backgroundColor = "#2563eb"}
                onMouseOut={(e) => e.target.style.backgroundColor = "#3b82f6"}
            >
                Toggle Drawer
            </button>

            <SlideDrawer
                show={showDrawer}
                onClose={() => setShowDrawer(false)}
                width={300}
                position="left"
                type="front"
                animated={true}
            >
                <div style={styles.drawer}>
                    {/* Header */}
                    <div style={styles.headerFooter}>
                        <span style={{ fontSize: "18px", fontWeight: "bold" }}>Drawer Header</span>
                        <button 
                            onClick={() => setShowDrawer(false)}
                            style={styles.closeButton}
                        >
                            &times;
                        </button>
                    </div>
                    
                    {/* Content */}
                    <div style={styles.content}>
                        <p>This is the content inside the drawer!</p>
                    </div>
                    
                    {/* Footer */}
                    <div style={{ ...styles.headerFooter, borderTop: "1px solid #d1d5db" }}>
                        <span style={{ fontSize: "14px", color: "#6b7280" }}>Drawer Footer</span>
                    </div>
                </div>
            </SlideDrawer>
        </div>
    );
};

const styles = {
    container: {
        display: "flex",
        justifyContent: "center",
        alignItems: "center",
        height: "100vh",
        backgroundColor: "#f3f4f6"
    },
    button: {
        padding: "10px 16px",
        backgroundColor: "#3b82f6",
        color: "white",
        borderRadius: "8px",
        boxShadow: "0 2px 4px rgba(0, 0, 0, 0.1)",
        cursor: "pointer",
        border: "none",
        transition: "background-color 0.3s"
    },
    drawer: {
        display: "flex",
        flexDirection: "column",
        height: "100%",
        backgroundColor: "#e5e7eb",
        boxShadow: "2px 0 5px rgba(0, 0, 0, 0.1)"
    },
    headerFooter: {
        padding: "16px",
        backgroundColor: "white",
        borderBottom: "1px solid #d1d5db",
        display: "flex",
        justifyContent: "space-between",
        alignItems: "center"
    },
    content: {
        flexGrow: 1,
        display: "flex",
        flexDirection: "column",
        alignItems: "center",
        justifyContent: "center",
        textAlign: "center",
        padding: "16px",
        color: "#374151"
    },
    closeButton: {
        color: "#6b7280",
        cursor: "pointer",
        fontSize: "20px"
    }
}

export default App;

Props

PropTypeDefault ValueDescription
showbooleanfalseToggle the drawer.
widthnumber250Specifies the width of the drawer in pixels.
animatebooleantrueDetermines whether the drawer animation should be enabled when opening and closing.
positionenum"left" or "right"Defines the position of the drawer. Set to 'left' or 'right' to determine which side the drawer slides in from.
forceFullScreenbooleanfalseIf true, the drawer will occupy the full screen. This is useful when the parent container has a relative position.
zIndexnumber10The z-index value of the drawer, used for layering with other elements.
onClose() => voidA function to be called when the drawer is closed (e.g., when the backdrop is clicked).
typeenum"slide" or "front"The drawer's behavior type. Set to 'front' for overlay-style or 'slide' for sliding-style animation. The 'back' type is not supported at this time.
showBackdropbooleantrueIf set to false, the backdrop will not be displayed. Only applies to 'front' drawer type.

License

React Slide Drawer is released under the MIT license.

1.1.6

6 months ago

1.1.5

6 months ago

1.1.4

6 months ago

1.1.3

6 months ago

1.1.2

6 months ago

1.1.1

6 months ago

1.1.0

6 months ago

1.0.17

6 months ago

1.0.16

6 months ago

1.0.13

6 months ago

1.0.12

6 months ago

1.0.11

6 months ago

1.0.10

6 months ago

1.0.9

6 months ago

1.0.7

6 months ago

1.0.6

6 months ago

1.0.5

6 months ago

1.0.2

6 months ago

1.0.1

6 months ago

1.0.0

6 months ago