tallyweb_components/
lib.rs

1#![feature(let_chains)]
2
3mod loading_screen;
4mod message;
5mod progressbar;
6mod resizebar;
7mod saving_screen;
8mod select;
9mod sidebar;
10mod slider;
11mod spinner;
12mod time;
13mod tooltip;
14mod treeview;
15
16pub use loading_screen::*;
17pub use message::{MessageKey, ProvideMessageSystem};
18pub use progressbar::*;
19pub use resizebar::{Direction, ResizeBar};
20pub use saving_screen::*;
21pub use select::{Select, SelectOption};
22pub use sidebar::*;
23pub use slider::*;
24pub use spinner::*;
25pub use time::{Clock, Timer};
26pub use tooltip::*;
27pub use treeview::*;
28
29pub type MessageJar = message::MessageJar<message::NoHandle>;
30
31use leptos::{logging::warn, *};
32
33#[derive(Debug, Clone)]
34pub struct CloseOverlays();
35
36#[component]
37pub fn Overlay(
38    #[prop(attrs)] attrs: Vec<(&'static str, Attribute)>,
39    show_overlay: RwSignal<bool>,
40    location: ReadSignal<(i32, i32)>,
41    children: ChildrenFn,
42) -> impl IntoView {
43    if let Some(close_signal) = use_context::<RwSignal<CloseOverlays>>() {
44        create_effect(move |_| {
45            close_signal.track();
46            show_overlay.set(false);
47        });
48    } else {
49        warn!("No `close overlay` signal available");
50    }
51
52    let location_style = move || {
53        format!(
54            "left: {}px; top: {}px;",
55            location().0 + 10,
56            location().1 + 10
57        )
58    };
59
60    view! {
61        <Show when=move || { show_overlay.get() } fallback=|| ()>
62            <div style=location_style() {..attrs.clone()}>
63                {children()}
64            </div>
65        </Show>
66    }
67}