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")
Will open issue if reception is positive :)
there is class="" now
i use the helix.dom
macros everywhere so I don’t really see much use
@lilactown (d/div {:class "foo bar baz-bosh"})
vs ($ "div.foo.bar.baz-bosh")
- really just for reducing typing I guess.
at least for the simple case of no properties. I'm very greenfield, so I do a lot of translating html into react.
yeah, that makes sense if you’re doing a lot of html->helix and back
I certainly used that feature a lot more in server-side hiccup
IME building an app, you typically end up needing something to compose class names together
e.g. at both gigs I’ve used CLJS at, I wrote a small wrapper around emotion.js
Reagent does a pretty fine job of this tbh.
in order to get sane precedence rules, you need to use emotion/cx
to combine classes which means you can’t use the shorthand
[:div {:class (style/cx class1 class2 class3)}
,,,]
I distinctly don't want to use css-in-js 😁. Not sure what cx does, but would [class1 class2 class3]
have worked there too?
Yeah, looks like it would have.
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
ah, I see.
and that would create a new class. Got it.
yeah
writing them as [class1 class2 class3]
would use CSS precedence which means whatever order they were defined in
Anyway - I'm not using css-in-js, and don't intend to.
I think manual is fine for that case. This is really to optimize for "doing normal css stuff".
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 itthis 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 😛
Sounds like a plan. Is add-class gonna be a pain to write with all the js object possibilities?
at the macro phase, maybe-props
should be either a map or Something Else:tm:
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 " " %))))
helix does not support {:class ["a" nil]}
then?
(I'm about to advocate for it to 😛)
I merged support that into master last week
haven’t done a release yet
aha, okay :). So I'll need to handle both, np.
ah right