Socket
Socket
Sign inDemoInstall

rc-drawer

Package Overview
Dependencies
12
Maintainers
5
Versions
133
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    rc-drawer

drawer component for react


Version published
Weekly downloads
1.3M
increased by4.24%
Maintainers
5
Install size
730 kB
Created
Weekly downloads
 

Package description

What is rc-drawer?

The rc-drawer package is a React component that provides a drawer panel that can slide in from the edge of the screen. It is commonly used for implementing side menus, navigation, or other hidden content that can be revealed interactively.

What are rc-drawer's main functionalities?

Basic Drawer

This code sample demonstrates how to create a basic drawer that can be toggled open and closed with a button. The drawer's visibility is controlled by the 'open' state.

import Drawer from 'rc-drawer';
import React from 'react';
import ReactDOM from 'react-dom';

class App extends React.Component {
  state = {
    open: false,
  };

  onOpenChange = (open) => {
    this.setState({ open });
  };

  render() {
    return (
      <div>
        <button onClick={() => this.onOpenChange(true)}>Open Drawer</button>
        <Drawer
          open={this.state.open}
          onOpenChange={this.onOpenChange}
        >
          <p>This is the content of the drawer.</p>
        </Drawer>
      </div>
    );
  }
}

ReactDOM.render(<App />, document.getElementById('container'));

Positioning

This code sample shows how to position the drawer on the right side of the screen. The 'position' prop can be set to 'left', 'right', 'top', or 'bottom'.

import Drawer from 'rc-drawer';
import React from 'react';
import ReactDOM from 'react-dom';

class App extends React.Component {
  state = {
    open: false,
  };

  onOpenChange = (open) => {
    this.setState({ open });
  };

  render() {
    return (
      <Drawer
        open={this.state.open}
        position='right'
        onOpenChange={this.onOpenChange}
      >
        <p>This drawer slides in from the right.</p>
      </Drawer>
    );
  }
}

ReactDOM.render(<App />, document.getElementById('container'));

Custom Styling

This code sample illustrates how to apply custom styles to the drawer. The 'style' prop accepts a JavaScript object with CSS properties.

import Drawer from 'rc-drawer';
import React from 'react';
import ReactDOM from 'react-dom';

class App extends React.Component {
  render() {
    return (
      <Drawer
        open={true}
        style={{ backgroundColor: 'lightblue' }}
      >
        <p>Custom styled drawer content.</p>
      </Drawer>
    );
  }
}

ReactDOM.render(<App />, document.getElementById('container'));

Other packages similar to rc-drawer

Readme

Source

rc-drawer

NPM version dumi build status codecov node version npm download

Example

https://drawer-react-component.vercel.app/

Usage

import Drawer from 'rc-drawer';
import React from 'react';
import ReactDom from 'react-dom';

ReactDom.render(
  <Drawer>
    {menu children}
  </Drawer>
, mountNode);

Install

rc-drawer

Browser Support

IEChromeFirefoxOperaSafari
IE 10+ ✔Chrome 31.0+ ✔Firefox 31.0+ ✔Opera 30.0+ ✔Safari 7.0+ ✔

API

propstypedefaultdescription
classNamestringnull-
classNames{ mask?: string; content?: string; wrapper?: string; }-pass className to target area
styles{ mask?: CSSProperties; content?: CSSProperties; wrapper?: CSSProperties; }-pass style to target area
prefixClsstring'drawer'prefix class
widthstring | numbernulldrawer content wrapper width, drawer level transition width
heightstring | numbernulldrawer content wrapper height, drawer level transition height
openbooleanfalseopen or close menu
defaultOpenbooleanfalsedefault open menu
placementstringleftleft top right bottom
levelstring | arrayallWith the drawer level element. all/ null / className / id / tagName / array
levelMovenumber | array | funcnulllevel move value. default is drawer width
durationstring.3slevel animation duration
easestringcubic-bezier(0.78, 0.14, 0.15, 0.86)level animation timing function
getContainerstring | func | HTMLElementbodyReturn the mount node for Drawer. if is null use React.creactElement
showMaskbooleantruemask is show
maskClosablebooleantrueClicking on the mask (area outside the Drawer) to close the Drawer or not.
maskStyleCSSPropertiesnullmask style
afterVisibleChangefuncnulltransition end callback(open)
onClosefuncnullclose click function
keyboardbooleantrueWhether support press esc to close
autoFocusbooleantrueWhether focusing on the drawer after it opened
onMouseEnterReact.MouseEventHandler<HTMLDivElement>-Trigger when mouse enter drawer panel
onMouseOverReact.MouseEventHandler<HTMLDivElement>-Trigger when mouse over drawer panel
onMouseLeaveReact.MouseEventHandler<HTMLDivElement>-Trigger when mouse leave drawer panel
onClickReact.MouseEventHandler<HTMLDivElement>-Trigger when mouse click drawer panel
onKeyDownReact.MouseEventHandler<HTMLDivElement>-Trigger when mouse keydown on drawer panel
onKeyUpReact.MouseEventHandler<HTMLDivElement>-Trigger when mouse keyup on drawer panel

2.0 Rename onMaskClick -> onClose, add maskClosable.

Development

npm install
npm start

Keywords

FAQs

Last updated on 07 Feb 2024

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc