Key hint

An input hint: a key glyph and what it does, optionally pressable.

Component

Key hint belongs to the Actions group in the CyberSpec catalog. It uses markup and CSS.

Installation

Use a React 19 project with shadcn configured. Render the installed components inside the Cyber root, and import your global stylesheet in the app entry point.

bunx --bun shadcn@latest add https://www.cyberspec.dev/r/key-hint.json

Example

"use client"

import * as React from "react"
import { KeyHint, KeyHints } from "@/components/ui/key-hint"

// The foot of an inventory screen. Equip and Drop are buttons too, for a
// pointer; a carbine in hand can't be dropped.
export default function KeyHintDemo() {
  const [equipped, setEquipped] = React.useState(true)
  return (
    <>
      <span data-kit="value" role="status">
        KR-9 // {equipped ? "EQUIPPED" : "STOWED"}
      </span>
      <KeyHints
        align="center"
        hints={[
          { keys: ["↑", "↓"], label: "Navigate" },
          { keys: "↵", label: "Open" },
          { keys: "E", label: "Equip", onPress: () => setEquipped((now) => !now) },
          { keys: "X", label: "Drop", onPress: () => {}, disabled: equipped },
        ]}
      />
      <KeyHint keys="Esc" label="Close" />
    </>
  )
}

Install this example

bunx --bun shadcn@latest add https://www.cyberspec.dev/r/key-hint-demo.json

Resources

View as Markdown