{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "record-table",
  "title": "Record table",
  "description": "A table of records, one row per record and one column per field, each row linking through to the record.",
  "dependencies": [
    "@registrystack/app-runtime@~0.43.0-next.0",
    "lucide-react@1.43.0"
  ],
  "registryDependencies": [
    "@registrystack/field-renderers",
    "@registrystack/lib-content",
    "@registrystack/lib-format"
  ],
  "files": [
    {
      "path": "record/record-table.tsx",
      "content": "import { ArrowUpRight } from \"lucide-react\";\nimport type { FieldModel, RecordView } from \"@registrystack/app-runtime\";\nimport { FieldValue } from \"@/blocks/fields/field-value\";\nimport { ReferenceHrefProvider } from \"@/blocks/fields/reference-value\";\nimport { InPhrase } from \"@/blocks/fields/values\";\nimport { useBlockContent, useLocale } from \"@/blocks/lib/content\";\nimport { fill } from \"@/blocks/lib/format\";\n\n/**\n * A record list as a table: one row per record, one column per field the\n * model names, a link on the title column and an icon link to the record on\n * every row. The columns are the fields of whichever entity the records\n * belong to, so a table can list related records. `recordHref` and `viewLabel` come from the app, since the route\n * a record opens on and the words a record is named by are its business.\n */\nexport function RecordTable({\n  caption,\n  columns,\n  linkColumn,\n  records,\n  recordHref,\n  viewLabel,\n}: {\n  /** Names the table and the region it scrolls in for assistive technology; visually hidden. */\n  caption: string;\n  columns: readonly FieldModel[];\n  /** The column whose cell links to the record; no column links without it. */\n  linkColumn?: FieldModel;\n  records: readonly RecordView[];\n  recordHref: (record: RecordView) => string;\n  /** The name read for a row's link, beside the generic \"View record\". */\n  viewLabel: (record: RecordView) => string;\n}) {\n  const c = useBlockContent();\n  const locale = useLocale();\n  return (\n    <div className=\"table-wrap\" tabIndex={0} role=\"region\" aria-label={caption}>\n      <table>\n        <caption className=\"sr-only\">{caption}</caption>\n        <thead>\n          <tr>\n            {columns.map((field) => (\n              <th key={field.id}>{field.label}</th>\n            ))}\n            <th>\n              <span className=\"sr-only\">{c.actions}</span>\n            </th>\n          </tr>\n        </thead>\n        <tbody>\n          {records.map((record) => {\n            const href = recordHref(record);\n            return (\n              <tr key={record.id}>\n                {columns.map((field) => (\n                  <td key={field.id}>\n                    {field === linkColumn ? (\n                      <a className=\"record-link\" href={href}>\n                        {/* The cell is already a link; a reference inside it must not nest another. */}\n                        <ReferenceHrefProvider href={() => null}>\n                          <InPhrase>\n                            <FieldValue\n                              field={field}\n                              value={record.values[field.id]}\n                            />\n                          </InPhrase>\n                        </ReferenceHrefProvider>\n                      </a>\n                    ) : (\n                      <FieldValue\n                        field={field}\n                        value={record.values[field.id]}\n                      />\n                    )}\n                  </td>\n                ))}\n                <td>\n                  <a\n                    aria-label={fill(\n                      c.labelled,\n                      { label: c.viewRecord, value: viewLabel(record) },\n                      locale,\n                    )}\n                    className=\"icon-link\"\n                    href={href}\n                  >\n                    <ArrowUpRight size={18} />\n                  </a>\n                </td>\n              </tr>\n            );\n          })}\n        </tbody>\n      </table>\n    </div>\n  );\n}\n",
      "type": "registry:block",
      "target": "@components/record/record-table.tsx"
    }
  ],
  "type": "registry:block"
}