# P calendar 24

> Pricing calendar with custom day buttons

A shadcn/ui block from the [@coss](https://coss.com/ui) registry, listed on [shadcn.exchange](https://shadcn.exchange/r/coss/p-calendar-24).

- Page, with a live preview: https://shadcn.exchange/r/coss/p-calendar-24
- Screenshot: https://abzjhwgwpdpz7ua5.public.blob.vercel-storage.com/shots/coss/p-calendar-24-light-fe127e9b4ffb3880.png
- Registry item: https://coss.com/ui/r/p-calendar-24.json
- Categories: calendar
- Listed: 2026-10-13, source last changed 2026-10-13

## Install

```bash
npx shadcn@latest add https://coss.com/ui/r/p-calendar-24.json
```

Run it in a project that has shadcn/ui set up. It adds the files below and installs what they depend on.

## Dependencies

- npm packages: `date-fns`
- Registry items: `@coss/calendar`

## Files

### `registry/default/particles/p-calendar-24.tsx`

```tsx
"use client";

import type { DayButtonProps } from "@daypicker/react";
import { format } from "date-fns";
import { useEffect, useState } from "react";
import { cn } from "@/registry/default/lib/utils";
import { Calendar } from "@/registry/default/ui/calendar";

const GOOD_PRICE_THRESHOLD = 100;

export default function Particle() {
  const today = new Date();
  const [date, setDate] = useState<Date | undefined>(today);

  const [mockPriceData, setMockPriceData] = useState<Record<string, number>>(
    {},
  );
  useEffect(() => {
    const generateMockPriceData = () => {
      const data: Record<string, number> = {};
      const todayDate = new Date();

      for (let i = 0; i < 180; i++) {
        const date = new Date(todayDate);
        date.setDate(todayDate.getDate() + i);
        const dateKey = format(date, "yyyy-MM-dd");
        const randomPrice = Math.floor(Math.random() * (200 - 80 + 1)) + 80;
        data[dateKey] = randomPrice;
      }
      return data;
    };
    setMockPriceData(generateMockPriceData());
  }, []);

  const isDateDisabled = (date: Date) => {
    return !mockPriceData[format(date, "yyyy-MM-dd")];
  };

  return (
    <Calendar
      classNames={{
        day_button: "size-12",
        month:
          "relative first-of-type:before:hidden before:absolute max-md:before:inset-x-2 max-md:before:h-px max-md:before:-top-4 md:before:inset-y-2 md:before:w-px before:bg-border md:before:-left-4",
        months: "sm:flex-col md:flex-row gap-8",
        today: "*:after:hidden",
        weekday: "w-12",
      }}
      components={{
        DayButton: (props: DayButtonProps) => (
          <DayButton {...props} prices={mockPriceData} />
        ),
      }}
      disabled={isDateDisabled}
      mode="single"
      numberOfMonths={2}
      onSelect={setDate}
      pagedNavigation
      selected={date}
      showOutsideDays={false}
    />
  );
}

function DayButton(props: DayButtonProps & { prices: Record<string, number> }) {
  const { day, prices, modifiers: _modifiers, ...buttonProps } = props;
  const price = prices[format(day.date, "yyyy-MM-dd")];
  const isGoodPrice = price !== undefined && price < GOOD_PRICE_THRESHOLD;

  return (
    <button {...buttonProps}>
      <span className="flex flex-col">
        {props.children}
        {price && (
          <span
            className={cn(
              "font-normal text-xs",
              isGoodPrice
                ? "text-emerald-500"
                : "in-data-selected:text-primary-foreground/70 text-muted-foreground",
            )}
          >
            ${price}
          </span>
        )}
      </span>
    </button>
  );
}
```
