css

For all your CSS related content...
leontalbot 2018-05-23T19:57:42.000091Z

Hello guys, quick question: If you were asked to make .cljc web components packaged as a library for both reagent and server-side hiccup. What would be your strategy, especially for handling styling/css? Any examples out there?

leontalbot 2018-05-23T19:57:45.000496Z

thanks!

niamu 2018-05-23T20:06:36.000635Z

@leontalbot Are you familiar with garden (https://github.com/noprompt/garden)?

leontalbot 2018-05-23T20:07:02.000274Z

I am a bit. Never used though

leontalbot 2018-05-23T20:07:08.000122Z

do you?

niamu 2018-05-23T20:08:20.000190Z

Yeah, I’ve used it quite a bit. I like it a lot and works nicely as a *.cljc library.

niamu 2018-05-23T20:08:50.000470Z

But, let’s talk about what you’re expecting the library to do on the front-end.

niamu 2018-05-23T20:09:08.000565Z

Is it necessary for reagent components to inline/embed styles?

leontalbot 2018-05-23T20:28:03.000036Z

Thanks @niamu for your help! Could the required component lib add css files to consuming project?

leontalbot 2018-05-23T20:28:21.000229Z

And if so, do you think it is a good idea?

niamu 2018-05-23T20:33:26.000280Z

I’m of the opinion that CSS should only ever be served from the server and shouldn’t live in the front-end at all. If you keep things separated that way, then everything is always server-side renderable which is advantageous and the only remaining concern as I see it is keeping track of which classes/IDs to use in your markup.

niamu 2018-05-23T20:35:55.000750Z

I don’t really have advice for managing the implicit relationship between the CSS markup and your HTML markup though. There are people who will recommend strategies like BEM (http://getbem.com) but it’s really just a collection of naming conventions that help make it easier to connect those implicit relationships.

leontalbot 2018-05-23T20:37:14.000732Z

ok. When you build library components you almost always add or modify css

niamu 2018-05-23T20:40:15.000379Z

Keeping in mind I haven’t actually built a component library, my off-hand strategy would be to have the library serve the components that are just React components without style information in them (just references to classes) and then separately serve CSS via Garden which would allow someone to only refer to the component styles that they are using.

niamu 2018-05-23T20:40:47.000649Z

That would allow easy theming possibilities later as you could swap out alternate styles as needed.

mattly 2018-05-23T20:41:13.000435Z

you can also avoid the naming problems altogether: https://johnpolacek.github.io/the-case-for-atomic-css/

mattly 2018-05-23T20:44:14.000101Z

I’ve been working on a utility class generator with garden but it’s nowhere near prime-time

leontalbot 2018-05-23T20:45:01.000082Z

I understand that having a separate project for css is a good option, but not sure for our needs (constant addition of small components that we want independant)

leontalbot 2018-05-23T20:45:44.000441Z

I suppose prefixing classes could avoid conflicts?

niamu 2018-05-23T20:45:48.000320Z

Yeah, perhaps investigating Atomic CSS is a good idea then since the coupling of style with markup is actually what you’re trying to achieve.

mattly 2018-05-23T20:47:21.000357Z

in addition to garden there’s also https://github.com/roman01la/cljss

theeternalpulse 2018-05-25T02:33:01.000298Z

This is interesting, I think I'm going to switch to this, I had to do some manual hoisting of local css objects to a header tag that's not very convenient or sutstaniable. This has exactly what I need.

mattly 2018-05-23T20:47:37.000653Z

which might be a good fit for what you’re trying to do

mattly 2018-05-23T20:48:00.000100Z

I have a side-project that’s got shared view code for three targets: web, electron, and react native

mattly 2018-05-23T20:48:15.000424Z

and once you start getting into react native, there is no “markup” to couple style to

mattly 2018-05-23T20:48:26.000638Z

and no such thing as style sheets

mattly 2018-05-23T20:49:08.000465Z

and once I embraced the idea that I could get rid of the indirection layer that “semantic classes” produced it became a lot easier

niamu 2018-05-23T20:59:47.000079Z

React Native compatibility is a strong argument.

👍 1
mattly 2018-05-23T21:01:20.000024Z

it’s not so much line-by-line technical compatibility as it is mindset compatibility

niamu 2018-05-23T21:02:49.000506Z

For completeness, I’ll say the 2 main benefits of an external stylesheet as I see it is theming and deduplication of data. But an external stylesheet does have trade-offs long-term maintenance and raises the barrier to understanding how style is affecting a component.

👍 1
niamu 2018-05-23T21:04:45.000378Z

I agree with @mattly that you’ll probably want to explore something akin to Atomic CSS for your purposes though.

leontalbot 2018-05-23T21:28:05.000017Z

cljss seams only for cljs

leontalbot 2018-05-23T21:28:05.000328Z

https://github.com/roman01la/cljss/issues/29

leontalbot 2018-05-23T21:28:35.000517Z

I also found this

leontalbot 2018-05-23T21:28:37.000055Z

https://github.com/thheller/shadow/wiki/shadow.markup

leontalbot 2018-05-23T21:28:46.000448Z

seems not largely used though?

felipebarros 2018-05-23T21:31:12.000401Z

Can you digress a bit more on this?

mattly 2018-05-23T22:33:28.000002Z

I think it’s like the difference between OOP and FP

mattly 2018-05-23T22:34:05.000090Z

“semantic” css classnames are a bit like OOP classes in that you’re typically naming something for what it is rather than what it does

mattly 2018-05-23T22:34:54.000171Z

and naming is really hard, and gets in the way of reusability

mattly 2018-05-23T22:34:59.000047Z

and composability

mattly 2018-05-23T22:35:41.000081Z

if you instead name something for what it does, that forces you to keep what it does small and specific

mattly 2018-05-23T22:35:52.000202Z

and therefore reusable and composable

mattly 2018-05-23T22:35:57.000128Z

similar to functions 😄