Calendar

Calendar (캘린더)

사용자가 날짜를 입력하고 수정할 수 있게 해주는 날짜 필드 컴포넌트예요. 현재 날짜를 보여주는 캘린더부터 날짜 선택기까지 다양하게 활용할 수 있어요.

출처: 문서

본문

소개 (About)

Calendar 컴포넌트는 React DayPicker 위에 만들어졌어요.

설치 (Installation)

CLI Manual
npx shadcn@latest add calendar

다음 의존성을 설치해요.

npm install react-day-picker date-fns

프로젝트에 Button 컴포넌트를 추가해요.

Calendar 컴포넌트는 Button 컴포넌트를 사용해요. 프로젝트에 설치되어 있는지 확인해요.

아래 코드를 프로젝트에 복사해서 붙여넣어요.

import 경로를 프로젝트 설정에 맞게 수정해요.

사용법 (Usage)

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-md border"
  />
)

더 자세한 내용은 React DayPicker 문서를 참고해요.

날짜 선택기 (Date Picker)

<Calendar> 컴포넌트를 이용하면 날짜 선택기를 만들 수 있어요. 자세한 내용은 Date Picker 페이지를 참고해요.

예시 (Examples)

Form

변경 내역 (Changelog)

2024-11-03 day_outside 색상

  • 대비를 개선하기 위해 day_outside 클래스의 색상을 다음과 같이 변경했어요.

    "day_outside:
          "day-outside text-muted-foreground aria-selected:bg-accent/50 aria-selected:text-muted-foreground",
    

더 알아보기 (Learn more)