Skip to content

useCustomizer ​

Opens and closes the theme customizer. One ref, because the things that open it are scattered and the drawer is mounted once.

Open in demo

Import ​

ts
import { useCustomizer } from '@shared/composables/useCustomizer'

Signature ​

ts
function useCustomizer(): {
  open: Ref<boolean>
  openCustomizer: () => void
  closeCustomizer: () => void
  toggleCustomizer: () => void
}

Returns ​

MemberTypeDescription
openRef<boolean>Writable, so it can be bound with v-model.
openCustomizer() => voidOpens the drawer.
closeCustomizer() => voidCloses it.
toggleCustomizer() => voidFlips it. Bound to t c.

Example ​

vue
<script setup lang="ts">
import { useCustomizer } from '@shared/composables/useCustomizer'

const { openCustomizer } = useCustomizer()
</script>

<template>
  <button type="button" @click="openCustomizer()">
    Change the theme
  </button>
</template>

Notes ​

  • A singleton ref rather than a prop or provide. The drawer is mounted once in App.vue, but the floating trigger, the showcase card and the t c shortcut all need to open it. A shared ref means none of that state has to be threaded through the layout tree.
  • This composable holds the open state only. What the drawer changes is useConfig and useTheme.