Skip to main content

Theme

The theme system provides a structured way to define colors, typography, spacing, and other visual properties used by ThunderID UI components. Use createTheme() to build a theme from scratch or apply partial overrides on top of the defaults.

createTheme(config?)

Create a Theme object by merging the provided ThemeConfig with the default theme. Returns the merged theme plus computed CSS variable references and raw CSS custom property declarations.

import { createTheme } from '@thunderid/javascript'

const theme = createTheme({
colors: {
primary: {
main: '#6200ea',
contrastText: '#ffffff',
},
},
})

// Apply CSS variables to the document root
Object.entries(theme.cssVariables).forEach(([key, value]) => {
document.documentElement.style.setProperty(key, value)
})

Parameters

ParameterTypeRequiredDescription
configRecursivePartial<ThemeConfig>Partial theme configuration. Deep-merged with DEFAULT_THEME

Response: Theme

Theme extends ThemeConfig with two additional properties:

PropertyTypeDescription
varsThemeVarsCSS variable references (e.g., theme.vars.colors.primary.main'var(--thunderid-colors-primary-main)')
cssVariablesRecord<string, string>Flat map of CSS custom property declarations ready to apply to :root

DEFAULT_THEME

The default theme object. Import it to inspect the base values or extend them:

import { DEFAULT_THEME } from '@thunderid/javascript'

console.log(DEFAULT_THEME.colors.primary.main)

ThemeConfig

PropertyTypeDescription
colorsThemeColorsColor palette
typographyThemeTypographyFont families and sizes
borderRadius{ large, medium, small }Border radius scale
spacing{ unit }Base spacing unit in pixels
shadows{ large, medium, small }Box shadow definitions
componentsThemeComponentsPer-component style overrides
cssVarPrefixstringCustom prefix for CSS variable names. Defaults to 'thunderid'
direction'ltr' | 'rtl'Text direction
imagesThemeImagesLogo, favicon, and other image URLs

ThemeColors

PropertyTypeDescription
primaryColorVariantsPrimary brand color (main, light, dark, contrastText)
secondaryColorVariantsSecondary brand color
backgroundobjectPage and surface background colors
textobjectForeground text colors (primary, secondary, disabled)
dividerstringDivider and border color
actionobjectState colors for hover, focus, selected, disabled
alertsobjectSemantic colors for info, success, warning, and error states

ThemeMode

ValueDescription
'light'Force light mode
'dark'Force dark mode
'system'Follow the OS preference (prefers-color-scheme)
'class'Controlled by CSS class (see ThemeDetection)

ThemeDetection

Used when mode is 'class' to specify which CSS class activates each mode:

const theme = createTheme({
// ...
})

// Apply 'dark-mode' CSS class to <html> to activate dark theme
const detection: ThemeDetection = {
darkClass: 'dark-mode',
lightClass: 'light-mode',
}
PropertyTypeDescription
darkClassstringCSS class name that triggers dark mode
lightClassstringCSS class name that triggers light mode
ThunderID LogoThunderID Logo

Product

DocsAPIsSDKs
© WSO2 LLC. All rights reserved.Privacy PolicyCookie Policy