Make the class name meaningful rather than random numbers and letters. #439
-
I already saw some related issues that were closed, but hope this would help with the reasoning behind the ask... When I code sometimes I want to have named css in my app so that I can easily find it in the dom and for demos and dynamically show my customer the variations in css as below code snippet shows ( I have way oversimplified the example for clearer understanding): /* 2023-08-25 - JMK - CSS - Demo bigger image */ /* 2023-08-26 - JMK - CSS - Demo current image size for title with a border / Suggestion is to put short meaningful name like in followed by the random part as you already have talked about in the fluent-ui video 3 So the class names could result in something like the following: .pl-10-randomnum { padding-left: 10px; } would be nice if could refer the to first unique part and if that is pl-10 vs c-red then it would be great as in below: That would be better than a random number... I like all of the existing features where I can create javascript objects, just suggesting changing the class name to be more meaningful and thus easier to use and search on the final html page doc. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Hey, There multiple reasons why we can't use anything human readable, mainly it's complexity and bundle size. Let me provide multiple examples: makeStyles({
root: { color: 'red' }
});
// ⬇️⬇️⬇️
// .cred { color: red } In the simple example it looks fine 👍 But what about usage of rbga values or CSS variables? ⬇️ makeStyles({
rootA: { color: 'rgba(255,0,0,0.3)' },
rootB: { color: 'var(--colorNeutralForeground1)' }
});
// ⬇️⬇️⬇️
// .c25500003 { color: rgba(255,0,0,0.3) } 🤔
// .cvarcolorNeutralForeground1 { color: var(--colorNeutralForeground1) } 🤔 Okay, but what about properties themselves? Let's assume what use first letter and other capitals to generate classes: makeStyles({
rootA: { fontStretch: 'initial' },
rootB: { fontSize: 'initial' }
});
// ⬇️⬇️⬇️
// .fs-initial { font-stretch: initial }
// .fs-initial { font-size: initial } 💣 oops, collision Do we need a dictionary for this case? 😱 We also need classes for nested selectors and media queries: makeStyles({
':before': { content: '""' },
},
root: {
'@media(forced-colors: active)': { color: 'red' },
},
}); What to do there? 🤔 The described approach has problems as you see and once we ago going to complex it's not really meaningful. On other side, hashes don't exceed 8 chars, deterministic and don't have collisions ¯_(ツ)_/¯ To simplify debugging, we created devtools that we suggest to use (https://chrome.google.com/webstore/detail/griffel-devtools/bejhagjehnpgagkaaeehdpdadmffbigb) instead of dealing with atomic classes. |
Beta Was this translation helpful? Give feedback.
Hey,
There multiple reasons why we can't use anything human readable, mainly it's complexity and bundle size. Let me provide multiple examples:
In the simple example it looks fine 👍 But what about usage of rbga values or CSS variables? ⬇️
Okay, but what about properties themselves? Let's assume what use first letter and other capitals to generate classes: