Skip to content

Commit

Permalink
BREAKING: change format for permutateThemes output for single-dimensi…
Browse files Browse the repository at this point in the history
…onal themes (#167)
  • Loading branch information
jorenbroekema committed Jun 30, 2023
1 parent 260d152 commit 3425572
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
5 changes: 5 additions & 0 deletions .changeset/quick-onions-lie.md
@@ -0,0 +1,5 @@
---
'@tokens-studio/sd-transforms': minor
---

BREAKING: permutateThemes to return the same format regardless of whether multi-dimensional themes are used or not. Format: `{ themeName: [sets] }`.
12 changes: 8 additions & 4 deletions src/permutateThemes.ts
Expand Up @@ -4,6 +4,12 @@ declare interface Options {
separator?: string;
}

function mapThemesToSetsObject(themes: ThemeObject[]) {
return Object.fromEntries(
themes.map(theme => [theme.name, filterTokenSets(theme.selectedTokenSets)]),
);
}

export function permutateThemes(themes: ThemeObject[], { separator = '-' } = {} as Options) {
if (themes.some(theme => theme.group)) {
// Sort themes by groups
Expand All @@ -19,9 +25,7 @@ export function permutateThemes(themes: ThemeObject[], { separator = '-' } = {}
});

if (Object.keys(groups).length <= 1) {
return Object.fromEntries(
themes.map(theme => [theme.name, filterTokenSets(theme.selectedTokenSets)]),
);
return mapThemesToSetsObject(themes);
}

// Create theme permutations
Expand All @@ -44,7 +48,7 @@ export function permutateThemes(themes: ThemeObject[], { separator = '-' } = {}
}),
);
} else {
return themes;
return mapThemesToSetsObject(themes);
}
}

Expand Down
5 changes: 4 additions & 1 deletion test/spec/permutateThemes.spec.ts
Expand Up @@ -196,6 +196,9 @@ describe('transform dimension', () => {
},
];

expect(permutateThemes(singleDimensionalThemes)).to.eql(singleDimensionalThemes);
expect(permutateThemes(singleDimensionalThemes)).to.eql({
dark: ['core', 'dark', 'theme'],
light: ['core', 'light', 'theme'],
});
});
});

0 comments on commit 3425572

Please sign in to comment.