1.9.1 ā€¢ Published 3 years ago

vue-float-menu v1.9.1

Weekly downloads
112
License
MIT
Repository
github
Last release
3 years ago

Build Status Maintainability DeepScan grade DeepSource Snyk Vulnerabilities for GitHub Repo minified Depfu

  • šŸ‘Œ Ā Drag and place the menu anywhere on screen.
  • šŸ‘“ The smart menu system detects the edges of the screen and flips the menu automatically.
  • šŸ‘ Support for nested menus.
  • āŒØ Keyboard Accessible.
  • šŸŒˆ Support for custom themes.
  • šŸ’Ŗ Built with Typescript.
  • šŸ§° Intuitive API with data driven behavior.
  • šŸŒ  Built with the all new Vue 3.

āš” Installation

yarn install vue-float-menu

šŸš€ Getting Started

vue-float-menu has some great defaults. Please check the props section for all available options.

vue-float-menu finds the optimal menu orientation depending on the position of the menu. for e.g if the menu is placed at the bottom edge and the orientation set to bottom, the component will automatically flip the orientation to top.

Here is a basic example that sets the default position of the menu as top left.

<template>
  <float-menu
    :position="'top left'"
    :dimension="50"
    :menu-data="items"
    :on-selected="handleSelection"
  >
    Drag
  </float-menu>
</template>

<script>
import { FloatMenu } from "vue-float-menu";
import "vue-float-menu/dist/vue-float-menu.css";

export default {
  components: {
    FloatMenu,
  },
  setup() {
    const handleSelection = (selectedItem) => {
      console.log(selectedItem);
    };
    return {
      handleSelection,
    };
  },
  data() {
    return {
      items: [
        { name: "New" },
        {
          name: "Edit",
          subMenu: {
            name: "edit-items",
            items: [{ name: "Copy" }, { name: "Paste" }],
          },
        },
        {
          name: "Open Recent"
        },
        {
          name: "Save",
        }
      ],
    };
  },
};
</script>

Props

PropTypeDescription
dimensionnumberdimension of the Menu Head width x height in pixels.
positionStringinitial position of the Menu Head. can be any one of the values top left, top right, bottom left, bottom right
fixedBooleandisables dragging and the menu will be fixed. use the position prop to fix the menu position
menu-dimensionObjectsets the width and minimum height of the Menu.
menu-dataObjectdata to generate the menu. refer to populating the menu for usage details.
on-selectedFunctionhook that is called on selection.
menu-styleStringcan be slide-out or accordion.slide-out is the default menu style.
flip-on-edgesBooleanflips the menu content on the right edges of the screen.
themeObjectprop to customize the color schemes. refer theme for usage.

Position

The position prop can be used to set the initial position of the Menu Head. The prop can accept any one of the following values.

  • top left (default)
  • top right
  • bottom left
  • bottom right
  <float-menu :dimension=50 position="bottom right">
    <template #icon>
      <BoxIcon />
    </template>
  </float-menu>

Menu head dimension

dimension prop can be used to set the width and height of the menu head. The prop takes a single number value to set the height and width of the Menu Head.

  <float-menu :dimension=50>
    <template #icon>
      <BoxIcon />
    </template>
  </float-menu>

Menu dimension

prop to set the height and width of the menu.

  <float-menu
    :dimension=50
    :menu-dimension="{height: 400, width: 300}"
    position="bottom right"
  >
    <template #icon>
      <BoxIcon />
    </template>
  </float-menu>

Menu Style

The component supports two modes slide-out(default) and accordion. The accordion style is more suitable for mobile devices.

  <float-menu
    position="bottom right"
    flip-on-edges
    menu-style="accordion"
  >
    <template #icon>
      <BoxIcon />
    </template>
  </float-menu>

accordion

Populating the Menu

Use the menu-data prop to create simple or nested menus of your liking. menu-data takes an array of MenuItem type

MenuItem properties

propertydescription
namedisplay name of the menu item.
subMenudata for the sub-menu
disableddisables the menu item
dividermakes the item as a divider

Here we create a simple Menu structure with 3 Menu items with no sub menus.

const menuData = [
  { name: "New" },
  {
    name: "Edit",
    subMenu: {
      name: "edit-items",
      items: [{ name: "Copy" }, { name: "Paste", disabled: true }],
    },
  },
  {divider: true},
  {
    name: "Open Recent",
    subMenu: {
      name: "recent-items",
      items: [{ name: "Document 1" }, {divider: true}, { name: "Document 2" }],
    },
  },
]
  <float-menu
    :dimension=50
    :menu-dimension="{height: 400, width: 300}"
    :menu-data="menuData"
    position="bottom right"
  >
    <BoxIcon />
  </float-menu>

on-select

hook for the menu item selection event.

  <float-menu
    :dimension=50
    position="bottom right"
    :menu-dimension="{height: 400, width: 300}"
    :menu-data="{items: [{name: 'File'}, {name: 'Open'}]}"
    on-select="handleSelection"
  >
    <BoxIcon />
  </float-menu>

Flip on edges

setting this prop flips the menu content on the right edges of the screen.

  <float-menu
    :dimension=50
    position="bottom right"
    flip-on-edges
    on-select="handleSelection"
  >
    <BoxIcon />
  </float-menu>

flip

Fixed Menu

To disable dragging and to fix the position statically, set fixed to true. This prop is disabled by default. Use this prop along with the position prop to set the desired position.

  <float-menu :dimension=50 position="bottom right" fixed>
    <template #icon>
      <BoxIcon />
    </template>
  </float-menu>

šŸŽØ Custom icon

To customize the Menu Icon, simply pass any content in between the float-menu tags. Here we render a custom icon.

  <float-menu
    :dimension=50
    :menu-data="menuData"
  >
    <template #icon>
      <BoxIcon />
    </template>
  </float-menu>

and here we render a text Click inside the Menu handle

  <float-menu
    :dimension=50
    :menu-data="menuData"
  >
    Click
  </float-menu>

example2

šŸŽ­ Icon support

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.

<float-menu
  :menu-data="items"
>
  <template #new>
    <img
      src="../assets/new.svg"
      alt="new"
    >
  </template>
  <template #edit>
    <img
      src="../assets/edit.svg"
      alt="edit"
    >
  </template>
</float-menu>

export default defineComponent({
  name: "MenuExample",
  data()  {
    return {
      items: [
        { name: "New File", iconSlot: "new" },
        { name: "New Window", iconSlot: "edit" },
      ]
    }
  }
})

menu-icon

This works seamlessly even for nested menu structure. Make sure the slot ids match and the component will render the icons appropriately.

<float-menu
  :menu-data="items"
>
  <template #cut>
    <img
      src="../assets/window-maximize.svg"
      alt="cut"
    >
  </template>
</float-menu>

export default defineComponent({
  name: "MenuExample",
  data()  {
    return {
      items: [
        { name: "edit",
        subMenu: [{ name: "cut", iconSlot: "cut" }]},
      ]
    }
  }
});

šŸŒˆ Theme

Customize the color schemes with the theme prop.

  <float-menu
    :dimension=50
    :theme="{
      primary: '#00539C',
      textColor: '#000',
      menuBgColor: '#fff',
      textSelectedColor: '#fff',
    }"
  >
    Click
  </float-menu>

šŸ“¦ Build Setup

# install dependencies
yarn install

# start dev
yarn run dev

# run css linting
yarn run lint:css

# lint everything
yarn run lint:all

# package lib
npm run rollup

šŸ”Ø Contributing

  1. Fork it ( https://github.com/prabhuignoto/vue-float-menu/fork )
  2. Create your feature branch (git checkout -b new-feature)
  3. Commit your changes (git commit -am 'Add feature')
  4. Push to the branch (git push origin new-feature)
  5. Create a new Pull Request

šŸ§± Built with

Notes

  • The project uses vite instead of @vue/cli. I choose vite for speed and i also believe vite will be the future.

Meta

Prabhu Murthy ā€“ @prabhumurthy2 ā€“ prabhu.m.murthy@gmail.com

https://www.prabhumurthy.com

Distributed under the MIT license. See LICENSE for more information.

https://github.com/prabhuingoto/

1.9.1

3 years ago

1.9.0

3 years ago

1.8.2

3 years ago

1.8.1

3 years ago

1.8.0

3 years ago

1.7.6

3 years ago

1.7.5

3 years ago

1.7.4

3 years ago

1.7.3

3 years ago

1.7.2

3 years ago

1.7.1

3 years ago

1.7.0

3 years ago

1.6.1

4 years ago

1.6.0

4 years ago

1.4.3

4 years ago

1.5.0

4 years ago

1.4.2

4 years ago

1.4.1

4 years ago

1.4.0

4 years ago

1.3.0

4 years ago

1.2.0

4 years ago

1.1.11

4 years ago

1.1.10

4 years ago

1.1.9

4 years ago

1.1.8

4 years ago

1.1.7

4 years ago

1.1.6

4 years ago

1.1.5

4 years ago

1.1.4

4 years ago

1.1.3

4 years ago

1.1.2

4 years ago

1.1.1

4 years ago

1.1.0

4 years ago

1.0.29

4 years ago

1.0.30

4 years ago

1.0.28

4 years ago

1.0.27

4 years ago

1.0.26

4 years ago

1.0.25

4 years ago

1.0.24

4 years ago

1.0.23

4 years ago

1.0.22

4 years ago

1.0.21

4 years ago

1.0.20

4 years ago

1.0.19

4 years ago

1.0.18

4 years ago

1.0.17

4 years ago

1.0.16

4 years ago

1.0.15

4 years ago

1.0.14

4 years ago

1.0.13

4 years ago

1.0.12

4 years ago

1.0.11

4 years ago

1.0.10

4 years ago

1.0.8

4 years ago

1.0.7

4 years ago

1.0.6

4 years ago

1.0.5

4 years ago

1.0.4

4 years ago

1.0.3

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago