-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Dynamic Prop Labels #3509
base: master
Are you sure you want to change the base?
Dynamic Prop Labels #3509
Conversation
Visit the preview URL for this PR (updated for commit 5fc9058): https://yew-rs-api--pr3509-dyn-prop-0vcn3vrd.web.app (expires Mon, 04 Dec 2023 08:06:38 GMT) 🔥 via Firebase Hosting GitHub Action 🌎 |
My local setup told me nothing about which Rust version is used, wow... Fixing 1.64.0 compiler support shortly I guess, there is nothing special, just |
Size Comparison
✅ None of the examples has changed their size significantly. |
Benchmark - SSRYew Master
Pull Request
|
Uh sorry, will check what it fails on tomorrow |
Wow, I passed even the benchmark lol |
Allows not only literals, e.g. "hx-on:click", but all expressions
You need both passing and failing tests for it. You can copy a |
If there are any |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome! I need this. At the moment I'm building the component linearGradient
manually and it's such a pain
#[function_component(LinearGradient)]
pub fn linear_gradient(
Props {
id,
gradient_transform,
children,
}: &Props,
) -> Html {
let mut vtag = yew::virtual_dom::VTag::new("linearGradient");
vtag.add_children(children.clone());
vtag.add_attribute("id", id.clone());
if let Some(x) = gradient_transform.clone() {
vtag.add_attribute("gradientTransform", x);
}
vtag.into()
}
Now with autoprops + dyn prop labels, I can simplify this code a lot
I tried to add following to the // property literal
_ = ::yew::html! { <span ~"hx-on:click"="alert('Clicked!')" /> };
_ = ::yew::html! { <span ~"hx-on:click"="alert('Clicked!')" ~"hx-on:click"="alert('Clicked!')" /> };
_ = ::yew::html! { <span ~{ "hx-on:click" }={ "alert('Clicked!')" } /> };
_ = ::yew::html! { <span ~{ "hx-on:click" }={ "alert('Clicked!')" } ~{ "hx-on:click" }={ "alert('Clicked!')" } /> };
// property expr
_ = ::yew::html! { <span ~{ dyn_prop() }={ "alert('Clicked!')" } /> };
_ = ::yew::html! { <span ~{ dyn_prop() }={ "alert('Clicked!')" } ~{ dyn_prop() }={ "alert('Clicked!')" } /> }; Tests (
As I was trying to find out whether any tests would help me figure out how to test the feature, I performed a quick search on all tests, only to find out that nobody tested |
Description
Partially implements features from discussion #3477. This PR adds Dynamic Prop Labels, so that anyone can write their favorite attributes like HTMX's
hx-on:click
:It works by using new
PropLabel
enum everywhere, which can be either aStatic
HtmlDashedName
like before, orDynamic
Expr
. When parsing, if it meets=
token after the expression group, it will read a value following it instead of assuming that it is shorthand syntax.Checklist