Accoutrement 4.0.5

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
tools.$changes: ('my-change': pink);
tools.$change-var-prefix: 'prefix_';
html { @include tools.change--('my-change') }
css compiled
html {
  --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
tools.$changes: (
  '_brand': hsl(120, 50%, 50%),
  'text': '#_brand' ('shade': 50%),
  'border': '#text',
);
html {
  @include tools.changes--;
}
css compiled
html {
  --change-text: rgb(31.875, 95.625, 31.875);
  --change-border: var(--change-text, rgb(31.875, 95.625, 31.875));
}

Requires

@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
tools.$changes: (
  '_brand': hsl(120, 50%, 50%),
  'text': '#_brand' ('shade': 50%),
  'border': '#text',
);
.example {
  @include tools.change--('border');
  @include tools.change--('outline', 'border', red);
}
css compiled
.example {
  --change-border: var(--change-text, rgb(31.875, 95.625, 31.875));
  --change-outline: var(--change-border, red);
}

Requires

@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
tools.$changes: (
  '_brand': hsl(120, 50%, 50%),
  'text': '#_brand' ('shade': 50%),
  'border': '#text',
);
.example {
  border-change: tools.var-change('border');
  change: tools.var-change('text', black);
}
css compiled
.example {
  border-change: var(--change-border, rgb(31.875, 95.625, 31.875));
  change: var(--change-text, black);
}

Requires

@function var-token()