component

Theme toggle

Light, dark or system as one segmented control, over Nuxt's color mode.

Three Nuxt UI buttons in a field group, the chosen one pressed. The preference is only known in the browser, so on the server a disabled copy stands in rather than a guess. It is the same toggle as in this site's header.

<template>
  <ZThemeToggle />
</template>

useZooTheme()

The toggle is a view over useZooTheme(), which you can use for a control of your own. theme is the preference (light, dark or system), writable, and setTheme changes it too. ZOO_THEMES lists the three.

The same preference as the toggle in the header.
<script setup lang="ts">
const { theme } = useZooTheme()
const themes = [...ZOO_THEMES]
</script>

<template>
  <div class="flex items-center gap-3">
    <ClientOnly>
      <USelect v-model="theme" :items="themes" class="w-32" aria-label="Theme" />
      <template #fallback><USelect :items="themes" class="w-32" disabled aria-label="Theme" /></template>
    </ClientOnly>
    <span class="text-sm text-muted">The same preference as the toggle in the header.</span>
  </div>
</template>

API

Props

No props.