Styling architecture
Functionality is headless and must work without the default theme. @ghostvue/vue must never import @ghostvue/themes as a requirement for behavior.
Both headless and themed use must be ordinary Vue: a composable and thin unstyled GhostButton from @ghostvue/vue, or a themed GhostButton from @ghostvue/themes that wraps it. Details, a hard rejection of PrimeVue pt objects, and worked examples are in ADR 0004. Component names use the Ghost prefix (GhostButton, useGhostButton); that convention is ADR 0003.
Layers
- Composable in
@ghostvue/vue(useGhostButton) owns behavior, a11y, and SSR. - Thin unstyled component in
@ghostvue/vue(GhostButton) spreads those bindings onto a native element, forwardsclassand attrs, and exposes slots. It ships no visual styles. - Themed wrapper in
@ghostvue/themeswraps the unstyled component, applies default classes, and exposes ordinary visual props. It may depend onvue;vuestill must not depend onthemes.
Styling hooks
Components expose stable data-* attributes as the documented styling API, in the style of Radix and Ark. Style against these hooks and --ghost-* custom properties, not against DOM structure. Internal wrapper nesting, element order, and tag names other than the native semantic element are not a public contract. Do not add per-part style-object props or a pt passthrough object.
Consumers must remain able to use normal CSS, utility CSS, CSS Modules, or another theme system. Headless semantics, focus behavior, and state must not depend on a particular visual treatment.
Attribute contract
| Attribute | Carries | Encoding |
|---|---|---|
data-part | Which part of the component an element is. Every element a consumer may style has one. | Kebab-case token. The outermost element of each component is root; other parts use nouns (trigger, content, indicator). |
data-state | The component's primary state axis. | One kebab-case token at a time. Absent when the component is idle or the axis has no active value. |
data-disabled | Unavailability when data-state already carries another axis (checked menu items, pages). | Presence attribute: empty string when true, absent when false. |
Other data-* (data-orientation) | Secondary axes that are not state, such as layout direction or themed visual props. | Enumerated token, or a presence attribute for booleans. |
Shared data-state vocabulary, reused instead of inventing synonyms:
- Disclosure:
open/closed(dialog, popover, menu, collapsible, tooltip triggers and contents). - Selection:
checked/unchecked(switch, checkable menu items),checkedalone where only the selected value is marked (checkbox, radio items),indeterminate(checkbox, progress). - Activation:
active/inactive(tabs),on/off(toggle and segmented items). - Availability and validity:
disabled,loading,invalid,readonly.
Component-specific values, such as avatar image loaded / error, are listed in that component's manifest.
When two states can apply at once, the component documents which one wins data-state and exposes the other through a native attribute or a separate hook. GhostButton prefers loading over disabled and keeps the native disabled attribute. Menu items keep checked in data-state and add data-disabled. Pointer-reactive surfaces use data-interactive and, on hosts that already own data-state, data-interactive-state.
Prefer native and ARIA attributes when they already express the state (:disabled, [aria-expanded], [aria-current]). The data hooks exist so the same selector works across native and composite elements and so utility CSS has one predictable attribute to target.
Stability
- Every hook value a component emits is listed in its component manifest under
styling:parts(data-part),states(data-state),attributes(otherdata-*hooks with their values), andcssProperties. The generated component reference pages render the same lists. - Renaming or removing a documented hook value is a breaking change, the same as renaming a prop. Adding a part, state, or attribute is additive.
- Undocumented
data-*attributes (for example internaldata-ghost-*markers) and class names are not part of this contract and may change. - Hooks render the same during SSR and hydration, so attribute selectors do not flash.
Examples
Plain CSS or CSS Modules:
.button[data-part='root'][data-state='loading'] {
cursor: progress;
}
.item[data-disabled] {
opacity: 0.5;
}Tailwind CSS (v3.2+ or v4) arbitrary data variants target the same hooks. The headless component ships no classes, so utilities apply directly:
<script setup lang="ts">
import { ref } from 'vue'
import { GhostButton } from '@ghostvue/vue'
const saving = ref(false)
</script>
<template>
<GhostButton
:loading="saving"
class="rounded-md bg-blue-600 px-3 py-2 text-white data-[state=disabled]:opacity-50 data-[state=loading]:cursor-progress data-[state=loading]:opacity-75"
>
Save
</GhostButton>
</template>Use data-[disabled]: for presence hooks and data-[orientation=vertical]: for enumerated ones. Use group-data-[state=open]: with a group class on the parent part to style children from a parent hook. The repository does not depend on Tailwind; these classes are consumer-side.
Themed wrapper roots
A themed wrapper activates its recipe in one of three ways: a data-themed attribute on the headless root, a display: contentsspan.ghost-themed-scope around it, or a block div.ghost-themed-scope container. The choice changes which element a consumer's <style scoped> block reaches. Vue puts the parent's scope attribute on the wrapper's own root node, while the wrapper forwards class and other attributes to the headless component, so wrappers copy the scope attribute to the element that receives class. Headless content parts, overlays, and the toast viewport render a portal as their root, which gives Vue no element to mark, so they bind the consumer's scope attribute on the element inside the portal that receives class (packages/vue/src/consumer-scope-attrs.ts). The per-component table and the consumer workarounds are in styling themed components from your app. Update that table when a wrapper changes strategy.
Color modes, motion, and forced colors
Themes respond to three user preferences. Component recipes must keep all three working without JavaScript, so server rendering never flashes.
Light and dark. Two strategies share one token set. With no
data-ghost-mode, generated token CSS follows@media (prefers-color-scheme: dark). Settingdata-ghost-mode="light"or"dark"on any element pins that subtree; the nearest attribute wins, so modes nest. Recipes consume semantic--ghost-*tokens only and never branch on the mode themselves.Reduced motion. Under
prefers-reduced-motion: reducethe generated--ghost-motion-*durations collapse (focus ring and stagger become instant; other transitions keep short color and opacity feedback). Recipes put movement (translate, scale, size transitions,@starting-style) behindprefers-reduced-motion: no-preferenceor a motion token, so movement is opt-in. See motion.Forced colors. Under
@media (forced-colors: active)the generated tokens map to CSS system colors (Canvas,CanvasText,ButtonFace,ButtonText,Highlight,GrayText), and recipes for elevation, materials, and gradients drop decorative layers. Token mapping alone is not enough where a state is shown only by a fill, opacity, or box shadow, because the browser repaints backgrounds asCanvasand removes shadows. A component sheet then adds its own forced-colors block:- checked, selected, active, and current indicators paint
HighlightwithHighlightTextand setforced-color-adjust: noneon that element only, so the pair stays legible (checkbox, radio, switch, tabs, tree, select and combobox options, calendar days, pagination); - disabled parts use
GrayTextwithopacity: 1instead of a faded token; - focus rings drawn with
box-shadowfall back to anoutlineinHighlight.
Do not add a forced-colors rule where the token mapping already yields a distinct system color (plain text, borders, surfaces). Forced-colors rendering is covered by
tests/e2e/forced-colors-visual.spec.ts.- checked, selected, active, and current indicators paint
Tokens
Tokens are authored as DTCG JSON and compiled to CSS custom properties, TypeScript types, and a JSON manifest. See design tokens, ADR 0005, ADR 0007, and ADR 0008. Public custom properties use --ghost-<role>-<part>-<state>. Components consume semantic tokens only. Brand themes are generated in Node (@ghostvue/themes/define) and applied with data-ghost-theme.