react-draggable-menu
Draggable menu with dynamic options to customise it as per user requirements.
A Node.js React package that gives draggable menu with dynamic options to make it custom as per user requirment. Also give a better user experience with better and flexible options.
Demo and Docs
-
Inspired by codepen link
Installation
The package can be installed via NPM:
npm install react-draggable-menu --save yarn add react-draggable-menu
react-draggable-menu can be imported as follows
var DraggableMenu = ; OR ;
Prerequisite
You need to include fontowesome script link in your index.html.
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.8.1/css/all.css" integrity="sha384-50oBUHEmvpQ+1lW4y57PTFmhCaXp0ML5d60M1M7uH2+nqUivzIebhndOJK28anvf" crossorigin="anonymous">
Visit Font awesome icon list to choose your icon list.
Examples
Basic Example with all default props
import React Component from 'react';import DraggableMenu from 'react-draggable-menu'; { return <DraggableMenu /> ; } ;
Example to pass the custom icon and data to menu
;; { return <DraggableMenu menuIcon= "fas fa-bars" '#fff' "#2196f3"0'Main Menu' menuList= "fab fa-affiliatetheme" '#fff' "#FBBD3B" 2'item 1' "fas fa-ad" '#fff' "#4185F4" 3'item 2' "fas fa-adjust" '#fff' "#48A853" 4'item 3' //icon name, color, background-color, id, tooltip-text /> ; } ;
Example to show handleChange and isOpen method of menu
import React Component from 'react';import DraggableMenu from 'react-draggable-menu'; { //do something here with data } { //do something here with value } { return <DraggableMenu = =/> ; } ;
Example to open menu item horizontally (by default it show items vertically)
;; { return <DraggableMenu isVerticalOpen= false /> ; } ;
Example to show menu item open by default initially
import React Component from 'react';import DraggableMenu from 'react-draggable-menu'; { return <DraggableMenu = /> ; } ;
Example to set initial position of menu icon on screen
;; { return <DraggableMenu initialPosition= margin: 'auto' top: 0 right: 0 bottom: 0 left: 0 //its default position, you camn change using css in this object /> ; } ;
Example to set border color and its style
;; { return <DraggableMenu border='1px solid #fff' //you can pass any valid border property in this prop /> ; } ;
Example to show drag menu to only right side
;; { return <DraggableMenu dragToRightOnly= true /> ; } ;
Example to show drag menu to only left side
;; { return <DraggableMenu dragToLeftOnly= true /> ; } ;
Example to show drag menu to only top side
;; { return <DraggableMenu dragToTopOnly= true /> ; } ;
Example to show drag menu to only bottom side
;; { return <DraggableMenu dragToBottomOnly= true /> ; } ;
Example to disable draggable menu
;; { return <DraggableMenu isDraggable= false /> ; } ;
Example to stop closing menu items on ESC press from keyboard
;; { return <DraggableMenu closeOnEsc= false /> ; } ;
Example to stop closing menu items on click outside menu
;; { return <DraggableMenu closeOnClick= false /> ; } ;
Example to stop closing menu items on selection(click) of item from menu list
;; { return <DraggableMenu closeOnSelection= false /> ; } ;
Example to show menu item list open for some time when page load and then close automatically
;; { return <DraggableMenu showMenuOpenForTime= 1000 //pass the values in miliseconds /> ; } ;
Default parameter options value
isVerticalOpen: true dragToRightOnly: false dragToLeftOnly: false dragToTopOnly: false dragToBottomOnly: false isDraggable: true isMenuOpen: false initialPosition: {} closeOnEsc: true closeOnClick: true closeOnSelection: true showMenuOpenForTime: 0 border:'1px solid #fff' menuIcon: "fas fa-bars" '#fff' "#2196f3"0'Main Menu' menuList: "fab fa-affiliatetheme" '#fff' "#FBBD3B" 2'item 1' "fas fa-ad" '#fff' "#4185F4" 3'item 2' "fas fa-adjust" '#fff' "#48A853" 4'item 3' "fab fa-adn" '#fff' "#EA4335" 5'item 4'
Available options list
isVerticalOpen: Boolean dragToRightOnly: Boolean dragToLeftOnly: Boolean dragToTopOnly: Boolean dragToBottomOnly: Boolean isDraggable: Boolean isMenuOpen: Boolean initialPosition: Object closeOnEsc: Boolean closeOnClick: Boolean closeOnSelection: Boolean showMenuOpenForTime: Number menuIcon: Array menuList: Arrays border: String isOpen: Function handleChange: Function