2.1.1 • Published 1 year ago

vue-stripe-menu v2.1.1

Weekly downloads
361
License
MIT
Repository
github
Last release
1 year ago

Vue Stripe Menu

Creating a navigation menu with animations like on Stripe

Demo Website

Vue 2 - branch

How to install

Install the library in your project:

$ npm i vue-stripe-menu
// or
$ yarn add vue-stripe-menu

Import components and styles:

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

import { createApp } from 'vue'
import VueStripeMenu from 'vue-stripe-menu'
import 'vue-stripe-menu/dist/vue-stripe-menu.css'

createApp({}).use(VueStripeMenu)

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

import { VsmMenu, VsmMob } from 'vue-stripe-menu'
import 'vue-stripe-menu/dist/vue-stripe-menu.css'

export default {
  components: {
    VsmMenu, VsmMob
  }
}

Add 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-section vsm-mob-full">
        Left side
      </li>
    </template>
    <template #after-nav>
      <li class="vsm-section 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 styles:

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

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

.vsm-root {
  display: flex;
  align-items: center;
  justify-content: center;
}

.vsm-section_menu {
  flex: 1 1 auto;
  justify-content: center;
}

.vsm-link {
  padding: 0 25px;
}

@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"
    :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
        class="vsm-section logo-section"
        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-->
      <!--For the same styles - add the vsm-section-->
      <li class="vsm-section vsm-mob-hide">
        <button>My Button</button>
      </li>
      <!--Display when user media screen below from $vsm-media (scss)-->
      <vsm-mob>Mobile Content</vsm-mob>
    </template>
  </vsm-menu>
</template>

<script>
/* eslint-disable */
/*
 * This is an example of possible settings, you can also control
 * scss variables, and also you need to add a little style.
 * So copy and delete what you don’t need.
 *
 * After #after-nav and #before-nav it is recommended to use
 * to maintain the correct HTML structure:
 *   <li class="vsm-section">
 */

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?
          element: 'span', // router-link
          // 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
          new_section: false,
        },
        {
          title: 'External Link',
          attributes: {
            href: 'https://github.com/Alexeykhr/vue-stripe-menu',
            target: '_blank'
          }
        }
        // ...
      ]
    }
  },
  methods: {
    onOpenDropdown() {
      console.log('onOpenDropdown')
    },
    onCloseDropdown() {
      console.log('onCloseDropdown')
    }
  }
}
</script>

Codepen Demo

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
handlerhover, clickWhat event should you open dropdown forStringhoverfalse

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

const elements = this.$refs[myVsmRef].hasDropdownEls

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
elementStringHTML element 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 button to open dropdown

[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

Install dependencies

$ yarn

Launch of a demo project (development of lib)

$ yarn dev

Build a demo project

$ yarn build

Build library

$ yarn build:lib

Run tests

$ yarn test

Check code on Eslint

$ yarn lint

Changelog

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

License

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

1.5.0-backport

1 year ago

1.5.1-backport

1 year ago

3.0.0-beta.1

2 years ago

3.0.0-beta.2

2 years ago

2.1.1

3 years ago

2.1.0

3 years ago

2.0.0

3 years ago

2.0.0-beta.7

3 years ago

2.0.0-beta.6

3 years ago

2.0.0-beta.2

3 years ago

2.0.0-beta.1

3 years ago

2.0.0-beta.5

3 years ago

2.0.0-beta.4

3 years ago

2.0.0-beta.3

3 years ago

1.5.0

3 years ago

1.4.0

4 years ago

1.3.1

4 years ago

1.3.0

4 years ago

1.2.12

4 years ago

1.2.11

4 years ago

1.2.10

4 years ago

1.2.9

4 years ago

1.2.8

4 years ago

1.2.7

4 years ago

1.2.6

4 years ago

1.2.5

4 years ago

1.2.4

4 years ago

1.2.3

4 years ago

1.2.2

4 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