# List

Rows of related items, shown right on the page.

```tsx
import { List, ListItem } from '@halo-ds/react';
```

## When to use it
Use a list for items people scan, open or act on: contacts, files, settings or notifications. Each row is a List item with an optional picture at the start, a title, an optional description and an optional control at the end. List items are also the rows inside Menus, Selects and Comboboxes.

## Do
- Keep the same parts in every row of a list.
- Put the most important words first in the title.
- Use Divided or Card for long lists on a page.
- Put more actions in a "⋯" Compact button.

## Don't
- Put more than one button at the end of a row.
- Mix sizes in one list.
- Write more than two lines in the description.
- Make only part of a row clickable without showing which part.

## Props
### List props
| Prop | Type | What it does |
| --- | --- | --- |
| `variant` | `"plain" \| "divided" \| "card" \| undefined` | plain, divided (lines between items) or card (a bordered box). Figma: Style. |
| `size` | `"sm" \| "md" \| undefined` | Figma: Size. |
| `inset` | `boolean \| undefined` | For lists whose rows can be hovered or selected, like conversations and pickers: every row gets 8px side padding, so the highlight doesn't touch the avatar or icon. Without it, rows have no side padding and line up with the content around the list; the card style gives its own inset. Figma: 8px side padding on the List item. |
| `classNames` | `Partial<Record<ListPart, string>> \| undefined` | Extra class names for the parts inside the component, by part name, like `{ header: 'my-header' }`. |
| `styles` | `Partial<Record<ListPart, CSSProperties>> \| undefined` | Inline styles for the parts inside the component, by part name, like `{ footer: { gap: 4 } }`. |
It also takes the usual HTML attributes for its element.

### ListItem props
| Prop | Type | What it does |
| --- | --- | --- |
| `title` (required) | `ReactNode` | Figma: Title. |
| `description` | `ReactNode` | Figma: Description. |
| `icon` | `ReactNode` | Icon before the text. Figma: L icon. |
| `leading` | `ReactNode` | Anything before the text instead of an icon, like an Avatar or Checkbox. Figma: L slot. |
| `trailing` | `ReactNode` | Anything after the text, like a Badge, Switch or value. Figma: R slot. |
| `trailingIcon` | `ReactNode` | Icon at the end, like a caret for items that open something. Figma: R icon. |
| `href` | `string \| undefined` | Makes the row a link. |
| `onClick` | `MouseEventHandler<HTMLElement> \| undefined` | Makes the row a button. |
| `selected` | `boolean \| undefined` | Purple background for the chosen row. Figma: State=Selected. |
| `disabled` | `boolean \| undefined` |  |
| `inset` | `boolean \| undefined` | 8px side padding for a row people hover or select. Defaults to the List's `inset`. |
| `classNames` | `Partial<Record<ListItemPart, string>> \| undefined` | Extra class names for the parts inside the component, by part name, like `{ header: 'my-header' }`. |
| `styles` | `Partial<Record<ListItemPart, CSSProperties>> \| undefined` | Inline styles for the parts inside the component, by part name, like `{ footer: { gap: 4 } }`. |
It also takes the usual HTML attributes for its element.

## Examples
### Overview
```tsx
import { List, ListItem } from '@halo-ds/react';
import { FileImage, FilePdf, FileText } from '@phosphor-icons/react';

export default function Example() {
  return (
    <div style={{ width: 360 }}>
      <List variant="divided" inset>
        <ListItem icon={<FilePdf />} title="Quarterly report.pdf" description="2.4 MB" onClick={() => {}} />
        <ListItem icon={<FileImage />} title="Cover image.png" description="840 KB" onClick={() => {}} />
        <ListItem icon={<FileText />} title="Notes.txt" description="12 KB" onClick={() => {}} />
      </List>
    </div>
  );
}
```

### Divided with avatars
Lines between rows, a person on the left and a status on the right.
```tsx
import { Avatar, Badge, List, ListItem } from '@halo-ds/react';

export default function Demo() {
  return (
    <div style={{ width: 380 }}>
      <List variant="divided">
        <ListItem title="Ada Obi" description="ada@example.com" leading={<Avatar size="sm" name="Ada Obi" color="purple" />} trailing={<Badge color="success">Active</Badge>} />
        <ListItem title="Kofi Mensah" description="kofi@example.com" leading={<Avatar size="sm" name="Kofi Mensah" />} trailing={<Badge>Invited</Badge>} />
        <ListItem title="Lena Park" description="lena@example.com" leading={<Avatar size="sm" name="Lena Park" color="blue" />} trailing={<Badge color="success">Active</Badge>} />
      </List>
    </div>
  );
}
```

### Card with switches
A bordered box in the small size, here for settings.
```tsx
import { List, ListItem, Switch } from '@halo-ds/react';

export default function Demo() {
  return (
    <div style={{ width: 380 }}>
      <List variant="card" size="sm">
        <ListItem title="Email updates" description="A weekly summary" trailing={<Switch aria-label="Email updates" defaultChecked />} />
        <ListItem title="Push notifications" description="Mentions and replies" trailing={<Switch aria-label="Push notifications" />} />
      </List>
    </div>
  );
}
```

More: https://halodesignsystem.dev/components/list
