Socket
Book a DemoInstallSign in
Socket

@trend/drawer

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@trend/drawer

"TREND Components drawer component."

0.5.0
latest
Source
npmnpm
Version published
Weekly downloads
1
Maintainers
1
Weekly downloads
 
Created
Source

Drawer

React off-canvas menu region that can contain a title, sub-title, and a self-contained inner scrollable area.

Installation

## Has peer dependency with react and react-dom
npm install react react-dom
npm install @trend/Drawer

Basic Usage

With a module bundler like webpack, use as you would anything else:

Default Drawer

// Using ES6 modules.
import React from 'react';
import Drawer from '@trend/drawer';

const {
  getRootProps,
  getHdProps,
  getTitleProps,
  getSubtitleProps,
  getInnerProps
} = Drawer.api();

function Aside({ children }) {
  return <Drawer>
    <div {...getRootProps()}>
      <div {...getHdProps()}>
        <h1 {...getTitleProps()}>Drawer Title</h1>
        <h2 {...getSubtitleProps()}>Drawer SubTitle</h2>
      </div>
      <div {...getInnerProps({ className: 'tc-phb'})}>
        Inner Drawer area
      </div>
    </div>
  </Drawer>;
}

// or pass children as a function

function AsideChildFunction({ children }) {
  return <Drawer>
    { api => (
      <div {...api.getRootProps()}>
        <div {...api.getHdProps()}>
          <h1 {...api/getTitleProps()}>Drawer Title</h1>
          <h2 {...api.getSubtitleProps()}>Drawer SubTitle</h2>
        </div>
        <div {...api.getInnerProps({ className: 'tc-phb'})}>
          Inner Drawer area
        </div>
      </div>
    )}
  </Drawer>;
}

Methods

API (static)

Returns an object of prop-getters for various sub-components to build out. See api table for getters.

Drawer Overlay

This is a controlled component, use the open prop to adjust the visibility of the drawer.

// Using ES6 modules.
import React from 'react';
import { DrawerOverlay as Drawer } from '@trend/drawer';

function Aside({ open, toggleDrawer }) {
  return <Drawer open={open} onToggle={toggleDrawer}>
    { api => (
      <Fragment>
        <div {...api.getHdProps()}>
          <h1 {...api.getTitleProps()}>Title</h1>
          <h2 {...api.getSubtitleProps()}>SubTitle</h2>
        </div>
        <div {...api.getInnerProps({className: 'tc-phb'})}>
          <a className="tc-display-block"
            href="#"
            onClick={this.onLinkClick}>
            link 1
          </a>
          <a className="tc-display-block"
            href="#"
            onClick={this.onLinkClick}>
            link 2
          </a>
          <button className="tc-display-block"
            onClick={this.toggleDrawer}>
            link 3
          </button>
        </div>
      </Fragment>
    )}
    </Drawer>;
}

NOTE Drawer overaly will automatically generate the root element, unlike the default Drawer component where the developer is responsible for implementing the root node. The default HTML tag is a div, pass in a tag prop to change the default.

Props:

hasMask

boolean | optional, true

Render a mask under the drawer above the content when opened.

onToggle

function | optional, noop

Function that gets called on clicks to the mask or areas outside of a drawer while opened.

open

boolean | required, false

The prop that will toggle the display of the drawer.

API

This API is the same for both the default and overlay drawer types.

PropertyCategoryTypeDescription
getRootPropsprop getterfunction(props: object)Returns props to the root node Only available for default Drawer.
getHdPropsprop getterfunction(props: object)Returns props for the header sub-component.
getTitlePropsprop getterfunction(props: object)Returns props for the drawer title.
getSubtitlePropsprop getterfunction(props: object)Returns props for the drawer subtitle.
getInnerPropsprop getterfunction(props: object)Returns props for the drawer inner sub-component.

Keywords

TREND Components

FAQs

Package last updated on 19 Apr 2019

Did you know?

Socket

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

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.