Token usage DX needs improvement...? #2398
Replies: 6 comments
-
Token Ambiguity
you can use I agree the automatic Token Referencingthe token category import { defineConfig } from '@pandacss/dev';
export default defineConfig({
// ...
theme: {
extend: {
tokens: {
spacing: {
"xl": { value: "40px"}
},
sizes: {
"xl": { value: "32px"}
},
fontWeights: {
"xl": { value: "72px"}
},
}
}
}
}); how would you know which one to use here
this syntax is however possible for CSS vars, overall, I understand the complaint, it's not the first time it has been voiced: Panda is too flexible just my personal opinion: by giving you a lot of features, you can choose to opt-in most of the time and start simple, then progressively use more if you need to |
Beta Was this translation helpful? Give feedback.
-
Thanks for taking the time to reply to me @astahmer 🙏
But then we have to use the square bracket escape hatch syntax, which just adds more friction and confusion.
I love automatic px! It's such a DX win. I also love a numeric space scale... Stitches-style dollar sign token format solved this 💔
The same way that If
No doubt curly braces would be necessary in most of the examples above, otherwise it's a parsing nightmare, but this seems like a no-brainer reference resolution system to me. It's easy to teach/learn, and easy to type/grok. I say all this with only a casual understanding of how Panda works 😅 I'm sure it'd be a big change to implement something like this, with implications for utils and other parts of the API... but with Panda being less than a year old (publicly), now's the time to be led by design goals and DX, rather than existing/historic implementation details... Just my 2c. Hope there's something interesting in my two essay posts! |
Beta Was this translation helpful? Give feedback.
-
how else would you like to solve this issue ? if I understand correctly you'd like to quickly discerne which value is a token from a raw value
why not, tho now we'd have a 4th way of doing token referencing (
how would you find the what if I have a I'm not saying it's not possible most likely won't be worth the effort just seeing the examples you gave and I don't feel like it would make this intuitive, as it means using that new short syntax doesn't always work (whereas the existing syntaxes do) |
Beta Was this translation helpful? Give feedback.
-
This stemmed from my original comment about how
Yup. But 5 because
Sorry, I said immediately after my list of examples that To be clear about the syntax/resolution changes I'm proposing:
eg. These are equivalent. Bracing is optional:
Same here:
Bracing not required for
Also equivalent, but bracing is required:
Invalid/left untouched:
Hope the above section clarifies my last post. I'm suggesting methods to iron out the inconsistencies in how tokens are consumed, because I can see how it can be confusing and frustrating to Panda newbies. I'm about to transition our dev team over to Panda, for all new work, and this is one of the things which I can see being an issue. |
Beta Was this translation helpful? Give feedback.
-
@manspaniel IMO, the way to iron out inconsistencies in the team would be to agree on practices for the team, not overconfigure the styling engine. When the team agrees with said practices, they can then be enforced:
We'll all have opinionated ways of going around things in our different teams, and it'll be inefficient for panda to try to satisfy all these. |
Beta Was this translation helpful? Give feedback.
-
I know how to iron out inconsistencies in a team... I'm talking about inconsistencies in Panda. Literally asking for more expressiveness and y'all keep recommending that I enable options that make Panda less expressive...? Stitches solved token scoping/cross-referencing years ago and it's basically what I'm describing. It's the most expressive syntax because of it's simplicity, and paired with Panda's tooling/functions it'd be killer... But it's clear there's strong resistance to a rethink of this part of Stitches, so I'll drop it. Thank you both though for the replies and discussion. |
Beta Was this translation helpful? Give feedback.
-
Coming from Stitches, and using it to build ~30 sites, our team have come to rely on it's excellent DX when it comes to design tokens. While Panda provides more advanced features, token consumption is a bit more confusing, inconsistent and verbose.
I'd like to highlight two of the overarching issues below.
Token Ambiguity
In Panda, it can sometimes be non-obvious when something is a token vs a regular CSS value.
Above,
blue
andlarge
could refer to the standard CSS keywords, or they could refer to tokens defined in a custom Panda configuration. You can only be sure by checking the generated CSS.On the other hand, Stitches token referencing syntax makes it very obvious.
As an added bonus, tokens appear first in IntelliSense dropdowns when they start with
$
, and again, it is obvious which are tokens vs keyword completions.(I am aware that this syntax can be enabled somewhat using the
tokens:created
as documented here)Things get even more confusing if you use numbers as token identifiers.
Token Referencing
In Stitches, token referencing is very simple:
$<token>
impliesvar(--<scale>-<token>)
(where the scale is inferred from the CSS property)$<scale>$<token>
impliesvar(--<scale>-<token>)
This syntax gives Stitches very clear and concise token referencing:
The above syntax works as you expect, is easy to read/write, and is scalable from a single token-only value up to a complex calc expression, and works well for compound properties. Once you learn that tokens can be referred to using dollar signs, your intuition tells you that you can use them in calc/min/max expressions, and your intuition is correct.
Panda, on the other hand, is less intuitive:
To combat this, Panda has two (or three?) solutions:
Why do I need to write the scale explicitly? Is that by design, or just because it was too hard to make it infer the scale?
Curly braces just make more mess. And by writing token() I'm saving one character over a native CSS variable — saved by the dash.
But then... despite requiring space prefixes on tokens when using
token()
and{token}
... they are forbidden when using the simpler syntax, for some reason.You can also technically/sometimes use the
token
TypeScript function, not to be confused with the CSS function above 😳, along with a template literal:Except... the above code is not statically extracted, so the generated classname of
h_calc(32px_/_2)
will not have a definition unless your code happens to havecss({ height: "calc(32px / 2)" })
in it somewhere else, in which case, yes it will work.Obviously, this last approach is not one that anybody should use... but since token references don't always work how you/everyone expects, I bet a lot of people new to Panda have tried it. Panda's static extraction system could probably be modified to handle this silly third option, or it could just remain broken and confuse anyone who uses it — to me, the most appealing option is to make token referencing so intuitive that nobody would bother trying it.
[End of rabbit hole]
I hope my post doesn't come across as too negative. I really do want Panda to succeed, and appreciate the effort and commitment that has gone into making it.
But, I'm curious to know whether these issues have been considered/discussed, and if there are any ideas for addressing them? Am I alone in these concerns?
Cheers, Dan.
Beta Was this translation helpful? Give feedback.
All reactions