Dev Helpers
← Back

Month grid offset

Import and render <MonthGridOffset /> in a React project.

Open this example in the interactive library

Live preview

Source code

// components/MonthGridOffset.tsx

export default function MonthGridOffset({ day = "2028-02-29" }: { day?: string } = {}) {
  const d = new Date(day + "T00:00Z");
  d.setUTCDate(1);
  const start = (d.getUTCDay() + 6) % 7;
  const count = new Date(
    Date.UTC(d.getUTCFullYear(), d.getUTCMonth() + 1, 0),
  ).getUTCDate();
  return (
    <ol
      aria-label="Month, starting Monday"
      style={{
        display: "grid",
        gridTemplateColumns: "repeat(7,1fr)",
        listStyle: "none",
      }}
    >
      {Array.from({ length: count }, (_, i) => (
        <li key={i} style={i === 0 ? { gridColumnStart: start + 1 } : undefined}>
          {i + 1}
        </li>
      ))}
    </ol>
  );
}