Skip to content

Get Theme

The getTheme action retrieves the current theme information from the host IDE, including whether it’s a dark or light theme and a set of semantic colors you can use to style your webview UI to match the IDE.

import { getTheme } from '@unextension/bridge'

Returns the current IDE color scheme and theme colors.

const theme = await getTheme()
console.log(theme.colorScheme) // 'dark' or 'light'
console.log(theme.colors.background) // '#1e1e1e'

None.

Promise<ThemeResult>


FieldTypeDescription
colorScheme'dark' | 'light'Whether the IDE is using a dark or light theme
colorsThemeColorsSemantic color values from the IDE theme

All color fields are optional strings in CSS color format (typically hex like #1e1e1e).

FieldTypeDescription
backgroundstringEditor/panel background color
foregroundstringDefault text color
inputBackgroundstringInput field background color
inputForegroundstringInput field text color
borderstringBorder color
selectionBackgroundstringText selection background color
selectionForegroundstringText selection foreground color
linkstringLink/hyperlink color
buttonBackgroundstringButton background color
buttonForegroundstringButton text color

import { getTheme } from '@unextension/bridge'
const theme = await getTheme()
if (theme.colorScheme === 'dark') {
document.body.classList.add('dark-mode')
} else {
document.body.classList.add('light-mode')
}
import { getTheme } from '@unextension/bridge'
const theme = await getTheme()
const root = document.documentElement
if (theme.colors.background) root.style.setProperty('--bg', theme.colors.background)
if (theme.colors.foreground) root.style.setProperty('--fg', theme.colors.foreground)
if (theme.colors.border) root.style.setProperty('--border', theme.colors.border)
import { getTheme } from '@unextension/bridge'
const { colors } = await getTheme()
const button = document.querySelector('button')
if (button && colors.buttonBackground) {
button.style.backgroundColor = colors.buttonBackground
button.style.color = colors.buttonForeground ?? '#ffffff'
}

All types are exported from @unextension/bridge:

import type { ThemeResult, ThemeColors } from '@unextension/bridge'
interface ThemeResult {
colorScheme: 'dark' | 'light'
colors: ThemeColors
}
interface ThemeColors {
background?: string
foreground?: string
inputBackground?: string
inputForeground?: string
border?: string
selectionBackground?: string
selectionForeground?: string
link?: string
buttonBackground?: string
buttonForeground?: string
}