styles icon indicating copy to clipboard operation
styles copied to clipboard

Prefixed Tokens results with extra dash

Open JoshRosenstein opened this issue 5 years ago β€’ 2 comments

If the final key of a token path starts with a symbol, the resulting variable returns a extra dash. This causes inconsistent css variable naming conventions when tokens have different depths. https://github.com/dash-ui/styles/blob/2fe6bcbf1a74cef66fdad6520abbfc21a50086d6/src/create-styles.ts#L793

Not sure if there was a certain reason for replacing special characters with a dash, if there is, would it be an issue if you were to just remove any special character at the beginning of a key?

const cssDisallowedRe = /[^\w-]/g;
const names = ["color", "red"];
const key = "$100";

console.log(names.join("-") + "-" + key.replace(cssDisallowedRe, "-"));
// color-red--100
console.log(
  names.join("-") +
    "-" +
    key.charAt(0).replace(cssDisallowedRe, "") +
    key.slice(1).replace(cssDisallowedRe, "-")
);
// color-red-100

JoshRosenstein avatar Dec 08 '20 00:12 JoshRosenstein

Thank you for filing! This is a good point. Would you want to submit a PR? Otherwise I can do it tonight.

jaredLunde avatar Dec 08 '20 00:12 jaredLunde

@jaredLunde Sorry, didn't see your response till today, PR submitted.

JoshRosenstein avatar Dec 14 '20 20:12 JoshRosenstein