theming / Interface

ThemeBuilder

Generic types:Config

Responsible for generating a group of theme tokens based on a configuration.

Notes

The generic type parameter declares the acceptable configuration type.

This package contains a built-in implementation: TokensBuilder.

Methods

build()

Generate a group of theme tokens based on a configuration.

Presentation
build(context: ThemeBuilderContext<Config>): ThemeTokens;
Parameters
NameTypeDescription
context
ThemeBuilderContext<Config>
Returns

Example usage

export interface MyThemeConfig {
  primaryColor: string;
}
export class MyThemeBuilder implements ThemeBuilder<MyThemeConfig> {
  build(context: ThemeBuilderContext<MyThemeConfig>): ThemeTokens {
    return {
      [`${context.name}-primary-color`]: context.config.primaryColor,
    };
  }
}