use crate::{
icons::{CarbonIcon, Icon},
t3::{
base::warning_glyph,
craft::{mono, rem, sans},
},
theme::color,
tokens::{self, ColorRole},
};
use gpui_kit::{AnyElement, Div, Hsla, IntoElement, ParentElement, SharedString, Styled, div, px};
pub(crate) use crate::u0::tasks::row::frame;
pub(crate) fn slrow_main(title: Div, lines: impl IntoIterator<Item = AnyElement>) -> Div {
div()
.flex()
.flex_col()
.flex_1()
.min_w_0()
.gap(px(2.))
.child(title)
.children(
lines
.into_iter()
.map(|l| sans(div(), 12., 400).min_w_0().child(l)),
)
}
pub(crate) fn title(ink: Hsla) -> Div {
div()
.flex()
.items_center()
.gap(tokens::SPACING_03)
.min_w_0()
.overflow_hidden()
.whitespace_nowrap()
.text_color(ink)
}
pub(crate) fn title_text(text: impl Into<SharedString>) -> Div {
div()
.min_w_0()
.overflow_hidden()
.whitespace_nowrap()
.text_ellipsis()
.child(text.into())
}
pub(crate) fn meta(runs: impl IntoIterator<Item = AnyElement>) -> Div {
sans(div(), 12., 400)
.flex()
.flex_wrap()
.items_center()
.gap_x(tokens::SPACING_03)
.gap_y(tokens::SPACING_02)
.text_color(color(ColorRole::TextSecondary))
.children(runs)
}
pub(crate) fn dim(text: impl Into<SharedString>, size: f32) -> Div {
sans(div(), size, 400)
.whitespace_nowrap()
.text_color(color(ColorRole::TextSecondary))
.child(text.into())
}
pub(crate) fn mono_text(text: impl Into<SharedString>) -> Div {
mono(div(), 12., 400).whitespace_nowrap().child(text.into())
}
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
pub enum StateTone {
Ok,
Warn,
Err,
}
impl StateTone {
pub fn ink(self) -> Hsla {
color(match self {
Self::Ok | Self::Warn => ColorRole::TextSecondary,
Self::Err => ColorRole::TextError,
})
}
pub fn glyph_ink(self) -> Hsla {
color(match self {
Self::Ok => ColorRole::SupportSuccess,
Self::Warn => ColorRole::SupportWarning,
Self::Err => ColorRole::SupportError,
})
}
pub fn glyph(self, size: f32) -> AnyElement {
match self {
Self::Warn => warning_glyph(size).into_any_element(),
Self::Ok => Icon::carbon(CarbonIcon::CheckmarkFilled)
.size_length(rem(size))
.color(self.glyph_ink())
.into_any_element(),
Self::Err => Icon::carbon(CarbonIcon::ErrorFilled)
.size_length(rem(size))
.color(self.glyph_ink())
.into_any_element(),
}
}
}
pub(crate) fn state_text(tone: StateTone, text: impl Into<SharedString>) -> Div {
sans(div(), 12., 400)
.flex()
.flex_none()
.items_center()
.gap(tokens::SPACING_02)
.whitespace_nowrap()
.text_color(tone.ink())
.child(div().flex().flex_none().child(tone.glyph(12.)))
.child(text.into())
}
pub(crate) fn state_text_wrapping(tone: StateTone, text: impl Into<SharedString>) -> Div {
sans(div(), 12., 400)
.flex()
.items_center()
.gap(tokens::SPACING_02)
.min_w_0()
.text_color(tone.ink())
.child(div().flex().flex_none().child(tone.glyph(12.)))
.child(div().min_w_0().whitespace_normal().child(text.into()))
}
pub(crate) fn tail(el: impl IntoElement) -> Div {
div().flex().flex_none().items_center().child(el)
}
#[cfg(test)]
mod tests {
use super::*;
use crate::CarbonTheme;
#[test]
fn state_tones_follow_g_ok_warn_err() {
crate::theme::tests_set(CarbonTheme::G100);
assert_eq!(StateTone::Ok.ink(), color(ColorRole::TextSecondary));
assert_eq!(StateTone::Warn.ink(), color(ColorRole::TextSecondary));
assert_eq!(StateTone::Err.ink(), color(ColorRole::TextError));
assert_eq!(StateTone::Ok.glyph_ink(), color(ColorRole::SupportSuccess));
assert_eq!(
StateTone::Warn.glyph_ink(),
color(ColorRole::SupportWarning)
);
assert_eq!(StateTone::Err.glyph_ink(), color(ColorRole::SupportError));
}
}