|
| 1 | +import * as ItemStories from './item.stories'; |
| 2 | + |
| 3 | +# Item |
| 4 | + |
| 5 | +Item is a flexible row for lists of accounts, organizations, and settings in Mosaic. It's composed from parts via dot syntax (`Item.Root`, `Item.Media`, `Item.Content`, `Item.Title`, …). `Item.Root` renders as a `<div>` by default; pass it a `render` prop to make a row an interactive link or button, which adds hover and cursor affordances. |
| 6 | + |
| 7 | +## Example |
| 8 | + |
| 9 | +<Story |
| 10 | + name='Default' |
| 11 | + storyModule={ItemStories} |
| 12 | +/> |
| 13 | + |
| 14 | +### Interactive |
| 15 | + |
| 16 | +<Story |
| 17 | + name='Interactive' |
| 18 | + storyModule={ItemStories} |
| 19 | +/> |
| 20 | + |
| 21 | +### Group |
| 22 | + |
| 23 | +<Story |
| 24 | + name='Group' |
| 25 | + storyModule={ItemStories} |
| 26 | +/> |
| 27 | + |
| 28 | +## Usage |
| 29 | + |
| 30 | +```tsx |
| 31 | +import { Avatar } from '@clerk/ui/mosaic/components/avatar'; |
| 32 | +import { Item } from '@clerk/ui/mosaic/components/item'; |
| 33 | + |
| 34 | +<Item.Group> |
| 35 | + <Item.Root render={({ children, ...props }) => <a {...props} href='/org'>{children}</a>}> |
| 36 | + <Item.Media> |
| 37 | + <Avatar.Root shape='square' size='md'> |
| 38 | + <Avatar.Image src={org.imageUrl} alt='' /> |
| 39 | + <Avatar.Fallback>{org.name[0]}</Avatar.Fallback> |
| 40 | + </Avatar.Root> |
| 41 | + </Item.Media> |
| 42 | + <Item.Content> |
| 43 | + <Item.Title>Test Organization</Item.Title> |
| 44 | + <Item.Description>Member</Item.Description> |
| 45 | + </Item.Content> |
| 46 | + <Item.Actions> |
| 47 | + <Button variant='outline'>Manage</Button> |
| 48 | + </Item.Actions> |
| 49 | + </Item.Root> |
| 50 | +</Item.Group>; |
| 51 | +``` |
| 52 | + |
| 53 | +## Parts |
| 54 | + |
| 55 | +| Part | Class | Description | |
| 56 | +| -------------------- | ------------------------ | -------------------------------------------------------------------- | |
| 57 | +| `Item.Root` | `cl-item` | Root row. Renders a `<div>`, or a custom element via `render`. | |
| 58 | +| `Item.Media` | `cl-item-media` | Leading (or trailing) media: icon, image, or avatar. | |
| 59 | +| `Item.Content` | `cl-item-content` | Vertical stack that grows to fill the row between media and actions. | |
| 60 | +| `Item.Title` | `cl-item-title` | Primary label. | |
| 61 | +| `Item.Description` | `cl-item-description` | Secondary text. Renders a `<p>`. | |
| 62 | +| `Item.Actions` | `cl-item-actions` | Trailing controls (buttons, badges). | |
| 63 | +| `Item.Header` | `cl-item-header` | Header row above a group: a label with optional actions. | |
| 64 | +| `Item.HeaderTitle` | `cl-item-header-title` | Label text within an `Item.Header`. | |
| 65 | +| `Item.HeaderActions` | `cl-item-header-actions` | Trailing controls within an `Item.Header`. | |
| 66 | +| `Item.Group` | `cl-item-group` | Vertical wrapper around a set of rows (layout only, no role). | |
| 67 | +| `Item.Separator` | `cl-item-separator` | Thin divider (`<hr>`) between rows. | |
| 68 | + |
| 69 | +Every part accepts a `render` prop for element polymorphism and forwards a ref. |
| 70 | + |
| 71 | +## Styling |
| 72 | + |
| 73 | +The root reflects its state as `data-*` attributes on `.cl-item`, so consumers can scope overrides without touching StyleX's hashed atoms: |
| 74 | + |
| 75 | +| Prop | Attribute | Values | Default | |
| 76 | +| --------- | ------------------ | ----------------------------------- | -------- | |
| 77 | +| `variant` | `data-variant` | `entity` \| `action` | `entity` | |
| 78 | +| `render` | `data-interactive` | present when a `render` is provided | — | |
| 79 | + |
| 80 | +`variant` sets the row's vertical density (`entity` is standard, `action` is denser) and, on interactive rows, promotes the title color. |
| 81 | + |
| 82 | +```css |
| 83 | +/* Re-theme interactive rows */ |
| 84 | +.cl-item[data-interactive] { |
| 85 | + background-color: var(--cl-color-card); |
| 86 | +} |
| 87 | +``` |
| 88 | + |
| 89 | +`Item.Media` sizes to its child and centers it; its height follows the row. Bring your own icon, avatar, or image at whatever dimensions you need, then size the slot by sizing that child. Colors, radii, and spacing all resolve from the Mosaic tokens (`--cl-color-*`, `--cl-radius-*`, `--cl-spacing`). |
0 commit comments