Skip to content

Theming

Vueland UI has a CSS-variable-based theming system. You define tokens in the plugin config — the library applies them to :root on startup and whenever you switch the active theme.

Defining themes

Pass a themes object to createVuelandUI. Each key is a theme name; the value is a ThemeDefinition object:

ts
import * as components from '@vueland/ui/components'
import { createVuelandUI } from '@vueland/ui'
import '@vueland/ui/styles.css'
import '@vueland/ui/css/lib.css'

export const vueland = createVuelandUI({
  components,
  theme: 'light',       // theme active on startup
  themes: {
    light: {
      primary: '#4f6ef7',
      onPrimary: '#ffffff',
      background: '#f5f7fa',
      surface: '#ffffff',
      text: '#1a1a2e',
      error: '#e53935',
    },
    dark: {
      primary: '#7b93ff',
      onPrimary: '#ffffff',
      background: '#121212',
      surface: '#1e1e2e',
      text: '#e0e0e0',
      error: '#ef5350',
    },
  },
})

Switching themes

Use applyTheme on the plugin instance:

ts
import { vueland } from './plugins/vueland'

vueland.applyTheme('dark')

Or via useCore inside a component:

ts
import { useCore } from '@vueland/ui/composables'

const core = useCore()

function toggleTheme() {
  core?.applyTheme(core.theme === 'light' ? 'dark' : 'light')
}

ThemeDefinition tokens

TokenDescription
primaryBrand primary color
onPrimaryText color on top of primary
secondarySecondary color
success / error / warning / infoSemantic colors
backgroundPage background
surfaceCard and panel background
surfaceVariantAlternative surface background
textMain text color
textSecondarySecondary text
placeholderPlaceholder color
borderBorder color
radiusDefault border radius
disabled / disabledBgDisabled state colors
readonly / readonlyBgRead-only state colors
focusFocus ring color
error / errorBgError color and its background
hover / overlayInteractive overlay colors

All tokens are optional — override only the ones you need.

Custom tokens

You can add any custom key — it will also become a CSS variable:

ts
themes: {
  light: {
    primary: '#4f6ef7',
    'sidebar-bg': '#f0f2f5',      // → var(--c-sidebar-bg)
    'header-height': '64px',      // → var(--c-header-height)
  },
}

CSS variables

Every token is converted to a CSS variable in the format --c-{token} and set on :root:

css
:root {
  --c-primary: #4f6ef7;
  --c-background: #f5f7fa;
  --c-text: #1a1a2e;
}

Use them in your own styles to automatically adapt to theme changes:

scss
.my-card {
  background: var(--c-surface);
  color: var(--c-text);
  border-color: var(--c-border);
}