Class Theme<TValues>

Creates a theme class for grouping variables and applying them to elements.

Type Parameters

Hierarchy

Constructors

Properties

_dependants: Base[] = []
_lastPropertiesSet: string[] = []
_listeners: Record<string, (() => void)[]> = ...
css: Record<string, string> = {}
els: HTMLElement[] = []
options: {
    escapeChar: string;
} = ...

Type declaration

  • escapeChar: string
ready: boolean = false
value: TValues = ...

Methods

  • Parameters

    • res: Record<string, string>
    • key: string
    • sep: string
    • value: ControlVar<any, any> | InterpolatedVars<any>
    • __namedParameters: {
          remove?: boolean;
      } = {}
      • Optional remove?: boolean

    Returns void

  • Parameters

    • dep: any

    Returns void

  • Attach to an element and automatically set and update the theme's properties on it.

    If no element is passed, attaches to document.documentElement.

    Parameters

    • el: HTMLElement = document.documentElement

    Returns void

  • Parameters

    • el: HTMLElement = document.documentElement

    Returns void

  • Parameters

    • __namedParameters: {
          recompute?: boolean;
      } = {}
      • Optional recompute?: boolean

    Returns void

  • Parameters

    • type: "change"
    • cb: (() => void)
        • (): void
        • Returns void

    Returns void

  • Parameters

    • type: "change"
    • cb: (() => void)
        • (): void
        • Returns void

    Returns void

  • The theme can force dependencies to recompute.

    This should not be needed unless you want to recompute based of some external state.

    Please file a bug report otherwise.

    Parameters

    • force: boolean = true

    Returns void

  • Parameters

    • key: string

    Returns void

  • Parameters

    • value: Partial<{
          escapeChar: string;
      }> = {}

    Returns void

  • Write theme variables to get autocomplete while developing. Only works from node.

    // src/bin/generateThemeVars.ts

    import { theme } from "../theme.js" // import theme instance
    // write relative to file
    theme.write(import.meta.url, "../assets/variables.scss")

    In package.json:

    "scripts": {
    "gen:theme": "pnpm ts-node src/bin/generateThemeVars.ts"
    }

    Parameters

    • metaUrl: string
    • filepath: string

    Returns Promise<void>

  • Set css variables on an element.

    Careful that the css properties are prefixed with --, otherwise they might conflict with other style properties.

    Can be passed a list of already set properties to remove. Returns a list of properties that were set.

    Parameters

    • el: HTMLElement
    • css: Record<string, string>
    • lastPropertiesSet: string[] = []

    Returns string[]

Generated using TypeDoc