Theme System
Introduction
Movk Nuxt provides unified runtime theme management on top of Nuxt UI theming: colors, radius, fonts, icon sets and dark mode are all centrally controlled and can be interactively adjusted at runtime, with one-click export of CSS variables or configuration code.
Theme capabilities consist of three parts:
- Module defaults: Declare available options in
movk.themeinsidenuxt.config.ts. ThemePickercomponent: A user-facing visual control panel with export support.useThemecomposable: Read and write theme state in scripts, export CSS/config.
Enable & Disable
The theme module is enabled by default. When disabled, appConfig defaults, the theme plugin and the ThemePicker component are no longer injected:
export default defineNuxtConfig({
movk: {
theme: { enabled: false }
}
})
ThemePicker Component
ThemePicker provides visual switching for colors, radius, icon sets and dark mode, and can export the current theme.
useTheme
useTheme exposes reactive theme state and export methods, suitable for custom theme panels or reading theme values in business logic:
const {
color, neutral, radius, icon, mode,
exportCSS, exportConfig, resetTheme
} = useTheme()
// Read/switch theme
color.value = 'green'
mode.value = 'dark'
// Export current theme
const css = exportCSS()
const config = exportConfig()
Fonts
The font is build-time configuration and does not switch at runtime. One line is all it takes:
export default defineNuxtConfig({
movk: {
theme: {
font: 'Alibaba PuHuiTi'
}
}
})
At build time the module does three things, all served straight from SSR with no runtime JS involved:
- Writes the font stylesheet
<link>into<head> - Adds a
preconnectwithcrossoriginfor cross-origin fonts - Injects
@theme { --font-sans }, appending a fallback stack that covers the system Chinese fonts on macOS, Windows and Linux
Built-in fonts are hosted by movk-fonts. The value must match the font-family in their @font-face declarations character for character:
| Value | Stylesheet |
|---|---|
Alibaba PuHuiTi | https://cdn.mhaibaraai.cn/fonts/alibaba-puhuiti.css |
OPPO Sans | https://cdn.mhaibaraai.cn/fonts/oppo-sans.css |
For self-hosted fonts, use the { name, href } form to supply the stylesheet URL:
export default defineNuxtConfig({
movk: {
theme: {
font: { name: 'My Font', href: '/fonts/my-font.css' }
}
}
})
name raises no error — it silently falls back to the system font. CSS family matching is case-insensitive, but alibaba-puhuiti and Alibaba PuHuiTi are two different names. A font that is neither built in nor given an href triggers no request at all, and the module warns during development.The @theme injected by the module lands with @import "@movk/nuxt", so any @theme written after it overrides --font-sans. To control the font entirely from your own CSS, leave movk.theme.font unset:
@import "tailwindcss";
@import "@movk/nuxt";
@theme {
--font-sans: "OPPO Sans", sans-serif;
}
unicode-range, so the browser only downloads the shards holding characters the page actually uses. That is why these fonts must not be handed to @nuxt/fonts — it downloads every shard into the build output at build time, losing both on-demand loading and the CDN cache shared across projects. @movk/nuxt already sets ui.fonts: false by default, so your project never needs to declare it.Icon Sets
ThemePicker and useTheme switch between the Lucide, Phosphor and Tabler icon sets at runtime. Switching only rewrites appConfig.ui.icons — no rebuild required.
By default the module feeds the icons used by its own components, plus all three icon sets, into the @nuxt/icon build-time bundle, so nothing has to be fetched from the Iconify API at runtime. Each set needs its own @iconify-json package to be inlined:
npx nypm add -D @iconify-json/lucide @iconify-json/ph @iconify-json/tabler
lucide collection is missing, while ph and tabler — only needed after switching icon sets — are reported as a debug log.To opt out entirely (for example when your project manages the icon bundle itself), turn it off; movk component icons then load at runtime:
export default defineNuxtConfig({
movk: {
icon: { clientBundle: false }
}
})
Radius
--ui-radius keeps its three-level precedence: ThemePicker selection > movk.theme.radius > your project CSS. When omitted, the module does not inject the variable and the @nuxt/ui default (0.25rem) applies, so your project can override it in its own CSS:
@theme {
--ui-radius: 0.5rem;
}
Customizing Options
Color aliases, radius steps and neutral colors can all be overridden in movk.theme, serving as the value range for ThemePicker and useTheme:
export default defineNuxtConfig({
movk: {
theme: {
colors: ['primary', 'secondary', 'success', 'info', 'warning', 'error'],
radiuses: [0, 0.125, 0.25, 0.375, 0.5],
neutralColors: ['slate', 'gray', 'zinc', 'neutral', 'stone']
}
}
})
Export & Reuse
The CSS variables exported by ThemePicker and useTheme.exportCSS() can be written directly into your project's main.css, solidifying runtime debugging results as the default theme:
@import "tailwindcss";
@import "@movk/nuxt";
:root {
/* Paste variables exported by exportCSS() */
}
ThemePicker Reference
Introduction
MThemePicker is a visual theme configuration component that allows users to preview and customize the application theme in real time. It unifies adjustments to primary, neutral, border-radius, icon sets, and color mode, with support for exporting CSS variables and app.config.ts configuration code.
MThemePicker is part of the theme module. If movk.theme.enabled is set to false, this component will not be registered.Usage
MThemePicker is typically used as a global theme configuration entry, placed in the application header or toolbar:
useTheme to read reactive state:<script setup lang="ts">
const theme = useTheme()
</script>
<template>
<div class="gap-4 flex">
<MThemePicker />
<ClientOnly>
<div class="grid grid-cols-2 gap-2 text-sm">
<div>primary: <UBadge :label="theme.primary.value" variant="subtle" /></div>
<div>neutral: <UBadge :label="theme.neutral.value" variant="outline" /></div>
<div>radius: {{ theme.radius.value }}rem</div>
<div>icons: {{ theme.icon.value }}</div>
<div>mode: {{ theme.mode.value }}</div>
</div>
<template #fallback>
<div class="grid grid-cols-2 gap-2 text-sm text-muted">
<USkeleton class="h-5" />
<USkeleton class="h-5" />
<USkeleton class="h-5" />
<USkeleton class="h-5" />
<USkeleton class="h-5" />
</div>
</template>
</ClientOnly>
</div>
</template>
Features
Primary Color Configuration
- Primary: Choose the main brand color, supporting black or preset colors
- Neutral: Configure neutral tones affecting text and backgrounds
Style Configuration
- Radius: Adjust global border-radius size (0–5 levels)
- Icons: Switch icon sets (Lucide, Phosphor, Tabler)
Color Mode
Three color modes are supported:
light: Light modedark: Dark modesystem: Follow system preference
Export Configuration
Once configured, you can export:
main.css: CSS variable configurationapp.config.ts: Application configuration code
Theme
export default defineAppConfig({
ui: {
theme: {}
}
})
Changelog
useTheme Reference
Introduction
useTheme exposes the reactive theme state and export methods. It is the underlying logic for the ThemePicker component and can be used to build custom theme panels or read/write theme values in business logic.
Return Values
const {
// Color
color, primary, primaryColors, neutral, neutralColors,
blackAsPrimary, setBlackAsPrimary,
// Radius / Icon / Mode
radius, radiuses, icon, icons, mode, modes,
// Injection and state
style, hasCSSChanges, hasConfigChanges,
// Export
exportCSS, exportConfig, resetTheme
} = useTheme()
| Group | Members | Description |
|---|---|---|
| Color | color / primary / primaryColors | Primary color and available options |
| Color | neutral / neutralColors | Neutral color and available options |
| Color | blackAsPrimary / setBlackAsPrimary | Toggle for using black as the primary color |
| Radius | radius / radiuses | Current border radius and available presets |
| Icon | icon / icons | Current icon set and available options |
| Mode | mode / modes | Dark mode (light/dark/system) and available options |
| Injection | style | CSS variables to inject into the page |
| State | hasCSSChanges / hasConfigChanges | Whether there are changes relative to the defaults |