Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pass class and id via shorthand in $ #81

Open
SevereOverfl0w opened this issue Apr 22, 2021 · 4 comments
Open

Pass class and id via shorthand in $ #81

SevereOverfl0w opened this issue Apr 22, 2021 · 4 comments

Comments

@SevereOverfl0w
Copy link
Contributor

I propose that $ support the following: ($ "div.foo.bar#unique#id" {} …) where {:class ["foo" "bar"] :id "unique id"} would be set as a result of this.

Many hiccup-inspired tools utilize this kind of syntax, for example Reagent. The shorthand makes it a lot easier to sell a team on Helix that is currently using something with "less typing".

We've been using a $-wrapping macro at work since using Helix (~6 months at least) and have not found any downsides yet. Our code is definitely shorter! :)

@lilactown
Copy link
Owner

This seems specific to the web DOM, so I think this would be a good addition to the helix.dom/$d macro, rather than the helix.core/$.

@SevereOverfl0w
Copy link
Contributor Author

There's an implementation of this in https://git.sr.ht/~severeoverfl0w/helix-sev

@lilactown
Copy link
Owner

lilactown commented Jun 4, 2021

Very nice! Question:

($d :div.foo.bar {& {:class "baz"}} ,,,)

based on my read of your code as-is, the dynamic prop :class will overwrite the class assoced onto the props map. This is because (helix detail) dynamic props are merged in after macro expansion, in something like:

(react/createElement "div" (merge-props #js {:class "foo bar"} {:class "baz"}) ,,,)

It's not clear to me what the correct behavior is here. what do you think?

@SevereOverfl0w
Copy link
Contributor Author

@lilactown You're right, that's a limitation right now. It has that limitation because I didn't think it was possible to implement things such that this limitation wouldn't exist. I think there're two behaviours here that make sense:

  • Behave like {:class "foo bar" :& {:class "baz"}} would
  • Always append the root onto the resulting props, no matter what.

If :&, &, etc. are present, we could wrap the expression such that the classes are appended. If they aren't present, then we do the current implementation?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants