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.
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.
@use "@vrembem/core/config";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.
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.
// 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"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.
// 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";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.
@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"); // => falseChanges 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.
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.
Type:function
Function to returns the value of an option in the configuration map.
$keys...stringA key or list of keys to follow in the configuration map and return.
@debug config.get("theme-default");
// Debug: light
@debug config.get("prefix-tokens");
// Debug: vbType: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.
$keystring | mapThe key in the map to set. Can be passed a map of key/value pairs.
$valueanyThe value to be stored.
@defaultnull
// 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"
));Type:mixin
Merges a map value of the configuration object with a provided map value.
$keystringThe name of the property to merge maps with.
$mapstringThe map to be merged with the existing map value.
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.
$configmapThe config map to set in the global config object.
$defaultmapThe default map that is also used as a map signature for $config.
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.
@use "@vrembem/core/config";
$config: () !default;
$default: (
"config-1": true,
"config-2": "asdf",
);
@include config.merge-with-default($config, $default);When we use this module, we can define the configuration using the Sass with clause:
@use "example" with (
$config: (
"config-1": false
)
);
// More imports here...We can also set our configuration values before the module is loaded and include our config at the top of our manifest file:
// 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"
));@use "config";
@use "example";
// More imports here...Type:mixin
Remove an option from the configuration map.
$keys...stringThe list of keys to follow and remove from the configuration map.
// Remove the theme default option
@include config.remove("theme-default");Type:mixin
Set a watcher to a specific property of the configuration object.
$propstringThe name of the property to watch for changes.
$idstringA unique ID to store the watcher under.
$mixinmixinThe mixin reference to run when the watched property has changed.
Type:mixin
Remove a watcher to a specific property of the configuration object.
$propstringThe name of the property to stop watching.
$idstringThe unique ID of the watcher to remove.
Type:mixin
Log to console the entire or a specific value in the configuration map.
$valuestringOptionally output a specific value of the configuration map.
@default"*"
@include config.log();
// Debug:
// Config options map: (
// "prefix-blocks": ,
// "prefix-elements": __,
// "prefix-modifiers": _,
// "prefix-modifier-values": _,
// ...
// )