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

@profesia/vue-accordion-component

v2.0.4

Published

Vue Component for accordion

Downloads

84

Readme

vue-accordion-component

npm npm total vue2

Install

NPM

Install the package:

npm install @profesia/vue-accordion-component --save-dev

Then import it in your project

import Vue from 'vue'
import {accordion} from '@profesia/vue-accordion-component'

Vue.component('accordion', accordion)

Browser global

Just include vue & accordion

<script src="path/to/vue.js"></script>
<script src="path/to/dist/js/accordion.min.js"></script>

Usage

Simply use it like so:

<accordion :items="items" :selectors="{ id: 'id', title: 'myTitle', content: 'post' }" :active="activeItemsOnStart" :collapseAll="false" ref="accordion"></accordion>

Options

items

Mandatory. An array of objects to create the panels inside the accordion. Default structure:

[
    {
      title: 'Title',
      content: 'text',
    },
    {
      title: 'Title 2',
      content: 'text 2',
    }
]
selectors

Optional. An object, which contains names of your selectors in items object list. Default selectors are:

id: 'id',
title: 'title',
content: 'content'
active

Optional. A string, a number or an array of ids, or index positions (starts from 0) of items, which should be opened at page start. Defaults to null.

collapseAll

Optional. Boolean parameter, which cause each accordion will collapse on another accordion click or not. Defaults to true.

ref

Optional. A string, which you can use for controlling accordions from another places via collapseAccordion method. Example: you have method setAccordion, which should open some accordion after click on element

setAccordion(id) {
    this.$refs.accordion.collapseAccordion(id, true)
}

Named Slots

You can set up items with title and content, or you can use your own templates (slots with names title and content), for example

<template slot="title" slot-scope="{ item }">
    Custom title: {{ item.title }}
</template>
<template slot="content" slot-scope="{ item }">
    Custom content<br>
    {{ item.content }}
</template>

Methods

collapseAccordion

Params id - mandatory - id or index (starts from 0) of item, which should be collapsed leaveOpen - optional - if true, after calling this method the item will stay opened. Defaults to false.

Structure

Once the accordion has been rendered, it'll create the following structure:

<div class="vue-accordion-component">
    <!-- First accordion item-->
    <div class="vue-accordion-item">
        <div class="vue-accordion-header">
            <div class="vue-accordion-title">
                Title
                <svg viewBox="0 0 32 32" class="vue-accordion-icon"><g><rect x="11.31" y="13.5" transform="matrix(0.7071 -0.7071 0.7071 0.7071 -5.0721 19.7549)" width="20" height="5"></rect> <rect x="0.69" y="13.5" transform="matrix(-0.7071 -0.7071 0.7071 -0.7071 6.9348 34.8725)" width="20" height="5"></rect></g></svg>
            </div>
        </div>
        <div class="vue-accordion-content">
            obsah testu 1
        </div>
    </div>
    
    <!-- Second accordion item-->
    <div class="vue-accordion-item">
        ...
    </div>
</div>

All CSS is based upon this structure.

.vue-accordion-component {
  ...
}

.vue-accordion-item {
  ...
}

.vue-accordion-header {
  ...
}

.vue-accordion-title {
  ...
}

.vue-accordion-content {
  ...
}

If you want to modify the styling, take a look at the class props.

FAQ

  • Where can I see, how it works? - Go to DEMO and enjoy ;)
  • How can I provide feedback? - Send an email to [email protected]; any feedback is appreciated.

Release History

  • 2.0.4 - Change babel preset to env
  • 2.0.3 - Add class with item ID when ID is filled
  • 2.0.2 - Small bug fix
  • 2.0.1 - Small bug fix
  • 2.0.0 - MINOR CHANGE, complete new version of accordion component
  • 1.0.1 - 1.0.7 Fix README
  • 1.0.0 Official release with docs
  • 0.0.1 Initial release