With variables, you can write components that can be customized externally by doing things like:
--_primary-color: var(--primary-color, oklch(...));
There should be a similar way to specify fallbacks for functions too. That way, people could e.g. define a function for all tints of a given color (e.g. --color-green(20) for a light green), and other code could try that first and provide a fallback light green if not specified.
However, rather than specifying a function or mixin specific syntax, I think we should really specify a generic fallback syntax for anything IACVT. Rationale:
- These cases are going to keep coming up, and unlike
var(), there is no clear syntactic fit for a function call fallback.
- Furthermore, even with variables there are cases where providing a fallback is painful. E.g. consider something like
oklch(90% 40% var(--hue)). To provide e.g. a medium gray as a fallback to the whole color (rather than just a fallback for --hue), you need to introduce an intermediate variable. Same for calc().
- A generic fallback syntax could also simplify
attr(), which currently has its own separate fallback.
In terms of syntax, I see two options:
- A new function, e.g.
fallback(<declaration-value> [ ; | , ] <declaration-value>). Main downside is verbosity.
- "Upgrading"
var() to accept arbitrary values in the first argument — probably not a good idea, as it would be impossible to disambiguate variable references from <dashed-ident> keywords.
With variables, you can write components that can be customized externally by doing things like:
There should be a similar way to specify fallbacks for functions too. That way, people could e.g. define a function for all tints of a given color (e.g.
--color-green(20)for a light green), and other code could try that first and provide a fallback light green if not specified.However, rather than specifying a function or mixin specific syntax, I think we should really specify a generic fallback syntax for anything IACVT. Rationale:
var(), there is no clear syntactic fit for a function call fallback.oklch(90% 40% var(--hue)). To provide e.g. a medium gray as a fallback to the whole color (rather than just a fallback for--hue), you need to introduce an intermediate variable. Same forcalc().attr(), which currently has its own separate fallback.In terms of syntax, I see two options:
fallback(<declaration-value> [ ; | , ] <declaration-value>). Main downside is verbosity.var()to accept arbitrary values in the first argument — probably not a good idea, as it would be impossible to disambiguate variable references from<dashed-ident>keywords.