mirror of
https://github.com/leptos-rs/leptos
synced 2024-11-10 06:44:17 +00:00
This commit is contained in:
parent
84590b98ed
commit
27dbadb7d2
2 changed files with 11 additions and 7 deletions
|
@ -53,7 +53,6 @@ impl From<()> for Amount {
|
|||
}
|
||||
}
|
||||
|
||||
// .into() will automatically be called on the parameter
|
||||
pub fn add_dot(el: Element, amount: Amount) {
|
||||
use leptos::wasm_bindgen::JsCast;
|
||||
let el = el.unchecked_into::<web_sys::HtmlElement>();
|
||||
|
@ -82,12 +81,17 @@ pub fn App() -> impl IntoView {
|
|||
let data = "Hello World!";
|
||||
|
||||
view! {
|
||||
<a href="#" use:copy_to_clipboard=data>"Copy \"" {data} "\" to clipboard"</a>
|
||||
<a href="#" use:copy_to_clipboard=data>
|
||||
"Copy \""
|
||||
{data}
|
||||
"\" to clipboard"
|
||||
</a>
|
||||
// automatically applies the directive to every root element in `SomeComponent`
|
||||
<SomeComponent use:highlight/>
|
||||
// no value will default to `().into()`
|
||||
<button use:add_dot>"Add a dot"</button>
|
||||
// `5.into()` automatically called
|
||||
<button use:add_dot=5>"Add 5 dots"</button>
|
||||
// can manually call `.into()` to convert to the correct type
|
||||
// (automatically calling `.into()` prevents using generics in directive functions)
|
||||
<button use:add_dot=5.into()>"Add 5 dots"</button>
|
||||
}
|
||||
}
|
||||
|
|
|
@ -520,7 +520,7 @@ pub(crate) fn attribute_absolute(
|
|||
} else if id == "use" {
|
||||
let key = &parts[1];
|
||||
let param = if let Some(value) = node.value() {
|
||||
quote!(::std::convert::Into::into(#value))
|
||||
quote!(#value)
|
||||
} else {
|
||||
quote_spanned!(node.key.span()=> ().into())
|
||||
};
|
||||
|
@ -1071,7 +1071,7 @@ pub(crate) fn directive_call_from_attribute_node(
|
|||
let handler = syn::Ident::new(directive_name, attr.key.span());
|
||||
|
||||
let param = if let Some(value) = attr.value() {
|
||||
quote!(::std::convert::Into::into(#value))
|
||||
quote!(#value)
|
||||
} else {
|
||||
quote_spanned!(attr.key.span()=> ().into())
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue