Menu

On this page
← Back to Core

core/config

A Sass module for managing global configuration options. This is available across all components to set things like BEM naming syntax, prefixes, and output options.

SCSS
@use "@vrembem/core/config";
Copied!

Basic usage

The purpose of core/config is to provide an API for managing library-wide configuration options. Configuration options are stored in a private map of key/value pairs.

There are two primary methods to configure options in the config module. The first is to import the module API directly and the second is using the Sass @use ... with clause.

Using config module

To use the configuration module directly, import the core/config module. Once imported you can use the API to set and get values in the configuration map.

_config.scss
// 1. Import the module
@use "@vrembem/core/config";

// 2. Set a configuration value
@include config.set("prefix-tokens", "sn");

// 3. Get a configuration value
@debug config.get("prefix-tokens"); // => "sn"
Copied!

Changes to the global config should be done in a file that is loaded before other Vrembem or custom components that use them. This ensures components use the correct configuration values when their modules are loaded.

style.scss
// 1. Make all your custom configurations
@use "./config";

// 2. Import components or other custom modules
@use "@vrembem/content";
@use "@vrembem/modal";
// ...

// 3. Output CSS variables
@use "@vrembem/core/tokens";
Copied!

Using with clause

To set configuration options via the Sass @use ... with clause, define and set options in a $config options map. Options set in the $config map are stored in the config module and backfilled with the modules defaults.

app.scss
@use "@vrembem/core" with (
  $config: (
    "prefix-blocks": "vb"
  )
);
@use "@vrembem/content" with (
  $config: (
    "content-output": false
  )
);

@debug core.config-get("prefix-blocks"); // => "vb"
@debug core.config-get("content-output"); // => false
Copied!

Changes to the global config should be done before loading other Vrembem or custom components. This ensures components use the correct configuration values when their modules are loaded.

Reference

This reference details the available configuration API, their arguments, and usage examples so you can customize and control global configurations across Vrembem and custom modules.

get

Type:function

Function to returns the value of an option in the configuration map.

Arguments

$keys...string

A key or list of keys to follow in the configuration map and return.

Example

SCSS
@debug config.get("theme-default");
// Debug: light

@debug config.get("prefix-tokens");
// Debug: vb
Copied!

set

Type:mixin

Set an option in the configuration map by providing a key and value to store, or pass a map to store multiple key/value pairs.

Arguments

$keystring | map

The key in the map to set. Can be passed a map of key/value pairs.

$valueany

The value to be stored.


@defaultnull

Example

SCSS
// Set a single option
@include config.set("theme-default", "dark");

// Set multiple options using a map
@include config.set((
  "prefix-tokens": "custom",
  "theme-default": "light"
));
Copied!

merge

Type:mixin

Merges a map value of the configuration object with a provided map value.

Arguments

$keystring

The name of the property to merge maps with.

$mapstring

The map to be merged with the existing map value.

merge-with-default

Type:mixin

Merges a configuration map to the config module based on the values in a default map. The provided configuration map must match the signature of the default map. This mixin is used to allow setting values in the config module using the Sass with clause.

Arguments

$configmap

The config map to set in the global config object.

$defaultmap

The default map that is also used as a map signature for $config.

Example

We define an empty $config map with the !default flag and a $default map containing the configurations we want to expose and their default values.

_example.scss
@use "@vrembem/core/config";

$config: () !default;
$default: (
  "config-1": true,
  "config-2": "asdf",
);

@include config.merge-with-default($config, $default);
Copied!

When we use this module, we can define the configuration using the Sass with clause:

app.scss
@use "example" with (
  $config: (
    "config-1": false
  )
);

// More imports here...
Copied!

We can also set our configuration values before the module is loaded and include our config at the top of our manifest file:

_config.scss
// Import the config module
@use "@vrembem/core/config";

// These values will be used once the module is loaded
@include config.set((
  "config-1": false,
  "config-2": "fdsa"
));
Copied!
app.scss
@use "config";
@use "example";

// More imports here...
Copied!

remove

Type:mixin

Remove an option from the configuration map.

Arguments

$keys...string

The list of keys to follow and remove from the configuration map.

Example

SCSS
// Remove the theme default option
@include config.remove("theme-default");
Copied!

watch

Type:mixin

Set a watcher to a specific property of the configuration object.

Arguments

$propstring

The name of the property to watch for changes.

$idstring

A unique ID to store the watcher under.

$mixinmixin

The mixin reference to run when the watched property has changed.

unwatch

Type:mixin

Remove a watcher to a specific property of the configuration object.

Arguments

$propstring

The name of the property to stop watching.

$idstring

The unique ID of the watcher to remove.

log

Type:mixin

Log to console the entire or a specific value in the configuration map.

Arguments

$valuestring

Optionally output a specific value of the configuration map.


@default"*"

Example

SCSS
@include config.log();
// Debug: 
// Config options map: (
//   "prefix-blocks": ,
//   "prefix-elements": __,
//   "prefix-modifiers": _,
//   "prefix-modifier-values": _,
//   ...
// )
Copied!