Kbd
A keyboard shortcut hint.
Web replica of the native GPUI output
Open the command palette with ⌘K
use gpui::{div, prelude::*};
use crate::ui::kbd::Kbd;
pub fn kbd_demo() -> impl IntoElement {
div()
.flex()
.items_center()
.gap_1()
.text_sm()
.child("Open the command palette with")
.child(Kbd::new("⌘"))
.child(Kbd::new("K"))
}Installation
Add the component
$ cargo hyuskui add kbdOr copy it by hand: paste the source below into
src/ui/kbd.rsand register it insrc/ui/mod.rs.Make sure the theme is installed
Every component reads colors from
crate::theme. If you have not runcargo hyuskui init, follow the installation guide first.
Usage
use crate::ui::kbd::*;Source
This file is yours after install. Change the styles, add variants, or delete what you do not need.
use gpui::{div, prelude::*, px, App, FontWeight, SharedString, Window};
use crate::theme::ActiveTheme;
/// A keyboard key hint, e.g. `Kbd::new("⌘K")`.
#[derive(IntoElement)]
pub struct Kbd {
keys: SharedString,
}
impl Kbd {
pub fn new(keys: impl Into<SharedString>) -> Self {
Self { keys: keys.into() }
}
}
impl RenderOnce for Kbd {
fn render(self, _window: &mut Window, cx: &mut App) -> impl IntoElement {
let theme = cx.theme();
div()
.flex()
.items_center()
.h(px(20.0))
.px(px(6.0))
.rounded(px(4.0))
.border_1()
.border_color(theme.border)
.bg(theme.muted)
.text_color(theme.muted_foreground)
.text_xs()
.font_weight(FontWeight::MEDIUM)
.child(self.keys)
}
}