tallyweb_components/
resizebar.rs1use leptos::*;
2
3#[derive(Debug, Clone, Copy, Default)]
4pub enum Direction {
5 #[default]
6 Vertical,
7 Horizontal,
8}
9
10#[component]
11pub fn ResizeBar(
12 direction: Direction,
13 #[prop(into)] position: MaybeSignal<usize>,
14 #[prop(attrs)] attrs: Vec<(&'static str, Attribute)>,
15) -> impl IntoView {
16 let cursor = match direction {
17 Direction::Vertical => "col-resize",
18 Direction::Horizontal => "row-resize",
19 };
20
21 let width = match direction {
22 Direction::Vertical => "12px",
23 Direction::Horizontal => "100%",
24 };
25
26 let height = match direction {
27 Direction::Vertical => "100%",
28 Direction::Horizontal => "12px",
29 };
30
31 let pos = move || match direction {
32 Direction::Vertical => (None, Some(format!("{}px", position() - 6))),
33 Direction::Horizontal => (Some(format!("{}px", position() - 6)), None),
34 };
35
36 view! {
37 <resize-bar
38 style:cursor=cursor
39 style:min-width=width
40 style:min-height=height
41 style:position="fixed"
42 style:top=move || pos().0
43 style:left=move || pos().1
44 draggable="true"
45 {..attrs}
46 >
47 <div style:min-height="100%" style:min-width="100%"></div>
48 </resize-bar>
49 }
50}