# Attachment Display Field
URL: /lynx/components/attachment-display-field
Source: https://github.com/daangn/seed-design/blob/dev/docs/content/lynx/components/attachment-display-field.mdx
A component that displays media provided from external sources and manages them through host actions.
사용 가능 버전: @seed-design/lynx-react@0.8.0, @seed-design/lynx-css@0.12.0
## Preview
```tsx
import "@seed-design/lynx-css/base.css";
import type { AttachmentDisplayEntry } from "@seed-design/lynx-react";
import { useRef } from "@lynx-js/react";
import {
AttachmentDisplay,
AttachmentDisplayField,
} from "@/components/ui/attachment-display-field";
import { VStack, useSeedClassName } from "@seed-design/lynx-react";
const FIXTURE_ENTRIES: AttachmentDisplayEntry[] = [
{
id: "fixture-1",
thumbnailUrl: "https://picsum.photos/seed/seed1/200/200",
status: "success",
},
{
id: "fixture-2",
thumbnailUrl: "https://picsum.photos/seed/seed2/200/200",
status: "success",
},
];
export default function AttachmentDisplayPreview() {
const seedClassName = useSeedClassName({ colorMode: "system" });
const nextFixtureId = useRef(0);
return (
{
// 문서 고정 fixture입니다. 실제 앱에서는 호스트 미디어 picker adapter를 전달하세요.
const id = `fixture-added-${nextFixtureId.current++}`;
addEntries([
{
id,
thumbnailUrl: `https://picsum.photos/seed/${id}/200/200`,
status: "success",
},
]);
}}
/>
);
}
```
## Installation
If you only need basic item display, install the following package and default snippet.
- npm: npm install @seed-design/lynx-react @seed-design/lynx-css
- pnpm: pnpm add @seed-design/lynx-react @seed-design/lynx-css
- yarn: yarn add @seed-design/lynx-react @seed-design/lynx-css
- bun: bun add @seed-design/lynx-react @seed-design/lynx-css
### Reorderable
If you need to reorder items, install a separate snippet that includes native horizontal long-press gesture.
- npm: npx @seed-design/cli@latest add ui:attachment-display-field-reorderable
- pnpm: pnpm dlx @seed-design/cli@latest add ui:attachment-display-field-reorderable
- yarn: yarn dlx @seed-design/cli@latest add ui:attachment-display-field-reorderable
- bun: bun x @seed-design/cli@latest add ui:attachment-display-field-reorderable
Lynx `AttachmentDisplayField` does not directly call media picker or upload APIs. When the trigger is tapped, `onTriggerTap` is executed, and pass the `AttachmentDisplayEntry[]` returned by the host app's media picker to the callback's `addEntries`. The `picsum.photos` URL in the documentation examples is a fixed demo fixture and does not assume actual app native module names or bridge APIs.
## Props
### `AttachmentDisplayField`
### `AttachmentDisplay`
### `AttachmentDisplayItem`
## Usage
Compose `AttachmentDisplay` within `AttachmentDisplayField`. `onTriggerTap` is a callback that calls the host media picker and passes the returned entries to `addEntries`.
```tsx
{
const entries = await hostMediaPicker();
addEntries(entries);
}}
/>
```
`hostMediaPicker` is an adapter owned by your app. Do not define specific native module names in snippets or documentation; implement it to return `[]` when cancelled. Display entries use a URL-based model. They use `id`, `thumbnailUrl`, and `status`, and optionally pass `progress` in the `uploading` state. `AttachmentDisplay` does not handle `File` or `Blob` and does not perform file validation.
### Composing Items Directly
The children of `AttachmentDisplay` are context render callbacks. You can directly render `AttachmentDisplayItem` in the order of `entries`, and pass native item root props and `dragging` variant prop to `AttachmentDisplayItem`. If children are omitted, the default image, uploading progress, retry, and remove action composition is automatically rendered.
```tsx
addEntries(await hostMediaPicker())}>
{({ entries }) => entries.map((entry) => )}
```
## Adding Entries
### Trigger
The default `AttachmentDisplay` provides both a trigger and an item list. Tapping the trigger calls `onTriggerTap({ addEntries, updateEntryStatus })`. When passing picker results to `addEntries`, the `maxEntries` limit and single-mode (`maxEntries={1}`) substitution are applied.
```tsx
import "@seed-design/lynx-css/base.css";
import { useRef } from "@lynx-js/react";
import type { AttachmentDisplayEntry } from "@seed-design/lynx-react";
import { VStack, useSeedClassName } from "@seed-design/lynx-react";
import {
AttachmentDisplay,
AttachmentDisplayField,
} from "@/components/ui/attachment-display-field";
const INITIAL_ENTRY: AttachmentDisplayEntry = {
id: "trigger-1",
thumbnailUrl: "https://picsum.photos/seed/trigger1/200/200",
status: "success",
};
export default function AttachmentDisplayTrigger() {
const seedClassName = useSeedClassName({ colorMode: "system" });
const nextId = useRef(0);
return (
{
// 문서 고정 fixture입니다. 실제 앱에서는 호스트 media picker 결과를 전달하세요.
const id = `trigger-added-${nextId.current++}`;
addEntries([
{ id, thumbnailUrl: `https://picsum.photos/seed/${id}/200/200`, status: "success" },
]);
}}
/>
);
}
```
### Listening to Entry Changes
You can manage the list in a controlled manner using `entries` and `onEntriesChange`. Both adding via trigger and tapping delete action results are passed to `onEntriesChange`. The `value-changes` example accumulates and displays added/removed values.
```tsx
import "@seed-design/lynx-css/base.css";
import { useRef, useState } from "@lynx-js/react";
import type { AttachmentDisplayEntry } from "@seed-design/lynx-react";
import { Text, VStack, useSeedClassName } from "@seed-design/lynx-react";
import {
AttachmentDisplay,
AttachmentDisplayField,
} from "@/components/ui/attachment-display-field";
export default function AttachmentDisplayValueChanges() {
const seedClassName = useSeedClassName({ colorMode: "system" });
const [entries, setEntries] = useState([]);
const entriesRef = useRef(entries);
const [logs, setLogs] = useState([]);
const nextId = useRef(0);
entriesRef.current = entries;
const handleEntriesChange = (next: AttachmentDisplayEntry[]) => {
const previous = entriesRef.current;
const added = next.filter((entry) => !previous.some((oldEntry) => oldEntry.id === entry.id));
const removed = previous.filter((entry) => !next.some((newEntry) => newEntry.id === entry.id));
setLogs((current) => [
...current,
...(added.length > 0 ? [`added: ${added.map((entry) => entry.id).join(", ")}`] : []),
...(removed.length > 0 ? [`removed: ${removed.map((entry) => entry.id).join(", ")}`] : []),
]);
entriesRef.current = next;
setEntries(next);
};
return (
{logs.length === 0 ? (
아이템을 추가하거나 삭제하면 로그가 표시됩니다.
) : null}
{logs.map((log, index) => (
{log}
))}
{
// 문서 고정 fixture입니다. 실제 앱에서는 호스트 picker adapter가 반환한 entries를 전달하세요.
const id = `value-change-${nextId.current++}`;
addEntries([
{ id, thumbnailUrl: `https://picsum.photos/seed/${id}/200/200`, status: "success" },
]);
}}
/>
);
}
```
## Managing Item Status
Item status is one of `pending`, `uploading`, `success`, or `error`. Update progress and final status via `updateEntryStatus` in your host app's upload operations.
- `uploading`: `ProgressCircle` is displayed, and if `progress` is present, that value (0–100) is shown.
- `error`: If `onRetry` is provided, a retry action is displayed. In the retry callback, revert the same id to `uploading` and restart the upload.
- `success`: Displays the completed thumbnail.
The example demonstrates both `uploading(0 → 25 → 60) → success` transitions and retry transitions for error items. These transitions are synchronous callbacks for demo fixtures; update with actual host upload results in your app.
```tsx
import "@seed-design/lynx-css/base.css";
import { useRef } from "@lynx-js/react";
import type {
AttachmentDisplayEntry,
AttachmentDisplayStatusDetails,
} from "@seed-design/lynx-react";
import { VStack, useSeedClassName } from "@seed-design/lynx-react";
import {
AttachmentDisplay,
AttachmentDisplayField,
} from "@/components/ui/attachment-display-field";
const INITIAL_ENTRIES: AttachmentDisplayEntry[] = [
{
id: "upload-1",
thumbnailUrl: "https://picsum.photos/seed/upload1/200/200",
status: "uploading",
progress: 30,
},
{ id: "upload-2", thumbnailUrl: "https://picsum.photos/seed/upload2/200/200", status: "success" },
{ id: "upload-3", thumbnailUrl: "https://picsum.photos/seed/upload3/200/200", status: "error" },
];
function runFixtureUpload(
id: string,
updateEntryStatus: (id: string, details: AttachmentDisplayStatusDetails) => void,
) {
"background only";
updateEntryStatus(id, { status: "uploading", progress: 0 });
setTimeout(() => updateEntryStatus(id, { status: "uploading", progress: 25 }), 250);
setTimeout(() => updateEntryStatus(id, { status: "uploading", progress: 60 }), 500);
setTimeout(() => updateEntryStatus(id, { status: "success" }), 750);
}
export default function AttachmentDisplayStatus() {
const seedClassName = useSeedClassName({ colorMode: "system" });
const nextId = useRef(0);
return (
{
// 문서 고정 fixture입니다. 실제 앱에서는 host upload operation을 시작하세요.
const id = `upload-added-${nextId.current++}`;
addEntries([
{
id,
thumbnailUrl: `https://picsum.photos/seed/${id}/200/200`,
status: "uploading",
},
]);
runFixtureUpload(id, updateEntryStatus);
}}
onRetry={(entry, { updateEntryStatus }) =>
runFixtureUpload(entry.id, updateEntryStatus)
}
/>
);
}
```
## Reordering Entries
Lynx does not use React's `dnd-kit` dependency. `AttachmentDisplayReorderable` uses native horizontal long-press gesture from a separate snippet, and when the gesture ends, calls `reorderEntry(fromIndex, toIndex)` to change the list order. Reordering gestures are blocked in `disabled` and `readOnly` states.
The `SortableAttachmentDisplayItem` from the separate snippet requires `index`. The default item map also uses explicit `SortableAttachmentDisplayItem`, and when using custom children callbacks, compose each item directly with that component. Callback results are not re-interpreted with `Children.toArray` or cloned by index.
```tsx
import "@seed-design/lynx-css/base.css";
import IconXmarkFill from "@karrotmarket/lynx-monochrome-icon/IconXmarkFill";
import { useRef, useState } from "@lynx-js/react";
import {
AttachmentDisplay as SeedAttachmentDisplay,
Icon,
VStack,
useSeedClassName,
} from "@seed-design/lynx-react";
import type { AttachmentDisplayEntry } from "@seed-design/lynx-react";
import { AttachmentDisplayField } from "@/components/ui/attachment-display-field";
import {
AttachmentDisplayReorderable,
SortableAttachmentDisplayItem,
} from "@/components/ui/attachment-display-field-reorderable";
const INITIAL_ENTRIES: AttachmentDisplayEntry[] = [
{
id: "reorder-1",
thumbnailUrl: "https://picsum.photos/seed/reorder1/200/200",
status: "success",
},
{
id: "reorder-2",
thumbnailUrl: "https://picsum.photos/seed/reorder2/200/200",
status: "success",
},
{
id: "reorder-3",
thumbnailUrl: "https://picsum.photos/seed/reorder3/200/200",
status: "success",
},
];
export default function AttachmentDisplayReorderableExample() {
const seedClassName = useSeedClassName({ colorMode: "system" });
const [entries, setEntries] = useState(INITIAL_ENTRIES);
const nextId = useRef(0);
return (
{
// 문서 고정 fixture입니다. 실제 앱에서는 호스트 picker 결과를 전달하세요.
const id = `reorder-added-${nextId.current++}`;
addEntries([
{ id, thumbnailUrl: `https://picsum.photos/seed/${id}/200/200`, status: "success" },
]);
}}
>
{({ entries: currentEntries }) =>
currentEntries.map((entry, index) => (
{index === 0 ? (
대표사진
) : null}
} />
))
}
);
}
```
## Examples
### Disabled
`disabled` prevents trigger addition and reordering gestures but allows remove action on existing items.
```tsx
import "@seed-design/lynx-css/base.css";
import type { AttachmentDisplayEntry } from "@seed-design/lynx-react";
import { VStack, useSeedClassName } from "@seed-design/lynx-react";
import {
AttachmentDisplay,
AttachmentDisplayField,
} from "@/components/ui/attachment-display-field";
const INITIAL_ENTRIES: AttachmentDisplayEntry[] = [
{
id: "disabled-1",
thumbnailUrl: "https://picsum.photos/seed/disabled1/200/200",
status: "success",
},
];
export default function AttachmentDisplayDisabled() {
const seedClassName = useSeedClassName({ colorMode: "system" });
return (
{}} />
);
}
```
### Read Only
`readOnly` prevents all trigger, remove, and reordering gestures. External updates to `entries` or hydrating the initial list are still allowed.
```tsx
import "@seed-design/lynx-css/base.css";
import type { AttachmentDisplayEntry } from "@seed-design/lynx-react";
import { VStack, useSeedClassName } from "@seed-design/lynx-react";
import {
AttachmentDisplay,
AttachmentDisplayField,
} from "@/components/ui/attachment-display-field";
const INITIAL_ENTRIES: AttachmentDisplayEntry[] = [
{
id: "readonly-1",
thumbnailUrl: "https://picsum.photos/seed/readonly1/200/200",
status: "success",
},
{
id: "readonly-2",
thumbnailUrl: "https://picsum.photos/seed/readonly2/200/200",
status: "success",
},
];
export default function AttachmentDisplayReadOnly() {
const seedClassName = useSeedClassName({ colorMode: "system" });
return (
{}} />
);
}
```
### Controlled
You can control the item list externally using `entries` and `onEntriesChange`. External reset is performed by updating app state like `setEntries([])`.
```tsx
import "@seed-design/lynx-css/base.css";
import { useRef, useState } from "@lynx-js/react";
import type { AttachmentDisplayEntry } from "@seed-design/lynx-react";
import { ActionButton, HStack, Text, VStack, useSeedClassName } from "@seed-design/lynx-react";
import {
AttachmentDisplay,
AttachmentDisplayField,
} from "@/components/ui/attachment-display-field";
export default function AttachmentDisplayControlled() {
const seedClassName = useSeedClassName({ colorMode: "system" });
const [entries, setEntries] = useState([]);
const nextId = useRef(0);
return (
{
// 문서 고정 fixture입니다. 실제 앱에서는 호스트 picker 결과를 전달하세요.
const id = `controlled-${nextId.current++}`;
addEntries([
{ id, thumbnailUrl: `https://picsum.photos/seed/${id}/200/200`, status: "success" },
]);
}}
/>
현재 아이템: {entries.length}개 setEntries([])}>전체 삭제
);
}
```
### Custom Inset
In a layout wrapping an actual horizontal scroll-view, you can extend the list beyond the global gutter using the `--seed-attachment-input-extend-x` CSS variable. The example includes a 400px gray outer container with TextField/AttachmentDisplay inside.
```tsx
import "@seed-design/lynx-css/base.css";
import * as React from "@lynx-js/react";
import { useRef } from "@lynx-js/react";
import type { AttachmentDisplayEntry } from "@seed-design/lynx-react";
import { useSeedClassName, VStack } from "@seed-design/lynx-react";
import {
AttachmentDisplay,
AttachmentDisplayField,
} from "@/components/ui/attachment-display-field";
import { TextField, TextFieldInput } from "@/components/ui/text-field";
type AttachmentDisplayFieldStyle = NonNullable<
React.ComponentProps["style"]
> & {
"--seed-attachment-input-extend-x": string;
};
const INSET_STYLE: AttachmentDisplayFieldStyle = {
"--seed-attachment-input-extend-x": "var(--seed-dimension-spacing-x-global-gutter)",
};
const INITIAL_ENTRIES: AttachmentDisplayEntry[] = Array.from({ length: 8 }, (_, index) => ({
id: `inset-${index + 1}`,
thumbnailUrl: `https://picsum.photos/seed/inset${index + 1}/200/200`,
status: "success",
}));
export default function AttachmentDisplayCustomInset() {
const seedClassName = useSeedClassName({ colorMode: "system" });
const nextId = useRef(0);
return (
{
// 문서 고정 fixture입니다. 실제 앱에서는 호스트 picker 결과를 전달하세요.
const id = `inset-added-${nextId.current++}`;
addEntries([
{
id,
thumbnailUrl: `https://picsum.photos/seed/${id}/200/200`,
status: "success",
},
]);
}}
/>
);
}
```
### Field Integration
You can use `label`, `indicator`, `description`, `errorMessage`, and `showRequiredIndicator` together with Field slots. The example displays `invalid` and error footer when the list is empty.
```tsx
import "@seed-design/lynx-css/base.css";
import { useRef, useState } from "@lynx-js/react";
import type { AttachmentDisplayEntry } from "@seed-design/lynx-react";
import { VStack, useSeedClassName } from "@seed-design/lynx-react";
import {
AttachmentDisplay,
AttachmentDisplayField,
} from "@/components/ui/attachment-display-field";
const INITIAL_ENTRY: AttachmentDisplayEntry = {
id: "field-1",
thumbnailUrl: "https://picsum.photos/seed/field1/200/200",
status: "success",
};
export default function AttachmentDisplayFieldExample() {
const seedClassName = useSeedClassName({ colorMode: "system" });
const [entries, setEntries] = useState([INITIAL_ENTRY]);
const nextId = useRef(0);
const invalid = entries.length < 1;
return (
{
// 문서 고정 fixture입니다. 실제 앱에서는 호스트 picker 결과를 전달하세요.
const id = `field-added-${nextId.current++}`;
addEntries([
{ id, thumbnailUrl: `https://picsum.photos/seed/${id}/200/200`, status: "success" },
]);
}}
/>
);
}
```
### Customizing Items
For non-default item compositions, use `SeedAttachmentDisplay.Item` compound slots to compose badge, progress, retry, and remove actions directly. The first fixture in the example has a representative photo badge.
```tsx
import "@seed-design/lynx-css/base.css";
import IconArrowClockwiseCircularFill from "@karrotmarket/lynx-monochrome-icon/IconArrowClockwiseCircularFill";
import IconXmarkFill from "@karrotmarket/lynx-monochrome-icon/IconXmarkFill";
import { useRef, useState } from "@lynx-js/react";
import {
AttachmentDisplay as SeedAttachmentDisplay,
Icon,
VStack,
useSeedClassName,
} from "@seed-design/lynx-react";
import type { AttachmentDisplayEntry } from "@seed-design/lynx-react";
import {
AttachmentDisplay,
AttachmentDisplayField,
} from "@/components/ui/attachment-display-field";
import { ProgressCircle } from "@/components/ui/progress-circle";
const INITIAL_ENTRIES: AttachmentDisplayEntry[] = [
{
id: "customizing-1",
thumbnailUrl: "https://picsum.photos/seed/customizing1/200/200",
status: "success",
},
{
id: "customizing-2",
thumbnailUrl: "https://picsum.photos/seed/customizing2/200/200",
status: "success",
},
{
id: "customizing-3",
thumbnailUrl: "https://picsum.photos/seed/customizing3/200/200",
status: "success",
},
];
export default function AttachmentDisplayCustomizingItems() {
const seedClassName = useSeedClassName({ colorMode: "system" });
const [entries, setEntries] = useState(INITIAL_ENTRIES);
const nextId = useRef(0);
return (
{
// 문서 고정 fixture입니다. 실제 앱에서는 호스트 picker 결과를 전달하세요.
const id = `customizing-added-${nextId.current++}`;
addEntries([
{ id, thumbnailUrl: `https://picsum.photos/seed/${id}/200/200`, status: "success" },
]);
}}
>
{({ entries: currentEntries }) =>
currentEntries.map((entry, index) => (
))
}
);
}
function CustomImageItem({ entry, isCover }: { entry: AttachmentDisplayEntry; isCover: boolean }) {
return (
{isCover ? (
대표사진
) : null}
{(item) => (
)}
{}}>
} />
재시도
} />
);
}
```
## State and Accessibility
`label`, `description`, `errorMessage`, `indicator`, and `showRequiredIndicator` are rendered as Field slots. The default trigger and remove action have accessibility labels provided. When composing custom actions, specify an `accessibility-label` that explains the meaning.
## Unsupported Lynx Features
- Browser drag-and-drop and React `dnd-kit`: Replace with native long-press reorder snippet.
- HTML ``, `File`, `Blob`, object URL: Configure the host media picker to return URL-based `AttachmentDisplayEntry`.
- HTML form submission and `react-hook-form`: Replace with app state and submit/controller adapter.