# Table

Data table built from columns and rows, with optional cell borders, striped rows, compact size, and a footer row. Scrolls horizontally on narrow screens.

- Category: Data
- Status: stable
- Registry: https://markas.jenderalcorp.com/r/table.json
- CLI: `npx markasui@latest add table`

## When to use

Showing structured data that is compared by column, such as a list of orders or members.

- Always set caption or label so the region has a name
- Right-align number and amount columns with align right
- For cells with a badge or button use renderCell in React and the cell-<key> slot in Vue
- Use bordered with a footer for reports and totals, size sm for dense data
- Pass the totals row through footer instead of adding it to rows

## Code

### Blade

Save at `resources/views/components/markas/table.blade.php`. No extra dependencies.

```blade
@props([
    'columns' => [],
    'rows' => [],
    'caption' => null,
    'showCaption' => false,
    'label' => null,
    'bordered' => false,
    'square' => false,
    'striped' => false,
    'size' => 'md',
    'footer' => null,
])

@php
    $wrapper = 'overflow-x-auto border border-line focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-primary';
    $tableClass = 'w-full border-collapse text-sm';
    $captionClasses = [
        'hidden' => 'sr-only',
        'visible' => 'px-4 py-3 text-left font-medium text-ink',
    ];
    $headRow = 'bg-subtle text-left text-sm font-medium text-muted';
    $rounded = 'rounded-xl';
    $borderedHeadRow = 'border-b-2 border-line';
    $headCell = 'font-medium whitespace-nowrap';
    $row = 'border-t border-line transition-colors duration-150 ease-out hover:bg-subtle/50 motion-reduce:transition-none';
    $stripedRow = 'even:bg-subtle/40';
    $footRow = 'border-t-2 border-line bg-subtle font-medium';
    $cell = 'whitespace-nowrap text-ink';
    $borderedCell = 'border-l border-line first:border-l-0';
    $sizes = [
        'sm' => 'px-3 py-2 text-[13px]',
        'md' => 'px-4 py-3',
    ];
    $aligns = [
        'left' => 'text-left',
        'center' => 'text-center',
        'right' => 'text-right',
    ];

    $regionLabel = $label ?? $caption ?? 'Table';
    $cellClass = fn ($base, $column) => implode(' ', array_filter([
        $base,
        $sizes[$size] ?? $sizes['md'],
        $bordered ? $borderedCell : null,
        $aligns[$column['align'] ?? 'left'],
    ]));
@endphp

<div {{ $attributes->merge(['tabindex' => '0', 'role' => 'region', 'aria-label' => $regionLabel])->class([$wrapper, $rounded => ! $square]) }}>
    <table class="{{ $tableClass }}">
        @if ($caption)
            <caption class="{{ $captionClasses[$showCaption ? 'visible' : 'hidden'] }}">{{ $caption }}</caption>
        @endif
        <thead>
            <tr class="{{ $headRow }}{{ $bordered ? ' '.$borderedHeadRow : '' }}">
                @foreach ($columns as $column)
                    <th scope="col" class="{{ $cellClass($headCell, $column) }}">{{ $column['label'] }}</th>
                @endforeach
            </tr>
        </thead>
        <tbody>
            @foreach ($rows as $item)
                <tr class="{{ $row }}{{ $striped ? ' '.$stripedRow : '' }}">
                    @foreach ($columns as $column)
                        <td class="{{ $cellClass($cell, $column) }}">{{ $item[$column['key']] ?? '' }}</td>
                    @endforeach
                </tr>
            @endforeach
        </tbody>
        @if ($footer)
            <tfoot>
                <tr class="{{ $footRow }}">
                    @foreach ($columns as $column)
                        <td class="{{ $cellClass($cell, $column) }}">{{ $footer[$column['key']] ?? '' }}</td>
                    @endforeach
                </tr>
            </tfoot>
        @endif
    </table>
</div>
```

```blade
<x-markas.table
    caption="Recent orders"
    :columns="[
        ['key' => 'code', 'label' => 'Order'],
        ['key' => 'customer', 'label' => 'Customer'],
        ['key' => 'total', 'label' => 'Total', 'align' => 'right'],
    ]"
    :rows="$orders->map(fn ($o) => ['code' => $o->code, 'customer' => $o->customer, 'total' => $o->total_label])->all()"
/>
```

### React

Save at `src/components/markas/Table.tsx`. No extra dependencies.

```tsx
import type { ComponentProps, ReactNode } from "react";

const wrapper =
  "overflow-x-auto border border-line focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-primary";
const tableClass = "w-full border-collapse text-sm";
const captionClasses = {
  hidden: "sr-only",
  visible: "px-4 py-3 text-left font-medium text-ink",
};
const headRow = "bg-subtle text-left text-sm font-medium text-muted";
const rounded = "rounded-xl";
const borderedHeadRow = "border-b-2 border-line";
const headCell = "font-medium whitespace-nowrap";
const rowClass =
  "border-t border-line transition-colors duration-150 ease-out hover:bg-subtle/50 motion-reduce:transition-none";
const stripedRow = "even:bg-subtle/40";
const footRow = "border-t-2 border-line bg-subtle font-medium";
const cell = "whitespace-nowrap text-ink";
const borderedCell = "border-l border-line first:border-l-0";
const sizes = {
  sm: "px-3 py-2 text-[13px]",
  md: "px-4 py-3",
};
const aligns = {
  left: "text-left",
  center: "text-center",
  right: "text-right",
};
const cx = (...c: (string | false | null | undefined)[]) =>
  c.filter(Boolean).join(" ");

export type TableColumn = {
  key: string;
  label: ReactNode;
  align?: keyof typeof aligns;
};

export type TableRow = Record<string, string | number | null | undefined>;

export type TableProps = ComponentProps<"div"> & {
  columns: TableColumn[];
  rows: TableRow[];
  caption?: string;
  showCaption?: boolean;
  label?: string;
  /** Nama field berisi id unik per baris, dipakai sebagai key. Tanpa ini key memakai indeks. */
  rowKey?: string;
  /** Isi sel kustom. Kembalikan undefined untuk memakai nilai teks bawaan. */
  renderCell?: (row: TableRow, key: string) => ReactNode;
  /** Garis di setiap sel, seperti grid kotak. */
  bordered?: boolean;
  /** Sudut siku (tanpa radius), seperti tabel klasik. */
  square?: boolean;
  /** Latar selang-seling di baris genap. */
  striped?: boolean;
  size?: keyof typeof sizes;
  /** Satu baris tfoot opsional, nilai per key kolom (misalnya total). */
  footer?: TableRow;
};

export function Table({
  columns,
  rows,
  caption,
  showCaption = false,
  label,
  rowKey,
  renderCell,
  bordered = false,
  square = false,
  striped = false,
  size = "md",
  footer,
  className,
  ...props
}: TableProps) {
  const cellClass = (base: string, column: TableColumn) =>
    cx(
      base,
      sizes[size] ?? sizes.md,
      bordered && borderedCell,
      aligns[column.align ?? "left"],
    );

  return (
    <div
      tabIndex={0}
      role="region"
      aria-label={label ?? caption ?? "Table"}
      className={cx(wrapper, !square && rounded, className)}
      {...props}
    >
      <table className={tableClass}>
        {caption && (
          <caption
            className={captionClasses[showCaption ? "visible" : "hidden"]}
          >
            {caption}
          </caption>
        )}
        <thead>
          <tr className={cx(headRow, bordered && borderedHeadRow)}>
            {columns.map((column) => (
              <th
                key={column.key}
                scope="col"
                className={cellClass(headCell, column)}
              >
                {column.label}
              </th>
            ))}
          </tr>
        </thead>
        <tbody>
          {rows.map((row, index) => (
            <tr
              key={rowKey === undefined ? index : String(row[rowKey])}
              className={cx(rowClass, striped && stripedRow)}
            >
              {columns.map((column) => (
                <td key={column.key} className={cellClass(cell, column)}>
                  {renderCell?.(row, column.key) ?? row[column.key] ?? ""}
                </td>
              ))}
            </tr>
          ))}
        </tbody>
        {footer && (
          <tfoot>
            <tr className={footRow}>
              {columns.map((column) => (
                <td key={column.key} className={cellClass(cell, column)}>
                  {footer[column.key] ?? ""}
                </td>
              ))}
            </tr>
          </tfoot>
        )}
      </table>
    </div>
  );
}
```

```tsx
import { Table } from "@/components/markas/Table";

<Table
  caption="Recent orders"
  columns={[
    { key: "code", label: "Order" },
    { key: "status", label: "Status" },
    { key: "total", label: "Total", align: "right" },
  ]}
  rows={orders}
  renderCell={(row, key) =>
    key === "status" ? <Badge>{row.status}</Badge> : undefined
  }
/>;
```

### Vue

Save at `src/components/markas/Table.vue`. No extra dependencies.

```vue
<script setup lang="ts">
export type TableColumn = {
  key: string;
  label: string;
  align?: "left" | "center" | "right";
};
export type TableRow = Record<string, string | number | null | undefined>;

const props = withDefaults(
  defineProps<{
    columns: TableColumn[];
    rows: TableRow[];
    caption?: string;
    showCaption?: boolean;
    label?: string;
    /** Nama field berisi id unik per baris, dipakai sebagai key. Tanpa ini key memakai indeks. */
    rowKey?: string;
    /** Garis di setiap sel, seperti grid kotak. */
    bordered?: boolean;
    /** Sudut siku (tanpa radius), seperti tabel klasik. */
    square?: boolean;
    /** Latar selang-seling di baris genap. */
    striped?: boolean;
    size?: "sm" | "md";
    /** Satu baris tfoot opsional, nilai per key kolom (misalnya total). */
    footer?: TableRow;
  }>(),
  {
    bordered: false,
    square: false,
    striped: false,
    size: "md",
    footer: undefined,
    caption: undefined,
    showCaption: false,
    label: undefined,
    rowKey: undefined,
  },
);

defineSlots<Record<`cell-${string}`, (props: { row: TableRow }) => unknown>>();

const wrapper =
  "overflow-x-auto border border-line focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-primary";
const tableClass = "w-full border-collapse text-sm";
const captionClasses = {
  hidden: "sr-only",
  visible: "px-4 py-3 text-left font-medium text-ink",
};
const headRow = "bg-subtle text-left text-sm font-medium text-muted";
const rounded = "rounded-xl";
const borderedHeadRow = "border-b-2 border-line";
const headCell = "font-medium whitespace-nowrap";
const rowClass =
  "border-t border-line transition-colors duration-150 ease-out hover:bg-subtle/50 motion-reduce:transition-none";
const stripedRow = "even:bg-subtle/40";
const footRow = "border-t-2 border-line bg-subtle font-medium";
const cell = "whitespace-nowrap text-ink";
const borderedCell = "border-l border-line first:border-l-0";
const sizes = {
  sm: "px-3 py-2 text-[13px]",
  md: "px-4 py-3",
};
const aligns = {
  left: "text-left",
  center: "text-center",
  right: "text-right",
};

const cellClass = (base: string, column: TableColumn) => [
  base,
  sizes[props.size] ?? sizes.md,
  props.bordered && borderedCell,
  aligns[column.align ?? "left"],
];
</script>

<template>
  <div
    tabindex="0"
    role="region"
    :aria-label="props.label ?? props.caption ?? 'Table'"
    :class="[wrapper, !props.square && rounded]"
  >
    <table :class="tableClass">
      <caption
        v-if="props.caption"
        :class="captionClasses[props.showCaption ? 'visible' : 'hidden']"
      >
        {{
          props.caption
        }}
      </caption>
      <thead>
        <tr :class="[headRow, props.bordered && borderedHeadRow]">
          <th
            v-for="column in props.columns"
            :key="column.key"
            scope="col"
            :class="cellClass(headCell, column)"
          >
            {{ column.label }}
          </th>
        </tr>
      </thead>
      <tbody>
        <tr
          v-for="(row, index) in props.rows"
          :key="props.rowKey === undefined ? index : String(row[props.rowKey])"
          :class="[rowClass, props.striped && stripedRow]"
        >
          <td
            v-for="column in props.columns"
            :key="column.key"
            :class="cellClass(cell, column)"
          >
            <slot :name="`cell-${column.key}`" :row="row">{{
              row[column.key] ?? ""
            }}</slot>
          </td>
        </tr>
      </tbody>
      <tfoot v-if="props.footer">
        <tr :class="footRow">
          <td
            v-for="column in props.columns"
            :key="column.key"
            :class="cellClass(cell, column)"
          >
            {{ props.footer[column.key] ?? "" }}
          </td>
        </tr>
      </tfoot>
    </table>
  </div>
</template>
```

```vue
<template>
  <Table
    caption="Recent orders"
    :columns="[
      { key: 'code', label: 'Order' },
      { key: 'status', label: 'Status' },
      { key: 'total', label: 'Total', align: 'right' },
    ]"
    :rows="orders"
  >
    <template #cell-status="{ row }">
      <Badge>{{ row.status }}</Badge>
    </template>
  </Table>
</template>
```

### Svelte

Save at `src/lib/components/markas/Table.svelte`. No extra dependencies.

```svelte
<script lang="ts" module>
  export type TableColumn = {
    key: string;
    label: string;
    align?: "left" | "center" | "right";
  };

  export type TableRow = Record<string, string | number | null | undefined>;
</script>

<script lang="ts">
  import type { Snippet } from "svelte";
  import type { HTMLAttributes } from "svelte/elements";

  const wrapper =
    "overflow-x-auto border border-line focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-primary";
  const tableClass = "w-full border-collapse text-sm";
  const captionClasses = {
    hidden: "sr-only",
    visible: "px-4 py-3 text-left font-medium text-ink",
  };
  const headRow = "bg-subtle text-left text-sm font-medium text-muted";
  const rounded = "rounded-xl";
  const borderedHeadRow = "border-b-2 border-line";
  const headCell = "font-medium whitespace-nowrap";
  const rowClass =
    "border-t border-line transition-colors duration-150 ease-out hover:bg-subtle/50 motion-reduce:transition-none";
  const stripedRow = "even:bg-subtle/40";
  const footRow = "border-t-2 border-line bg-subtle font-medium";
  const cell = "whitespace-nowrap text-ink";
  const borderedCell = "border-l border-line first:border-l-0";
  const sizes = {
    sm: "px-3 py-2 text-[13px]",
    md: "px-4 py-3",
  };
  const aligns = {
    left: "text-left",
    center: "text-center",
    right: "text-right",
  };

  type Props = HTMLAttributes<HTMLDivElement> & {
    columns: TableColumn[];
    rows: TableRow[];
    caption?: string;
    showCaption?: boolean;
    label?: string;
    /** Field holding a unique id per row, used as the key. Without it the index is used. */
    rowKey?: string;
    /** Custom cell content per column key. Other columns show the plain value. */
    cells?: Record<string, Snippet<[TableRow]>>;
    /** Lines around every cell, like a grid. */
    bordered?: boolean;
    /** Square corners (no radius), like a classic table. */
    square?: boolean;
    /** Alternating background on even rows. */
    striped?: boolean;
    size?: keyof typeof sizes;
    /** One optional tfoot row, values per column key (for example a total). */
    footer?: TableRow;
  };

  let {
    columns,
    rows,
    caption,
    showCaption = false,
    label,
    rowKey,
    cells = {},
    bordered = false,
    square = false,
    striped = false,
    size = "md",
    footer,
    class: className,
    ...rest
  }: Props = $props();

  const cellClass = (base: string, column: TableColumn) => [
    base,
    sizes[size] ?? sizes.md,
    bordered && borderedCell,
    aligns[column.align ?? "left"],
  ];
</script>

<!-- svelte-ignore a11y_no_noninteractive_tabindex -->
<div
  tabindex="0"
  role="region"
  aria-label={label ?? caption ?? "Table"}
  class={[wrapper, !square && rounded, className]}
  {...rest}
>
  <table class={tableClass}>
    {#if caption}
      <caption class={captionClasses[showCaption ? "visible" : "hidden"]}
        >{caption}</caption
      >
    {/if}
    <thead>
      <tr class={[headRow, bordered && borderedHeadRow]}>
        {#each columns as column (column.key)}
          <th scope="col" class={cellClass(headCell, column)}>{column.label}</th
          >
        {/each}
      </tr>
    </thead>
    <tbody>
      {#each rows as row, index (rowKey === undefined ? index : String(row[rowKey]))}
        <tr class={[rowClass, striped && stripedRow]}>
          {#each columns as column (column.key)}
            {@const custom = cells[column.key]}
            <td class={cellClass(cell, column)}
              >{#if custom}{@render custom(row)}{:else}{row[column.key] ??
                  ""}{/if}</td
            >
          {/each}
        </tr>
      {/each}
    </tbody>
    {#if footer}
      <tfoot>
        <tr class={footRow}>
          {#each columns as column (column.key)}
            <td class={cellClass(cell, column)}>{footer[column.key] ?? ""}</td>
          {/each}
        </tr>
      </tfoot>
    {/if}
  </table>
</div>
```

```svelte
<script lang="ts">
  import Badge from "$lib/components/markas/Badge.svelte";
  import Table, { type TableRow } from "$lib/components/markas/Table.svelte";

  const columns = [
    { key: "code", label: "Order" },
    { key: "status", label: "Status" },
    { key: "total", label: "Total", align: "right" as const },
  ];
</script>

{#snippet status(row: TableRow)}
  <Badge>{row.status}</Badge>
{/snippet}

<Table caption="Recent orders" {columns} rows={orders} cells={{ status }} />
```

`cells` maps a column key to a snippet that receives the row. Other columns show the plain value.

### Astro

Save at `src/components/markas/Table.astro`. No extra dependencies.

```astro
---
import type { HTMLAttributes } from "astro/types";

export type TableColumn = {
  key: string;
  label: string;
  align?: "left" | "center" | "right";
};

export type TableRow = Record<string, string | number | null | undefined>;

const wrapper =
  "overflow-x-auto border border-line focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-primary";
const tableClass = "w-full border-collapse text-sm";
const captionClasses = {
  hidden: "sr-only",
  visible: "px-4 py-3 text-left font-medium text-ink",
};
const headRow = "bg-subtle text-left text-sm font-medium text-muted";
const rounded = "rounded-xl";
const borderedHeadRow = "border-b-2 border-line";
const headCell = "font-medium whitespace-nowrap";
const rowClass =
  "border-t border-line transition-colors duration-150 ease-out hover:bg-subtle/50 motion-reduce:transition-none";
const stripedRow = "even:bg-subtle/40";
const footRow = "border-t-2 border-line bg-subtle font-medium";
const cell = "whitespace-nowrap text-ink";
const borderedCell = "border-l border-line first:border-l-0";
const sizes = {
  sm: "px-3 py-2 text-[13px]",
  md: "px-4 py-3",
};
const aligns = {
  left: "text-left",
  center: "text-center",
  right: "text-right",
};

type Props = HTMLAttributes<"div"> & {
  columns: TableColumn[];
  rows: TableRow[];
  caption?: string;
  showCaption?: boolean;
  label?: string;
  /** Lines around every cell, like a grid. */
  bordered?: boolean;
  /** Square corners (no radius), like a classic table. */
  square?: boolean;
  /** Alternating background on even rows. */
  striped?: boolean;
  size?: keyof typeof sizes;
  /** One optional tfoot row, values per column key (for example a total). */
  footer?: TableRow;
};

const {
  columns,
  rows,
  caption,
  showCaption = false,
  label,
  bordered = false,
  square = false,
  striped = false,
  size = "md",
  footer,
  class: className,
  ...rest
} = Astro.props;

const cellClass = (base: string, column: TableColumn) => [
  base,
  sizes[size] ?? sizes.md,
  bordered && borderedCell,
  aligns[column.align ?? "left"],
];

// A function child, (row, key) => markup, renders custom cells. Empty output falls back to the value.
const hasRenderer = Astro.slots.has("default");
const body = await Promise.all(
  rows.map((row) =>
    Promise.all(
      columns.map(async (column) => ({
        column,
        html: hasRenderer
          ? (await Astro.slots.render("default", [row, column.key])).trim()
          : "",
        text: row[column.key] ?? "",
      })),
    ),
  ),
);
---

<div
  tabindex="0"
  role="region"
  aria-label={label ?? caption ?? "Table"}
  class:list={[wrapper, !square && rounded, className]}
  {...rest}
>
  <table class={tableClass}>
    {
      caption && (
        <caption class={captionClasses[showCaption ? "visible" : "hidden"]}>
          {caption}
        </caption>
      )
    }
    <thead>
      <tr class:list={[headRow, bordered && borderedHeadRow]}>
        {
          columns.map((column) => (
            <th scope="col" class:list={cellClass(headCell, column)}>
              {column.label}
            </th>
          ))
        }
      </tr>
    </thead>
    <tbody>
      {
        body.map((cells) => (
          <tr class:list={[rowClass, striped && stripedRow]}>
            {cells.map(({ column, html, text }) =>
              html ? (
                <td class:list={cellClass(cell, column)} set:html={html} />
              ) : (
                <td class:list={cellClass(cell, column)}>{text}</td>
              ),
            )}
          </tr>
        ))
      }
    </tbody>
    {
      footer && (
        <tfoot>
          <tr class={footRow}>
            {columns.map((column) => (
              <td class:list={cellClass(cell, column)}>
                {footer[column.key] ?? ""}
              </td>
            ))}
          </tr>
        </tfoot>
      )
    }
  </table>
</div>
```

```astro
---
import Badge from "@/components/markas/Badge.astro";
import Table, { type TableRow } from "@/components/markas/Table.astro";
---

<Table caption="Recent orders" columns={columns} rows={orders}>
  {
    (row: TableRow, key: string) =>
      key === "status" && <Badge>{row.status}</Badge>
  }
</Table>
```

The function child runs for every cell. Return nothing to keep the plain value.

### Angular

Save at `src/app/markas/table.component.ts`. No extra dependencies.

```ts
import { NgTemplateOutlet } from "@angular/common";
import {
  booleanAttribute,
  ChangeDetectionStrategy,
  Component,
  computed,
  input,
  type TemplateRef,
} from "@angular/core";

const wrapper =
  "overflow-x-auto border border-line focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-primary";
const tableClass = "w-full border-collapse text-sm";
const captionClasses = {
  hidden: "sr-only",
  visible: "px-4 py-3 text-left font-medium text-ink",
};
const headRow = "bg-subtle text-left text-sm font-medium text-muted";
const rounded = "rounded-xl";
const borderedHeadRow = "border-b-2 border-line";
const headCell = "font-medium whitespace-nowrap";
const rowClass =
  "border-t border-line transition-colors duration-150 ease-out hover:bg-subtle/50 motion-reduce:transition-none";
const stripedRow = "even:bg-subtle/40";
const footRow = "border-t-2 border-line bg-subtle font-medium";
const cell = "whitespace-nowrap text-ink";
const borderedCell = "border-l border-line first:border-l-0";
const sizes = {
  sm: "px-3 py-2 text-[13px]",
  md: "px-4 py-3",
};
const aligns = {
  left: "text-left",
  center: "text-center",
  right: "text-right",
};

export type TableColumn = {
  key: string;
  label: string;
  align?: keyof typeof aligns;
};

export type TableRow = Record<string, string | number | null | undefined>;

export type TableCellContext = { $implicit: TableRow };

const join = (...c: (string | false | null | undefined)[]) =>
  c.filter(Boolean).join(" ");

/**
 * Attribute selector on the native wrapper div: the user's class and attributes stay on the
 * scrollable region. Custom cells: `[cells]="{ status: statusCell }"` with
 * `<ng-template #statusCell let-row>`.
 */
@Component({
  selector: "div[markas-table]",
  changeDetection: ChangeDetectionStrategy.OnPush,
  imports: [NgTemplateOutlet],
  host: {
    tabindex: "0",
    role: "region",
    "[attr.aria-label]": "label() ?? caption() ?? 'Table'",
    "[class]": "wrapperClass()",
  },
  template: `
    <table [class]="tableClass">
      @if (caption()) {
        <caption [class]="captionClass()">
          {{
            caption()
          }}
        </caption>
      }
      <thead>
        <tr [class]="headRowClass()">
          @for (column of columns(); track column.key) {
            <th scope="col" [class]="cellClass(headCell, column)">
              {{ column.label }}
            </th>
          }
        </tr>
      </thead>
      <tbody>
        @for (row of rows(); track trackRow($index, row)) {
          <tr [class]="bodyRowClass()">
            @for (column of columns(); track column.key) {
              <td [class]="cellClass(cell, column)">
                @if (cells()[column.key]; as custom) {
                  <ng-container
                    [ngTemplateOutlet]="custom"
                    [ngTemplateOutletContext]="{ $implicit: row }"
                  />
                } @else {
                  {{ row[column.key] ?? "" }}
                }
              </td>
            }
          </tr>
        }
      </tbody>
      @if (footer(); as foot) {
        <tfoot>
          <tr [class]="footRow">
            @for (column of columns(); track column.key) {
              <td [class]="cellClass(cell, column)">
                {{ foot[column.key] ?? "" }}
              </td>
            }
          </tr>
        </tfoot>
      }
    </table>
  `,
})
export class Table {
  readonly columns = input.required<TableColumn[]>();
  readonly rows = input.required<TableRow[]>();
  readonly caption = input<string>();
  readonly showCaption = input(false, { transform: booleanAttribute });
  readonly label = input<string>();
  /** Field holding a unique id per row, used to track rows. Without it the index is used. */
  readonly rowKey = input<string>();
  /** Custom cell templates per column key. Other columns show the plain value. */
  readonly cells = input<Record<string, TemplateRef<TableCellContext>>>({});
  /** Lines around every cell, like a grid. */
  readonly bordered = input(false, { transform: booleanAttribute });
  /** Square corners (no radius), like a classic table. */
  readonly square = input(false, { transform: booleanAttribute });
  /** Alternating background on even rows. */
  readonly striped = input(false, { transform: booleanAttribute });
  readonly size = input<keyof typeof sizes>("md");
  /** One optional tfoot row, values per column key (for example a total). */
  readonly footer = input<TableRow>();

  protected readonly tableClass = tableClass;
  protected readonly headCell = headCell;
  protected readonly cell = cell;
  protected readonly footRow = footRow;
  protected readonly wrapperClass = computed(() =>
    join(wrapper, !this.square() && rounded),
  );
  protected readonly captionClass = computed(
    () => captionClasses[this.showCaption() ? "visible" : "hidden"],
  );
  protected readonly headRowClass = computed(() =>
    join(headRow, this.bordered() && borderedHeadRow),
  );
  protected readonly bodyRowClass = computed(() =>
    join(rowClass, this.striped() && stripedRow),
  );

  protected cellClass(base: string, column: TableColumn) {
    return join(
      base,
      sizes[this.size()] ?? sizes.md,
      this.bordered() && borderedCell,
      aligns[column.align ?? "left"],
    );
  }

  protected trackRow(index: number, row: TableRow) {
    const key = this.rowKey();
    return key === undefined ? index : String(row[key]);
  }
}
```

```ts
import { Component } from "@angular/core";
import { Badge } from "./markas/badge.component";
import { Table, type TableColumn } from "./markas/table.component";

@Component({
  selector: "app-orders",
  imports: [Badge, Table],
  template: `
    <div
      markas-table
      caption="Recent orders"
      [columns]="columns"
      [rows]="orders"
      [cells]="{ status: statusCell }"
    ></div>
    <ng-template #statusCell let-row>
      <span markas-badge>{{ row.status }}</span>
    </ng-template>
  `,
})
export class Orders {
  columns: TableColumn[] = [
    { key: "code", label: "Order" },
    { key: "status", label: "Status" },
    { key: "total", label: "Total", align: "right" },
  ];
  orders = [{ code: "INV-1024", status: "Paid", total: "$250.00" }];
}
```

`cells` maps a column key to an `ng-template` that receives the row as `let-row`.

## Props

| Name | Type | Default | Description |
| --- | --- | --- | --- |
| `columns` | `{ key: string, label: string, align?: 'left' \| 'center' \| 'right' }[]` | [] | List of columns. key points to a property on each row. |
| `rows` | `Record<string, string \| number>[]` | [] | Row data. A PHP array in Blade. |
| `caption` | `string` | - | Table title in the caption element. Visually hidden unless show-caption is set. |
| `showCaption` | `boolean` | false | Show the caption above the table. |
| `label` | `string` | caption or Table | aria-label of the scrollable region wrapper. Falls back to caption, then to Table. |
| `bordered` | `boolean` | false | Draw lines around every cell, including the header, for a classic grid look. The header gets a stronger bottom line. |
| `square` | `boolean` | false | Square corners with no radius, like a classic spreadsheet table. |
| `striped` | `boolean` | false | Give even rows a subtle background. |
| `size` | `'sm' \| 'md'` | md | Cell padding. sm uses tighter padding and 13px text for dense data. |
| `footer` | `Record<string, string \| number>` | - | Optional single footer row in tfoot, with a value per column key, such as totals. Missing keys render as empty cells. |
| `rowKey` | `string` | - | Name of the field holding a unique id per row (such as id), used as the React and Vue key so rows do not get mixed up when data is sorted or removed. Without it the key is the index. Not used in Blade. |
| `renderCell / slot cell-<key> / cells` | `(row, key) => ReactNode · slot { row } · Record<string, Snippet \| TemplateRef>` | - | Custom cell content. React uses renderCell, Vue the named slot cell-<key>, Svelte and Angular a cells map of snippets or ng-templates per column key, Astro a function child (row, key) that returns markup or nothing. Blade is text only. |

## Accessibility

- The wrapper uses role region, an aria-label, and tabindex 0, so a clipped table can be focused and scrolled with the arrow keys.
- Column headers use th with scope col.
- The caption is still read by screen readers when visually hidden.
- The footer row is rendered inside tfoot, so screen readers announce it as the table footer.

## Notes

- Blade only shows escaped text values. For cells with other components, write the table by hand with the same classes, or prepare the string in the controller.
- A `renderCell` that returns `undefined` falls back to the plain text value, so only handle the columns that need it.
- Add `show-caption` (Blade, Vue) or `showCaption` (React) to show the caption above the table.
- Cells do not wrap (`whitespace-nowrap`). On narrow screens the table scrolls horizontally inside its wrapper.
- Set `rowKey` (React and Vue, such as `rowKey="id"`) to a field with a unique id per row when rows can be sorted, filtered, or removed. Without `rowKey`, the key is the row index. Blade does not need it.
- The region is named by `label`, then `caption`, then "Table". Set `label` or `caption` in your site's language.
- Add `bordered` for a classic grid with lines around every cell, `striped` for alternating row backgrounds, and `size="sm"` for tighter padding with 13px text in dense tables.
- Pass totals through `footer`, an object (a PHP array in Blade) keyed by column, such as `:footer="['item' => 'Total', 'value' => '$4,578.00']"` in Blade or `footer={{ item: "Total", value: "$4,578.00" }}` in React. It renders one row in `tfoot` with the same alignment as each column.
