ml-in-barcelona / jsoo-react

js_of_ocaml bindings for ReactJS. Based on ReasonReact.
https://ml-in-barcelona.github.io/jsoo-react
MIT License
138 stars 19 forks source link

dsl: add classNames helper to Html and Svg props #157

Closed glennsl closed 2 years ago

glennsl commented 2 years ago

I've found it very useful to be able to pass a list of class names, rather than having to build a class string manually. This is the simplest version of that, but I could imagine something more sophisticated to support optional class names for example.

Currently, to pass an optional class name you'd have to do something like:

div [| classNames [ "widget"; if disabled then "disabled" else "" ] |] [ ... ]

but could perhaps instead be:

div [| classNames [ "widget"; class_if disabled "disabled" ] |] [ ... ]

But this could be added in a way that maintains backwards-compatibility, so not all that important to do now I think.

jchavarri commented 2 years ago

Yeah I like that this is the minimal expression.

I could imagine something more sophisticated to support optional class names for example

Do you think this should be part of jsoo-react? Or rather a 3rd party lib like rescript-classnames ?

glennsl commented 2 years ago

Do you think this should be part of jsoo-react? Or rather a 3rd party lib like rescript-classnames ?

I'm thinking it might as well be, since I imagine pretty much everyone would want this. Depends a bit on how opinionated the solution is though. Could also do a halfway solutions by putting it in a separate namespace, temporarily or permanently. but either way there's no rush I think.