Skip to main content

things3_cloud/ui/components/
header.rs

1use iocraft::prelude::*;
2
3use crate::{ids::ThingsId, ui::components::id::Id};
4
5#[derive(Default, Props)]
6pub struct HeaderProps<'a> {
7    pub uuid: Option<&'a ThingsId>,
8    pub title: Option<&'a str>,
9    pub id_prefix_len: usize,
10    pub icon: Option<&'a str>,
11}
12
13#[component]
14pub fn Header<'a>(props: &HeaderProps<'a>) -> impl Into<AnyElement<'a>> {
15    let (Some(uuid), Some(title)) = (props.uuid, props.title) else {
16        return element!(Fragment).into_any();
17    };
18
19    let text = if let Some(icon) = props.icon {
20        format!("{} {}", icon, title)
21    } else {
22        title.to_string()
23    };
24
25    element! {
26        View(flex_direction: FlexDirection::Row, gap: 1) {
27            Id(id: uuid, length: props.id_prefix_len)
28            Text(content: text, wrap: TextWrap::NoWrap, weight: Weight::Bold)
29        }
30    }
31    .into_any()
32}