1#![allow(non_snake_case)]
4
5use strata_dom::{NodeBlueprint, View};
6use strata_macro::{component, rsx};
7
8#[component]
11pub fn WindowDragHandle(class: Option<&'static str>, children: Option<Vec<NodeBlueprint>>) -> View {
12 let custom = class.unwrap_or("");
13 rsx! {
14 <div data-app-region="drag" class={format!("flex items-center select-none cursor-default {}", custom)}>
15 {children.unwrap_or_default()}
16 </div>
17 }
18}
19
20#[component]
23pub fn TitleBar(
24 title: Option<String>,
25 drag_region: Option<bool>,
26 show_controls: Option<bool>,
27 on_minimize: Option<std::rc::Rc<dyn Fn(strata_dom::Event)>>,
28 on_maximize: Option<std::rc::Rc<dyn Fn(strata_dom::Event)>>,
29 on_close: Option<std::rc::Rc<dyn Fn(strata_dom::Event)>>,
30 class: Option<&'static str>,
31 children: Option<Vec<NodeBlueprint>>,
32) -> View {
33 let custom = class.unwrap_or("");
34 let is_drag = drag_region.unwrap_or(true);
35 let app_region = if is_drag { "drag" } else { "no-drag" };
36 let controls = show_controls.unwrap_or(true);
37 let window_title = title.unwrap_or_else(|| "Strata Application".to_string());
38
39 let min_cb = on_minimize.unwrap_or_else(|| std::rc::Rc::new(|_| {}));
40 let max_cb = on_maximize.unwrap_or_else(|| std::rc::Rc::new(|_| {}));
41 let close_cb = on_close.unwrap_or_else(|| std::rc::Rc::new(|_| {}));
42
43 rsx! {
44 <header
45 data-app-region={app_region}
46 class={format!("w-full h-10 px-3 bg-[#1e1e1e] border-b border-[#2d2d2d] flex items-center justify-between select-none {}", custom)}
47 >
48 <div data-app-region={app_region} class="flex items-center space-x-2 flex-1 min-w-0">
49 <span data-app-region={app_region} class="text-xs font-medium text-neutral-300 truncate">
50 {window_title}
51 </span>
52 </div>
53
54 <div data-app-region="no-drag" class="flex items-center space-x-1 shrink-0">
55 {children.unwrap_or_default()}
56
57 {if controls {
58 rsx! {
59 <div class="flex items-center space-x-1 ml-2">
60 <button
61 data-app-region="no-drag"
62 data-window-action="minimize"
63 class="w-7 h-7 flex items-center justify-center rounded hover:bg-neutral-700/60 text-neutral-400 hover:text-neutral-200 transition-colors cursor-pointer"
64 onclick={min_cb}
65 >
66 <svg class="w-3.5 h-3.5" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
67 <line x1="5" y1="12" x2="19" y2="12" />
68 </svg>
69 </button>
70 <button
71 data-app-region="no-drag"
72 data-window-action="maximize"
73 class="w-7 h-7 flex items-center justify-center rounded hover:bg-neutral-700/60 text-neutral-400 hover:text-neutral-200 transition-colors cursor-pointer"
74 onclick={max_cb}
75 >
76 <svg class="w-3.5 h-3.5" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
77 <rect x="4" y="4" width="16" height="16" rx="2" />
78 </svg>
79 </button>
80 <button
81 data-app-region="no-drag"
82 data-window-action="close"
83 class="w-7 h-7 flex items-center justify-center rounded hover:bg-red-600/80 text-neutral-400 hover:text-white transition-colors cursor-pointer"
84 onclick={close_cb}
85 >
86 <svg class="w-3.5 h-3.5" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
87 <line x1="18" y1="6" x2="6" y2="18" />
88 <line x1="6" y1="6" x2="18" y2="18" />
89 </svg>
90 </button>
91 </div>
92 }
93 } else {
94 rsx! { <></> }
95 }}
96 </div>
97 </header>
98 }
99}