# Table List

Turns table-style rows and columns into a grouped list of rows with a title, description and trailing values.

Table List is an open-source mobile pattern from suiss/uim: components composed into a flow for React Native and Expo, with SwiftUI and Jetpack Compose versions built from the same design tokens. The @esuiss/uim CLI copies its source into your project, so you own the code.

Source: https://uim.suiss.app/docs/patterns/table-list

![Preview](https://uim.suiss.app/previews/patterns-table-list--default.light.webp)

```tsx
import { View } from "react-native"
import { TableList, type TableListColumn } from "@/components/patterns/table-list"

type Invoice = {
  id: string
  customer: string
  status: string
  method: string
  amount: string
}

const invoices: Invoice[] = [
  {
    id: "INV001",
    customer: "Olivia Martin",
    status: "Paid",
    method: "Card",
    amount: "$250.00",
  },
  {
    id: "INV002",
    customer: "Jackson Lee",
    status: "Pending",
    method: "PayPal",
    amount: "$150.00",
  },
  {
    id: "INV003",
    customer: "Isabella Nguyen",
    status: "Unpaid",
    method: "Transfer",
    amount: "$350.00",
  },
  {
    id: "INV004",
    customer: "William Kim",
    status: "Paid",
    method: "Card",
    amount: "$450.00",
  },
]

const columns: TableListColumn<Invoice>[] = [
  {
    key: "customer",
    header: "Customer",
    cell: (row) => row.customer,
    slot: "title",
  },
  {
    key: "status",
    header: "Status",
    cell: (row) => row.status,
    slot: "description",
  },
  {
    key: "method",
    header: "Method",
    cell: (row) => row.method,
    slot: "description",
  },
  {
    key: "amount",
    header: "Amount",
    cell: (row) => row.amount,
    slot: "trailing",
    align: "end",
  },
]

export function TableListExample() {
  return (
    <View className="gap-8">
      <TableList
        title="Invoices"
        rows={invoices}
        columns={columns}
        getKey={(row) => row.id}
        onRowPress={() => {}}
      />
      <TableList rows={[]} columns={columns} emptyText="No invoices yet." />
    </View>
  )
}
```

```swift
import EsuissUI
import SwiftUI

struct TableListExample: View {
  var body: some View {
    VStack(alignment: .leading, spacing: 32) {
      TableList(tableListInvoices, columns: tableListColumns, title: "Invoices", action: { _ in })
      TableList([TableListInvoice](), columns: tableListColumns, emptyText: "No invoices yet.")
    }
  }
}

struct TableListInvoice: Identifiable {
  let id: String
  let customer: String
  let status: String
  let method: String
  let amount: String
}

let tableListInvoices = [
  TableListInvoice(id: "INV001", customer: "Olivia Martin", status: "Paid", method: "Card", amount: "$250.00"),
  TableListInvoice(id: "INV002", customer: "Jackson Lee", status: "Pending", method: "PayPal", amount: "$150.00"),
  TableListInvoice(id: "INV003", customer: "Isabella Nguyen", status: "Unpaid", method: "Transfer", amount: "$350.00"),
  TableListInvoice(id: "INV004", customer: "William Kim", status: "Paid", method: "Card", amount: "$450.00"),
]

let tableListColumns: [TableListColumn<TableListInvoice>] = [
  TableListColumn("customer", header: "Customer", slot: .title) { Text(verbatim: $0.customer) },
  TableListColumn("status", header: "Status", slot: .description) { Text(verbatim: $0.status) },
  TableListColumn("method", header: "Method", slot: .description) { Text(verbatim: $0.method) },
  TableListColumn("amount", header: "Amount", slot: .trailing) { Text(verbatim: $0.amount) },
]
```

```kotlin
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.runtime.Composable
import androidx.compose.ui.unit.dp
import com.esuiss.ui.components.Text
import com.esuiss.ui.patterns.TableList
import com.esuiss.ui.patterns.TableListAlign
import com.esuiss.ui.patterns.TableListColumn
import com.esuiss.ui.patterns.TableListSlot

class TableListInvoice(
    val id: String,
    val customer: String,
    val status: String,
    val method: String,
    val amount: String,
)

val tableListInvoices = listOf(
    TableListInvoice("INV001", "Olivia Martin", "Paid", "Card", "$250.00"),
    TableListInvoice("INV002", "Jackson Lee", "Pending", "PayPal", "$150.00"),
    TableListInvoice("INV003", "Isabella Nguyen", "Unpaid", "Transfer", "$350.00"),
    TableListInvoice("INV004", "William Kim", "Paid", "Card", "$450.00"),
)

val tableListColumns = listOf(
    TableListColumn<TableListInvoice>("customer", "Customer", slot = TableListSlot.Title) { Text(it.customer, maxLines = 1) },
    TableListColumn<TableListInvoice>("status", "Status", slot = TableListSlot.Description) { Text(it.status, maxLines = 1) },
    TableListColumn<TableListInvoice>("method", "Method", slot = TableListSlot.Description) { Text(it.method, maxLines = 1) },
    TableListColumn<TableListInvoice>("amount", "Amount", slot = TableListSlot.Trailing, align = TableListAlign.End) {
        Text(it.amount, maxLines = 1)
    },
)

@Composable
fun TableListDefault() {
    Column(verticalArrangement = Arrangement.spacedBy(32.dp)) {
        TableList(
            rows = tableListInvoices,
            columns = tableListColumns,
            getKey = { row, _ -> row.id },
            title = "Invoices",
            onRowClick = {},
        )
        TableList(rows = emptyList(), columns = tableListColumns, emptyText = "No invoices yet.")
    }
}
```

`TableList` takes `rows` and a `columns` definition, and renders each row as a `TableListRow` inside one rounded group. Each column has a `slot` that decides where its cell goes: the row title, the description line, the trailing side, or nowhere.

The row parts are also exported, so you can build the same grouped look inside a `FlatList` for long or virtualized lists.

## Installation

```bash title="Terminal"
npx @esuiss/uim@latest add table-list
```

```bash title="Terminal"
npx @esuiss/uim@latest add table-list --platform swift
```

```bash title="Terminal"
npx @esuiss/uim@latest add table-list --platform kotlin
```

The CLI also adds what it builds on: [Item](/docs/components/item), [Text](/docs/components/text).

### Manual

**Uniwind**

1. Install the dependencies:

```bash title="Terminal"
npx expo install cn
```

2. Add the pieces it builds on: [Item](/docs/components/item), [Text](/docs/components/text).

3. Copy the source into `components/patterns/table-list.tsx`:

```tsx title="uniwind/components/patterns/table-list.tsx"
import { cn } from "cn"
import * as React from "react"
import { View, type ViewProps } from "react-native"
import {
  Item,
  ItemActions,
  ItemContent,
  ItemDescription,
  ItemTitle,
} from "@/components/ui/item"
import { Text } from "@/components/ui/text"

type TableListColumn<T> = {
  key: string
  header: React.ReactNode
  cell: (row: T) => React.ReactNode
  mobileCell?: (row: T) => React.ReactNode
  slot?: "title" | "description" | "trailing" | "hidden"
  align?: "start" | "end"
}

function isText(node: React.ReactNode) {
  return typeof node === "string" || typeof node === "number"
}

function TableListTitle({
  className,
  ...props
}: React.ComponentProps<typeof Text>) {
  return (
    <Text
      role="heading"
      className={cn("text-3xl font-bold text-label", className)}
      {...props}
    />
  )
}

function TableListHeader({
  className,
  ...props
}: React.ComponentProps<typeof Text>) {
  return (
    <Text
      role="heading"
      className={cn(
        "px-4 pt-4 pb-1.5 text-sm text-label-secondary uppercase",
        className
      )}
      {...props}
    />
  )
}

function TableListFooter({
  className,
  ...props
}: React.ComponentProps<typeof Text>) {
  return (
    <Text
      className={cn("px-4 pt-1.5 pb-2 text-sm text-label-secondary", className)}
      {...props}
    />
  )
}

function TableListSeparator({ className, ...props }: ViewProps) {
  return (
    <View
      accessible={false}
      importantForAccessibility="no"
      className={cn("bg-surface-secondary", className)}
      {...props}
    >
      <View className="ms-4 h-px bg-separator" />
    </View>
  )
}

function TableListRow({
  title,
  description,
  trailing,
  first = false,
  last = false,
  className,
  children,
  ...props
}: Omit<React.ComponentProps<typeof Item>, "children"> & {
  title?: React.ReactNode
  description?: React.ReactNode
  trailing?: React.ReactNode
  first?: boolean
  last?: boolean
  children?: React.ReactNode
}) {
  return (
    <Item
      size="sm"
      className={cn(
        "min-h-11 flex-nowrap gap-4 rounded-none bg-surface-secondary px-4 py-2.75 active:bg-surface-tertiary",
        first && "rounded-t-2xl",
        last && "rounded-b-2xl",
        className
      )}
      {...props}
    >
      {children ?? (
        <>
          <ItemContent className="gap-0.5">
            {title != null ? (
              <ItemTitle className="font-normal">{title}</ItemTitle>
            ) : null}
            {description != null ? (
              <ItemDescription numberOfLines={1}>{description}</ItemDescription>
            ) : null}
          </ItemContent>
          {trailing != null ? (
            <ItemActions>
              {isText(trailing) ? (
                <Text className="text-base text-label-secondary tabular-nums">
                  {trailing}
                </Text>
              ) : (
                trailing
              )}
            </ItemActions>
          ) : null}
        </>
      )}
    </Item>
  )
}

function TableList<T>({
  rows,
  columns,
  getKey = (_, index) => index,
  title,
  emptyText = "No results.",
  onRowPress,
  className,
  ...props
}: ViewProps & {
  rows: T[]
  columns: TableListColumn<T>[]
  getKey?: (row: T, index: number) => React.Key
  title?: React.ReactNode
  emptyText?: React.ReactNode
  onRowPress?: (row: T, index: number) => void
}) {
  const titleColumn = columns.find((column) => column.slot === "title")
  const trailing = columns.filter((column) => column.slot === "trailing")
  const description = columns.filter((column) => column.slot === "description")
  const mobileCell = (column: TableListColumn<T>, row: T) =>
    (column.mobileCell ?? column.cell)(row)

  return (
    <View className={cn("flex-col gap-3", className)} {...props}>
      {title != null ? <TableListTitle>{title}</TableListTitle> : null}
      {rows.length === 0 ? (
        <View className="rounded-2xl bg-surface-secondary px-4 py-3">
          {isText(emptyText) ? (
            <Text className="text-base text-label-secondary">{emptyText}</Text>
          ) : (
            emptyText
          )}
        </View>
      ) : (
        <View role="list" className="overflow-hidden rounded-2xl">
          {rows.map((row, index) => (
            <React.Fragment key={getKey(row, index)}>
              {index > 0 ? <TableListSeparator /> : null}
              <TableListRow
                role={onRowPress ? "button" : "listitem"}
                onPress={onRowPress ? () => onRowPress(row, index) : undefined}
                title={titleColumn ? mobileCell(titleColumn, row) : undefined}
                description={
                  description.length > 0
                    ? description.map((column, position) => (
                        <React.Fragment key={column.key}>
                          {position > 0 ? " · " : null}
                          {mobileCell(column, row)}
                        </React.Fragment>
                      ))
                    : undefined
                }
                trailing={
                  trailing.length > 0
                    ? trailing.map((column) => {
                        const cell = mobileCell(column, row)
                        return isText(cell) ? (
                          <Text
                            key={column.key}
                            className="shrink-0 text-base text-label-secondary tabular-nums"
                          >
                            {cell}
                          </Text>
                        ) : (
                          <React.Fragment key={column.key}>
                            {cell}
                          </React.Fragment>
                        )
                      })
                    : undefined
                }
              />
            </React.Fragment>
          ))}
        </View>
      )}
    </View>
  )
}

export {
  TableList,
  type TableListColumn,
  TableListFooter,
  TableListHeader,
  TableListRow,
  TableListSeparator,
  TableListTitle,
}
```

4. Update the import paths to match your project.

**NativeWind**

1. Install the dependencies:

```bash title="Terminal"
npx expo install cn
```

2. Add the pieces it builds on: [Item](/docs/components/item), [Text](/docs/components/text).

3. Copy the source into `components/patterns/table-list.tsx`:

```tsx title="nativewind/components/patterns/table-list.tsx"
import { cn } from "cn"
import * as React from "react"
import { View, type ViewProps } from "react-native"
import {
  Item,
  ItemActions,
  ItemContent,
  ItemDescription,
  ItemTitle,
} from "@/components/ui/item"
import { Text } from "@/components/ui/text"

type TableListColumn<T> = {
  key: string
  header: React.ReactNode
  cell: (row: T) => React.ReactNode
  mobileCell?: (row: T) => React.ReactNode
  slot?: "title" | "description" | "trailing" | "hidden"
  align?: "start" | "end"
}

function isText(node: React.ReactNode) {
  return typeof node === "string" || typeof node === "number"
}

function TableListTitle({
  className,
  ...props
}: React.ComponentProps<typeof Text>) {
  return (
    <Text
      role="heading"
      className={cn("text-3xl font-bold text-label", className)}
      {...props}
    />
  )
}

function TableListHeader({
  className,
  ...props
}: React.ComponentProps<typeof Text>) {
  return (
    <Text
      role="heading"
      className={cn(
        "px-4 pt-4 pb-1.5 text-sm text-label-secondary uppercase",
        className
      )}
      {...props}
    />
  )
}

function TableListFooter({
  className,
  ...props
}: React.ComponentProps<typeof Text>) {
  return (
    <Text
      className={cn("px-4 pt-1.5 pb-2 text-sm text-label-secondary", className)}
      {...props}
    />
  )
}

function TableListSeparator({ className, ...props }: ViewProps) {
  return (
    <View
      accessible={false}
      importantForAccessibility="no"
      className={cn("bg-surface-secondary", className)}
      {...props}
    >
      <View className="ms-4 h-px bg-separator" />
    </View>
  )
}

function TableListRow({
  title,
  description,
  trailing,
  first = false,
  last = false,
  className,
  children,
  ...props
}: Omit<React.ComponentProps<typeof Item>, "children"> & {
  title?: React.ReactNode
  description?: React.ReactNode
  trailing?: React.ReactNode
  first?: boolean
  last?: boolean
  children?: React.ReactNode
}) {
  return (
    <Item
      size="sm"
      className={cn(
        "min-h-11 flex-nowrap gap-4 rounded-none bg-surface-secondary px-4 py-[0.6875rem] active:bg-surface-tertiary",
        first && "rounded-t-2xl",
        last && "rounded-b-2xl",
        className
      )}
      {...props}
    >
      {children ?? (
        <>
          <ItemContent className="gap-0.5">
            {title != null ? (
              <ItemTitle className="font-normal">{title}</ItemTitle>
            ) : null}
            {description != null ? (
              <ItemDescription numberOfLines={1}>{description}</ItemDescription>
            ) : null}
          </ItemContent>
          {trailing != null ? (
            <ItemActions>
              {isText(trailing) ? (
                <Text className="text-base text-label-secondary tabular-nums">
                  {trailing}
                </Text>
              ) : (
                trailing
              )}
            </ItemActions>
          ) : null}
        </>
      )}
    </Item>
  )
}

function TableList<T>({
  rows,
  columns,
  getKey = (_, index) => index,
  title,
  emptyText = "No results.",
  onRowPress,
  className,
  ...props
}: ViewProps & {
  rows: T[]
  columns: TableListColumn<T>[]
  getKey?: (row: T, index: number) => React.Key
  title?: React.ReactNode
  emptyText?: React.ReactNode
  onRowPress?: (row: T, index: number) => void
}) {
  const titleColumn = columns.find((column) => column.slot === "title")
  const trailing = columns.filter((column) => column.slot === "trailing")
  const description = columns.filter((column) => column.slot === "description")
  const mobileCell = (column: TableListColumn<T>, row: T) =>
    (column.mobileCell ?? column.cell)(row)

  return (
    <View className={cn("flex-col gap-3", className)} {...props}>
      {title != null ? <TableListTitle>{title}</TableListTitle> : null}
      {rows.length === 0 ? (
        <View className="rounded-2xl bg-surface-secondary px-4 py-3">
          {isText(emptyText) ? (
            <Text className="text-base text-label-secondary">{emptyText}</Text>
          ) : (
            emptyText
          )}
        </View>
      ) : (
        <View role="list" className="overflow-hidden rounded-2xl">
          {rows.map((row, index) => (
            <React.Fragment key={getKey(row, index)}>
              {index > 0 ? <TableListSeparator /> : null}
              <TableListRow
                role={onRowPress ? "button" : "listitem"}
                onPress={onRowPress ? () => onRowPress(row, index) : undefined}
                title={titleColumn ? mobileCell(titleColumn, row) : undefined}
                description={
                  description.length > 0
                    ? description.map((column, position) => (
                        <React.Fragment key={column.key}>
                          {position > 0 ? " · " : null}
                          {mobileCell(column, row)}
                        </React.Fragment>
                      ))
                    : undefined
                }
                trailing={
                  trailing.length > 0
                    ? trailing.map((column) => {
                        const cell = mobileCell(column, row)
                        return isText(cell) ? (
                          <Text
                            key={column.key}
                            className="shrink-0 text-base text-label-secondary tabular-nums"
                          >
                            {cell}
                          </Text>
                        ) : (
                          <React.Fragment key={column.key}>
                            {cell}
                          </React.Fragment>
                        )
                      })
                    : undefined
                }
              />
            </React.Fragment>
          ))}
        </View>
      )}
    </View>
  )
}

export {
  TableList,
  type TableListColumn,
  TableListFooter,
  TableListHeader,
  TableListRow,
  TableListSeparator,
  TableListTitle,
}
```

4. Update the import paths to match your project.

**StyleSheet**

1. Add the pieces it builds on: [Item](/docs/components/item), [Text](/docs/components/text).

2. Copy the source into `components/patterns/table-list.tsx`:

```tsx title="stylesheet/components/patterns/table-list.tsx"
import * as React from "react"
import { StyleSheet, View, type ViewProps } from "react-native"
import {
  Item,
  ItemActions,
  ItemContent,
  ItemDescription,
  ItemTitle,
} from "@/components/ui/item"
import { Text } from "@/components/ui/text"
import { fontSize, radius, useTheme } from "@/components/ui/theme"

type TableListColumn<T> = {
  key: string
  header: React.ReactNode
  cell: (row: T) => React.ReactNode
  mobileCell?: (row: T) => React.ReactNode
  slot?: "title" | "description" | "trailing" | "hidden"
  align?: "start" | "end"
}

const styles = StyleSheet.create({
  root: { flexDirection: "column", gap: 12 },
  title: { ...fontSize["3xl"], fontWeight: "700" },
  header: {
    ...fontSize.sm,
    paddingHorizontal: 16,
    paddingTop: 16,
    paddingBottom: 6,
    textTransform: "uppercase",
  },
  footer: {
    ...fontSize.sm,
    paddingHorizontal: 16,
    paddingTop: 6,
    paddingBottom: 8,
  },
  separator: { marginStart: 16, height: 1 },
  row: {
    minHeight: 44,
    flexWrap: "nowrap",
    gap: 16,
    borderRadius: 0,
    paddingHorizontal: 16,
    paddingVertical: 11,
  },
  first: {
    borderTopLeftRadius: radius["2xl"],
    borderTopRightRadius: radius["2xl"],
  },
  last: {
    borderBottomLeftRadius: radius["2xl"],
    borderBottomRightRadius: radius["2xl"],
  },
  rowContent: { gap: 2 },
  trailing: {
    ...fontSize.base,
    flexShrink: 0,
    fontVariant: ["tabular-nums"],
  },
  empty: {
    borderRadius: radius["2xl"],
    paddingHorizontal: 16,
    paddingVertical: 12,
  },
  list: { overflow: "hidden", borderRadius: radius["2xl"] },
})

function isText(node: React.ReactNode) {
  return typeof node === "string" || typeof node === "number"
}

function TableListTitle({
  style,
  ...props
}: React.ComponentProps<typeof Text>) {
  const { colors } = useTheme()
  return (
    <Text
      role="heading"
      style={[styles.title, { color: colors.label }, style]}
      {...props}
    />
  )
}

function TableListHeader({
  style,
  ...props
}: React.ComponentProps<typeof Text>) {
  const { colors } = useTheme()
  return (
    <Text
      role="heading"
      style={[styles.header, { color: colors.labelSecondary }, style]}
      {...props}
    />
  )
}

function TableListFooter({
  style,
  ...props
}: React.ComponentProps<typeof Text>) {
  const { colors } = useTheme()
  return (
    <Text
      style={[styles.footer, { color: colors.labelSecondary }, style]}
      {...props}
    />
  )
}

function TableListSeparator({ style, ...props }: ViewProps) {
  const { colors } = useTheme()
  return (
    <View
      accessible={false}
      importantForAccessibility="no"
      style={[{ backgroundColor: colors.surfaceSecondary }, style]}
      {...props}
    >
      <View style={[styles.separator, { backgroundColor: colors.separator }]} />
    </View>
  )
}

function TableListRow({
  title,
  description,
  trailing,
  first = false,
  last = false,
  style,
  children,
  ...props
}: Omit<React.ComponentProps<typeof Item>, "children"> & {
  title?: React.ReactNode
  description?: React.ReactNode
  trailing?: React.ReactNode
  first?: boolean
  last?: boolean
  children?: React.ReactNode
}) {
  const { colors } = useTheme()
  return (
    <Item
      size="sm"
      style={(state) => [
        styles.row,
        {
          backgroundColor: state.pressed
            ? colors.surfaceTertiary
            : colors.surfaceSecondary,
        },
        first && styles.first,
        last && styles.last,
        typeof style === "function" ? style(state) : style,
      ]}
      {...props}
    >
      {children ?? (
        <>
          <ItemContent style={styles.rowContent}>
            {title != null ? (
              <ItemTitle style={{ fontWeight: "400" }}>{title}</ItemTitle>
            ) : null}
            {description != null ? (
              <ItemDescription numberOfLines={1}>{description}</ItemDescription>
            ) : null}
          </ItemContent>
          {trailing != null ? (
            <ItemActions>
              {isText(trailing) ? (
                <Text
                  style={[styles.trailing, { color: colors.labelSecondary }]}
                >
                  {trailing}
                </Text>
              ) : (
                trailing
              )}
            </ItemActions>
          ) : null}
        </>
      )}
    </Item>
  )
}

function TableList<T>({
  rows,
  columns,
  getKey = (_, index) => index,
  title,
  emptyText = "No results.",
  onRowPress,
  style,
  ...props
}: ViewProps & {
  rows: T[]
  columns: TableListColumn<T>[]
  getKey?: (row: T, index: number) => React.Key
  title?: React.ReactNode
  emptyText?: React.ReactNode
  onRowPress?: (row: T, index: number) => void
}) {
  const { colors } = useTheme()
  const titleColumn = columns.find((column) => column.slot === "title")
  const trailing = columns.filter((column) => column.slot === "trailing")
  const description = columns.filter((column) => column.slot === "description")
  const mobileCell = (column: TableListColumn<T>, row: T) =>
    (column.mobileCell ?? column.cell)(row)

  return (
    <View style={[styles.root, style]} {...props}>
      {title != null ? <TableListTitle>{title}</TableListTitle> : null}
      {rows.length === 0 ? (
        <View
          style={[styles.empty, { backgroundColor: colors.surfaceSecondary }]}
        >
          {isText(emptyText) ? (
            <Text style={{ ...fontSize.base, color: colors.labelSecondary }}>
              {emptyText}
            </Text>
          ) : (
            emptyText
          )}
        </View>
      ) : (
        <View role="list" style={styles.list}>
          {rows.map((row, index) => (
            <React.Fragment key={getKey(row, index)}>
              {index > 0 ? <TableListSeparator /> : null}
              <TableListRow
                role={onRowPress ? "button" : "listitem"}
                onPress={onRowPress ? () => onRowPress(row, index) : undefined}
                title={titleColumn ? mobileCell(titleColumn, row) : undefined}
                description={
                  description.length > 0
                    ? description.map((column, position) => (
                        <React.Fragment key={column.key}>
                          {position > 0 ? " · " : null}
                          {mobileCell(column, row)}
                        </React.Fragment>
                      ))
                    : undefined
                }
                trailing={
                  trailing.length > 0
                    ? trailing.map((column) => {
                        const cell = mobileCell(column, row)
                        return isText(cell) ? (
                          <Text
                            key={column.key}
                            style={[
                              styles.trailing,
                              { color: colors.labelSecondary },
                            ]}
                          >
                            {cell}
                          </Text>
                        ) : (
                          <React.Fragment key={column.key}>
                            {cell}
                          </React.Fragment>
                        )
                      })
                    : undefined
                }
              />
            </React.Fragment>
          ))}
        </View>
      )}
    </View>
  )
}

export {
  TableList,
  type TableListColumn,
  TableListFooter,
  TableListHeader,
  TableListRow,
  TableListSeparator,
  TableListTitle,
}
```

3. Update the import paths to match your project.

**SwiftUI**

1. Target iOS 17 or later.

2. Copy the theme files every view uses:

```swift title="swift/Theme/Theme.swift"
import SwiftUI
import UIKit

struct RGBA: Sendable {
  let red: CGFloat
  let green: CGFloat
  let blue: CGFloat
  let alpha: CGFloat

  init(_ hex: UInt32, _ alpha: CGFloat = 1) {
    red = CGFloat((hex >> 16) & 0xFF) / 255
    green = CGFloat((hex >> 8) & 0xFF) / 255
    blue = CGFloat(hex & 0xFF) / 255
    self.alpha = alpha
  }

  var uiColor: UIColor {
    UIColor(red: red, green: green, blue: blue, alpha: alpha)
  }
}

extension Color {
  static func adaptive(light: RGBA, dark: RGBA) -> Color {
    let lightColor = light.uiColor
    let darkColor = dark.uiColor
    return Color(uiColor: UIColor { traits in
      traits.userInterfaceStyle == .dark ? darkColor : lightColor
    })
  }
}

public struct TextStyle: Sendable, Hashable {
  public let size: CGFloat
  public let lineHeight: CGFloat
  public let letterSpacing: CGFloat

  public init(size: CGFloat, lineHeight: CGFloat, letterSpacing: CGFloat) {
    self.size = size
    self.lineHeight = lineHeight
    self.letterSpacing = letterSpacing
  }

  public func font(weight: Font.Weight = .regular) -> Font {
    .system(size: size, weight: weight)
  }

  public var lineSpacing: CGFloat {
    max(0, lineHeight - UIFont.systemFont(ofSize: size).lineHeight)
  }
}

extension Hashable where Self == Font {
  public static func textStyle(_ style: TextStyle, weight: Font.Weight = .regular) -> Font {
    style.font(weight: weight)
  }
}

private struct TextStyleModifier: ViewModifier {
  let style: TextStyle
  let weight: Font.Weight

  func body(content: Content) -> some View {
    content
      .font(style.font(weight: weight))
      .tracking(style.letterSpacing)
      .lineSpacing(style.lineSpacing)
      .padding(.vertical, style.lineSpacing / 2)
  }
}

extension View {
  public func textStyle(_ style: TextStyle, weight: Font.Weight = .regular) -> some View {
    modifier(TextStyleModifier(style: style, weight: weight))
  }
}

public struct Shadow: Sendable, Hashable {
  public let color: Color
  public let radius: CGFloat
  public let x: CGFloat
  public let y: CGFloat

  public init(color: Color, radius: CGFloat, x: CGFloat = 0, y: CGFloat = 0) {
    self.color = color
    self.radius = radius
    self.x = x
    self.y = y
  }
}

extension View {
  public func shadow(_ shadow: Shadow) -> some View {
    self.shadow(color: shadow.color, radius: shadow.radius, x: shadow.x, y: shadow.y)
  }
}
```

```swift title="swift/Theme/Tokens.swift"
import SwiftUI

extension Color {
  public static let surface = Color.adaptive(light: .init(0xFFFFFF), dark: .init(0x000000))
  public static let surfaceSecondary = Color.adaptive(light: .init(0xF5F5F7), dark: .init(0x161617))
  public static let surfaceTertiary = Color.adaptive(light: .init(0xE8E8ED), dark: .init(0x2C2C2E))
  public static let surfaceRaised = Color.adaptive(light: .init(0xFFFFFF), dark: .init(0x1D1D1F))
  public static let label = Color.adaptive(light: .init(0x1D1D1F), dark: .init(0xF5F5F7))
  public static let labelSecondary = Color.adaptive(light: .init(0x6E6E73), dark: .init(0xA1A1A6))
  public static let labelTertiary = Color.adaptive(light: .init(0x86868B), dark: .init(0x86868B))
  public static let labelQuaternary = Color.adaptive(light: .init(0xD2D2D7), dark: .init(0x424245))
  public static let control = Color.adaptive(light: .init(0x000000, 0.04), dark: .init(0xFFFFFF, 0.1))
  public static let controlPressed = Color.adaptive(light: .init(0x000000, 0.12), dark: .init(0xFFFFFF, 0.22))
  public static let controlSelected = Color.adaptive(light: .init(0x1D1D1F), dark: .init(0xF5F5F7))
  public static let controlDisabled = Color.adaptive(light: .init(0x000000, 0.03), dark: .init(0xFFFFFF, 0.05))
  public static let onControlSelected = Color.adaptive(light: .init(0xFFFFFF), dark: .init(0x000000))
  public static let itemPressed = Color.adaptive(light: .init(0x000000, 0.08), dark: .init(0xFFFFFF, 0.12))
  public static let itemSelected = Color.adaptive(light: .init(0x000000, 0.06), dark: .init(0xFFFFFF, 0.1))
  public static let separator = Color.adaptive(light: .init(0xD2D2D7), dark: .init(0x424245))
  public static let separatorStrong = Color.adaptive(light: .init(0x86868B), dark: .init(0x6E6E73))
  public static let accent = Color.adaptive(light: .init(0x0071E3), dark: .init(0x0071E3))
  public static let accentPressed = Color.adaptive(light: .init(0x005BB8), dark: .init(0x004D9E))
  public static let accentSelected = Color.adaptive(light: .init(0x0071E3), dark: .init(0x0071E3))
  public static let accentDisabled = Color.adaptive(light: .init(0x0071E3, 0.4), dark: .init(0x0071E3, 0.4))
  public static let onAccent = Color.adaptive(light: .init(0xFFFFFF), dark: .init(0xFFFFFF))
  public static let accentSurface = Color.adaptive(light: .init(0x0071E3, 0.09), dark: .init(0x0071E3, 0.18))
  public static let accentSurfacePressed = Color.adaptive(light: .init(0x0071E3, 0.18), dark: .init(0x0071E3, 0.3))
  public static let link = Color.adaptive(light: .init(0x0066CC), dark: .init(0x2997FF))
  public static let focus = Color.adaptive(light: .init(0x0071E3), dark: .init(0x0071E3))
  public static let scrim = Color.adaptive(light: .init(0x000000, 0.48), dark: .init(0x000000, 0.48))
  public static let media = Color.adaptive(light: .init(0x000000), dark: .init(0x000000))
  public static let onMedia = Color.adaptive(light: .init(0xFFFFFF), dark: .init(0xFFFFFF))
  public static let danger = Color.adaptive(light: .init(0xD0000A), dark: .init(0xFF5447))
  public static let dangerSurface = Color.adaptive(light: .init(0xD70015, 0.08), dark: .init(0xFF453A, 0.2))
  public static let dangerSurfacePressed = Color.adaptive(light: .init(0xD70015, 0.16), dark: .init(0xFF453A, 0.36))
  public static let success = Color.adaptive(light: .init(0x008009), dark: .init(0x30D158))
  public static let successSurface = Color.adaptive(light: .init(0xEFFAF1), dark: .init(0x30D158, 0.16))
  public static let warning = Color.adaptive(light: .init(0xB64400), dark: .init(0xFF9F0A))
  public static let warningSurface = Color.adaptive(light: .init(0xFFF5EA), dark: .init(0xFF9F0A, 0.16))
}

public enum Radius {
  public static let xs: CGFloat = 3
  public static let sm: CGFloat = 5
  public static let md: CGFloat = 8
  public static let lg: CGFloat = 10
  public static let xl: CGFloat = 12
  public static let xl2: CGFloat = 18
  public static let xl3: CGFloat = 28
  public static let full: CGFloat = 9999
}

extension TextStyle {
  public static let xs3 = TextStyle(size: 11, lineHeight: 13, letterSpacing: 0.066)
  public static let xs2 = TextStyle(size: 12, lineHeight: 16, letterSpacing: 0)
  public static let xs = TextStyle(size: 13, lineHeight: 18, letterSpacing: -0.078)
  public static let sm = TextStyle(size: 15, lineHeight: 20, letterSpacing: -0.24)
  public static let md = TextStyle(size: 16, lineHeight: 21, letterSpacing: -0.32)
  public static let base = TextStyle(size: 17, lineHeight: 22, letterSpacing: -0.442)
  public static let lg = TextStyle(size: 20, lineHeight: 25, letterSpacing: -0.46)
  public static let xl = TextStyle(size: 22, lineHeight: 28, letterSpacing: -0.264)
  public static let xl2 = TextStyle(size: 28, lineHeight: 34, letterSpacing: 0.392)
  public static let xl3 = TextStyle(size: 34, lineHeight: 41, letterSpacing: 0.408)

  public static let allCases: [TextStyle] = [.xs3, .xs2, .xs, .sm, .md, .base, .lg, .xl, .xl2, .xl3]
}

extension Shadow {
  public static let md = Shadow(color: .black.opacity(0.08), radius: 6, x: 2, y: 4)
  public static let lg = Shadow(color: .black.opacity(0.12), radius: 12, y: 4)
}
```

3. Copy the source and every file it uses:

```swift title="swift/Patterns/TableList.swift"
import SwiftUI

public enum TableListSlot: CaseIterable, Sendable {
  case title, description, trailing, hidden
}

public struct TableListColumn<Row> {
  public let key: String
  public let header: LocalizedStringKey
  public let slot: TableListSlot
  public let cell: (Row) -> Text

  public init(
    _ key: String,
    header: LocalizedStringKey,
    slot: TableListSlot = .hidden,
    cell: @escaping (Row) -> Text
  ) {
    self.key = key
    self.header = header
    self.slot = slot
    self.cell = cell
  }
}

public struct TableList<Row, ID: Hashable>: View {
  let rows: [Row]
  let id: (Row) -> ID
  let columns: [TableListColumn<Row>]
  let title: LocalizedStringKey?
  let emptyText: LocalizedStringKey
  let action: ((Row) -> Void)?

  public init(
    _ rows: [Row],
    id: KeyPath<Row, ID>,
    columns: [TableListColumn<Row>],
    title: LocalizedStringKey? = nil,
    emptyText: LocalizedStringKey = "No results.",
    action: ((Row) -> Void)? = nil
  ) {
    self.rows = rows
    self.id = { $0[keyPath: id] }
    self.columns = columns
    self.title = title
    self.emptyText = emptyText
    self.action = action
  }

  public var body: some View {
    VStack(alignment: .leading, spacing: 12) {
      if let title {
        Text(title)
          .scaledTextStyle(.xl3, weight: .bold)
          .foregroundStyle(Color.label)
          .accessibilityAddTraits(.isHeader)
      }
      if rows.isEmpty {
        Text(emptyText)
          .scaledTextStyle(.base)
          .foregroundStyle(Color.labelSecondary)
          .padding(.horizontal, 16)
          .padding(.vertical, 12)
          .frame(maxWidth: .infinity, alignment: .leading)
          .background(Color.surfaceSecondary, in: RoundedRectangle(cornerRadius: Radius.xl2, style: .continuous))
      } else {
        TableListGroup {
          ForEach(rows.map { TableListEntry(id: id($0), row: $0) }) { entry in
            TableListRow(action: action.map { action in { action(entry.row) } }) {
              cells(entry.row)
            }
          }
        }
      }
    }
    .frame(maxWidth: .infinity, alignment: .leading)
    .tableListRowInsets()
  }

  @ViewBuilder private func cells(_ row: Row) -> some View {
    let titleColumn = columns.first { $0.slot == .title }
    let descriptions = columns.filter { $0.slot == .description }
    let trailing = columns.filter { $0.slot == .trailing }
    VStack(alignment: .leading, spacing: 2) {
      if let titleColumn {
        titleColumn.cell(row)
          .scaledTextStyle(.base)
          .foregroundStyle(Color.label)
          .lineLimit(1)
      }
      if !descriptions.isEmpty {
        descriptions.enumerated().reduce(Text(verbatim: "")) { text, entry in
          entry.offset == 0 ? text + entry.element.cell(row) : text + Text(verbatim: " \u{00B7} ") + entry.element.cell(row)
        }
        .scaledTextStyle(.sm)
        .foregroundStyle(Color.labelSecondary)
        .lineLimit(1)
      }
    }
    .frame(maxWidth: .infinity, alignment: .leading)
    ForEach(trailing, id: \.key) { column in
      column.cell(row)
        .scaledTextStyle(.base)
        .monospacedDigit()
        .foregroundStyle(Color.labelSecondary)
        .lineLimit(1)
        .fixedSize()
    }
  }
}

extension TableList where Row: Identifiable, ID == Row.ID {
  public init(
    _ rows: [Row],
    columns: [TableListColumn<Row>],
    title: LocalizedStringKey? = nil,
    emptyText: LocalizedStringKey = "No results.",
    action: ((Row) -> Void)? = nil
  ) {
    self.init(rows, id: \.id, columns: columns, title: title, emptyText: emptyText, action: action)
  }
}

struct TableListEntry<Row, ID: Hashable>: Identifiable {
  let id: ID
  let row: Row
}

struct TableListRowKey: PreferenceKey {
  static var defaultValue: [Anchor<CGRect>] { [] }

  static func reduce(value: inout [Anchor<CGRect>], nextValue: () -> [Anchor<CGRect>]) {
    value.append(contentsOf: nextValue())
  }
}

public struct TableListGroup<Content: View>: View {
  let content: Content

  public init(@ViewBuilder content: () -> Content) {
    self.content = content()
  }

  public var body: some View {
    let shape = RoundedRectangle(cornerRadius: Radius.xl2, style: .continuous)
    VStack(alignment: .leading, spacing: 0) {
      content
    }
    .frame(maxWidth: .infinity, alignment: .leading)
    .overlayPreferenceValue(TableListRowKey.self) { anchors in
      GeometryReader { proxy in
        let rects = anchors.map { proxy[$0] }.sorted { $0.minY < $1.minY }
        ForEach(Array(rects.dropFirst().enumerated()), id: \.offset) { _, rect in
          Rectangle()
            .fill(Color.separator)
            .frame(width: max(rect.width - 16, 0), height: 1)
            .offset(x: rect.minX + 16, y: rect.minY)
        }
      }
      .allowsHitTesting(false)
      .accessibilityHidden(true)
    }
    .transformPreference(TableListRowKey.self) { $0 = [] }
    .background(Color.surfaceSecondary, in: shape)
    .clipShape(shape)
    .environment(\.itemGroupInset, true)
    .accessibilityElement(children: .contain)
  }
}

public struct TableListRow<Content: View>: View {
  let action: (() -> Void)?
  let content: Content

  public init(action: (() -> Void)? = nil, @ViewBuilder content: () -> Content) {
    self.action = action
    self.content = content()
  }

  public var body: some View {
    Group {
      if let action {
        Button(action: action) { row }
          .buttonStyle(TableListRowStyle())
      } else {
        row
      }
    }
    .anchorPreference(key: TableListRowKey.self, value: .bounds) { [$0] }
  }

  private var row: some View {
    HStack(spacing: 16) {
      content
    }
    .padding(.vertical, 11)
    .padding(.trailing, 16)
    .frame(maxWidth: .infinity, minHeight: 44, alignment: .leading)
    .padding(.leading, 16)
    .contentShape(Rectangle())
    .accessibilityElement(children: .combine)
  }
}

private struct TableListRowStyle: ButtonStyle {
  func makeBody(configuration: Configuration) -> some View {
    configuration.label
      .foregroundStyle(Color.label)
      .background(configuration.isPressed ? Color.itemPressed : .clear)
  }
}

public struct TableListSection<Content: View>: View {
  let header: LocalizedStringKey?
  let footer: LocalizedStringKey?
  let content: Content

  public init(
    header: LocalizedStringKey? = nil,
    footer: LocalizedStringKey? = nil,
    @ViewBuilder content: () -> Content
  ) {
    self.header = header
    self.footer = footer
    self.content = content()
  }

  public var body: some View {
    VStack(alignment: .leading, spacing: 8) {
      if let header {
        Text(header)
          .textCase(.uppercase)
          .scaledTextStyle(.xs)
          .foregroundStyle(Color.labelSecondary)
          .padding(.horizontal, 16)
          .accessibilityAddTraits(.isHeader)
      }
      TableListGroup { content }
      if let footer {
        Text(footer)
          .scaledTextStyle(.xs)
          .foregroundStyle(Color.labelSecondary)
          .fixedSize(horizontal: false, vertical: true)
          .padding(.horizontal, 16)
      }
    }
    .frame(maxWidth: .infinity, alignment: .leading)
    .tableListRowInsets()
  }
}

extension View {
  func tableListRowInsets() -> some View {
    listRowInsets(EdgeInsets())
      .listRowBackground(Color.clear)
      .listRowSeparator(.hidden)
  }
}
```

```swift title="swift/Components/Item.swift"
import SwiftUI

public enum ItemVariant: CaseIterable, Sendable {
  case `default`, outline, muted
}

public enum ItemSize: CaseIterable, Sendable {
  case `default`, sm, xs

  var horizontalPadding: CGFloat {
    switch self {
    case .default: 16
    case .sm: 14
    case .xs: 12
    }
  }

  var verticalPadding: CGFloat {
    switch self {
    case .default: 14
    case .sm: 12
    case .xs: 10
    }
  }

  var gap: CGFloat {
    self == .xs ? 10 : 14
  }

  var groupGap: CGFloat {
    switch self {
    case .default: 16
    case .sm: 10
    case .xs: 8
    }
  }

  var mediaImage: CGFloat {
    switch self {
    case .default: 40
    case .sm: 32
    case .xs: 24
    }
  }
}

public enum ItemGroupVariant: CaseIterable, Sendable {
  case `default`, inset
}

extension EnvironmentValues {
  @Entry var itemSize: ItemSize = .default
  @Entry var itemGroupInset = false
  @Entry var itemHasDescription = false
}

struct ItemGapKey: PreferenceKey {
  static var defaultValue: CGFloat? { nil }

  static func reduce(value: inout CGFloat?, nextValue: () -> CGFloat?) {
    guard let next = nextValue() else { return }
    value = min(value ?? next, next)
  }
}

struct ItemDescriptionKey: PreferenceKey {
  static var defaultValue: Bool { false }

  static func reduce(value: inout Bool, nextValue: () -> Bool) {
    value = value || nextValue()
  }
}

enum ItemSlot: Sendable {
  case media, content, actions, fullRow, other
}

struct ItemSlotKey: LayoutValueKey {
  static let defaultValue = ItemSlot.other
}

public struct ItemGroup<Content: View>: View {
  let variant: ItemGroupVariant
  let content: Content

  @State private var gap: CGFloat?

  public init(_ variant: ItemGroupVariant = .default, @ViewBuilder content: () -> Content) {
    self.variant = variant
    self.content = content()
  }

  public var body: some View {
    let inset = variant == .inset
    let shape = RoundedRectangle(cornerRadius: Radius.xl2, style: .continuous)
    VStack(alignment: .leading, spacing: inset ? 0 : gap ?? ItemSize.default.groupGap) {
      content
    }
    .frame(maxWidth: .infinity, alignment: .leading)
    .environment(\.itemGroupInset, inset)
    .onPreferenceChange(ItemGapKey.self) { gap = $0 }
    .transformPreference(ItemGapKey.self) { $0 = nil }
    .background(inset ? Color.surfaceSecondary : .clear, in: shape)
    .clipShape(inset ? AnyShape(shape) : AnyShape(Rectangle()))
    .accessibilityElement(children: .contain)
  }
}

public struct ItemSeparator: View {
  @Environment(\.itemGroupInset) private var inset

  public init() {}

  public var body: some View {
    Separator()
      .padding(.vertical, inset ? 0 : 8)
      .padding(.leading, inset ? 16 : 0)
  }
}

public struct Item<Content: View>: View {
  let variant: ItemVariant
  let size: ItemSize
  let action: (() -> Void)?
  let content: Content

  @State private var hasDescription = false
  @Environment(\.itemGroupInset) private var inset

  public init(
    _ variant: ItemVariant = .default,
    size: ItemSize = .default,
    action: (() -> Void)? = nil,
    @ViewBuilder content: () -> Content
  ) {
    self.variant = variant
    self.size = size
    self.action = action
    self.content = content()
  }

  public var body: some View {
    Group {
      if let action {
        Button(action: action) {
          surface
        }
        .buttonStyle(ItemButtonStyle(variant: variant, inset: inset))
      } else {
        surface.background(ItemBackground(variant: variant, inset: inset, pressed: false))
      }
    }
    .preference(key: ItemGapKey.self, value: size.groupGap)
  }

  private var surface: some View {
    ItemLayout(gap: size.gap, topAlignMedia: hasDescription) {
      content
    }
    .scaledFont(.base)
    .foregroundStyle(Color.label)
    .padding(.horizontal, size.horizontalPadding)
    .padding(.vertical, size.verticalPadding)
    .frame(maxWidth: .infinity, alignment: .leading)
    .environment(\.itemSize, size)
    .environment(\.itemHasDescription, hasDescription)
    .onPreferenceChange(ItemDescriptionKey.self) { hasDescription = $0 }
    .contentShape(Rectangle())
  }
}

private struct ItemBackground: View {
  let variant: ItemVariant
  let inset: Bool
  let pressed: Bool

  var body: some View {
    let shape = RoundedRectangle(cornerRadius: inset ? 0 : Radius.xl, style: .continuous)
    ZStack {
      shape.fill(variant == .muted ? Color.surfaceSecondary.opacity(0.5) : .clear)
      if pressed {
        shape.fill(Color.itemPressed)
      }
      if variant == .outline {
        shape.strokeBorder(Color.separator)
      }
    }
  }
}

private struct ItemButtonStyle: ButtonStyle {
  let variant: ItemVariant
  let inset: Bool

  @Environment(\.isEnabled) private var isEnabled

  func makeBody(configuration: Configuration) -> some View {
    configuration.label
      .background(ItemBackground(variant: variant, inset: inset, pressed: configuration.isPressed && isEnabled))
      .opacity(isEnabled ? 1 : 0.5)
  }
}

struct ItemLayout: Layout {
  var gap: CGFloat
  var topAlignMedia: Bool

  private struct Line {
    var indices: [Int]
    var full: Bool
  }

  private func lines(_ subviews: Subviews) -> [Line] {
    var result: [Line] = []
    var current: [Int] = []
    for index in subviews.indices {
      if subviews[index][ItemSlotKey.self] == .fullRow {
        if !current.isEmpty { result.append(Line(indices: current, full: false)) }
        current = []
        result.append(Line(indices: [index], full: true))
      } else {
        current.append(index)
      }
    }
    if !current.isEmpty { result.append(Line(indices: current, full: false)) }
    return result
  }

  private func widths(_ line: Line, subviews: Subviews, width: CGFloat?) -> [CGFloat] {
    if line.full {
      return [width ?? subviews[line.indices[0]].sizeThatFits(.unspecified).width]
    }
    let spacing = gap * CGFloat(max(line.indices.count - 1, 0))
    let flexible = line.indices.first { subviews[$0][ItemSlotKey.self] == .content }
    var fixed: [Int: CGFloat] = [:]
    for index in line.indices where index != flexible {
      fixed[index] = subviews[index].sizeThatFits(.unspecified).width
    }
    let used = fixed.values.reduce(0, +) + spacing
    return line.indices.map { index in
      if index == flexible {
        if let width { return max(width - used, 0) }
        return subviews[index].sizeThatFits(.unspecified).width
      }
      return fixed[index] ?? 0
    }
  }

  func sizeThatFits(proposal: ProposedViewSize, subviews: Subviews, cache: inout ()) -> CGSize {
    var height: CGFloat = 0
    var widest: CGFloat = 0
    let all = lines(subviews)
    for (position, line) in all.enumerated() {
      let sizes = widths(line, subviews: subviews, width: proposal.width)
      var lineHeight: CGFloat = 0
      for (index, width) in zip(line.indices, sizes) {
        lineHeight = max(lineHeight, subviews[index].sizeThatFits(ProposedViewSize(width: width, height: nil)).height)
      }
      let spacing = gap * CGFloat(max(line.indices.count - 1, 0))
      widest = max(widest, sizes.reduce(0, +) + (line.full ? 0 : spacing))
      height += lineHeight + (position > 0 ? gap : 0)
    }
    return CGSize(width: proposal.width ?? widest, height: height)
  }

  func placeSubviews(in bounds: CGRect, proposal: ProposedViewSize, subviews: Subviews, cache: inout ()) {
    var y = bounds.minY
    for line in lines(subviews) {
      let sizes = widths(line, subviews: subviews, width: bounds.width)
      var heights: [CGFloat] = []
      for (index, width) in zip(line.indices, sizes) {
        heights.append(subviews[index].sizeThatFits(ProposedViewSize(width: width, height: nil)).height)
      }
      let lineHeight = heights.max() ?? 0
      var x = bounds.minX
      for (offset, index) in line.indices.enumerated() {
        let width = sizes[offset]
        let height = heights[offset]
        let top = topAlignMedia && subviews[index][ItemSlotKey.self] == .media
        let originY = top ? y + 2 : y + (lineHeight - height) / 2
        subviews[index].place(
          at: CGPoint(x: x, y: originY),
          anchor: .topLeading,
          proposal: ProposedViewSize(width: width, height: height)
        )
        x += width + gap
      }
      y += lineHeight + gap
    }
  }
}

public enum ItemMediaVariant: CaseIterable, Sendable {
  case `default`, icon, image
}

public struct ItemMedia<Content: View>: View {
  let variant: ItemMediaVariant
  let content: Content

  @Environment(\.itemSize) private var size

  public init(_ variant: ItemMediaVariant = .default, @ViewBuilder content: () -> Content) {
    self.variant = variant
    self.content = content()
  }

  public var body: some View {
    Group {
      switch variant {
      case .default:
        HStack(spacing: 8) { content }
      case .icon:
        content.frame(width: 16, height: 16)
      case .image:
        content
          .scaledToFill()
          .frame(width: size.mediaImage, height: size.mediaImage)
          .clipShape(RoundedRectangle(cornerRadius: size == .xs ? Radius.sm : Radius.md, style: .continuous))
      }
    }
    .accessibilityHidden(variant != .default)
    .layoutValue(key: ItemSlotKey.self, value: .media)
  }
}

public struct ItemContent<Content: View>: View {
  let content: Content

  @Environment(\.itemSize) private var size

  public init(@ViewBuilder content: () -> Content) {
    self.content = content()
  }

  public var body: some View {
    VStack(alignment: .leading, spacing: size == .xs ? 2 : 4) {
      content
    }
    .frame(maxWidth: .infinity, alignment: .leading)
    .layoutValue(key: ItemSlotKey.self, value: .content)
  }
}

public struct ItemTitle<Content: View>: View {
  let content: Content

  public init(@ViewBuilder content: () -> Content) {
    self.content = content()
  }

  public var body: some View {
    HStack(spacing: 8) {
      content
    }
    .scaledTextStyle(.base, weight: .semibold)
    .foregroundStyle(Color.label)
    .lineLimit(1)
    .accessibilityElement(children: .combine)
  }
}

extension ItemTitle where Content == Text {
  public init(_ title: LocalizedStringKey) {
    self.init { Text(title) }
  }

  public init(verbatim title: String) {
    self.init { Text(verbatim: title) }
  }
}

public struct ItemDescription: View {
  let text: Text

  public init(_ description: LocalizedStringKey) {
    text = Text(description)
  }

  public init(verbatim description: String) {
    text = Text(verbatim: description)
  }

  public var body: some View {
    text
      .scaledTextStyle(.sm)
      .foregroundStyle(Color.labelSecondary)
      .multilineTextAlignment(.leading)
      .lineLimit(2)
      .fixedSize(horizontal: false, vertical: true)
      .preference(key: ItemDescriptionKey.self, value: true)
  }
}

public struct ItemActions<Content: View>: View {
  let content: Content

  public init(@ViewBuilder content: () -> Content) {
    self.content = content()
  }

  public var body: some View {
    HStack(spacing: 8) {
      content
    }
    .fixedSize()
    .layoutValue(key: ItemSlotKey.self, value: .actions)
  }
}

public struct ItemHeader<Content: View>: View {
  let content: Content

  public init(@ViewBuilder content: () -> Content) {
    self.content = content()
  }

  public var body: some View {
    SpaceBetween(spacing: 8) {
      content
    }
    .frame(maxWidth: .infinity)
    .layoutValue(key: ItemSlotKey.self, value: .fullRow)
  }
}

public struct ItemFooter<Content: View>: View {
  let content: Content

  public init(@ViewBuilder content: () -> Content) {
    self.content = content()
  }

  public var body: some View {
    SpaceBetween(spacing: 8) {
      content
    }
    .frame(maxWidth: .infinity)
    .layoutValue(key: ItemSlotKey.self, value: .fullRow)
  }
}

struct SpaceBetween: Layout {
  var spacing: CGFloat

  func sizeThatFits(proposal: ProposedViewSize, subviews: Subviews, cache: inout ()) -> CGSize {
    let sizes = subviews.map { $0.sizeThatFits(.unspecified) }
    let natural = sizes.reduce(0) { $0 + $1.width } + spacing * CGFloat(max(subviews.count - 1, 0))
    return CGSize(width: proposal.width ?? natural, height: sizes.map(\.height).max() ?? 0)
  }

  func placeSubviews(in bounds: CGRect, proposal: ProposedViewSize, subviews: Subviews, cache: inout ()) {
    let sizes = subviews.map { $0.sizeThatFits(.unspecified) }
    let total = sizes.reduce(0) { $0 + $1.width }
    let gaps = CGFloat(max(subviews.count - 1, 0))
    let gap = subviews.count > 1 ? max(spacing, (bounds.width - total) / gaps) : 0
    var x = bounds.minX
    for (index, view) in subviews.enumerated() {
      let size = sizes[index]
      view.place(
        at: CGPoint(x: x, y: bounds.midY - size.height / 2),
        anchor: .topLeading,
        proposal: ProposedViewSize(size)
      )
      x += size.width + gap
    }
  }
}
```

```swift title="swift/Components/Separator.swift"
import SwiftUI

public struct Separator: View {
  let orientation: Axis

  public init(_ orientation: Axis = .horizontal) {
    self.orientation = orientation
  }

  public var body: some View {
    Rectangle()
      .fill(Color.separator)
      .frame(width: orientation == .vertical ? 1 : nil, height: orientation == .horizontal ? 1 : nil)
      .frame(maxWidth: orientation == .horizontal ? .infinity : nil, maxHeight: orientation == .vertical ? .infinity : nil)
      .accessibilityHidden(true)
  }
}
```

```swift title="swift/Components/TextVariant.swift"
import SwiftUI

public enum TextVariant: CaseIterable, Sendable {
  case `default`, h1, h2, h3, h4, p, blockquote, code, lead, large, small, muted

  var style: TextStyle {
    switch self {
    case .h1: .xl3
    case .h2: .xl2
    case .h3: .xl
    case .h4, .lead, .large: .lg
    case .code, .small, .muted: .sm
    default: .base
    }
  }

  var weight: Font.Weight {
    switch self {
    case .h1, .h2: .bold
    case .h3, .h4, .large, .code: .semibold
    case .small: .medium
    default: .regular
    }
  }

  var color: Color {
    switch self {
    case .lead, .muted: .labelSecondary
    default: .label
    }
  }

  var isHeading: Bool {
    switch self {
    case .h1, .h2, .h3, .h4: true
    default: false
    }
  }
}

private struct TextVariantModifier: ViewModifier {
  let variant: TextVariant

  func body(content: Content) -> some View {
    switch variant {
    case .blockquote:
      styled(content)
        .italic()
        .padding(.leading, 12)
        .overlay(alignment: .leading) {
          Rectangle().fill(Color.separator).frame(width: 2)
        }
        .padding(.top, 16)
    case .code:
      styled(content)
        .monospaced()
        .padding(.horizontal, 4)
        .padding(.vertical, 2)
        .background(Color.surfaceSecondary, in: RoundedRectangle(cornerRadius: Radius.sm, style: .continuous))
    case .p:
      styled(content).padding(.top, 12)
    default:
      styled(content)
    }
  }

  private func styled(_ content: Content) -> some View {
    content
      .scaledTextStyle(variant.style, weight: variant.weight)
      .foregroundStyle(variant.color)
      .accessibilityAddTraits(variant.isHeading ? .isHeader : [])
  }
}

extension View {
  public func textVariant(_ variant: TextVariant) -> some View {
    modifier(TextVariantModifier(variant: variant))
  }
}

private struct ScaledTextStyleModifier: ViewModifier {
  let style: TextStyle
  let weight: Font.Weight

  @ScaledMetric(relativeTo: .body) private var scale: CGFloat = 1

  func body(content: Content) -> some View {
    let size = style.size * scale
    let lineSpacing = max(0, style.lineHeight * scale - UIFont.systemFont(ofSize: size).lineHeight)
    content
      .font(.system(size: size, weight: weight))
      .tracking(style.letterSpacing)
      .lineSpacing(lineSpacing)
      .padding(.vertical, lineSpacing / 2)
  }
}

extension View {
  func scaledTextStyle(_ style: TextStyle, weight: Font.Weight = .regular) -> some View {
    modifier(ScaledTextStyleModifier(style: style, weight: weight))
  }

  func scaledFont(_ style: TextStyle, weight: Font.Weight = .regular) -> some View {
    modifier(ScaledFontModifier(style: style, weight: weight))
  }
}

private struct ScaledFontModifier: ViewModifier {
  let style: TextStyle
  let weight: Font.Weight

  @ScaledMetric(relativeTo: .body) private var scale: CGFloat = 1

  func body(content: Content) -> some View {
    content
      .font(.system(size: style.size * scale, weight: weight))
      .tracking(style.letterSpacing)
  }
}
```

4. Add the files to your app target.

**Jetpack Compose**

1. Set `minSdk` to 24 or higher and add the dependencies:

```kotlin title="build.gradle.kts"
implementation(platform("androidx.compose:compose-bom:2026.09.00"))
implementation("androidx.compose.foundation:foundation")
implementation("androidx.compose.ui:ui")
implementation("com.adamglin:phosphor-icon-android:1.0.0")
```

2. Copy the theme files every view uses:

```kt title="kotlin/theme/Theme.kt"
package com.esuiss.ui.theme

import androidx.compose.foundation.isSystemInDarkTheme
import androidx.compose.runtime.Composable
import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.runtime.Immutable
import androidx.compose.runtime.staticCompositionLocalOf
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.dropShadow
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.Shape
import androidx.compose.ui.graphics.shadow.Shadow as DropShadow
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.text.style.LineHeightStyle
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.DpOffset
import androidx.compose.ui.unit.em
import androidx.compose.ui.unit.sp

internal fun textStyle(size: Double, lineHeight: Double, letterSpacing: Double) = TextStyle(
    fontSize = size.sp,
    lineHeight = lineHeight.sp,
    letterSpacing = letterSpacing.em,
    lineHeightStyle = LineHeightStyle(
        alignment = LineHeightStyle.Alignment.Center,
        trim = LineHeightStyle.Trim.None,
    ),
)

@Immutable
data class Shadow(
    val offsetX: Dp,
    val offsetY: Dp,
    val blur: Dp,
    val color: Color,
)

fun Modifier.shadow(shadow: Shadow, shape: Shape): Modifier = dropShadow(
    shape,
    DropShadow(
        radius = shadow.blur,
        color = shadow.color,
        offset = DpOffset(shadow.offsetX, shadow.offsetY),
    ),
)

val LocalColors = staticCompositionLocalOf { LightColors }

object EsuissTheme {
    val colors: Colors
        @Composable get() = LocalColors.current

    val typography: Typography
        get() = Typography

    val radius: Radius
        get() = Radius

    val shadows: Shadows
        get() = Shadows
}

@Composable
fun EsuissTheme(
    darkTheme: Boolean = isSystemInDarkTheme(),
    content: @Composable () -> Unit,
) {
    CompositionLocalProvider(
        LocalColors provides if (darkTheme) DarkColors else LightColors,
        content = content,
    )
}
```

```kt title="kotlin/theme/Tokens.kt"
package com.esuiss.ui.theme

import androidx.compose.runtime.Immutable
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.unit.dp

@Immutable
data class Colors(
    val surface: Color,
    val surfaceSecondary: Color,
    val surfaceTertiary: Color,
    val surfaceRaised: Color,
    val label: Color,
    val labelSecondary: Color,
    val labelTertiary: Color,
    val labelQuaternary: Color,
    val control: Color,
    val controlPressed: Color,
    val controlSelected: Color,
    val controlDisabled: Color,
    val onControlSelected: Color,
    val itemPressed: Color,
    val itemSelected: Color,
    val separator: Color,
    val separatorStrong: Color,
    val accent: Color,
    val accentPressed: Color,
    val accentSelected: Color,
    val accentDisabled: Color,
    val onAccent: Color,
    val accentSurface: Color,
    val accentSurfacePressed: Color,
    val link: Color,
    val focus: Color,
    val scrim: Color,
    val media: Color,
    val onMedia: Color,
    val danger: Color,
    val dangerSurface: Color,
    val dangerSurfacePressed: Color,
    val success: Color,
    val successSurface: Color,
    val warning: Color,
    val warningSurface: Color,
    val blue: Color,
    val green: Color,
    val orange: Color,
    val red: Color,
    val yellow: Color,
    val purple: Color,
    val pink: Color,
    val indigo: Color,
    val teal: Color,
    val mint: Color,
    val cyan: Color,
    val brown: Color,
    val gray: Color,
    val isDark: Boolean,
)

val LightColors = Colors(
    surface = Color(0xFFFFFFFF),
    surfaceSecondary = Color(0xFFF5F5F7),
    surfaceTertiary = Color(0xFFE8E8ED),
    surfaceRaised = Color(0xFFFFFFFF),
    label = Color(0xFF1D1D1F),
    labelSecondary = Color(0xFF6E6E73),
    labelTertiary = Color(0xFF86868B),
    labelQuaternary = Color(0xFFD2D2D7),
    control = Color(0xFF000000).copy(alpha = 0.04f),
    controlPressed = Color(0xFF000000).copy(alpha = 0.12f),
    controlSelected = Color(0xFF1D1D1F),
    controlDisabled = Color(0xFF000000).copy(alpha = 0.03f),
    onControlSelected = Color(0xFFFFFFFF),
    itemPressed = Color(0xFF000000).copy(alpha = 0.08f),
    itemSelected = Color(0xFF000000).copy(alpha = 0.06f),
    separator = Color(0xFFD2D2D7),
    separatorStrong = Color(0xFF86868B),
    accent = Color(0xFF0071E3),
    accentPressed = Color(0xFF005BB8),
    accentSelected = Color(0xFF0071E3),
    accentDisabled = Color(0xFF0071E3).copy(alpha = 0.4f),
    onAccent = Color(0xFFFFFFFF),
    accentSurface = Color(0xFF0071E3).copy(alpha = 0.09f),
    accentSurfacePressed = Color(0xFF0071E3).copy(alpha = 0.18f),
    link = Color(0xFF0066CC),
    focus = Color(0xFF0071E3),
    scrim = Color(0xFF000000).copy(alpha = 0.48f),
    media = Color(0xFF000000),
    onMedia = Color(0xFFFFFFFF),
    danger = Color(0xFFD0000A),
    dangerSurface = Color(0xFFD70015).copy(alpha = 0.08f),
    dangerSurfacePressed = Color(0xFFD70015).copy(alpha = 0.16f),
    success = Color(0xFF008009),
    successSurface = Color(0xFFEFFAF1),
    warning = Color(0xFFB64400),
    warningSurface = Color(0xFFFFF5EA),
    blue = Color(0xFF007AFF),
    green = Color(0xFF34C759),
    orange = Color(0xFFFF9500),
    red = Color(0xFFFF3B30),
    yellow = Color(0xFFFFCC00),
    purple = Color(0xFFAF52DE),
    pink = Color(0xFFFF2D55),
    indigo = Color(0xFF5856D6),
    teal = Color(0xFF30B0C7),
    mint = Color(0xFF00C7BE),
    cyan = Color(0xFF32ADE6),
    brown = Color(0xFFA2845E),
    gray = Color(0xFF8E8E93),
    isDark = false,
)

val DarkColors = Colors(
    surface = Color(0xFF000000),
    surfaceSecondary = Color(0xFF161617),
    surfaceTertiary = Color(0xFF2C2C2E),
    surfaceRaised = Color(0xFF1D1D1F),
    label = Color(0xFFF5F5F7),
    labelSecondary = Color(0xFFA1A1A6),
    labelTertiary = Color(0xFF86868B),
    labelQuaternary = Color(0xFF424245),
    control = Color(0xFFFFFFFF).copy(alpha = 0.1f),
    controlPressed = Color(0xFFFFFFFF).copy(alpha = 0.22f),
    controlSelected = Color(0xFFF5F5F7),
    controlDisabled = Color(0xFFFFFFFF).copy(alpha = 0.05f),
    onControlSelected = Color(0xFF000000),
    itemPressed = Color(0xFFFFFFFF).copy(alpha = 0.12f),
    itemSelected = Color(0xFFFFFFFF).copy(alpha = 0.1f),
    separator = Color(0xFF424245),
    separatorStrong = Color(0xFF6E6E73),
    accent = Color(0xFF0071E3),
    accentPressed = Color(0xFF004D9E),
    accentSelected = Color(0xFF0071E3),
    accentDisabled = Color(0xFF0071E3).copy(alpha = 0.4f),
    onAccent = Color(0xFFFFFFFF),
    accentSurface = Color(0xFF0071E3).copy(alpha = 0.18f),
    accentSurfacePressed = Color(0xFF0071E3).copy(alpha = 0.3f),
    link = Color(0xFF2997FF),
    focus = Color(0xFF0071E3),
    scrim = Color(0xFF000000).copy(alpha = 0.48f),
    media = Color(0xFF000000),
    onMedia = Color(0xFFFFFFFF),
    danger = Color(0xFFFF5447),
    dangerSurface = Color(0xFFFF453A).copy(alpha = 0.2f),
    dangerSurfacePressed = Color(0xFFFF453A).copy(alpha = 0.36f),
    success = Color(0xFF30D158),
    successSurface = Color(0xFF30D158).copy(alpha = 0.16f),
    warning = Color(0xFFFF9F0A),
    warningSurface = Color(0xFFFF9F0A).copy(alpha = 0.16f),
    blue = Color(0xFF0A84FF),
    green = Color(0xFF30D158),
    orange = Color(0xFFFF9F0A),
    red = Color(0xFFFF453A),
    yellow = Color(0xFFFFD60A),
    purple = Color(0xFFBF5AF2),
    pink = Color(0xFFFF375F),
    indigo = Color(0xFF5E5CE6),
    teal = Color(0xFF40C8E0),
    mint = Color(0xFF66D4CF),
    cyan = Color(0xFF64D2FF),
    brown = Color(0xFFAC8E68),
    gray = Color(0xFF8E8E93),
    isDark = true,
)

object Radius {
    val xs = 3.dp
    val sm = 5.dp
    val md = 8.dp
    val lg = 10.dp
    val xl = 12.dp
    val xl2 = 18.dp
    val xl3 = 28.dp
    val full = 9999.dp
}

object Typography {
    val xs3 = textStyle(11.0, 13.0, 0.006)
    val xs2 = textStyle(12.0, 16.0, 0.0)
    val xs = textStyle(13.0, 18.0, -0.006)
    val sm = textStyle(15.0, 20.0, -0.016)
    val md = textStyle(16.0, 21.0, -0.02)
    val base = textStyle(17.0, 22.0, -0.026)
    val lg = textStyle(20.0, 25.0, -0.023)
    val xl = textStyle(22.0, 28.0, -0.012)
    val xl2 = textStyle(28.0, 34.0, 0.014)
    val xl3 = textStyle(34.0, 41.0, 0.012)

    val all = listOf(xs3, xs2, xs, sm, md, base, lg, xl, xl2, xl3)
}

object Shadows {
    val md = Shadow(2.dp, 4.dp, 12.dp, Color.Black.copy(alpha = 0.08f))
    val lg = Shadow(0.dp, 4.dp, 24.dp, Color.Black.copy(alpha = 0.12f))
}
```

3. Copy the source and every file it uses:

```kt title="kotlin/patterns/TableList.kt"
package com.esuiss.ui.patterns

import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.lazy.LazyListScope
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.foundation.text.BasicText
import androidx.compose.runtime.Composable
import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.runtime.key
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.draw.drawWithContent
import androidx.compose.ui.geometry.Offset
import androidx.compose.ui.geometry.Size
import androidx.compose.ui.graphics.RectangleShape
import androidx.compose.ui.semantics.Role
import androidx.compose.ui.semantics.heading
import androidx.compose.ui.semantics.semantics
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.unit.LayoutDirection
import androidx.compose.ui.unit.dp
import com.esuiss.ui.components.ItemContent
import com.esuiss.ui.components.ItemFrame
import com.esuiss.ui.components.ItemSize
import com.esuiss.ui.components.ItemVariant
import com.esuiss.ui.components.LocalContentColor
import com.esuiss.ui.components.LocalContentStyle
import com.esuiss.ui.theme.EsuissTheme
import com.esuiss.ui.theme.Radius
import com.esuiss.ui.theme.Typography

enum class TableListSlot { Title, Description, Trailing, Hidden }

enum class TableListAlign { Start, End }

class TableListColumn<T>(
    val key: String,
    val header: String,
    val slot: TableListSlot? = null,
    val align: TableListAlign = TableListAlign.Start,
    val mobileCell: (@Composable (T) -> Unit)? = null,
    val cell: @Composable (T) -> Unit,
)

@Composable
fun <T> TableList(
    rows: List<T>,
    columns: List<TableListColumn<T>>,
    modifier: Modifier = Modifier,
    getKey: (T, Int) -> Any = { _, index -> index },
    title: String? = null,
    emptyText: String = "No results.",
    onRowClick: ((T) -> Unit)? = null,
) {
    val colors = EsuissTheme.colors
    val titleColumn = columns.firstOrNull { it.slot == TableListSlot.Title }
    val description = columns.filter { it.slot == TableListSlot.Description }
    val trailing = columns.filter { it.slot == TableListSlot.Trailing }
    Column(modifier = modifier.fillMaxWidth(), verticalArrangement = Arrangement.spacedBy(12.dp)) {
        if (title != null) TableListTitle(title)
        if (rows.isEmpty()) {
            val shape = RoundedCornerShape(Radius.xl2)
            BasicText(
                emptyText,
                modifier = Modifier
                    .fillMaxWidth()
                    .clip(shape)
                    .background(colors.surfaceSecondary, shape)
                    .padding(horizontal = 16.dp, vertical = 12.dp),
                style = Typography.base.copy(color = colors.labelSecondary),
            )
        } else {
            Column(modifier = Modifier.fillMaxWidth()) {
                rows.forEachIndexed { index, row ->
                    key(getKey(row, index)) {
                        TableListRow(
                            first = index == 0,
                            last = index == rows.lastIndex,
                            onClick = onRowClick?.let { { it(row) } },
                        ) {
                            TableListCells(row, titleColumn, description, trailing)
                        }
                    }
                }
            }
        }
    }
}

@Composable
private fun <T> TableListCells(
    row: T,
    titleColumn: TableListColumn<T>?,
    description: List<TableListColumn<T>>,
    trailing: List<TableListColumn<T>>,
) {
    val colors = EsuissTheme.colors
    val cell: (TableListColumn<T>) -> @Composable (T) -> Unit = { it.mobileCell ?: it.cell }
    ItemContent {
        if (titleColumn != null) {
            CompositionLocalProvider(LocalContentStyle provides Typography.base.copy(color = colors.label)) {
                cell(titleColumn)(row)
            }
        }
        if (description.isNotEmpty()) {
            CompositionLocalProvider(
                LocalContentStyle provides Typography.sm.copy(color = colors.labelSecondary),
                LocalContentColor provides colors.labelSecondary,
            ) {
                Row(verticalAlignment = Alignment.CenterVertically) {
                    description.forEachIndexed { position, column ->
                        if (position > 0) BasicText(" · ", style = LocalContentStyle.current, maxLines = 1)
                        cell(column)(row)
                    }
                }
            }
        }
    }
    trailing.forEach { column ->
        CompositionLocalProvider(
            LocalContentStyle provides Typography.base.copy(color = colors.labelSecondary, fontFeatureSettings = "tnum"),
            LocalContentColor provides colors.labelSecondary,
        ) {
            cell(column)(row)
        }
    }
}

@Composable
fun TableListTitle(text: String, modifier: Modifier = Modifier) {
    BasicText(
        text,
        modifier = modifier.semantics { heading() },
        style = Typography.xl3.copy(color = EsuissTheme.colors.label, fontWeight = FontWeight.Bold),
    )
}

@Composable
fun TableListHeader(text: String, modifier: Modifier = Modifier) {
    BasicText(
        text,
        modifier = modifier
            .fillMaxWidth()
            .semantics { heading() }
            .padding(start = 16.dp, end = 16.dp, bottom = 8.dp),
        style = Typography.xs.copy(color = EsuissTheme.colors.labelSecondary),
    )
}

@Composable
fun TableListFooter(text: String, modifier: Modifier = Modifier) {
    BasicText(
        text,
        modifier = modifier
            .fillMaxWidth()
            .padding(start = 16.dp, end = 16.dp, top = 8.dp),
        style = Typography.xs.copy(color = EsuissTheme.colors.labelSecondary),
    )
}

@Composable
fun TableListRow(
    first: Boolean,
    last: Boolean,
    modifier: Modifier = Modifier,
    onClick: (() -> Unit)? = null,
    onLongClick: (() -> Unit)? = null,
    enabled: Boolean = true,
    selected: Boolean? = null,
    content: @Composable () -> Unit,
) {
    val colors = EsuissTheme.colors
    val radius = Radius.xl2
    val shape = when {
        first && last -> RoundedCornerShape(radius)
        first -> RoundedCornerShape(topStart = radius, topEnd = radius)
        last -> RoundedCornerShape(bottomStart = radius, bottomEnd = radius)
        else -> RectangleShape
    }
    val separator = colors.separator
    ItemFrame(
        modifier = modifier
            .clip(shape)
            .background(colors.surfaceSecondary, shape)
            .drawWithContent {
                drawContent()
                if (!first) {
                    val inset = 16.dp.toPx()
                    val start = if (layoutDirection == LayoutDirection.Rtl) 0f else inset
                    drawRect(separator, Offset(start, 0f), Size(size.width - inset, 1.dp.toPx()))
                }
            },
        variant = ItemVariant.Default,
        size = ItemSize.Default,
        shape = shape,
        padding = PaddingValues(horizontal = 16.dp, vertical = 11.dp),
        onClick = onClick,
        onLongClick = onLongClick,
        enabled = enabled,
        selected = selected,
        role = Role.Button,
        onClickLabel = null,
        minHeight = 44.dp,
        gap = 16.dp,
        content = content,
    )
}

@Composable
fun TableListRowText(
    title: String,
    description: String? = null,
    trailing: String? = null,
) {
    val colors = EsuissTheme.colors
    ItemContent {
        BasicText(
            title,
            style = Typography.base.copy(color = LocalContentColor.current),
            maxLines = 1,
            overflow = TextOverflow.Ellipsis,
        )
        if (description != null) {
            BasicText(
                description,
                style = Typography.sm.copy(color = colors.labelSecondary),
                maxLines = 1,
                overflow = TextOverflow.Ellipsis,
            )
        }
    }
    if (trailing != null) {
        BasicText(
            trailing,
            style = Typography.base.copy(color = colors.labelSecondary, fontFeatureSettings = "tnum"),
            maxLines = 1,
        )
    }
}

class TableListSectionScope internal constructor() {
    internal val rows = mutableListOf<TableListEntry>()

    fun item(
        key: Any? = null,
        onClick: (() -> Unit)? = null,
        content: @Composable () -> Unit,
    ) {
        rows += TableListEntry(key, onClick, content)
    }

    fun row(
        title: String,
        description: String? = null,
        trailing: String? = null,
        key: Any? = null,
        onClick: (() -> Unit)? = null,
    ) {
        item(key, onClick) { TableListRowText(title, description, trailing) }
    }

    fun <T> items(
        items: List<T>,
        key: ((T) -> Any)? = null,
        onClick: ((T) -> Unit)? = null,
        content: @Composable (T) -> Unit,
    ) {
        items.forEach { value ->
            item(key?.invoke(value), onClick?.let { { it(value) } }) { content(value) }
        }
    }
}

internal class TableListEntry(
    val key: Any?,
    val onClick: (() -> Unit)?,
    val content: @Composable () -> Unit,
)

private sealed interface TableListBlock {
    class Title(val text: String) : TableListBlock
    class Section(
        val header: String?,
        val footer: String?,
        val emptyText: String?,
        val rows: List<TableListEntry>,
    ) : TableListBlock
}

class TableListScope internal constructor() {
    private val blocks = mutableListOf<TableListBlock>()

    fun title(text: String) {
        blocks += TableListBlock.Title(text)
    }

    fun section(
        header: String? = null,
        footer: String? = null,
        emptyText: String? = null,
        content: TableListSectionScope.() -> Unit,
    ) {
        val scope = TableListSectionScope().apply(content)
        blocks += TableListBlock.Section(header, footer, emptyText, scope.rows.toList())
    }

    internal fun emit(lazy: LazyListScope, prefix: String) {
        var sectionIndex = 0
        blocks.forEachIndexed { blockIndex, block ->
            when (block) {
                is TableListBlock.Title -> lazy.item(key = "$prefix:title:$blockIndex", contentType = "table-list-title") {
                    TableListTitle(block.text, Modifier.padding(bottom = 12.dp))
                }
                is TableListBlock.Section -> {
                    val section = sectionIndex++
                    if (section > 0) {
                        lazy.item(key = "$prefix:gap:$section", contentType = "table-list-gap") {
                            Spacer(Modifier.height(24.dp))
                        }
                    }
                    if (block.header != null) {
                        lazy.item(key = "$prefix:header:$section", contentType = "table-list-header") {
                            TableListHeader(block.header)
                        }
                    }
                    if (block.rows.isEmpty() && block.emptyText != null) {
                        lazy.item(key = "$prefix:empty:$section", contentType = "table-list-row") {
                            TableListRow(first = true, last = true) {
                                ItemContent {
                                    BasicText(block.emptyText, style = Typography.base.copy(color = EsuissTheme.colors.labelSecondary))
                                }
                            }
                        }
                    }
                    block.rows.forEachIndexed { index, entry ->
                        lazy.item(
                            key = entry.key?.let { "$prefix:row:$section:$it" },
                            contentType = "table-list-row",
                        ) {
                            TableListRow(
                                first = index == 0,
                                last = index == block.rows.lastIndex,
                                onClick = entry.onClick,
                                content = entry.content,
                            )
                        }
                    }
                    if (block.footer != null) {
                        lazy.item(key = "$prefix:footer:$section", contentType = "table-list-footer") {
                            TableListFooter(block.footer)
                        }
                    }
                }
            }
        }
    }
}

fun LazyListScope.tableList(
    key: String = "table-list",
    content: TableListScope.() -> Unit,
) {
    TableListScope().apply(content).emit(this, key)
}
```

```kt title="kotlin/components/Button.kt"
package com.esuiss.ui.components

import androidx.compose.foundation.background
import androidx.compose.foundation.border
import androidx.compose.foundation.clickable
import androidx.compose.foundation.interaction.MutableInteractionSource
import androidx.compose.foundation.interaction.collectIsPressedAsState
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.RowScope
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.foundation.text.BasicText
import androidx.compose.runtime.Composable
import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.runtime.getValue
import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.semantics.Role
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.text.style.TextDecoration
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp
import com.esuiss.ui.theme.Colors
import com.esuiss.ui.theme.EsuissTheme
import com.esuiss.ui.theme.Radius
import com.esuiss.ui.theme.Typography

enum class ButtonVariant { Default, Outline, Secondary, Tinted, Ghost, Plain, Destructive, Link }

enum class ButtonSize(
    val height: Dp,
    val horizontalPadding: Dp,
    val spacing: Dp,
    val iconSize: Dp,
    val blockRadius: Dp,
    val isIcon: Boolean,
) {
    Default(36.dp, 16.dp, 6.dp, 16.dp, Radius.md, false),
    Xs(24.dp, 11.dp, 4.dp, 12.dp, Radius.sm, false),
    Sm(32.dp, 12.dp, 4.dp, 16.dp, Radius.md, false),
    Lg(44.dp, 22.dp, 6.dp, 16.dp, Radius.lg, false),
    Xl(56.dp, 31.dp, 8.dp, 16.dp, Radius.xl, false),
    Icon(36.dp, 0.dp, 6.dp, 16.dp, Radius.md, true),
    IconXs(24.dp, 0.dp, 4.dp, 12.dp, Radius.sm, true),
    IconSm(32.dp, 0.dp, 4.dp, 16.dp, Radius.md, true),
    IconLg(44.dp, 0.dp, 6.dp, 16.dp, Radius.lg, true),
    IconXl(56.dp, 0.dp, 8.dp, 16.dp, Radius.xl, true),
    ;

    val textStyle: TextStyle
        get() = when (this) {
            Xs, IconXs -> Typography.xs2
            Lg, Xl -> Typography.base
            else -> Typography.sm
        }
}

@Composable
fun Button(
    onClick: () -> Unit,
    modifier: Modifier = Modifier,
    variant: ButtonVariant = ButtonVariant.Default,
    size: ButtonSize = ButtonSize.Default,
    block: Boolean = false,
    enabled: Boolean = true,
    content: @Composable RowScope.() -> Unit,
) {
    val colors = EsuissTheme.colors
    val interaction = remember { MutableInteractionSource() }
    val pressed by interaction.collectIsPressedAsState()
    val foreground = buttonForeground(variant, colors, enabled)
    val group = LocalButtonGroup.current?.takeIf { variant != ButtonVariant.Ghost && variant != ButtonVariant.Plain }
    RegisterButtonGroupOutline(group, variant == ButtonVariant.Outline)
    val shape = group.itemShape(if (block) RoundedCornerShape(size.blockRadius) else CircleShape)
    val sizing = when {
        block -> Modifier.fillMaxWidth().height(size.height)
        size.isIcon -> Modifier.size(size.height)
        else -> Modifier.height(size.height)
    }

    Row(
        modifier = modifier
            .then(sizing)
            .clip(shape)
            .background(buttonBackground(variant, colors, pressed && enabled, enabled), shape)
            .then(
                when {
                    variant != ButtonVariant.Outline -> Modifier
                    group != null -> Modifier.buttonGroupEdge(group, colors.separator)
                    else -> Modifier.border(1.dp, colors.separator, shape)
                },
            )
            .clickable(
                interactionSource = interaction,
                indication = null,
                enabled = enabled,
                role = Role.Button,
                onClick = onClick,
            )
            .padding(horizontal = size.horizontalPadding),
        horizontalArrangement = Arrangement.spacedBy(size.spacing, Alignment.CenterHorizontally),
        verticalAlignment = Alignment.CenterVertically,
    ) {
        CompositionLocalProvider(
            LocalButtonGroup provides null,
            LocalContentStyle provides size.textStyle.copy(
                color = foreground,
                textDecoration = if (variant == ButtonVariant.Link && pressed && enabled) {
                    TextDecoration.Underline
                } else {
                    null
                },
            ),
            LocalContentColor provides foreground,
            LocalIconSize provides size.iconSize,
        ) {
            content()
        }
    }
}

@Composable
fun Button(
    text: String,
    onClick: () -> Unit,
    modifier: Modifier = Modifier,
    variant: ButtonVariant = ButtonVariant.Default,
    size: ButtonSize = ButtonSize.Default,
    block: Boolean = false,
    enabled: Boolean = true,
) {
    Button(onClick, modifier, variant, size, block, enabled) {
        BasicText(text, style = LocalContentStyle.current, maxLines = 1)
    }
}

private fun buttonForeground(variant: ButtonVariant, colors: Colors, enabled: Boolean): Color =
    when (variant) {
        ButtonVariant.Default -> colors.onAccent
        ButtonVariant.Outline, ButtonVariant.Secondary, ButtonVariant.Ghost ->
            if (enabled) colors.label else colors.labelQuaternary
        ButtonVariant.Tinted, ButtonVariant.Plain ->
            if (enabled) colors.link else colors.link.copy(alpha = 0.4f)
        ButtonVariant.Destructive ->
            if (enabled) colors.danger else colors.danger.copy(alpha = 0.4f)
        ButtonVariant.Link -> if (enabled) colors.link else colors.labelQuaternary
    }

private fun buttonBackground(variant: ButtonVariant, colors: Colors, pressed: Boolean, enabled: Boolean): Color =
    when (variant) {
        ButtonVariant.Default -> when {
            !enabled -> colors.accentDisabled
            pressed -> colors.accentPressed
            else -> colors.accent
        }
        ButtonVariant.Outline -> when {
            pressed -> colors.itemPressed
            colors.isDark -> Color.Transparent
            else -> colors.surface
        }
        ButtonVariant.Secondary -> when {
            !enabled -> colors.controlDisabled
            pressed -> colors.controlPressed
            else -> colors.control
        }
        ButtonVariant.Tinted -> if (pressed) colors.accentSurfacePressed else colors.accentSurface
        ButtonVariant.Ghost -> if (pressed) colors.itemPressed else Color.Transparent
        ButtonVariant.Plain -> if (pressed) colors.itemPressed else Color.Transparent
        ButtonVariant.Destructive -> if (pressed) colors.dangerSurfacePressed else colors.dangerSurface
        ButtonVariant.Link -> Color.Transparent
    }
```

```kt title="kotlin/components/ButtonGroup.kt"
package com.esuiss.ui.components

import androidx.compose.foundation.background
import androidx.compose.foundation.gestures.Orientation
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.RowScope
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.foundation.shape.CornerSize
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.runtime.Composable
import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.runtime.DisposableEffect
import androidx.compose.runtime.Immutable
import androidx.compose.runtime.Stable
import androidx.compose.runtime.compositionLocalOf
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableIntStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.draw.drawBehind
import androidx.compose.ui.draw.drawWithContent
import androidx.compose.ui.geometry.Offset
import androidx.compose.ui.geometry.Size
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.RectangleShape
import androidx.compose.ui.graphics.Shape
import androidx.compose.ui.graphics.drawOutline
import androidx.compose.ui.graphics.drawscope.Stroke
import androidx.compose.ui.graphics.drawscope.translate
import androidx.compose.ui.graphics.takeOrElse
import androidx.compose.ui.layout.Layout
import androidx.compose.ui.layout.Placeable
import androidx.compose.ui.layout.layout
import androidx.compose.ui.layout.layoutId
import androidx.compose.ui.layout.onPlaced
import androidx.compose.ui.platform.LocalLayoutDirection
import androidx.compose.ui.semantics.isTraversalGroup
import androidx.compose.ui.semantics.semantics
import androidx.compose.ui.unit.Constraints
import androidx.compose.ui.unit.LayoutDirection
import androidx.compose.ui.unit.constrainHeight
import androidx.compose.ui.unit.constrainWidth
import androidx.compose.ui.unit.dp
import com.esuiss.ui.theme.EsuissTheme
import com.esuiss.ui.theme.Radius
import com.esuiss.ui.theme.Typography

enum class ButtonGroupOrientation { Horizontal, Vertical }

@Stable
internal class ButtonGroupState(val orientation: ButtonGroupOrientation) {
    var nested by mutableIntStateOf(0)
    var outlined by mutableIntStateOf(0)
}

internal val LocalButtonGroup = compositionLocalOf<ButtonGroupState?> { null }

internal object ButtonGroupFill

private object ButtonGroupDivider

internal fun ButtonGroupState?.itemShape(default: Shape): Shape = if (this == null) default else RectangleShape

@Immutable
internal class ButtonGroupItem(val shape: Shape, val modifier: Modifier)

@Composable
internal fun rememberButtonGroupItem(group: ButtonGroupState?, default: Shape): ButtonGroupItem {
    var edges by remember { mutableIntStateOf(0) }
    val horizontal = group?.orientation != ButtonGroupOrientation.Vertical
    val rtl = LocalLayoutDirection.current == LayoutDirection.Rtl
    val shape = remember(edges, horizontal) {
        val round = if (horizontal) CornerSize(50) else CornerSize(Radius.xl2)
        val square = CornerSize(0)
        val start = if (edges and 1 != 0) round else square
        val end = if (edges and 2 != 0) round else square
        if (horizontal) {
            RoundedCornerShape(topStart = start, topEnd = end, bottomEnd = end, bottomStart = start)
        } else {
            RoundedCornerShape(topStart = start, topEnd = start, bottomEnd = end, bottomStart = end)
        }
    }
    if (group == null || group.nested > 0) return ButtonGroupItem(default, Modifier)
    return ButtonGroupItem(
        shape = shape,
        modifier = Modifier.onPlaced { coordinates ->
            val parent = coordinates.parentLayoutCoordinates ?: return@onPlaced
            val bounds = parent.localBoundingBoxOf(coordinates, clipBounds = false)
            val first: Boolean
            val last: Boolean
            if (horizontal) {
                val left = bounds.left <= 0.5f
                val right = bounds.right >= parent.size.width - 0.5f
                first = if (rtl) right else left
                last = if (rtl) left else right
            } else {
                first = bounds.top <= 0.5f
                last = bounds.bottom >= parent.size.height - 0.5f
            }
            edges = (if (first) 1 else 0) or (if (last) 2 else 0)
        },
    )
}

internal fun Modifier.buttonGroupEdge(group: ButtonGroupState?, color: Color): Modifier {
    if (group == null) return this
    return drawBehind {
        val stroke = 1.dp.toPx()
        if (group.orientation == ButtonGroupOrientation.Horizontal) {
            val x = if (layoutDirection == LayoutDirection.Rtl) 0f else size.width - stroke
            drawRect(color, Offset(x, 0f), Size(stroke, size.height))
        } else {
            drawRect(color, Offset(0f, size.height - stroke), Size(size.width, stroke))
        }
    }
}

@Composable
internal fun RegisterButtonGroupOutline(group: ButtonGroupState?, outlined: Boolean) {
    DisposableEffect(group, outlined) {
        if (group != null && outlined) group.outlined += 1
        onDispose {
            if (group != null && outlined) group.outlined -= 1
        }
    }
}

@Composable
fun ButtonGroup(
    modifier: Modifier = Modifier,
    orientation: ButtonGroupOrientation = ButtonGroupOrientation.Horizontal,
    content: @Composable () -> Unit,
) {
    val parent = LocalButtonGroup.current
    DisposableEffect(parent) {
        parent?.let { it.nested += 1 }
        onDispose { parent?.let { it.nested -= 1 } }
    }
    val state = remember(orientation) { ButtonGroupState(orientation) }
    val colors = EsuissTheme.colors
    val joined = state.nested == 0
    val horizontal = orientation == ButtonGroupOrientation.Horizontal
    val shape = if (horizontal) CircleShape else RoundedCornerShape(Radius.xl2)
    val outline = colors.separator
    Layout(
        content = {
            CompositionLocalProvider(LocalButtonGroup provides state, content = content)
        },
        modifier = modifier
            .semantics { isTraversalGroup = true }
            .then(
                if (joined) {
                    Modifier
                        .clip(shape)
                        .drawWithContent {
                            drawContent()
                            if (state.outlined > 0) {
                                val stroke = 1.dp.toPx()
                                val inset = stroke / 2
                                val path = shape.createOutline(
                                    Size(size.width - stroke, size.height - stroke),
                                    layoutDirection,
                                    this,
                                )
                                translate(inset, inset) {
                                    drawOutline(path, outline, style = Stroke(stroke))
                                }
                            }
                        }
                } else {
                    Modifier
                },
            ),
    ) { measurables, constraints ->
        val gap = if (joined) 0 else 8.dp.roundToPx()
        val items = measurables.filter { it.layoutId != ButtonGroupDivider }
        if (horizontal) {
            val height = if (constraints.hasFixedHeight) {
                constraints.maxHeight
            } else {
                constraints.constrainHeight(items.maxOfOrNull { it.maxIntrinsicHeight(Constraints.Infinity) } ?: 0)
            }
            val fills = measurables.count { it.layoutId == ButtonGroupFill }
            val placeables = arrayOfNulls<Placeable>(measurables.size)
            var used = 0
            measurables.forEachIndexed { index, measurable ->
                if (measurable.layoutId != ButtonGroupFill) {
                    val placeable = measurable.measure(Constraints(minHeight = height, maxHeight = height))
                    placeables[index] = placeable
                    used += placeable.width
                }
            }
            val gaps = gap * (items.size - 1).coerceAtLeast(0)
            val remaining = if (constraints.hasBoundedWidth) {
                (constraints.maxWidth - used - gaps).coerceAtLeast(0)
            } else {
                0
            }
            measurables.forEachIndexed { index, measurable ->
                if (measurable.layoutId == ButtonGroupFill) {
                    val placeable = if (constraints.hasBoundedWidth) {
                        val width = remaining / fills
                        measurable.measure(Constraints(width, width, height, height))
                    } else {
                        measurable.measure(Constraints(minHeight = height, maxHeight = height))
                    }
                    placeables[index] = placeable
                    used += placeable.width
                }
            }
            val width = constraints.constrainWidth(used + gaps)
            layout(width, height) {
                var x = 0
                measurables.forEachIndexed { index, measurable ->
                    val placeable = placeables[index] ?: return@forEachIndexed
                    val divider = measurable.layoutId == ButtonGroupDivider
                    placeable.placeRelative(x, 0, zIndex = if (divider) 1f else 0f)
                    if (!divider) x += placeable.width + gap
                }
            }
        } else {
            val width = if (constraints.hasFixedWidth) {
                constraints.maxWidth
            } else {
                constraints.constrainWidth(items.maxOfOrNull { it.maxIntrinsicWidth(Constraints.Infinity) } ?: 0)
            }
            val placeables = measurables.map { it.measure(Constraints(minWidth = width, maxWidth = width)) }
            val gaps = gap * (items.size - 1).coerceAtLeast(0)
            val height = constraints.constrainHeight(
                placeables.filterIndexed { index, _ -> measurables[index].layoutId != ButtonGroupDivider }.sumOf { it.height } + gaps,
            )
            layout(width, height) {
                var y = 0
                measurables.forEachIndexed { index, measurable ->
                    val divider = measurable.layoutId == ButtonGroupDivider
                    placeables[index].placeRelative(0, y, zIndex = if (divider) 1f else 0f)
                    if (!divider) y += placeables[index].height + gap
                }
            }
        }
    }
}

@Composable
fun ButtonGroupText(
    modifier: Modifier = Modifier,
    content: @Composable RowScope.() -> Unit,
) {
    val colors = EsuissTheme.colors
    val shape = LocalButtonGroup.current.itemShape(CircleShape)
    Row(
        modifier = modifier
            .clip(shape)
            .background(colors.control, shape)
            .padding(horizontal = 10.dp),
        horizontalArrangement = Arrangement.spacedBy(8.dp),
        verticalAlignment = Alignment.CenterVertically,
    ) {
        CompositionLocalProvider(
            LocalButtonGroup provides null,
            LocalContentStyle provides Typography.sm.copy(color = colors.label),
            LocalContentColor provides colors.label,
            LocalIconSize provides 16.dp,
        ) {
            content()
        }
    }
}

@Composable
fun ButtonGroupSeparator(
    modifier: Modifier = Modifier,
    orientation: Orientation = Orientation.Vertical,
    color: Color = Color.Unspecified,
) {
    val line = color.takeOrElse { EsuissTheme.colors.label.copy(alpha = 0.2f) }
    Box(
        modifier = modifier
            .layoutId(ButtonGroupDivider)
            .then(
                if (orientation == Orientation.Vertical) {
                    Modifier.layout { measurable, constraints ->
                        val placeable = measurable.measure(constraints.copy(minWidth = 0, maxWidth = 0))
                        layout(0, placeable.height) { placeable.place(0, 0) }
                    }
                } else {
                    Modifier.layout { measurable, constraints ->
                        val placeable = measurable.measure(constraints.copy(minHeight = 0, maxHeight = 0))
                        layout(placeable.width, 0) { placeable.place(0, 0) }
                    }
                },
            )
            .drawBehind {
                val stroke = 1.dp.toPx()
                val inset = 9.dp.toPx()
                if (orientation == Orientation.Vertical) {
                    val x = if (layoutDirection == LayoutDirection.Rtl) -stroke else 0f
                    drawRect(line, Offset(x, inset), Size(stroke, (size.height - inset * 2).coerceAtLeast(0f)))
                } else {
                    drawRect(line, Offset(inset, 0f), Size((size.width - inset * 2).coerceAtLeast(0f), stroke))
                }
            },
    )
}
```

```kt title="kotlin/components/Content.kt"
package com.esuiss.ui.components

import androidx.compose.runtime.compositionLocalOf
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp

val LocalContentStyle = compositionLocalOf { TextStyle.Default }

val LocalContentColor = compositionLocalOf { Color.Unspecified }

val LocalIconSize = compositionLocalOf { 20.dp }
```

```kt title="kotlin/components/Header.kt"
package com.esuiss.ui.components

import androidx.compose.animation.core.animate
import androidx.compose.animation.core.animateFloatAsState
import androidx.compose.animation.core.tween
import androidx.compose.foundation.clickable
import androidx.compose.foundation.interaction.MutableInteractionSource
import androidx.compose.foundation.interaction.collectIsPressedAsState
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.RowScope
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.text.BasicText
import androidx.compose.runtime.Composable
import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.runtime.Stable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableFloatStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.runtime.staticCompositionLocalOf
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clipToBounds
import androidx.compose.ui.draw.drawWithContent
import androidx.compose.ui.geometry.Offset
import androidx.compose.ui.geometry.Size
import androidx.compose.ui.graphics.graphicsLayer
import androidx.compose.ui.input.nestedscroll.NestedScrollConnection
import androidx.compose.ui.input.nestedscroll.NestedScrollSource
import androidx.compose.ui.layout.Layout
import androidx.compose.ui.layout.layoutId
import androidx.compose.ui.semantics.Role
import androidx.compose.ui.semantics.heading
import androidx.compose.ui.semantics.semantics
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.unit.Constraints
import androidx.compose.ui.unit.Velocity
import androidx.compose.ui.unit.dp
import com.adamglin.PhosphorIcons
import com.adamglin.phosphoricons.Regular
import com.adamglin.phosphoricons.regular.CaretLeft
import com.esuiss.ui.theme.EsuissTheme
import com.esuiss.ui.theme.Typography

private val HeaderBarHeight = 44.dp

private enum class HeaderSlot { Back, Start, End, Title, LargeTitle }

enum class HeaderActionsSide { Leading, Trailing }

@Stable
class HeaderState {
    internal var range by mutableFloatStateOf(0f)
    internal var offset by mutableFloatStateOf(0f)

    val collapsedFraction: Float
        get() = if (range <= 0f) 1f else (offset / range).coerceIn(0f, 1f)

    val nestedScrollConnection: NestedScrollConnection = object : NestedScrollConnection {
        override fun onPreScroll(available: Offset, source: NestedScrollSource): Offset {
            if (available.y >= 0f || range <= 0f) return Offset.Zero
            val next = (offset - available.y).coerceAtMost(range)
            val used = next - offset
            offset = next
            return Offset(0f, -used)
        }

        override fun onPostScroll(consumed: Offset, available: Offset, source: NestedScrollSource): Offset {
            if (available.y <= 0f || range <= 0f) return Offset.Zero
            val next = (offset - available.y).coerceAtLeast(0f)
            val used = offset - next
            offset = next
            return Offset(0f, used)
        }

        override suspend fun onPostFling(consumed: Velocity, available: Velocity): Velocity {
            settle()
            return Velocity.Zero
        }
    }

    internal suspend fun settle() {
        if (range <= 0f || offset <= 0f || offset >= range) return
        val target = if (offset < range / 2f) 0f else range
        animate(offset, target, animationSpec = tween(250)) { value, _ -> offset = value }
    }
}

@Composable
fun rememberHeaderState(): HeaderState = remember { HeaderState() }

private val LocalHeaderState = staticCompositionLocalOf<HeaderState?> { null }

@Composable
fun Header(
    modifier: Modifier = Modifier,
    state: HeaderState = rememberHeaderState(),
    content: @Composable () -> Unit,
) {
    val colors = EsuissTheme.colors
    val collapsed = state.range > 0f && state.offset >= state.range
    val separator by animateFloatAsState(if (state.range <= 0f || collapsed) 1f else 0f, tween(150), label = "separator")
    CompositionLocalProvider(LocalHeaderState provides state) {
        Layout(
            content = content,
            modifier = modifier
                .clipToBounds()
                .drawWithContent {
                    drawContent()
                    val stroke = 1.dp.toPx()
                    drawRect(colors.separator.copy(alpha = colors.separator.alpha * separator), Offset(0f, size.height - stroke), Size(size.width, stroke))
                },
        ) { measurables, constraints ->
            val width = constraints.maxWidth
            val bar = HeaderBarHeight.roundToPx()
            val inset = 8.dp.roundToPx()
            val loose = Constraints(maxWidth = width, maxHeight = bar)
            val back = measurables.firstOrNull { it.layoutId == HeaderSlot.Back }?.measure(loose)
            val start = measurables.firstOrNull { it.layoutId == HeaderSlot.Start }?.measure(loose)
            val end = measurables.firstOrNull { it.layoutId == HeaderSlot.End }?.measure(loose)
            val leading = (back?.width ?: 0) + (start?.width ?: 0)
            val side = maxOf(leading, end?.width ?: 0) + inset
            val titleWidth = (width - side * 2).coerceAtLeast(0)
            val title = measurables.firstOrNull { it.layoutId == HeaderSlot.Title }
                ?.measure(Constraints(maxWidth = titleWidth, maxHeight = bar))
            val large = measurables.firstOrNull { it.layoutId == HeaderSlot.LargeTitle }
                ?.measure(Constraints(minWidth = width, maxWidth = width))
            val range = (large?.height ?: 0).toFloat()
            if (state.range != range) state.range = range
            val offset = state.offset.coerceIn(0f, range).toInt()
            val height = bar + (large?.height ?: 0) - offset
            layout(width, height) {
                var x = inset
                back?.let {
                    it.placeRelative(x, (bar - it.height) / 2)
                    x += it.width
                }
                start?.placeRelative(x, (bar - (start.height)) / 2)
                end?.let { it.placeRelative(width - inset - it.width, (bar - it.height) / 2) }
                title?.placeRelative((width - title.width) / 2, (bar - title.height) / 2)
                large?.placeRelative(0, bar - offset)
            }
        }
    }
}

@Composable
fun HeaderTitle(
    text: String,
    modifier: Modifier = Modifier,
    subtitle: String? = null,
) {
    val colors = EsuissTheme.colors
    val state = LocalHeaderState.current
    Column(
        modifier = modifier
            .layoutId(HeaderSlot.Title)
            .graphicsLayer {
                val fraction = state?.collapsedFraction ?: 1f
                alpha = if (state == null || state.range <= 0f) 1f else ((fraction - 0.6f) / 0.4f).coerceIn(0f, 1f)
            }
            .semantics { heading() },
        horizontalAlignment = Alignment.CenterHorizontally,
    ) {
        BasicText(
            text,
            style = Typography.base.copy(color = colors.label, fontWeight = FontWeight.SemiBold, textAlign = TextAlign.Center),
            maxLines = 1,
            overflow = TextOverflow.Ellipsis,
        )
        if (subtitle != null) {
            BasicText(
                subtitle,
                style = Typography.xs2.copy(color = colors.labelSecondary, textAlign = TextAlign.Center),
                maxLines = 1,
                overflow = TextOverflow.Ellipsis,
            )
        }
    }
}

@Composable
fun HeaderLargeTitle(
    text: String,
    modifier: Modifier = Modifier,
    subtitle: String? = null,
) {
    val colors = EsuissTheme.colors
    val state = LocalHeaderState.current
    Column(
        modifier = modifier
            .layoutId(HeaderSlot.LargeTitle)
            .graphicsLayer {
                val fraction = state?.collapsedFraction ?: 0f
                alpha = (1f - fraction * 1.4f).coerceIn(0f, 1f)
            }
            .padding(start = 16.dp, end = 16.dp, top = 4.dp, bottom = 8.dp),
        verticalArrangement = Arrangement.spacedBy(2.dp),
    ) {
        BasicText(
            text,
            modifier = Modifier.semantics { heading() },
            style = Typography.xl3.copy(color = colors.label, fontWeight = FontWeight.Bold),
            maxLines = 2,
            overflow = TextOverflow.Ellipsis,
        )
        if (subtitle != null) {
            BasicText(subtitle, style = Typography.sm.copy(color = colors.labelSecondary))
        }
    }
}

@Composable
fun HeaderBack(
    onClick: () -> Unit,
    modifier: Modifier = Modifier,
    text: String? = "Back",
    contentDescription: String = text ?: "Back",
) {
    val colors = EsuissTheme.colors
    val interaction = remember { MutableInteractionSource() }
    val pressed by interaction.collectIsPressedAsState()
    Row(
        modifier = modifier
            .layoutId(HeaderSlot.Back)
            .height(HeaderBarHeight)
            .clickable(
                interactionSource = interaction,
                indication = null,
                role = Role.Button,
                onClickLabel = contentDescription,
                onClick = onClick,
            )
            .graphicsLayer { alpha = if (pressed) 0.4f else 1f }
            .padding(end = 8.dp),
        horizontalArrangement = Arrangement.spacedBy(2.dp),
        verticalAlignment = Alignment.CenterVertically,
    ) {
        Icon(PhosphorIcons.Regular.CaretLeft, contentDescription = if (text == null) contentDescription else null, size = 24.dp, tint = colors.link)
        if (text != null) {
            BasicText(text, style = Typography.base.copy(color = colors.link), maxLines = 1)
        }
    }
}

@Composable
fun HeaderActions(
    modifier: Modifier = Modifier,
    side: HeaderActionsSide = HeaderActionsSide.Trailing,
    content: @Composable RowScope.() -> Unit,
) {
    Row(
        modifier = modifier.layoutId(if (side == HeaderActionsSide.Leading) HeaderSlot.Start else HeaderSlot.End),
        horizontalArrangement = Arrangement.spacedBy(4.dp),
        verticalAlignment = Alignment.CenterVertically,
        content = content,
    )
}
```

```kt title="kotlin/components/Icon.kt"
package com.esuiss.ui.components

import androidx.compose.foundation.Image
import androidx.compose.foundation.layout.size
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.ColorFilter
import androidx.compose.ui.graphics.takeOrElse
import androidx.compose.ui.graphics.vector.ImageVector
import androidx.compose.ui.unit.Dp
import com.esuiss.ui.theme.EsuissTheme

@Composable
fun Icon(
    imageVector: ImageVector,
    contentDescription: String?,
    modifier: Modifier = Modifier,
    size: Dp = LocalIconSize.current,
    tint: Color = LocalContentColor.current.takeOrElse { EsuissTheme.colors.label },
) {
    Image(
        imageVector = imageVector,
        contentDescription = contentDescription,
        modifier = modifier.size(size),
        colorFilter = ColorFilter.tint(tint),
    )
}
```

```kt title="kotlin/components/Item.kt"
package com.esuiss.ui.components

import androidx.compose.foundation.background
import androidx.compose.foundation.border
import androidx.compose.foundation.combinedClickable
import androidx.compose.foundation.interaction.MutableInteractionSource
import androidx.compose.foundation.interaction.collectIsPressedAsState
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.BoxScope
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.ColumnScope
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.RowScope
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.heightIn
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.foundation.text.BasicText
import androidx.compose.runtime.Composable
import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.runtime.DisposableEffect
import androidx.compose.runtime.Stable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableIntStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.runtime.staticCompositionLocalOf
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.RectangleShape
import androidx.compose.ui.graphics.Shape
import androidx.compose.ui.layout.Layout
import androidx.compose.ui.layout.Measurable
import androidx.compose.ui.layout.Placeable
import androidx.compose.ui.layout.layoutId
import androidx.compose.ui.semantics.Role
import androidx.compose.ui.semantics.isTraversalGroup
import androidx.compose.ui.semantics.selected
import androidx.compose.ui.semantics.semantics
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.unit.Constraints
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp
import com.esuiss.ui.theme.EsuissTheme
import com.esuiss.ui.theme.Radius
import com.esuiss.ui.theme.Typography

enum class ItemVariant { Default, Outline, Muted }

enum class ItemSize(
    internal val horizontalPadding: Dp,
    internal val verticalPadding: Dp,
    internal val gap: Dp,
    internal val contentGap: Dp,
    internal val imageSize: Dp,
) {
    Default(16.dp, 14.dp, 14.dp, 4.dp, 40.dp),
    Sm(14.dp, 12.dp, 14.dp, 4.dp, 32.dp),
    Xs(12.dp, 10.dp, 10.dp, 2.dp, 24.dp),
}

enum class ItemGroupVariant { Default, Inset }

enum class ItemMediaVariant { Default, Icon, Image }

private enum class ItemSlot { Media, Content, Actions, Header, Footer }

@Stable
private class ItemState(val size: ItemSize) {
    var descriptions by mutableIntStateOf(0)
}

private val LocalItemState = staticCompositionLocalOf<ItemState?> { null }

internal val LocalItemGroupVariant = staticCompositionLocalOf<ItemGroupVariant?> { null }

@Composable
fun ItemGroup(
    modifier: Modifier = Modifier,
    variant: ItemGroupVariant = ItemGroupVariant.Default,
    content: @Composable ColumnScope.() -> Unit,
) {
    val colors = EsuissTheme.colors
    val inset = variant == ItemGroupVariant.Inset
    val shape = RoundedCornerShape(Radius.xl2)
    Column(
        modifier = modifier
            .fillMaxWidth()
            .then(if (inset) Modifier.clip(shape).background(colors.surfaceSecondary, shape) else Modifier)
            .semantics { isTraversalGroup = true },
        verticalArrangement = if (inset) Arrangement.Top else Arrangement.spacedBy(16.dp),
    ) {
        CompositionLocalProvider(LocalItemGroupVariant provides variant) {
            content()
        }
    }
}

@Composable
fun ItemSeparator(modifier: Modifier = Modifier) {
    val inset = LocalItemGroupVariant.current == ItemGroupVariant.Inset
    Box(
        modifier = modifier
            .fillMaxWidth()
            .padding(start = if (inset) 16.dp else 0.dp)
            .padding(vertical = if (inset) 0.dp else 8.dp)
            .height(1.dp)
            .background(EsuissTheme.colors.separator),
    )
}

@Composable
fun Item(
    modifier: Modifier = Modifier,
    variant: ItemVariant = ItemVariant.Default,
    size: ItemSize = ItemSize.Default,
    onClick: (() -> Unit)? = null,
    onLongClick: (() -> Unit)? = null,
    enabled: Boolean = true,
    selected: Boolean? = null,
    role: Role? = Role.Button,
    onClickLabel: String? = null,
    content: @Composable () -> Unit,
) {
    val inset = LocalItemGroupVariant.current == ItemGroupVariant.Inset
    val shape = if (inset) RectangleShape else RoundedCornerShape(Radius.xl)
    ItemFrame(
        modifier = modifier,
        variant = variant,
        size = size,
        shape = shape,
        padding = PaddingValues(horizontal = size.horizontalPadding, vertical = size.verticalPadding),
        onClick = onClick,
        onLongClick = onLongClick,
        enabled = enabled,
        selected = selected,
        role = role,
        onClickLabel = onClickLabel,
        content = content,
    )
}

@Composable
internal fun ItemFrame(
    modifier: Modifier,
    variant: ItemVariant,
    size: ItemSize,
    shape: Shape,
    padding: PaddingValues,
    onClick: (() -> Unit)?,
    onLongClick: (() -> Unit)?,
    enabled: Boolean,
    selected: Boolean?,
    role: Role?,
    onClickLabel: String?,
    minHeight: Dp = 0.dp,
    gap: Dp = size.gap,
    content: @Composable () -> Unit,
) {
    val colors = EsuissTheme.colors
    val interaction = remember { MutableInteractionSource() }
    val pressed by interaction.collectIsPressedAsState()
    val state = remember(size) { ItemState(size) }
    val interactive = onClick != null || onLongClick != null
    val background = when {
        pressed && enabled && interactive -> colors.itemPressed
        selected == true -> colors.itemSelected
        variant == ItemVariant.Muted -> colors.surfaceSecondary.copy(alpha = colors.surfaceSecondary.alpha * 0.5f)
        else -> Color.Transparent
    }
    val foreground = if (enabled) colors.label else colors.labelQuaternary
    val behaviour = if (interactive) {
        Modifier
            .heightIn(min = maxOf(minHeight, 48.dp))
            .combinedClickable(
                interactionSource = interaction,
                indication = null,
                enabled = enabled,
                onClickLabel = onClickLabel,
                role = role,
                onLongClick = onLongClick,
                onClick = onClick ?: {},
            )
    } else {
        Modifier
            .heightIn(min = minHeight)
            .semantics(mergeDescendants = true) {}
    }
    Box(
        modifier = modifier
            .fillMaxWidth()
            .clip(shape)
            .background(background, shape)
            .then(if (variant == ItemVariant.Outline) Modifier.border(1.dp, colors.separator, shape) else Modifier)
            .then(if (selected != null) Modifier.semantics { this.selected = selected } else Modifier)
            .then(behaviour)
            .padding(padding),
        contentAlignment = Alignment.CenterStart,
    ) {
        CompositionLocalProvider(
            LocalItemState provides state,
            LocalContentStyle provides Typography.base.copy(color = foreground),
            LocalContentColor provides foreground,
            LocalIconSize provides 16.dp,
        ) {
            ItemLayout(gap, state.descriptions > 0, content)
        }
    }
}

@Composable
private fun ItemLayout(gap: Dp, mediaAtTop: Boolean, content: @Composable () -> Unit) {
    Layout(content = content, modifier = Modifier.fillMaxWidth()) { measurables, constraints ->
        val gapPx = gap.roundToPx()
        val nudge = if (mediaAtTop) 2.dp.roundToPx() else 0
        val lines = mutableListOf<List<Measurable>>()
        var current = mutableListOf<Measurable>()
        measurables.forEach { measurable ->
            val slot = measurable.layoutId
            if (slot == ItemSlot.Header || slot == ItemSlot.Footer) {
                if (current.isNotEmpty()) lines += current
                lines += listOf(measurable)
                current = mutableListOf()
            } else {
                current += measurable
            }
        }
        if (current.isNotEmpty()) lines += current
        val bounded = constraints.hasBoundedWidth
        val available = if (bounded) constraints.maxWidth else Constraints.Infinity
        val measured = lines.map { line ->
            val placeables = arrayOfNulls<Placeable>(line.size)
            val flexIndex = line.indexOfFirst { it.layoutId == ItemSlot.Content }
            var used = gapPx * (line.size - 1).coerceAtLeast(0)
            line.forEachIndexed { index, measurable ->
                if (index == flexIndex) return@forEachIndexed
                val full = measurable.layoutId == ItemSlot.Header || measurable.layoutId == ItemSlot.Footer
                val childConstraints = when {
                    full && bounded -> Constraints(minWidth = available, maxWidth = available)
                    bounded -> Constraints(maxWidth = (available - used).coerceAtLeast(0))
                    else -> Constraints()
                }
                val placeable = measurable.measure(childConstraints)
                placeables[index] = placeable
                used += placeable.width
            }
            if (flexIndex >= 0) {
                val remaining = (available - used).coerceAtLeast(0)
                placeables[flexIndex] = line[flexIndex].measure(
                    if (bounded) Constraints(minWidth = remaining, maxWidth = remaining) else Constraints(),
                )
            }
            placeables.requireNoNulls().toList()
        }
        val width = if (bounded) {
            constraints.maxWidth
        } else {
            measured.maxOfOrNull { line -> line.sumOf { it.width } + gapPx * (line.size - 1).coerceAtLeast(0) } ?: 0
        }
        val lineHeights = measured.mapIndexed { lineIndex, line ->
            line.mapIndexed { index, placeable ->
                val isMedia = lines[lineIndex][index].layoutId == ItemSlot.Media
                placeable.height + if (isMedia) nudge else 0
            }.maxOrNull() ?: 0
        }
        val height = (lineHeights.sum() + gapPx * (measured.size - 1).coerceAtLeast(0))
            .coerceIn(constraints.minHeight, constraints.maxHeight)
        layout(width, height) {
            var y = 0
            measured.forEachIndexed { lineIndex, line ->
                val lineHeight = lineHeights[lineIndex]
                var x = 0
                line.forEachIndexed { index, placeable ->
                    val isMedia = lines[lineIndex][index].layoutId == ItemSlot.Media
                    val top = if (isMedia && mediaAtTop) nudge else (lineHeight - placeable.height) / 2
                    placeable.placeRelative(x, y + top)
                    x += placeable.width + gapPx
                }
                y += lineHeight + gapPx
            }
        }
    }
}

@Composable
fun ItemMedia(
    modifier: Modifier = Modifier,
    variant: ItemMediaVariant = ItemMediaVariant.Default,
    content: @Composable BoxScope.() -> Unit,
) {
    val size = LocalItemState.current?.size ?: ItemSize.Default
    val sizing = when (variant) {
        ItemMediaVariant.Image -> {
            val shape = RoundedCornerShape(if (size == ItemSize.Xs) Radius.sm else Radius.md)
            Modifier.size(size.imageSize).clip(shape)
        }
        else -> Modifier
    }
    Box(
        modifier = modifier.layoutId(ItemSlot.Media).then(sizing),
        contentAlignment = Alignment.Center,
    ) {
        CompositionLocalProvider(LocalIconSize provides if (variant == ItemMediaVariant.Icon) 16.dp else LocalIconSize.current) {
            content()
        }
    }
}

@Composable
fun ItemContent(
    modifier: Modifier = Modifier,
    content: @Composable ColumnScope.() -> Unit,
) {
    val size = LocalItemState.current?.size ?: ItemSize.Default
    Column(
        modifier = modifier.layoutId(ItemSlot.Content),
        verticalArrangement = Arrangement.spacedBy(size.contentGap),
        content = content,
    )
}

@Composable
fun ItemTitle(
    modifier: Modifier = Modifier,
    content: @Composable RowScope.() -> Unit,
) {
    val color = LocalContentColor.current
    Row(
        modifier = modifier,
        horizontalArrangement = Arrangement.spacedBy(8.dp),
        verticalAlignment = Alignment.CenterVertically,
    ) {
        CompositionLocalProvider(
            LocalContentStyle provides Typography.base.copy(color = color, fontWeight = FontWeight.SemiBold),
        ) {
            content()
        }
    }
}

@Composable
fun ItemTitle(text: String, modifier: Modifier = Modifier) {
    val color = LocalContentColor.current
    BasicText(
        text,
        modifier = modifier,
        style = Typography.base.copy(color = color, fontWeight = FontWeight.SemiBold),
        maxLines = 1,
        overflow = TextOverflow.Ellipsis,
    )
}

@Composable
fun ItemDescription(text: String, modifier: Modifier = Modifier) {
    val state = LocalItemState.current
    if (state != null) {
        DisposableEffect(state) {
            state.descriptions += 1
            onDispose { state.descriptions -= 1 }
        }
    }
    BasicText(
        text,
        modifier = modifier,
        style = Typography.sm.copy(color = EsuissTheme.colors.labelSecondary),
        maxLines = 2,
        overflow = TextOverflow.Ellipsis,
    )
}

@Composable
fun ItemActions(
    modifier: Modifier = Modifier,
    content: @Composable RowScope.() -> Unit,
) {
    Row(
        modifier = modifier.layoutId(ItemSlot.Actions),
        horizontalArrangement = Arrangement.spacedBy(8.dp),
        verticalAlignment = Alignment.CenterVertically,
        content = content,
    )
}

@Composable
fun ItemHeader(
    modifier: Modifier = Modifier,
    content: @Composable RowScope.() -> Unit,
) {
    Row(
        modifier = modifier.layoutId(ItemSlot.Header),
        horizontalArrangement = Arrangement.SpaceBetween,
        verticalAlignment = Alignment.CenterVertically,
        content = content,
    )
}

@Composable
fun ItemFooter(
    modifier: Modifier = Modifier,
    content: @Composable RowScope.() -> Unit,
) {
    Row(
        modifier = modifier.layoutId(ItemSlot.Footer),
        horizontalArrangement = Arrangement.SpaceBetween,
        verticalAlignment = Alignment.CenterVertically,
        content = content,
    )
}
```

4. Update the `com.esuiss.ui` package names to match your project.

## Usage

```tsx
import { TableListTitle, TableListHeader, TableListFooter, TableListSeparator, TableListRow, TableList } from "@/components/patterns/table-list"
```

```tsx
<View className="gap-8">
  <TableList
    title="Invoices"
    rows={invoices}
    columns={columns}
    getKey={(row) => row.id}
    onRowPress={() => {}}
  />
  <TableList rows={[]} columns={columns} emptyText="No invoices yet." />
</View>
```

Define columns with `key`, `header`, `cell` and `slot`. Several `description` columns are joined with ` · `, and several `trailing` columns are shown side by side. Use `mobileCell` to render a different value than `cell` in the list, such as a shorter date.

Pass `onRowPress` to make rows pressable. When there are no rows, `emptyText` is shown in the group. The `TableListColumn` type is exported.

With a `FlatList`, use `TableListRow` as the item, pass `first` and `last` to round the ends, `TableListSeparator` as `ItemSeparatorComponent`, and `TableListHeader` and `TableListFooter` around the list.

## Examples

### With flat list

Builds the grouped list in a `FlatList` with a header, footer and separators.

![Preview](https://uim.suiss.app/previews/patterns-table-list--with-flat-list.light.webp)

```tsx
import { FlatList } from "react-native"
import { TableListFooter, TableListHeader, TableListRow, TableListSeparator } from "@/components/patterns/table-list"

type Invoice = {
  id: string
  customer: string
  status: string
  method: string
  amount: string
}

const invoices: Invoice[] = [
  {
    id: "INV001",
    customer: "Olivia Martin",
    status: "Paid",
    method: "Card",
    amount: "$250.00",
  },
  {
    id: "INV002",
    customer: "Jackson Lee",
    status: "Pending",
    method: "PayPal",
    amount: "$150.00",
  },
  {
    id: "INV003",
    customer: "Isabella Nguyen",
    status: "Unpaid",
    method: "Transfer",
    amount: "$350.00",
  },
  {
    id: "INV004",
    customer: "William Kim",
    status: "Paid",
    method: "Card",
    amount: "$450.00",
  },
]

export function TableListWithFlatListExample() {
  return (
    <FlatList
      data={invoices}
      keyExtractor={(item) => item.id}
      ListHeaderComponent={<TableListHeader>Recent</TableListHeader>}
      ListFooterComponent={
        <TableListFooter>Payments settle within two days.</TableListFooter>
      }
      ItemSeparatorComponent={TableListSeparator}
      renderItem={({ item, index }) => (
        <TableListRow
          first={index === 0}
          last={index === invoices.length - 1}
          title={item.customer}
          description={item.status}
          trailing={item.amount}
          onPress={() => {}}
        />
      )}
    />
  )
}
```

```swift
import EsuissUI
import SwiftUI

struct TableListWithFlatListExample: View {
  var body: some View {
    TableListSection(header: "Recent", footer: "Payments settle within two days.") {
      ForEach(tableListInvoices) { invoice in
        TableListRow(action: {}) {
          VStack(alignment: .leading, spacing: 2) {
            Text(verbatim: invoice.customer)
              .textStyle(.base)
              .foregroundStyle(Color.label)
              .lineLimit(1)
            Text(verbatim: invoice.status)
              .textStyle(.sm)
              .foregroundStyle(Color.labelSecondary)
              .lineLimit(1)
          }
          .frame(maxWidth: .infinity, alignment: .leading)
          Text(verbatim: invoice.amount)
            .textStyle(.base)
            .monospacedDigit()
            .foregroundStyle(Color.labelSecondary)
            .lineLimit(1)
            .fixedSize()
        }
      }
    }
  }
}

struct TableListInvoice: Identifiable {
  let id: String
  let customer: String
  let status: String
  let method: String
  let amount: String
}

let tableListInvoices = [
  TableListInvoice(id: "INV001", customer: "Olivia Martin", status: "Paid", method: "Card", amount: "$250.00"),
  TableListInvoice(id: "INV002", customer: "Jackson Lee", status: "Pending", method: "PayPal", amount: "$150.00"),
  TableListInvoice(id: "INV003", customer: "Isabella Nguyen", status: "Unpaid", method: "Transfer", amount: "$350.00"),
  TableListInvoice(id: "INV004", customer: "William Kim", status: "Paid", method: "Card", amount: "$450.00"),
]
```

```kotlin
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.heightIn
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.itemsIndexed
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import com.esuiss.ui.patterns.TableListFooter
import com.esuiss.ui.patterns.TableListHeader
import com.esuiss.ui.patterns.TableListRow
import com.esuiss.ui.patterns.TableListRowText

class TableListInvoice(
    val id: String,
    val customer: String,
    val status: String,
    val method: String,
    val amount: String,
)

val tableListInvoices = listOf(
    TableListInvoice("INV001", "Olivia Martin", "Paid", "Card", "$250.00"),
    TableListInvoice("INV002", "Jackson Lee", "Pending", "PayPal", "$150.00"),
    TableListInvoice("INV003", "Isabella Nguyen", "Unpaid", "Transfer", "$350.00"),
    TableListInvoice("INV004", "William Kim", "Paid", "Card", "$450.00"),
)

@Composable
fun TableListWithFlatList() {
    LazyColumn(Modifier.fillMaxWidth().heightIn(max = 640.dp)) {
        item(key = "header") { TableListHeader("Recent") }
        itemsIndexed(tableListInvoices, key = { _, item -> item.id }) { index, item ->
            TableListRow(first = index == 0, last = index == tableListInvoices.lastIndex, onClick = {}) {
                TableListRowText(item.customer, item.status, item.amount)
            }
        }
        item(key = "footer") { TableListFooter("Payments settle within two days.") }
    }
}
```

## API Reference

### TableListTitle

A large heading above the list.

### TableListHeader

A small uppercase heading above a group.

### TableListFooter

A note below a group.

### TableListSeparator

An inset divider between rows.

### TableListRow

One row with a title, description and trailing content.

### TableList

Renders rows from a column definition, with an optional title and empty state.

## Accessibility

- The group has the `list` role; rows have the `listitem` role, or `button` when `onRowPress` is set.
- `TableListTitle` and `TableListHeader` have the `heading` role.
- Separators are hidden from screen readers.

## Notes

- Rows use `bg-surface-secondary` and `bg-surface-tertiary` when pressed.
- The `header` and `align` column fields are not rendered by the list layout.
