Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: documentation tokens #2286

Merged
merged 1 commit into from
Oct 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/curvy-laws-attend.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@tokens-studio/figma-plugin': patch
---

Fixes a bug that caused raw value documentation tokens to stop working
12 changes: 8 additions & 4 deletions src/plugin/node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export function mapValuesToTokens(tokens: Map<string, AnyTokenList[number]>, val
if (!resolvedToken) return acc;
if (isSingleToken(resolvedToken)) {
// We only do this for rawValue as its a documentation and we want to show this to the user
if (returnValueToLookFor(key) === 'rawValue' && resolvedToken.$extensions) {
if (returnValueToLookFor(key) === 'rawValue' && resolvedToken.$extensions?.['studio.tokens']?.modify) {
const modifier = resolvedToken.$extensions?.['studio.tokens']?.modify;
if (modifier) {
acc[key] = modifier.type === ColorModifierTypes.MIX ? `${resolvedToken.rawValue} / mix(${modifier.color}, ${modifier.value}) / ${modifier.space}` : `${resolvedToken.rawValue} / ${modifier.type}(${modifier.value}) / ${modifier.space}`;
Expand All @@ -69,12 +69,16 @@ export function mapValuesToTokens(tokens: Map<string, AnyTokenList[number]>, val
acc.borderColor = value.color;
}
});
} else if (returnValueToLookFor(key) === 'description') {
// Not all tokens have a description, so we need to treat it special
acc[key] = resolvedToken.description ? resolvedToken.description : 'No description';
} else if (borderPropertyMap.get(key as Properties) && resolvedToken.type === TokenTypes.BORDER && typeof resolvedToken.value === 'object' && 'color' in resolvedToken.value && resolvedToken.value.color) {
// Same as above, if we're dealing with border tokens we want to extract the color part to be applied (we can only apply color on the whole border, not individual sides)
// Same as above, if we're dealing with border tokens we want to extract the color part to be applied (we can only apply color on the whole border, not individual sides)
acc.borderColor = resolvedToken.value.color;
acc[key] = resolvedToken[returnValueToLookFor(key)] || resolvedToken.value;
// We return the value because the token holds its values in the 'value' prop
acc[key] = resolvedToken.value;
} else {
// Otherwise, just apply the value
// Otherwise, try to apply the key, if we dont have it, apply the value
acc[key] = resolvedToken[returnValueToLookFor(key)] || resolvedToken.value;
}
} else {
Expand Down