use leptos::{ev, html, prelude::*};
use super::arrow::arrow_style;
use super::positioning::OverlayPlacementInjection;
#[derive(Clone, Copy)]
pub struct OverlayArrowInjection {
pub node_ref: NodeRef<html::Div>,
}
#[derive(Clone, Copy)]
pub struct OverlayPanelInjection {
pub panel_ref: NodeRef<html::Div>,
pub on_mouse_enter: Callback<ev::MouseEvent>,
pub on_mouse_leave: Callback<ev::MouseEvent>,
}
#[component]
pub fn OverlaySurface(
#[prop(into)] class: Signal<String>,
#[prop(optional, into)] role: MaybeProp<String>,
children: Children,
) -> impl IntoView {
let panel = expect_context::<OverlayPanelInjection>();
let placement_ctx = use_context::<OverlayPlacementInjection>();
let arrow = use_context::<OverlayArrowInjection>().map(|inj| {
view! {
<div
class="orbital-popover-surface__angle"
style=arrow_style()
node_ref=inj.node_ref
></div>
}
.into_any()
});
view! {
<div
class=class
role=role
node_ref=panel.panel_ref
on:mouseenter=move |e| panel.on_mouse_enter.run(e)
on:mouseleave=move |e| panel.on_mouse_leave.run(e)
prop:data-orbital-placement=move || {
placement_ctx
.map(|ctx| ctx.placement_label.get())
.unwrap_or_default()
}
>
{arrow}
{children()}
</div>
}
}