Multi-Level Menu for React Projects.
The main goal of this package is to deliver a slim and Skinny Multi-Level Menu for React Projects. That can fit into any kind of projects with no muss, no fuss. Within few lines, you will get an animation ready multilevel list that just works.
Check the Multi-Level Menu in action, click here.
- FontAwesome Icons are supported.
- Use images as icons in the list.
You can use either the npm or yarn command-line tool to install packages. Use whichever is appropriate for your project in the examples below.
npm install --save react-multilevel-menu
yarn add --save react-multilevel-menu
Follow below steps to add multi level list in your project
import { MultilevelMenu } from 'react-multilevel-menu';
import {list, configurations} from './constants'; // Your Menu Array and configuration Object
const App = () => {
const selectedItem = (event) => {
console.log(event);
}
return (
<div className="app__page-container">
<MultilevelMenu
list={list}
configuration={configurations}
selectedListItem={selectedItem}
selectedLabel={selectedItem}
/>
</div>
);
};
export default App
Make sure you structure of array should look like array shown below,
const list: MultilevelNodes[] = [
{
label: 'NPM',
faIcon: 'fab fa-500px',
link: 'https://www.npmjs.com/package/ng-material-multilevel-menu',
hrefTargetType: '_blank' // _blank|_self|_parent|_top|framename
},
{
label: 'Item 1 (with Font awesome icon)',
imageIcon: '/batman.jpg',
activeImageIcon: '/ironman.jpg',
items: [
{
label: 'Item 1.1',
faIcon: 'fab fa-accusoft',
onSelected: function() {
console.log('Item 1.2.2.1');
}
},
{
label: 'Item 1.2',
faIcon: 'fab fa-accessible-icon',
items: [
{
label: 'Item 1.2.1',
faIcon: 'fas fa-allergies',
onSelected: function() {
console.log('Item 1.2.2.1');
}
},
{
label: 'Item 1.2.2',
faIcon: 'fas fa-ambulance',
items: [
{
label: 'Item 1.2.2.1',
faIcon: 'fas fa-anchor',
onSelected: function() {
console.log('Item 1.2.2.1');
}
}
]
}
]
}
]
},
{
label: 'Item 2',
faIcon: 'fas fa-anchor',
items: [
{
label: 'Item 2.1',
faIcon: 'fab fa-accusoft',
activeFaIcon: 'fab fa-accusoft',
disabled: true,
},
{
label: 'Item 2.2',
faIcon: 'fas fa-anchor',
activeFaIcon: 'fab fa-accusoft',
}
]
},
{
label: 'Item 3',
faIcon: 'fab fa-accusoft',
activeFaIcon: 'fas fa-anchor',
onSelected: function() {
console.log('Item 3');
}
},
{
label: 'Item 4',
link: '/item-4',
faIcon: 'fab fa-accusoft',
hidden: true
}
];
- Using
configuration
, You can customise the appearance of the list.paddingAtStart: boolean
=> [optional] If you don't want padding at the start of the list item, then you can givefalse
. The default value will betrue
.highlightOnSelect: boolean
=> [optional] If you want to highlight the clicked item in the list, then you can do that by making ittrue
. The default value will befalse
.useDividers: boolean
=> [optional] If you want to the list to have dividers. The default value will betrue
.classname: string;
=> [optional] You can give your own custom class name in order to modify the list appearance.listBackgroundColor: string;
=> [optional] You can apply custom color to the background of the list.fontColor: string;
=> [optional] Changes the color of Text and icons inside the list.backgroundColor: string;
=> [optional] This will change the background color list container.selectedListFontColor: string;
=> [optional] This will change the font color of selected list item.
Below is example how you can apply different background and Font colors,
config = {
paddingAtStart: true,
classname: 'my-custom-class',
listBackgroundColor: `rgb(208, 241, 239)`,
fontColor: `rgb(8, 54, 71)`,
backgroundColor: `rgb(208, 241, 239)`,
selectedListFontColor: `red`,
highlightOnSelect: true,
useDividers: false,
};
selected-amml-item
: This class will be applied to currently selected link and it's father links.active-amml-item
: This class will be applied to currently selected link.
I welcome you to fork and add more features into it. If you have any bugs or feature request, please create an issue at github repository.
This Project is build using tsdx.
MIT