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

TimeInput → TimeField 마이그레이션

원문 보기 위키 갱신

HeroUI v2의 TimeInput을 v3의 TimeField로 옮길 때 바뀌는 컴포넌트 구조와 prop을 정리한 가이드예요. v3의 완전한 API와 스타일링 가이드는 공식 문서에서 확인할 수 있어요.

출처: HeroUI

본문

참고: v3 TimeField 문서에서 완전한 API 레퍼런스, 스타일링 가이드, 고급 예시를 확인할 수 있어요. 이 가이드는 HeroUI v2에서 마이그레이션하는 데 집중해요.

구조 변화 (Structure Changes)

v2에서는 TimeInput이 prop을 가진 단일 컴포넌트였어요.

import { TimeInput } from "@heroui/react";

export default function App() {
  return <TimeInput label="Time" name="time" />;
}

v3에서는 TimeField가 DateInputGroup과 세그먼트용 render prop을 가진 compound 컴포넌트를 요구해요.

import { TimeField, DateInputGroup, Label } from "@heroui/react";

export default function App() {
  return (
    <TimeField className="w-[256px]" name="time">
      <Label>Time</Label>
      <DateInputGroup>
        <DateInputGroup.Input>
          {(segment) => <DateInputGroup.Segment segment={segment} />}
        </DateInputGroup.Input>
      </DateInputGroup>
    </TimeField>
  );
}

주요 변화 (Key Changes)

1. 컴포넌트 이름

v2: TimeInput
v3: TimeField

2. 컴포넌트 구조

v2: prop을 가진 단일 컴포넌트
v3: compound 컴포넌트: TimeField(루트) + DateInputGroup과 함께 DateInputGroup.Input(render prop) 및 DateInputGroup.Segment. 선택적으로 DateInputGroup.Prefix와 DateInputGroup.Suffix 사용 가능

3. Prop 변화

v2 Prop v3 위치 설명
label — Label 컴포넌트 사용
description — Description 컴포넌트 사용
errorMessage — FieldError 컴포넌트 사용
value, defaultValue, onChange TimeField 동일 (React Aria)
minValue, maxValue, granularity, placeholderValue TimeField 동일
isRequired, isDisabled, isReadOnly, isInvalid, name TimeField 동일
validationBehavior, shouldForceLeadingZeros TimeField 동일
variant DateInputGroup primary | secondary만으로 단순화됨
fullWidth TimeField 또는 DateInputGroup 루트 또는 그룹에 적용
color — 제거됨 (Tailwind CSS 사용)
size — 제거됨 (Tailwind CSS 사용)
radius — 제거됨 (Tailwind CSS 사용)
labelPlacement — 레이아웃으로 처리
startContent DateInputGroup.Prefix Prefix child 사용
endContent DateInputGroup.Suffix Suffix child 사용
classNames — TimeField와 DateInputGroup 파트에 className 사용
groupProps — DateInputGroup에 className 또는 DOM props 사용
labelProps — Label에 className 사용
fieldProps — DateInputGroup에 className 사용
innerWrapperProps — 그룹/입력 파트에 className 사용
descriptionProps — Description에 className 사용
errorMessageProps — FieldError에 className 사용
inputRef — Ref는 TimeField / React Aria가 처리

마이그레이션 예시 (Migration Examples)

Description과 Error를 함께 쓰는 경우

v2:

<TimeInput
  description="Select start time"
  label="Start time"
  name="startTime"
/>

<TimeInput
  errorMessage="Please enter a valid time"
  isInvalid
  label="Time"
  name="time"
/>

v3:

import { Description, FieldError, Label } from "@heroui/react";

<TimeField className="w-[256px]" name="startTime">
  <Label>Start time</Label>
  <DateInputGroup>
    <DateInputGroup.Input>
      {(segment) => <DateInputGroup.Segment segment={segment} />}
    </DateInputGroup.Input>
  </DateInputGroup>
  <Description>Select start time</Description>
</TimeField>

<TimeField className="w-[256px]" isInvalid name="time">
  <Label>Time</Label>
  <DateInputGroup>
    <DateInputGroup.Input>
      {(segment) => <DateInputGroup.Segment segment={segment} />}
    </DateInputGroup.Input>
  </DateInputGroup>
  <FieldError>Please enter a valid time</FieldError>
</TimeField>

제어되는 컴포넌트 (Controlled)

v2:

import { parseTime } from "@internationalized/date";
import { useState } from "react";

const [value, setValue] = useState(null);

<TimeInput
  label="Time"
  name="time"
  value={value}
  onChange={setValue}
/>

v3:

import type { TimeValue } from "@internationalized/date";
import { useState } from "react";

const [value, setValue] = useState<TimeValue | null>(null);

<TimeField
  className="w-[256px]"
  name="time"
  value={value}
  onChange={setValue}
>
  <Label>Time</Label>
  <DateInputGroup>
    <DateInputGroup.Input>
      {(segment) => <DateInputGroup.Segment segment={segment} />}
    </DateInputGroup.Input>
  </DateInputGroup>
</TimeField>

Min/Max와 Granularity

v2:

import { parseTime } from "@internationalized/date";

<TimeInput
  granularity="minute"
  label="Time"
  maxValue={parseTime("18:00")}
  minValue={parseTime("09:00")}
  name="time"
/>

v3:

import { parseTime } from "@internationalized/date";

<TimeField
  className="w-[256px]"
  granularity="minute"
  maxValue={parseTime("18:00")}
  minValue={parseTime("09:00")}
  name="time"
>
  <Label>Time</Label>
  <DateInputGroup>
    <DateInputGroup.Input>
      {(segment) => <DateInputGroup.Segment segment={segment} />}
    </DateInputGroup.Input>
  </DateInputGroup>
</TimeField>

시작/끝 콘텐츠

v2:

<TimeInput
  endContent={<ClockIcon />}
  label="Time"
  name="time"
  startContent={<ClockIcon />}
/>

v3:

<TimeField className="w-[256px]" name="time">
  <Label>Time</Label>
  <DateInputGroup>
    <DateInputGroup.Prefix>
      <ClockIcon />
    </DateInputGroup.Prefix>
    <DateInputGroup.Input>
      {(segment) => <DateInputGroup.Segment segment={segment} />}
    </DateInputGroup.Input>
    <DateInputGroup.Suffix>
      <ClockIcon />
    </DateInputGroup.Suffix>
  </DateInputGroup>
</TimeField>

컴포넌트 구조 (Component Anatomy)

v3 TimeField는 다음과 같은 구조를 따릅니다.

TimeField (Root)
  ├── Label (optional)
  ├── DateInputGroup
  │   ├── DateInputGroup.Prefix (optional)
  │   ├── DateInputGroup.Input → (segment) => DateInputGroup.Segment
  │   └── DateInputGroup.Suffix (optional)
  ├── Description (optional)
  └── FieldError (optional)

요약 (Summary)

  1. 컴포넌트 이름 변경: TimeInput → TimeField
  2. 컴포넌트 구조: 반드시 compound 컴포넌트를 사용해야 해요: TimeField(루트)와 DateInputGroup이 DateInputGroup.Input(render prop) 및 DateInputGroup.Segment와 함께 사용
  3. Label/Description/Error: 별도 컴포넌트(Label, Description, FieldError)를 사용
  4. Time Props 불변: value, defaultValue, onChange, minValue, maxValue, granularity, placeholderValue, isRequired, isDisabled, isInvalid, name, validationBehavior, shouldForceLeadingZeros는 TimeField에 유지됨
  5. DateInputGroup의 Variant: v3는 DateInputGroup에서 variant="primary"와 variant="secondary"만 지원해요. color, size, radius는 제거됨 - Tailwind CSS 사용
  6. 시작/끝 콘텐츠: startContent/endContent → DateInputGroup.Prefix 및 DateInputGroup.Suffix
  7. 라벨 위치 제거됨: labelPlacement 제거됨 - 레이아웃으로 처리
  8. DOM/Class Props: groupProps, labelProps, fieldProps, classNames 제거됨 - 해당 파트에 className(및 표준 DOM props) 사용

더 알아보기 (Learn more)