Skip to content

Getting started ​

Install @ghostvue/vue and @ghostvue/themes, load one theme stylesheet, and import components from @ghostvue/themes to get styled, accessible components in a few minutes. If you bring your own design system, skip to Bring your own styles for the unstyled layer.

Warning

GhostVue is published on npm and is in active pre-1.0 development. Minor releases may include breaking API changes. Check the release notes before upgrading.

Install ​

Install both packages. @ghostvue/vue holds the accessible behavior and @ghostvue/themes adds the styled wrappers and stylesheets used below. Vue 3.5 or newer is a peer dependency, and @ghostvue/themes peers on @ghostvue/vue so both share one copy. The GhostVue packages share one version; keep them on the same release.

bash
pnpm add @ghostvue/vue @ghostvue/themes

Add a theme ​

Import a flagship stylesheet once and make the <html> element the app's theme host. Themed components read tokens from the nearest data-ghost-theme host, and overlays such as dialogs and menus teleport to <body> by default, so a host on <html> covers them too. Importing from @ghostvue/themes already loads the base stylesheet, in development and in production builds, so you do not need a separate @ghostvue/themes/default.css import.

ts
// main.ts
import { createApp } from 'vue'
import '@ghostvue/themes/calm.css'
import App from './App.vue'

createApp(App).mount('#app')
html
<!-- index.html -->
<html lang="en" class="ghost-theme" data-ghost-theme="calm"></html>

The host needs both:

  • class="ghost-theme" paints the app canvas: the surface background, text color, and font from the active palette. Without it, components are themed but the page keeps the browser's default background, text color, and serif font.
  • data-ghost-theme="calm" selects the palette tokens. Without it, a ghost-theme host uses the default palette.

Keep the host on <html> rather than on your app's mount element. A dialog, drawer, menu, popover, or tooltip teleported to <body> sits outside #app, so it would lose the palette there.

Flagships: default, calm, vibrant, mono. Light and dark follow prefers-color-scheme. Set data-ghost-mode="dark" on any element to force it.

Your first themed component ​

Copy this SFC into App.vue. It imports GhostField and GhostInput from @ghostvue/themes and needs no CSS of its own: with the setup above it renders in the calm palette and follows light and dark. The preview here follows the documentation theme picker instead.

Themed stack

Default vertical spacing from @ghostvue/themes.

The label, description, and input are wired together for assistive technology: GhostFieldControl passes the input its id and aria-describedby through the slot props. Browse components for the rest of the themed catalogue; each one imports from @ghostvue/themes the same way.

Importing from @ghostvue/themes loads the recipe for every themed component. If your app renders only a few of them and CSS size matters, see opt-in theme CSS: one palette, a shared base, and only the recipes you use, with components from @ghostvue/themes/components.

What a themed app imports from @ghostvue/vue ​

@ghostvue/themes exports a component only when it has a theme. Parts that add behavior but no styles of their own ship from @ghostvue/vue only, and a themed app imports them from there next to its themed components:

Import from @ghostvue/vueWhy it is not in @ghostvue/themes
GhostTooltipProviderRenders nothing. It shares open and skip delays between the themed tooltips inside it.
GhostForm, useGhostFormRenders a plain <form> and feeds validation errors to the themed fields inside it.
GhostTableCaption, GhostTableHead, GhostTableBody, GhostTableFoot, GhostTableRow, GhostTableHeaderCell, GhostTableCellThe themed GhostTable styles these parts, so they have no wrapper of their own.
GhostVisuallyHidden, GhostPortal, GhostPresenceUtilities with no visual design: screen-reader-only text, teleporting, and mount and unmount timing.
GhostDataGrid, useGhostDataGridHeadless only for now; style it with its ghost-* classes and data-part hooks.
Most useGhost* composables, plus shared ones such as useGhostId and useFloatingComposables drive your own markup, so they carry no theme.

Types for these parts, such as GhostFormSubmitPayload and StandardSchemaV1, come from @ghostvue/vue too. A few composables that themed components need at the call site, such as useGhostToast, useGhostSelect, and useGhostDataTable, are exported by both packages; import them from either.

An App.vue that wraps the app in one tooltip provider and submits a validated form imports from both packages:

vue
<!-- App.vue -->
<script setup lang="ts">
import { reactive } from 'vue'
import { z } from 'zod'

// Behavior with no theme of its own.
import {
  GhostForm,
  GhostTooltipProvider,
  type GhostFormSubmitPayload,
} from '@ghostvue/vue'
// Styled components.
import {
  GhostButton,
  GhostField,
  GhostFieldControl,
  GhostFieldError,
  GhostFieldLabel,
  GhostInput,
  GhostTooltip,
  GhostTooltipContent,
  GhostTooltipTrigger,
} from '@ghostvue/themes'

// Any Standard Schema v1 validator works; Zod is one.
const schema = z.object({
  email: z.email('Enter an email address.'),
})
type Invite = z.input<typeof schema>

const values = reactive<Invite>({ email: '' })

function invite({
  output,
}: GhostFormSubmitPayload<z.output<typeof schema>, Invite>): void {
  console.log(`Inviting ${output.email}`)
}
</script>

<template>
  <GhostTooltipProvider :delay-duration="300">
    <GhostForm :schema="schema" :values="values" @submit="invite">
      <GhostField name="email" required>
        <GhostFieldLabel>Email</GhostFieldLabel>
        <GhostFieldControl v-slot="field">
          <GhostInput v-bind="field" v-model="values.email" type="email" />
        </GhostFieldControl>
        <GhostFieldError />
      </GhostField>

      <GhostTooltip>
        <GhostTooltipTrigger :as="GhostButton" type="submit">
          Invite
        </GhostTooltipTrigger>
        <GhostTooltipContent>Sends an email invitation</GhostTooltipContent>
      </GhostTooltip>
    </GhostForm>
  </GhostTooltipProvider>
</template>

See Form, Tooltip, and Table for the full patterns.

Choose headless or themed ​

You wantImport fromYou get
Your own design system@ghostvue/vueUnstyled, accessible components and useGhost* composables. No CSS.
A polished default you can tune@ghostvue/themesThe same components with variant, tone, and size props and token-driven styles.

Both are ordinary Vue components with the same behavior and names, so you can start themed and replace pieces with headless ones later.

Bring your own styles ​

This path is for teams with their own design system or CSS. Every themed component has a headless counterpart in @ghostvue/vue with the same name, props, and accessibility behavior, and no CSS.

Your first headless component ​

Import primitives from @ghostvue/vue when you want full control over CSS. Components wire ARIA attributes, IDs, and keyboard behavior while exposing ghost-* classes and data-part / data-state hooks for your own styles. This sample renders with browser defaults until you style it:

Labeled input Headless

Label, hint, and control id wiring for GhostInput.

If you use only the headless layer, you can leave out @ghostvue/themes and skip Add a theme.

SSR ​

Components render deterministic markup and IDs on the server and do not read browser globals during setup. Mode follows prefers-color-scheme in CSS, so there is no flash of the wrong palette.

Tooling: Nuxt, auto-imports, and ESLint ​

Auto-imports and Nuxt ​

Named imports stay the primary API, and the steps above work unchanged in any Vue 3.5 app. For Nuxt apps, @ghostvue/nuxt auto-imports headless Ghost* components and useGhost* composables from @ghostvue/vue and adds no CSS by default. To get the themed result from this guide through auto-imports, opt in with components: 'themed' and css: ['calm'] under the module's ghostvue key and give the <html> element the same class="ghost-theme" and data-ghost-theme="calm" host as above. Other Vite apps can use GhostVueResolver() from @ghostvue/vue/resolver with unplugin-vue-components. See Nuxt and auto-imports.

ESLint template validation ​

@ghostvue/eslint-plugin validates <Ghost*> props, slots, and v-model bindings in .vue templates against the library's published component contracts:

bash
pnpm add -D @ghostvue/eslint-plugin eslint eslint-plugin-vue
js
// eslint.config.js
import ghostvue from '@ghostvue/eslint-plugin'
import vue from 'eslint-plugin-vue'

export default [
  ...vue.configs['flat/recommended'],
  ghostvue.configs.recommended,
]

See ESLint plugin for rule details and configuration options.

Try it from a checkout ​

Contributors can run the local playground and docs with Node.js 22.12+ and pnpm 11+.

bash
git clone https://github.com/zprue743/ghostvue.git
cd ghostvue
pnpm install
pnpm dev        # playground with every component and theme
pnpm docs:dev   # this site, with live examples

Next steps ​