1use gpui::prelude::*;
4use gpui::{div, px, App, FontWeight, IntoElement, SharedString, Window};
5
6use crate::theme::{theme, ColorName, Size};
7
8#[derive(IntoElement)]
10pub struct Kbd {
11 key: SharedString,
12}
13
14impl Kbd {
15 pub fn new(key: impl Into<SharedString>) -> Self {
16 Kbd { key: key.into() }
17 }
18}
19
20impl RenderOnce for Kbd {
21 fn render(self, _window: &mut Window, cx: &mut App) -> impl IntoElement {
22 let t = theme(cx);
23 let bg = t.color(ColorName::Gray, if t.scheme.is_dark() { 7 } else { 0 }).hsla();
24 let border = t.color(ColorName::Gray, if t.scheme.is_dark() { 6 } else { 3 }).hsla();
25
26 div()
27 .px(px(7.0))
28 .py(px(2.0))
29 .rounded(px(t.radius(Size::Sm)))
30 .border_1()
31 .border_color(border)
32 .bg(bg)
33 .text_color(t.text().hsla())
34 .text_size(px(t.font_size(Size::Xs)))
35 .font_weight(FontWeight::SEMIBOLD)
36 .child(self.key)
37 }
38}