-
Notifications
You must be signed in to change notification settings - Fork 253
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 for #650: Generate friendly class names #916
Fix for #650: Generate friendly class names #916
Conversation
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. Latest deployment of this branch, based on commit 72d7c8c:
|
I'm not sure it's being blocked, so much as the Stitches team has been focused elsewhere; to my knowledge, it is not an intentional blocking. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we add tests for the feature?
I can take over a unit test.
Oh, good point. I think I had done so already in my old commit; I'll see if I can find them and add them here. Thanks! |
packages/core/src/features/css.js
Outdated
const createComposer = (/** @type {InitComposer} */ { variants: initSingularVariants, compoundVariants: initCompoundVariants, defaultVariants: initDefaultVariants, ...style }, /** @type {Config} */ config) => { | ||
const createComposer = (/** @type {InitComposer} */ { variants: initSingularVariants, compoundVariants: initCompoundVariants, defaultVariants: initDefaultVariants, componentName, ...style }, /** @type {Config} */ config) => { | ||
/** @type {string} */ | ||
const hash = componentName ? `${componentName}-${toHash(style)}` : toHash(style) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe componentName
is not a part of the hash.
It probably should be something like
const className = toTailHash(config.prefix) + ['c', componentName, toHash(style)].filter(Boolean).join('-');
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I understand you correctly (and I'm not sure I do), I think both pieces of code are doing the same thing; it's just my use of a variable name hash
that is causing confusion.
My code is equivalent to doing this (note the change from hash
to baseClass
):
let baseClass = toHash(style)
if (componentName) {
baseClass = `${componentName}-${baseClass}`
}
const className = `${toTailDashed(config.prefix)}c-${baseClass}`
So in both your code and mine, the componentName
is getting conditionally added after the prefix and c-
, but before the generated hash.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But I'll change the name of the variable, to avoid confusion. Let me know if you're okay with that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, they're doing the same thing, my note was about naming.
Thanks!
I've added some tests to both |
Hope this PR gets merged soon |
@guipolitano Sadly, i don't think it's possible to get this merged as is as the API conflicts with another stitches API which is composing n number of styles into one component
To be clear, We love this feature and we know how important it is for the reasons outlined in the PR but we just need to think more about the API in order to maintain the DX that everyone loves about Stitches We will think more about this and hopefully come back with a plan/decision for the API sometime next week and discuss it with @LucasUnplugged and everyone in here. |
@hadihallak my code shouldn't conflict with that usage, because it only applies if there are at least 2 arguments, and the last argument is a string. In your example, only the first argument is a string, so it should still work as intended. |
That's true but it's re-using the same API which we've so far only reserved for styling so i'm wondering if we can do it differently so that it can be more clearly documented and easily readable for someone who isn't familiar with Stitches and reading the code for the first time Maybe we could add a method or something similar that more explicitly tells the user what's going on behind the scenes. |
That makes sense, @hadihallak. Something like this would indeed be clearer:
I'm not even sure if that's (realistically) possible, so didn't even attempt it. |
Sadly =/. |
@guipolitano |
Understood, hope you guys find a way. Thx for the great job, im loving to use Stitches with Radix. :) |
Closing in favor of #1005 |
Closing the loop here: |
(Addresses #650)
I'm giving this one another try, with the latest version (plus my suggested fixes from PRs #893 and #900).
I've been working from a build off this branch for a couple of weeks now, with no adverse side-effects. This has resulted in this kind of rendered HTML:
...which at this point, my brain quickly reads as (by ignoring the hashes):
I find that vastly more helpful, for debugging purposes, than a sea of hashed classes that mean nothing to me.
Proposed API
Users can pass in a string as the last parameter of their calls to
styled
, like so:This proposed solution can be combined with a babel plugin, to make friendly class names possible with no extra effort, for those using Babel.
Related Discussion
There was a related discussion at #677, but the solution proposed there by the Stitches team (
defaultProps
) was removed from the v1 API.