label.rs

 1use gpui2::elements::div;
 2use gpui2::style::StyleHelpers;
 3use gpui2::{Element, IntoElement, ParentElement, ViewContext};
 4
 5use crate::theme;
 6
 7#[derive(Default, PartialEq, Copy, Clone)]
 8pub enum LabelColor {
 9    #[default]
10    Default,
11    Created,
12    Modified,
13    Deleted,
14    Hidden,
15}
16
17#[derive(Element, Clone)]
18pub struct Label {
19    label: &'static str,
20    color: LabelColor,
21}
22
23pub fn label(label: &'static str) -> Label {
24    Label {
25        label,
26        color: LabelColor::Default,
27    }
28}
29
30impl Label {
31    pub fn color(mut self, color: LabelColor) -> Self {
32        self.color = color;
33        self
34    }
35
36    fn render<V: 'static>(&mut self, _: &mut V, cx: &mut ViewContext<V>) -> impl IntoElement<V> {
37        let theme = theme(cx);
38
39        let color = match self.color {
40            LabelColor::Default => theme.lowest.base.default.foreground,
41            LabelColor::Created => theme.lowest.positive.default.foreground,
42            LabelColor::Modified => theme.lowest.warning.default.foreground,
43            LabelColor::Deleted => theme.lowest.negative.default.foreground,
44            LabelColor::Hidden => theme.lowest.variant.default.foreground,
45        };
46
47        div().text_sm().text_color(color).child(self.label.clone())
48    }
49}