On this page

Toggle button

Live examples of Toggle button, with the exact Vue file that renders each one.

Every example is a complete Vue file. Copy it into an app that has the registry installed, or open it in StackBlitz.

On and off

Default (outline) and Subtle toggles. On: graphite 5 fill with a bold border, so it never looks like hover.

ToggleBasic.vue
<script setup lang="ts">
import { Pin } from '@lucide/vue'
import { ref } from 'vue'
import { Toggle } from '@/components/ui/toggle'

const pinned = ref(true)
</script>

<template>
  <div class="flex items-center gap-(--bh-space-100)">
    <Toggle v-model="pinned" variant="outline"><Pin />Pin</Toggle>
    <Toggle><Pin />Pin</Toggle>
    <Toggle variant="outline" disabled><Pin />Pin</Toggle>
  </div>
</template>

Icon only

An icon-only toggle names the option, not the state: “Wrap lines”.

ToggleIcon.vue
<script setup lang="ts">
import { WrapText } from '@lucide/vue'
import { ref } from 'vue'
import { Toggle } from '@/components/ui/toggle'
import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from '@/components/ui/tooltip'

const wrap = ref(false)
</script>

<template>
  <TooltipProvider>
    <Tooltip relationship="label">
      <TooltipTrigger as-child>
        <Toggle v-model="wrap" size="icon"><WrapText /></Toggle>
      </TooltipTrigger>
      <TooltipContent>Wrap lines</TooltipContent>
    </Tooltip>
  </TooltipProvider>
</template>

Filter a list

The change applies at once, without a Save button.

  • Orders to ERP
  • Stock from warehouse · Failed
  • Customers to CRM
ToggleFilter.vue
<script setup lang="ts">
import { ref } from 'vue'
import { Toggle } from '@/components/ui/toggle'

const onlyErrors = ref(false)
const runs = [
  { id: 1, name: 'Orders to ERP', failed: false },
  { id: 2, name: 'Stock from warehouse', failed: true },
  { id: 3, name: 'Customers to CRM', failed: false },
]
</script>

<template>
  <div class="flex w-full max-w-100 flex-col gap-(--bh-space-100)">
    <Toggle v-model="onlyErrors" variant="outline" size="sm" class="self-start">Show only errors</Toggle>
    <ul class="m-0 list-none p-0">
      <li v-for="run in runs.filter(r => !onlyErrors || r.failed)" :key="run.id" class="py-(--bh-space-050)">
        {{ run.name }}<span v-if="run.failed" class="text-(--bh-color-text-danger)"> · Failed</span>
      </li>
    </ul>
  </div>
</template>