A component that shows keyboard keys and shortcuts. This is a custom component with no Base UI primitive. It provides the Kbd.Root and Kbd.Group subcomponents and a variant prop on Kbd.Root.
Here is the component implementation code that you can copy to your project:
// https://devie-ui.com/components/kbd
import clsx from "clsx";
import type React from "react";
import styles from "./Kbd.module.scss";
function Root({ className, variant = "badge", ...props }: Kbd.Root.Props) {
return (
<kbd
className={clsx(
styles.root,
variant === "badge" && styles.variantBadge,
variant === "naked" && styles.variantNaked,
className,
)}
{...props}
/>
);
}
function Group({ className, ...props }: Kbd.Group.Props) {
return <kbd className={clsx(styles.group, className)} {...props} />;
}
const Kbd = {
Root,
Group,
};
namespace Kbd {
export type Variant = "badge" | "naked";
export namespace Root {
export interface Props extends React.ComponentProps<"kbd"> {
variant?: Variant;
}
}
export namespace Group {
export type Props = React.ComponentProps<"kbd">;
}
}
export default Kbd;Put one key in each Kbd.Root, as a letter, a symbol, or a word.
Set variant on Kbd.Root to badge or naked. The default is badge; use naked for text-only keys in dense lists and menus.
Wrap several Kbd.Root elements in Kbd.Group for shortcuts that are pressed together.