1use crate::theme::theme;
2use crate::{label, LabelColor, LabelSize};
3use gpui2::elements::div;
4use gpui2::style::StyleHelpers;
5use gpui2::{Element, IntoElement};
6use gpui2::{ParentElement, ViewContext};
7
8#[derive(Element)]
9pub struct PaletteItem {
10 pub label: &'static str,
11 pub keybinding: Option<&'static str>,
12}
13
14pub fn palette_item(label: &'static str, keybinding: Option<&'static str>) -> PaletteItem {
15 PaletteItem { label, keybinding }
16}
17
18impl PaletteItem {
19 pub fn label(mut self, label: &'static str) -> Self {
20 self.label = label;
21 self
22 }
23
24 pub fn keybinding(mut self, keybinding: Option<&'static str>) -> Self {
25 self.keybinding = keybinding;
26 self
27 }
28
29 fn render<V: 'static>(&mut self, _: &mut V, cx: &mut ViewContext<V>) -> impl IntoElement<V> {
30 let theme = theme(cx);
31
32 let keybinding_label = match self.keybinding {
33 Some(keybind) => label(keybind)
34 .color(LabelColor::Muted)
35 .size(LabelSize::Small),
36 None => label(""),
37 };
38
39 div()
40 .flex()
41 .flex_row()
42 .grow()
43 .justify_between()
44 .child(label(self.label))
45 .child(
46 self.keybinding
47 .map(|_| {
48 div()
49 .flex()
50 .items_center()
51 .justify_center()
52 .px_1()
53 .py_0()
54 .my_0p5()
55 .rounded_md()
56 .text_sm()
57 .fill(theme.lowest.on.default.background)
58 .child(keybinding_label)
59 })
60 .unwrap_or_else(|| div()),
61 )
62 }
63}