helix

https://github.com/Lokeh/helix
dominicm 2020-05-12T15:18:00.286700Z

I think I let this get lost in history, what's the thoughts on $ supporting class names in the type string? e.g. ($ "div.foo.bar.baz-bosh")

dominicm 2020-05-12T15:18:30.286900Z

Will open issue if reception is positive :)

Aron 2020-05-12T15:18:42.287100Z

there is class="" now

lilactown 2020-05-12T15:19:20.287500Z

i use the helix.dom macros everywhere so I don’t really see much use

dominicm 2020-05-12T15:24:16.287600Z

@lilactown (d/div {:class "foo bar baz-bosh"}) vs ($ "div.foo.bar.baz-bosh") - really just for reducing typing I guess.

dominicm 2020-05-12T15:24:47.288Z

at least for the simple case of no properties. I'm very greenfield, so I do a lot of translating html into react.

lilactown 2020-05-12T15:25:14.288400Z

yeah, that makes sense if you’re doing a lot of html->helix and back

lilactown 2020-05-12T15:25:23.288700Z

I certainly used that feature a lot more in server-side hiccup

lilactown 2020-05-12T15:25:51.289200Z

IME building an app, you typically end up needing something to compose class names together

lilactown 2020-05-12T15:26:06.289600Z

e.g. at both gigs I’ve used CLJS at, I wrote a small wrapper around emotion.js

dominicm 2020-05-12T15:26:22.290Z

Reagent does a pretty fine job of this tbh.

lilactown 2020-05-12T15:26:43.290400Z

in order to get sane precedence rules, you need to use emotion/cx to combine classes which means you can’t use the shorthand

lilactown 2020-05-12T15:26:59.290900Z

[:div {:class (style/cx class1 class2 class3)}
 ,,,]

dominicm 2020-05-12T15:27:33.291Z

I distinctly don't want to use css-in-js 😁. Not sure what cx does, but would [class1 class2 class3] have worked there too?

dominicm 2020-05-12T15:28:44.291600Z

Yeah, looks like it would have.

lilactown 2020-05-12T15:28:51.291800Z

it would not work the same; the CSS-in-JS solution would do a merge of those styles, using the order I wrote them as precedence

dominicm 2020-05-12T15:29:02.292100Z

ah, I see.

dominicm 2020-05-12T15:29:09.292300Z

and that would create a new class. Got it.

lilactown 2020-05-12T15:29:14.292500Z

yeah

lilactown 2020-05-12T15:29:29.292900Z

writing them as [class1 class2 class3] would use CSS precedence which means whatever order they were defined in

dominicm 2020-05-12T15:29:40.293100Z

Anyway - I'm not using css-in-js, and don't intend to.

dominicm 2020-05-12T15:30:33.293400Z

I think manual is fine for that case. This is really to optimize for "doing normal css stuff".

lilactown 2020-05-12T15:32:54.295300Z

my suggestion would be to create a macro that wraps $:

(defmacro $
  [type maybe-props & args]
  (let [[type' class-string] (process-class type)
        maybe-props' (add-class maybe-props class-string)]
   `(helix/$ ~type' ~maybe-props' ~@args)))
and if you find this works really well, I would think about taking a PR for it

lilactown 2020-05-12T15:34:51.295900Z

this isn’t the first time someone has asked about this so, I’m willing to accept it might just be a use case I don’t have - doesn’t make it invalid 😛

dominicm 2020-05-12T15:40:53.296Z

Sounds like a plan. Is add-class gonna be a pain to write with all the js object possibilities?

lilactown 2020-05-12T15:45:13.296600Z

at the macro phase, maybe-props should be either a map or Something Else:tm:

lilactown 2020-05-12T15:47:10.298500Z

so add-class could probably be something like:

(defn add-class
  [props class]
  (if-not (and (map? props) (some? class))
    props
    (update props :class #(str class " " %)))) 

dominicm 2020-05-12T16:08:14.298700Z

helix does not support {:class ["a" nil]} then?

dominicm 2020-05-12T16:08:43.298800Z

(I'm about to advocate for it to 😛)

lilactown 2020-05-12T16:09:28.299100Z

I merged support that into master last week

lilactown 2020-05-12T16:09:33.299300Z

haven’t done a release yet

dominicm 2020-05-12T16:13:44.299400Z

aha, okay :). So I'll need to handle both, np.

lilactown 2020-05-12T16:14:06.299600Z

ah right