amzn / style-dictionary

A build system for creating cross-platform styles.
https://styledictionary.com
Apache License 2.0
3.93k stars 557 forks source link

Order of precedence for inline tokens, include tokens, and source tokens #921

Open adamstankiewicz opened 1 year ago

adamstankiewicz commented 1 year ago

Hello! We are migrating the design system for the Open edX platform to style-dictionary. One of the requirements for the Open edX platform is that it must support custom theming / overrides of the core design tokens. We are able to do this through by configuring style-dictionary to use include to import the core design tokens and source to import the custom tokens. The source tokens override the include tokens, as expected, which matches the documentation here:

image

My question lies in the expected order of precedence for the tokens option as it relates to include and source options. In the code, it looks like the inline tokens passed through tokens have the least priority, getting overridden by the include tokens and then the source tokens. The documentation doesn't entirely make it clear how tokens interacts with source tokens.

https://github.com/amzn/style-dictionary/blob/e1626a7d60e084bff18c4dc7f45e964c3ae00f54/lib/extend.js#L144

For additional context, we have a use case where we would like the tokens to take precedence over both include and source tokens, thus treating them similar to inline CSS styles where inline styles do indeed have precedence.

Also, per the above docs, it looks as if the source option is required even though in the source code, it's conditionally handled, and thus technically optional (same for tokens, really).

Through this issue, I'm hoping to:

Thanks!