All files / components CaseStudy.tsx

100% Statements 9/9
100% Branches 12/12
100% Functions 8/8
100% Lines 9/9

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81      7x             4x     7x 7x             5x                 5x                         5x                       5x 13x                                                
import type { CaseStudyBlock } from "@/content/types";
 
function slugify(text: string): string {
  return text
    .toLowerCase()
    .replace(/[^a-z0-9]+/g, "-")
    .replace(/(^-|-$)/g, "");
}
 
export function CaseStudy({ blocks }: { blocks: readonly CaseStudyBlock[] }) {
  return (
    <div className="flex flex-col gap-14">
      {blocks.map((block) => {
        const id = slugify(block.heading);
        return (
          <section key={block.heading} aria-labelledby={id} className="prose-measure">
            <h2 id={id} className="display mb-4 text-4xl">
              {block.heading}
            </h2>
            {block.type === "text" &&
              block.body.map((paragraph) => (
                <p key={paragraph.slice(0, 32)} className="mb-4 last:mb-0">
                  {paragraph}
                </p>
              ))}
            {block.type === "list" && (
              <>
                {block.intro && <p className="mb-4">{block.intro}</p>}
                <ul className="flex list-disc flex-col gap-2 pl-5 marker:text-spruce">
                  {block.items.map((item) => (
                    <li key={item}>{item}</li>
                  ))}
                </ul>
              </>
            )}
            {block.type === "table" && (
              <>
                {block.intro && <p className="mb-4">{block.intro}</p>}
                <div className="overflow-x-auto">
                  <table className="w-full border-collapse text-left text-[0.95rem]">
                    <thead>
                      <tr>
                        {block.columns.map((col) => (
                          <th
                            key={col}
                            scope="col"
                            className="border-b-2 border-ink py-2 pr-4 font-semibold"
                          >
                            {col}
                          </th>
                        ))}
                      </tr>
                    </thead>
                    <tbody>
                      {block.rows.map((row) => (
                        <tr key={row[0]} className="border-b border-line">
                          {row.map((cell, i) =>
                            i === 0 ? (
                              <th key={cell} scope="row" className="py-2 pr-4 font-semibold">
                                {cell}
                              </th>
                            ) : (
                              <td key={cell} className="py-2 pr-4 text-muted">
                                {cell}
                              </td>
                            ),
                          )}
                        </tr>
                      ))}
                    </tbody>
                  </table>
                </div>
              </>
            )}
          </section>
        );
      })}
    </div>
  );
}