import * as z from "zod"; const DEFAULT_TABLE_COLUMNS = ["Feature", "Column 1", "Column 2", "Column 3"]; const DEFAULT_ROWS = [ { cells: ["Component-based", "check", "check", "check"] }, { cells: ["TypeScript Support", "check", "check", "check"] }, { cells: ["Learning Curve", "Medium", "Easy", "Steep"] }, { cells: ["Bundle Size", "40KB", "34KB", "167KB"] }, { cells: ["Performance", "Excellent", "Excellent", "Good"] }, { cells: ["Community Size", "Huge", "Large", "Large"] }, ]; const ComparisonRowSchema = z.object({ cells: z.array(z.string().max(24)).min(1).max(6).meta({ description: "Cell values for this row in left-to-right order. Match the number of table columns.", }), }); export const slideLayoutId = "table-slide"; export const slideLayoutName = "Table Slide"; export const slideLayoutDescription = "A slide with title and a table."; export const Schema = z.object({ title: z.string().min(6).max(18).default("Comparison").meta({ description: "Slide title shown above the table.", }), tableColumns: z.array(z.string().max(18)).min(1).max(6).meta({ description: "Table columns shown in the first row.", }).default(DEFAULT_TABLE_COLUMNS), rows: z .array(ComparisonRowSchema) .min(1) .max(6) .default(DEFAULT_ROWS) .meta({ description: "Table rows where each row contains a cells array matching the table columns.", }), }).superRefine((value, ctx) => { value.rows.forEach((row, rowIndex) => { if (row.cells.length !== value.tableColumns.length) { ctx.addIssue({ code: z.ZodIssueCode.custom, path: ["rows", rowIndex, "cells"], message: "Each row must contain the same number of cells as tableColumns.", }); } }); }); export type SchemaType = z.infer; function getGridTemplateColumns(columnCount: number) { if (columnCount <= 1) { return "minmax(0, 1fr)"; } return `minmax(0, 1.4fr) repeat(${columnCount - 1}, minmax(0, 1fr))`; } function renderCell(value: string, isFirstColumn: boolean) { if (!isFirstColumn && value && value.toLowerCase() === "check") { return ; } return ( {value} ); } const CodeSlide05ComparisonTable = ({ data }: { data: Partial }) => { const tableColumns = data.tableColumns?.length ? data.tableColumns : DEFAULT_TABLE_COLUMNS; const rows = data.rows?.length ? data.rows : DEFAULT_ROWS; const gridTemplateColumns = getGridTemplateColumns(tableColumns.length); return ( <>

{data.title}

{tableColumns.map((column, columnIndex) => (

{column}

))}
{rows.map((row, rowIndex) => (
{row.cells.map((cell, cellIndex) => (
{renderCell(cell, cellIndex === 0)}
))}
))}
); }; export default CodeSlide05ComparisonTable;