use crate::{
components::{Button, ButtonSize, ButtonVariant},
density,
icons::{CarbonIcon, Icon},
t3::craft::{mono, rem, sans},
theme::color,
tokens::{self, ColorRole},
};
use gpui_kit::{
App, Div, ElementId, ParentElement, SharedString, Styled, Window, div,
prelude::FluentBuilder as _,
};
use std::rc::Rc;
pub type Handler = Rc<dyn Fn(&mut Window, &mut App)>;
pub fn code_head() -> Div {
sans(div(), 12., 400)
.flex()
.flex_none()
.items_center()
.gap(tokens::SPACING_03)
.h(density::current().row())
.pl(tokens::SPACING_04)
.pr(tokens::SPACING_02)
.bg(color(ColorRole::LayerAccent01))
.text_color(color(ColorRole::TextSecondary))
.overflow_hidden()
}
pub fn head_icon(name: CarbonIcon) -> Div {
div().flex().flex_none().child(
Icon::carbon(name)
.size_length(rem(14.))
.color(color(ColorRole::TextSecondary)),
)
}
pub fn head_name(name: impl Into<SharedString>, role: ColorRole) -> Div {
mono(div(), 12., 400)
.min_w_0()
.overflow_hidden()
.whitespace_nowrap()
.text_ellipsis()
.text_color(color(role))
.child(name.into())
}
pub fn dim(text: impl Into<SharedString>, size: f32) -> Div {
sans(div(), size, 400)
.flex_none()
.whitespace_nowrap()
.text_color(color(ColorRole::TextSecondary))
.child(text.into())
}
pub fn grow() -> Div {
div().flex_1().min_w_0()
}
pub fn sep() -> Div {
div()
.flex_none()
.w(gpui_kit::px(1.))
.h(rem(16.))
.mx(tokens::SPACING_02)
.bg(color(ColorRole::BorderSubtle01))
}
pub fn ghost_icon(
id: impl Into<ElementId>,
label: impl Into<SharedString>,
glyph: CarbonIcon,
disabled: bool,
on_click: Option<Handler>,
) -> Button {
Button::new(id, label)
.variant(ButtonVariant::Ghost)
.size(ButtonSize::Sm)
.icon(glyph)
.icon_only(true)
.disabled(disabled)
.when_some(on_click, |b, f| b.on_click(move |_, w, cx| f(w, cx)))
}
pub fn ghost_text(
id: impl Into<ElementId>,
label: impl Into<SharedString>,
on_click: Option<Handler>,
) -> Button {
Button::new(id, label)
.variant(ButtonVariant::Ghost)
.size(ButtonSize::Sm)
.when_some(on_click, |b, f| b.on_click(move |_, w, cx| f(w, cx)))
}