use dioxus::prelude::*;
#[component]
pub fn ContextMenu(
children: Element,
x: f64,
y: f64,
on_close: EventHandler<()>,
) -> Element {
rsx! {
div {
class: "context-menu-overlay",
onclick: move |_| on_close.call(()),
div {
class: "context-menu",
style: "left: {x}px; top: {y}px;",
onclick: move |evt| evt.stop_propagation(),
{children}
}
}
}
}
#[component]
pub fn ContextMenuItem(
label: String,
#[props(default = false)] danger: bool,
#[props(default = false)] disabled: bool,
onclick: EventHandler<()>,
) -> Element {
let class = if danger {
"context-menu__item context-menu__item--danger"
} else if disabled {
"context-menu__item context-menu__item--disabled"
} else {
"context-menu__item"
};
rsx! {
button {
class: "{class}",
disabled: disabled,
onclick: move |_| onclick.call(()),
"{label}"
}
}
}