Lynx

Attachment Display Field

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

사용 가능 버전@seed-design/[email protected], @seed-design/[email protected]
Lynx 예제를 불러오는 중입니다.

Installation

기본 항목 표시에는 다음 패키지와 기본 snippet을 설치합니다.

npm install @seed-design/lynx-react @seed-design/lynx-css

Reorderable

항목 순서를 변경하려면 네이티브 가로 long-press gesture를 포함한 별도 snippet을 설치합니다. 프로젝트에 @seed-design/lynx-react-sortable 의존성이 추가됩니다.

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

Lynx AttachmentDisplayField는 미디어 picker나 업로드 API를 호출하지 않습니다. 호스트 picker가 반환한 AttachmentDisplayEntry[]를 onTriggerTap callback의 addEntries에 전달해야 합니다. 문서의 picsum.photos URL은 demo fixture이며 실제 앱의 native bridge API를 가정하지 않습니다.

Props

AttachmentDisplayField

Prop

Type

children?React.ReactNode
label?React.ReactNode
labelWeight?"medium" | "bold" | undefined
indicator?React.ReactNode
description?React.ReactNode
errorMessage?React.ReactNode
showRequiredIndicator?boolean | undefined

AttachmentDisplay

Prop

Type

onTriggerTap(helpers: DisplayTriggerHelpers) => void
children?((context: UseAttachmentDisplayContext) => React.ReactNode) | undefined
onRetry?((entry: DisplayEntry, helpers: DisplayRetryHelpers) => void) | undefined

AttachmentDisplayItem

Prop

Type

entryDisplayItemEntry
onRetry?(() => void) | undefined

Usage

onTriggerTap에서 호스트 미디어 picker를 호출하고 반환된 entries를 addEntries에 전달합니다.

<AttachmentDisplayField defaultEntries={[]} maxEntries={10}>
  <AttachmentDisplay
    onTriggerTap={async ({ addEntries }) => {
      const entries = await hostMediaPicker();
      addEntries(entries);
    }}
  />
</AttachmentDisplayField>

hostMediaPicker는 앱이 소유한 adapter이며, 취소하면 []를 반환해야 합니다. Display entry는 URL 기반 모델로 id, thumbnailUrl, status를 사용하고 uploading 상태에서는 progress를 전달할 수 있습니다. AttachmentDisplay는 File, Blob을 다루지 않으며 파일 유효성도 검증하지 않습니다.

Adding Entries

Trigger

기본 AttachmentDisplay의 trigger를 탭하면 onTriggerTap({ addEntries, updateEntryStatus })가 호출됩니다. picker 결과를 addEntries에 전달하면 maxEntries 상한과 single mode(maxEntries={1}) 치환이 적용됩니다.

Lynx 예제를 불러오는 중입니다.

Listening to Entry Changes

entries와 onEntriesChange로 목록을 외부에서 관리할 수 있습니다. 추가와 삭제 결과는 모두 onEntriesChange로 전달됩니다.

Lynx 예제를 불러오는 중입니다.

Managing Item Status

항목의 status는 pending, uploading, success, error 중 하나입니다. 호스트 앱은 updateEntryStatus로 업로드 진행률과 최종 상태를 갱신합니다.

  • uploading: ProgressCircle이 표시되며 progress가 있으면 해당 값(0–100)을 표시합니다.
  • error: onRetry가 있으면 재시도 action이 표시됩니다. 재시도할 때 같은 id를 uploading으로 바꾸고 업로드를 다시 시작합니다.
  • success: 완료된 thumbnail을 표시합니다.

예제의 상태 전이는 demo fixture입니다. 실제 앱에서는 호스트 업로드 결과로 상태를 갱신합니다.

Lynx 예제를 불러오는 중입니다.

Reordering Entries

ui:attachment-display-field-reorderable은 브라우저 dnd-kit 대신 네이티브 가로 long-press gesture로 목록 순서를 변경합니다. disabled와 readOnly에서는 정렬할 수 없습니다.

사용자 지정 항목을 렌더링할 때는 SortableAttachmentDisplayItem에 현재 index를 전달해야 합니다. 스크린 리더는 항목 이름, 순서, 업로드 상태를 읽고 앞·뒤 이동과 파일 제거 동작을 제공합니다. error 상태에 onRetry가 있으면 재시도 동작도 제공합니다. iOS에서는 항목 내부 버튼 대신 이 사용자 지정 접근성 동작을 사용합니다. readOnly에서는 이동과 제거가, disabled에서는 이동만 비활성화됩니다.

Lynx 예제를 불러오는 중입니다.

Examples

Disabled

disabled는 trigger 추가와 정렬 gesture를 막지만, 기존 항목의 remove action은 허용합니다.

Lynx 예제를 불러오는 중입니다.

Read Only

readOnly는 trigger, remove, 정렬 gesture를 모두 막습니다. 외부에서 entries를 갱신하거나 초기 목록을 hydrate하는 것은 허용됩니다.

Lynx 예제를 불러오는 중입니다.

Controlled

entries와 onEntriesChange를 사용하여 외부에서 아이템 목록을 제어할 수 있습니다. 외부 reset은 setEntries([])처럼 앱 state를 갱신하여 수행합니다.

Lynx 예제를 불러오는 중입니다.

Custom Inset

--seed-attachment-input-extend-x CSS 변수를 사용하면 가로 목록을 global gutter 바깥으로 확장할 수 있습니다.

Lynx 예제를 불러오는 중입니다.

Field Integration

Field와 함께 안내 문구와 오류 상태를 표시할 수 있습니다. 예제는 목록이 비었을 때 invalid와 error footer를 표시합니다.

Lynx 예제를 불러오는 중입니다.

Customizing Items

기본 항목 구성을 바꾸는 방법은 다음 예제에서 확인할 수 있습니다. 첫 번째 항목에는 대표 사진 badge가 표시됩니다.

Lynx 예제를 불러오는 중입니다.

State and accessibility

기본 trigger와 remove action에는 접근성 label이 제공됩니다. 사용자 지정 action에는 의미를 설명하는 accessibility-label을 지정해야 합니다.

Lynx 미지원 기능

  • 브라우저 drag-and-drop 및 React dnd-kit은 네이티브 long-press reorder snippet으로 대체합니다.
  • HTML <input type="file">, File, Blob, object URL 대신 호스트 media picker가 URL 기반 AttachmentDisplayEntry를 반환해야 합니다.
  • HTML form 제출 및 react-hook-form 대신 앱 state와 submit adapter를 사용합니다.

Last updated on

목차