Skip to main content

Chip Component

The <Chip> component is designed to render customizable chip elements, typically used for displaying tags, categories, or small pieces of information.

Basic Usage​

The component renders a chip with text and customizable styling.

import { Chip } from "react-better-html";

function App() {
return (
<Chip text="Category" />
);
}

Common Props​

  • text - the content of the chip. Can be a string or any element
  • beforeText / afterText - elements rendered before and after the text
  • isCircle - fully rounded corners
  • color / backgroundColor - the colors of the text and the background
  • onClick / onClickWithValue - makes the chip clickable (with hover effect). onClickWithValue is used together with the value prop like in the <Div> component

Border, padding, font and height props are also supported.

import { Div, Chip } from "react-better-html";

function App() {
return (
<Div.row gap={8}>
{["React", "Vue", "Svelte"].map((tag) => (
<Chip
text={tag}
value={tag}
onClickWithValue={(value) => console.log("Clicked:", value)}
key={tag}
/>
))}
</Div.row>
);
}

Subcomponents​

A number of components in the library have a subcomponent feature witch is like a preset of the same component that is frequently used.

Chip.colored​

This component renders with a border and a background color.

import { Chip } from "react-better-html";

function App() {
return <Chip.colored text="Colored Text" color="#ff0000" />;
}

The text color is automatically lightened or darkened from color depending on the color theme. Use withWhiteBackground when the chip is placed on a colored background so the transparent fill does not mix with it.