bun add @karrotmarket/lynx-monochrome-icon @seed-design/lynx-react
Copy the code below and paste it in
/** * @file ui:attachment-display-field-reorderable * @requires @seed-design/lynx-react@>=0.8.0 <1.0.0 * @requires @seed-design/lynx-css@>=0.12.0 <1.0.0 * @requires @karrotmarket/lynx-monochrome-icon@>=1.20.0 <2.0.0 **/import * as React from "@lynx-js/react";import IconCameraFill from "@karrotmarket/lynx-monochrome-icon/IconCameraFill";import { AttachmentDisplay as SeedAttachmentDisplay } from "@seed-design/lynx-react";import { AttachmentDisplayItem, type AttachmentDisplayItemProps, type AttachmentDisplayProps,} from "./attachment-display-field";import { HorizontalReorderItem, HorizontalReorderList } from "../lib/attachment-sortable";const LABEL_SELECT_FILE = "파일 선택";let nextReorderInstanceId = 0;type ReorderableContext = Parameters<NonNullable<AttachmentDisplayProps["children"]>>[0];export type AttachmentDisplayReorderableProps = { onTriggerTap: AttachmentDisplayProps["onTriggerTap"]; id?: string; scrollEdgeOffset?: number; onDragStateChange?: (dragging: boolean) => void;} & ( | { children: NonNullable<AttachmentDisplayProps["children"]>; onRetry?: never } | { children?: undefined; onRetry?: AttachmentDisplayProps["onRetry"] });/** * Horizontal native long-press reorder for AttachmentDisplay. * * The gesture only emits a reorder intent; AttachmentDisplay remains the * source of truth for entries and applies disabled/readOnly guards. * * @see https://crispy.carrot-soft.tech/lynx/components/attachment-display-field */export const AttachmentDisplayReorderable = React.forwardRef< React.ComponentRef<typeof SeedAttachmentDisplay.Container>, AttachmentDisplayReorderableProps>(({ onTriggerTap, children, onRetry, id, scrollEdgeOffset, onDragStateChange }, ref) => { const [instanceId] = React.useState(() => nextReorderInstanceId++); const boundaryId = id ? `${id}-container` : `attachment-display-reorder-container-${instanceId}`; const reorderId = id ? `${id}-list` : `attachment-display-reorder-list-${instanceId}`; return ( <SeedAttachmentDisplay.Context> {(context: ReorderableContext) => ( <HorizontalReorderList items={context.entries} getItemKey={(entry) => entry.id} disabled={context.disabled} readOnly={context.readOnly} id={reorderId} scrollableBoundaryId={boundaryId} scrollEdgeOffset={scrollEdgeOffset} onReorder={context.reorderEntry} onDragStateChange={onDragStateChange} > {({ onScroll, dragging }) => ( <SeedAttachmentDisplay.Container ref={ref} id={boundaryId} main-thread:bindscroll={onScroll} enable-scroll={!dragging} > <SeedAttachmentDisplay.Trigger bindtap={() => { "background only"; onTriggerTap({ addEntries: context.addEntries, updateEntryStatus: context.updateEntryStatus, }); }} accessibility-label={LABEL_SELECT_FILE} > <SeedAttachmentDisplay.TriggerIcon image={<IconCameraFill />} /> <SeedAttachmentDisplay.TriggerItemCount /> </SeedAttachmentDisplay.Trigger> <SeedAttachmentDisplay.ItemGroup> {typeof children === "function" ? children(context) : context.entries.map((entry, index) => ( <SortableAttachmentDisplayItem key={entry.id} entry={entry} index={index} {...(onRetry ? { onRetry: () => onRetry(entry, { updateEntryStatus: context.updateEntryStatus }), } : {})} /> ))} </SeedAttachmentDisplay.ItemGroup> </SeedAttachmentDisplay.Container> )} </HorizontalReorderList> )} </SeedAttachmentDisplay.Context> );});AttachmentDisplayReorderable.displayName = "AttachmentDisplayReorderable";export type SortableAttachmentDisplayItemProps = AttachmentDisplayItemProps & { index: number;};export const SortableAttachmentDisplayItem = React.forwardRef< React.ComponentRef<typeof AttachmentDisplayItem>, SortableAttachmentDisplayItemProps>(({ index, entry, ...props }, ref) => ( <HorizontalReorderItem itemId={entry.id} index={index}> {(dragging) => <AttachmentDisplayItem ref={ref} entry={entry} {...props} dragging={dragging} />} </HorizontalReorderItem>));SortableAttachmentDisplayItem.displayName = "SortableAttachmentDisplayItem";/** * This file is a snippet from Crispy, helping you get started quickly with @seed-design/* packages. * You can extend this snippet however you want. */
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.
Compose AttachmentDisplay within AttachmentDisplayField. onTriggerTap is a callback that calls the host media picker and passes the returned entries to addEntries.
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.
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.
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.
Loading Lynx example…
Preparing URL…
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 ( <view className={seedClassName}> <VStack gap="x4" p="x6" width="100%"> <AttachmentDisplayField defaultEntries={[INITIAL_ENTRY]} maxEntries={3}> <AttachmentDisplay onTriggerTap={({ addEntries }) => { // 문서 고정 fixture입니다. 실제 앱에서는 호스트 media picker 결과를 전달하세요. const id = `trigger-added-${nextId.current++}`; addEntries([ { id, thumbnailUrl: `https://picsum.photos/seed/${id}/200/200`, status: "success" }, ]); }} /> </AttachmentDisplayField> </VStack> </view> );}
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.
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.
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.
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.
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.
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.
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.