Generating user-friendly class names #677
Replies: 2 comments 2 replies
-
Hi, thanks so much for kicking this off. I agree that allowing users to provide a friendly class name is a good idea! I like your proposal, but the I have a couple of ideas that I'd like feedback on: Introduce
|
Beta Was this translation helpful? Give feedback.
-
Linking my latest proposal PR for this here as well: #916. |
Beta Was this translation helpful? Give feedback.
-
Hi all! 👋🏻 I'm new to the Stitches community, but feel like I'm hooked! 😁
I've been having a conversation with @peduarte and @afzalsayed96 in this (closed) issue and, as suggested, am moving the convo onto a discussion thread.
Overview
The core of what is being discussed is the generation of user-friendly class names, which would make it easier to debug the rendered code, by letting us know where each class is coming from.
Also at the core is if/how this might change the Stitches API, and whether that's desirable.
A semi-related (though slightly different) part of the conversation has been about setting the component
displayName
, which is handy when inspecting the code via React Dev Tools. @afzalsayed96 has already created a babel plugin for that — which is awesome, though doesn't address the class name issue.Proposal
Here's what I'm proposing, as seen in this commit to my fork:
styled
function would have an optional 3rd param (string), which could be used to generate friendly names.displayName
property.Usage
Usage (possibly done through a plugin) would be as simple as:
Output
I've tested this with a local build, and it worked beautifully, with an output such as:
And a React Dev Tools output of:
And a Chrome dev tools output of:
That looks pretty sweet to me, and would make understanding where each style is coming from (via the class names) very easy.
NOTE that the
Header
is composed ofstyled
components, in this sequence:Beta Was this translation helpful? Give feedback.
All reactions