본문으로 바로가기 본문 바로가기
WIKI 기술 지식 베이스

달력(Calendar)

원문 보기 위키 갱신

날짜와 요일을 표시하고 날짜 관련 상호작용을 돕는 컴포넌트예요. 예약, 기념일, 일정 선택처럼 사용자에게 날짜를 골라야 하는 상황에 잘 어울려요.

출처: 문서

본문

<script lang="ts">
  import { Calendar } from "bits-ui";
  import CaretLeft from "phosphor-svelte/lib/CaretLeft";
  import CaretRight from "phosphor-svelte/lib/CaretRight";
  import { getLocalTimeZone, today } from "@internationalized/date";
  let value = $state(today(getLocalTimeZone()));
</script>
<Calendar.Root
  class="border-dark-10 bg-background-alt shadow-card mt-6 rounded-[15px] border p-[22px]"
  weekdayFormat="short"
  fixedWeeks={true}
  type="single"
  bind:value
>
  {#snippet children({ months, weekdays })}
    <Calendar.Header class="flex items-center justify-between">
      <Calendar.PrevButton
        class="rounded-9px bg-background-alt hover:bg-muted inline-flex size-10 items-center justify-center active:scale-[0.98] active:transition-all"
      >
        <CaretLeft class="size-6" />
      </Calendar.PrevButton>
      <Calendar.Heading class="text-[15px] font-medium" />
      <Calendar.NextButton
        class="rounded-9px bg-background-alt hover:bg-muted inline-flex size-10 items-center justify-center active:scale-[0.98] active:transition-all"
      >
        <CaretRight class="size-6" />
      </Calendar.NextButton>
    </Calendar.Header>
    <div
      class="flex flex-col space-y-4 pt-4 sm:flex-row sm:space-x-4 sm:space-y-0"
    >
      {#each months as month, i (i)}
        <Calendar.Grid class="w-full border-collapse select-none space-y-1">
          <Calendar.GridHead>
            <Calendar.GridRow class="mb-1 flex w-full justify-between">
              {#each weekdays as day, i (i)}
                <Calendar.HeadCell
                  class="text-muted-foreground font-normal! w-10 rounded-md text-xs"
                >
                  <div>{day.slice(0, 2)}</div>
                </Calendar.HeadCell>
              {/each}
            </Calendar.GridRow>
          </Calendar.GridHead>
          <Calendar.GridBody>
            {#each month.weeks as weekDates, i (i)}
              <Calendar.GridRow class="flex w-full">
                {#each weekDates as date, i (i)}
                  <Calendar.Cell
                    {date}
                    month={month.value}
                    class="p-0! relative size-10 text-center text-sm"
                  >
                    <Calendar.Day
                      class="rounded-9px text-foreground hover:border-foreground data-selected:bg-foreground data-disabled:text-foreground/30 data-selected:text-background data-unavailable:text-muted-foreground data-disabled:pointer-events-none data-outside-month:pointer-events-none data-selected:font-medium data-unavailable:line-through group relative inline-flex size-10 items-center justify-center whitespace-nowrap border border-transparent bg-transparent p-0 text-sm font-normal"
                    >
                      <div
                        class="bg-foreground group-data-selected:bg-background group-data-today:block absolute top-[5px] hidden size-1 rounded-full"
                      ></div>
                      {date.day}
                    </Calendar.Day>
                  </Calendar.Cell>
                {/each}
              </Calendar.GridRow>
            {/each}
          </Calendar.GridBody>
        </Calendar.Grid>
      {/each}
    </div>
  {/snippet}
</Calendar.Root>
주의하세요!(Heads up!)

이 컴포넌트를 다루기 전에 Bits UI에서 날짜/시간이 어떻게 동작하는지 이해하는 게 중요해요. 자세한 내용은 Dates 문서를 먼저 읽어주세요!

구조(Structure)

<script lang="ts">
  import { Calendar } from "bits-ui";
</script>
<Calendar.Root>
  {#snippet children({ months, weekdays })}
    <Calendar.Header>
      <Calendar.PrevButton />
      <Calendar.Heading />
      <Calendar.NextButton />
    </Calendar.Header>
    {#each months as month}
      <Calendar.Grid>
        <Calendar.GridHead>
          <Calendar.GridRow>
            {#each weekdays as day}
              <Calendar.HeadCell>
                {day}
              </Calendar.HeadCell>
            {/each}
          </Calendar.GridRow>
        </Calendar.GridHead>
        <Calendar.GridBody>
          {#each month.weeks as weekDates}
            <Calendar.GridRow>
              {#each weekDates as date}
                <Calendar.Cell {date} month={month.value}>
                  <Calendar.Day />
                </Calendar.Cell>
              {/each}
            </Calendar.GridRow>
          {/each}
        </Calendar.GridBody>
      </Calendar.Grid>
    {/each}
  {/snippet}
</Calendar.Root>

Placeholder

Calendar.Root 컴포넌트의 placeholder prop은 사용자가 아직 날짜를 선택하지 않았을 때 달력이 어느 날짜에서 시작할지를 결정해요. 또한 달력의 현재 "뷰(view)"를 결정하기도 해요.

사용자가 달력을 탐색하면서 placeholder는 그 뷰에서 현재 포커스된 날짜를 반영하도록 갱신돼요.

기본적으로 placeholder는 maxValue/minValue로 허용된 값에서 현재 날짜와 가장 가까운 값으로 설정되고, 타입은 CalendarDate예요.

Placeholder 상태 관리하기

이 절에서는 Calendar의 placeholder 상태를 관리하는 방법을 다뤄요.

양방향 바인딩(Two-Way Binding)

bind:placeholder를 사용하면 상태가 자동으로 동기화되어 아주 간단해요.

<script lang="ts">
  import { Calendar } from "bits-ui";
  import { CalendarDateTime } from "@internationalized/date";
  let myPlaceholder = $state(new CalendarDateTime(2024, 8, 3, 12, 30));
</script>
<button onclick={() => (myPlaceholder = new CalendarDate(2024, 8, 3))}>
  Set placeholder to August 3rd, 2024
</button>
<Calendar.Root bind:placeholder={myPlaceholder}>
  <!-- ... -->
</Calendar.Root>

완전 제어(Fully Controlled)

함수 바인딩(Function Binding)을 사용하면 상태의 읽기와 쓰기를 완전히 제어할 수 있어요.

<script lang="ts">
  import { Calendar } from "bits-ui";
  import type { DateValue } from "@internationalized/date";
  let myPlaceholder = $state<DateValue>();
  function getPlaceholder() {
    return myPlaceholder;
  }
  function setPlaceholder(newPlaceholder: DateValue) {
    myPlaceholder = newPlaceholder;
  }
</script>
<Calendar.Root bind:placeholder={getPlaceholder, setPlaceholder}>
  <!-- ... -->
</Calendar.Root>

상태 관리에 대해 더 자세히 알고 싶다면 State Management 문서를 참고하세요.

value 상태 관리하기

이 절에서는 Calendar의 value 상태를 관리하는 방법을 다뤄요.

양방향 바인딩(Two-Way Binding)

bind:value를 사용하면 상태가 자동으로 동기화되어 아주 간단해요.

<script lang="ts">
  import { Calendar } from "bits-ui";
  import { CalendarDateTime } from "@internationalized/date";
  let myValue = $state(new CalendarDateTime(2024, 8, 3, 12, 30));
</script>
<button onclick={() => (myValue = myValue.add({ days: 1 }))}>
  Add 1 day
</button>
<Calendar.Root type="single" bind:value={myValue}>
  <!-- ... -->
</Calendar.Root>

완전 제어(Fully Controlled)

함수 바인딩(Function Binding)을 사용하면 상태의 읽기와 쓰기를 완전히 제어할 수 있어요.

<script lang="ts">
  import { Calendar } from "bits-ui";
  import type { DateValue } from "@internationalized/date";
  let myValue = $state();
  function getValue() {
    return myValue;
  }
  function setValue(newValue: DateValue) {
    myValue = newValue;
  }
</script>
<Calendar.Root type="single" bind:value={getValue, setValue}>
  <!-- ... -->
</Calendar.Root>

상태 관리에 대해 더 자세히 알고 싶다면 State Management 문서를 참고하세요.

기본값(Default Value)

Calendar.Root 컴포넌트를 기본값으로 시작하고 싶은 경우가 많아요. 이 값은 보통 ISO 8601 문자열 형식으로 데이터베이스에서 내려오곤 하죠.

@internationalized/date 패키지의 parseDate 함수를 사용해 문자열을 CalendarDate 객체로 파싱할 수 있어요.

<script lang="ts">
  import { Calendar } from "bits-ui";
  import { parseDate } from "@internationalized/date";
  // this came from a database/API call
  const date = "2024-08-03";
  let value = $state(parseDate(date));
</script>
<Calendar.Root {value}>
  <!-- ...-->
</Calendar.Root>

검증(Validation)

최솟값(Minimum Value)

Calendar.Root의 minValue prop으로 달력의 최솟값을 설정할 수 있어요. 사용자가 최솟값보다 이른 날짜를 선택하면 달력은 invalid로 표시돼요.

<script lang="ts">
  import { Calendar } from "bits-ui";
  import { today, getLocalTimeZone } from "@internationalized/date";
  const todayDate = today(getLocalTimeZone());
  const yesterday = todayDate.subtract({ days: 1 });
</script>
<Calendar.Root minValue={todayDate} value={yesterday}>
  <!-- ...-->
</Calendar.Root>

최댓값(Maximum Value)

Calendar.Root의 maxValue prop으로 달력의 최댓값을 설정할 수 있어요. 사용자가 최댓값보다 늦은 날짜를 선택하면 달력은 invalid로 표시돼요.

<script lang="ts">
  import { Calendar } from "bits-ui";
  import { today, getLocalTimeZone } from "@internationalized/date";
  const todayDate = today(getLocalTimeZone());
  const tomorrow = todayDate.add({ days: 1 });
</script>
<Calendar.Root maxValue={todayDate} value={tomorrow}>
  <!-- ...-->
</Calendar.Root>

선택 불가 날짜(Unavailable Dates)

isDateUnavailable prop으로 선택할 수 없는 특정 날짜를 지정할 수 있어요. 이 prop은 해당 날짜가 선택 불가인지 여부를 나타내는 불리언을 반환하는 함수를 받아요.

<script lang="ts">
  import { Calendar } from "bits-ui";
  import { today, getLocalTimeZone, isNotNull } from "@internationalized/date";
  const todayDate = today(getLocalTimeZone());
  const tomorrow = todayDate.add({ days: 1 });
  function isDateUnavailable(date: DateValue) {
    return date.day === 1;
  }
</script>
<Calendar.Root {isDateUnavailable} value={tomorrow}>
  <!-- ...-->
</Calendar.Root>

비활성 날짜(Disabled Dates)

isDateDisabled prop으로 선택이 비활성화될 특정 날짜를 지정할 수 있어요.

<script lang="ts">
  import { Calendar } from "bits-ui";
  import { today, getLocalTimeZone, isNotNull } from "@internationalized/date";
  const todayDate = today(getLocalTimeZone());
  const tomorrow = todayDate.add({ days: 1 });
  function isDateDisabled(date: DateValue) {
    return date.day === 1;
  }
</script>
<Calendar.Root {isDateDisabled} value={tomorrow}>
  <!-- ...-->
</Calendar.Root>

최대 일수(Max Days)

달력이 'multiple' 타입일 때 선택할 수 있는 최대 일수를 제한하려면 maxDays prop을 설정할 수 있어요.

<Calendar.Root type="multiple" maxDays={3}>
  <!-- ...-->
</Calendar.Root>

코드 펼치기(Expand Code)

<script lang="ts">
  import { Calendar } from "bits-ui";
  import CaretLeft from "phosphor-svelte/lib/CaretLeft";
  import CaretRight from "phosphor-svelte/lib/CaretRight";
  import { getLocalTimeZone, today } from "@internationalized/date";
  let value = $state([today(getLocalTimeZone())]);
</script>
<Calendar.Root
  class="border-dark-10 bg-background-alt shadow-card mt-6 rounded-[15px] border p-[22px]"
  weekdayFormat="short"
  fixedWeeks={true}
  type="multiple"
  bind:value
  maxDays={3}
>
  {#snippet children({ months, weekdays })}
    <Calendar.Header class="flex items-center justify-between">
      <Calendar.PrevButton
        class="rounded-9px bg-background-alt hover:bg-muted inline-flex size-10 items-center justify-center active:scale-[0.98] active:transition-all"
      >
        <CaretLeft class="size-6" />
      </Calendar.PrevButton>
      <Calendar.Heading class="text-[15px] font-medium" />
      <Calendar.NextButton
        class="rounded-9px bg-background-alt hover:bg-muted inline-flex size-10 items-center justify-center active:scale-[0.98] active:transition-all"
      >
        <CaretRight class="size-6" />
      </Calendar.NextButton>
    </Calendar.Header>
    <div
      class="flex flex-col space-y-4 pt-4 sm:flex-row sm:space-x-4 sm:space-y-0"
    >
      {#each months as month, i (i)}
        <Calendar.Grid class="w-full border-collapse select-none space-y-1">
          <Calendar.GridHead>
            <Calendar.GridRow class="mb-1 flex w-full justify-between">
              {#each weekdays as day, i (i)}
                <Calendar.HeadCell
                  class="text-muted-foreground font-normal! w-10 rounded-md text-xs"
                >
                  <div>{day.slice(0, 2)}</div>
                </Calendar.HeadCell>
              {/each}
            </Calendar.GridRow>
          </Calendar.GridHead>
          <Calendar.GridBody>
            {#each month.weeks as weekDates, i (i)}
              <Calendar.GridRow class="flex w-full">
                {#each weekDates as date, i (i)}
                  <Calendar.Cell
                    {date}
                    month={month.value}
                    class="p-0! relative size-10 text-center text-sm"
                  >
                    <Calendar.Day
                      class="rounded-9px text-foreground hover:border-foreground data-selected:bg-foreground data-disabled:text-foreground/30 data-selected:text-background data-unavailable:text-muted-foreground data-disabled:pointer-events-none data-outside-month:pointer-events-none data-selected:font-medium data-unavailable:line-through group relative inline-flex size-10 items-center justify-center whitespace-nowrap border border-transparent bg-transparent p-0 text-sm font-normal"
                    >
                      <div
                        class="bg-foreground group-data-selected:bg-background group-data-today:block absolute top-[5px] hidden size-1 rounded-full"
                      ></div>
                      {date.day}
                    </Calendar.Day>
                  </Calendar.Cell>
                {/each}
              </Calendar.GridRow>
            {/each}
          </Calendar.GridBody>
        </Calendar.Grid>
      {/each}
    </div>
  {/snippet}
</Calendar.Root>

외형과 동작(Appearance & Behavior)

고정 주(Fixed Weeks)

fixedWeeks prop을 사용하면 달력이 월의 일수와 관계없이 항상 일정한 주 수를 렌더링하게 할 수 있어요. 월마다 일수가 달라져도 달력이 시각적으로 일관되게 유지되어 좋아요.

<Calendar.Root fixedWeeks>
  <!-- ...-->
</Calendar.Root>

여러 달(Multiple Months)

numberOfMonths prop을 사용해 한 번에 여러 달을 렌더링할 수 있어요.

<Calendar.Root numberOfMonths={2}>
  <!-- ...-->
</Calendar.Root>

페이지 단위 내비게이션(Paged Navigation)

기본적으로 달력에 달이 하나 이상이면 이전/다음 버튼은 달력을 한 달씩 이동해요. 하지만 pagedNavigation prop을 true로 설정하면 표시 중인 달의 수만큼 이동하도록 바꿀 수 있어요.

<Calendar.Root pagedNavigation>
  <!-- ...-->
</Calendar.Root>

지역화(Localization)

달력은 locale prop에 따라 내용을 자동으로 포맷해요. 기본값은 'en-US'지만, Intl.DateTimeFormat API가 지원하는 어떤 locale로도 바꿀 수 있어요.

<Calendar.Root locale="fr-FR">
  <!-- ...-->
</Calendar.Root>

주 시작 요일(Week Starts On)

달력은 locale에 따라 내용을 자동으로 포맷하며, 이 값이 한 주의 첫 요일도 결정해요.

weekStartsOn prop을 설정해 이 값을 덮어쓸 수도 있어요. 0은 일요일, 6은 토요일이며, 모든 locale에서 일관된 주 시작 요일을 강제할 수 있어요.

<Calendar.Root weekStartsOn={1}>
  <!-- ...-->
</Calendar.Root>

다중 선택(Multiple Selection)

type prop을 'multiple'로 설정하면 사용자가 한 번에 여러 날짜를 선택할 수 있어요.

<Calendar.Root type="multiple">
  <!-- ...-->
</Calendar.Root>

커스텀 구성(Custom Composition)

월 선택기(Month Selector)

Calendar 컴포넌트에는 사용자가 달 사이를 이동할 수 있게 해주는 PrevButton과 NextButton 컴포넌트가 포함돼 있어요. 유용하지만, 때로는 한 달씩 넘어가는 대신 월 목록에서 특정 달을 선택하게 하고 싶을 수도 있어요.

이를 위해 placeholder prop으로 달력 뷰의 월을 프로그래밍 방식으로 설정할 수 있어요.

<script lang="ts">
  import { Calendar } from "bits-ui";
  import { CalendarDate } from "@internationalized/date";
  let placeholder = $state(new CalendarDate(2024, 8, 3));
</script>
<!-- You can use a select, button, or whatever you wish -->
<button
  onclick={() => {
    placeholder = placeholder.set({ month: 8 });
  }}
>
  Set month to August
</button>
<Calendar.Root bind:placeholder>
  <!-- ... -->
</Calendar.Root>

placeholder를 갱신하면 달력 뷰가 새 월을 반영하도록 바뀌어요.

예제(Examples)

월·연도 선택(Month and Year Selects)

이 예시는 placeholder prop을 사용해 달력 뷰의 월과 연도를 프로그래밍 방식으로 설정하는 방법을 보여줘요.

코드 펼치기(Expand Code)

<script lang="ts">
  import { Calendar } from "bits-ui";
  import { getLocalTimeZone, today } from "@internationalized/date";
  let value = $state(today(getLocalTimeZone()));
</script>
<Calendar.Root
  class="border-dark-10 bg-background-alt shadow-card mt-6 rounded-[15px] border p-[22px]"
  weekdayFormat="short"
  fixedWeeks={true}
  type="single"
  bind:value
>
  {#snippet children({ months, weekdays })}
    <Calendar.Header class="flex items-center justify-between gap-3">
      <Calendar.MonthSelect aria-label="Select month" class="w-full" />
      <Calendar.YearSelect aria-label="Select year" />
    </Calendar.Header>
    <div
      class="flex flex-col space-y-4 pt-4 sm:flex-row sm:space-x-4 sm:space-y-0"
    >
      {#each months as month, i (i)}
        <Calendar.Grid class="w-full border-collapse select-none space-y-1">
          <Calendar.GridHead>
            <Calendar.GridRow class="mb-1 flex w-full justify-between">
              {#each weekdays as day, i (i)}
                <Calendar.HeadCell
                  class="text-muted-foreground font-normal! w-10 rounded-md text-xs"
                >
                  <div>{day.slice(0, 2)}</div>
                </Calendar.HeadCell>
              {/each}
            </Calendar.GridRow>
          </Calendar.GridHead>
          <Calendar.GridBody>
            {#each month.weeks as weekDates, i (i)}
              <Calendar.GridRow class="flex w-full">
                {#each weekDates as date, i (i)}
                  <Calendar.Cell
                    {date}
                    month={month.value}
                    class="p-0! relative size-10 text-center text-sm"
                  >
                    <Calendar.Day
                      class="rounded-9px text-foreground hover:border-foreground data-selected:bg-foreground data-disabled:text-foreground/30 data-selected:text-background data-unavailable:text-muted-foreground data-disabled:pointer-events-none data-outside-month:pointer-events-none data-selected:font-medium data-unavailable:line-through group relative inline-flex size-10 items-center justify-center whitespace-nowrap border border-transparent bg-transparent p-0 text-sm font-normal"
                    >
                      <div
                        class="bg-foreground group-data-selected:bg-background group-data-today:block absolute top-[5px] hidden size-1 rounded-full"
                      ></div>
                      {date.day}
                    </Calendar.Day>
                  </Calendar.Cell>
                {/each}
              </Calendar.GridRow>
            {/each}
          </Calendar.GridBody>
        </Calendar.Grid>
      {/each}
    </div>
  {/snippet}
</Calendar.Root>

사전 설정 날짜(Preset Dates)

이 예시는 사용자가 버튼을 누르면 달력의 value를 특정 날짜로 프로그래밍 방식으로 설정하는 방법을 보여줘요.

코드 펼치기(Expand Code)

<script lang="ts">
  import { Button, Calendar, Separator } from "bits-ui";
  import CaretLeft from "phosphor-svelte/lib/CaretLeft";
  import CaretRight from "phosphor-svelte/lib/CaretRight";
  import { getLocalTimeZone, today } from "@internationalized/date";
  const currentDate = today(getLocalTimeZone());
  let value = $state(currentDate);
  const presets = [
    {
      label: "Today",
      onclick: () => {
        value = currentDate;
      }
    },
    {
      label: "Tomorrow",
      onclick: () => {
        value = currentDate.add({ days: 1 });
      }
    },
    {
      label: "In 3 days",
      onclick: () => {
        value = currentDate.add({ days: 3 });
      }
    },
    {
      label: "In a week",
      onclick: () => {
        value = currentDate.add({ days: 7 });
      }
    },
    {
      label: "In a month",
      onclick: () => {
        value = currentDate.add({ months: 1 });
      }
    },
    {
      label: "In a year",
      onclick: () => {
        value = currentDate.add({ years: 1 });
      }
    }
  ];
</script>
<div
  class="border-dark-10 bg-background-alt shadow-card mt-6 flex max-w-[324px] flex-col gap-4 rounded-[15px] border p-[22px]"
>
  <Calendar.Root
    weekdayFormat="short"
    fixedWeeks={true}
    type="single"
    bind:value
  >
    {#snippet children({ months, weekdays })}
      <Calendar.Header class="flex items-center justify-between">
        <Calendar.PrevButton
          class="rounded-9px bg-background-alt hover:bg-muted inline-flex size-10 items-center justify-center active:scale-[0.98] active:transition-all"
        >
          <CaretLeft class="size-6" />
        </Calendar.PrevButton>
        <Calendar.Heading class="text-[15px] font-medium" />
        <Calendar.NextButton
          class="rounded-9px bg-background-alt hover:bg-muted inline-flex size-10 items-center justify-center active:scale-[0.98] active:transition-all"
        >
          <CaretRight class="size-6" />
        </Calendar.NextButton>
      </Calendar.Header>
      <div
        class="flex flex-col space-y-4 pt-4 sm:flex-row sm:space-x-4 sm:space-y-0"
      >
        {#each months as month, i (i)}
          <Calendar.Grid class="w-full border-collapse select-none space-y-1">
            <Calendar.GridHead>
              <Calendar.GridRow class="mb-1 flex w-full justify-between">
                {#each weekdays as day, i (i)}
                  <Calendar.HeadCell
                    class="text-muted-foreground font-normal! w-10 rounded-md text-xs"
                  >
                    <div>{day.slice(0, 2)}</div>
                  </Calendar.HeadCell>
                {/each}
              </Calendar.GridRow>
            </Calendar.GridHead>
            <Calendar.GridBody>
              {#each month.weeks as weekDates, i (i)}
                <Calendar.GridRow class="flex w-full">
                  {#each weekDates as date, i (i)}
                    <Calendar.Cell
                      {date}
                      month={month.value}
                      class="p-0! relative size-10 text-center text-sm"
                    >
                      <Calendar.Day
                        class="rounded-9px text-foreground hover:border-foreground data-selected:bg-foreground data-disabled:text-foreground/30 data-selected:text-background data-unavailable:text-muted-foreground data-disabled:pointer-events-none data-outside-month:pointer-events-none data-selected:font-medium data-unavailable:line-through group relative inline-flex size-10 items-center justify-center whitespace-nowrap border border-transparent bg-transparent p-0 text-sm font-normal"
                      >
                        <div
                          class="bg-foreground group-data-selected:bg-background group-data-today:block absolute top-[5px] hidden size-1 rounded-full"
                        ></div>
                        {date.day}
                      </Calendar.Day>
                    </Calendar.Cell>
                  {/each}
                </Calendar.GridRow>
              {/each}
            </Calendar.GridBody>
          </Calendar.Grid>
        {/each}
      </div>
    {/snippet}
  </Calendar.Root>
  <Separator.Root class="bg-dark-10 h-px w-full" />
  <div class="flex w-full flex-row flex-wrap items-center gap-2">
    {#each presets as preset (preset.label)}
      <Button.Root
        class="border-dark-10 text-foreground shadow-mini hover:bg-foreground/5 inline-flex h-8 flex-1 select-none items-center justify-center whitespace-nowrap rounded-md border px-[17px] text-xs font-medium transition-all active:scale-[0.98]"
        onclick={preset.onclick}
      >
        <span class="sr-only"> Set date to </span>
        {preset.label}
      </Button.Root>
    {/each}
  </div>
</div>

API 참조(API Reference)

Calendar.Root

다른 모든 달력 컴포넌트를 포함하는 루트 달력 컴포넌트예요.

Property Type Description Details
type required enum - 'single' | 'multiple' The type of the component, used to determine the type of the value, when 'multiple' the value will be an array.Default:  —— undefined
value $bindable union - DateValue | DateValue[] The selected date(s). If type is 'single', this will be a DateValue. If type is 'multiple', this will be an array of DateValues.Default:  —— undefined
onValueChange function - (value: DateValue) => void | (value: DateValue[]) => void A function that is called when the selected date changes.Default:  —— undefined
placeholder DateValue - import type { CalendarDate, CalendarDateTime, ZonedDateTime } from "@internationalized/date"; type DateValue = CalendarDate | CalendarDateTime | ZonedDateTime The placeholder date, which is used to determine what month to display when no date is selected. This updates as the user navigates the calendar, and can be used to programmatically control the calendar's view.Default:  —— undefined
onPlaceholderChange function - (date: DateValue) => void A function that is called when the placeholder date changes.Default:  —— undefined
pagedNavigation boolean Whether or not to use paged navigation for the calendar. Paged navigation causes the previous and next buttons to navigate by the number of months displayed at once, rather than by one month.Default: false
preventDeselect boolean Whether or not to prevent the user from deselecting a date without selecting another date first.Default: false
weekStartsOn number An absolute day of the week to start the calendar on, regardless of locale. 0 is Sunday, 1 is Monday, etc. If not provided, the calendar will default to the locale's first day of the week.Default:  —— undefined
weekdayFormat enum - 'narrow' | 'short' | 'long' The format to use for the weekday strings provided via the weekdays slot prop.Default: ''narrow''
calendarLabel string The accessible label for the calendar.Default:  —— undefined
fixedWeeks boolean Whether or not to always display 6 weeks in the calendar.Default: false
isDateDisabled function - (date: DateValue) => boolean A function that returns whether or not a date is disabled.Default:  —— undefined
isDateUnavailable function - (date: DateValue) => boolean A function that returns whether or not a date is unavailable.Default:  —— undefined
maxValue DateValue - import type { CalendarDate, CalendarDateTime, ZonedDateTime } from "@internationalized/date"; type DateValue = CalendarDate | CalendarDateTime | ZonedDateTime The maximum date that can be selected.Default:  —— undefined
minValue DateValue - import type { CalendarDate, CalendarDateTime, ZonedDateTime } from "@internationalized/date"; type DateValue = CalendarDate | CalendarDateTime | ZonedDateTime The minimum date that can be selected.Default:  —— undefined
locale string The locale to use for formatting dates.Default: 'en'
numberOfMonths number The number of months to display at once.Default: 1
disabled boolean Whether or not the calendar is disabled.Default: false
readonly boolean Whether or not the calendar is readonly.Default: false
initialFocus boolean If true, the calendar will focus the selected day, today, or the first day of the month in that order depending on what is visible when the calendar is mounted.Default: false
disableDaysOutsideMonth boolean Whether or not to disable days outside the current month.Default: false
maxDays number The maximum number of days that can be selected when the calendar is 'multiple' type.Default:  —— undefined
monthFormat union - short | long | narrow | numeric | 2-digit | (month: number) => string The format to use for the month strings provided via the months slot prop.Default: 'long'
yearFormat union - numeric | 2-digit | (year: number) => string The format to use for the year strings provided via the years slot prop.Default: 'numeric'
ref $bindable HTMLDivElement The underlying DOM element being rendered. You can bind to this to get a reference to the element.Default: null
children Snippet - type Month<T> = { /** * A `DateValue` used to represent the month. Since days * from the previous and next months may be included in the * calendar grid, we need a source of truth for the value * the grid is representing. */ value: DateValue /** * An array of arrays representing the weeks in the calendar. * Each sub-array represents a week, and contains the dates for each * day in that week. This structure is useful for rendering the calendar * grid using a table, where each row represents a week and each cell * represents a day. */ weeks: T[][] /** * An array of all the dates in the current month, including dates from * the previous and next months that are used to fill out the calendar grid. * This array is useful for rendering the calendar grid in a customizable way, * as it provides all the dates that should be displayed in the grid in a flat * array. */ dates: T[] } type ChildrenSnippetProps = { months: Month<DateValue>[] weekdays: string[] } The children content to render.Default:  —— undefined
child Snippet - type Month<T> = { /** * A `DateValue` used to represent the month. Since days * from the previous and next months may be included in the * calendar grid, we need a source of truth for the value * the grid is representing. */ value: DateValue /** * An array of arrays representing the weeks in the calendar. * Each sub-array represents a week, and contains the dates for each * day in that week. This structure is useful for rendering the calendar * grid using a table, where each row represents a week and each cell * represents a day. */ weeks: T[][] /** * An array of all the dates in the current month, including dates from * the previous and next months that are used to fill out the calendar grid. * This array is useful for rendering the calendar grid in a customizable way, * as it provides all the dates that should be displayed in the grid in a flat * array. */ dates: T[] } type ChildSnippetProps = { props: Record<string, unknown> months: Month<DateValue>[] weekdays: string[] } Use render delegation to render your own element. See Child Snippet docs for more information.Default:  —— undefined
Data Attribute Value Description Details
data-invalid '' Present on the root element when the calendar is invalid.
data-disabled '' Present on the root element when the calendar is disabled.
data-readonly '' Present on the root element when the calendar is readonly.
data-calendar-root '' Present on the root element.

Calendar.Header

달력의 헤더예요.

Property Type Description Details
ref $bindable HTMLElement The underlying DOM element being rendered. You can bind to this to get a reference to the element.Default: null
children Snippet The children content to render.Default:  —— undefined
child Snippet - type SnippetProps = { props: Record<string, unknown>; }; Use render delegation to render your own element. See Child Snippet docs for more information.Default:  —— undefined
Data Attribute Value Description Details
data-disabled '' Present on the header element when the calendar is disabled.
data-readonly '' Present on the header element when the calendar is readonly.
data-calendar-header '' Present on the header element.

Calendar.Heading

달력의 제목(헤딩)이에요.

Property Type Description Details
ref $bindable HTMLDivElement The underlying DOM element being rendered. You can bind to this to get a reference to the element.Default: null
children Snippet The children content to render.Default:  —— undefined
child Snippet - type SnippetProps = { props: Record<string, unknown>; }; Use render delegation to render your own element. See Child Snippet docs for more information.Default:  —— undefined
Data Attribute Value Description Details
data-disabled '' Present on the heading element when the calendar is disabled.
data-readonly '' Present on the heading element when the calendar is readonly.
data-calendar-heading '' Present on the heading element.

Calendar.NextButton

달력의 다음 버튼이에요.

Property Type Description Details
ref $bindable HTMLButtonElement The underlying DOM element being rendered. You can bind to this to get a reference to the element.Default: null
children Snippet The children content to render.Default:  —— undefined
child Snippet - type SnippetProps = { props: Record<string, unknown>; }; Use render delegation to render your own element. See Child Snippet docs for more information.Default:  —— undefined
Data Attribute Value Description Details
data-disabled '' Present on the next button element when the calendar or this button is disabled.
data-calendar-next-button '' Present on the next button element.

Calendar.PrevButton

달력의 이전 버튼이에요.

Property Type Description Details
ref $bindable HTMLButtonElement The underlying DOM element being rendered. You can bind to this to get a reference to the element.Default: null
children Snippet The children content to render.Default:  —— undefined
child Snippet - type SnippetProps = { props: Record<string, unknown>; }; Use render delegation to render your own element. See Child Snippet docs for more information.Default:  —— undefined
Data Attribute Value Description Details
data-disabled '' Present on the prev button element when the calendar or this button is disabled.
data-calendar-prev-button '' Present on the prev button element.

Calendar.Cell

달력 그리드의 셀(cell)이에요.

Property Type Description Details
date DateValue - import type { CalendarDate, CalendarDateTime, ZonedDateTime } from "@internationalized/date"; type DateValue = CalendarDate | CalendarDateTime | ZonedDateTime The date for the cell.Default:  —— undefined
month DateValue - import type { CalendarDate, CalendarDateTime, ZonedDateTime } from "@internationalized/date"; type DateValue = CalendarDate | CalendarDateTime | ZonedDateTime The current month the date is being displayed in.Default:  —— undefined
ref $bindable HTMLTableCellElement The underlying DOM element being rendered. You can bind to this to get a reference to the element.Default: null
children Snippet The children content to render.Default:  —— undefined
child Snippet - type SnippetProps = { props: Record<string, unknown>; }; Use render delegation to render your own element. See Child Snippet docs for more information.Default:  —— undefined
Data Attribute Value Description Details
data-disabled '' Present when the day is disabled.
data-unavailable '' Present when the day is unavailable.
data-today '' Present when the day is today.
data-outside-month '' Present when the day is outside the current month.
data-outside-visible-months '' Present when the day is outside the visible months.
data-focused '' Present when the day is focused.
data-selected '' Present when the day is selected.
data-value '' The date in the format "YYYY-MM-DD".
data-calendar-cell '' Present on the cell element.

Calendar.Day

달력 그리드의 하루(day)예요.

Property Type Description Details
ref $bindable HTMLDivElement The underlying DOM element being rendered. You can bind to this to get a reference to the element.Default: null
children Snippet The children content to render.Default:  —— undefined
child Snippet - type SnippetProps = { props: Record<string, unknown>; }; Use render delegation to render your own element. See Child Snippet docs for more information.Default:  —— undefined
Data Attribute Value Description Details
data-disabled '' Present when the day is disabled.
data-unavailable '' Present when the day is unavailable.
data-today '' Present when the day is today.
data-outside-month '' Present when the day is outside the current month.
data-outside-visible-months '' Present when the day is outside the visible months.
data-focused '' Present when the day is focused.
data-selected '' Present when the day is selected.
data-value '' The date in the format "YYYY-MM-DD".
data-calendar-day '' Present on the day element.

Calendar.Grid

보통 한 달을 나타내는 달력의 날짜 그리드예요.

Property Type Description Details
ref $bindable HTMLTableElement The underlying DOM element being rendered. You can bind to this to get a reference to the element.Default: null
children Snippet The children content to render.Default:  —— undefined
child Snippet - type SnippetProps = { props: Record<string, unknown>; }; Use render delegation to render your own element. See Child Snippet docs for more information.Default:  —— undefined
Data Attribute Value Description Details
data-disabled '' Present on the grid element when the calendar is disabled.
data-readonly '' Present on the grid element when the calendar is readonly.
data-calendar-grid '' Present on the grid element.

Calendar.GridBody

달력 날짜 그리드의 본문이에요.

Property Type Description Details
ref $bindable HTMLTableSectionElement The underlying DOM element being rendered. You can bind to this to get a reference to the element.Default: null
children Snippet The children content to render.Default:  —— undefined
child Snippet - type SnippetProps = { props: Record<string, unknown>; }; Use render delegation to render your own element. See Child Snippet docs for more information.Default:  —— undefined
Data Attribute Value Description Details
data-disabled '' Present on the grid element when the calendar is disabled.
data-readonly '' Present on the grid element when the calendar is readonly.
data-calendar-grid-body '' Present on the grid body element.

Calendar.GridHead

달력 날짜 그리드의 머리 부분이에요.

Property Type Description Details
ref $bindable HTMLTableSectionElement The underlying DOM element being rendered. You can bind to this to get a reference to the element.Default: null
children Snippet The children content to render.Default:  —— undefined
child Snippet - type SnippetProps = { props: Record<string, unknown>; }; Use render delegation to render your own element. See Child Snippet docs for more information.Default:  —— undefined
Data Attribute Value Description Details
data-disabled '' Present on the grid head element when the calendar is disabled.
data-readonly '' Present on the grid head element when the calendar is readonly.
data-calendar-grid-head '' Present on the grid head element.

Calendar.GridRow

달력 날짜 그리드의 한 행이에요.

Property Type Description Details
ref $bindable HTMLTableRowElement The underlying DOM element being rendered. You can bind to this to get a reference to the element.Default: null
children Snippet The children content to render.Default:  —— undefined
child Snippet - type SnippetProps = { props: Record<string, unknown>; }; Use render delegation to render your own element. See Child Snippet docs for more information.Default:  —— undefined
Data Attribute Value Description Details
data-disabled '' Present on the grid row element when the calendar is disabled.
data-readonly '' Present on the grid row element when the calendar is readonly.
data-calendar-grid-row '' Present on the grid row element.

Calendar.HeadCell

달력 날짜 그리드 머리 부분의 셀이에요.

Property Type Description Details
ref $bindable HTMLTableCellElement The underlying DOM element being rendered. You can bind to this to get a reference to the element.Default: null
children Snippet The children content to render.Default:  —— undefined
child Snippet - type SnippetProps = { props: Record<string, unknown>; }; Use render delegation to render your own element. See Child Snippet docs for more information.Default:  —— undefined
Data Attribute Value Description Details
data-disabled '' Present on the head cell element when the calendar is disabled.
data-readonly '' Present on the head cell element when the calendar is readonly.
data-calendar-head-cell '' Present on the head cell element.

Calendar.MonthSelect

달력 뷰에서 특정 달로 이동할 때 사용하는 셀렉트예요.

Property Type Description Details
months number[] The month values to render in the select.Default: [1-12]
monthFormat enum - 'narrow' | 'short' | 'long' | 'numeric' | '2-digit' | '(month: number) => string' The format to use for the month strings provided via the months slot prop. If a function is provided, it will be called with the month number as an argument and should return a string.Default: ''narrow''
ref $bindable HTMLSelectElement The underlying DOM element being rendered. You can bind to this to get a reference to the element.Default: null
children Snippet - type ChildrenSnippetProps = { monthItems: Array<{ value: number; label: string }> selectedMonthItem: { value: number; label: string } } The children content to render.Default:  —— undefined
child Snippet - type ChildSnippetProps = { props: Record<string, unknown> monthItems: Array<{ value: number; label: string }> selectedMonthItem: { value: number; label: string } } Use render delegation to render your own element. See Child Snippet docs for more information.Default:  —— undefined
Data Attribute Value Description Details
data-disabled '' Present on the month select element when the calendar is disabled.
data-calendar-month-select '' Present on the month select element.

Calendar.YearSelect

달력 뷰에서 특정 연도로 이동할 때 사용하는 셀렉트예요.

Property Type Description Details
years number[] The year values to render in the select.Default: The current year or placeholder year (whichever is higher) + 10 and minus 100 years. When a `minValue`/`maxValue` is provided to `Calendar.Root`, those will be used to constrain the range.
yearFormat enum - 'numeric' | '2-digit' | '(year: number) => string' The format to use for the year strings provided via the years slot prop. If a function is provided, it will be called with the year as an argument and should return a string.Default: ''numeric''
ref $bindable HTMLSelectElement The underlying DOM element being rendered. You can bind to this to get a reference to the element.Default: null
children Snippet - type ChildrenSnippetProps = { yearItems: Array<{ value: number; label: string }> selectedYearItem: { value: number; label: string } } The children content to render.Default:  —— undefined
child Snippet - type ChildSnippetProps = { props: Record<string, unknown> yearItems: Array<{ value: number; label: string }> selectedYearItem: { value: number; label: string } } Use render delegation to render your own element. See Child Snippet docs for more information.Default:  —— undefined
Data Attribute Value Description Details
data-disabled '' Present on the year select element when the calendar is disabled.
data-calendar-year-select '' Present on the year select element.

더 알아보기 (Learn more)

날짜를 입력 필드로 받고 싶다면 데이트 필드(Date Field)나 데이트 피커(Date Picker) 컴포넌트를 살펴보세요. 날짜 범위를 선택해야 한다면 범위 달력(Range Calendar)이 더 적합할 수 있어요.