Chip
Filter / input tag. 3 styles × 4 states.
import * as React from "react";
import { Chip } from "@/components/ui/chip";
export default function Example() {
const [on, setOn] = React.useState(["green"]);
const toggle = (k: string) => setOn(s => (s.includes(k) ? s.filter(x => x !== k) : [...s, k]));
return (
<div className="flex flex-wrap gap-2">
{[["green", "Green tea"], ["black", "Black tea"], ["herbal", "Herbal"], ["chai", "Masala chai"]].map(([k, label]) => (
<Chip key={k} selected={on.includes(k)} onClick={() => toggle(k)}>{label}</Chip>
))}
</div>
);
}
Installation
$ npx uix-ui@latest add chipThis copies the file into components/ui/chip.tsx in your project. npx shadcn@latest add @uix/chip works too.
Usage
import { Chip } from "@/components/ui/chip";
<div className="flex flex-wrap items-center gap-2">
<Chip appearance="filled">Filled</Chip>
<Chip appearance="outline">Outline</Chip>
<Chip appearance="soft">Soft</Chip>
<Chip appearance="outline" disabled>Disabled</Chip>
</div>
Examples
Appearances
import { Chip } from "@/components/ui/chip";
export default function Example() {
return (
<div className="flex flex-wrap items-center gap-2">
<Chip appearance="filled">Filled</Chip>
<Chip appearance="outline">Outline</Chip>
<Chip appearance="soft">Soft</Chip>
<Chip appearance="outline" disabled>Disabled</Chip>
</div>
);
}
Removable
import * as React from "react";
import { Chip } from "@/components/ui/chip";
export default function Example() {
const [tags, setTags] = React.useState(["Sylhet", "Organic", "Under ৳500"]);
return (
<div className="flex flex-wrap gap-2">
{tags.map(t => <Chip key={t} appearance="soft" onRemove={() => setTags(s => s.filter(x => x !== t))}>{t}</Chip>)}
{tags.length === 0 ? <span className="text-body-small text-fg-secondary">No filters</span> : null}
</div>
);
}
Props
| Prop | Type | Default | Description |
|---|---|---|---|
appearance | filled | outline | soft | "filled" | |
selected | boolean | false | |
disabled | boolean | false | |
onClick | React.MouseEventHandler<HTMLButtonElement> | – | |
leadingAvatar | React.ReactNode | – | Avatar before the label (for example <Avatar size="xs" initials="AB" />). |
leadingIcon | React.ReactNode | – | Icon before the label. |
onRemove | () => void | – | Shows a remove button and calls this when it is pressed. |
Everything else is passed to the root element, so className, aria-* and event handlers work as usual.
Dependencies
Installed for you by the CLI.
class-variance-authorityclsxtailwind-merge
lib/utils.tscomponents/ui/icons.tsx