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

Calendar

원문 보기 위키 갱신

Calendar는 React Aria Calendar를 기반으로 월 그리드, 내비게이션, 연도 선택기 지원을 제공하는 구성 가능한(composable) 날짜 선택 컴포넌트예요. 해요체로 쉽게 설명드릴게요.

출처: HeroUI Calendar

본문

사용법 (Usage)

import { Calendar } from '@heroui/react';
{"name": "calendar-basic"}

구조 (Anatomy)

import {Calendar} from '@heroui/react';

export default () => (
  <Calendar aria-label="Event date">
    <Calendar.Header>
      <Calendar.Heading />
      <Calendar.NavButton slot="previous" />
      <Calendar.NavButton slot="next" />
    </Calendar.Header>
    <Calendar.Grid>
      <Calendar.GridHeader>
        {(day) => <Calendar.HeaderCell>{day}</Calendar.HeaderCell>}
      </Calendar.GridHeader>
      <Calendar.GridBody>
        {(date) => <Calendar.Cell date={date} />}
      </Calendar.GridBody>
    </Calendar.Grid>
  </Calendar>
)

예시 (Examples)

비활성화 (Disabled)

{"name": "calendar-disabled"}

읽기 전용 (Read Only)

{"name": "calendar-read-only"}

기본값 (Default Value)

{"name": "calendar-default-value"}

연도 선택기 (Year Picker)

Calendar.YearPickerTrigger, Calendar.YearPickerGrid와 그 하위의 body/cell 하위 컴포넌트들은 통합된 연도 내비게이션 패턴을 제공해요.

{"name": "calendar-year-picker"}

제어된 상태 (Controlled)

외부 상태 조정과 커스텀 단축키에는 제어된 value와 focusedValue를 사용해요.

{"name": "calendar-controlled"}

최소·최대 날짜 (Min and Max Dates)

{"name": "calendar-min-max-dates"}

선택 불가 날짜 (Unavailable Dates)

isDateUnavailable를 사용해 주말, 공휴일 또는 예약된 자리 같은 날짜를 차단할 수 있어요.

{"name": "calendar-unavailable-dates"}

월의 주 수 (Weeks in Month)

weeksInMonth를 고정 값(예: 6)으로 설정하면 월 사이를 이동할 때 그리드 높이를 안정적으로 유지할 수 있어요. firstDayOfWeek와 마찬가지로 비-그레고리력 로케일에서는 주의해서 사용해요.

{"name": "calendar-weeks-in-month"}

주 보기 (Week View)

visibleDuration={{ weeks: n }}을 설정하면 한 번에 한 주 이상을 표시할 수 있어요. 내비게이션은 보이는 주 범위만큼 이동해요. 여러 주를 표시할 때 한 번에 한 주씩 이동하려면 pageBehavior="single"을 사용해요.

{"name": "calendar-week-view"}

일 보기 (Day View)

visibleDuration={{ days: n }}을 설정하면 연속된 날짜의 롤링 창(window)을 표시할 수 있어요. 내비게이션은 보이는 일 범위만큼 이동해요. 여러 일을 표시할 때 하루씩 이동하려면 pageBehavior="single"을 사용해요.

{"name": "calendar-day-view"}

다중 선택 (Multiple Selection)

selectionMode="multiple"을 설정하면 사용자가 여러 날짜를 선택할 수 있어요. value, defaultValue, onChange는 날짜 배열을 사용해요.

{"name": "calendar-multiple-selection"}

포커스 값 (Focused Value)

focusedValue와 onFocusChange를 사용해 포커스될 날짜를 프로그래밍 방식으로 제어할 수 있어요.

{"name": "calendar-focused-value"}

셀 표시기 (Cell Indicators)

Calendar.Cell 자식을 커스터마이징하고 Calendar.CellIndicator를 사용해 이벤트 같은 메타데이터를 표시할 수 있어요.

{"name": "calendar-with-indicators"}

커스텀 내비게이션 아이콘 (Custom Navigation Icons)

Calendar.NavButton에 자식을 전달해 기본 셰브론 아이콘을 교체할 수 있어요.

{"name": "calendar-custom-icons"}

여러 달 (Multiple Months)

visibleDuration과 offset으로 여러 그리드를 렌더링해 예약 및 플래닝 경험을 만들 수 있어요.

{"name": "calendar-multiple-months"}

실제 사례 (Real-World Example)

{"name": "calendar-booking-calendar"}

국제 달력 (International Calendars)

기본적으로 Calendar는 사용자 로케일의 달력 체계를 사용해 날짜를 표시해요. Calendar를 I18nProvider로 감싸고 유니코드 달력 로케일 확장을 설정하면 이를 재정의할 수 있어요.

아래 예시는 인도 달력 체계를 보여줘요:

{"name": "calendar-international-calendar"}

참고: onChange 이벤트는 표시되는 로케일과 관계없이 항상 value 또는 defaultValue와 동일한 달력 체계(값이 제공되지 않으면 그레고리력)의 날짜를 반환해요. 이렇게 하면 앱 로직이 사용자의 선호 형식으로 날짜를 표시하면서도 단일 달력 체계로 일관성 있게 동작할 수 있어요.

커스터마이징 (Customization)

Tailwind CSS

{"name": "calendar-custom-styles"}

Global CSS

@layer components {
  .calendar {
    @apply w-72 rounded-2xl border border-border bg-surface p-3 shadow-sm;
  }

  .calendar__heading {
    @apply text-sm font-semibold text-default-700;
  }

  .calendar__cell[data-selected="true"] {
    @apply bg-accent text-accent-foreground;
  }
}

스타일링 참고 (Styling Reference)

HeroUI는 BEM 방법론을 따라 컴포넌트 변형과 상태를 재사용하고 쉽게 커스터마이징할 수 있게 해요.

CSS 클래스 (CSS Classes)

Calendar는 packages/styles/components/calendar.css와 packages/styles/components/calendar-year-picker.css의 클래스를 사용해요:

  • .calendar - 루트 컨테이너.
  • .calendar__header - 내비게이션 버튼과 제목이 있는 헤더 행.
  • .calendar__heading - 현재 월 라벨.
  • .calendar__nav-button - 이전/다음 내비게이션 컨트롤.
  • .calendar__grid - 메인 일 그리드.
  • .calendar__grid-header - 요일 헤더 행 래퍼.
  • .calendar__grid-body - 날짜 행 래퍼.
  • .calendar__header-cell - 요일 헤더 셀.
  • .calendar__cell - 상호작용 가능한 일 셀.
  • .calendar__cell-indicator - 일 셀 안의 점 표시기.
  • .calendar-year-picker__trigger - 연도 선택기 토글 버튼.
  • .calendar-year-picker__trigger-heading - 연도 선택기 트리거 안의 제목 텍스트.
  • .calendar-year-picker__trigger-indicator - 연도 선택기 트리거 안의 표시기 아이콘.
  • .calendar-year-picker__year-grid - 선택 가능한 연도의 오버레이 그리드.
  • .calendar-year-picker__year-cell - 개별 연도 옵션.

상호작용 상태 (Interactive States)

Calendar는 의사 클래스와 React Aria 데이터 속성을 모두 지원해요:

  • 선택됨 (Selected): [data-selected="true"]
  • 오늘 (Today): [data-today="true"]
  • 선택 불가 (Unavailable): [data-unavailable="true"]
  • 월 밖 (Outside month): [data-outside-month="true"]
  • 호버 (Hovered): :hover 또는 [data-hovered="true"]
  • 눌림 (Pressed): :active 또는 [data-pressed="true"]
  • 포커스 표시 (Focus visible): :focus-visible 또는 [data-focus-visible="true"]
  • 비활성화 (Disabled): :disabled 또는 [data-disabled="true"]

API 참고 (API Reference)

Calendar

Calendar는 React Aria Calendar의 모든 prop을 상속받아요.

Prop Type Default Description
selectionMode 'single' | 'multiple' 'single' Whether one or many dates can be selected.
value DateValue | null or DateValue[] | null - Controlled selected date(s). Use an array when selectionMode is multiple.
defaultValue DateValue | null or DateValue[] | null - Initial selected date(s) (uncontrolled).
onChange (value: DateValue | null) or (value: DateValue[] | null) => void - Called when selection changes.
focusedValue DateValue - Controlled focused date.
onFocusChange (value: DateValue) => void - Called when focus moves to another date.
minValue DateValue Calendar-aware 1900-01-01 Earliest selectable date.
maxValue DateValue Calendar-aware 2099-12-31 Latest selectable date.
weeksInMonth number - The number of weeks in a month. This overrides the default set by the locale.
isDateUnavailable (date: DateValue) => boolean - Marks dates as unavailable.
firstDayOfWeek 'sun' | 'mon' | 'tue' | 'wed' | 'thu' | 'fri' | 'sat' - Overrides the locale default for the first day of the week.
pageBehavior 'visible' | 'single' 'visible' Whether paging advances by the visible duration or one unit at a time.
selectionAlignment 'start' | 'center' | 'end' 'center' Aligns the visible range to the selection on initial render.
isDisabled boolean false Disables interaction and selection.
isReadOnly boolean false Keeps content readable but prevents selection changes.
isInvalid boolean false Marks the calendar as invalid for validation UI.
visibleDuration {months?: number; weeks?: number; days?: number} {months: 1} Visible time range. Use { months: n } for month view, { weeks: n } for week view, or { days: n } for day view.
defaultYearPickerOpen boolean false Initial open state of internal year picker.
isYearPickerOpen boolean - Controlled year picker open state.
onYearPickerOpenChange (isOpen: boolean) => void - Called when year picker open state changes.

구성 파트 (Composition Parts)

Component Description
Calendar.Header Header container for navigation and heading.
Calendar.Heading Formatted heading for the visible range. Supports offset (for multi-month layouts) and format (month/year/day options).
Calendar.NavButton Previous/next navigation control (slot="previous" or slot="next").
Calendar.Grid Day grid for one month (offset supported for multi-month layouts).
Calendar.GridHeader Weekday header container.
Calendar.GridBody Date cell body container.
Calendar.HeaderCell Weekday label cell.
Calendar.Cell Individual date cell.
Calendar.CellIndicator Optional indicator element for custom metadata.
Calendar.YearPickerTrigger Trigger to toggle year-picker mode.
Calendar.YearPickerTriggerHeading Localized heading content inside the year-picker trigger.
Calendar.YearPickerTriggerIndicator Toggle icon inside the year-picker trigger.
Calendar.YearPickerGrid Overlay year selection grid container.
Calendar.YearPickerGridBody Body renderer for year grid cells.
Calendar.YearPickerCell Individual year option cell.

연도 선택기 파트 (Year Picker Parts)

연도 선택기 하위 컴포넌트는 React Aria useCalendarHeading와 useCalendarYearPicker에서 포맷 prop을 상속받아요.

Component Prop Type Default Description
Calendar.YearPickerTriggerHeading format DateFormatterOptions - Customize month/year label (e.g. {month: 'short'}).
Calendar.YearPickerTriggerHeading offset {months?: number} - Shift the heading relative to the focused date (multi-month layouts).
Calendar.YearPickerGrid format DateFormatterOptions {year: 'numeric'} Customize year cell labels (era, calendar system, etc.).
Calendar.YearPickerGrid visibleYears number min–max span or 20 Number of years shown in the sliding window. Defaults to the full range between minValue and maxValue when both are set.

Calendar.Cell Render Props

Calendar.Cell 자식이 함수일 때 React Aria 렌더 프롭을 사용할 수 있어요:

Prop Type Description
formattedDate string Localized day label for the cell.
isSelected boolean Whether the date is selected.
isUnavailable boolean Whether the date is unavailable.
isDisabled boolean Whether the cell is disabled.
isOutsideMonth boolean Whether the date belongs to adjacent month.

지원되는 달력 체계와 식별자의 전체 목록은 다음을 참고해요:

  • @internationalized/date — 모든 날짜 컴포넌트가 사용하는 날짜 타입(CalendarDate, CalendarDateTime, ZonedDateTime)과 유틸리티
  • I18nProvider — 하위 트리의 로케일 재정의
  • useLocale — 현재 로케일과 레이아웃 방향 읽기

더 알아보기 (Learn more)