Attributes & specifiers
Asterix relies in a few attributes to work.
Attributes are filled with specifiers to enable related css rules. They can be chained.
<div data-layout="--grid--items-center" data-cols="--2--l4" data-gap="--2">
<div>Items</div>
<div>Items</div>
<div>Items</div>
<div>Items</div>
<div data-col="--2--l4">Fullwidth items</div>
</div>
Asterix provides a bunch of specifiers.
Specifiers can be added anywhere in your code. They can be set globally, locally and responsively.
Built-in attributes and specifiers
All builtins specifiers are responsive
Adding a specifier
You can use the --spe($name[, $responsively: false, $attribute: data-spe])
mixin.
Let's say you want to create a button design system.
Implementing buttons variations with --spe()
provides a reliable pattern allowing unlimited chaining. This is perfect for extending a basic design system item.
It could start like this:
.btn{
// Component internal css variables.
--bg: transparent;
--txt: var(--clr-light);
--size: 1rem;
// Properties.
color: var(--txt);
padding: 0.33em 1em;
font-size: var(--size);
background-color: var(--bg);
transition: all 0.1s ease-in-out;
// Specifiers.
@include --spe(primary){
--bg: var(--clr-primary);
--border: var(--clr-primary);
}
@include --spe(large, true){
--size: 1.3rem;
}
//...
}
<button class="btn">Defaults</button>
<button class="btn" data-spe="--primary">Primary</button>
<button class="btn" data-spe="--primary--large">Primary large</button>
<button class="btn" data-spe="--primary--mlarge">Responsive</button>
Optional parameters
Create a new attribute
You design system will probably need extra values, and you want to be able to use them responsively on the HTML side.
Let's say you want to implement a basic design-system buttons layout.
First step is to implement the basic button styling. By using css variables internally, we make it simpler to extend, but you can perfectly use sass variables... Write your own rules !
[data-bt] {
// Set CSS variables with defaults.
--color: var(--clr-default);
--font-size: 1rem;
--background: var(--clr-light);
--background-on: var(--clr-background);
// Default button style.
color: var(--color);
border: none;
outline: none;
display: block;
cursor: pointer;
// Playing with em allow padding to fit button's font-size
padding: 0.5em 1em;
position: relative;
font-size: var(--font-size);
max-width: 100%;
box-shadow: 0px 0px 0px var(--background);
transition: all 125ms ease-in-out;
font-weight: bold;
white-space: nowrap;
border-radius: 3px;
text-overflow: ellipsis;
letter-spacing: -0.1px;
text-decoration: none;
background-color: var(--background);
&:visited {
color: var(--color);
}
&:hover {
transform: translateX(-2px) translateY(-2px);
box-shadow: 4px 4px 0px var(--background);
transition-duration: 70ms;
background-color: var(--background-on);
}
}
This makes any HTML element having data-btn as attribute a button
<button data-bt>Button</button>
<a data-bt>Link as a button</a>
<div data-bt>Div as a button (don't to that)</div>
Then, you need to extend from this basic layout to make your declinals:
// Specifiers
@include --spe(primary, $attribute: data-bt, $local: false) {
--color: var(--clr-light);
--background: var(--clr-primary);
--background-on: var(--clr-primary-on);
}
@include --spe(secondary, $attribute: data-bt, $local: false) {
--color: var(--clr-light);
--background: var(--clr-secondary);
--background-on: var(--clr-secondary-on);
}
@include --spe(large, $attribute: data-bt, $local: false) {
--font-size: 1.3rem;
}
@include --spe(small, $attribute: data-bt, $local: false) {
--font-size: 0.8rem;
}
@include --spe(disabled, $attribute: data-bt, $local: false) {
opacity: 0.3;
pointer-events: none;
}
And you'll have on the html side plenty specifiers available for setting easily your buttons:
<a data-bt="--small" type="button">Button</a>
<a data-bt="--primary--small" type="button">Button</a>
<a data-bt="--secondary--small" type="button">Button</a>
<button data-bt type="button">Button</button>
<button data-bt="--primary" type="button">Button</button>
<button data-bt="--secondary" type="button">Button</button>
<button data-bt="--disabled" type="button">Button</button>
<button data-bt="--primary--disabled" type="button">Button</button>
<button data-bt="--secondary--disabled" type="button">Button</button>
<button data-bt="--large" type="button">Button</button>
<button data-bt="--primary--large" type="button">Button</button>
<button data-bt="--secondary--large" type="button">Button</button>

Last updated