Stacks UI
Key Paths
- Core package:
storage/framework/core/ui/src/
- Components:
storage/framework/core/ui/src/components/
- UI config:
config/ui.ts (Headwind)
- STX config:
config/stx.ts
- STX engine:
node_modules/@stacksjs/stx/
- Crosswind:
node_modules/@cwcss/crosswind/
- Component types:
storage/framework/types/components.d.ts
Source Files
ui/src/
├── index.ts # Re-exports from @stacksjs/stx
├── components.ts # Component re-exports
└── components/
├── autocomplete.ts # Combobox, ComboboxInput, ComboboxOption, ComboboxOptions
├── disclosure.ts # Disclosure, DisclosureButton, DisclosurePanel
├── menu.ts # Menu, MenuButton, MenuItem, MenuItems
├── modal.ts # Dialog, DialogDescription, DialogPanel, DialogTitle
├── popover.ts # Popover, PopoverButton, PopoverPanel
├── radio-group.ts # RadioGroup, RadioGroupLabel, RadioGroupOption
├── select.ts # Combobox-based select
├── tabs.ts # Tab, TabGroup, TabList, TabPanel, TabPanels
├── toggle.ts # Switch
└── transition.ts # TransitionChild, TransitionRoot
Headless Components
import { Combobox, ComboboxInput, ComboboxOption, ComboboxOptions } from '@stacksjs/ui'
import { Dialog, DialogDescription, DialogPanel, DialogTitle } from '@stacksjs/ui'
import { Menu, MenuButton, MenuItem, MenuItems } from '@stacksjs/ui'
import { Tab, TabGroup, TabList, TabPanel, TabPanels } from '@stacksjs/ui'
import { Switch } from '@stacksjs/ui'
import { TransitionChild, TransitionRoot } from '@stacksjs/ui'
Craft Native Components
Built-in components with native HTML fallbacks:
| Component |
Fallback |
Key Props |
craft-button |
<button> |
variant (primary/secondary/outline) |
craft-text-input |
<input> |
placeholder, value, type, disabled |
craft-textarea |
<textarea> |
placeholder, value, rows |
craft-checkbox |
<input type="checkbox"> |
checked, disabled, label |
craft-select |
<select> |
value, options, placeholder |
craft-modal |
<dialog> |
open, title, closable, size |
craft-tabs |
<div> |
activeTab, tabs |
craft-table |
<table> |
columns, rows, sortable, selectable |
craft-card |
<div> |
title, subtitle, variant |
craft-alert |
<div> |
variant, title, dismissible |
craft-toast |
<div> |
variant, duration, position |
craft-tooltip |
<span> |
content, position |
craft-pagination |
<nav> |
total, page, pageSize |
craft-code-editor |
<textarea> |
value, language, theme, lineNumbers |
craft-date-picker |
<input type="date"> |
value, min, max, format |
craft-color-picker |
<input type="color"> |
value, format |
craft-badge |
<span> |
variant, size |
craft-avatar |
<div> |
src, alt, size, fallback |
craft-progress |
<div> |
value, max, variant |
craft-spinner |
<div> |
size |
craft-accordion |
<details> |
open, title |
craft-divider |
<hr> |
orientation, variant |
craft-breadcrumb |
<nav> |
items, separator |
craft-menu |
<nav> |
items, orientation |
craft-tree |
<div> |
nodes, expandable, selectable |
craft-list |
<ul> |
items, selectable |
craft-slider |
<input type="range"> |
value, min, max, step |
craft-radio |
<input type="radio"> |
checked, name, value, label |
craft-file-browser |
<div> |
path, showHidden, selectable |
Reactivity System
import { ref, namedRef, computed, watch } from '@stacksjs/stx'
const count = ref(0)
count.value = 5
const doubled = computed(() => count.value * 2)
const stop = watch(
() => count.value,
(newVal, oldVal) => console.log(`${oldVal} → ${newVal}`),
{ immediate: false }
)
stop() // cleanup
Types
interface Ref<T> { value: T | null, readonly current: T | null }
interface ComponentInstance {
id: string, element: Element | null
mountHooks: LifecycleHook[], destroyHooks: CleanupFn[], updateHooks: LifecycleHook[]
refs: Map<string, Ref<any>>, watchers: Array<{ stop: () => void }>
isMounted: boolean
}
Lifecycle Hooks
import { onMount, onDestroy, onUpdate } from '@stacksjs/stx'
// Aliases: onMounted, onUnmounted, onUpdated
onMount(() => {
console.log('mounted')
return () => console.log('cleanup') // optional
})
onDestroy(() => console.log('destroyed'))
onUpdate(() => console.log('updated'))
Dependency Injection
import { provide, inject, createInjectionKey, withInjectionScope } from '@stacksjs/stx'
const ThemeKey = createInjectionKey<string>('theme')
provide(ThemeKey, 'dark')
const theme = inject(ThemeKey) // 'dark'
const theme = inject(ThemeKey, 'light') // with default
Browser Composables
import {
useLocalStorage, useSessionStorage, useEventListener,
useClickOutside, useWindowSize, useMediaQuery,
usePrefersDark, useOnline
} from '@stacksjs/stx'
const { value, remove } = useLocalStorage('key', defaultValue)
const { width, height } = useWindowSize()
const isDark = usePrefersDark()
const isOnline = useOnline()
const cleanup = useClickOutside(elementRef, handler)
Headwind Configuration (config/ui.ts)
export default {
content: [
'./resources/**/*.{html,js,ts,jsx,tsx,stx}',
'./storage/framework/defaults/**/*.{html,js,ts,jsx,tsx,stx}',
'./storage/framework/views/**/*.{html,js,ts,jsx,tsx,stx}',
],
output: './storage/framework/assets/headwind.css',
minify: false,
} satisfies HeadwindOptions
STX Configuration (config/stx.ts)
export default {
componentsDir: 'resources/components',
layoutsDir: 'resources/layouts',
partialsDir: 'resources/partials',
} satisfies StxOptions
Full StxConfig
interface StxConfig {
enabled: boolean, debug: boolean
templatesDir?, componentsDir, partialsDir, layoutsDir?, defaultLayout?
ssr?: boolean, cache?: boolean, cachePath: string
i18n?: Partial<I18nConfig>
webComponents?: Partial<WebComponentConfig>
streaming?: Partial<StreamingConfig>
hydration?: Partial<HydrationConfig>
a11y?: Partial<A11yConfig>
seo?: Partial<SeoFeatureConfig>
animation?: Partial<AnimationConfig>
markdown?: Partial<MarkdownConfig>
pwa?: Partial<PwaConfig>
strict?: boolean | StrictModeConfig
}
Accessibility
import { checkA11y, autoFixA11y, scanA11yIssues } from '@stacksjs/stx'
const violations = await checkA11y(html, filePath)
const result = autoFixA11y(html, config)
const issues = await scanA11yIssues('./resources', { recursive: true })
interface A11yConfig {
enabled: boolean, addSrOnlyStyles: boolean
level: 'AA' | 'AAA', ignoreChecks?: string[], autoFix: boolean
}
Crosswind CSS Framework
Utility-first CSS (like Tailwind), built into Stacks:
import { buildCrosswindCSS, extractClassNames, generateCrosswindCSS } from '@stacksjs/stx'
const css = await buildCrosswindCSS(cwd)
const classNames = extractClassNames(htmlContent)
Features: theme config, 40+ variant modifiers, custom rules, shortcuts, attributify mode, bracket syntax, presets.
Gotchas
- @stacksjs/ui re-exports from @stacksjs/stx — the UI package is thin, the engine is in STX
- Craft components use native fallbacks —
preferNative: true renders plain HTML
- Refs are not Vue refs — similar API but custom reactive implementation
- Lifecycle hooks require component context — must be called within
setupComponent()
- Headwind is not Tailwind — Stacks' own CSS utility implementation
- Crosswind is the utility engine — handles class extraction, CSS generation, purging
- STX is the templating engine — handles
.stx files, SSR, streaming, hydration
- Two CSS systems coexist — Headwind (config) and Crosswind (engine)
- 150+ globally registered Vue components — no imports needed
1---2name: stacks-ui-43description: Use when working with UI in a Stacks application — components, composables, reactivity (refs/watch/computed), Craft native components, Headwind CSS, Crosswind utility framework, accessibility, or the STX templating engine. Covers @stacksjs/ui, @stacksjs/stx, and related UI tooling.4license: MIT5---67# Stacks UI89## Key Paths10- Core package: `storage/framework/core/ui/src/`11- Components: `storage/framework/core/ui/src/components/`12- UI config: `config/ui.ts` (Headwind)13- STX config: `config/stx.ts`14- STX engine: `node_modules/@stacksjs/stx/`15- Crosswind: `node_modules/@cwcss/crosswind/`16- Component types: `storage/framework/types/components.d.ts`1718## Source Files19```20ui/src/21├── index.ts # Re-exports from @stacksjs/stx22├── components.ts # Component re-exports23└── components/24 ├── autocomplete.ts # Combobox, ComboboxInput, ComboboxOption, ComboboxOptions25 ├── disclosure.ts # Disclosure, DisclosureButton, DisclosurePanel26 ├── menu.ts # Menu, MenuButton, MenuItem, MenuItems27 ├── modal.ts # Dialog, DialogDescription, DialogPanel, DialogTitle28 ├── popover.ts # Popover, PopoverButton, PopoverPanel29 ├── radio-group.ts # RadioGroup, RadioGroupLabel, RadioGroupOption30 ├── select.ts # Combobox-based select31 ├── tabs.ts # Tab, TabGroup, TabList, TabPanel, TabPanels32 ├── toggle.ts # Switch33 └── transition.ts # TransitionChild, TransitionRoot34```3536## Headless Components3738```typescript39import { Combobox, ComboboxInput, ComboboxOption, ComboboxOptions } from '@stacksjs/ui'40import { Dialog, DialogDescription, DialogPanel, DialogTitle } from '@stacksjs/ui'41import { Menu, MenuButton, MenuItem, MenuItems } from '@stacksjs/ui'42import { Tab, TabGroup, TabList, TabPanel, TabPanels } from '@stacksjs/ui'43import { Switch } from '@stacksjs/ui'44import { TransitionChild, TransitionRoot } from '@stacksjs/ui'45```4647## Craft Native Components4849Built-in components with native HTML fallbacks:5051| Component | Fallback | Key Props |52|-----------|----------|-----------|53| `craft-button` | `<button>` | variant (primary/secondary/outline) |54| `craft-text-input` | `<input>` | placeholder, value, type, disabled |55| `craft-textarea` | `<textarea>` | placeholder, value, rows |56| `craft-checkbox` | `<input type="checkbox">` | checked, disabled, label |57| `craft-select` | `<select>` | value, options, placeholder |58| `craft-modal` | `<dialog>` | open, title, closable, size |59| `craft-tabs` | `<div>` | activeTab, tabs |60| `craft-table` | `<table>` | columns, rows, sortable, selectable |61| `craft-card` | `<div>` | title, subtitle, variant |62| `craft-alert` | `<div>` | variant, title, dismissible |63| `craft-toast` | `<div>` | variant, duration, position |64| `craft-tooltip` | `<span>` | content, position |65| `craft-pagination` | `<nav>` | total, page, pageSize |66| `craft-code-editor` | `<textarea>` | value, language, theme, lineNumbers |67| `craft-date-picker` | `<input type="date">` | value, min, max, format |68| `craft-color-picker` | `<input type="color">` | value, format |69| `craft-badge` | `<span>` | variant, size |70| `craft-avatar` | `<div>` | src, alt, size, fallback |71| `craft-progress` | `<div>` | value, max, variant |72| `craft-spinner` | `<div>` | size |73| `craft-accordion` | `<details>` | open, title |74| `craft-divider` | `<hr>` | orientation, variant |75| `craft-breadcrumb` | `<nav>` | items, separator |76| `craft-menu` | `<nav>` | items, orientation |77| `craft-tree` | `<div>` | nodes, expandable, selectable |78| `craft-list` | `<ul>` | items, selectable |79| `craft-slider` | `<input type="range">` | value, min, max, step |80| `craft-radio` | `<input type="radio">` | checked, name, value, label |81| `craft-file-browser` | `<div>` | path, showHidden, selectable |8283## Reactivity System8485```typescript86import { ref, namedRef, computed, watch } from '@stacksjs/stx'8788const count = ref(0)89count.value = 59091const doubled = computed(() => count.value * 2)9293const stop = watch(94 () => count.value,95 (newVal, oldVal) => console.log(`${oldVal} → ${newVal}`),96 { immediate: false }97)98stop() // cleanup99```100101### Types102```typescript103interface Ref<T> { value: T | null, readonly current: T | null }104105interface ComponentInstance {106 id: string, element: Element | null107 mountHooks: LifecycleHook[], destroyHooks: CleanupFn[], updateHooks: LifecycleHook[]108 refs: Map<string, Ref<any>>, watchers: Array<{ stop: () => void }>109 isMounted: boolean110}111```112113## Lifecycle Hooks114115```typescript116import { onMount, onDestroy, onUpdate } from '@stacksjs/stx'117// Aliases: onMounted, onUnmounted, onUpdated118119onMount(() => {120 console.log('mounted')121 return () => console.log('cleanup') // optional122})123onDestroy(() => console.log('destroyed'))124onUpdate(() => console.log('updated'))125```126127## Dependency Injection128129```typescript130import { provide, inject, createInjectionKey, withInjectionScope } from '@stacksjs/stx'131132const ThemeKey = createInjectionKey<string>('theme')133provide(ThemeKey, 'dark')134const theme = inject(ThemeKey) // 'dark'135const theme = inject(ThemeKey, 'light') // with default136```137138## Browser Composables139140```typescript141import {142 useLocalStorage, useSessionStorage, useEventListener,143 useClickOutside, useWindowSize, useMediaQuery,144 usePrefersDark, useOnline145} from '@stacksjs/stx'146147const { value, remove } = useLocalStorage('key', defaultValue)148const { width, height } = useWindowSize()149const isDark = usePrefersDark()150const isOnline = useOnline()151const cleanup = useClickOutside(elementRef, handler)152```153154## Headwind Configuration (config/ui.ts)155156```typescript157export default {158 content: [159 './resources/**/*.{html,js,ts,jsx,tsx,stx}',160 './storage/framework/defaults/**/*.{html,js,ts,jsx,tsx,stx}',161 './storage/framework/views/**/*.{html,js,ts,jsx,tsx,stx}',162 ],163 output: './storage/framework/assets/headwind.css',164 minify: false,165} satisfies HeadwindOptions166```167168## STX Configuration (config/stx.ts)169170```typescript171export default {172 componentsDir: 'resources/components',173 layoutsDir: 'resources/layouts',174 partialsDir: 'resources/partials',175} satisfies StxOptions176```177178### Full StxConfig179```typescript180interface StxConfig {181 enabled: boolean, debug: boolean182 templatesDir?, componentsDir, partialsDir, layoutsDir?, defaultLayout?183 ssr?: boolean, cache?: boolean, cachePath: string184 i18n?: Partial<I18nConfig>185 webComponents?: Partial<WebComponentConfig>186 streaming?: Partial<StreamingConfig>187 hydration?: Partial<HydrationConfig>188 a11y?: Partial<A11yConfig>189 seo?: Partial<SeoFeatureConfig>190 animation?: Partial<AnimationConfig>191 markdown?: Partial<MarkdownConfig>192 pwa?: Partial<PwaConfig>193 strict?: boolean | StrictModeConfig194}195```196197## Accessibility198199```typescript200import { checkA11y, autoFixA11y, scanA11yIssues } from '@stacksjs/stx'201202const violations = await checkA11y(html, filePath)203const result = autoFixA11y(html, config)204const issues = await scanA11yIssues('./resources', { recursive: true })205```206207```typescript208interface A11yConfig {209 enabled: boolean, addSrOnlyStyles: boolean210 level: 'AA' | 'AAA', ignoreChecks?: string[], autoFix: boolean211}212```213214## Crosswind CSS Framework215216Utility-first CSS (like Tailwind), built into Stacks:217218```typescript219import { buildCrosswindCSS, extractClassNames, generateCrosswindCSS } from '@stacksjs/stx'220221const css = await buildCrosswindCSS(cwd)222const classNames = extractClassNames(htmlContent)223```224225Features: theme config, 40+ variant modifiers, custom rules, shortcuts, attributify mode, bracket syntax, presets.226227## Gotchas228- **@stacksjs/ui re-exports from @stacksjs/stx** — the UI package is thin, the engine is in STX229- **Craft components use native fallbacks** — `preferNative: true` renders plain HTML230- **Refs are not Vue refs** — similar API but custom reactive implementation231- **Lifecycle hooks require component context** — must be called within `setupComponent()`232- **Headwind is not Tailwind** — Stacks' own CSS utility implementation233- **Crosswind is the utility engine** — handles class extraction, CSS generation, purging234- **STX is the templating engine** — handles `.stx` files, SSR, streaming, hydration235- **Two CSS systems coexist** — Headwind (config) and Crosswind (engine)236- **150+ globally registered Vue components** — no imports needed