125k

Calendar

日付または日付範囲を選択できるカレンダー コンポーネント。

September 2026
"use client"

import * as React from "react"

インストール

pnpm dlx shadcn@latest add calendar

使用法

import { Calendar } from "@/components/ui/calendar"
const [date, setDate] = React.useState<Date | undefined>(new Date())
 
return (
  <Calendar
    mode="single"
    selected={date}
    onSelect={setDate}
    className="rounded-lg border"
  />
)

詳細については、React DayPicker ドキュメントを参照してください。

概要

Calendar コンポーネントは、React DayPicker の上に構築されています。

日付ピッカー

<Calendar> コンポーネントを使用して日付ピッカーを構築できます。詳細については、日付ピッカー ページを参照してください。

ペルシア語/ヒジュラ語/ジャラリ語カレンダー

ペルシャ暦を使用するには、components/ui/calendar.tsx を編集し、react-day-picker を react-day-picker/persian に置き換えます。

- import { DayPicker } from "react-day-picker"
+ import { DayPicker } from "react-day-picker/persian"
خرداد ۱۴۰۴
"use client"

import * as React from "react"

選択された日付 (タイムゾーンあり)

Calendar コンポーネントは timeZone プロパティを受け入れ、ユーザーのローカル タイムゾーンで日付が表示および選択されるようにします。

export function CalendarWithTimezone() {
  const [date, setDate] = React.useState<Date | undefined>(undefined)
  const [timeZone, setTimeZone] = React.useState<string | undefined>(undefined)
 
  React.useEffect(() => {
    setTimeZone(Intl.DateTimeFormat().resolvedOptions().timeZone)
  }, [])
 
  return (
    <Calendar
      mode="single"
      selected={date}
      onSelect={setDate}
      timeZone={timeZone}
    />
  )
}

注意: 選択した日付のオフセットに気付いた場合 (たとえば、20 日を選択すると 19 日が強調表示されます)、timeZone プロパティがユーザーのローカル タイムゾーンに設定されていることを確認してください。

クライアント側で行う理由 サーバー側レンダリングとの互換性を確保するために、useEffect 内の Intl.DateTimeFormat().resolvedOptions().timeZone を使用してタイムゾーンが検出されます。サーバーとクライアントのタイムゾーンが異なる可能性があるため、レンダリング中にタイムゾーンを検出するとハイドレーションの不一致が発生します。

基本

基本的なカレンダー コンポーネント。カレンダーのスタイルには className="rounded-lg border" を使用しました。

September 2026
"use client"

import { Calendar } from "@/components/ui/radix/calendar"

範囲カレンダー

mode="range" プロパティを使用して範囲選択を有効にします。

January 2026
February 2026
"use client"

import * as React from "react"

月と年のセレクター

月と年のドロップダウンを表示するには、captionLayout="dropdown" を使用します。

September 2026
"use client"

import { Calendar } from "@/components/ui/radix/calendar"

プリセット

September 2026
"use client"

import * as React from "react"

日付と時刻のピッカー

September 2026
"use client"

import * as React from "react"

予約済みの日付

February 2026
"use client"

import * as React from "react"

カスタムセルサイズ

December 2026
"use client"

import * as React from "react"

CSS 変数 --cell-size を使用して、カレンダーのセルのサイズをカスタマイズできます。ブレークポイント固有の値を使用して応答性を高めることもできます。

<Calendar
  mode="single"
  selected={date}
  onSelect={setDate}
  className="rounded-lg border [--cell-size:--spacing(11)] md:[--cell-size:--spacing(12)]"
/>

または、固定値を使用します。

<Calendar
  mode="single"
  selected={date}
  onSelect={setDate}
  className="rounded-lg border [--cell-size:2.75rem] md:[--cell-size:3rem]"
/>

週番号

週番号を表示するには showWeekNumber を使用します。

February 2026
06
07
08
09
"use client"

import * as React from "react"

RTL

shadcn/ui で RTL サポートを有効にするには、RTL 構成ガイド を参照してください。

ペルシア語/ヒジュラ語/ジャラリ語カレンダーを有効にする方法については、ヒジュラ語ガイドも参照してください。

سبتمبر 2026
"use client"

import * as React from "react"

RTL を使用する場合は、react-day-picker/locale からロケールをインポートし、locale と dir の両方のプロパティを Calendar コンポーネントに渡します。

import { arSA } from "react-day-picker/locale"
 
;<Calendar
  mode="single"
  selected={date}
  onSelect={setDate}
  locale={arSA}
  dir="rtl"
/>

API リファレンス

Calendar コンポーネントの詳細については、React DayPicker ドキュメントを参照してください。

変更履歴

RTL サポート

Calendar コンポーネントの以前のバージョンからアップグレードする場合は、ロケールサポートを追加するために次の更新を適用する必要があります。

Locale 型をインポートします。

react-day-picker からのインポートに Locale を追加します。

  import {
    DayPicker,
    getDefaultClassNames,
    type DayButton,
+   type Locale,
  } from "react-day-picker"

locale プロパティを Calendar コンポーネントに追加します。

locale プロパティをコンポーネントのプロパティに追加します。

  function Calendar({
    className,
    classNames,
    showOutsideDays = true,
    captionLayout = "label",
    buttonVariant = "ghost",
+   locale,
    formatters,
    components,
    ...props
  }: React.ComponentProps<typeof DayPicker> & {
    buttonVariant?: React.ComponentProps<typeof Button>["variant"]
  }) {

locale を DayPicker に渡します。

locale プロパティを DayPicker コンポーネントに渡します。

    <DayPicker
      showOutsideDays={showOutsideDays}
      className={cn(...)}
      captionLayout={captionLayout}
+     locale={locale}
      formatters={{
        formatMonthDropdown: (date) =>
-         date.toLocaleString("default", { month: "short" }),
+         date.toLocaleString(locale?.code, { month: "short" }),
        ...formatters,
      }}

ロケールを受け入れるように CalendarDayButton を更新します。

CalendarDayButton コンポーネントのシグネチャを更新し、locale を渡します。

  function CalendarDayButton({
    className,
    day,
    modifiers,
+   locale,
    ...props
- }: React.ComponentProps<typeof DayButton>) {
+ }: React.ComponentProps<typeof DayButton> & { locale?: Partial<Locale> }) {

CalendarDayButton の日付書式を更新します。

日付書式設定で locale?.code を使用します。

    <Button
      variant="ghost"
      size="icon"
-     data-day={day.date.toLocaleDateString()}
+     data-day={day.date.toLocaleDateString(locale?.code)}
      ...
    />

ロケールを DayButton コンポーネントに渡します。

DayButton コンポーネントの使用法を更新して、locale prop を渡します。

      components={{
        ...
-       DayButton: CalendarDayButton,
+       DayButton: ({ ...props }) => (
+         <CalendarDayButton locale={locale} {...props} />
+       ),
        ...
      }}

RTL 対応の CSS クラスを更新します。

RTL サポートを向上させるために、方向性クラスを論理プロパティに置き換えます。

  // In the day classNames:
- [&:last-child[data-selected=true]_button]:rounded-r-(--cell-radius)
+ [&:last-child[data-selected=true]_button]:rounded-e-(--cell-radius)
- [&:nth-child(2)[data-selected=true]_button]:rounded-l-(--cell-radius)
+ [&:nth-child(2)[data-selected=true]_button]:rounded-s-(--cell-radius)
- [&:first-child[data-selected=true]_button]:rounded-l-(--cell-radius)
+ [&:first-child[data-selected=true]_button]:rounded-s-(--cell-radius)
 
  // In range_start classNames:
- rounded-l-(--cell-radius) ... after:right-0
+ rounded-s-(--cell-radius) ... after:end-0
 
  // In range_end classNames:
- rounded-r-(--cell-radius) ... after:left-0
+ rounded-e-(--cell-radius) ... after:start-0
 
  // In CalendarDayButton className:
- data-[range-end=true]:rounded-r-(--cell-radius)
+ data-[range-end=true]:rounded-e-(--cell-radius)
- data-[range-start=true]:rounded-l-(--cell-radius)
+ data-[range-start=true]:rounded-s-(--cell-radius)

これらの変更を適用すると、locale プロパティを使用してロケール固有の書式を指定できるようになります。

import { enUS } from "react-day-picker/locale"
 
;<Calendar mode="single" selected={date} onSelect={setDate} locale={enUS} />