tablo_ui/components/composites/
empty_state.rs1use topcoat::{
2 Result,
3 context::Cx,
4 icon::icon,
5 view::{Attributes, Child, StaticClass, View, class, component, view},
6};
7
8const EMPTY_STATE: StaticClass = class!("flex flex-col items-center gap-2 px-6 py-12 text-center");
9const EMPTY_STATE_ICON: StaticClass = class!(
10 "mb-1 flex size-10 items-center justify-center rounded-full bg-muted \
11 text-muted-foreground [&>svg]:size-5"
12);
13const EMPTY_STATE_TITLE: StaticClass = class!("text-sm font-medium text-foreground");
14const EMPTY_STATE_DETAIL: StaticClass = class!("text-sm text-muted-foreground");
15const EMPTY_STATE_ACTION: StaticClass =
16 class!("mt-2 flex flex-wrap items-center justify-center gap-2");
17
18#[component]
29pub async fn empty_state(
30 cx: &Cx,
31 #[into]
33 title: String,
34 #[into]
36 #[default]
37 detail: String,
38 #[default]
40 action: Option<Child<'_>>,
41 #[default]
43 mut attrs: Attributes,
44) -> Result<impl View> {
45 Ok(view! {
46 <div class=(class!(EMPTY_STATE, attrs.remove("class"))) (attrs)>
47 <div class=(EMPTY_STATE_ICON) aria-hidden="true">
48 icon(data: crate::icons::INBOX)
49 </div>
50 <p class=(EMPTY_STATE_TITLE)>(title)</p>
51 if !detail.is_empty() {
52 <p class=(EMPTY_STATE_DETAIL)>(detail)</p>
53 }
54 if let Some(action) = action {
55 <div class=(EMPTY_STATE_ACTION)>(action)</div>
56 }
57 </div>
58 })
59}