1.5.0-backport • Published 2 years ago

vue-stripe-menu v1.5.0-backport

Weekly downloads
361
License
MIT
Repository
github
Last release
2 years ago

Vue Stripe Menu

Creating a navigation menu with animations like on Stripe

Only for Vue 3 (changelog)

Documentation

Vue 2 - Branch

How to install

Install the library in your project:

$ npm i -D vue-stripe-menu

// $ yarn add -D vue-stripe-menu
// $ pnpm add -D vue-stripe-menu

Import components:

// >>> Install globally - .js file <<<

import { createApp } from 'vue'
import VueStripeMenu from 'vue-stripe-menu'

createApp({}).use(VueStripeMenu)

// >>> Install locally - .vue file <<<

import { VsmMenu, VsmMob } from 'vue-stripe-menu'

export default {
  components: {
    VsmMenu, VsmMob
  }
}

// Optionally if you don't want to use @import in your
// <style> section (because its scoped for example):
// import 'vue-stripe-menu/css'

Add the component:

<template>
  <vsm-menu :menu="menu">
    <template #default="{ item }">
      <div style="width: 300px; padding: 30px">
        Dropdown content - {{ item.title }}
      </div>
    </template>
    <template #before-nav>
      <li class="vsm-mob-full">
        Left side
      </li>
    </template>
    <template #after-nav>
      <li class="vsm-mob-hide">
        Right side
      </li>
      <vsm-mob>
        <div style="min-height: 200px; padding: 30px">
          Mobile Content
        </div>
      </vsm-mob>
    </template>
  </vsm-menu>
</template>

<script>
export default {
  data() {
    return {
      menu: [
        { title: 'Item1', dropdown: 'dropdown-1' },
        { title: 'Item2', dropdown: 'dropdown-2' },
        { title: 'Just link', attributes: { href: '#clicked' } },
      ]
    }
  }
}
</script>

Add css/scss styles:

// >>> SCSS style (required sass-loader, node-sass) <<<
// https://github.com/oleksiikhr/vue-stripe-menu/blob/main/src/scss/_variables.scss
// $vsm-transition: .5s;

@import "~vue-stripe-menu/scss";

// >>> CSS style <<<
// @import 'vue-stripe-menu/css';

.vsm-menu {
  max-width: 1024px;
  width: 100%;
  margin: 0 auto;
}

.vsm-nav {
  margin: 0 10px;
}

.vsm-link-container {
  display: flex;
  flex: 1 1 auto;
  justify-content: center;
}

@media screen and (max-width: 768px) {
  .vsm-mob-show {
    display: block;
  }
  .vsm-mob-hide {
    display: none;
  }
  .vsm-mob-full {
    flex-grow: 1;
  }
}

Full Example

<template>
  <vsm-menu
    :menu="menu"
    element="header"
    handler="hover"
    align="center"
    :screen-offset="10"
    :dropdown-offset="0"
    @open-dropdown="onOpenDropdown"
    @close-dropdown="onCloseDropdown"
  >
    <template #default="{ item }">
      <!--Dropdown content of each menu item with a "dropdown" property-->
      <!--You can replace it with a separate component if each menu item has its own style-->
      <!--Necessarily need to have at least one element within the slot-->
      <!--An alternate background will be applied from the 2nd element-->
      <div style="width: 300px; padding: 30px">
        Header: {{ item }}
      </div>
      <div style="padding: 30px">
        Second element
      </div>
    </template>
    <template #before-nav>
      <!--Image or svg of website logo-->
      <li style="width: 50px; height: 50px">
        <img
          src="https://vuejs.org/images/logo.png"
          alt="My Logo"
        >
      </li>
    </template>
    <template #title="data">
      <!--Display menu items through slots-->
      {{ data.item.title }}
    </template>
    <template #after-nav>
      <!--Mobile Burger, buttons, etc-->
      <li class="vsm-mob-hide">
        <button>My Button</button>
      </li>
      <!--Set "display: block" for the .vsm-mob-show class to display content-->
      <vsm-mob>Mobile Content</vsm-mob>
    </template>
  </vsm-menu>
</template>

<script>
/*
 * Inside #after-nav and #before-nav it is recommended to use
 * to maintain the correct HTML structure:
 *   <li><!--Content--></li>
 */

export default {
  data() {
    return {
      menu: [
        {
          // display menu item (can be overridden with title slot)
          title: 'News',
          // this element now has dropdown content
          dropdown: 'news',
          // don't want a button element? Pass HTMLElement or global component
          // (pass only as a string, component must be globally accessible)
          element: 'span', // div, router-link, nuxt-link, custom-component
          // offset the position of the dropdown menu
          align: 'center',
          // menu item can accept all attributes
          attributes: {
            // I want more classes! No problem
            // string, array, object, not matter
            class: ['my-class1', { 'my-class2': true }],
            // Custom attributes
            'data-big': 'yes'
          },
          // add some events?
          listeners: {
            // all possible native events
            mouseover: (evt) => {
              console.log('news hover', evt)
            }
          },
          // just extra properties in the object
          customAttribute: true,
        },
        {
          title: 'External Link',
          attributes: {
            href: 'https://github.com/oleksiikhr/vue-stripe-menu',
            target: '_blank'
          }
        }
        // ...
      ]
    }
  },
  methods: {
    onOpenDropdown() {
      console.log('onOpenDropdown')
    },
    onCloseDropdown() {
      console.log('onCloseDropdown')
    }
  }
}
</script>

API

Menu Props

PropertyParametersDescriptionTypeDefaultRequired
menuMenuObjectDescription of the menu itemsarraytrue
elementHTMLElement for the root elementstringheaderfalse
screen-offsetOffset from the window screenstring, numberheaderfalse
dropdown-offsetOffset from the dropdown menustring, numberheaderfalse
transition-timeoutAnimation speed in ms (equals $vsm-transition scss)string, number250false
handlerhover, clickOn what event to open dropdown menustringhoverfalse
aligncenter, left, rightOffset the position of the dropdown menustringcenterfalse

Menu Events

NameDescriptionReturn
open-dropdownOpen the dropdown menu, return the active HTMLElementHTMLElement
close-dropdownClose the dropdown menu, return the closed HTMLElementHTMLElement

Menu Slots

NameParametersDescription
defaultMenuItem, indexThe main content for the dropdown list
before-navbefore-navContent to the left of the list
after-navafter-navContent to the right of the list
titleMenuItem, indexReplace the output of menu[i].title with your own

Menu Methods

this.$refs[myVsmRef].closeDropdown()

NameParametersDescriptionReturn
toggleDropdownHTMLElementOpen dropdown menu, if it is an active HTMLElement - close
openDropdownHTMLElementOpen dropdown menu for selected HTMLElement
closeDropdownClose active dropdown menu
resizeDropdownRecalculate size and location of dropdown menu

Menu Properties

this.$refs[myVsmRef].itemsWithDropdown

NameDescriptionReturn
itemsWithDropdownFiltered menu items with "dropdown" propertyArray\
elementsWithDropdownList of HTMLElements that have dropdown contentArray\
dropdownContainerItemsList of dropdown HTMLElementsArray<{el: HTMLElement, name: string, content: HTMLElement}>

Menu MenuObject (menu props)

PropertyTypeDescription
titlestringMenu item name. Can also be redefined through the slot
dropdownstringUnique value indicates that this item has a dropdown menu
alignstringOffset the position of the dropdown menu (center/left/right)
elementstringHTMLElement or global component in the header element, if not specified, it will be or
attributesobjectAll attributes to be assigned in the header element (v-bind)
listenersobjectAll events to be assigned in the header element (v-on)

[Mob] Props

PropertyParametersDescriptionTypeDefaultRequired
v-modelThe state of the open/close the menubooleanfalsefalse

[Mob] Slots

NameParametersDescription
defaultMain content
hamburgerReplace hamburger button
closeReplace close button

[Mob] Methods

this.$refs[myVsmMobRef].closeDropdown()

NameParametersDescriptionReturn
closeDropdownClose dropdown menu

Classes

NameDescription
vsm-mob-showShow HTMLElements in mobile design
vsm-mob-hideHide HTMLElements in mobile design

Contributing

Please make sure to read the [Contributing Guide](https://github.com/oleksiikhr/vue-stripe-menu/blob/main/.github/CONTRIBUTING.md) before making a pull request.

Changelog

Detailed changes for each release are documented in the [CHANGELOG.md](https://github.com/oleksiikhr/vue-stripe-menu/blob/main/CHANGELOG.md).

License

[MIT](https://opensource.org/licenses/MIT)

1.5.0-backport

2 years ago

1.5.1-backport

2 years ago

3.0.0-beta.1

3 years ago

3.0.0-beta.2

3 years ago

2.1.1

4 years ago

2.1.0

4 years ago

2.0.0

4 years ago

2.0.0-beta.7

4 years ago

2.0.0-beta.6

4 years ago

2.0.0-beta.2

4 years ago

2.0.0-beta.1

4 years ago

2.0.0-beta.5

4 years ago

2.0.0-beta.4

4 years ago

2.0.0-beta.3

4 years ago

1.5.0

4 years ago

1.4.0

5 years ago

1.3.1

5 years ago

1.3.0

5 years ago

1.2.12

5 years ago

1.2.11

5 years ago

1.2.10

5 years ago

1.2.9

5 years ago

1.2.8

5 years ago

1.2.7

5 years ago

1.2.6

5 years ago

1.2.5

5 years ago

1.2.4

5 years ago

1.2.3

5 years ago

1.2.2

5 years ago

1.2.1

5 years ago

1.2.0

5 years ago

1.1.0

5 years ago

1.0.0

5 years ago

0.3.0

5 years ago

0.2.0

5 years ago

0.1.2

5 years ago

0.1.1

5 years ago

0.1.0

5 years ago