@vuesimple/vs-accordion
v3.0.7
Published
A simple vue accordion.
Downloads
151
Maintainers
Readme
Vue Simple Tag
🗃 A simple vue accordion. Perfect for all your accordion, faq's scenarios.
A light weight vue plugin built groundup.
📺 Live Demo
Code Sandbox: Link
🛠 Install
npm i @vuesimple/vs-accordion
🚀 Usage
<template>
<vs-accordion :is-box="true" is-compact>
<vs-accordion-item v-for="(n, index) in [1, 2, 3]" :key="index">
<!-- This slot will handle the title of the accordion and is the part you click on -->
<template slot="accordion-trigger">
<h4>Item {{ n }}</h4>
</template>
<!-- Default content -->
<div>
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore
magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
consequat.
</div>
</vs-accordion-item>
</vs-accordion>
</template>
<script>
import { VsAccordion, VsAccordionItem } from '@vuesimple/vs-accordion';
export default {
components: {
VsAccordion,
VsAccordionItem,
},
};
</script>
🌎 CDN
<script src="https://unpkg.com/@vuesimple/vs-accordion@<version>/dist/vs-accordion.min.js"></script>
// Main/Entry file
app.use(VsAccordion.plugin);
<template>
<vs-accordion :is-box="true" is-compact>
<vs-accordion-item v-for="(n, index) in [1, 2, 3]" :key="index">
<!-- This slot will handle the title of the accordion and is the part you click on -->
<template slot="accordion-trigger">
<h4>Item {{ n }}</h4>
</template>
<!-- Default content -->
<div>
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore
magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
consequat.
</div>
</vs-accordion-item>
</vs-accordion>
</template>
Nuxt Code Snippet
After installation,
Create a file
/plugins/vs-accordion.js
import Vue from 'vue'; import { VsAccordion, VsAccordionItem } from '@vuesimple/vs-accordion'; Vue.component('vs-accordion', VsTag);
Update
nuxt.config.js
module.exports = { ... plugins: [ { src: '~plugins/vs-accordion', mode: 'client' } ... ] }
In the page/ component
<template> <vs-accordion :is-box="true" is-compact> <vs-accordion-item v-for="(n, index) in [1, 2, 3]" :key="index"> <!-- This slot will handle the title of the accordion and is the part you click on --> <template slot="accordion-trigger"> <h4>Item {{ n }}</h4> </template> <!-- Default content --> <div> Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. </div> </vs-accordion-item> </vs-accordion> </template>
Note
- For older Nuxt versions, use
<no-ssr>...</no-ssr>
tag. - You can also do
import { VsAccordion, VsAccordionItem } from '@vuesimple/vs-accordion'
& add incomponent:{ VsAccordion, VsAccordionItem }
and use it within component, without globally installing in plugin folder.
⚙ Props
VsAccordion
| Name | Type | Default | Description |
| --------------- | ------- | ------- | ------------------------------------------------------------------ |
| active | Number | - | Index of the accordion to be made active/visible. Starts from 0
. |
| is-box | String | - | Box syle applied. |
| is-expandable | Boolean | - | Enables simultaneous expansion of accordion sections. |
| level | Boolean | - | Sets aria-level heading rank in the document structure. |
| is-compact | Boolean | - | Applies compact styling. |
| disable-animate | Boolean | - | Disable toggle animation. |
🔥 Events
VsAccordionItem
| Name | Description |
| ------ | ----------------------------------------------------------------------------------- |
| change | Triggered accordion open/close click { index: 0, visible: true }
|
| open | Emitted when the accordion starts to open. Listen for it using @open
. |
| hide | Emitted when the accordion close transition completes. Listen for it using @hide
. |
📎 Slots
VsAccordion
You can define own item markup via slots:
| Name | Description | | ----------------------- | ----------------------------------------- | | (default) | Default wrapper content for vs-accordion. | | accordion-non-clickable | Non-Clickable content inside header |
VsAccordionItem
You can define own item markup via slots:
| Name | Description | | ----------------- | -------------------------------------------------------- | | accordion-trigger | Heading content. | | accordion-icon | Icon content. If not present, default icon will be shown | | (default) | Default accordion content section for vs-accordion-item. |