Content
List item
A list item is one row of a list that sits flat on paper, such as a payment in a statement, an entry in the timeline or a project in a web list.
In kanso-ui as ListItem
Web and native
ListItem in kanso-ui 0.59.0, for React.
import { ListItem } from '@kanso-labs/kanso-ui'A single static list row: a headline with optional leading content, supporting line, overline and trailing content.
It is the row the Material Design lists spec draws: a 56px one-line container with a body-large headline and a body-medium supporting line. One extra line (supporting or overline) makes the 72px two-line item; an overline with a supporting line makes the 88px three-line item, where the leading and trailing slots move to the top of the row. Nothing truncates: a long headline wraps and the row grows.
What you provide
- The headline as
children. - A container with a width; the row fills its parent.
- For an interactive row, an
onClick(or other handlers) to act on the press.
Props
| Prop | Type | Default | Description |
|---|---|---|---|
children | ReactNode | — | The row's title — the one thing it is mostly about. |
density | 'compact' | 'default' | 'default' | How tall the row stands: `default`, Kanso's 60px row, or `compact`, its 44px row for one-line rows on the web. A row whose text wraps grows past either. |
interactive | boolean | false | Renders a `<button>` that takes Kanso's hover and focus layers and ripples at its pressed layer, for a row that is itself pressable, such as one that opens what it names. Its name is its text, title first. Leave it off for a row that only presents. Only an interactive row takes `onClick`, `onContextMenu` and the pointer handlers. A row that only presents is a `<div>` that cannot be focused or operated from the keyboard, so a handler on it would answer a mouse and nothing else. An interactive row's slots hold content and never a control. The row is one button, and a checkbox, a switch, a link or a button inside it is invalid HTML: axe reports it as nested interactive content, and React warns as well when the control is itself a button. A row that carries a control is a presenting row, or a `List.Item`, whose rows are built to hold them. |
isDisabled | boolean | false | Draws the row disabled, in Kanso's disabled treatment: its text at 38% of `ink`, the line under the title and the overline included, and its leading and trailing content faded to 38%. Kanso's page leaves a row that cannot be used out rather than disabling it, so prefer that. An interactive row's button is disabled outright: it takes no focus, no hover tint, no press and no ripple. A row that only presents has nothing to disable, and is marked `aria-disabled` instead so the state it draws is announced as well. |
leading | ReactNode | — | Content before the title: an avatar, as Kanso leads a row a person did, the time, as it leads a row time orders, an icon, or on a row that is not `interactive`, a checkbox. Hide an avatar from assistive technology with its `decorative` when the row's text names the person. |
onClick | never | — | |
onContextMenu | never | — | |
onPointerCancel | never | — | |
onPointerDown | never | — | |
onPointerLeave | never | — | |
onPointerUp | never | — | |
overline | ReactNode | — | A line above the title, in the same 13px `ink-muted` the line under it takes — a category, a date, a status. |
supporting | ReactNode | — | The line under the title, Kanso's meta line: 13px in `ink-muted`, such as a date and who did it, or a status in words. |
trailing | ReactNode | — | Content after the title, set in Kanso's mono figure: an amount with its sign, a chevron on a row that opens something, or on a row that is not `interactive`, a control. One thing, never two. |
Also takes the props of HTMLAttributes<HTMLElement>.
Example
import { Avatar, Card, ListItem } from '@kanso-labs/kanso-ui'
<Card padding="none" variant="outlined">
<ListItem
interactive
leading={<Avatar name="Ada Lovelace" size="md" />}
supporting="Supporting line"
>
Headline
</ListItem>
</Card>The design’s classes
k-list, k-list--inset, k-item, k-item--compact, k-item--selected, k-item__time, k-item__body, k-item__title, k-item__meta, k-item__trail, k-item__chevron, with k-avatar, k-mark and k-figure--positive. Maps to ListItem, inside List, in kanso-ui and react-native-kanso-ui.