Socket
Socket
Sign inDemoInstall

react-bootstrap-dropdown-menu

Package Overview
Dependencies
4
Maintainers
1
Versions
48
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    react-bootstrap-dropdown-menu

A simple Dropdown Menu for React. Commonly used as a user 'Settings' menu on websites where users login.


Version published
Weekly downloads
214
increased by98.15%
Maintainers
1
Install size
31.5 kB
Created
Weekly downloads
 

Readme

Source

react-bootstrap-dropdown-menu

npm version

A simple Dropdown Menu for React. Commonly used as a 'User Settings' menu on websites where users login.

Installation

npm install react-bootstrap-dropdown-menu --save

Include bootstrap in your project(if not already included)

<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" media="all">

Usage

A simple example using OnClick events. Download and run the demo for more examples, or browse the examples.

alt tag

import React from 'react';
import { DropdownMenu, MenuItem } from 'react-bootstrap-dropdown-menu';

class SettingsMenu extends React.Component {
  constructor() {
    super();
    this.deleteAccount = this.deleteAccount.bind(this);
    this.logout = this.logout.bind(this);
  }

  deleteAccount(e) {
    console.log("Deleting Account")
  }

  logout(e) {
    console.log("Logging out")
  }

  render() {
    return (
      <DropdownMenu userName="Chris Smith">
        <MenuItem text="Home" location="/home" />
        <MenuItem text="Edit Profile" location="/profile" />
        <MenuItem text="Change Password" location="/change-password" />
        <MenuItem text="Privacy Settings" location="/privacy-settings" />
        <MenuItem text="Delete Account" onClick={this.deleteAccount} />
        <MenuItem text="Logout" onClick={this.logout} />
      </DropdownMenu>
    );
  }
}

export default SettingsMenu;

DropdownMenu props

NameTypeRequiredDefaultPossible ValuesDescription
userNameStringNoundefinedAny string(e.g. 'John Doe')When provided, will render 'Logged in as: {userName}' in the top MenuItem
cssObjectNoSee Css belowObject as with attributes as described belowCSS as JS variables to be overridden
positionStringNorightleft, center, rightChanges the menu's horizontal drop position relative to the trigger
triggerTypeStringNoiconicon, text, imageThe Type of drop trigger
triggerStringNoglyphicon glyphicon-cogDepends on triggerTypeFor 'icon' triggerType: Any bootstrap glyphicon(http://getbootstrap.com/components/)
For 'text' triggerType: Any String can be used
For 'image' triggerType: Path to image(e.g. "/images/myimage.png")
triggerWidthStringNo50px (only applies to triggerType='image')Any numeric value with 'px' appended(e.g. '45px')The width to render the image trigger image.
triggerHeightStringNo50px (only applies to triggerType='image')Any numeric value with 'px' appended(e.g. '45px')The height to render the image trigger image.
caratColorStringNo#000000 (Black)Any 6 digit hex value (e.g. #F4E3A2)The color of the DropDown carat (for triggerType 'image' and 'text' only)
iconColorStringNo#000000 (Black)Any 6 digit hex value (e.g. #F4E3A2)The color of the Bootstrap icon
fadeInBooleanNofalsetrue or falseDropdown menu will fade in when set to true
onMouseoverFunctionNoundefinedA FunctionA function that will fire when the mouse pointer hovers over the DropdownMenu trigger
onMouseoutFunctionNoundefinedA FunctionA function that will fire when the mouse pointer moves away from the DropdownMenu trigger

MenuItem props

NameTypeRequiredDefaultPossible ValuesDescription
typeStringNoundefinedseparatorA horizontal rule. text prop is not required when using this type.
textStringYesundefinedAny String valueText value of the Link in the MenuItem
disabledBooleanNofalsetrue or falseDisables a MenuItem
locationStringNoundefinedAny String valueAn absolute or relative path
linkStyleObjectNoinheritedHash containing javascript styles(not CSS). See examples for more info
onClickFunctionNoundefinedA FunctionA function that will fire when the MenuItem Link is clicked

Css Override

The following CSS(as JS) can be passed to the DropdownMenu via the css prop to override color, padding etc. NOTE: separator only applies to the child MenuItem component.


const cssAsJs = {
  gear: {
    fontSize: '1.7em',
    cursor: 'pointer',
    color: 'black',
    padding: '14px',
    border: 'none'
  },
  triangle: {
    fontSize: '0.9em',
    cursor: 'pointer',
    color: '#000000',
    padding: '14px',
    border: 'none'
  },
  imageTrigger: {
    height: '50px',
    width: '50px',
    cursor: 'pointer',
    padding: '3px',
    border: 'none'
  },
  textTrigger: {
    cursor: 'pointer',
    padding: '14px',
    border: 'none',
    fontWeight: 'bold'
  },
  menuContent: {
    backgroundColor: '#f9f9f9',
    minWidth: '180px',
    padding: '12px',
    boxShadow: '0px 8px 16px 0px rgba(0,0,0,0.2)'
  },
  separator: {
    width: '90%',
    borderTop: '1px solid light-grey'
  }
}

Download Examples

git clone https://github.com/grizzthedj/react-bootstrap-dropdown-menu.git
cd react-bootstrap-dropdown-menu
npm install
gulp demo
Browse http://localhost:8080

Backlog

  • More Error handling.
  • Extend CSS styling so that user defined styles can be passed in as props.

Keywords

FAQs

Last updated on 22 Dec 2020

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