elements
Accordion
Display togglable accordion panels.
Usage
Pass an array to the items
prop of the Accordion component. Each item can have any property from the Button component such as label
, icon
, color
, variant
, size
, etc. but also:
slot
- A key to customize the item with a slot.content
- The content to display in the panel by default.disabled
- Determines whether the item is disabled or not.defaultOpen
- Determines whether the item is initially open or closed.closeOthers
- Determines whether the item click close others or not. It only works with multiple mode.
<script setup>
const items = [{
label: 'Getting Started',
icon: 'i-heroicons-information-circle',
defaultOpen: true,
content: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed neque elit, tristique placerat feugiat ac, facilisis vitae arcu. Proin eget egestas augue. Praesent ut sem nec arcu pellentesque aliquet. Duis dapibus diam vel metus tempus vulputate.'
}, {
label: 'Installation',
icon: 'i-heroicons-arrow-down-tray',
disabled: true,
content: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed neque elit, tristique placerat feugiat ac, facilisis vitae arcu. Proin eget egestas augue. Praesent ut sem nec arcu pellentesque aliquet. Duis dapibus diam vel metus tempus vulputate.'
}, ...]
</script>
<template>
<UAccordion :items="items" />
</template>
Style
You can also pass any prop from the Button component directly to the Accordion component to style the buttons.
<UAccordion color="primary" variant="soft" size="sm" />
Icon
Use any icon from Iconify by setting the open-icon
and close-icon
props by using this pattern: i-{collection_name}-{icon_name}
or change it globally in ui.accordion.default.openIcon
and ui.accordion.default.closeIcon
.
You can also set them to null
to hide the icons.
<UAccordion open-icon="i-heroicons-plus" close-icon="i-heroicons-minus" />
Multiple
Use the multiple
prop to to allow multiple elements to be opened at the same time.
<UAccordion multiple />
Open
Use the default-open
prop to open all items by default. Works better when the multiple
prop is set to true
.
<UAccordion default-open multiple />
Slots
You can use slots to customize the buttons and items content of the Accordion.
default
Use the #default
slot to customize the trigger buttons. You will have access to the item
, index
, open
properties and close
method in the slot scope.
<script setup>
const items = [...]
</script>
<template>
<UAccordion :items="items" :ui="{ wrapper: 'flex flex-col w-full' }">
<template #default="{ item, index, open }">
<UButton color="gray" variant="ghost" class="border-b border-gray-200 dark:border-gray-700" :ui="{ rounded :'rounded-none', padding: { sm:'p-3' } }">
<template #leading>
<div class="w-6 h-6 rounded-full bg-primary-500 dark:bg-primary-400 flex items-center justify-center -my-1">
<UIcon :name="item.icon" class="w-4 h-4 text-white dark:text-gray-900" />
</div>
</template>
<span class="truncate">{{ index + 1 }}. {{ item.label }}</span>
<template #trailing>
<UIcon
name="i-heroicons-chevron-right-20-solid"
class="w-5 h-5 ms-auto transform transition-transform duration-200"
:class="[open && 'rotate-90']"
/>
</template>
</UButton>
</template>
</UAccordion>
</template>
item
Use the #item
slot to customize the items content or pass a slot
property to customize a specific item. You will have access to the item
, index
, open
properties and close
method in the slot scope.
Fully styled and customizable components for Nuxt.
Installation
Install @nuxt/ui
dependency to your project:
$ npm i @nuxt/ui
$ yarn add @nuxt/ui
$ pnpm add @nuxt/ui
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed neque elit, tristique placerat feugiat ac, facilisis vitae arcu. Proin eget egestas augue. Praesent ut sem nec arcu pellentesque aliquet. Duis dapibus diam vel metus tempus vulputate.
<script setup>
const items = [{
label: 'Getting Started',
icon: 'i-heroicons-information-circle',
defaultOpen: true,
slot: 'getting-started'
}, {
label: 'Installation',
icon: 'i-heroicons-arrow-down-tray',
defaultOpen: true,
slot: 'installation'
}, {
label: 'Theming',
icon: 'i-heroicons-eye-dropper',
defaultOpen: true,
description: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed neque elit, tristique placerat feugiat ac, facilisis vitae arcu. Proin eget egestas augue. Praesent ut sem nec arcu pellentesque aliquet. Duis dapibus diam vel metus tempus vulputate.'
}, ...]
</script>
<template>
<UAccordion :items="items">
<template #item="{ item }">
<p class="italic text-gray-900 dark:text-white text-center">
{{ item.description }}
</p>
</template>
<template #getting-started>
<div class="text-gray-900 dark:text-white text-center">
<Logo class="w-auto h-8 mx-auto" />
<p class="text-sm text-gray-500 dark:text-gray-400 mt-2">
Fully styled and customizable components for Nuxt.
</p>
</div>
</template>
<template #installation="{ description }">
<div class="flex flex-col justify-center items-center gap-1 mb-4">
<h3 class="text-xl font-bold text-gray-900 dark:text-white">
Installation
</h3>
<p class="text-sm text-gray-500 dark:text-gray-400">
Install <code>@nuxt/ui</code> dependency to your project:
</p>
<p>
{{ description }}
</p>
</div>
<div class="flex flex-col items-center">
<code>$ npm install @nuxt/ui</code>
<code>$ nnpm install -D @nuxt/ui</code>
<code>$ pnpm i -D @nuxt/ui</code>
</div>
</template>
</UAccordion>
</template>
Props
{}
[]
appConfig.ui.accordion.default.openIcon
appConfig.ui.accordion.default.closeIcon
false
false
Preset
{
"wrapper": "w-full flex flex-col",
"item": {
"base": "",
"size": "text-sm",
"color": "text-gray-500 dark:text-gray-400",
"padding": "pt-1.5 pb-3",
"icon": "ms-auto transform transition-transform duration-200"
},
"transition": {
"enterActiveClass": "overflow-hidden transition-[height] duration-200 ease-out",
"leaveActiveClass": "overflow-hidden transition-[height] duration-200 ease-out"
},
"default": {
"openIcon": "i-heroicons-chevron-down-20-solid",
"closeIcon": "",
"class": "mb-1.5 w-full",
"variant": "soft"
}
}