Skip to content

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.
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.
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.
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.
vue
<script setup>
const items = [{
  label: 'Getting Started',
  icon: 'icon-[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: 'icon-[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.'
},
  {
  label: 'Theming',
  icon: 'icon-[heroicons--eye-dropper]',
  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>
  <s-accordion :items="items" />
</template>

Style

You can also pass any prop from the Button component directly to the Accordion component to style the buttons.

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.
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.
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.
vue
<script setup>
const items = [{
  label: '1. Getting Started',
  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: '2. Components',
  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: '3. Theming',
  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>
  <s-accordion :items="items" color="primary" variant="outline" size="sm" />
</template>

Icon

Use any icon from Iconify by setting the open-icon and close-icon props by using this pattern: icon-[{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.

Lorem ipsum dolor sit amet, consectetur adipiscing elit
Lorem ipsum dolor sit amet, consectetur adipiscing elit
Lorem ipsum dolor sit amet, consectetur adipiscing elit
Lorem ipsum dolor sit amet, consectetur adipiscing elit
vue
<template>
  <s-accordion
      open-icon="icon-[heroicons--plus-20-solid]"
      close-icon="icon-[heroicons--minus-20-solid]"
      :items="[{ label: '1. What is Stellar UI?', content: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit' }, { label: '2. Getting Started', content: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit' }, { label: '3. Theming', content: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit' }, { label: '4. Components', content: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit' }]"
  />
</template>

Multiple

Use the multiple prop to to allow multiple elements to be opened at the same time.

Lorem ipsum dolor sit amet, consectetur adipiscing elit
Lorem ipsum dolor sit amet, consectetur adipiscing elit
Lorem ipsum dolor sit amet, consectetur adipiscing elit
Lorem ipsum dolor sit amet, consectetur adipiscing elit
vue
<template>
  <s-accordion
      multiple
      :items="[{ label: 'What is Stellar UI?', content: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit' }, { label: 'Getting Started', content: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit' }, { label: 'Theming', content: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit' }, { label: 'Components', content: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit' }]"
  />
</template>

Open

Use the default-open prop to open all items by default. Works better when the multiple prop is set to true.

Lorem ipsum dolor sit amet, consectetur adipiscing elit
Lorem ipsum dolor sit amet, consectetur adipiscing elit
Lorem ipsum dolor sit amet, consectetur adipiscing elit
Lorem ipsum dolor sit amet, consectetur adipiscing elit
vue
<template>
  <s-accordion
      default-open
      multiple
      :items="[{ label: 'What is Stellar UI?', content: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit' }, { label: 'Getting Started', content: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit' }, { label: 'Theming', content: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit' }, { label: 'Components', content: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit' }]"
  />
</template>

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.

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.
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.
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.
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.
vue
<script setup>
const items = [
  {
    label: 'Getting Started',
    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.',
    icon: 'icon-[heroicons--information-circle]'
  },
  {
    label: 'Installation',
    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.',
    icon: 'icon-[heroicons--arrow-down-tray]'
  },
  {
    label: 'Theming',
    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.',
    icon: 'icon-[heroicons--eye-dropper]'
  },
  {
    label: 'Components',
    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.',
    icon: 'icon-[heroicons--square-3-stack-3d]'
  }
]
</script>

<template>
  <s-accordion :items="items" :ui="{ wrapper: 'flex flex-col w-full' }">
    <template #default="{ item, index, open }">
      <s-button 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">
            <s-icon :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>
          <s-icon
              name="icon-[heroicons--chevron-right-20-solid]"
              class="w-5 h-5 ms-auto transform transition-transform duration-200"
              :class="[open && 'rotate-90']"
          />
        </template>
      </s-button>
    </template>
  </s-accordion>
</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 Vue.

Installation

Install stellar-ui dependency to your project:

$ npm install stellar-ui$ yarn add stellar-ui$ pnpm add stellar-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.
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.
vue
<script setup>
const items = [
  {
    label: 'Getting Started',
    icon: 'icon-[heroicons--information-circle]',
    defaultOpen: true,
    slot: 'getting-started'
  },
  {
    label: 'Installation',
    icon: 'icon-[heroicons--arrow-down-tray]',
    defaultOpen: true,
    slot: 'installation'
  },
  {
    label: 'Theming',
    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.',
    icon: 'icon-[heroicons--eye-dropper]',
    defaultOpen: true,
    slot: 'theming'
  },
  {
    label: 'Components',
    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.',
    icon: 'icon-[heroicons--square-3-stack-3d]',
    slot: 'Components'
  }
]
</script>

<template>
  <s-accordion :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 Vue.
        </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>stellar-ui</code> dependency to your project:
        </p>
        <p>
          {{ description }}
        </p>
      </div>

      <div class="flex flex-col items-center">
        <code>$ npm install stellar-ui</code>
        <code>$ yarn add stellar-ui</code>
        <code>$ pnpm add stellar-ui</code>
      </div>
    </template>
  </s-accordion>
</template>

Released under the MIT License.