Overview
The Pill component is an interactive button-like element ideal for filters, tags, or selectable options with support for icons, counts, and various states.
Basic Usage
import Pill from '@newtonschool/grauity';
function MyComponent() {
return (
<Pill
onClick={() => console.log('Clicked')}
>
Filter Option
</Pill>
);
}
Label content for the pill.
Optional count to display in the pill.
leftIconName
grauityIconName
default:"null"
Icon to display on the left side.
Icon to display on the right side.
Highlights the pill in an active state.
Disables the pill and applies disabled styles.
Makes the pill read-only with appropriate styles.
Size of the pill.Available choices: small, medium, large
Color theme when the pill is active.Available choices: brand, error, success, warning, yellow, purple
Callback function when the pill is clicked.Signature: (event: React.MouseEvent<HTMLButtonElement>) => void
Aria label for accessibility.
Additional CSS class name.
Additional inline styles.
Active State
<Pill isActive={true} color="brand">
Active Filter
</Pill>
<Pill isActive={false}>
Inactive Filter
</Pill>
With Count
<Pill count={5}>
Category
</Pill>
<Pill isActive={true} count={12} color="brand">
Selected Items
</Pill>
With Icons
<Pill leftIconName="filter">
Filter
</Pill>
<Pill leftIconName="star" rightIconName="chevron-down">
Favorites
</Pill>
<Pill isActive={true} leftIconName="check" color="success">
Completed
</Pill>
<Pill size="small">Small</Pill>
<Pill size="medium">Medium</Pill>
<Pill size="large">Large</Pill>
<Pill isActive={true} color="brand">Brand</Pill>
<Pill isActive={true} color="success">Success</Pill>
<Pill isActive={true} color="error">Error</Pill>
<Pill isActive={true} color="warning">Warning</Pill>
<Pill isActive={true} color="yellow">Yellow</Pill>
<Pill isActive={true} color="purple">Purple</Pill>
Disabled State
<Pill isDisabled={true}>
Disabled
</Pill>
<Pill isDisabled={true} count={3}>
Disabled with Count
</Pill>
Read-Only State
<Pill isReadOnly={true}>
Read Only
</Pill>
Filter Pills Example
function FilterExample() {
const [filters, setFilters] = useState({
active: false,
pending: false,
completed: false,
});
return (
<div style={{ display: 'flex', gap: '8px' }}>
<Pill
isActive={filters.active}
onClick={() => setFilters({ ...filters, active: !filters.active })}
leftIconName="check-circle"
count={15}
>
Active
</Pill>
<Pill
isActive={filters.pending}
onClick={() => setFilters({ ...filters, pending: !filters.pending })}
leftIconName="clock"
count={8}
>
Pending
</Pill>
<Pill
isActive={filters.completed}
onClick={() => setFilters({ ...filters, completed: !filters.completed })}
leftIconName="check"
count={42}
color="success"
>
Completed
</Pill>
</div>
);
}
Constants
import { PILL_SIZES_ENUM } from '@newtonschool/grauity';
// Usage
<Pill size={PILL_SIZES_ENUM.MEDIUM} />