βDockable Menu bar for Vue
yarn install vue-dock-menu
vue-dock-menu
has some great defaults. Please check the prop section for all available options.
The following snippet creates a simple Menubar and docks it to the top
of the page.
<template>
<vue-dock-menu :items="items">
</vue-dock-menu>
</template>
<script>
import { DockMenu } from "vue-dock-menu";
import "vue-dock-menu/dist/vue-dock-menu.css";
export default {
name: "example",
components: {
DockMenu
},
data() {
return {
items = [
{
name: "File",
menu: [{ name: "Open"}, {name: "New Window"}, {name: "Exit"}]
},
{
name: "Edit",
menu: [{ name: "Cut"}, {name: "Copy"}, {name: "Paste"}]
}
]
}
}
}
</script>
Name | Description | Default |
---|---|---|
dock | default docking position. Can be any one of TOP , LEFT , RIGHT , BOTTOM |
TOP |
on-selected | Callback that will be called on a menu item selection | |
items | Data for the Menu bar | [] |
theme | prop to customize the color theme | |
draggable | enables/disbales dragging on the menubar. | True |
use the dock
prop to dock the menubar to your preferred position. The prop can accept the following values TOP
, BOTTOM
, LEFT
, RIGHT
.
Here we dock the Menu bar to the right side of the screen.
<vue-dock-menu>
:items="items"
dock="RIGHT"
</vue-dock-menu>
The on-selected
prop is used to retrieve the selected menu item. The callback receives an object with name
and a path
property.
if you select the Copy
menu item under the Edit
menu, below would be the payload received on the on-selected
callback.
{
name: "Copy",
path: "edit>copy"
}
Use the items
prop to create Simple or Nested menus of your liking.
Here we create a simple Menu structure with 3 Menu items with Edit
and Open Recent
having sub menus.
isDivider
property set to true
.disable
to true
.const items = [
{ name: "New" },
{ isDivider: true },
{
name: "Edit",
menu: {
name: "edit-items",
disable: true
},
},
{ isDivider: true },
{
name: "Open Recent",
menu: {
name: "recent-items",
},
},
{ isDivider: true },
{ name: "Save", disable: true },
{ name: "Save As..." },
{ isDivider: true },
{ name: "Close" },
{ name: "Exit" },
]
<vue-dock-menu>
:items="items"
dock="BOTTOM"
</vue-dock-menu>
use the theme
prop to customize the colors of the menu bar.
<menu-bar
:items="items"
:on-selected="selected"
:theme="{
primary: '#001B48',
secondary: '#02457a',
tertiary: '#018abe',
textColor: '#fff'
}"
/>
Each menu item can be iconified and the component uses slots to inject the icons.
Pass individual icons (or images) as templates marked with a unique slot id
. please make sure the ids
match the iconSlot
property in the items array.
<menu-bar
:items="items"
:on-selected="selected"
>
<template #file>
<img
src="../assets/file.svg"
alt="file"
:style="style"
>
</template>
<template #window>
<img
src="../assets/window-maximize.svg"
alt="file"
:style="style"
>
</template>
</menu-bar>
export default defineComponent({
name: "MenuExample",
data() {
return {
items: [
{ name: "New File", iconSlot: "file" },
{ name: "New Window", iconSlot: "window" },
]
}
}
})
This works seamlessly even for nested
menu structure. Make sure the slot ids
match and the component will render the icons appropriately.
<menu-bar
:items="items"
:on-selected="selected"
>
<template #window>
<img
src="../assets/window-maximize.svg"
alt="file"
:style="style"
>
</template>
</menu-bar>
export default defineComponent({
name: "MenuExample",
data() {
return {
items: [
{ name: "New File",
subMenu: [{ name: "New Window", iconSlot: "window" }]},
]
}
}
});
# install dependencies
yarn install
# start dev
yarn run dev
# package lib
npm run rollup
# run css linting
yarn run lint:css
git checkout -b new-feature
)git commit -am 'Add feature'
)git push origin new-feature
)Prabhu Murthy β @prabhumurthy2 β [email protected]
Distributed under the MIT license. See LICENSE
for more information.