This is likely to cause an edge case in looping that crops up in most threads about custom properties.
However I would like to propose two extensions to the syntax to generate variables on the fly:
:root {
--use-info-light: blue;
--use-info-lighter: lightblue;
--use-warning-light: red;
--use-warning-lighter: pink;
}
my-flash-message {
[use=--use] {
my-heading {
color: var(--use-var(--use)-lighter, --use-info-lighter);
}
my-block {
color: var(--use-var(--use)-light, --use-info-light);
}
}
}
Where I have a custom element:
<my-flash-message use="warning">...</my-flash-message>
The suggestions are:
- Variable variable syntax:
var(--use-var(--use)-light)
orvar(--calc(use- + var(--use) + -light))
- Attribute selector variables:
[use=--use]
whereuse="warning"
makesvar(--use)
equal ‘warning’
The rationale is:
Having the ability to create a property that adds semantic meaning to custom elements that defines style dependent on the custom element and context (Top level selectors wouldn’t work). Generated macro code works for this use case somewhat however the output selectors becomes very large quickly.