Used to display textual user input from keyboard.
Installation
npx shadcn@latest add @caprice/kbdpnpm dlx shadcn@latest add @caprice/kbdyarn dlx shadcn@latest add @caprice/kbdbunx shadcn@latest add @caprice/kbdnpm install @caprice-ui/reactpnpm add @caprice-ui/reactyarn add @caprice-ui/reactbun add @caprice-ui/reactInstall the following dependencies:
npm install @base-ui/react lucide-reactpnpm add @base-ui/react lucide-reactyarn add @base-ui/react lucide-reactbun add @base-ui/react lucide-reactAdd a cn helper
import { cn as merge } from 'cn';
import type { VariantProps } from 'cva';
import { defineConfig } from 'cva/config';
import { getSchema } from 'cva/tools';
export const { cva, cx: cn } = defineConfig({
cx: merge,
});
export type { VariantProps };
export { getSchema };
Copy and paste the following code into your project.
import { cn } from '@/lib/utils';
/**
* A keyboard key.
* Renders a `<kbd>` element.
*
* Documentation: [Caprice UI Kbd](https://caprice-ui.com/docs/components/kbd)
*/
export namespace Kbd {
export type Props = React.ComponentProps<'kbd'>;
}
export function Kbd({ className, ...props }: Kbd.Props) {
return (
<kbd
className={cn(
'pointer-events-none inline-flex h-5 w-fit min-w-5 select-none items-center justify-center gap-1 rounded-sm bg-muted px-1 font-medium font-sans text-muted-foreground text-xs',
"[&_svg:not([class*='size-'])]:size-3",
'in-data-[slot=tooltip-content]:bg-background/20 in-data-[slot=tooltip-content]:text-background dark:in-data-[slot=tooltip-content]:bg-background/10',
className
)}
data-slot="kbd"
{...props}
/>
);
}
/**
* A group of keyboard keys.
* Renders a `<kbd>` element.
*
* Documentation: [Caprice UI Kbd](https://caprice-ui.com/docs/components/kbd)
*/
export namespace KbdGroup {
export type Props = React.ComponentProps<'kbd'>;
}
export function KbdGroup({ className, ...props }: KbdGroup.Props) {
return (
<kbd
className={cn('inline-flex items-center gap-1', className)}
data-slot="kbd-group"
{...props}
/>
);
}
Update the import paths to match your project setup.
Usage
import { Kbd, KbdGroup } from "@/components/caprice-ui/kbd"import { Kbd, KbdGroup } from "@caprice-ui/react/kbd"<KbdGroup>
<Kbd>Ctrl</Kbd>
<Kbd>+</Kbd>
<Kbd>C</Kbd>
</KbdGroup>Last updated on