1use gpui::{div, Component, Div, ParentElement, Render, SharedString, Styled, ViewContext};
2use theme2::ActiveTheme;
3
4use crate::{h_stack, v_stack, Label, LabelColor, StyledExt};
5
6use super::keybinding;
7
8#[derive(Clone, Debug)]
9pub struct TextTooltip {
10 title: SharedString,
11 meta: Option<SharedString>,
12 keybinding: Option<SharedString>,
13}
14
15impl TextTooltip {
16 pub fn new(title: impl Into<SharedString>) -> Self {
17 Self {
18 title: title.into(),
19 meta: None,
20 keybinding: None,
21 }
22 }
23
24 pub fn meta(mut self, meta: impl Into<SharedString>) -> Self {
25 self.meta = Some(meta.into());
26 self
27 }
28
29 pub fn keybinding(mut self, keybinding: impl Into<SharedString>) -> Self {
30 self.keybinding = Some(keybinding.into());
31 self
32 }
33}
34
35impl Render for TextTooltip {
36 type Element = Div<Self>;
37
38 fn render(&mut self, cx: &mut ViewContext<Self>) -> Self::Element {
39 v_stack()
40 .elevation_2(cx)
41 .font("Zed Sans")
42 .text_ui_sm()
43 .text_color(cx.theme().colors().text)
44 .py_1()
45 .px_2()
46 .child(h_stack().child(self.title.clone()).when_some(
47 self.keybinding.clone(),
48 |this, keybinding| {
49 this.justify_between()
50 .child(Label::new(keybinding).color(LabelColor::Muted))
51 },
52 ))
53 .when_some(self.meta.clone(), |this, meta| {
54 this.child(Label::new(meta).color(LabelColor::Muted))
55 })
56 }
57}