React Modern Drawer

1.4.0 · active · verified Sun Apr 19

React Modern Drawer is a lightweight and performant component library for creating highly customizable slide-out drawers in React applications. Currently at version 1.4.0, it offers a simple API to integrate responsive drawers for navigation, settings, or auxiliary content. The project maintains an active development pace, with recent updates focused on type improvements and build process fixes. Key differentiators include its small bundle size, excellent performance across various browsers, and ease of use, making it a strong candidate for projects prioritizing efficiency and developer experience without relying on larger UI frameworks. It provides fine-grained control over drawer direction, size, and overlay behavior.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to integrate and control a modern drawer component in a React application using hooks for state management. It shows how to toggle the drawer, set its direction and size, and apply custom CSS classes.

import React, { useState, useCallback } from 'react';
import Drawer from 'react-modern-drawer';
import 'react-modern-drawer/dist/index.css';

const MyDrawerComponent: React.FC = () => {
  const [isOpen, setIsOpen] = useState<boolean>(false);

  const toggleDrawer = useCallback(() => {
    setIsOpen((prevState) => !prevState);
  }, []);

  return (
    <div>
      <button onClick={toggleDrawer} style={{ padding: '10px 20px', cursor: 'pointer' }}>
        {isOpen ? 'Close' : 'Open'} Drawer
      </button>

      <Drawer
        open={isOpen}
        onClose={toggleDrawer}
        direction='right'
        size={320}
        className='custom-drawer-style'
        overlayClassName='custom-overlay-style'
      >
        <div style={{ padding: '20px', backgroundColor: '#f0f0f0', height: '100%' }}>
          <h2>Drawer Content</h2>
          <p>This is a modern drawer example with custom styling.</p>
          <button onClick={toggleDrawer} style={{ marginTop: '15px' }}>
            Close from inside
          </button>
        </div>
      </Drawer>
    </div>
  );
};

export default MyDrawerComponent;

view raw JSON →