use crate::hook::TagInputState;
use crate::tag::TagLike;
use dioxus::prelude::*;
#[derive(Props, Clone, PartialEq)]
pub struct TagRemoveProps<T: TagLike + 'static> {
pub tag: T,
#[props(default)]
pub children: Option<Element>,
#[props(extends = GlobalAttributes)]
pub attributes: Vec<Attribute>,
}
pub fn TagRemove<T: TagLike>(props: TagRemoveProps<T>) -> Element {
let mut ctx = use_context::<TagInputState<T>>();
let is_disabled = *ctx.is_disabled.read() || *ctx.is_readonly.read();
let tag_id = props.tag.id().to_string();
let label = format!("Remove {}", props.tag.name());
rsx! {
button {
r#type: "button",
aria_label: "{label}",
tabindex: "-1",
disabled: is_disabled,
"data-slot": "tag-remove",
"data-disabled": is_disabled,
onmousedown: move |evt: Event<MouseData>| {
evt.prevent_default();
ctx.remove_tag(&tag_id);
},
..props.attributes,
if let Some(children) = props.children {
{children}
} else {
{"\u{00D7}"}
}
}
}
}