# Attachment Field URL: /lynx/components/attachment-field Source: https://github.com/daangn/seed-design/blob/dev/docs/content/lynx/components/attachment-field.mdx A component that receives host native file selection results and displays and manages attachment items. 사용 가능 버전: @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 { NativeFile } from "@seed-design/lynx-react"; import { AttachmentField, AttachmentInput } from "@/components/ui/attachment-field"; import { VStack, useSeedClassName } from "@seed-design/lynx-react"; // 문서 고정 fixture입니다. 실제 앱에서는 호스트가 제공하는 파일 선택 adapter를 전달하세요. const FIXTURE_FILES: NativeFile[] = [ { uri: "fixture://attachment-field/document.pdf", name: "document.pdf", type: "application/pdf", size: 5, }, ]; export default function AttachmentFieldPreview() { const seedClassName = useSeedClassName({ colorMode: "system" }); return ( FIXTURE_FILES} > ); } ``` ## Installation ### Default Install the default snippet if reordering is not needed. - npm: npx @seed-design/cli@latest add ui:attachment-field - pnpm: pnpm dlx @seed-design/cli@latest add ui:attachment-field - yarn: yarn dlx @seed-design/cli@latest add ui:attachment-field - bun: bun x @seed-design/cli@latest add ui:attachment-field ### Reorderable Install a separate snippet to change the order of attachment items using native horizontal long-press gestures. The default snippet does not include the reorder gesture. - npm: npx @seed-design/cli@latest add ui:attachment-field-reorderable - pnpm: pnpm dlx @seed-design/cli@latest add ui:attachment-field-reorderable - yarn: yarn dlx @seed-design/cli@latest add ui:attachment-field-reorderable - bun: bun x @seed-design/cli@latest add ui:attachment-field-reorderable Lynx `AttachmentField` does not create a browser file input. Pass the native file selection adapter provided by the host to `onSelectFiles`. The `fixture://` URI and fixed images in this document are document fixtures, not working pickers. ## Props ### `AttachmentField` ### `AttachmentInput` ### `AttachmentInputItem` ## Usage Combine `AttachmentInput` inside `AttachmentField`. The host adapter passed to `onSelectFiles` returns `NativeFile[]` or `Promise`. Return an empty array if selection is canceled. Errors from the adapter are passed to `onSelectError`. ```tsx import { AttachmentField, AttachmentInput } from "@/components/ui/attachment-field"; ; ``` `NativeFile` consists of `uri`, `name`, `type`, `size`, and optional `previewUrl`. `File`, `Blob`, HTML ``, and object URLs are not used. When `accept` is set to images only, image items are displayed; if `previewUrl` is missing, `uri` is used. In general file mode, a file icon, name, and size are displayed. Files returned by the host adapter are validated by `AttachmentInput` using `accept`, `maxFiles`, `minFileSize`, `maxFileSize`, and `validate` conditions. The picker's MIME filter is only for UI convenience; final validation must be performed by the app and upload server. If the adapter returns an empty array indicating cancellation, the list remains unchanged. ### Directly Constructing Items `AttachmentInput` supports context render prop. You can directly render `acceptedFileEntries` as `AttachmentInputItem` and update the app's upload status using `updateFileEntryStatus`. ```tsx {({ acceptedFileEntries }) => acceptedFileEntries.map((fileEntry) => ( ))} ; ``` `AttachmentInputItemProps` includes the root native props of the actual `AttachmentInput.Item`, so `id`, accessibility props, style, `dragging`, etc. can be passed. `fileEntry` is required; if `onRetry` is passed, a retry action appears in error state. ## Uploading Files ### Trigger The default `AttachmentInput` provides both file selection trigger and attachment item list. Tapping the trigger calls the host adapter and returned files are added to the list. ```tsx import "@seed-design/lynx-css/base.css"; import type { AttachmentFileEntry, NativeFile } from "@seed-design/lynx-react"; import { AttachmentField, AttachmentInput } from "@/components/ui/attachment-field"; import { VStack, useSeedClassName } from "@seed-design/lynx-react"; const DEFAULT_FILES: AttachmentFileEntry[] = [ { id: "document", file: { uri: "fixture://attachment-field/document.pdf", name: "document.pdf", type: "application/pdf", size: 5, }, status: "success", }, ]; const PICKED_FILES: NativeFile[] = [ { uri: "fixture://attachment-field/photo.png", name: "photo.png", type: "image/png", size: 8, previewUrl: "https://picsum.photos/seed/attachment-trigger/200/200", }, ]; export default function AttachmentFieldTrigger() { const seedClassName = useSeedClassName({ colorMode: "system" }); return ( PICKED_FILES} > ); } ``` ### Listening to Accepted File Changes `acceptedFileEntries` is the list of validated files. `onAcceptedFileEntriesChange` passes list changes including additions, deletions, status changes, and reordering. Run the following example to see upload callback and logs together. ```tsx import "@seed-design/lynx-css/base.css"; import { useState } from "@lynx-js/react"; import type { NativeFile } from "@seed-design/lynx-react"; import { AttachmentField, AttachmentInput, AttachmentInputItem, } from "@/components/ui/attachment-field"; import { Text, VStack, useSeedClassName } from "@seed-design/lynx-react"; const PICKED_FILES: NativeFile[] = [ { uri: "fixture://attachment-field/value-changes.txt", name: "value-changes.txt", type: "text/plain", size: 12, }, ]; export default function AttachmentFieldValueChanges() { const seedClassName = useSeedClassName({ colorMode: "system" }); const [logs, setLogs] = useState([]); const addLog = (message: string) => setLogs((previous) => [...previous, message]); return ( {logs.length === 0 ? ( 파일을 추가하거나 삭제하면 로그가 표시됩니다. ) : ( logs.map((log, index) => ( {log} )) )} PICKED_FILES} onFileAccept={(entries, { updateFileEntryStatus }) => { addLog(`onFileAccept: ${entries.map((entry) => entry.file.name).join(", ")}`); for (const entry of entries) { updateFileEntryStatus(entry.id, { status: "uploading", progress: 0 }); setTimeout( () => updateFileEntryStatus(entry.id, { status: "uploading", progress: 50 }), 250, ); setTimeout(() => updateFileEntryStatus(entry.id, { status: "success" }), 500); } }} onAcceptedFileEntriesChange={(entries) => addLog( `onAcceptedFileEntriesChange: ${entries.map((entry) => `${entry.file.name} (${entry.status})`).join(", ")}`, ) } onFileReject={(files) => addLog( `onFileReject: ${files.map((file) => `${file.file.name} (${file.errors.join(", ")})`).join(", ")}`, ) } > {({ acceptedFileEntries }) => acceptedFileEntries.map((fileEntry) => ( )) } ); } ``` ## Validating Files ### Max Files `maxFiles` limits the final file count at the package level. Passing a limit or filter to the picker is supplementary for UX; excess results are rejected as `TOO_MANY_FILES`. ```tsx import "@seed-design/lynx-css/base.css"; import type { AttachmentFileEntry, NativeFile } from "@seed-design/lynx-react"; import { AttachmentField, AttachmentInput } from "@/components/ui/attachment-field"; import { VStack, useSeedClassName } from "@seed-design/lynx-react"; const DEFAULT_FILES: AttachmentFileEntry[] = [ { id: "document", file: { uri: "fixture://attachment-field/document.pdf", name: "document.pdf", type: "application/pdf", size: 5, }, status: "success", }, ]; const PICKED_FILES: NativeFile[] = [ { uri: "fixture://attachment-field/one.txt", name: "one.txt", type: "text/plain", size: 1 }, { uri: "fixture://attachment-field/two.txt", name: "two.txt", type: "text/plain", size: 1 }, { uri: "fixture://attachment-field/three.txt", name: "three.txt", type: "text/plain", size: 1 }, ]; export default function AttachmentFieldMaxFiles() { const seedClassName = useSeedClassName({ colorMode: "system" }); return ( PICKED_FILES} > ); } ``` ### Invalid File Type `accept` accepts MIME types (`image/png`, `image/*`) or file extension patterns. Files returned by bypassing host picker limits also undergo package validation and `onFileReject` is called with `INVALID_TYPE`. ```tsx import "@seed-design/lynx-css/base.css"; import { useRef, useState } from "@lynx-js/react"; import type { NativeFile } from "@seed-design/lynx-react"; import { AttachmentField, AttachmentInput } from "@/components/ui/attachment-field"; import { VStack, useSeedClassName } from "@seed-design/lynx-react"; const INVALID_FILE: NativeFile = { uri: "fixture://attachment-field/document.pdf", name: "document.pdf", type: "application/pdf", size: 5, }; const VALID_FILE: NativeFile = { uri: "fixture://attachment-field/photo.jpg", name: "photo.jpg", type: "image/jpeg", size: 8, previewUrl: "https://picsum.photos/seed/attachment-invalid/200/200", }; export default function AttachmentFieldInvalidFileType() { const seedClassName = useSeedClassName({ colorMode: "system" }); const pickCount = useRef(0); const [errorMessage, setErrorMessage] = useState(); return ( [pickCount.current++ === 0 ? INVALID_FILE : VALID_FILE]} onAcceptedFileEntriesChange={() => setErrorMessage(undefined)} onFileReject={(files) => setErrorMessage( files .map( ({ file, errors }) => `"${file.name}": ${errors.includes("INVALID_TYPE") ? "지원하지 않는 파일 형식입니다" : "업로드에 실패했습니다"}`, ) .join("\n"), ) } > ); } ``` ### File Size `minFileSize` and `maxFileSize` validate `NativeFile.size` (bytes). If out of range, they are rejected as `FILE_TOO_SMALL` and `FILE_TOO_LARGE` respectively. ```tsx import "@seed-design/lynx-css/base.css"; import { useRef, useState } from "@lynx-js/react"; import type { NativeFile } from "@seed-design/lynx-react"; import { AttachmentField, AttachmentInput } from "@/components/ui/attachment-field"; import { VStack, useSeedClassName } from "@seed-design/lynx-react"; const MIN_FILE_SIZE = 1024; const MAX_FILE_SIZE = 10 * 1024; const SMALL_FILE: NativeFile = { uri: "fixture://attachment-field/small.txt", name: "small.txt", type: "text/plain", size: 1, }; const VALID_FILE: NativeFile = { uri: "fixture://attachment-field/valid.txt", name: "valid.txt", type: "text/plain", size: 2048, }; export default function AttachmentFieldValidation() { const seedClassName = useSeedClassName({ colorMode: "system" }); const pickCount = useRef(0); const [errorMessage, setErrorMessage] = useState(); return ( [pickCount.current++ === 0 ? SMALL_FILE : VALID_FILE]} onAcceptedFileEntriesChange={() => setErrorMessage(undefined)} onFileReject={(files) => setErrorMessage( files .map( ({ file, errors }) => `"${file.name}": ${errors.includes("FILE_TOO_SMALL") ? "크기가 1KB 미만입니다" : errors.includes("FILE_TOO_LARGE") ? "크기가 10KB를 초과합니다" : "업로드에 실패했습니다"}`, ) .join("\n"), ) } > ); } ``` ### Custom Validation `validate` returns an array of custom error codes or `null` for each `NativeFile`. Convert to messages matching your app in `onFileReject`. ```tsx import "@seed-design/lynx-css/base.css"; import { useRef, useState } from "@lynx-js/react"; import type { NativeFile } from "@seed-design/lynx-react"; import { AttachmentField, AttachmentInput } from "@/components/ui/attachment-field"; import { VStack, useSeedClassName } from "@seed-design/lynx-react"; const LONG_NAME_FILE: NativeFile = { uri: "fixture://attachment-field/filename-too-long.txt", name: "filename-too-long.txt", type: "text/plain", size: 5, }; const VALID_FILE: NativeFile = { uri: "fixture://attachment-field/short.txt", name: "short.txt", type: "text/plain", size: 5, }; export default function AttachmentFieldCustomValidation() { const seedClassName = useSeedClassName({ colorMode: "system" }); const pickCount = useRef(0); const [errorMessage, setErrorMessage] = useState(); return ( file.name.replace(/\.[^.]+$/, "").length > 8 ? ["FILENAME_TOO_LONG"] : null } invalid={!!errorMessage} errorMessage={errorMessage} label="파일 업로드" description="파일 이름은 확장자를 제외하고 8자 이하여야 합니다" onSelectFiles={() => [pickCount.current++ === 0 ? LONG_NAME_FILE : VALID_FILE]} onAcceptedFileEntriesChange={() => setErrorMessage(undefined)} onFileReject={(files) => { if (files.every((file) => file.errors.includes("FILENAME_TOO_LONG"))) setErrorMessage( `"${files.map((file) => file.file.name).join(", ")}"은(는) 파일 이름이 8자를 초과합니다.`, ); }} > ); } ``` ## Managing File Status Each item has `pending`, `uploading`, `success`, `error` states. Newly added items start as `pending`. Start your app's upload job in `onFileAccept` and update `uploading` progress, `success`, `error` with the helper. The actual upload API and retry policy are owned by the host app. ```tsx import "@seed-design/lynx-css/base.css"; import { useRef } from "@lynx-js/react"; import type { AttachmentFileStatusDetails, NativeFile } from "@seed-design/lynx-react"; import { AttachmentField, AttachmentInput } from "@/components/ui/attachment-field"; import { VStack, useSeedClassName } from "@seed-design/lynx-react"; const PICKED_FILE: NativeFile = { uri: "fixture://attachment-field/status.png", name: "status.png", type: "image/png", size: 8, previewUrl: "https://picsum.photos/seed/attachment-status/200/200", }; export default function AttachmentFieldStatus() { const seedClassName = useSeedClassName({ colorMode: "system" }); const attempts = useRef>({}); const startUpload = ( id: string, update: (entryId: string, details: AttachmentFileStatusDetails) => void, ) => { attempts.current[id] = (attempts.current[id] ?? 0) + 1; update(id, { status: "uploading", progress: 0 }); setTimeout(() => update(id, { status: "uploading", progress: 50 }), 250); setTimeout(() => update(id, { status: attempts.current[id] === 1 ? "error" : "success" }), 500); }; return ( [PICKED_FILE]} onFileAccept={(entries, { updateFileEntryStatus }) => { for (const entry of entries) startUpload(entry.id, updateFileEntryStatus); }} > startUpload(entry.id, updateFileEntryStatus) } /> ); } ``` - `uploading`: `ProgressCircle` is displayed. Without progress, it shows indeterminate state. Image mode uses `staticWhite` tone to be visible over images. - `error`: If `onRetry` is provided, retry action is shown. In the retry callback, change the same id back to `uploading` and resume app upload. - If picker throws synchronously or returns a rejected Promise, `onSelectError` is called and the existing list is preserved. ## Reordering Files `AttachmentInputReorderable` in `ui:attachment-field-reorderable` uses native horizontal long-press gesture instead of browser `dnd-kit`. When the gesture ends, `reorderFileEntry(fromIndex, toIndex)` is called and the list order changes. Drag is blocked in `disabled` and `readOnly` states. The default item snippet is composed of `SortableAttachmentInputItem`. When composing directly, pass the context as-is and must pass `index` to the exported `SortableAttachmentInputItem`. Do not remap or clone callback results with `Children.toArray`. ```tsx import { AttachmentInputReorderable, SortableAttachmentInputItem, } from "@/components/ui/attachment-field-reorderable"; {({ acceptedFileEntries }) => acceptedFileEntries.map((fileEntry, index) => ( ))} ; ``` ```tsx import "@seed-design/lynx-css/base.css"; import IconXmarkFill from "@karrotmarket/lynx-monochrome-icon/IconXmarkFill"; import type { AttachmentFileEntry, NativeFile } from "@seed-design/lynx-react"; import { AttachmentInput as SeedAttachmentInput, Icon, VStack, useSeedClassName, } from "@seed-design/lynx-react"; import { ProgressCircle } from "@/components/ui/progress-circle"; import { AttachmentField } from "@/components/ui/attachment-field"; import { AttachmentInputReorderable, SortableAttachmentInputItem, } from "@/components/ui/attachment-field-reorderable"; const PIXEL_SUNSET = "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAIAAACQd1PeAAAADElEQVR4nGN4FcEDAAN+AU+hW/ICAAAAAElFTkSuQmCC"; const PIXEL_CITY = "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAIAAACQd1PeAAAADElEQVR4nGOYbPwKAAMNAbHKe2UaAAAAAElFTkSuQmCC"; const PIXEL_COFFEE = "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAIAAACQd1PeAAAADElEQVR4nGN4tZkDAAQwAaYlKXDxAAAAAElFTkSuQmCC"; function createFixture(name: string, data: string): NativeFile { return { uri: `fixture://attachment-field/${name}`, name, type: "image/png", size: 1, previewUrl: `data:image/png;base64,${data}`, }; } const DEFAULT_FILES: AttachmentFileEntry[] = [ { id: "1", file: createFixture("sunset-landscape.png", PIXEL_SUNSET), status: "success" }, { id: "2", file: createFixture("city-night.png", PIXEL_CITY), status: "success" }, { id: "3", file: createFixture("morning-coffee.png", PIXEL_COFFEE), status: "success" }, ]; function SortableImageItem({ fileEntry, index, isCover, }: { fileEntry: AttachmentFileEntry; index: number; isCover: boolean; }) { return ( {(dragging) => ( {isCover ? ( 대표사진 ) : null} {(entry) => ( )} } /> )} ); } export default function AttachmentFieldReorderable() { const seedClassName = useSeedClassName({ colorMode: "system" }); return ( {({ acceptedFileEntries }) => acceptedFileEntries.map((fileEntry, index) => ( )) } ); } ``` ## Examples ### Showing Thumbnails Allow only image files with `accept="image/*"` and display thumbnail using `previewUrl` returned by the host. ```tsx import "@seed-design/lynx-css/base.css"; import { useRef, useState } from "@lynx-js/react"; import type { NativeFile } from "@seed-design/lynx-react"; import { AttachmentField, AttachmentInput } from "@/components/ui/attachment-field"; import { VStack, useSeedClassName } from "@seed-design/lynx-react"; const IMAGE_FILE: NativeFile = { uri: "fixture://attachment-field/photo.png", name: "photo.png", type: "image/png", size: 8, previewUrl: "https://picsum.photos/seed/attachment-image/200/200", }; const OTHER_FILE: NativeFile = { uri: "fixture://attachment-field/readme.pdf", name: "readme.pdf", type: "application/pdf", size: 5, }; export default function AttachmentFieldAcceptImage() { const seedClassName = useSeedClassName({ colorMode: "system" }); const pickCount = useRef(0); const [errorMessage, setErrorMessage] = useState(); return ( [pickCount.current++ === 0 ? IMAGE_FILE : OTHER_FILE]} onAcceptedFileEntriesChange={() => setErrorMessage(undefined)} onFileReject={() => setErrorMessage("지원하지 않는 파일 형식입니다")} > ); } ``` ### Disabled `disabled` blocks trigger and add/sort operations. In the Lynx contract, deletion of existing items is allowed, so use `readOnly` or app policy if you need to block deletion as well. ```tsx import "@seed-design/lynx-css/base.css"; import type { AttachmentFileEntry, NativeFile } from "@seed-design/lynx-react"; import { AttachmentField, AttachmentInput } from "@/components/ui/attachment-field"; import { VStack, useSeedClassName } from "@seed-design/lynx-react"; const DEFAULT_FILES: AttachmentFileEntry[] = [ { id: "document", file: { uri: "fixture://attachment-field/document.pdf", name: "document.pdf", type: "application/pdf", size: 5, }, status: "success", }, { id: "image", file: { uri: "fixture://attachment-field/image.png", name: "image.png", type: "image/png", size: 8, previewUrl: "https://picsum.photos/seed/attachment-disabled/200/200", }, status: "success", }, ]; export default function AttachmentFieldDisabled() { const seedClassName = useSeedClassName({ colorMode: "system" }); return ( ); } ``` ### Read Only `readOnly` blocks trigger, add, delete, clear, and sort operations. Externally hydrating or updating controlled state is allowed. ```tsx import "@seed-design/lynx-css/base.css"; import type { AttachmentFileEntry, NativeFile } from "@seed-design/lynx-react"; import { AttachmentField, AttachmentInput } from "@/components/ui/attachment-field"; import { VStack, useSeedClassName } from "@seed-design/lynx-react"; const DEFAULT_FILES: AttachmentFileEntry[] = [ { id: "document", file: { uri: "fixture://attachment-field/document.pdf", name: "document.pdf", type: "application/pdf", size: 5, }, status: "success", }, { id: "image", file: { uri: "fixture://attachment-field/image.png", name: "image.png", type: "image/png", size: 8, previewUrl: "https://picsum.photos/seed/attachment-readonly/200/200", }, status: "success", }, ]; export default function AttachmentFieldReadOnly() { const seedClassName = useSeedClassName({ colorMode: "system" }); return ( ); } ``` ### Controlled The list can be controlled externally using `acceptedFileEntries` and `onAcceptedFileEntriesChange`. ```tsx import "@seed-design/lynx-css/base.css"; import { useState } from "@lynx-js/react"; import type { AttachmentFileEntry, NativeFile } from "@seed-design/lynx-react"; import { ActionButton, HStack, Text, VStack, useSeedClassName } from "@seed-design/lynx-react"; import { AttachmentField, AttachmentInput } from "@/components/ui/attachment-field"; const PICKED_FILE: NativeFile = { uri: "fixture://attachment-field/controlled.txt", name: "controlled.txt", type: "text/plain", size: 5, }; export default function AttachmentFieldControlled() { const seedClassName = useSeedClassName({ colorMode: "system" }); const [acceptedFileEntries, setAcceptedFileEntries] = useState([]); function clearFiles() { "background only"; setAcceptedFileEntries([]); } return ( [PICKED_FILE]} > 현재 파일: {JSON.stringify(acceptedFileEntries.map((entry) => entry.file.name))} 전체 삭제 ); } ``` ### Custom Inset Using the `--seed-attachment-input-extend-x` style variable extends the horizontal item list beyond the global gutter. This is an example using real file metadata and nested fields together. ```tsx import "@seed-design/lynx-css/base.css"; import * as React from "@lynx-js/react"; import type { NativeFile } from "@seed-design/lynx-react"; import { AttachmentField, AttachmentInput } from "@/components/ui/attachment-field"; import { TextField, TextFieldInput } from "@/components/ui/text-field"; import { VStack, useSeedClassName } from "@seed-design/lynx-react"; type AttachmentFieldStyle = NonNullable["style"]> & { "--seed-attachment-input-extend-x": string; }; const INSET_STYLE: AttachmentFieldStyle = { "--seed-attachment-input-extend-x": "var(--seed-dimension-spacing-x-global-gutter)", }; const MOCKED_FILES: NativeFile[] = Array.from({ length: 8 }, (_, index) => ({ uri: `fixture://attachment-field/file${index + 1}.txt`, name: `file${index + 1}.txt`, type: "text/plain", size: 1, })); export default function AttachmentFieldCustomInset() { const seedClassName = useSeedClassName({ colorMode: "system" }); return ( ({ id: `${index}`, file, status: "pending", }))} style={INSET_STYLE} onSelectFiles={() => [MOCKED_FILES[0]]} > ); } ``` ### Field Integration `label`, `description`, `indicator`, `errorMessage`, `required`, `showRequiredIndicator`, `invalid` can be connected to Field slots. Manage `invalid` and messages in your app's submit-equivalent validation instead of HTML form submit. ```tsx import "@seed-design/lynx-css/base.css"; import type { NativeFile } from "@seed-design/lynx-react"; import { AttachmentField, AttachmentInput } from "@/components/ui/attachment-field"; import { Divider, VStack, useSeedClassName } from "@seed-design/lynx-react"; const PICKED_FILE: NativeFile = { uri: "fixture://attachment-field/field.txt", name: "field.txt", type: "text/plain", size: 5, }; export default function AttachmentFieldField() { const seedClassName = useSeedClassName({ colorMode: "system" }); return ( [PICKED_FILE]} > ); } ``` ### Customizing Items Instead of the default item, you can directly combine the package's compound `AttachmentInput.Item` with `ItemBadge`, `ItemBackdrop`, `ProgressCircle`, and action/icon slots. Display the representative badge according to your app's ordering policy. ```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 { AttachmentInput as SeedAttachmentInput, Icon, VStack, useSeedClassName, } from "@seed-design/lynx-react"; import { ProgressCircle } from "@/components/ui/progress-circle"; import type { AttachmentFileEntry, AttachmentFileStatusDetails, NativeFile, } from "@seed-design/lynx-react"; import { AttachmentField, AttachmentInput } from "@/components/ui/attachment-field"; const PICKED_FILE: NativeFile = { uri: "fixture://attachment-field/custom.png", name: "custom.png", type: "image/png", size: 8, previewUrl: "https://picsum.photos/seed/attachment-custom/200/200", }; function CustomImageItem({ fileEntry, isCover, onRetry, }: { fileEntry: AttachmentFileEntry; isCover: boolean; onRetry?: () => void; }) { return ( {isCover ? 대표사진 : null} {(entry) => ( )} {onRetry ? ( } /> 재시도 ) : null} } /> ); } export default function AttachmentFieldCustomizingItems() { const seedClassName = useSeedClassName({ colorMode: "system" }); return ( [PICKED_FILE]} onFileAccept={(entries, { updateFileEntryStatus }) => { for (const entry of entries) { updateFileEntryStatus(entry.id, { status: "uploading", progress: 0 }); setTimeout(() => updateFileEntryStatus(entry.id, { status: "success" }), 500); } }} > {({ acceptedFileEntries, updateFileEntryStatus }) => acceptedFileEntries.map((fileEntry, index) => ( { updateFileEntryStatus(fileEntry.id, { status: "uploading", progress: 0, } satisfies AttachmentFileStatusDetails); setTimeout( () => updateFileEntryStatus(fileEntry.id, { status: "success" }), 500, ); }} /> )) } ); } ``` ## Unsupported Lynx Features and App Alternatives ### Dropzone Browser drag-and-drop events and HTML file input from React `AttachmentDropzone` are not supported in Lynx. No working dropzone example is provided. Instead, connect the native file picker to `onSelectFiles` and map any drag gestures or additional host actions supported by your app to picker calls. Use `ui:attachment-field-reorderable` to change file list order. ### HTML form Lynx has no browser `form`, `FormData`, `input[type=file]` submission path. Maintain app state with `onAcceptedFileEntriesChange` or `onFileAccept`, then pass `NativeFile[]` to the host upload/submit adapter in the submit action. Map server validation errors to Field's `invalid` and `errorMessage`. ### react-hook-form React examples using `react-hook-form` cannot run as-is because they depend on browser file input and form submission paths. In Lynx, connect `acceptedFileEntries` and `onAcceptedFileEntriesChange` to your app state, validate list length and upload status on submit, then update Field error state. ### Browser file APIs `File`, `Blob`, `FileList`, object URLs, and `window.alert` are not used in Native examples. The host adapter must provide `NativeFile`'s `uri`, metadata, and optional `previewUrl`. Return `[]` on cancel, and `onSelectError` receives picker or permission errors.