npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

vuejs-sidebar-menu

v1.0.0

Published

A simple Vue 3 plugin to create a sidebar menu

Downloads

16

Readme

vuejs-sidebar-menu

Software License Vue 3.x

A simple Vue 3 plugin to create a sidebar menu.

Demo

View a demo | Sandbox

Dependencies

The plugin was created with Vue 3 and is designed to work with vue-router.

| Name | Version | | ----------------- |---------- | | core-js | 3.8.3 | | vue | 3.2.13 | | vue-router | 4.0.13 |

Project setup

npm install --save vuejs-sidebar-menu

Global registration

main.js:

import { createApp } from 'vue'
import App from './App.vue'

import SidebarMenu from 'vuejs-sidebar-menu'
import 'vuejs-sidebar-menu/dist/vuejs-sidebar-menu.css'

createApp(App).use(SidebarMenu).mount('#app')

Local registration

App.vue:

<script>
import { SidebarMenu } from 'vuejs-sidebar-menu'
import 'vuejs-sidebar-menu/dist/vuejs-sidebar-menu.css'

export default {
    components: {
        SidebarMenu
    }
}
</script>

Basic usage

App.vue:

<template>
    <sidebar-menu :items="items" />

    <div class="container">
        <router-view/>  
    </div>
</template>

<script>
import { SidebarMenu } from 'vuejs-sidebar-menu'
import 'vuejs-sidebar-menu/dist/vuejs-sidebar-menu.css'

export default {
    components: {
        SidebarMenu
    },
    data() {
        return {
            items: [
                { name:"My space", tooltip:"Mon tooltip Spécifique", icon:"bx-user", href:"/" },
                { name:"My Favorites", icon:"bxs-star", href:"/favorites" },
                { name:"Players", icon:"bxs-user-detail", href:"/players" },
                { name:"Clubs", icon:"bxs-school", href:"/clubs" },
                { name:"Competitions", icon:"bxs-trophy", href:"/competitions" },
                { isFooter:true, tooltip:"Vue.js Facebook page", icon:"bxl-facebook", href:"https://fr-fr.facebook.com/vuejsdevelopers" },
                { isFooter:true, tooltip:"Vue.js Twitter page", icon:"bxl-twitter", href:"https://twitter.com/vuejs" },
                { isFooter:true, tooltip:"Vue.js LinkedIn page", icon:"bxl-linkedin", href:"https://www.linkedin.com/company/vuejsdevelopers" }
            ]
        }
    }
}
</script>

<style>
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;

    /* Remove cursor "|" in html balise */
    -moz-user-select: none;
    -webkit-user-select: none;
    user-select: none;
}

#app {
  display: flex;
  font-family: Avenir, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-align: center;
  color: #2c3e50;
}

.container {
  flex-basis: 100%;
  background-color: white;
  height: 100vh;
  overflow-y: auto;
}
</style>

Component properties

| Name | Type | Default | Example | | ----------------- |:--------- | -------- | -------- | | items | String[] :{name: String,tooltip: String,icon: String,href: String,isFooter: Boolean} | [] | {name:"My Favorites",tooltip:"Mon tooltip Spécifique",icon:"bxs-star",href:"/favorites",isFooter:false}| | isOpened | Boolean | true | | | width | Number | 250 | | | logo | String | logo.png (image in src/assets) | | | textColor | String | white | | | bgColorPrimary | String | rgb(41, 40, 40) | | | bgColorSecondary| String | #080a0c | | | bgColorHover | String | #41b883 | |

Explanations of the properties of items:
If the tooltip property is not set, the name property is used by default.

By default, the icons in the sidebar use the boxicons' library
The value of the icon property takes a class name defined in this library.
It is possible to use another icon library such as Font Awesome but you will need to import the necessary files for this library.

The href property can contain a relative link or a http link.
In the case of the relative link, the vue-router plugin is used.
In the case of the http link, it will be opened in a new tab.

If the isFooter property is not set, the element will be placed in the sidebar content

Example with custom parameters:

<template>
    <sidebar-menu 
      :items="items" 
      :isOpened="true"
      :width="300"
      logo="logo.png"  
      textColor="#41b883"
      bgColorPrimary="rgb(41, 40, 40)"
      bgColorSecondary="#080a0c"
      bgColorHover="white"
      />
</template>

Slots

Override sidebar header

By default, the sidebar header contains the logo "logo.png" present in the assets and an icon allowing to reduce/enlarge the panel.

SidebarMenu.vue:

<template>
    ...
    <div class="sidebar-header">
        <slot name="header">
            <img id="sidebar-logo" alt="Vue logo" :src="require(`@/assets/${logo}`)">
            <i class="bx" :class="isOpened ? 'bx-menu-alt-right' : 'bx-menu'" @click="isOpened = !isOpened" />
        </slot>
    </div>
</template>

You can totally change this behaviour:

App.vue:

<template>
    <sidebar-menu :items="items">
        <!-- Add custom header -->
        <template #header>
            <img id="sidebar-logo" alt="Vue logo" style="height:60px" :src="require(`@/assets/logo.png`)">
            <div>
                <p>My scrollbar title</p>
            </div>
      </template>
    </sidebar-menu>
</template>

Override sidebar content

By default, the sidebar content is filled with items whose isFooter property is unspecified or set to false.

SidebarMenu.vue:

<template>
    ...
    <div class="sidebar-content" :class="hasScroll ? 'scroll': ''">
        <ul>
            <slot>
                <sidebar-item v-for="item in contentItems" :key="item" 
                    :name="item.name" 
                    :tooltip="item.tooltip" 
                    :icon="item.icon" 
                    :href="item.href" />
            </slot>
        </ul>
    </div>
    ...
</template>

You can totally change this behaviour:

App.vue:

<template>
    <sidebar-menu :items="items">
        <!-- Add custom content -->
        <li class="sidebar-item"><a>My link 1</a></li>
        <li class="sidebar-item"><a>My link 2</a></li>
        <li class="sidebar-item"><a>My link 3</a></li>
        <li class="sidebar-item"><a>My link 4</a></li>
    </sidebar-menu>
</template>

Override sidebar footer

By default, the sidebar footer is filled with items whose isFooter property is set to true.

SidebarMenu.vue:

<template>
    ...
    <div class="sidebar-footer" v-if="hasFooter">
        <ul>
            <slot name="footer">
                <sidebar-item v-for="item in footerItems" :key="item" 
                    :name="item.name" 
                    :tooltip="item.tooltip" 
                    :icon="item.icon" 
                    :href="item.href" />
            </slot>
        </ul>
    </div>
</template>

You can totally change this behaviour:

App.vue:

<template>
    <sidebar-menu :items="items">
        <!-- Add custom footer -->
        <template #footer>
            <p class="sidebar-footer-content">(c) My company 2022</p>
        </template>
    </sidebar-menu>
</template>