Mixins

variables

accessibility

$accessibility: 'AA' !default;

Description

Defines the default accessibility for all mixins. Can be AA, AAA, or false.

Example

@use 'sass-themes' with ($accessibility: 'AAA');

Used by

base-styles

$base-styles: 'extend' !default;

Description

Defines how base styles (setting text, background, and border colors) are included by default. Can be extend, include, or false. By default, styles are extended so that they can be overridden by the same specificity rules.

Example

@use 'sass-themes' with ($base-styles: false);

functions

[private] _classify

@function _classify($str) { ... }

Description

Turns a string into a class name. Leaves strings formatted as selectors unmodified.

Parameters

parameter Nameparameter Descriptionparameter Typeparameter Default value
$str noneString none

Returns

String

Used by

mixins

[private] _create

@mixin _create($text, $bg, $brand: null, $styles: $base-styles) { ... }

Description

Defines the CSS properties for a theme class. Uses the define mixin from the scss-properties library.

Parameters

parameter Nameparameter Descriptionparameter Typeparameter Default value
$text noneColor none
$bg noneColor none
$brand noneColornull
$styles

Controls how base styles (setting text, background, and border colors) should be added.

'extend' or 'include' or False$base-styles

Output

Output is simplified for readability. Actual output shown in comments.

body, .light {
  --light-theme:      1;                                          // 1 if text color is darker than background, else 0
  --dark-theme:       0;                                          // opposite --light-theme
  --theme-tx:         #111;                                       // hsla(var(--theme-tx-h), var(--theme-tx-s), var(--theme-tx-l), var(--theme-tx-a));
  --theme-bg:         white;                                      // hsla(var(--theme-bg-h), var(--theme-bg-s), var(--theme-bg-l), var(--theme-bg-a));
  --theme-br:         royalblue                                   // hsla(var(--theme-br-h), var(--theme-br-s), var(--theme-br-l), var(--theme-br-a));
  --button-text:      if($brand and not $light-theme, $text, $bg) // hsla(var(--button-text-h), var(--button-text-s), var(--button-text-l), var(--button-text-a));
  --button-bg:        $brand or $text                             // hsla(var(--button-bg-h), var(--button-bg-s), var(--button-bg-l), var(--button-bg-a));
  --theme-tx--light:  #{scss-properties.mix(                      // rgba(calc((var(--theme-tx-r) * (0.58 + (0.18 * var(--theme-dark)))) + (var(--theme-bg-r) * (1 - (0.58 + (0.18 * var(--theme-dark)))))),
                        --theme-tx,                               //      calc((var(--theme-tx-g) * (0.58 + (0.18 * var(--theme-dark)))) + (var(--theme-bg-g) * (1 - (0.58 + (0.18 * var(--theme-dark)))))),
                        --theme-bg,                               //      calc((var(--theme-tx-b) * (0.58 + (0.18 * var(--theme-dark)))) + (var(--theme-bg-b) * (1 - (0.58 + (0.18 * var(--theme-dark)))))),
                        '(0.58 + (0.18 * var(--theme-dark)))'     //      calc((var(--theme-tx-a) * (0.58 + (0.18 * var(--theme-dark)))) + (var(--theme-bg-a) * (1 - (0.58 + (0.18 * var(--theme-dark)))))));
                      )};

  color:              var(--theme-tx);
  background-color:   var(--theme-bg);
  border-color:       var(--theme-tx);
}

Used by

create

@mixin create($tx, $bg, $br: null, $accessibility: $accessibility, $styles: 'extend', $keywords: null) { ... }

Description

Wrapper for _create, which normalizes arguments and keyword aliases before creating a theme. Must define at least a text and a background color.

Parameters

parameter Nameparameter Descriptionparameter Typeparameter Default value
$tx

Aliases: $text, $color, $text-color, $--theme-tx

Color none
$bg

Aliases: $background, $background-color, $--theme-bg

Color none
$br

Aliases: $brand, $brand-color, $--theme-br

Colornull
$accessibility

The accessibility standard to check this themes colors against.

'aaa' or 'aa' or False$accessibility
$styles

Controls how base styles (setting text, background, and border colors) should be added.

'extend' or 'include' or False'extend'
$keywords

A map that sets multiple the parameter values if passed as the only argument.

Mapnull

Example

@use 'sass-themes';

body, .light {
  // using keyword arguments
  @include sass-themes.create(
    $tx: #111,
    $bg: white,
    $br: royalblue
  )
}

.dark {
  // using a map of keyword arguments
  @include sass-themes.create((
    --theme-tx: white;
    --theme-bg: #111;
    --theme-br: royalblue;
  ));
}
@use 'sass-themes';

@include sass-themes.create((
  // using a map of class names and keyword arguments
  'light': (
      --theme-tx: #111,
      --theme-bg: white,
      --theme-br: royalblue ),
  'dark': (
      --theme-tx: white,
      --theme-bg: #111,
      --theme-br: royalblue )));

Throws

  • theme must specify at least text and background colors: #{&}

Requires

accessibility

@mixin accessibility($text, $bg, $brand: null, $accessibility: $accessibility) { ... }

Description

Checks the color contrast ratios against the WCAG standards. Throws a warning when the provided colors do not meet the standard.

Parameters

parameter Nameparameter Descriptionparameter Typeparameter Default value
$text noneColor none
$bg noneColor none
$brand noneColornull
$accessibility

The accessibility standard to check this themes colors against.

'aaa' or 'aa' or False$accessibility

Requires

Used by

base

@mixin base() { ... }

Description

The styles applied to all theme classes after their properties have been defined.

Parameters

None.

Styles: Base

variables

anchor-override

$anchor-override: '.subtle-link' !default;

Description

Name of the class that unsets the default theme styles for links.

Used by

Links

css

blockquote

blockquote { ... }

Description

Default styles for blockquotes.

Links

pre, code

pre,
code { ... }

Description

Default styles for code blocks.

Links

input[type='text'], textarea

input[type='text'],
textarea { ... }

Description

Default styles for form fields.

Links

#{list.join($anchor-override, (), 'comma', false)}

#{list.join($anchor-override, (), 'comma', false)} { ... }

Description

Override default link styles.

Links

Styles: Backgrounds

variables

overlay

$overlay: 0.5 !default;

Description

Opacity of the .overlay class

Used by

heavy-overlay

$heavy-overlay: 0.75 !default;

Description

Opacity of the .heavy-overlay class

Used by

css

.theme-bg

.theme-bg { ... }

Description

Applies the --theme-bg to an element's background color.

.no-bg

.no-bg { ... }

Description

Removes an element's background color.

.overlay

.overlay { ... }

Description

Applies a semi-transparent --theme-bg to an element's background color.

Links

.heavy-overlay

.heavy-overlay { ... }

Description

Same as .overlay, but with a separate control.

Links

Styles: Borders

variables

border-light

$border-light: 10% !default;

Description

Percent of text color mixed with background in the .border-light class.

border-x-light

$border-x-light: 5% !default;

Description

Percent of text color mixed with background in the .border-x-light class.

css

&-light

&-light { ... }

Description

Applies a subtle color to border styles, relative to --theme-tx and --theme-bg. @name .border-light @require $border-light

&-x-light

&-x-light { ... }

Description

Applies an even subtler color to border styles, relative to --theme-tx and --theme-bg. @name .border-x-light @require $border-x-light

Styles: Buttons

variables

btn-hover-mix

$btn-hover-mix: 80% !default;

Description

Controls how much the .button and .button-o elements react on hover.

Used by

Links

css

.button

.button { ... }

Description

Button element with an opaque, branded background.

Links

&.subtle-button

&.subtle-button { ... }

Description

More subtle styling for the .button class @name .button.subtle-button @require {css} .button

Links

&-o

&-o { ... }

Description

Button element with default background and branded outlines. @name .button-o

Links

&.subtle-button:not(:hover)

&.subtle-button:not(:hover) { ... }

Description

More subtle styling for the .button-o class @name .button-o.subtle-button @require {css} .button-o

Links

Styles: SVG

css

.fill-color-theme

.fill-color-theme { ... }

Description

SVG fill classes.

.stroke-color-theme

.stroke-color-theme { ... }

Description

SVG stroke classes.

Styles: Text

css

.text-light

.text-light { ... }

Description

Light text, relative to background color.

.text-brand

.text-brand { ... }

Description

Applies the brand color to text.

Utilities

functions

if-light

@function if-light($true, $false) { ... }

Description

Returns one of two values depending on whether the current theme is light or dark. The values can either be custom CSS properties produced by the create mixin, or any CSS value that can be multiplied in a calc() function.

Parameters

parameter Nameparameter Descriptionparameter Typeparameter Default value
$true noneString or Number none
$false noneString or Number none

Returns

Value

a calc function that resolves to $true on light themes and $false on dark themes.

Example

.theme-class {
  color: sass-themes.if-light(--theme-tx, --theme-br);
}
.theme-class {
  height: sass-themes.if-light(100px, 80em);
}

if-dark

@function if-dark($true, $false) { ... }

Description

Same as if-light but reversed.

Parameters

parameter Nameparameter Descriptionparameter Typeparameter Default value
$true noneString or Number none
$false noneString or Number none

Returns

Value

a calc function that resolves to $true on dark themes and $false on light themes.

See