Skip to content

MazTabs

MazTabs is a standalone component to display content in tabs with animations

Basic usage

Tab 1
vue
<script lang="ts" setup>
import { MazTabs, MazTabsBar, type MazTabsBarItem, MazTabsContent, MazTabsContentItem } from 'maz-ui/components'

const tabs: MazTabsBarItem[] = [
  { label: 'First Tab', disabled: false },
  { label: 'Second Tab', disabled: false, badge: { color: 'destructive', content: 1, roundedSize: 'full' } },
  { label: 'Third Tab', disabled: true },
]
</script>

<template>
  <MazTabs>
    <MazTabsBar :items="tabs" />

    <MazTabsContent>
      <MazTabsContentItem :tab="1" class="maz-py-4">
        Tab 1
      </MazTabsContentItem>
      <MazTabsContentItem :tab="2" class="maz-py-4">
        Tab 2
      </MazTabsContentItem>
      <MazTabsContentItem :tab="3" class="maz-py-4">
        Tab 3
      </MazTabsContentItem>
    </MazTabsContent>
  </MazTabs>
</template>

With model-value

Tab 2

View code
vue
<script lang="ts" setup>
import { ref } from 'vue'

const currentTab = ref(2)

const tabs: MazTabsBarItem[] = ['First Tab', 'Second Tab', 'Third Tab']
</script>

<template>
  <MazTabs v-model="currentTab">
    <MazTabsBar :items="tabs" />

    <MazTabsContent>
      <MazTabsContentItem :tab="1" class="maz-py-4">
        Tab 1
      </MazTabsContentItem>
      <MazTabsContentItem :tab="2" class="maz-py-4">
        Tab 2
      </MazTabsContentItem>
      <MazTabsContentItem :tab="3" class="maz-py-4">
        Tab 3
      </MazTabsContentItem>
    </MazTabsContent>
  </MazTabs>

  <br>

  <MazBtn @click="currentTab = currentTab === 1 ? 2 : 1">
    Set model-value to {{ currentTab === 1 ? 2 : 1 }}
  </MazBtn>
</template>

Persistent tab

To keep the tab current when the page reloads, you can use the persistent props on the component <MazTabsBar />.

The component will save the current table index in the URL of the page via a query parameter.

You can choose the name of this query parameter with the props query-param @default 'tab'

Tab 1

Custom tabs with slot

html
<MazTabs>
  <MazTabsBar :items="tabs">
    <template #item="{ item, index, active }">
      {{ item.label }}

      <MazBadge size="0.6rem" rounded-size="full" :color="active ? 'primary' : 'transparent'"> {{ index }} </MazBadge>
    </template>
  </MazTabsBar>
</MazTabs>

Types

ts
type MazTabsBarItem
  = | {
    /**
     * Label of the tab
     */
    label: string
    /**
     * Will disable the tab
     * @default false
     */
    disabled?: boolean
    /**
     * Badge to display in the tab
     * Inherit all props of MazBadge component
     */
    badge?: MazBadgeProps & {
      /**
       * Content of the badge
       */
      content: string | number | boolean
    }
  }
  | string

Props & Events emitted

MazTabs

Props

NameDescriptionTypeRequired
model-valueThe the selected tab numbernumberNo

Events

Event namePropertiesDescription
update:model-valuenewValue number - new value setEmitted when the selected tab change

Slots

NameDescriptionBindings
default

MazTabsBar

Props

NameDescriptionTypeRequiredDefault
itemsThe items to display in the tabs barMazTabsBarItem[]Yesundefined
persistentWill add a query param to the url to keep the selected tab on page refreshbooleanNofalse
query-paramThe name of the query param to add to the urlstringNotab
blockWill make the tabs bar full widthbooleanNofalse
elevationWill remove the elevationbooleanNofalse
auto-scrollWill add a scroll on the tabs bar to show selected elementbooleanNotrue
borderedWill add a border to the tabs barbooleanNotrue

Slots

NameDescriptionBindings
itemContent of item to display in the tabs baritem MazTabsBarItem[] - all data of the item
active boolean - true if the tab is active
index number - index of the item
badge-contentContent in the badgecontent string | number | boolean - content of the badge provided in item

MazTabsContent

Slots

NameDescriptionBindings
default

MazTabsContentItem

Props

NameDescriptionTypeRequired
tabnumberYes

Slots

NameDescriptionBindings
default