Themes and Dark Mode
Using Official Themes
@univerjs/themes exports defaultTheme (also available as blueTheme), darkBlueTheme, greenTheme, orangeTheme, purpleTheme, redTheme, and yellowTheme.
defaultTheme.Installing Theme Plugins
Preset Mode
In preset mode, import themes from @univerjs/presets:
// import { defaultTheme } from "@univerjs/presets";import { yellowTheme } from '@univerjs/presets'const { univer } = createUniver({ theme: yellowTheme, // theme: defaultTheme,})Plugin Mode
In plugin mode, themes are provided by @univerjs/themes. Install that package first.
pnpm add @univerjs/themesnpm install @univerjs/themesyarn add @univerjs/themesbun add @univerjs/themesimport { yellowTheme } from '@univerjs/themes'// import { defaultTheme } from "@univerjs/themes";const univer = new Univer({ theme: yellowTheme, // theme: defaultTheme,})Customizing Themes
A theme is an object that conforms to the Theme interface. Start from defaultTheme, override the fields that need to change, and pass the result to Univer. The theme type reference documents how the default variables are defined.
import type { Theme } from '@univerjs/themes';import { defaultTheme } from '@univerjs/themes';export const customTheme: Theme = { ...defaultTheme, primary: { ...defaultTheme.primary, 50: '#F5F3FF', 100: '#EDE9FE', 200: '#DDD6FE', 300: '#C4B5FD', 400: '#A78BFA', 500: '#8B5CF6', 600: '#7C3AED', 700: '#6D28D9', 800: '#5B21B6', 900: '#4C1D95', },};// Import your custom theme hereimport { customTheme } from './custom-theme'const univer = new Univer({ theme: customTheme,})Theme Customizer
The theme customizer is a standalone tool for editing Univer theme tokens, previewing light and dark modes, and copying the resulting Theme JSON.
Dark Mode
Set darkMode to true to start Univer in dark mode.
new Univer({ darkMode: true,})Facade API
The Facade API can also switch dark mode at runtime.
import { darkBlueTheme } from '@univerjs/themes'univerAPI.setTheme(darkBlueTheme)univerAPI.toggleDarkMode(true)const currentTheme = univerAPI.getCurrentTheme()console.log(univerAPI.isDarkMode(), currentTheme)univerAPI.toggleDarkMode(false)How is this guide?