COMPONENTS/DATA DISPLAY
Chip.
A small, removable detail.
In practice
Design
Use onRemove for removable tags and give each remove button a specific removeLabel. Use Badge for static status and ToggleGroup for selection.
Installation
Install Coal once. Components and TypeScript declarations are included. React 19 and React DOM 19 are peer dependencies.
Terminal · local package
npm install http://localhost:3100/downloads/chlohal-coal-ui-0.5.0.tgzThis installs the local package. It is not yet published on npm. See installation for stylesheet setup and integration.
Usage
example.tsx
"use client";
import * as React from "react";
import "@chlohal/coal-ui/styles.css";
import { Chip, Button } from "@chlohal/coal-ui";
export default function Example() {
const [saved, setSaved] = React.useState(false);
return (<div>
{!saved ? (<Chip removeLabel="Remove Design tag" onRemove={() => setSaved(true)}>
Design
</Chip>) : (<Button variant="ghost" onClick={() => setSaved(false)}>
Restore tag
</Button>)}
</div>);
}
Source
The original Coal implementation. Use the package export to integrate it.
packages/react/src/chip.tsx
"use client";
import * as React from "react";
import { cn } from "./internal.js";
export type ChipProps = React.ComponentPropsWithRef<"span"> & {
onRemove?: () => void;
removeLabel?: string;
disabled?: boolean;
};
export function Chip({
children,
className,
onRemove,
removeLabel = "Remove item",
disabled,
...props
}: ChipProps) {
return (
<span className={cn("coal-chip", className)} {...props}>
{children}
{onRemove && (
<button
type="button"
disabled={disabled}
aria-label={removeLabel}
onClick={onRemove}
>
×
</button>
)}
</span>
);
}
Accessibility checklist
- Provide an accessible name for controls, including icon-only buttons.
- Check keyboard navigation, visible focus and disabled states in your application.
- Do not rely on color alone to communicate status.