0.2.6 • Published 7 years ago

simple-rc-slidepanel v0.2.6

Weekly downloads
90
License
-
Repository
github
Last release
7 years ago

simple-rc-slidepanel

Accessible and simple slide panel component for React.JS

Table of Contents

Instalition

$ npm install simple-rc-slidepanel

Demo

You can find demo here.

Usage

<Slidepanel
	setWrapperRef = { this.setWrapperRef }
	closePanel = { this.closePanel }
	isPanelOpen = { isPanelOpen }
	left
	width = { "35%" }
	height = { "100%" }
	bgColor = { "#FFFAF0" }
>
	<h3>Children element</h3>
</Slidepanel>

Props

NameTypeDescription
left-panel position
right-panel position
top-panel position
bottom-panel position
widthstringpanel width
heightstringpanel height
bgColorstringpanel background color

Code example

import React, { Component } from 'react';
import Slidepanel from 'simple-rc-slidepanel';

export class App extends Component {
  constructor(props) {
      super(props);

      this.state = {
          isPanelOpen: false
      };

      this.openPanel = this.openPanel.bind(this);
      this.closePanel = this.closePanel.bind(this);
      this.setWrapperRef = this.setWrapperRef.bind(this);
      this.handleClickOutside = this.handleClickOutside.bind(this);
  }

  componentDidMount() {
      document.addEventListener('click', this.handleClickOutside, true);
  }

  componentWillUnmount() {
      document.removeEventListener('click', this.handleClickOutside, true);
  }

  setWrapperRef(node) {
      this.wrapperRef = node;
  }

  handleClickOutside(event) {
      if (this.wrapperRef && !this.wrapperRef.contains(event.target)) {
          this.closePanel();
      }
  }

  openPanel() {
      this.setState({ isPanelOpen: true });
  }

  closePanel() {
      this.setState({ isPanelOpen: false });
  }

  render() {
      const { isPanelOpen } = this.state;

      return (
          <div className="app">
              <div>
                  <button onClick = { this.openPanel }>Open left Slidepanel</button>
              </div>
              <Slidepanel
                  setWrapperRef = { this.setWrapperRef }
                  closePanel = { this.closePanel }
                  isPanelOpen = { isPanelOpen }
                  left
                  width = { "35%" }
                  height = { "100%" }
                  bgColor = { "#FFFAF0" }
              >
                  <h3>Children element</h3>
              </Slidepanel>
          </div>
      );
  }
}
0.2.6

7 years ago

0.2.5

7 years ago

0.2.4

7 years ago

0.2.3

7 years ago

0.2.2

7 years ago

0.2.1

7 years ago

0.2.0

7 years ago

0.1.12

7 years ago

0.1.11

7 years ago

0.1.10

7 years ago

0.1.9

7 years ago

0.1.8

7 years ago

0.1.7

7 years ago

0.1.6

7 years ago

0.1.5

7 years ago

0.1.4

7 years ago

0.1.3

7 years ago

0.1.2

7 years ago

0.1.1

7 years ago

0.0.3

7 years ago

0.0.1

7 years ago