question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Generating and applying reusable single purpose classes rather than unique id classnames

See original GitHub issue

Is your feature request related to a problem? No, rather an idea.

Describe the solution you’d like So you may have heard about css tachyons, which is basically single purpose utility classes. Now remembering such tachyon names while programming is not what you want to do.

So while implementing my own html rendering library, I started generating such single purpose classes from style object in js. It also supports media queries. (I did not know about CSS-in-JS at the time). My code for generating css and classnames is spaghetti code 😃 So I was thinking what if a jss plugin could be written that did a better job than my code.

Example:

{
    display: 'flex'
}

Becomes:

.d-f{display:flex}

This means that any element that uses flex will simply have the class “d-f”. The size of css becomes minimalistic, while the number of classes per element grows a bit 😉

There are more advanced examples here:

Perhaps there is some other framework (that I could not find) plugged into react that already does this? It would be nice to not be limited to React and do SSR.

Perhaps even compile time (though thats not to applicable for dynamic components where styling changes depending upon props).

Are you willing to implement it? Yes, but can I 😃

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:21 (10 by maintainers)

github_iconTop GitHub Comments

1reaction
kofcommented, Aug 21, 2018

I think you are talking about atomic css. I think you could achieve that with a plugin. The question is why? Usually with this model people try to reduce css payload. Also it allows a different caching strategy. At the same time it brings a bunch of problems.

0reactions
kofcommented, Sep 15, 2018

I think we can close this issue since it is not really actionable. The idea of rendering to atomic css is not new and if someone finds time I am happy to restart this discussion.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Delightful ways to write reusable CSS using subclasses
Let's talk about how to recognize patterns in your CSS, and how to create reusable, flexible styles by using CSS subclasses.
Read more >
CSS Class Selectors: How to Use to Style an HTML Element
Do you want to stylize HTML elements without hassle? CSS classes will help you do the job! Here, you'll learn how to use...
Read more >
Reusing Styles - Tailwind CSS
Managing duplication and creating reusable abstractions. Tailwind encourages a utility-first workflow, where designs are implemented using only low-level ...
Read more >
CSS Id vs Class: Reasons not to use IDs in CSS
This means that if you attach a style to an ID, you won't be able to reuse it within the same webpage. Classes,...
Read more >
The Difference Between ID and Class | CSS-Tricks
Classes has you covered there, as you can apply more than one class: ... but it also has a unique ID value (dynamically...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found