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: non prefix themes styling issue #3103

Merged
merged 21 commits into from
Aug 30, 2024
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
7 changes: 7 additions & 0 deletions .changeset/fuzzy-schools-warn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@tokens-studio/figma-plugin": patch
---

Fixes an issue where applied styles are not displaying in Figma, when the themes have been exported as non-prefixed styles from the plugin.

Fixes the issue where applied styles are not displaying in Figma, when the themes have been exported with both 'prefix styles with active theme name' and 'ignore first part of token name for styles' options have been checked
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,8 @@ export class TokenValueRetriever {

public createStylesWithVariableReferences;

private getAdjustedTokenName(tokenName: string, internalParent: string | undefined): string {
const withIgnoredFirstPart = this.ignoreFirstPartForStyles && tokenName.split('.').length > 1
? tokenName.split('.').slice(1).join('.')
: tokenName;

const withPrefix = [internalParent || this.stylePathPrefix, withIgnoredFirstPart].filter((n) => n).join('.');
private getAdjustedTokenName(tokenName: string): string {
cuserox marked this conversation as resolved.
Show resolved Hide resolved
const withPrefix = [this.stylePathPrefix, tokenName].filter((n) => n).join('.');

return withPrefix;
}
Expand Down Expand Up @@ -57,8 +53,8 @@ export class TokenValueRetriever {
this.tokens = new Map<string, any>(tokens.map((token) => {
const variableId = variableReferences?.get(token.name);
// For styles, we need to ignore the first part of the token name as well as consider theme prefix
const adjustedTokenName = this.getAdjustedTokenName(token.name, token.internal__Parent);
const styleId = styleReferences?.get(adjustedTokenName);
const adjustedTokenName = this.getAdjustedTokenName(token.name);
const styleId = styleReferences?.get(token.name);
return [token.name, {
...token, variableId, styleId, adjustedTokenName,
}];
Expand Down
akshay-gupta7 marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -333,8 +333,8 @@ describe('Can set values on node', () => {
},
},
);
expect(setTextValuesOnTargetSpy).not.toHaveBeenCalled();
expect(textNodeMock).toEqual({ ...textNodeMock, textStyleId: '456' });
expect(setTextValuesOnTargetSpy).toHaveBeenCalled();
expect(textNodeMock).toEqual({ ...textNodeMock });
});

it('sets effectStyle if matching Style is found', async () => {
Expand Down Expand Up @@ -453,8 +453,8 @@ describe('Can set values on node', () => {
},
},
);
expect(setEffectValuesOnTargetSpy).not.toHaveBeenCalled();
expect(solidNodeMock).toEqual({ ...solidNodeMock, effectStyleId: '123' });
expect(setEffectValuesOnTargetSpy).toHaveBeenCalled();
expect(solidNodeMock).toEqual({ ...solidNodeMock, effectStyleId: '' });
});

it('sets fillStyle if matching Style', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export async function getThemeReferences(prefixStylesWithThemeName?: boolean) {
const figmaVariableReferences: RawVariableReferenceMap = new Map();

const activeThemes = themeInfo.themes?.filter((theme) => Object.values(themeInfo.activeTheme).some((v) => v === theme.id));

const stylePathPrefix = prefixStylesWithThemeName && activeThemes.length > 0 ? activeThemes[0].name : undefined;

activeThemes?.forEach((theme) => {
Expand Down
Loading