References
These utilities have to do with token references/aliases.
usesReference
Whether or not a token value contains references
resolveReferences
Takes a token value string value and resolves any reference inside it
getReferences
Whether or not a token value contains references
Complicated example
You can use the getReferences
utility to create your own custom formats that have outputReferences
capability.
outputReferencesFilter
An OutputReferences
function that filters for tokens containing references to other tokens that are filtered out in the output.
Usually Style Dictionary will throw a warning when you’re using outputReferences: true
and are about to have a broken reference in your output because the token you’re referencing is filtered out.
What that means is that you usually have to either adjust your filter or disable outputReferences
altogether, but supplying a function instead allows you to conditionally output references on a per token basis.
Output:
Note that --colors-grey
was filtered out and therefore the shadow does not contain a CSS custom property (reference) but rather the resolved value.
Live Demo:
outputReferencesTransformed
An outputReferences
function that checks for each token whether
the value has changed through a transitive transform compared to the original value where references are resolved.
Output:
Note that --referred
is using the resolved value that is a transformed version of --base
instead of rgba(var(--base), 12%)
which would be invalid CSS.
This can be verified by setting outputReferences
to true
in the demo below.
Live Demo:
Combining multiple outputReference utility functions
These utility functions can be quite easily combined together: