Accoutrement 2.1.1

Times » CSS Variables

$time-var-prefix (string)

scss
$time-var-prefix: 'time-' !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 time-tokens, and we’ll apply it when setting or calling css variables based on your time maps. Set to null or '' (empty string) for no prefix.

Since 2.0.0:

  • NEW: Initial release

Example

scss
$times: ('my-time': 1s);
$time-var-prefix: 'prefix_';
:root { @include time--('my-time') }
css compiled
:root {
  --prefix_my-time: 1s;
}

Used By

@mixin times--()

@mixin time--()

@function var-time()

@mixin times--()

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

  • Time names that start with _ or - are considered “private” and will not be output as variables
  • Times 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: $times (map)

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

{CSS output} (code block)

Custom properties for all public times in the map

Example

scss
$times: (
  '_fast': 200ms,
  'text': '#_fast',
  'fade': '#text',
);
:root {
  @include times--;
}
css compiled
:root {
  --time-text: 200ms;
  --time-fade: var(--time-text, 200ms);
}

Requires

@mixin tokens--()

$time-var-prefix (string)

@mixin time--()

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

Since 2.0.0:

  • NEW: Initial release

Parameters

$time: (*)

Time 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 $time

$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: $times (map)

Optional map of times to use as a palette source

Example

scss
$times: (
  '_brand': 200ms,
  'text': '#_brand' ('plus': 50ms),
  'fade': '#text',
);
.example {
  @include time--('fade');
  @include time--('color-change', 'fade', 0.2s);
}
css compiled
.example {
  --time-fade: var(--time-text, 250ms);
  --time-color-change: var(--time-fade, 0.2s);
}

Requires

@mixin token--()

$time-var-prefix (string)

@function var-time()

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

$time: (*)

Time 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 times to use as source

@return (string)

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

Example

scss
$times: (
  '_fast': 200ms,
  'text': '#_fast' ('plus': 50ms),
  'fade': '#text',
);
.example {
  transition: opacity var-time('fade'), color var-time('text', 150ms);
}
css compiled
.example {
  transition: opacity var(--time-fade, 250ms), color var(--time-text, 150ms);
}

Requires

@function var-token()

$time-var-prefix (string)