Skip to content

Commit

Permalink
fix: make pathToToken more closely match real world scenario
Browse files Browse the repository at this point in the history
  • Loading branch information
jaredLunde committed Nov 2, 2021
1 parent e0b20db commit abe91b3
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 19 deletions.
5 changes: 2 additions & 3 deletions src/create-styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -866,9 +866,8 @@ function mergeTokens<
* @param path - A dot-notation string that represents the path to a value
*/
export function pathToToken<
Tokens extends DashTokens = DashTokens,
Themes extends DashThemes = { default: {} }
>(path: KeysUnion<O.Merge<Tokens, ValueOf<Themes>, "deep">>) {
Tokens extends Record<string, unknown> = TokensUnion<DashTokens, DashThemes>
>(path: KeysUnion<Tokens>) {
return (
"var(--" +
path.replace(/\./g, "-").replace(cssCaseRe, "-$&").toLowerCase() +
Expand Down
20 changes: 4 additions & 16 deletions src/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1089,22 +1089,10 @@ describe("pathToToken()", () => {
expect(pathToToken("color.scale.0")).toEqual("var(--color-scale-0)");

expect(
pathToToken<
{
button: { color: { primaryHover: "foo" } };
color: { primary: "foo" };
},
{
light: {
button: { color: { primaryHover: "foo" } };
color: { primary: "foo" };
};
dark: {
button: { color: { primaryHover: "foo" } };
color: { primary: "foo"; blue: "bar" };
};
}
>("button.color.primaryHover")
pathToToken<{
button: { color: { primaryHover: "foo" } };
color: { primary: "foo" };
}>("button.color.primaryHover")
).toEqual("var(--button-color-primary-hover)");
});
});

0 comments on commit abe91b3

Please sign in to comment.