Variables
SCSS variables
Asterix uses a map variable called $asterix-vars wich contains all required and custom values.
It is used during sass compilation to write internal rules like responsive ones, but also to write css3 variables.
You can add, update or remove groups and properties.
Default settings
// /_configuration.scss - Default settings
$asterix-vars: (
breakpoints: (
xs: 480px,
s: 768px,
m: 1024px,
l: 1200px,
),
colors: (
default: black,
),
font-families: (
default: 'sans-serif',
),
gaps: (
1: 0.5rem,
2: 1rem,
3: 1.5rem,
4: 3rem,
),
shapes: (
default: 4px,
),
) !default;Minimal configuration
In order to use builtins mixins, functions and layout system, you have to include those maps:
breakpoints: ( key: value, key: value...)gaps: (key:value, key:value...)
Other maps are totally optional.
Retrieve $asterix-vars values
$asterix-vars valuesYou can use the --var($group[, $property]) function to retrieve a specific value or an entire group.
$group : the $asterix-vars group name to retrieve.
$property: when set, return the specific property value.
If the group doesn't exist, return an empy map ().
If the property doesn't exist, return unset.
Update $asterix-vars values
$asterix-vars valuesAlways update between the asterix's main @import and the call of the asterix() mixin.
The mixin --update-vars($updatedVars) will merge the map you provide with the current settings.
CSS Variables
Asterix loves css3 variables, as it uses them in its layout engine.
By using css3 variables instead of rendered scss variables, you will be able to update them client side, any time you want, at any scope you want, combinated with any css rule you want, including transitions and animations.
This can be a very powerful tool for handling, for instance, a dark mode.
Translate scss variables into css variables
Manually:
Or a bunch of maps at once with the --set-css-variables($variables) mixin:
Generated css3 variables names follow a --[groupName]-[valueName] pattern.
About colors
When translating a sass color into a css variables, its value cannot normally be used into rgba() css rules. Here's a basic example of the issue:
--set-css-variables will automatically detect any color provided and will create two css variables for each of them, the first containing the inital value and the second filled with the sass computed rgb value.
Core css variables
Internal variables
Logic
Basically, declaring an attribute will set to some properties some css variables. Values provided to the attribute will set the css variables values.
Here is a minimal example :
With this approach, the core is writing a very few code in the loops used to render columns, gap and breakpoints, and a bit more in attribute global selector. This way, code can be extended at a low byte cost.
Finally, by using css variables, the asterix's code is non-invasive as it can be manually updated in any scope level, without struggling with inheritance.
Last updated