# V calendar 12

> Date of Birth

A shadcn/ui block from the [@cnippet](https://ui.cnippet.dev/) registry, listed on [shadcn.exchange](https://shadcn.exchange/r/cnippet/v-calendar-12).

- Page, with a live preview: https://shadcn.exchange/r/cnippet/v-calendar-12
- Screenshot: https://abzjhwgwpdpz7ua5.public.blob.vercel-storage.com/shots/cnippet/v-calendar-12-light-1f08c881aa4471bf.png
- Registry item: https://ui.cnippet.dev/r/v-calendar-12.json
- Categories: calendar
- Listed: 2026-10-13, source last changed 2026-10-13

## Install

```bash
npx shadcn@latest add https://ui.cnippet.dev/r/v-calendar-12.json
```

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

## Dependencies

- Registry items: `@cnippet/calendar`

## Files

### `registry/default/variants/v-calendar-12.tsx`

```tsx
"use client";

import * as React from "react";
import type { DropdownProps } from "react-day-picker";
import { Calendar } from "@/registry/default/ui/calendar";
import {
  Select,
  SelectItem,
  SelectPopup,
  SelectTrigger,
  SelectValue,
} from "@/registry/default/ui/select";

function CalendarDropdown(props: DropdownProps) {
  const { options, value, onChange, "aria-label": ariaLabel } = props;

  const handleValueChange = (newValue: string | null) => {
    if (onChange && newValue) {
      const syntheticEvent = {
        target: { value: newValue },
      } as React.ChangeEvent<HTMLSelectElement>;
      onChange(syntheticEvent);
    }
  };

  const items =
    options?.map((option) => ({
      disabled: option.disabled,
      label: option.label,
      value: option.value.toString(),
    })) ?? [];

  return (
    <Select
      aria-label={ariaLabel}
      items={items}
      onValueChange={handleValueChange}
      value={value?.toString()}
    >
      <SelectTrigger className="min-w-none">
        <SelectValue />
      </SelectTrigger>
      <SelectPopup>
        {items.map((item) => (
          <SelectItem
            disabled={item.disabled}
            key={item.value}
            value={item.value}
          >
            {item.label}
          </SelectItem>
        ))}
      </SelectPopup>
    </Select>
  );
}

const today = new Date();
today.setHours(0, 0, 0, 0);

function calcAge(dob: Date): number {
  const diff = today.getTime() - dob.getTime();
  return Math.floor(diff / (365.25 * 24 * 60 * 60 * 1000));
}

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

  const age = date ? calcAge(date) : null;

  return (
    <div className="flex flex-col gap-3">
      <Calendar
        captionLayout="dropdown"
        components={{ Dropdown: CalendarDropdown }}
        defaultMonth={new Date(1990, 0)}
        disabled={{ after: today }}
        endMonth={today}
        mode="single"
        onSelect={setDate}
        selected={date}
        startMonth={new Date(1900, 0)}
      />
      <div className="rounded-lg border px-4 py-3 text-sm">
        {date && age !== null ? (
          <p>
            Date of birth:{" "}
            <span className="font-semibold">
              {date.toLocaleDateString("en-US", {
                day: "numeric",
                month: "long",
                year: "numeric",
              })}
            </span>
            <span className="ml-2 text-muted-foreground">
              ({age} years old)
            </span>
          </p>
        ) : (
          <p className="text-muted-foreground">Select your date of birth.</p>
        )}
      </div>
    </div>
  );
}
```
