Comparator Table
A tiered feature-comparison table — plan columns with CTAs over grouped feature rows whose cells are checkmarks or text values.
import type { Block } from 'payload'import { comparatorFields } from '@/blocks/shared/comparatorFields'import { linkGroup } from '@/fields/linkGroup'export const ComparatorTable: Block = { slug: 'comparatorTable', interfaceName: 'ComparatorTableBlock', fields: [ // Shared comparator header (title, description). Variant-specific fields // follow; edit the shared shape in @/blocks/shared/comparatorFields. ...comparatorFields, { name: 'plans', type: 'array', required: true, minRows: 2, maxRows: 4, admin: { initCollapsed: true, }, fields: [ { name: 'name', type: 'text', required: true, }, { name: 'badge', type: 'text', admin: { description: 'Optional pill above the plan name, e.g. "Most popular".', }, }, { name: 'highlighted', type: 'checkbox', admin: { description: 'Tints this column to draw the eye to the recommended plan.', }, }, linkGroup({ overrides: { maxRows: 1, }, }), ], }, { name: 'features', type: 'array', required: true, minRows: 1, admin: { initCollapsed: true, }, fields: [ { name: 'groupLabel', type: 'text', admin: { description: 'Optional section heading rendered as a divider row above this feature.', }, }, { name: 'feature', type: 'text', required: true, }, { name: 'values', type: 'array', admin: { description: 'One cell per plan, in the same order as Plans. Tick "included" for a checkmark, or set a label for a text value.', }, fields: [ { name: 'included', type: 'checkbox', }, { name: 'label', type: 'text', }, ], }, ], }, ], labels: { plural: 'Comparator Table Blocks', singular: 'Comparator Table', },}import React from 'react'import { Check } from 'lucide-react'import type { ComparatorTableBlock as ComparatorTableBlockData } from '@/payload-types'import { CMSLink } from '@/components/Link'import { Badge } from '@/components/ui/badge'import { cn } from '@/utilities/ui'type Props = ComparatorTableBlockData & { id?: string className?: string disableInnerContainer?: boolean}export const ComparatorTableBlock: React.FC<Props> = ({ className, description, disableInnerContainer, features, id, plans, title,}) => { const planCount = plans?.length ?? 0 return ( <section className={cn('container', className)} id={id ? `block-${id}` : undefined}> <div className="overflow-hidden rounded-frame border border-border/70 bg-card/35 px-6 py-10 sm:px-8 lg:px-12 lg:py-14"> <div className={cn('flex flex-col gap-10', { 'mx-auto max-w-5xl': !disableInnerContainer, })} > {title || description ? ( <div className="flex max-w-2xl flex-col gap-4"> {title ? ( <h2 className="text-4xl font-medium tracking-display text-balance sm:text-5xl">{title}</h2> ) : null} {description ? ( <p className="text-base leading-7 text-muted-foreground sm:text-lg">{description}</p> ) : null} </div> ) : null} {plans && plans.length > 0 ? ( <div className="overflow-x-auto"> <table className="w-full border-collapse text-left text-sm"> <thead> <tr> <th className="w-2/5 p-4 align-bottom" /> {plans.map((plan, planIndex) => ( <th key={plan.id ?? planIndex} scope="col" className={cn('min-w-40 p-4 align-bottom', { 'bg-primary/5': plan.highlighted, })} > <div className="flex flex-col gap-3"> <div className="flex flex-wrap items-center gap-2"> <span className="text-base font-medium text-foreground">{plan.name}</span> {plan.badge ? ( <Badge variant="outline" className="rounded-full px-2 py-0.5 text-xs uppercase tracking-eyebrow" > {plan.badge} </Badge> ) : null} </div> {plan.links && plan.links.length > 0 ? ( <div className="flex flex-col gap-2"> {plan.links.map(({ link }, linkIndex) => ( <CMSLink key={linkIndex} appearance={link.appearance === 'outline' ? 'outline' : 'default'} {...link} /> ))} </div> ) : null} </div> </th> ))} </tr> </thead> <tbody> {features?.map((row, rowIndex) => ( <React.Fragment key={row.id ?? rowIndex}> {row.groupLabel ? ( <tr> <td className="px-4 pb-2 pt-8 text-xs font-medium uppercase tracking-eyebrow text-muted-foreground" colSpan={planCount + 1} > {row.groupLabel} </td> </tr> ) : null} <tr className="border-t border-border/70"> <td className="p-4 text-muted-foreground">{row.feature}</td> {plans.map((plan, planIndex) => { const cell = row.values?.[planIndex] return ( <td key={plan.id ?? planIndex} className={cn('p-4 text-foreground', { 'bg-primary/5': plan.highlighted, })} > {cell?.included ? ( <Check aria-label="Included" className="size-4 text-primary" role="img" /> ) : cell?.label ? ( <span>{cell.label}</span> ) : ( <span className="text-muted-foreground">—</span> )} </td> ) })} </tr> </React.Fragment> ))} </tbody> </table> </div> ) : null} </div> </div> </section> )}import type { Field } from 'payload'/** * Shared field core for the Comparator component family. * * Every comparator variant (comparator-table, comparator-grid, comparator-stack) * spreads this optional section header first and then appends its own plan/feature * shape — the feature matrix for the table and grid layouts, or the per-plan * checklists for the stacked layout. Editing the shared title/description here * updates every installed comparator block at once, so the family never drifts * field-by-field across a repo. * * Installed once per repo at `src/blocks/shared/comparatorFields.ts`; re-running * `payload-components add comparator-*` never overwrites a copy you have already edited. */export const comparatorFields: Field[] = [ { name: 'title', type: 'text', }, { name: 'description', type: 'textarea', },]Installation
npx payload-components add comparator-tableCopy the files straight from the registry, then wire the Payload fragments by hand:
pnpm dlx shadcn@latest add https://www.payload-components.xyz/r/comparator-table.jsonWhat it installs
Copies 3 source files into your project:
src/blocks/shared/comparatorFields.tssharedsrc/blocks/ComparatorTable/config.tssrc/blocks/ComparatorTable/Component.tsx
…and makes 4 edits to wire the block into your project:
| Registers the block | src/collections/Pages/index.ts |
| Maps the renderer | src/blocks/RenderBlocks.tsx |
| Regenerates types | src/payload-types.ts |
| Regenerates the admin import map | src/app/(payload)/admin/importMap.js |
comparatorFields.ts is the shared field core for this family — every variant composes it. Editing it updates each installed block at once, and re-running an install never overwrites a copy you have changed.Re-running the install converges: it detects existing wiring, skips it, and records install state in .payload-components/state.json.
Content model
title and description come from the shared Comparator family base
(src/blocks/shared/comparatorFields.ts); the plans columns and the features matrix are
specific to this variant. Each feature row holds one values cell per plan, in the same order as
plans — keep the two aligned.
Prop
Type
Each item in plans carries:
Prop
Type
Each item in features carries:
Prop
Type
Usage
ComparatorTable block to its layout.RenderBlocks on the frontend, fully typed — no extra wiring.Requirements
- Target
- payload-website-starter
- Payload
- v3
- Next.js
- 15 / 16
- shadcn UI
- badge
Your project must already expose components.json, src/payload.config.ts, src/blocks/RenderBlocks.tsx, src/collections/Pages/index.ts — the surfaces payload-components add patches. The CLI verifies this against the support matrix before touching anything.
In this family
comparator-tablecurrentcomparator-gridcomparator-stack