1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
//! Resizable component — draggable panels that resize horizontally or vertically.
use maud::{html, Markup};
/// A single resizable panel.
#[derive(Clone, Debug)]
pub struct Panel {
pub content: Markup,
pub default_size: f64,
pub min_size: Option<f64>,
}
/// Layout direction for the resizable group.
#[derive(Clone, Debug)]
pub enum Direction {
Horizontal,
Vertical,
}
impl Direction {
fn as_str(&self) -> &'static str {
match self {
Direction::Horizontal => "horizontal",
Direction::Vertical => "vertical",
}
}
fn aria_orientation(&self) -> &'static str {
match self {
Direction::Horizontal => "horizontal",
Direction::Vertical => "vertical",
}
}
}
/// Resizable group rendering properties.
#[derive(Clone, Debug)]
pub struct Props {
pub id: String,
pub panels: Vec<Panel>,
pub direction: Direction,
}
impl Default for Props {
fn default() -> Self {
Self {
id: "resizable".to_string(),
panels: vec![],
direction: Direction::Horizontal,
}
}
}
/// Render a resizable panel group with the given properties.
pub fn render(props: Props) -> Markup {
let dir = props.direction.as_str();
let orientation = props.direction.aria_orientation();
let panel_count = props.panels.len();
html! {
div class=(format!("mui-resizable mui-resizable--{}", dir))
data-mui="resizable"
data-direction=(dir)
id=(props.id)
{
@for (i, panel) in props.panels.iter().enumerate() {
@let min = panel.min_size.unwrap_or(10.0);
div class="mui-resizable__panel"
style=(format!("flex: {} 1 0%", panel.default_size))
data-min-size=(format!("{}", min))
{
(panel.content)
}
@if i < panel_count - 1 {
div class="mui-resizable__handle"
data-index=(format!("{}", i))
tabindex="0"
role="separator"
aria-orientation=(orientation)
aria-valuenow=(format!("{}", panel.default_size))
{
div class="mui-resizable__handle-bar" {}
}
}
}
}
}
}
/// Showcase resizable panel examples.
pub fn showcase() -> Markup {
html! {
div class="mui-showcase__grid" {
// Two horizontal panels — sidebar + content
div {
h3 class="mui-showcase__caption" { "Sidebar + Content" }
(render(Props {
id: "demo-resize-h2".to_string(),
direction: Direction::Horizontal,
panels: vec![
Panel {
content: html! {
div class="mui-resizable__demo-content" {
h4 { "Navigation" }
ul class="mui-resizable__demo-nav" {
li { a class="active" href="#" { "Dashboard" } }
li { a href="#" { "Projects" } }
li { a href="#" { "Team" } }
li { a href="#" { "Settings" } }
li { a href="#" { "Analytics" } }
}
}
},
default_size: 30.0,
min_size: Some(15.0),
},
Panel {
content: html! {
div class="mui-resizable__demo-content" {
h4 { "Dashboard" }
p { "Welcome back. Here is an overview of your recent activity, key metrics, and pending tasks. Drag the handle to resize the sidebar." }
}
},
default_size: 70.0,
min_size: Some(30.0),
},
],
}))
}
// Three horizontal panels — file explorer layout
div {
h3 class="mui-showcase__caption" { "Three-column Layout" }
(render(Props {
id: "demo-resize-h3".to_string(),
direction: Direction::Horizontal,
panels: vec![
Panel {
content: html! {
div class="mui-resizable__demo-content" {
h4 { "Explorer" }
ul class="mui-resizable__demo-nav" {
li { a class="active" href="#" { "src/" } }
li { a href="#" { "tests/" } }
li { a href="#" { "docs/" } }
li { a href="#" { "Cargo.toml" } }
}
}
},
default_size: 20.0,
min_size: Some(10.0),
},
Panel {
content: html! {
div class="mui-resizable__demo-content" {
h4 { "Editor" }
p { "Select a file from the explorer to view its contents here. This center panel occupies the majority of the available space." }
}
},
default_size: 55.0,
min_size: Some(20.0),
},
Panel {
content: html! {
div class="mui-resizable__demo-content" {
h4 { "Inspector" }
p { "Properties and metadata for the selected item will appear in this panel." }
}
},
default_size: 25.0,
min_size: Some(10.0),
},
],
}))
}
}
}
}