DEV Community

Discussion on: Easy Inline CSS3 Lookups in JavaScript

Collapse
 
isaachagoel profile image
Isaac Hagoel

Cool writeup. It is similar to how we normally handle any other strings that need to be used in multiple places (theme related stuff, event names, enums etc.) - dy defining constants.

Some random thoughts:

  1. About the holy-wars, putting libraries like 'styled-components' asaide, inline-css is a must when assigning a dynamically calculated numeric values. For example, in the fancy drag and drop library the x and y transforms for the object being dragged and the objects that make room for it are all inlined.
  2. Bundle size will increase because of this. Sometimes it matters, sometimes not so much.
Collapse
 
bytebodger profile image
Adam Nathaniel Davis

One more note on bundle size. If I were to put this into a proper NPM "package", I could create deploy hooks that would essentially empty out the lookup class and replace the code with the raw text/number values for the CSS properties. But, for the time being, that kinda feels like overkill and I don't have the time to dive into that...

Collapse
 
isaachagoel profile image
Isaac Hagoel

Another interesting option might be an IDE plug-in.
It could also maybe provide some documentation for each attribute/ value on the fly.
But yhea.. probably an overkill :)

Thread Thread
 
isaachagoel profile image
Isaac Hagoel
Thread Thread
 
bytebodger profile image
Adam Nathaniel Davis

Ideally, the plugin would be configurable, so you could drop in any object that would serve as a kinda "definition file". It could then be used in your autocompletes without needing to be bundled into the code itself.

It should be configurable, because even if this plugin worked beautifully, I'd hate to have to write another plugin (or find another one out there on the interwebs) the next time I have another set of commonly-used constants that I want to autocomplete.

Collapse
 
bytebodger profile image
Adam Nathaniel Davis • Edited

Thanks again for the thoughtful feedback!

You're absolutely right that, when you boil it down, this is just a basic shared constant. I'm just amazed/annoyed sometimes when I realize that there are no "pre-baked" constants for the important shit that I find myself googling over and over and over...

  1. Totally agree about the inline-styling necessities (at times). I put that Holy War caveat in the article because, amongst some people, you simply cannot have an intelligent conversation about inline styles (especially, in React) without some pedantic jerk trying to shout you down. There's a whole other article on the horizon about this exact topic... One of my favorite (and simplest) justifications for inline React styles something like this: display : someCondition ? 'inherit' : 'none'. There's just no way that I'm gonna try to pack that away into two conditional CSS classes.

  2. Good point about bundle size. I will freely admit that, more often than not, I pay this little attention, because in today's high-bandwidth environment, I feel that this is usually a "micro-optimization". But that's not meant to discount your accurate observation. Like any other library/class/utility that is providing nothing more than syntactic convenience, it's always a good idea to at least be aware of the cost in package size.

Collapse
 
isaachagoel profile image
Isaac Hagoel

BTW, I do agree with the problem statement :)
I forgot to say in the original comment.
Remembering all of these css attributes and values and what they all do is like trying to memorize an encyclopedia.