Vitral 0.2.18
Painel

Tabs

Vistas que dividem um mesmo lugar na página, trocadas por uma lista de abas.

Importação

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

Básico

Files you opened in the last week.

value: recent
<script setup lang="ts">import { Tab, TabList, TabPanel, TabPanels, Tabs } from '@vitral/vue';import { ref } from 'vue'; const tab = ref<string | number>('recent');const views = [    { value: 'recent', label: 'Recent', body: 'Files you opened in the last week.' },    { value: 'shared', label: 'Shared with me', body: 'Files other people gave you access to.' },    { value: 'favorites', label: 'Favorites', body: 'Files you starred.' },    { value: 'trash', label: 'Recycle bin', body: 'Deleted files, kept for 30 days.', disabled: true }];</script> <template>    <Tabs v-model:value="tab" style="width: 100%">        <TabList aria-label="Files">            <Tab v-for="v in views" :key="v.value" :value="v.value" :disabled="v.disabled">{{ v.label }}</Tab>        </TabList>        <TabPanels>            <TabPanel v-for="v in views" :key="v.value" :value="v.value">                <p style="margin: 0">{{ v.body }}</p>            </TabPanel>        </TabPanels>    </Tabs>    <small style="color: var(--vt-text-muted-color)">value: {{ tab }}</small></template>

Com rolagem

`scrollable` deixa as abas que não cabem rolarem pela faixa, na horizontal ou na vertical. Os botões avançam quase uma página por vez; `scroll-buttons` coloca um em cada ponta (`sides`, o padrão, cada um visível só enquanto houver mais naquele sentido), os dois juntos no início (`start`) ou no fim (`end`), ou nenhum (`none`). A aba selecionada sempre é trazida à vista — pressione End nas abas para vê-la acompanhar.

The report for January.

The report for January.

<script setup lang="ts">import { SelectButton, Tab, TabList, TabPanel, TabPanels, Tabs } from '@vitral/vue';import { ref } from 'vue'; const months = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];const tab = ref('January');const upright = ref('January');const buttons = ref<'sides' | 'start' | 'end' | 'none'>('sides');</script> <template>    <div style="display: flex; flex-direction: column; gap: 1rem; width: 100%">        <SelectButton v-model="buttons" :options="['sides', 'start', 'end', 'none']" :allow-empty="false" aria-label="Where the buttons go" />        <Tabs v-model:value="tab" scrollable :scroll-buttons="buttons" style="width: 100%; max-width: 32rem">            <TabList aria-label="Months">                <Tab v-for="m in months" :key="m" :value="m">{{ m }}</Tab>            </TabList>            <TabPanels>                <TabPanel v-for="m in months" :key="m" :value="m">                    <p style="margin: 0">The report for {{ m }}.</p>                </TabPanel>            </TabPanels>        </Tabs>        <!-- Upright, the strip scrolls within the height the Tabs are given. -->        <Tabs v-model:value="upright" orientation="vertical" scrollable :scroll-buttons="buttons" style="width: 100%; height: 14rem">            <TabList aria-label="Months, upright">                <Tab v-for="m in months" :key="m" :value="m">{{ m }}</Tab>            </TabList>            <TabPanels>                <TabPanel v-for="m in months" :key="m" :value="m">                    <p style="margin: 0">The report for {{ m }}.</p>                </TabPanel>            </TabPanels>        </Tabs>    </div></template>

Vertical

Name, email and password.

<script setup lang="ts">import { Tab, TabList, TabPanel, TabPanels, Tabs } from '@vitral/vue';import { ref } from 'vue'; const vertical = ref<string | number>(0);</script> <template>    <Tabs v-model:value="vertical" orientation="vertical" style="width: 100%">        <TabList aria-label="Settings">            <Tab :value="0">Account</Tab>            <Tab :value="1">Notifications</Tab>            <Tab :value="2">Billing</Tab>        </TabList>        <TabPanels>            <TabPanel :value="0"><p style="margin: 0">Name, email and password.</p></TabPanel>            <TabPanel :value="1"><p style="margin: 0">What to be told about, and where.</p></TabPanel>            <TabPanel :value="2"><p style="margin: 0">Plan, invoices and payment method.</p></TabPanel>        </TabPanels>    </Tabs></template>

Estilos

Um componente, cinco visuais além da seleção tingida padrão: um discreto, só com a pílula, um sublinhado da largura da aba, pílulas preenchidas, um controle segmentado e abas com ícone e contador. Cada um é o componente com os tokens trocados só naquela instância via `dt` — a trilha do segmentado soma um estilo via `pt` — então um preset dá o mesmo visual a todos os Tabs definindo os mesmos tokens.

Quiet
Underline
Pills
Segmented
Icons and a count

Activity lives here.

<script setup lang="ts">import { Badge, Icon, Tab, TabList, TabPanel, TabPanels, Tabs } from '@vitral/vue';import { ref } from 'vue'; const views = [    { value: 'overview', label: 'Overview', icon: 'home' },    { value: 'activity', label: 'Activity', icon: 'bell', count: 4 },    { value: 'files', label: 'Files', icon: 'folder' },    { value: 'settings', label: 'Settings', icon: 'sliders' }];const quiet = ref('overview');const underline = ref('overview');const pills = ref('activity');const segmented = ref('files');const withIcons = ref('activity'); // Every look below is the same component with its tokens changed for this// instance (`dt`), and — for the segmented strip's track — a class or a style// through pass-through (`pt`). A preset sets the same tokens for every Tabs. /** Quieter than the default: no tint behind the selected tab, only the pill under it. */const quietTokens = { tabs: { tab: { activeBackground: 'transparent', activeColor: '{text.hoverColor}' } } }; /** An underline as wide as the tab, over a hairline along the whole strip. */const underlineTokens = {    tabs: {        tablist: { borderWidth: '1px', gap: '0' },        tab: { borderRadius: '0', hoverBackground: 'transparent', activeBackground: 'transparent', activeColor: '{text.hoverColor}', padding: '0.625rem 1rem' },        indicator: { width: '100%', thickness: '2px', borderRadius: '0' }    }}; /** Filled pills: the selected tab is the solid accent, and the indicator steps aside. */const pillTokens = {    tabs: {        tablist: { gap: '0.375rem' },        tab: { borderRadius: '{borderRadius.pill}', padding: '0.375rem 0.875rem', activeBackground: '{primary.color}', activeColor: '{primary.contrastColor}' },        indicator: { thickness: '0' }    }}; /** A segmented control: a track, and the selected tab raised on it. */const segmentedTokens = {    tabs: {        tablist: { padding: '0.25rem', gap: '0.25rem' },        tab: { borderRadius: '{borderRadius.md}', activeBackground: '{content.background}', activeColor: '{text.hoverColor}', hoverBackground: 'transparent' },        indicator: { thickness: '0' }    }};const trackPt = { tablist: { style: 'background: var(--vt-content-hover-background); border-radius: var(--vt-border-radius-lg); align-self: flex-start' } };const raisedPt = { tab: ({ state }: { state: unknown }) => ((state as { selected?: boolean }).selected ? { style: 'box-shadow: 0 1px 2px rgb(0 0 0 / 0.12)' } : {}) };</script> <template>    <div style="display: grid; gap: 1.75rem; width: 100%">        <section>            <small class="demo-caption">Quiet</small>            <Tabs v-model:value="quiet" :dt="quietTokens">                <TabList aria-label="Quiet">                    <Tab v-for="v in views" :key="v.value" :value="v.value">{{ v.label }}</Tab>                </TabList>            </Tabs>        </section>         <section>            <small class="demo-caption">Underline</small>            <Tabs v-model:value="underline" :dt="underlineTokens">                <TabList aria-label="Underline">                    <Tab v-for="v in views" :key="v.value" :value="v.value">{{ v.label }}</Tab>                </TabList>            </Tabs>        </section>         <section>            <small class="demo-caption">Pills</small>            <Tabs v-model:value="pills" :dt="pillTokens">                <TabList aria-label="Pills">                    <Tab v-for="v in views" :key="v.value" :value="v.value">{{ v.label }}</Tab>                </TabList>            </Tabs>        </section>         <section>            <small class="demo-caption">Segmented</small>            <Tabs v-model:value="segmented" :dt="segmentedTokens">                <TabList aria-label="Segmented" :pt="trackPt">                    <Tab v-for="v in views" :key="v.value" :value="v.value" :pt="raisedPt">{{ v.label }}</Tab>                </TabList>            </Tabs>        </section>         <section>            <small class="demo-caption">Icons and a count</small>            <Tabs v-model:value="withIcons" :dt="underlineTokens">                <TabList aria-label="With icons">                    <Tab v-for="v in views" :key="v.value" :value="v.value">                        <Icon :icon="v.icon" />                        {{ v.label }}                        <Badge v-if="v.count" :value="v.count" severity="danger" />                    </Tab>                </TabList>                <TabPanels>                    <TabPanel v-for="v in views" :key="v.value" :value="v.value">                        <p style="margin: 0">{{ v.label }} lives here.</p>                    </TabPanel>                </TabPanels>            </Tabs>        </section>    </div></template> <style scoped>.demo-caption {    display: block;    margin-bottom: 0.375rem;    color: var(--vt-text-muted-color);}</style>

Ativação manual

Com `select-on-focus` desligado, as setas só movem o foco; Enter ou Espaço selecionam.

Rendered only while selected (`lazy`).

<script setup lang="ts">import { Tab, TabList, TabPanel, TabPanels, Tabs } from '@vitral/vue';</script> <template>    <Tabs value="a" :select-on-focus="false" lazy>        <TabList aria-label="Manual">            <Tab value="a">Overview</Tab>            <Tab value="b">Activity</Tab>            <Tab value="c">Members</Tab>        </TabList>        <TabPanels>            <TabPanel value="a"><p style="margin: 0">Rendered only while selected (`lazy`).</p></TabPanel>            <TabPanel value="b"><p style="margin: 0">Recent activity.</p></TabPanel>            <TabPanel value="c"><p style="margin: 0">Who is in the project.</p></TabPanel>        </TabPanels>    </Tabs></template>

API

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

Props

NomeTipoDescrição
orientation 'horizontal' | 'vertical'Abas acima dos painéis (o padrão) ou ao lado deles.
lazy booleanRenderiza um painel só enquanto sua aba está selecionada.
selectOnFocus booleanSeleciona uma aba assim que as setas chegam nela: a ativação automática do APG, e o padrão. Desligado, as setas só movem o foco e Enter/Espaço selecionam.
scrollable booleanAs abas que não cabem rolam pela faixa, com um botão em cada ponta que ainda tem mais para mostrar; a aba selecionada é sempre trazida à vista.
scrollButtons 'sides' | 'start' | 'end' | 'none'Onde ficam os botões de uma faixa rolável: um em cada ponta (`'sides'`, o padrão), os dois juntos no início ou no fim, ou nenhum — as setas do teclado, a roda do mouse e o toque ainda rolam.

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

Slots

NomeProps do slotDescrição
default ——