Getting started
Using with Jaspr
Writing classes in components, handling state and reusing styles.
The classes attribute
Every Jaspr HTML component accepts a classes
string: that is where utilities live.
button(
classes: 'px:5 py:3 br:lg fw:semibold c:white bg:blue hover:bg:blue-700',
onClick: save,
[.text('Save')],
)
Conditional classes
Build a list and join it: each branch stays a string literal the CLI can read.
li(
classes: [
'px:3 py:2 br:md',
if (active) 'c:white bg:blue' else 'c:gray-700 hover:bg:gray-100',
].join(' '),
[.text(label)],
)
Reusing styles
Put frequent combinations in constants. They stay literals, so they are detected:
const primaryAction = 'px:5 py:3 br:lg fw:semibold c:white bg:blue';
const tones = {
'info': 'c:blue-700 bg:blue-100',
'danger': 'c:red-700 bg:red-100',
};
The engine at runtime
The engine can also be used as a library (package:jx_cli/engine.dart), on the server or in the browser. This site uses it to compile its examples and to power the playground:
import 'package:jx_cli/engine.dart';
final result = JxEngine().compile('p:4 md:p:8');
print(result.css); // generated stylesheet
print(result.ruleCount); // number of rules
print(result.warnings); // rejected classes