Accoutrement 2.1.1

Changes » CSS Variables

$change-var-prefix (string)

scss
$change-var-prefix: 'change-' !default;

Since CSS variables are often defined in a global space, it can be useful to prefix different variable types. Accoutrement maps help solve that problem in Sass, so we wanted to carry that over into our CSS variable support. Set a prefix for all change-tokens, and we’ll apply it when setting or calling css variables based on your change maps. Set to null or '' (empty string) for no prefix.

Since 2.0.0:

  • NEW: Initial release

Example

scss
$changes: ('my-change': pink);
$change-var-prefix: 'prefix_';
:root { @include change--('my-change') }
css compiled
:root {
  --prefix_my-change: pink;
}

Used By

@mixin changes--()

@mixin change--()

@function var-change()

@mixin changes--()

Convert any change-map into CSS variables, using the global $change-var-prefix.

  • Change names that start with _ or - are considered “private” and will not be output as variables
  • Changes that contain a simple alias with no adjustments will be output with a var() value, keeping the alias relationship intact

Since 2.0.0:

  • NEW: Initial release

Parameters & Output

$source: $changes (map)

Optionally use a custom map of changes to set as css variables

{CSS output} (code block)

Custom properties for all public changes in the map

Example

scss
$changes: (
  '_brand': hsl(120, 50%, 50%),
  'text': '#_brand' ('shade': 50%),
  'border': '#text',
);
:root {
  @include changes--;
}
css compiled
:root {
  --change-text: #206020;
  --change-border: var(--change-text, #206020);
}

Requires

@mixin tokens--()

@mixin change--()

Set a single custom property based on a map-change, with optional alias and fallback

Since 2.0.0:

  • NEW: Initial release

Parameters

$change: (*)

Change name available in the $source map, or alias to use in naming the CSS variable

$value: null (string | null)

Optional value for the variable, if different from the given $change

$fallback: true (*)

The optional fallback value for a var() function:

  • true will generate a fallback based on the token value
  • A token name will fallback to the value of that css-variable and then to the token’s calculated value
  • Any other fallback will be passed through unchanged

$source: $changes (map)

Optional map of changes to use as a palette source

Example

scss
$changes: (
  '_brand': hsl(120, 50%, 50%),
  'text': '#_brand' ('shade': 50%),
  'border': '#text',
);
.example {
  @include change--('border');
  @include change--('outline', 'border', red);
}
css compiled
.example {
  --change-border: var(--change-text, #206020);
  --change-outline: var(--change-border, red);
}

Requires

@mixin token--()

@function var-change()

Access the CSS variable associated with a given token, along with a fallback value based on the token itself

Since 2.0.0:

  • NEW: Initial release

Parameters & Return

$change: (*)

Change name available in the $source map

$fallback: true (*)

The optional fallback value for a var() function:

  • true will generate a fallback based on the token value
  • A token name will fallback to the value of that css-variable and then to the token’s calculated value
  • Any other fallback will be passed through unchanged

$source: (map)

Optional Accoutrement map of changes to use as source

@return (string)

CSS variable call, in the format: var(--<token>, <fallback>)

Example

scss
$changes: (
  '_brand': hsl(120, 50%, 50%),
  'text': '#_brand' ('shade': 50%),
  'border': '#text',
);
.example {
  border-change: var-change('border');
  change: var-change('text', black);
}
css compiled
.example {
  border-change: var(--change-border, #206020);
  change: var(--change-text, black);
}

Requires

@function var-token()