Theming
/ API Reference
Theming
/ API Reference

createVariable

A small utility function that creates a CSS variable and its reference.
Primarily useful when creating lower-level abstractions like createTheme or createThemes.

The Gist

import { createVariable } from '@weser/theming'

const [reference, declaration] = createVariable('brand-color', 'red')

// => 'var(--brand-color)'
console.log(reference)

// => '--brand-color:red'
console.log(declaration)

Parameters

ParameterTypeDescription
namestringThe CSS variable name
valuestringThe value assigned to the variable

Returns

([string, string]) A tuple where the first element is a string referencing the CSS variable and the second element is a string referencing the variable declaration to be inlined somewhere in your application.

On this page