use crate::{
components::button::{Button, ButtonSize, ButtonVariant},
icons::CarbonIcon,
t3::craft::{rem, sans},
theme::color,
tokens::{self, ColorRole},
};
use gpui_kit::{
App, Div, ElementId, IntoElement, ParentElement, SharedString, Styled, Window, div,
prelude::FluentBuilder as _,
};
use std::rc::Rc;
pub(crate) type Handler = Rc<dyn Fn(&mut Window, &mut App)>;
pub(crate) use crate::u0::tasks::row::frame;
pub(crate) fn main(title: impl IntoElement, subtitle: Option<Div>) -> Div {
div()
.flex()
.flex_col()
.flex_1()
.min_w_0()
.gap(rem(2.))
.child(
div()
.flex()
.items_center()
.gap(tokens::SPACING_03)
.overflow_hidden()
.whitespace_nowrap()
.text_ellipsis()
.child(title),
)
.when_some(subtitle, |this, s| this.child(s))
}
pub(crate) fn subtitle(text: impl Into<SharedString>) -> Div {
sans(div(), 12., 400)
.text_color(color(ColorRole::TextSecondary))
.overflow_hidden()
.whitespace_nowrap()
.text_ellipsis()
.child(text.into())
}
pub(crate) fn ghost_button(
id: impl Into<ElementId>,
label: SharedString,
glyph: Option<CarbonIcon>,
on_click: Option<Handler>,
) -> Button {
Button::new(id, label)
.variant(ButtonVariant::Ghost)
.size(ButtonSize::Sm)
.when_some(glyph, |b, g| b.icon(g))
.when_some(on_click, |b, f| b.on_click(move |_, w, cx| f(w, cx)))
}
pub(crate) fn icon_button(
id: impl Into<ElementId>,
label: SharedString,
glyph: CarbonIcon,
on_click: Option<Handler>,
) -> Button {
ghost_button(id, label, Some(glyph), on_click).icon_only(true)
}