2.2.5 • Published 5 years ago

@opuscapita/react-dropdown v2.2.5

Weekly downloads
4
License
MIT
Repository
github
Last release
5 years ago

react-dropdown

Description

Describe the component here

Installation

npm install @opuscapita/react-dropdown

Demo

View the DEMO

Builds

UMD

The default build with compiled styles in the .js file. Also minified version available in the lib/umd directory.

CommonJS/ES Module

You need to configure your module loader to use cjs or es fields of the package.json to use these module types. Also you need to configure sass loader, since all the styles are in sass format.

API

DropdownContainer

Prop nameTypeDefaultDescription
idnumber or stringrequiredUnique HTML id attribute
titlenumber, string or elementrequiredTitle of the dropdown
childrenstring, element or arrayContent of the dropdown
disabledbooleanfalseIs dropdown disabled or not
dropupbooleanfalseIs dropup or dropdown
isOpenbooleanfalseIs dropdown open by default
noCaretbooleanfalseIf false, caret is show
onTogglefunctionempty functionCallback function for toggle
pullRightbooleanfalseIf false, dropdown is aligned on left, otherwise on right
styleobject{ bsSize: 'xs', bsStyle: 'info' }Custom style for the dropdown
useAnchorbooleanfalseIf true, title is anchor

DropdownMenu

Prop nameTypeDefaultDescription
idnumber or stringrequiredUnique HTML id attribute
menuItemsarray of menu itemsrequiredList of the dropdown menu items
caretbooleanfalseIf true, caret is show
disabledbooleanfalseIs dropdown disabled or not
dropupbooleanfalseIs dropup or dropdown
pullLeftbooleanfalseIf false, dropdown is aligned on right, otherwise on left
titlenumber, string or elementTitle of the dropdown

DropdownMenu - menuItems prop attributes

Prop nameTypeDefaultDescription
disabledbooleanIs dropdown menu item disabled
disableClosingbooleanIs dropdown menu item's closing disabled
hrefstringHyperlink of the dropdown menu item
iconelementIcon of the dropdown menu item
idnumber or stringUnique HTML id attribute
onClickfunctionCallback function of click
titlenumber, string or elementTitle of the dropdown menu item
typestringEnumeration either 'item' or 'divider'

DropdownMultiSelect

Prop nameTypeDefaultDescription
idnumber or stringrequiredUnique HTML id attribute
isClearablebooleantrueIf false, selection cannot be empty
itemsarray of itemsrequiredDropdown menu items
checkedItemsListempty listChecked items
defaultPlaceholderstring'{N} items selected'Default placeholder
onChangefunctionempty functionCallback function of checked change
tabIndexnumber or string1tabIndex attribute

DropdownMultiSelect - items prop attributes

Prop nameTypeDefaultDescription
labelstringLabel of the dropdown menu item
labelPlaceholderstringPlaceholder of the dropdown menu item
valueboolean, number or stringValue of the dropdown menu item

Code example

import React from 'react';
import {
  DropdownContainer,
  DropdownMenu,
  DropdownMultiSelect,
} from '@opuscapita/react-dropdown';

export default class ReactView extends React.Component {
  constructor(props) {
    super(props);
    this.state = { checkedItems: List() };
  }

  componentWillMount() {
    this.items = this.initializeItems();
  }

  onChange = (checkedItems) => {
    this.setState({ checkedItems });
  }

  initializeItems = () => {
    const items = [];
    for (let i = 0; i < 300; i += 1) {
      items.push({ value: i, label: `Item ${i}` });
    }
    return items;
  };

  render() {
    return (
    <div>
      <DropdownContainer
        id="exampleDropdownContainer"
        isOpen
        noCaret
        title="Dropdown title"
      >
        <div>
          CONTENT
        </div>
      </DropdownContainer>
      <DropdownMenu
        id="example"
        menuItems={[
          {
            id: 'item_id_11',
            title: 'Item 1, dont\'t close',
            onClick: () => console.log('Item 1 clicked'),
            disableClosing: true,
          },
          {
            id: 'item_id_12',
            title: 'Item 2, with the icon',
            onClick: () => console.log('Item 2 clicked'),
            icon: <Icon type="indicator" name="ok" width={25} height={25} />,
          },
          {
            id: 'item_id_d1',
            type: 'divider',
          },
          {
            id: 'item_id_13',
            title: 'Item 3',
            onClick: () => console.log('Item 3 clicked'),
            disabled: true,
          },
        ]}
      />
      <DropdownMenu
        id="example2"
        menuItems={[
          {
            id: 'item_id_21',
            title: 'Item 1',
            onClick: () => console.log('Item 1 clicked'),
          },
          {
            id: 'item_id_22',
            title: 'Item 2',
            onClick: () => console.log('Item 2 clicked'),
          },
          {
            id: 'item_id_d1',
            type: 'divider',
          },
          {
            id: 'item_id_23',
            title: 'Item 3',
            onClick: () => console.log('Item 3 clicked'),
            disableClosing: true,
          },
        ]}
        title="Dropdown"
        caret
        pullRight={false}
      />
      <DropdownMultiSelect
        checkedItems={this.state.checkedItems}
        id="exampleDropdownMultiSelect"
        items={this.items}
        onChange={this.onChange}
        defaultPlaceholder="{N} kpl"
      />
    </div>
    );
  }
}