Generators

The generators are special (a naming convention in Spruce CSS only) mixins, which we use to generate base styles.

By default, Spruce CSS doesn’t generate styles: importing it, you access the variables, mixins and functions, but nothing more. If you wish to use the styling, you have to include it explicitly.

The Goal of the Generators

The goal is to separate other Spruce CSS functionality from the style generation and modularity. There can be cases where you don’t need all or any of the given CSS code.

The Difference Between Generator Mixin and a Regular Mixin

  • A generator mixin is always prefixed with generate-*.
  • A generator mixin gives back complete rules with selectors (some of them accept the selectors as arguments). It is a wrapper to call style declarations.
  • A generator mixin is usually used once per project. Including any of them more than once may generate unnecessary repetition and bloat.

generate-color-variables

Using generate-color-variables, we can generate our CSS variables from a map object everywhere we want. You can find an example in the core.

View Source on GitHub

Argument(s)

NameDefault ValueDescription
$colors$colorsThe color Sass map.
$selector:rootThe selector which will scope the CSS custom properties.

Example(s)

@use 'sprucecss/scss/spruce' as *;

@include generate-color-variables(
  $colors,
  ':root'
);

generate-variables

A useful internal utility mixin to generate CSS custom properties anywhere. We use it in custom property mode to generate the scoped variables where needed. With the $hook argument (new in v3), every value reads a namespaced style hook first.

If you want to see it in action check out the check form component.

Argument(s)

NameDefault ValueDescription
$mapThe name Sass map.
$excludenullA Sass list what to exclude from the map.
$includenullA Sass list what to include from the map.
$hooknullThe name of the style hook namespace (like 'btn').

View Source on GitHub

generate-styles

The generate-styles mixin is a shorthand to call all the mixins from the list below. You can control the output with the $generators map.

@use 'sprucecss/scss/spruce' as *;

@include generate-styles;

Turn any part off (or the opt-in parts on) with the $generators map:

@use 'sprucecss/scss/spruce' with (
  $generators: (
    'content': (
      'dark-mode': true,  // opt-in
      'dialog': false,
      'styles': true,     // opt-in
    ),
    'form': (
      'btn-group': false,
      'form-range': false,
    ),
  ),
);
GroupKeyDefaultGenerates
contentaccessibilitytrue.sr-only, .sr-only-focusable
contentdark-modefalseThe dark mode
contentdefaulttrueBase element styles (selection, links, box sizing)
contentdetailstruedetails
contentdialogtruedialog
contentdisplaytrueThe $display and shadow custom properties
contentdividertruehr
contentlayouttrueThe $layout custom properties
contentmediatrueImages, video, iframes, figures
contentnormalizetruenormalize.css
contentprinttruePrint styles (also needs the print setting)
contentprogresstrueprogress and meter
contentroottrueThe :root custom properties
contentstylesfalseThe style presets
contenttabletrueTables
contenttypographytrueTypography
contentutilitiestrueUtilities
formbtntrueButtons and their variants
formbtn-grouptrue.btn-group
formfile-btn … form-switchtrueThe form elements

View Source on GitHub

generate-field-icons

New in v3. Regenerate the SVG field icons (select arrow, checkbox, radio, switch knob, validation icons) for a color map under a selector. The icons are data URIs, so they can’t follow CSS custom properties; use this mixin when you change the related colors for a theme. The dark mode and the styles call it for you.

NameDefault ValueDescription
$colorsThe color map (only the defined keys are used).
$scopeThe scope selector.
$control'.form-control'The form control selector.
$check'.form-check__control'The checkbox and radio selector.
$switch'.form-switch__control'The switch selector.
$suffix''A suffix for every control selector.
@include generate-field-icons($high-contrast-colors, '[data-theme-mode="high-contrast"]');

generate-style

New in v3. Generate one style preset under any scope. generate-style-presets calls it for every preset based on the styles settings.

@include generate-style('brutalist', map.get($styles, 'brutalist'), '.promo');

Documentation

Learn about Spruce CSS through our extensive documentation.

Components

Explore our UI library of accessible components built with Spruce CSS.

Blocks and Pages

Full-width page blocks and complete page templates, ready to copy.

Find us on GitHub

Did you find a bug? Have an idea or a question? Please open an issue to help us develop the project.