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.
- Basic
- Circle
- Before & After
- Custom
import { Chip } from "react-better-html";
function App() {
return (
<Chip text="Category" />
);
}
import { Chip } from "react-better-html";
function App() {
return (
<Chip text="Category" isCircle />
);
}
import { Chip, Icon } from "react-better-html";
function App() {
return (
<Chip
text="Verified"
beforeText={<Icon name="check" size={12} />}
afterText={<Icon name="XMark" size={12} />}
/>
);
}
import { Chip } from "react-better-html";
function App() {
return (
<Chip text="Category" fontWeight={700} color="#ffffff" backgroundColor="#ff0000" />
);
}
Common Props
text- the content of the chip. Can be a string or any elementbeforeText/afterText- elements rendered before and after the textisCircle- fully rounded cornerscolor/backgroundColor- the colors of the text and the backgroundonClick/onClickWithValue- makes the chip clickable (with hover effect).onClickWithValueis used together with thevalueprop 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.