Forms
Chip & Kbd
32px selectable and removable tokens for criteria builders and tag editors, plus keyboard keys.
react-aria-componentslucide-react
Preview
Press ⌘K to open quick actions
"use client";
import { useState } from "react";
import { Chip, RemovableChip } from "@/components/ui/chip";
import { Kbd } from "@/components/ui/kbd";
export default function Example() {
const [tags, setTags] = useState(["VP Sales", "Head of Revenue", "CRO"]);
return (
<div className="flex flex-col gap-4">
<div className="flex flex-wrap gap-2">
<Chip>VP Sales</Chip>
<Chip defaultSelected>Head of Revenue</Chip>
<Chip>Director of Sales</Chip>
</div>
<div className="flex flex-wrap gap-2">
{tags.map((t) => (
<RemovableChip key={t} onRemove={() => setTags((x) => x.filter((y) => y !== t))}>{t}</RemovableChip>
))}
</div>
<div className="flex items-center gap-1.5 text-sm text-fg-muted">
Press <Kbd>⌘</Kbd><Kbd>K</Kbd> to open quick actions
</div>
</div>
);
}Installation
Components are copied into your project — no runtime package.
Install the following dependencies:
terminalnpm install react-aria-components lucide-reactCreate a
chip.tsxfile and paste the following code into it.src/components/ui/chip.tsx"use client"; import { Check, X } from "lucide-react"; import type { ReactNode } from "react"; import { Button as AriaButton, ToggleButton, type ToggleButtonProps } from "react-aria-components"; import { cx } from "@/utils/cx"; const chipBase = "inline-flex h-8 cursor-default items-center gap-1.5 rounded-sm px-3 text-base font-medium outline-none transition-colors " + "data-focus-visible:shadow-focus [&_svg]:size-3.5"; /** Selectable token used in criteria builders and persona pickers. */ export function Chip({ children, className, ...props }: Omit<ToggleButtonProps, "children" | "className"> & { children: ReactNode; className?: string }) { return ( <ToggleButton {...props} className={cx( chipBase, "bg-surface text-fg shadow-button data-hovered:bg-subtle", "data-selected:bg-accent-soft data-selected:text-accent-text data-selected:shadow-[inset_0_0_0_1px_var(--color-accent-soft-border)]", className, )} > {({ isSelected }) => ( <> {isSelected && <Check aria-hidden />} {children} </> )} </ToggleButton> ); } /** Removable token used in tag editors. */ export function RemovableChip({ children, onRemove, className }: { children: ReactNode; onRemove?: () => void; className?: string }) { return ( <span className={cx(chipBase, "bg-surface pr-1.5 text-fg shadow-button", className)}> {children} <AriaButton aria-label={`Remove ${typeof children === "string" ? children : "item"}`} onPress={onRemove} className="inline-flex size-5 items-center justify-center rounded-xs text-fg-muted outline-none data-hovered:bg-muted data-hovered:text-fg data-focus-visible:shadow-focus" > <X /> </AriaButton> </span> ); }Create a
kbd.tsxfile and paste the following code into it.src/components/ui/kbd.tsximport { cx } from "@/utils/cx"; /** Marks keyboard shortcuts. */ export function Kbd({ className, children }: { className?: string; children: React.ReactNode }) { return ( <kbd className={cx( "inline-flex h-5 min-w-5 items-center justify-center rounded-[6px] border border-line bg-surface px-1.5 font-sans text-xs font-medium text-fg-muted", className, )} > {children} </kbd> ); }Add the theme tokens and the
cxhelper from Installation if you haven’t yet, then update the import paths to match your project setup.