프리뷰 또는 이전 버전의 문서를 보고 있습니다.seed-design.io 방문
우리는 왜 디자인 엔지니어를 찾게 됐을까
Skip to Content
React

Attachment Display Field

외부 소스에서 제공된 미디어를 URL 기반으로 표시하고 관리하는 컴포넌트입니다.

사용 가능 버전@seed-design/[email protected], @seed-design/[email protected]

Installation

Default

순서 변경이 불필요한 경우 사용할 수 있는 컴포넌트를 포함합니다.

npx @seed-design/cli@latest add ui:attachment-display-field

Reorderable

드래그 앤 드롭을 통한 항목 순서 변경이 필요한 경우 활용할 수 있는 컴포넌트를 포함합니다. 프로젝트에 dnd-kit 의존성이 추가됩니다.

npx @seed-design/cli@latest add ui:attachment-display-field-reorderable

Props

AttachmentDisplayField

Prop

Type

label?React.ReactNode
labelWeight?"bold" | "medium" | undefined

Default

"medium"

indicator?React.ReactNode
description?React.ReactNode
errorMessage?React.ReactNode
showRequiredIndicator?boolean | undefined
controlProps?Omit<SeedAttachmentDisplay.ControlProps, "asChild" | "children"> | undefined
entries?AttachmentDisplayItemEntry[] | undefined
defaultEntries?AttachmentDisplayItemEntry[] | undefined
onEntriesChange?((entries: AttachmentDisplayItemEntry[]) => void) | undefined
disabled?boolean | undefined

Default

false

invalid?boolean | undefined

Default

false

readOnly?boolean | undefined

Default

false

maxEntries?number | undefined

Default

1

AttachmentDisplay

Prop

Type

onTriggerClick(helpers: Pick<AttachmentDisplayContextValue, "addEntries" | "updateEntryStatus">) => void
children?((context: AttachmentDisplayContextValue) => React.ReactNode) | undefined
onRetry?((entry: AttachmentDisplayItemEntry, helpers: Pick<AttachmentDisplayContextValue, "updateEntryStatus">) => void) | undefined

AttachmentDisplayItem

Prop

Type

onRetry?(() => void) | undefined
reorderHandle?React.ReactNode

Rendered before the item contents. Pass an AttachmentDisplay.ItemReorderHandle to make the item reorderable.

entryAttachmentDisplayItemEntry
dragging?boolean | undefined

Shows the item in its dragging state. Pass the drag state from your drag and drop library while the item is being reordered.

Default

false

Usage

기본 사용법

AttachmentDisplayField 안에 AttachmentDisplay 또는 AttachmentDisplayReorderable을 조합하여 사용합니다.

AttachmentDisplay는 HTML <input type="file">을 사용하지 않습니다. onTriggerClick으로 외부 미디어 피커를 호출하고, 콜백 인자로 전달되는 addEntries에 그 결과를 넘겨 표시하세요. addEntries는 maxEntries 상한과 single-mode(maxEntries={1}) 치환을 내부에서 처리하므로, entries를 직접 펼쳐 넣는 것보다 안전합니다.

AttachmentField와 달리 AttachmentDisplayField는 파일의 유효성을 검증하거나 파일 객체를 직접 다루지 않습니다.

import { AttachmentDisplay, AttachmentDisplayField } from "seed-design/ui/attachment-display-field";

<AttachmentDisplayField defaultEntries={[]} maxEntries={10}>
  <AttachmentDisplay
    onTriggerClick={async ({ addEntries }) => {
      const pickedEntries = await openMediaPicker();
      addEntries(pickedEntries);
    }}
  />
</AttachmentDisplayField>;

entries와 onEntriesChange로 목록을 직접 제어하는 controlled 방식도 지원합니다. 이 경우에도 addEntries는 동일하게 동작합니다(Controlled 참고).

Item 직접 구성하기

AttachmentDisplay, AttachmentDisplayReorderable은 children을 render prop으로 사용합니다.

entries를 활용하여 AttachmentDisplayItem을 직접 렌더링할 수 있습니다. 이때 DisplayItemEntry 타입이 제공하는 id를 key로 활용하는 것을 권장합니다.

children을 제공하지 않는 경우 자동으로 entries를 AttachmentDisplayItem으로 렌더링합니다.

import {
  AttachmentDisplay,
  AttachmentDisplayField,
  AttachmentDisplayItem,
} from "seed-design/ui/attachment-display-field";

<AttachmentDisplayField defaultEntries={[]} maxEntries={10}>
  <AttachmentDisplay
    onTriggerClick={async ({ addEntries }) => {
      addEntries(await openMediaPicker());
    }}
  >
    {({ entries }) =>
      entries.map((entry) => (
        <AttachmentDisplayItem key={entry.id} entry={entry} />
      ))
    }
  </AttachmentDisplay>
</AttachmentDisplayField>;

Adding Entries

Trigger

AttachmentDisplay는 trigger(업로드 버튼)가 포함된 레이아웃을 제공합니다. trigger 클릭 시 onTriggerClick 콜백이 실행됩니다. 일반적으로 외부 미디어 피커 호출을 수행합니다. 콜백은 { addEntries, updateEntryStatus }를 인자로 받아, 피커 결과를 추가하고 곧바로 업로드 상태를 갱신할 수 있습니다.

Listening to Entry Changes

entries는 현재 표시되고 있는 항목의 목록입니다. onEntriesChange 콜백으로 entries에 등록된 파일 변경 이벤트를 감지할 수 있습니다.

아이템을 추가하거나 삭제하면 로그가 표시됩니다.

    Managing Item Status

    entries의 각 항목은 pending, uploading, success, error의 status를 가질 수 있습니다. 새로 추가되는 항목의 status 기본값은 의도에 맞게 자유롭게 지정할 수 있습니다(외부 피커가 막 던진 항목이라면 uploading, 이미 업로드 완료된 미디어를 hydrate한다면 success).

    외부 업로드 API와 연동하는 경우, onTriggerClick·onRetry 콜백으로 함께 전달되는 updateEntryStatus 헬퍼를 사용하여 각 항목의 status를 업데이트합니다.

    • uploading: ProgressCircle이 표시됩니다.
      • progress를 설정하여 업로드 진행률을 표시할 수 있습니다.
      • progress를 지정하지 않는 경우 indeterminate 상태로 표시됩니다.
    • error: 재시도 버튼이 표시됩니다.
      • 클릭 시 AttachmentDisplay에 지정한 onRetry 콜백이 (entry, { updateEntryStatus }) 인자로 실행됩니다. updateEntryStatus로 해당 항목을 다시 uploading 상태로 되돌려 업로드를 재시도하세요.

    Reordering Entries

    AttachmentDisplayReorderable을 사용하면 드래그로 항목의 순서를 변경할 수 있습니다.

    해당 컴포넌트는 dnd-kit 의존성 분리를 위해 별도 snippet ui:attachment-display-field-reorderable로 제공됩니다.

    Context를 통해 reorderEntry가 제공되므로, 필요한 경우 원하는 드래그 앤 드롭 동작을 직접 구현하거나, 이미 프로젝트에서 사용 중인 드래그 앤 드롭 라이브러리와 연동하여 사용할 수 있습니다.

    snippet의 SortableAttachmentDisplayItem은 항목마다 순서 변경 버튼인 AttachmentDisplay.ItemReorderHandle을 렌더링합니다. 항목 자체는 목록 항목으로 남으므로 스크린 리더와 키보드에서 순서 변경 버튼과 제거 버튼을 따로 탐색할 수 있습니다. 다른 라이브러리와 연동할 때도 AttachmentDisplay.ItemReorderHandle에 라이브러리의 handle ref와 aria-label을 연결하고, 드래그 중인 항목에는 dragging을 전달하세요.

    Examples

    Disabled

    disabled prop으로 trigger 버튼을 비활성화할 수 있습니다.

    Read Only

    readOnly prop으로 읽기 전용 상태를 표현할 수 있습니다. trigger, 파일 제거 버튼, 순서 변경 모두 비활성화됩니다.

    Controlled

    entries와 onEntriesChange를 사용하여 외부에서 아이템 목록을 제어할 수 있습니다.

      현재 아이템: 0개

      Custom Inset

      --seed-attachment-input-extend-x CSS 변수를 사용하여 스크롤되는 아이템 목록이 레이아웃 바깥으로 빠져나오도록 구성할 수 있습니다.

      controlProps에 extendSafeAreaX를 함께 지정하면 목록이 --seed-attachment-input-extend-x에 좌우 safe area inset을 더한 만큼 넓어져 화면 끝까지 스크롤되고, 첫 항목과 마지막 항목은 safe area 안에 남습니다. AppScreenContent처럼 inset을 반영한 컨테이너 안에서 사용하세요. 화면 끝까지 채우는 다른 방법은 Safe Area 구현 가이드를 참고하세요.

      Field Integration

      label, description, errorMessage 등 Field 관련 prop을 전달할 수 있습니다.

      프로필 사진선택

      Customizing Items

      Snippet이 제공하는 기본 아이템 구성 외에 추가적인 커스터마이징이 필요한 경우, @seed-design/react에서 제공하는 AttachmentDisplay.ItemBadge 등의 요소를 활용하여 직접 아이템을 구성할 수 있습니다.

      아래 예시에서는 AttachmentDisplay.ItemBadge를 사용하여 첫 번째 이미지에 "대표사진" 배지를 표시합니다.

      • 대표사진

      Video Duration

      AttachmentDisplayItemDurationBadge는 동영상의 재생시간을 아이템의 왼쪽 위에 표시합니다. seconds에 초 단위 재생시간을 넘기면 1시간 미만은 2:05, 1시간 이상은 1:02:05 형식으로 표시합니다. 초 미만은 버리고, 24시간을 넘어도 시간 단위로 누적합니다.

      스크린리더에는 "재생시간 1시간 2분 5초" 같은 문구를 aria-label로 제공합니다. 다른 문구가 필요하면 aria-label을 직접 넘기세요. 포맷은 ui:attachment-display-field와 함께 설치되는 lib:format-duration이 처리합니다.

      썸네일 URL과 재생시간은 미디어 피커나 서버에서 받아 Entry와 함께 관리하세요.

      Attachment Display Field vs. Attachment Field

      HTML <input type="file">을 사용해야 하는 경우 AttachmentField를, 외부 소스와 연동하여 URL 기반으로 미디어를 표시해야 하는 경우 AttachmentDisplayField를 사용하세요.

      Attachment FieldAttachment Display
      미디어 소스HTML <input type="file">이미지 URL
      데이터 모델File 기반 FileEntryURL 기반 DisplayItemEntry
      파일 선택<input type="file">다루지 않음 (onTriggerClick 위임)
      드래그 앤 드롭으로 업로드AttachmentDropzone다루지 않음
      파일 검증accept, maxFileSize 등다루지 않음
      Form 연동<input type="file"> 동기화다루지 않음

      Extending to Safe Area

      아래 예제는 좌우에 가상의 inset을 적용합니다. 붉은 빗금은 콘텐츠를 피해야 하는 inset 영역이며, 두 경계선 사이는 안전 영역입니다. 스위치로 확장 전(AS IS)과 확장 후(TO BE)를 비교하고, 배경·스크롤 영역의 경계와 콘텐츠 위치를 확인하세요. 같은 버전에서 옵션을 끄고 켠 비교입니다.

      비교용 inset: 왼쪽 24px · 오른쪽 48px (가상)

      붉은 빗금은 콘텐츠를 피해야 하는 inset 영역이며, 두 경계선 사이는 안전 영역입니다.

      확장 전 (AS IS) · extendSafeAreaX=false
      첨부 이미지

      Last updated on 2026. 11. 27.