Extending Pollen
Just as you can customise, extend, and overwrite the included modules in Pollen, you can also use Pollen to generate your own completely custom design system.

Custom modules

Every key in Pollen's modules configuration is turned into a family of CSS variables. The module name becomes the variable prefix, and a property is generated for each key in the module object.
For example this configuration would generate a new group of variables as --typeset-*
Configuration
Generated CSS
1
module.exports = {
2
modules: {
3
typeset: {
4
'0': 'var(--scale-0)/1.3 var(--font-sans)',
5
'1': 'var(--scale-1)/1.5 var(--font-sans)',
6
'2': 'var(--scale-2)/1.4 var(--font-sans)',
7
'3': 'var(--scale-3)/1.2 var(--font-sans)',
8
'4': 'var(--scale-4)/1.1 var(--font-sans)',
9
}
10
}
11
}
Copied!
1
:root {
2
// The rest of Pollen's CSS
3
--typeset-0: var(--scale-0)/1.3 var(--font-sans);
4
--typeset-1: var(--scale-1)/1.5 var(--font-sans);
5
--typeset-2: var(--scale-2)/1.4 var(--font-sans);
6
--typeset-3: var(--scale-4)/1.1 var(--font-sans);
7
}
Copied!
Property keys in module configuration are automatically kebab-cased. For example pageWidth in the grid module becomes --grid-page-width.

Configuration logic

Since Pollen's configuration is just JavaScript, you can run any logic you need to generate your design system configuration as long as it's synchronous.
The above example could be simplified with a makeTypeset() function like so
1
function makeTypeset(scale, lh) {
2
return `var(--scale-${scale})/${lh} var(--font-sans)`;
3
}
4
5
module.exports = {
6
modules: {
7
typeset: {
8
'0': makeTypeset(0, 1.3),
9
'1': makeTypeset(1, 1.5),
10
'2': makeTypeset(2, 1.4),
11
'3': makeTypeset(3, 1.2),
12
'4': makeTypeset(4, 1.1)
13
}
14
}
15
}
Copied!
This can be especially powerful for things like generating opacities from HEX colours, value scales based on ratios, and more.
Last modified 1mo ago
Copy link
Edit on GitHub