Chips
Chips are compact components that represent discrete information.
Chips allow users to enter information, make selections, filter content, or trigger actions. While buttons are expected to appear consistently and with familiar calls to action, chips should appear dynamically as a group of multiple interactive elements.
The most common use will be in some form of input, so some of the behaviour demonstrated here is not shown in context.
ActionChips
Action chips trigger actions related to primary content.
Despite that buttons are an alternative to action chips, there is an important difference between them. Buttons should appear persistently and consistently, while action buttons should appear dynamically and contextually.
You can declare the desired action with the onClick
property.
RemovableChips
Removable chips represent information used in fields, and they can be removed with the help of a remove button.
They enable user input and verify that input by converting text into chips.
You can declare the desired remove action with the onRemove
property.
ChoiceChips
Choice chips represent a selection / filters for a collection.
They are a good alternative to toggle buttons, radio buttons, checkboxes, and select menus.
Choice chips can be controlled or uncontrolled.
To set the default state of the uncontrolled choice chips, use defaultSelected
property with a boolean value.
To control the state of the controlled choice chips, use selected={boolean}
and onToggle
properties.
Disabled
Disabled chips do not respond to any action.
Rounded
To have a rounded version of chips use rounded
property.
Size
To have the larger or smaller chips, use the size
property.
Outlined
Outlined chips offer an alternative style.
With Leading Icon
Sometimes you might want to have icons for certain chips to enhance the UX of the application as we recognize imagery more easily than plain text.
API
Learn more about the properties and the customization points.
Usage
import ActionChip from "@sonnat/ui/ActionChip";import RemovableChip from "@sonnat/ui/RemovableChip";import ChoiceChip from "@sonnat/ui/ChoiceChip";//orimport { ActionChip, RemovableChip, ChoiceChip } from "@sonnat/ui";
Properties
Note that the documentation avoids mentioning all the native props (there are a lot) in this section of the components.
Shared Properties
The properties that are common to choice, action, and removable chips.
Name | Type | Default | Description |
---|---|---|---|
label required | string | - | The content of the chip. |
className | string | - | Append to the class names applied to the component so you can override or extend the styles. |
rounded | boolean | false | If true , the chip will be rounded. |
disabled | boolean | false | If true , the chip will be disabled. |
size | "large" | "medium" | "small" | "medium" | The size of the chip. |
color | "default" | "primary" | "secondary" | "default" | The color of the chip. |
variant | "filled" | "outlined" | "filled" | The variant of the chip. |
leadingIcon | node | - | The leading icon element placed before the label. |
|
ActionChip Specific Properties
The properties that are only available to action chips.
Name | Type | Default | Description |
---|---|---|---|
onClick | function | - | Callback fired when the action chip is clicked. Signature: function(event: React.MouseEvent) => void |
RemovableChip Specific Properties
The properties that are only available to removable chips.
Name | Type | Default | Description |
---|---|---|---|
onRemove | function | - | Callback fired when the remove button is clicked. Signature: function(event: React.MouseEvent) => void |
ChoiceChip Specific Properties
The properties that are only available to choice chips.
Name | Type | Default | Description |
---|---|---|---|
selected | boolean | false | If true , the chip will be selected. |
defaultSelected | boolean | false | The default state of selected . Use when the component is not controlled. |
onToggle | function | - | Callback fired when the chip is selected/unselected. Signature: function(isSelected: boolean) => void |