create-vue-docs-ui
Version:
Scaffolding tool for Vue Docs UI projects - Create beautiful documentation websites with one command
319 lines (238 loc) • 6.37 kB
Markdown
Vue Docs UI comes with a powerful theming system that supports light, dark, and custom themes.
Configure your theme in `site.yaml`:
```yaml
theme:
defaultMode: "auto"
allowToggle: true
```
- **light**: Force light theme
- **dark**: Force dark theme
- **auto**: Follow system preference (default)
## Color System
### Default Color Palette
```yaml
theme:
colors:
# Brand Colors
primary: "#3b82f6" # Primary brand color
secondary: "#64748b" # Secondary color
accent: "#06b6d4" # Accent color
# Background Colors
background: "#ffffff" # Main background
surface: "#f8fafc" # Cards, panels
# Text Colors
text: "#1e293b" # Primary text
textSecondary: "#64748b" # Secondary text
# UI Colors
border: "#e2e8f0" # Borders, dividers
success: "#10b981" # Success states
warning: "#f59e0b" # Warning states
error: "#ef4444" # Error states
```
### Dark Theme Colors
Dark theme automatically adjusts colors, but you can customize them:
```css
.dark {
--primary-color:
--bg-color:
--surface-color:
--text-color:
--text-secondary-color:
--border-color:
}
```
```yaml
theme:
fonts:
primary: "Inter, -apple-system, BlinkMacSystemFont, sans-serif"
mono: "JetBrains Mono, Consolas, Monaco, monospace"
```
Load external fonts in your HTML:
```html
<link rel="preconnect" href="https://fonts.googleapis.com">
<link href="https://fonts.googleapis.com/css2?family=Roboto:wght@300;400;500;700&display=swap" rel="stylesheet">
```
Then reference them in your theme:
```yaml
theme:
fonts:
primary: "Roboto, sans-serif"
```
```yaml
theme:
layout:
headerHeight: "60px"
sidebarWidth: "280px"
tocWidth: "240px"
contentMaxWidth: "1200px"
```
```css
/* Customize breakpoints */
:root {
--mobile-breakpoint: 768px;
--tablet-breakpoint: 1024px;
--desktop-breakpoint: 1200px;
}
```
Vue Docs UI uses CSS custom properties for easy theming:
```css
:root {
/* Colors */
--primary-color:
--secondary-color:
--accent-color:
/* Background */
--bg-color:
--bg-color-secondary:
--bg-color-hover: rgba(59, 130, 246, 0.05);
/* Text */
--text-color:
--text-color-light:
/* Border */
--border-color:
--border-color-light:
/* Layout */
--header-height: 60px;
--sidebar-width: 280px;
--toc-width: 240px;
/* Typography */
--font-family: 'Inter', sans-serif;
--font-family-mono: 'JetBrains Mono', monospace;
}
```
```css
:root {
/* Header */
--header-bg: rgba(255, 255, 255, 0.95);
--header-border: var(--border-color);
/* Sidebar */
--sidebar-bg: var(--bg-color);
--sidebar-border: var(--border-color);
/* Code blocks */
--code-bg:
--code-color:
--code-block-bg:
}
```
Create a custom theme file:
```css
/* themes/custom.css */
.theme-custom {
--primary-color:
--secondary-color:
--accent-color:
--bg-color:
--bg-color-secondary:
--text-color:
--text-color-light:
}
```
```typescript
// Apply theme programmatically
document.documentElement.className = 'theme-custom'
// Or add theme class based on user preference
const applyTheme = (themeName: string) => {
document.documentElement.className = `theme-${themeName}`
}
```
```css
:root {
--transition-fast: 150ms ease;
--transition-normal: 200ms ease;
--transition-slow: 300ms ease;
}
/* Apply to components */
.nav-link {
transition: color var(--transition-fast);
}
```
```css
/* Custom hover effects */
.chapter-card {
transition: transform var(--transition-normal);
}
.chapter-card:hover {
transform: translateY(-4px);
}
```
```vue
<template>
<button @click="toggleTheme" class="theme-toggle">
<SunIcon v-if="isDark" />
<MoonIcon v-else />
</button>
</template>
<script setup>
import { ref, onMounted } from 'vue'
const isDark = ref(false)
const toggleTheme = () => {
isDark.value = !isDark.value
document.documentElement.classList.toggle('dark', isDark.value)
localStorage.setItem('theme', isDark.value ? 'dark' : 'light')
}
onMounted(() => {
const saved = localStorage.getItem('theme')
const prefersDark = window.matchMedia('(prefers-color-scheme: dark)').matches
isDark.value = saved ? saved === 'dark' : prefersDark
document.documentElement.classList.toggle('dark', isDark.value)
})
</script>
```
```yaml
colors:
primary: "#3b82f6"
success: "#10b981"
warning: "#f59e0b"
error: "#ef4444"
```
Ensure sufficient contrast ratios:
- Normal text: 4.5:1 minimum
- Large text: 3:1 minimum
- UI components: 3:1 minimum
Always test your customizations in both light and dark modes.
Prefer CSS variables over hardcoded values for maintainability:
```css
/* Good */
color: var(--text-color);
/* Avoid */
color:
```
Design for light theme first, then enhance for dark:
```css
/* Base styles */
.component {
background: var(--bg-color);
color: var(--text-color);
}
/* Dark mode enhancements */
.dark .component {
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.3);
}
```