# Kbd

Crate: `libero`
Import: `use libero::components::Kbd;`
Feature: `kbd` (on by default, turns on `box`; [features.md](features.md))
Source: <https://github.com/tdymel/libero/tree/main/libero/src/components/typography/kbd.rs>
Index: [index.md](index.md) lists every other page
Description: A single keyboard key, rendered as a real `<kbd>` and styled from the theme.

One keyboard key in a real `<kbd>`, styled from the theme. A shortcut is
several keys with your own separator.

## Usage

```rust
use dioxus::prelude::*;
use libero::components::{Kbd, Text};

#[component]
fn Demo() -> Element {
    rsx! {
        Text {
            "Save with "
            Kbd { "Ctrl" }
            " + "
            Kbd { "S" }
            "."
        }
    }
}
```

## Props

| Prop | Type | Default | Description |
|---|---|---|---|
| `size` | `Responsive<Size>` | `md` | Font size. The rest of the look comes from the theme. Or one per breakpoint, `size: responsive(Size::Sm).md(Size::Lg)`. Breakpoints follow the window, not the parent. |
| `children` | `Element` | required | The key label. |

Like every component, `Kbd` also takes the shared props `sx`, `class`, `style`,
`states`, `hidden_from`, `visible_from`, and any extra HTML attributes.

## Accessibility

### Libero handles

- Each key is a real `<kbd>`.

### You must

- Put the separator in the text around the keys. A screen reader reads
  `Kbd { "Ctrl" } " + " Kbd { "S" }` as "Ctrl plus S", but one
  `Kbd { "Ctrl+S" }` as a single token. Put `dir: "ltr"` on the element around a
  chord, or a right-to-left page shows it as `S + Ctrl`.

### Example

A save hint, `Kbd { "Ctrl" } " + " Kbd { "S" }`: a screen reader reads "Ctrl
plus S", key by key.

## Theme defaults

`KbdDefaults` on the theme.

| Field | Type | Description |
|---|---|---|
| `size` | `Size` | Default `size` when the prop is omitted; `md`. |
| `font_sizes` | `Sizes<u16>` | Pixels at a 16px root per size step: 10, 12, 14, 16, 20, 24, written as `rem`, so a key grows with a raised text size. |
| `font_family` | `&'static str` | The keycap's font; the theme's mono stack. |
| `background` | `&'static str` | Keycap fill; `var(--lsx-muted-1)`. |
| `border` | `&'static str` | Border color, used on all four sides; `var(--lsx-muted-4)`. |
| `color` | `&'static str` | Label color; `var(--lsx-muted-7)`, darkened or lightened until it reads at 4.5:1. |

## CSS variables

| Variable | Description |
|---|---|
| `--lsx-kbd-font-size-<size>` | `font-size` for that size step. |
| `--lsx-kbd-font-family` | The keycap's font family. |
| `--lsx-kbd-background` | Keycap fill. |
| `--lsx-kbd-border` | Border color; the bottom border draws it 3px, the others 1px. |
| `--lsx-kbd-color` | Label color. |

The corner radius reads the shared `--lsx-radius-sm`.

## Data attributes

State tokens on the root's `data-state`.

| Token | Condition |
|---|---|
| `size-<size>` | The `size` in effect. |
