Vitral 0.2
Painel

Accordion

Seções empilhadas que abrem e fecham, uma por vez ou várias ao mesmo tempo, com cabeçalhos que seguem o accordion do WAI-ARIA.

Importação

main.ts
import { Accordion } from '@vitral/vue';

Uma aberta por vez

Language, region and the start page.

value: general
<script setup lang="ts">import { Accordion, AccordionContent, AccordionHeader, AccordionPanel } from '@vitral/vue';import { ref } from 'vue'; const sections = [    { value: 'general', title: 'General', body: 'Language, region and the start page.' },    { value: 'appearance', title: 'Appearance', body: 'Theme, accent colour and density.' },    { value: 'privacy', title: 'Privacy & security', body: 'Permissions, history and what is shared.' },    { value: 'updates', title: 'Updates', body: 'Channel and when to install.', disabled: true }]; const single = ref<string | number | (string | number)[] | null>('general');</script> <template>    <Accordion v-model:value="single" style="width: 100%">        <AccordionPanel v-for="s in sections" :key="s.value" :value="s.value" :disabled="s.disabled">            <AccordionHeader>{{ s.title }}</AccordionHeader>            <AccordionContent>                <p style="margin: 0">{{ s.body }}</p>            </AccordionContent>        </AccordionPanel>    </Accordion>    <small style="color: var(--vt-text-muted-color)">value: {{ single ?? 'null' }}</small></template>

Várias

Language, region and the start page.

Permissions, history and what is shared.

value: [ "general", "privacy" ]
<script setup lang="ts">import { Accordion, AccordionContent, AccordionHeader, AccordionPanel } from '@vitral/vue';import { ref } from 'vue'; const sections = [    { value: 'general', title: 'General', body: 'Language, region and the start page.' },    { value: 'appearance', title: 'Appearance', body: 'Theme, accent colour and density.' },    { value: 'privacy', title: 'Privacy & security', body: 'Permissions, history and what is shared.' }]; const several = ref<string | number | (string | number)[] | null>(['general', 'privacy']);</script> <template>    <Accordion v-model:value="several" multiple style="width: 100%">        <AccordionPanel v-for="s in sections" :key="s.value" :value="s.value">            <AccordionHeader>{{ s.title }}</AccordionHeader>            <AccordionContent>                <p style="margin: 0">{{ s.body }}</p>            </AccordionContent>        </AccordionPanel>    </Accordion>    <small style="color: var(--vt-text-muted-color)">value: {{ several }}</small></template>

Ícones personalizados

A Vue 3 component library with a theme engine of its own.

<script setup lang="ts">import { Accordion, AccordionContent, AccordionHeader, AccordionPanel } from '@vitral/vue';</script> <template>    <Accordion value="a" expand-icon="plus" collapse-icon="minus" style="width: 100%">        <AccordionPanel value="a">            <AccordionHeader>What is Vitral?</AccordionHeader>            <AccordionContent>A Vue 3 component library with a theme engine of its own.</AccordionContent>        </AccordionPanel>        <AccordionPanel value="b">            <AccordionHeader>Does it work unstyled?</AccordionHeader>            <AccordionContent>Yes: every part takes pass-through, and `unstyled` drops the built-in classes.</AccordionContent>        </AccordionPanel>    </Accordion></template>

API

Lido de packages/vue/src/components/Accordion/types.ts, então diz o que o componente aceita de fato.

Props

NomeTipoDescrição
multiplebooleanPermite vários painéis abertos ao mesmo tempo; `value` passa a ser um array.
lazybooleanRenderiza o conteúdo de um painel só enquanto ele está aberto.
headingLevelnumberO nível do título em que fica o botão de cada cabeçalho. O padrão é 3; ajuste-o à estrutura da página.
expandIconIconPropMostrado num painel fechado no lugar da seta.
collapseIconIconPropMostrado num painel aberto no lugar da seta.

Mais pt, dt e unstyled de BaseProps; veja pass-through e modo sem estilo.

Slots

NomeProps do slotDescrição
default——