Segmented Control Vue Component

Segmented control is a linear set of two or more segments (buttons), each of which functions as a mutually exclusive button. Within the control, all buttons are equal in width. Segmented controls are often used to display different views (switch tabs).

Segmented Components

There are following components included:

  • Segmented - segmented wrapper for buttons
  • SegmentedButton - single segmented button

Segmented Props

NameTypeDefaultDescription
activeButtonIndexnumberundefined

Only for strong segmented. Active index of the currently active button. If not specified it will look in child components for button with active or segmenterActive prop.

childButtonsLengthnumberundefined

Only for strong segmented. Amount of segmented buttons. If not specified it will look on the amount of child components.

colorsobject

Object with Tailwind CSS colors classes

colors.borderstring'border-primary'

Outline segmented border color

colors.dividestring'divide-primary'

Outline segmented divider color

componentstring'div'

Component's HTML Element

outlinebooleanfalse

Makes segmented outline

raisedbooleanfalse

Makes segmented raised

roundedbooleanfalse

Makes segmented rounded

strongbooleanfalse

Makes segmented strong

SegmentedButton Props

SegmentedButton component extends Button component, it supports all Button props and the following additional props:

NameTypeDefaultDescription
activebooleanfalse

Highlights button as active

componentstring'button'

Component's HTML Element

roundedbooleanfalse

Makes segmented button rounded (should be used within <Segmented rounded>)

strongbooleanfalse

Makes strong segmented button (should be used within <Segmented strong>)

Examples

SegmentedControl.vue
<template>
<twm-page>
<twm-navbar title="Segmented Control" />
<twm-block-title>Default Segmented</twm-block-title>
<twm-block strong class="space-y-4">
<twm-segmented>
<twm-segmented-button
:active="activeSegmented === 1"
@click="() => (activeSegmented = 1)"
>
Button
</twm-segmented-button>
<twm-segmented-button
:active="activeSegmented === 2"
@click="() => (activeSegmented = 2)"
>
Button
</twm-segmented-button>
<twm-segmented-button
:active="activeSegmented === 3"
@click="() => (activeSegmented = 3)"
>
Button
</twm-segmented-button>
</twm-segmented>
<twm-segmented rounded>
<twm-segmented-button
:active="activeSegmented === 1"
@click="() => (activeSegmented = 1)"
>
Button
</twm-segmented-button>
<twm-segmented-button
:active="activeSegmented === 2"
@click="() => (activeSegmented = 2)"
>
Button
</twm-segmented-button>
<twm-segmented-button
:active="activeSegmented === 3"
@click="() => (activeSegmented = 3)"
>
Button
</twm-segmented-button>
</twm-segmented>
</twm-block>
<twm-block-title>Raised Segmented</twm-block-title>
<twm-block strong class="space-y-4">
<twm-segmented raised>
<twm-segmented-button
:active="activeSegmented === 1"
@click="() => (activeSegmented = 1)"
>
Button
</twm-segmented-button>
<twm-segmented-button
:active="activeSegmented === 2"
@click="() => (activeSegmented = 2)"
>
Button
</twm-segmented-button>
<twm-segmented-button
:active="activeSegmented === 3"
@click="() => (activeSegmented = 3)"
>
Button
</twm-segmented-button>
</twm-segmented>
<twm-segmented raised rounded>
<twm-segmented-button
:active="activeSegmented === 1"
@click="() => (activeSegmented = 1)"
>
Button
</twm-segmented-button>
<twm-segmented-button
:active="activeSegmented === 2"
@click="() => (activeSegmented = 2)"
>
Button
</twm-segmented-button>
<twm-segmented-button
:active="activeSegmented === 3"
@click="() => (activeSegmented = 3)"
>
Button
</twm-segmented-button>
</twm-segmented>
</twm-block>
<twm-block-title>Outline</twm-block-title>
<twm-block strong class="space-y-4">
<twm-segmented outline>
<twm-segmented-button
:active="activeSegmented === 1"
@click="() => (activeSegmented = 1)"
>
Button
</twm-segmented-button>
<twm-segmented-button
:active="activeSegmented === 2"
@click="() => (activeSegmented = 2)"
>
Button
</twm-segmented-button>
<twm-segmented-button
:active="activeSegmented === 3"
@click="() => (activeSegmented = 3)"
>
Button
</twm-segmented-button>
</twm-segmented>
<twm-segmented rounded outline>
<twm-segmented-button
:active="activeSegmented === 1"
@click="() => (activeSegmented = 1)"
>
Button
</twm-segmented-button>
<twm-segmented-button
:active="activeSegmented === 2"
@click="() => (activeSegmented = 2)"
>
Button
</twm-segmented-button>
<twm-segmented-button
:active="activeSegmented === 3"
@click="() => (activeSegmented = 3)"
>
Button
</twm-segmented-button>
</twm-segmented>
</twm-block>
<twm-block-title>Strong Segmented</twm-block-title>
<twm-block strong class="space-y-4">
<twm-segmented strong>
<twm-segmented-button
strong
:active="activeSegmented === 1"
@click="() => (activeSegmented = 1)"
>
Button
</twm-segmented-button>
<twm-segmented-button
strong
:active="activeSegmented === 2"
@click="() => (activeSegmented = 2)"
>
Button
</twm-segmented-button>
<twm-segmented-button
strong
:active="activeSegmented === 3"
@click="() => (activeSegmented = 3)"
>
Button
</twm-segmented-button>
</twm-segmented>
<twm-segmented strong rounded>
<twm-segmented-button
strong
rounded
:active="activeSegmented === 1"
@click="() => (activeSegmented = 1)"
>
Button
</twm-segmented-button>
<twm-segmented-button
strong
rounded
:active="activeSegmented === 2"
@click="() => (activeSegmented = 2)"
>
Button
</twm-segmented-button>
<twm-segmented-button
strong
rounded
:active="activeSegmented === 3"
@click="() => (activeSegmented = 3)"
>
Button
</twm-segmented-button>
</twm-segmented>
</twm-block>
</twm-page>
</template>
<script>
import { ref } from 'vue';
import {
twmPage,
twmNavbar,
twmNavbarBackLink,
twmSegmented,
twmSegmentedButton,
twmBlock,
twmBlockTitle,
} from 'tailwind-mobile/vue';
export default {
components: {
twmPage,
twmNavbar,
twmNavbarBackLink,
twmSegmented,
twmSegmentedButton,
twmBlock,
twmBlockTitle,
},
setup() {
const activeSegmented = ref(1);
return {
activeSegmented,
};
},
};
</script>
Code licensed under MIT.
2021 © Tailwind Mobile by nolimits4web.