BlueGit

ict rusty-teams

Files

rusty-teams / crates / app-ui-kit / src / reaction_proposal_pill.rs

reaction_proposal_pill.rs

3e25d31a History
reaction_proposal_pill.rs 1.7 KiB Download Raw
1use std::rc::Rc;
2
3use gpui_kit::component::h_flex;
4use gpui_kit::*;
5
6use app_base::theme;
7
8const PILL_HEIGHT: f32 = 26.;
9const PILL_PADDING: f32 = 10.;
10const PILL_GAP: f32 = 8.;
11const PILL_TEXT_SIZE: f32 = 12.;
12pub const REACTION_PILL: &str = "shell/islands/main/reaction-pill";
13
14pub type PillAction = Rc<dyn Fn(&mut App)>;
15
16#[derive(Clone)]
17pub struct ReactionPill {
18 pub agent: &'static str,
19 pub emoji: String,
20 pub accept: PillAction,
21 pub discard: PillAction,
22}
23
24fn pill_link(id: String, label: &'static str, color: Hsla, action: PillAction) -> Stateful<Div> {
25 div()
26 .id(ElementId::Name(id.into()))
27 .flex_none()
28 .cursor_pointer()
29 .font_weight(FontWeight::SEMIBOLD)
30 .text_color(color)
31 .hover(|link| link.underline())
32 .child(label)
33 .on_click(move |_, _, cx| action(cx))
34}
35
36pub fn reaction_pill(pill: ReactionPill, key: &str) -> Div {
37 h_flex()
38 .h(px(PILL_HEIGHT))
39 .flex_none()
40 .items_center()
41 .gap(px(PILL_GAP))
42 .px(px(PILL_PADDING))
43 .rounded_full()
44 .bg(theme::row_hover())
45 .text_size(px(PILL_TEXT_SIZE))
46 .debug_selector(|| REACTION_PILL.into())
47 .child(
48 div()
49 .flex_none()
50 .text_color(theme::text_muted())
51 .child(format!("{}: {}", pill.agent, pill.emoji)),
52 )
53 .child(pill_link(
54 format!("reaction-accept-{key}"),
55 "Accept",
56 theme::accent_text(),
57 pill.accept,
58 ))
59 .child(pill_link(
60 format!("reaction-discard-{key}"),
61 "Discard",
62 theme::text_muted(),
63 pill.discard,
64 ))
65}