forge
Explore
Log in

Don't you dare go Hollow

project_note

Clone
★ 0

0 watching0 forksRust3.6 MiBc49f5e7Tahinli1 month ago2 commits

kbd.rs44 lines, 1.2 KiBHistoryRawDownload
1use topcoat::{
2 Result,
3 view::{Attributes, Child, StaticClass, View, class, component, view},
4};
5
6/// Classes that draw a key label in a bordered box.
7const KBD: StaticClass = class!("keycap");
8
9/// A keyboard key label rendered as `<kbd>`.
10///
11/// Pass the key name as children and use [`kbd_group`] for a shortcut with several
12/// keys. `attrs` are forwarded to the `<kbd>`, with extra classes added to its classes.
13///
14/// ```ignore
15/// view! {
16/// kbd_group(kbd("Ctrl") kbd("K"))
17/// }
18/// ```
19#[component]
20pub async fn kbd(
21 #[default] mut attrs: Attributes,
22 #[default] child: Child<'_>,
23) -> Result<impl View> {
24 Ok(view! { <kbd class=(class!(KBD, attrs.remove("class"))) (attrs)>(child)</kbd> })
25}
26
27/// A row of key labels for one keyboard shortcut. The keys stay on one line.
28#[component]
29pub async fn kbd_group(
30 #[default] mut attrs: Attributes,
31 #[default] child: Child<'_>,
32) -> Result<impl View> {
33 Ok(view! {
34 <span
35 class=(class!(
36 "inline-flex items-center gap-1 whitespace-nowrap",
37 attrs.remove("class"),
38 ))
39 (attrs)
40 >
41 (child)
42 </span>
43 })
44}