Skip to content
2k
On This Page

Calendar

A calendar component that allows users to select a date or a range of dates.

November 2026

SunMonTueWedThuFriSat
1234567
891011121314
15161718192021
22232425262728
293012345
2026-11-17
import { createSignal } from "solid-js"

import { Calendar } from "~/components/ui/calendar"
export default function CalendarDemo() {
  const [value, setValue] = createSignal<string | null>("2026-11-17")
  return (
    <div class="grid gap-3">
      <Calendar
        value={value()}
        onValueChange={(v) => setValue(typeof v === "string" ? v : null)}
        defaultMonth="2026-11"
        today="2026-11-17"
        class="rounded-md border"
      />
      <output class="text-center text-sm">{value() ?? "Choose a day"}</output>
    </div>
  )
}

Installation

pnpm dlx solidui-cli@latest add calendar

Install the following dependencies:

pnpm add @ui-sdk/solid @ui-sdk/core

Copy and paste the following code into your project.

components/ui/calendar.tsx
// Inline SVG icons from Lucide (https://lucide.dev), ISC License, Copyright (c) Lucide Icons and Contributors.
import type { ComponentProps } from "@solidjs/web"
import {
  Calendar as SdkCalendar,
  CalendarPrevious as SdkCalendarPrevious,
  CalendarNext as SdkCalendarNext,
  CalendarHeading as SdkCalendarHeading,
  CalendarGrid as SdkCalendarGrid,
  CalendarWeekday as SdkCalendarWeekday,
  CalendarDay as SdkCalendarDay
} from "@ui-sdk/solid/calendar"
import {
  CalendarWeekdays as SdkCalendarWeekdays,
  CalendarWeeks as SdkCalendarWeeks
} from "@ui-sdk/solid/calendar"
import { omit } from "solid-js"
import { For } from "solid-js"

import { cn } from "~/lib/utils"

export function CalendarRoot(
  props: Omit<ComponentProps<typeof SdkCalendar>, "class"> & { class?: string }
) {
  return <SdkCalendar {...props} class={cn("p-2 [--cell-radius:var(--radius-md)] [--cell-size:--spacing(7)] w-fit", props.class)} />
}

export function CalendarPrevious(
  props: Omit<ComponentProps<typeof SdkCalendarPrevious>, "class"> & {
    class?: string
  }
) {
  return (
    <SdkCalendarPrevious
      {...props}
      class={cn(
        "inline-flex size-(--cell-size) items-center justify-center rounded-md hover:bg-muted disabled:opacity-50",
        props.class
      )}
    >
      {props.children ?? (
        <svg
          width="24"
          height="24"
          viewBox="0 0 24 24"
          fill="none"
          stroke="currentColor"
          stroke-width="2"
          stroke-linecap="round"
          stroke-linejoin="round"
          aria-hidden="true"
          class="size-4 rtl:rotate-180"
        >
          <path d="m15 18-6-6 6-6" />
        </svg>
      )}
    </SdkCalendarPrevious>
  )
}

export function CalendarNext(
  props: Omit<ComponentProps<typeof SdkCalendarNext>, "class"> & {
    class?: string
  }
) {
  return (
    <SdkCalendarNext
      {...props}
      class={cn(
        "inline-flex size-(--cell-size) items-center justify-center rounded-md hover:bg-muted disabled:opacity-50",
        props.class
      )}
    >
      {props.children ?? (
        <svg
          width="24"
          height="24"
          viewBox="0 0 24 24"
          fill="none"
          stroke="currentColor"
          stroke-width="2"
          stroke-linecap="round"
          stroke-linejoin="round"
          aria-hidden="true"
          class="size-4 rtl:rotate-180"
        >
          <path d="m9 18 6-6-6-6" />
        </svg>
      )}
    </SdkCalendarNext>
  )
}

export function CalendarHeading(
  props: Omit<ComponentProps<typeof SdkCalendarHeading>, "class"> & {
    class?: string
  }
) {
  return (
    <SdkCalendarHeading
      {...props}
      class={cn(
        "h-6 pr-1 pl-1.5 flex-1 text-center text-sm font-medium",
        props.class
      )}
    />
  )
}

export function CalendarGrid(
  props: Omit<ComponentProps<typeof SdkCalendarGrid>, "class"> & {
    class?: string
  }
) {
  return (
    <SdkCalendarGrid
      {...props}
      class={cn("w-full border-collapse", props.class)}
    />
  )
}

export function CalendarWeekday(
  props: Omit<ComponentProps<typeof SdkCalendarWeekday>, "class"> & {
    class?: string
  }
) {
  return (
    <SdkCalendarWeekday
      {...props}
      class={cn(
        "text-xs h-(--cell-size) font-normal text-muted-foreground",
        props.class
      )}
    />
  )
}

export function CalendarDayButton(
  props: Omit<ComponentProps<typeof SdkCalendarDay>, "class"> & {
    class?: string
  }
) {
  return (
    <SdkCalendarDay
      {...props}
      class={cn(
        "size-(--cell-size) rounded-(--cell-radius) text-center text-sm outline-none hover:bg-accent focus-visible:ring-2 focus-visible:ring-ring data-outside:text-muted-foreground data-range-middle:rounded-none data-today:font-bold data-[selected]:bg-primary data-[selected]:text-primary-foreground data-disabled:opacity-40",
        props.class
      )}
    />
  )
}

export function CalendarMonth(props: { offset?: number }) {
  return (
    <CalendarGrid offset={props.offset ?? 0}>
      <SdkCalendarWeekdays>
        {(index) => <CalendarWeekday index={index} />}
      </SdkCalendarWeekdays>
      <SdkCalendarWeeks>
        {(cell) => <CalendarDayButton value={cell.date} />}
      </SdkCalendarWeeks>
    </CalendarGrid>
  )
}

export function Calendar(props: ComponentProps<typeof CalendarRoot>) {
  const rest = omit(props, "children")
  return (
    <CalendarRoot {...rest}>
      {props.children ?? (
        <>
          <div class="flex items-center">
            <CalendarPrevious />
            <CalendarHeading />
            <CalendarNext />
          </div>
          <div class="flex gap-4">
            <For each={Array.from({ length: props.months ?? 1 }, (_, i) => i)}>
              {(offset) => <CalendarMonth offset={offset} />}
            </For>
          </div>
        </>
      )}
    </CalendarRoot>
  )
}

Update the import paths to match your project setup.

Usage

import { Calendar } from "~/components/ui/calendar"
<Calendar aria-label="Select a date" />

Dates use ISO strings, such as "2026-11-17". Set mode to single, multiple, or range. onValueChange receives the ISO value. Use months for multiple grids and min, max, or unavailable for restrictions. The SDK renders focusable table cells, so days do not contain extra buttons.

See the UI SDK calendar API for native options and keyboard behavior.

About

The Calendar component styles the grid, day cells, and navigation from UI SDK Calendar.

Date Picker

You can use the <Calendar> component to build a date picker. See the Date Picker page for more information.

Persian / Hijri / Jalali Calendar

The upstream example uses a Persian calendar with right-to-left layout.

Selected Date (With TimeZone)

The Calendar component accepts a timeZone prop to ensure dates are displayed and selected in the userโ€™s local timezone.

Note: If you notice a selected date offset (for example, selecting the 20th highlights the 19th), make sure the timeZone prop is set to the userโ€™s local timezone.

The SDK uses timeZone to determine today. Without it, the SDK reads the browser time zone after hydration.

Basic

A basic calendar styled with class="rounded-lg border".

November 2026

SunMonTueWedThuFriSat
1234567
891011121314
15161718192021
22232425262728
293012345
import { Calendar } from "~/components/ui/calendar"

export default function CalendarBasic() {
  return <Calendar aria-label="Select a date" class="rounded-lg border" />
}

Range Calendar

Use the mode="range" prop to enable range selection.

November โ€“ December 2026

SunMonTueWedThuFriSat
1234567
891011121314
15161718192021
22232425262728
2930
SunMonTueWedThuFriSat
12345
6789101112
13141516171819
20212223242526
272829303112
import { Calendar } from "~/components/ui/calendar"
export default function CalendarRange() {
  return (
    <Calendar
      mode="range"
      defaultValue={["2026-11-17", "2026-11-22"]}
      defaultMonth="2026-11"
      today="2026-11-17"
      months={2}
      class="max-w-full overflow-auto rounded-md border"
    />
  )
}

Month and Year Selector

Use month and year dropdowns to change the calendarโ€™s visible month.

SunMonTueWedThuFriSat
1234567
891011121314
15161718192021
22232425262728
293012345
import { createSignal, For } from "solid-js"

import {
  Calendar,
  CalendarMonth,
  CalendarNext,
  CalendarPrevious
} from "~/components/ui/calendar"

const months = Array.from({ length: 12 }, (_, index) => ({
  value: String(index + 1).padStart(2, "0"),
  label: new Intl.DateTimeFormat("en", {
    month: "long",
    timeZone: "UTC"
  }).format(new Date(Date.UTC(2026, index, 1)))
}))
const years = Array.from({ length: 11 }, (_, index) => String(2021 + index))

export default function CalendarCaption() {
  const [month, setMonth] = createSignal("2026-11")
  return (
    <Calendar
      aria-label="Choose date"
      month={month()}
      onMonthChange={setMonth}
      class="rounded-lg border"
    >
      <div class="flex items-center justify-between gap-1">
        <CalendarPrevious />
        <select
          aria-label="Month"
          value={month().slice(5)}
          onChange={(event) =>
            setMonth(`${month().slice(0, 4)}-${event.currentTarget.value}`)
          }
        >
          <For each={months}>
            {(option) => <option value={option.value}>{option.label}</option>}
          </For>
        </select>
        <select
          aria-label="Year"
          value={month().slice(0, 4)}
          onChange={(event) =>
            setMonth(`${event.currentTarget.value}-${month().slice(5)}`)
          }
        >
          <For each={years}>
            {(year) => <option value={year}>{year}</option>}
          </For>
        </select>
        <CalendarNext />
      </div>
      <CalendarMonth />
    </Calendar>
  )
}

Presets

November 2026

SunMonTueWedThuFriSat
1234567
891011121314
15161718192021
22232425262728
293012345
import { createSignal, For } from "solid-js"

import { Button } from "~/components/ui/button"
import { Calendar } from "~/components/ui/calendar"

const presets = [
  { label: "Today", days: 0 },
  { label: "Tomorrow", days: 1 },
  { label: "In 3 days", days: 3 },
  { label: "In a week", days: 7 },
  { label: "In 2 weeks", days: 14 }
]
const today = "2026-11-18"

export default function CalendarPresets() {
  const [value, setValue] = createSignal<string | null>(today)
  const [month, setMonth] = createSignal(today.slice(0, 7))
  const choose = (days: number) => {
    const date = new Date(today)
    date.setUTCDate(date.getUTCDate() + days)
    const next = date.toISOString().slice(0, 10)
    setValue(next)
    setMonth(next.slice(0, 7))
  }

  return (
    <div class="flex flex-col items-stretch gap-2 rounded-lg border p-2">
      <Calendar
        aria-label="Choose date"
        value={value()}
        month={month()}
        onMonthChange={setMonth}
        onValueChange={(next) =>
          setValue(typeof next === "string" ? next : null)
        }
      />
      <div class="flex max-w-72 flex-wrap gap-1">
        <For each={presets}>
          {(preset) => (
            <Button
              variant="outline"
              size="sm"
              onClick={() => choose(preset.days)}
            >
              {preset.label}
            </Button>
          )}
        </For>
      </div>
    </div>
  )
}

Date and Time Picker

November 2026

SunMonTueWedThuFriSat
1234567
891011121314
15161718192021
22232425262728
293012345
// Inline SVG icons from Lucide (https://lucide.dev), ISC License, Copyright (c) Lucide Icons and Contributors.

import { Calendar } from "~/components/ui/calendar"
import { Field, FieldGroup, FieldLabel } from "~/components/ui/field"
import {
  InputGroup,
  InputGroupAddon,
  InputGroupInput
} from "~/components/ui/input-group"

export default function CalendarTime() {
  return (
    <div class="grid max-w-64 gap-3 rounded-lg border p-3">
      <Calendar
        aria-label="Appointment date"
        defaultValue="2026-11-18"
        defaultMonth="2026-11"
      />
      <FieldGroup>
        <Field>
          <FieldLabel for="time-from">Start Time</FieldLabel>
          <InputGroup>
            <InputGroupInput id="time-from" type="time" value="10:30" />
            <InputGroupAddon>
              <svg
                width="24"
                height="24"
                viewBox="0 0 24 24"
                fill="none"
                stroke="currentColor"
                stroke-width="2"
                stroke-linecap="round"
                stroke-linejoin="round"
                aria-hidden="true"
              >
                <circle cx="12" cy="12" r="10" />
                <path d="M12 6v6l4 2" />
              </svg>
            </InputGroupAddon>
          </InputGroup>
        </Field>
        <Field>
          <FieldLabel for="time-to">End Time</FieldLabel>
          <InputGroup>
            <InputGroupInput id="time-to" type="time" value="12:30" />
            <InputGroupAddon>
              <svg
                width="24"
                height="24"
                viewBox="0 0 24 24"
                fill="none"
                stroke="currentColor"
                stroke-width="2"
                stroke-linecap="round"
                stroke-linejoin="round"
                aria-hidden="true"
              >
                <circle cx="12" cy="12" r="10" />
                <path d="M12 6v6l4 2" />
              </svg>
            </InputGroupAddon>
          </InputGroup>
        </Field>
      </FieldGroup>
    </div>
  )
}

Booked dates

November 2026

SunMonTueWedThuFriSat
1234567
891011121314
15161718192021
22232425262728
293012345

Booked dates are unavailable.

import { Calendar } from "~/components/ui/calendar"

const booked = ["2026-11-07", "2026-11-15", "2026-11-21", "2026-11-28"]

export default function CalendarBookedDates() {
  return (
    <div class="grid gap-2">
      <Calendar
        aria-label="Book an appointment"
        unavailable={booked}
        defaultMonth="2026-11"
        class="rounded-lg border"
      />
      <p class="text-center text-xs text-muted-foreground">
        Booked dates are unavailable.
      </p>
    </div>
  )
}

Custom Cell Size

November 2026

SunMonTueWedThuFriSat
1234567
891011121314
15161718192021
22232425262728
293012345
import {
  CalendarWeeks as SdkCalendarWeeks,
  CalendarWeekdays as SdkCalendarWeekdays
} from "@ui-sdk/solid/calendar"

import {
  Calendar,
  CalendarDayButton,
  CalendarGrid,
  CalendarHeading,
  CalendarNext,
  CalendarPrevious,
  CalendarWeekday
} from "~/components/ui/calendar"

function isWeekend(date: string) {
  return [0, 6].includes(new Date(date).getUTCDay())
}

export default function CalendarCustomDays() {
  return (
    <Calendar
      mode="range"
      defaultValue={["2026-11-15", "2026-11-22"]}
      defaultMonth="2026-11"
      class="rounded-lg border"
    >
      <div class="flex items-center">
        <CalendarPrevious />
        <CalendarHeading />
        <CalendarNext />
      </div>
      <CalendarGrid>
        <SdkCalendarWeekdays>
          {(index) => <CalendarWeekday index={index} />}
        </SdkCalendarWeekdays>
        <SdkCalendarWeeks>
          {(cell) => (
            <CalendarDayButton
              value={cell.date}
              class={isWeekend(cell.date) ? "text-destructive" : ""}
            />
          )}
        </SdkCalendarWeeks>
      </CalendarGrid>
    </Calendar>
  )
}

Set --cell-size to a fixed value or use responsive utilities such as [--cell-size:2rem] sm:[--cell-size:2.5rem].

Week Numbers

Add a column to the calendar grid to display ISO week numbers.

February 2026

Week numberMonTueWedThuFriSatSun
52627282930311
62345678
79101112131415
816171819202122
92324252627281
import { For, Show } from "solid-js"

import {
  Calendar,
  CalendarDayButton,
  CalendarGrid,
  CalendarHeading,
  CalendarNext,
  CalendarPrevious,
  CalendarWeekday
} from "~/components/ui/calendar"
import { Card, CardContent } from "~/components/ui/card"

function weekNumber(date: string | undefined) {
  if (!date) return
  const thursday = new Date(date)
  thursday.setUTCDate(thursday.getUTCDate() + 4 - (thursday.getUTCDay() || 7))
  const newYear = Date.UTC(thursday.getUTCFullYear(), 0, 1)
  return Math.ceil((thursday.getTime() - newYear + 86_400_000) / 604_800_000)
}

export default function CalendarWeekNumbers() {
  return (
    <Card class="mx-auto w-fit p-0">
      <CardContent class="p-0">
        <Calendar
          defaultMonth="2026-02"
          defaultValue="2026-02-03"
          weekStartsOn={1}
        >
          <div class="flex items-center">
            <CalendarPrevious />
            <CalendarHeading />
            <CalendarNext />
          </div>
          <CalendarGrid>
            {(grid) => (
              <>
                <thead>
                  <tr>
                    <th scope="col" class="w-(--cell-size)">
                      <span class="sr-only">Week number</span>
                    </th>
                    <For each={grid.weekdays} keyed={false}>
                      {(_, index) => <CalendarWeekday index={index} />}
                    </For>
                  </tr>
                </thead>
                <tbody>
                  <For each={grid.weeks} keyed={(week) => week[0]?.date}>
                    {(week) => (
                      <tr>
                        <th
                          scope="row"
                          class="text-xs font-normal text-muted-foreground"
                        >
                          {weekNumber(week()[0]?.date)}
                        </th>
                        <For each={week()} keyed={(day) => day.date}>
                          {(day) => (
                            <Show when={!day().hidden} fallback={<td />}>
                              <CalendarDayButton value={day().date} />
                            </Show>
                          )}
                        </For>
                      </tr>
                    )}
                  </For>
                </tbody>
              </>
            )}
          </CalendarGrid>
        </Calendar>
      </CardContent>
    </Card>
  )
}

API Reference

See the UI SDK Calendar API for supported options and slot states.

Changelog