This package has been deprecated

Author message:

This package has been deprecated. Please find this package under its new name @cloudflare/component-dropdown.

cf-component-dropdown

6.0.0 • Public • Published

cf-component-dropdown

Cloudflare Dropdown Component

Installation

Installation with yarn is recommended

 
$ yarn add cf-component-dropdown
 

Usage

import React from 'react';
import {
  Dropdown,
  DropdownLink,
  DropdownSeparator
} from 'cf-component-dropdown';
import { Button, ButtonGroup } from 'cf-component-button';
import { Code, CodeBlock } from 'cf-component-code';
 
class DropdownComponent extends React.Component {
  constructor(props) {
    super(props);
    this.state = {
      dropdown1Open: false,
      dropdown2Open: false
    };
  }
 
  render() {
    return (
      <div>
        <ButtonGroup>
          <Button
            type="primary"
            onClick={() => this.setState({ dropdown1Open: true })}
          >
            Open Dropdown 1
          </Button>
 
          {this.state.dropdown1Open && (
            <Dropdown onClose={() => this.setState({ dropdown1Open: false })}>
              <DropdownLink to="/foo">Link to /foo</DropdownLink>
              <DropdownLink to="/bar">Link to /bar</DropdownLink>
              <DropdownSeparator />
              <DropdownLink to="/baz">Link to /baz</DropdownLink>
              <DropdownLink to="/bat">Link to /bat</DropdownLink>
              <DropdownLink disabled to="/bad">
                Disabled dropdown link
              </DropdownLink>
            </Dropdown>
          )}
 
          <Button
            type="success"
            onClick={() => this.setState({ dropdown2Open: true })}
          >
            Open Dropdown 2
          </Button>
 
          {this.state.dropdown2Open && (
            <Dropdown
              align="right"
              onClose={() => this.setState({ dropdown2Open: false })}
            >
              <DropdownLink to="/foo">Link to /foo</DropdownLink>
              <DropdownLink to="/bar">Link to /bar</DropdownLink>
              <DropdownSeparator />
              <DropdownLink to="/baz">Link to /baz</DropdownLink>
              <DropdownLink to="/bat">Link to /bat</DropdownLink>
            </Dropdown>
          )}
        </ButtonGroup>
        <p>
          {`You can also optionally pass an align prop with either "left" or
          "right"`}
        </p>
        <CodeBlock>{`<Dropdown align="right" ...>`}</CodeBlock>
        <p>
          <Code>{`<DropdownLink/>`}</Code> just wraps cf-component-link so you
          can use either to to specify a route or pass an onClick handler.
        </p>
        <CodeBlock>{`<DropdownLink to="/my-route"/>`}</CodeBlock>
        <CodeBlock>{`<DropdownLink onClick={this.handleClick}/>`}</CodeBlock>
        <p>
          Note: to requires that you setup cf-util-route-handler prior to
          routing.
        </p>
      </div>
    );
  }
}
 
export default DropdownComponent;
 

Readme

Keywords

none

Package Sidebar

Install

npm i cf-component-dropdown

Weekly Downloads

230

Version

6.0.0

License

BSD-3-Clause

Unpacked Size

43.7 kB

Total Files

19

Last publish

Collaborators

  • lerwincf
  • lbarthonet
  • cf-media-manager
  • jacobbednarz
  • celso
  • cf-radar
  • dash_service_account
  • g4brym
  • snigdha34
  • wrangler-publisher
  • marksteyn
  • chiminator
  • sgoodhew_cf
  • terinjokes
  • third774
  • jsteinberger
  • jasnell
  • asapzacy
  • pcostanzo
  • gregbrimble
  • geelen
  • rexscaria
  • dcruz_cf
  • xuranwang
  • jculvey
  • sejoker
  • vasturiano
  • cf-ci-write
  • segments-write
  • thibmeu
  • xortive
  • gurjinder
  • cf-ci2
  • lvalenta
  • worenga