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
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 (
< view className = {seedClassName}>
< VStack gap = "x4" p = "x6" width = "100%" >
< AttachmentField
maxFiles = { 3 }
label = "파일 업로드"
description = "최대 3개까지 업로드할 수 있습니다"
onSelectFiles = {() => FIXTURE_FILES }
>
< AttachmentInput />
</ AttachmentField >
</ VStack >
</ view >
);
}
Install the default snippet if reordering is not needed.
npx @seed-design/cli@latest add ui:attachment-field pnpm dlx @seed-design/cli@latest add ui:attachment-field yarn dlx @seed-design/cli@latest add ui:attachment-field bun x @seed-design/cli@latest add ui:attachment-field
Install dependencies
npm install @karrotmarket/lynx-monochrome-icon @seed-design/lynx-react yarn add @karrotmarket/lynx-monochrome-icon @seed-design/lynx-react pnpm add @karrotmarket/lynx-monochrome-icon @seed-design/lynx-react bun add @karrotmarket/lynx-monochrome-icon @seed-design/lynx-react Copy the code below and paste it in /**
* @file ui:attachment-field
* @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 IconArrowClockwiseCircularFill from "@karrotmarket/lynx-monochrome-icon/IconArrowClockwiseCircularFill" ;
import IconCameraFill from "@karrotmarket/lynx-monochrome-icon/IconCameraFill" ;
import IconExclamationmarkCircleFill from "@karrotmarket/lynx-monochrome-icon/IconExclamationmarkCircleFill" ;
import IconPaperclipFill from "@karrotmarket/lynx-monochrome-icon/IconPaperclipFill" ;
import IconXmarkFill from "@karrotmarket/lynx-monochrome-icon/IconXmarkFill" ;
import {
AttachmentInput as SeedAttachmentInput,
Field as SeedField,
Icon,
PrefixIcon,
HStack,
useAttachmentInputContext,
} from "@seed-design/lynx-react" ;
import { ProgressCircle } from "./progress-circle" ;
import type {
AttachmentFileEntry,
AttachmentFileStatusDetails,
AttachmentInputRootProps,
NativeFile,
} from "@seed-design/lynx-react" ;
const LABEL_SELECT_FILE = "파일 선택" ;
const LABEL_RETRY = "재시도" ;
const LABEL_REMOVE_FILE = "파일 제거" ;
type FieldRootRef = React . ComponentRef < typeof SeedField.Root>;
type FileEntry = AttachmentFileEntry ;
type AttachmentInputContext = React . ComponentProps < typeof SeedAttachmentInput.Context>;
type RetryHelpers = {
updateFileEntryStatus : ( id : string , details : AttachmentFileStatusDetails ) => void ;
};
export interface AttachmentFieldProps extends Omit < AttachmentInputRootProps , "children" > {
children ?: React . ReactNode ;
label ?: React . ReactNode ;
labelWeight ?: SeedField . LabelProps [ "weight" ];
indicator ?: React . ReactNode ;
description ?: React . ReactNode ;
errorMessage ?: React . ReactNode ;
showRequiredIndicator ?: boolean ;
}
/**
* @see https://crispy.carrot-soft.tech/lynx/components/attachment-field
*/
export const AttachmentField = React. forwardRef < FieldRootRef , AttachmentFieldProps >(
(
{
label,
labelWeight,
indicator,
description,
errorMessage,
showRequiredIndicator,
children,
disabled,
required,
invalid,
readOnly,
... props
},
ref,
) => {
const renderHeader = label != null || indicator != null ;
const renderErrorMessage = errorMessage != null && invalid;
const renderDescription = description != null && ! renderErrorMessage;
const renderFooter = renderDescription || renderErrorMessage;
return (
< SeedField.Root
ref = {ref}
disabled = {disabled}
required = {required}
invalid = {invalid}
readOnly = {readOnly}
>
{renderHeader ? (
< SeedField.Header >
< SeedField.Label weight = {labelWeight}>
{label}
{showRequiredIndicator ? < SeedField.RequiredIndicator /> : null }
{indicator != null ? (
< SeedField.IndicatorText >{indicator}</ SeedField.IndicatorText >
) : null }
</ SeedField.Label >
</ SeedField.Header >
) : null }
< SeedAttachmentInput.Root
{ ... props}
disabled = {disabled}
required = {required}
invalid = {invalid}
readOnly = {readOnly}
>
{children}
</ SeedAttachmentInput.Root >
{renderFooter ? (
< SeedField.Footer >
{renderDescription ? (
< SeedField.Description >{description}</ SeedField.Description >
) : null }
{renderErrorMessage ? (
< HStack gap = "x1_5" align = "flex-start" width = "100%" >
< HStack height = "var(--seed-line-height-t4)" align = "center" shrink = { 0 }>
< PrefixIcon
icon = {< IconExclamationmarkCircleFill />}
size = "x4"
color = "fg.critical"
/>
</ HStack >
< SeedField.ErrorMessage style = {{ flexShrink: 1 }}>
{errorMessage}
</ SeedField.ErrorMessage >
</ HStack >
) : null }
</ SeedField.Footer >
) : null }
</ SeedField.Root >
);
},
);
AttachmentField.displayName = "AttachmentField" ;
export type AttachmentInputProps =
| { children : AttachmentInputContext [ "children" ]; onRetry ?: never }
| {
children ?: undefined ;
onRetry ?: ( fileEntry : FileEntry , helpers : RetryHelpers ) => void ;
};
/**
* @see https://crispy.carrot-soft.tech/lynx/components/attachment-field
*/
export const AttachmentInput = React.forwardRef <
React.ComponentRef <typeof SeedAttachmentInput.Container > ,
AttachmentInputProps
> (({ children , onRetry }, ref ) => {
return (
< SeedAttachmentInput.Container ref = {ref}>
< SeedAttachmentInput.Trigger accessibility-label = { LABEL_SELECT_FILE }>
< SeedAttachmentInput.TriggerIcon
image = {< IconCameraFill />}
general = {< IconPaperclipFill />}
/>
< SeedAttachmentInput.TriggerItemCount />
</ SeedAttachmentInput.Trigger >
< SeedAttachmentInput.ItemGroup >
< SeedAttachmentInput.Context >
{ typeof children === "function"
? children
: ({ acceptedFileEntries , updateFileEntryStatus }) =>
acceptedFileEntries. map (( fileEntry ) => (
< AttachmentInputItem
key = {fileEntry.id}
fileEntry = {fileEntry}
{ ... (onRetry
? { onRetry : () => onRetry (fileEntry, { updateFileEntryStatus }) }
: {})}
/>
))}
</ SeedAttachmentInput.Context >
</ SeedAttachmentInput.ItemGroup >
</ SeedAttachmentInput.Container >
);
});
AttachmentInput.displayName = "AttachmentInput" ;
type AttachmentInputItemNativeProps = Omit <
React . ComponentProps < typeof SeedAttachmentInput.Item>,
"children" | "fileEntry"
>;
export interface AttachmentInputItemProps extends AttachmentInputItemNativeProps {
fileEntry : FileEntry ;
onRetry ?: () => void ;
}
/**
* @see https://crispy.carrot-soft.tech/lynx/components/attachment-field
*/
export const AttachmentInputItem = React.forwardRef <
React.ComponentRef <typeof SeedAttachmentInput.Item > ,
AttachmentInputItemProps
> (({ fileEntry , onRetry , ... itemProps }, ref ) => {
const { acceptType } = useAttachmentInputContext ();
return (
< SeedAttachmentInput.Item ref = {ref} fileEntry = {fileEntry} { ... itemProps}>
< SeedAttachmentInput.ItemSurface >
< SeedAttachmentInput.ItemImage />
< SeedAttachmentInput.ItemThumbnail >
< Icon icon = {< IconPaperclipFill />} />
</ SeedAttachmentInput.ItemThumbnail >
< SeedAttachmentInput.ItemMetadata >
< SeedAttachmentInput.ItemName />
< SeedAttachmentInput.ItemSize />
</ SeedAttachmentInput.ItemMetadata >
< SeedAttachmentInput.ItemBackdrop status = "uploading" >
{( entry ) => (
< ProgressCircle
size = "24"
tone = {acceptType === "image" ? "staticWhite" : "neutral" }
{ ... ( "progress" in entry ? { value: entry.progress } : {})}
/>
)}
</ SeedAttachmentInput.ItemBackdrop >
{onRetry ? (
< SeedAttachmentInput.ItemBackdrop status = "error" >
< SeedAttachmentInput.ItemActionButton bindtap = {onRetry}>
< Icon icon = {< IconArrowClockwiseCircularFill />} />
{ LABEL_RETRY }
</ SeedAttachmentInput.ItemActionButton >
</ SeedAttachmentInput.ItemBackdrop >
) : null }
</ SeedAttachmentInput.ItemSurface >
< SeedAttachmentInput.ItemRemoveButton accessibility-label = { LABEL_REMOVE_FILE }>
< Icon icon = {< IconXmarkFill />} />
</ SeedAttachmentInput.ItemRemoveButton >
</ SeedAttachmentInput.Item >
);
});
AttachmentInputItem.displayName = "AttachmentInputItem" ;
export type { NativeFile };
/**
* This file is a snippet from Crispy, helping you get started quickly with @seed-design/* packages.
* You can extend this snippet however you want.
*/
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.
npx @seed-design/cli@latest add ui:attachment-field-reorderable pnpm dlx @seed-design/cli@latest add ui:attachment-field-reorderable yarn dlx @seed-design/cli@latest add ui:attachment-field-reorderable bun x @seed-design/cli@latest add ui:attachment-field-reorderable
Install dependencies
npm install @karrotmarket/lynx-monochrome-icon @seed-design/lynx-react yarn add @karrotmarket/lynx-monochrome-icon @seed-design/lynx-react pnpm add @karrotmarket/lynx-monochrome-icon @seed-design/lynx-react bun add @karrotmarket/lynx-monochrome-icon @seed-design/lynx-react Copy the code below and paste it in /**
* @file ui:attachment-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 { AttachmentInput as SeedAttachmentInput } from "@seed-design/lynx-react" ;
import IconCameraFill from "@karrotmarket/lynx-monochrome-icon/IconCameraFill" ;
import IconPaperclipFill from "@karrotmarket/lynx-monochrome-icon/IconPaperclipFill" ;
import {
AttachmentInputItem,
type AttachmentInputItemProps,
type AttachmentInputProps,
} from "./attachment-field" ;
import { HorizontalReorderItem, HorizontalReorderList } from "../lib/attachment-sortable" ;
type AttachmentInputContext = React . ComponentProps < typeof SeedAttachmentInput.Context>;
let nextAttachmentReorderId = 0 ;
export type AttachmentInputReorderableProps = {
id ?: string ;
scrollEdgeOffset ?: number ;
onDragStateChange ?: ( dragging : boolean ) => void ;
} & (
| { children : AttachmentInputContext [ "children" ]; onRetry ?: never }
| { children ?: undefined ; onRetry ?: AttachmentInputProps [ "onRetry" ] }
);
/**
* Horizontal native long-press reorder for AttachmentInput.
*
* The gesture only emits a reorder intent; AttachmentInput remains the source
* of truth for entries and applies disabled/readOnly guards.
*
* @see https://crispy.carrot-soft.tech/lynx/components/attachment-field
*/
export const AttachmentInputReorderable = React.forwardRef <
React.ComponentRef <typeof SeedAttachmentInput.Container > ,
AttachmentInputReorderableProps
> (({ children , onRetry , id , scrollEdgeOffset , onDragStateChange }, ref ) => {
const [ generatedId ] = React. useState (() => `instance-${ nextAttachmentReorderId ++ }` );
const boundaryId = id ? `${ id }-container` : `attachment-input-reorder-container-${ generatedId }` ;
const reorderId = id ? `${ id }-list` : `attachment-input-reorder-list-${ generatedId }` ;
return (
< SeedAttachmentInput.Context >
{( context ) => {
const { acceptedFileEntries , reorderFileEntry , disabled , readOnly , updateFileEntryStatus } =
context;
return (
< HorizontalReorderList
items = {acceptedFileEntries}
getItemKey = {( entry ) => entry.id}
disabled = {disabled}
readOnly = {readOnly}
id = {reorderId}
scrollableBoundaryId = {boundaryId}
scrollEdgeOffset = {scrollEdgeOffset}
onReorder = {reorderFileEntry}
onDragStateChange = {onDragStateChange}
>
{({ onScroll , dragging }) => (
< SeedAttachmentInput.Container
ref = {ref}
id = {boundaryId}
enable-scroll = { ! dragging}
main-thread : bindscroll = {onScroll}
>
< SeedAttachmentInput.Trigger accessibility-label = "파일 선택" >
< SeedAttachmentInput.TriggerIcon
image = {< IconCameraFill />}
general = {< IconPaperclipFill />}
/>
< SeedAttachmentInput.TriggerItemCount />
</ SeedAttachmentInput.Trigger >
< SeedAttachmentInput.ItemGroup >
< SeedAttachmentInput.Context >
{ typeof children === "function"
? children
: ({ acceptedFileEntries : entries }) =>
entries. map (( fileEntry , index ) => (
< SortableAttachmentInputItem
key = {fileEntry.id}
fileEntry = {fileEntry}
index = {index}
{ ... (onRetry
? {
onRetry : () => onRetry (fileEntry, { updateFileEntryStatus }),
}
: {})}
/>
))}
</ SeedAttachmentInput.Context >
</ SeedAttachmentInput.ItemGroup >
</ SeedAttachmentInput.Container >
)}
</ HorizontalReorderList >
);
}}
</ SeedAttachmentInput.Context >
);
});
AttachmentInputReorderable.displayName = "AttachmentInputReorderable" ;
export type SortableAttachmentInputItemProps = AttachmentInputItemProps & {
index : number ;
children ?: ( dragging : boolean ) => React . ReactNode ;
};
export const SortableAttachmentInputItem = React.forwardRef <
React.ComponentRef <typeof AttachmentInputItem > ,
SortableAttachmentInputItemProps
> (({ index , fileEntry , children , ... props }, ref ) => (
< HorizontalReorderItem itemId = {fileEntry.id} index = {index}>
{( dragging ) =>
children ? (
children (dragging)
) : (
< AttachmentInputItem ref = {ref} fileEntry = {fileEntry} dragging = {dragging} { ... props} />
)
}
</ HorizontalReorderItem >
));
SortableAttachmentInputItem.displayName = "SortableAttachmentInputItem" ;
/**
* This file is a snippet from Crispy, helping you get started quickly with @seed-design/* packages.
* You can extend this snippet however you want.
*/
children?React.ReactNode
label?React.ReactNode
labelWeight?"medium" | "bold" | undefined
indicator?React.ReactNode
description?React.ReactNode
errorMessage?React.ReactNode
showRequiredIndicator?boolean | undefined
id?string | undefined
flatten?boolean | undefined
accept?string | string[] | undefined
disabled?boolean | undefined
required?boolean | undefined
invalid?boolean | undefined
readOnly?boolean | undefined
maxFiles?number | undefined
maxFileSize?number | undefined
minFileSize?number | undefined
validate?(( file : NativeFile ) => AttachmentFileError[] | null ) | undefined
onSelectFiles?(() => NativeFile[] | Promise < NativeFile[] > ) | undefined
onSelectError?(( error : unknown ) => void ) | undefined
acceptedFileEntries?AttachmentFileEntry[] | undefined
defaultAcceptedFileEntries?AttachmentFileEntry[] | undefined
onAcceptedFileEntriesChange?(( entries : AttachmentFileEntry []) => void ) | undefined
onFileReject?(( rejections : AttachmentFileRejection []) => void ) | undefined
onFileAccept?(( entries : AttachmentFileEntry [], helpers : { updateFileEntryStatus : ( id : string , details : AttachmentFileStatusDetails ) => void ; }) => void ) | undefined
style?CSSProperties | undefined
className?string | undefined
children?(( context : AttachmentInputContextValue ) => React.ReactNode) | undefined
onRetry?(( fileEntry : FileEntry , helpers : RetryHelpers ) => void ) | undefined
fileEntryAttachmentFileEntry
onRetry?(() => void ) | undefined
id?string | undefined
flatten?boolean | undefined
style?CSSProperties | undefined
className?string | undefined
Combine AttachmentInput inside AttachmentField. The host adapter passed to onSelectFiles returns NativeFile[] or Promise<NativeFile[]>. Return an empty array if selection is canceled. Errors from the adapter are passed to onSelectError.
import { AttachmentField, AttachmentInput } from "@/components/ui/attachment-field" ;
< AttachmentField
maxFiles = { 3 }
label = "Upload file"
onSelectFiles = {openNativeFilePicker}
onSelectError = {handleFilePickerError}
>
< AttachmentInput />
</ AttachmentField >;
NativeFile consists of uri, name, type, size, and optional previewUrl. File, Blob, HTML <input type="file">, 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.
AttachmentInput supports context render prop. You can directly render acceptedFileEntries as AttachmentInputItem and update the app's upload status using updateFileEntryStatus.
< AttachmentField onSelectFiles = {openNativeFilePicker}>
< AttachmentInput >
{({ acceptedFileEntries }) =>
acceptedFileEntries. map (( fileEntry ) => (
< AttachmentInputItem key = {fileEntry.id} fileEntry = {fileEntry} />
))}
</ AttachmentInput >
</ AttachmentField >;
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.
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.
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 (
< view className = {seedClassName}>
< VStack gap = "x4" p = "x6" width = "100%" >
< AttachmentField
maxFiles = { 3 }
label = "파일 업로드"
defaultAcceptedFileEntries = { DEFAULT_FILES }
onSelectFiles = {() => PICKED_FILES }
>
< AttachmentInput />
</ AttachmentField >
</ VStack >
</ view >
);
}
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.
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 < string []>([]);
const addLog = ( message : string ) => setLogs (( previous ) => [ ... previous, message]);
return (
< view className = {seedClassName}>
< VStack gap = "x4" width = "100%" align = "center" >
< VStack gap = "x1" >
{logs. length === 0 ? (
< Text color = "fg.neutralMuted" >파일을 추가하거나 삭제하면 로그가 표시됩니다.</ Text >
) : (
logs. map (( log , index ) => (
< Text key = {index} fontSize = "fontSize.caption1" >
{log}
</ Text >
))
)}
</ VStack >
< AttachmentField
maxFiles = { 3 }
label = "파일 업로드"
description = "콜백 호출 로그를 확인하세요"
onSelectFiles = {() => 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 ( ", " ) }` ,
)
}
>
< AttachmentInput >
{({ acceptedFileEntries }) =>
acceptedFileEntries. map (( fileEntry ) => (
< AttachmentInputItem key = {fileEntry.id} fileEntry = {fileEntry} />
))
}
</ AttachmentInput >
</ AttachmentField >
</ VStack >
</ view >
);
}
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.
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 (
< view className = {seedClassName}>
< VStack gap = "x4" p = "x6" width = "100%" >
< AttachmentField
maxFiles = { 3 }
label = "파일 업로드"
description = "최대 3개까지 업로드할 수 있습니다"
defaultAcceptedFileEntries = { DEFAULT_FILES }
onSelectFiles = {() => PICKED_FILES }
>
< AttachmentInput />
</ AttachmentField >
</ VStack >
</ view >
);
}
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.
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 < string >();
return (
< view className = {seedClassName}>
< VStack gap = "x4" p = "x6" width = "100%" >
< AttachmentField
accept = {[ "image/png" , "image/jpeg" ]}
maxFiles = { 3 }
invalid = { !! errorMessage}
errorMessage = {errorMessage}
label = "이미지 업로드"
description = "PNG, JPEG 파일만 업로드할 수 있습니다"
onSelectFiles = {() => [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 " ),
)
}
>
< AttachmentInput />
</ AttachmentField >
</ VStack >
</ view >
);
}
minFileSize and maxFileSize validate NativeFile.size (bytes). If out of range, they are rejected as FILE_TOO_SMALL and FILE_TOO_LARGE respectively.
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 < string >();
return (
< view className = {seedClassName}>
< VStack gap = "x4" p = "x6" width = "100%" >
< AttachmentField
maxFiles = { 3 }
minFileSize = { MIN_FILE_SIZE }
maxFileSize = { MAX_FILE_SIZE }
invalid = { !! errorMessage}
errorMessage = {errorMessage}
label = "파일 업로드"
description = "1KB ~ 10KB 크기의 파일만 업로드할 수 있습니다"
onSelectFiles = {() => [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 " ),
)
}
>
< AttachmentInput />
</ AttachmentField >
</ VStack >
</ view >
);
}
validate returns an array of custom error codes or null for each NativeFile. Convert to messages matching your app in onFileReject.
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 < string >();
return (
< view className = {seedClassName}>
< VStack gap = "x4" p = "x6" width = "100%" >
< AttachmentField
maxFiles = { 5 }
validate = {( file ) =>
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자를 초과합니다.` ,
);
}}
>
< AttachmentInput />
</ AttachmentField >
</ VStack >
</ view >
);
}
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.
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 < Record < string , number >>({});
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 (
< view className = {seedClassName}>
< VStack gap = "x4" p = "x6" width = "100%" >
< AttachmentField
accept = "image/*"
maxFiles = { 5 }
label = "파일 업로드"
description = "업로드 상태 시뮬레이션"
onSelectFiles = {() => [ PICKED_FILE ]}
onFileAccept = {( entries , { updateFileEntryStatus }) => {
for ( const entry of entries) startUpload (entry.id, updateFileEntryStatus);
}}
>
< AttachmentInput
onRetry = {( entry , { updateFileEntryStatus }) =>
startUpload (entry.id, updateFileEntryStatus)
}
/>
</ AttachmentField >
</ VStack >
</ view >
);
}
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.
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.
import {
AttachmentInputReorderable,
SortableAttachmentInputItem,
} from "@/components/ui/attachment-field-reorderable" ;
< AttachmentField >
< AttachmentInputReorderable >
{({ acceptedFileEntries }) =>
acceptedFileEntries. map (( fileEntry , index ) => (
< SortableAttachmentInputItem
key = {fileEntry.id}
fileEntry = {fileEntry}
index = {index}
/>
))}
</ AttachmentInputReorderable >
</ AttachmentField >;
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 (
< SortableAttachmentInputItem fileEntry = {fileEntry} index = {index}>
{( dragging ) => (
< SeedAttachmentInput.Item fileEntry = {fileEntry} dragging = {dragging}>
< SeedAttachmentInput.ItemSurface >
< SeedAttachmentInput.ItemImage />
{isCover ? (
< SeedAttachmentInput.ItemBadge >대표사진</ SeedAttachmentInput.ItemBadge >
) : null }
< SeedAttachmentInput.ItemBackdrop status = "uploading" >
{( entry ) => (
< ProgressCircle
size = "24"
tone = "staticWhite"
{ ... ( "progress" in entry ? { value: entry.progress } : {})}
/>
)}
</ SeedAttachmentInput.ItemBackdrop >
</ SeedAttachmentInput.ItemSurface >
< SeedAttachmentInput.ItemRemoveButton accessibility-label = "파일 제거" >
< Icon icon = {< IconXmarkFill />} />
</ SeedAttachmentInput.ItemRemoveButton >
</ SeedAttachmentInput.Item >
)}
</ SortableAttachmentInputItem >
);
}
export default function AttachmentFieldReorderable () {
const seedClassName = useSeedClassName ({ colorMode: "system" });
return (
< view className = {seedClassName}>
< VStack p = "x6" width = "100%" >
< AttachmentField
accept = "image/*"
maxFiles = { 5 }
label = "이미지 업로드"
description = "길게 눌러 드래그하여 순서를 변경할 수 있습니다"
defaultAcceptedFileEntries = { DEFAULT_FILES }
>
< AttachmentInputReorderable >
{({ acceptedFileEntries }) =>
acceptedFileEntries. map (( fileEntry , index ) => (
< SortableImageItem
key = {fileEntry.id}
fileEntry = {fileEntry}
index = {index}
isCover = {index === 0 }
/>
))
}
</ AttachmentInputReorderable >
</ AttachmentField >
</ VStack >
</ view >
);
}
Allow only image files with accept="image/*" and display thumbnail using previewUrl returned by the host.
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 < string >();
return (
< view className = {seedClassName}>
< VStack gap = "x4" p = "x6" width = "100%" >
< AttachmentField
accept = "image/*"
maxFiles = { 5 }
label = "이미지 업로드"
description = "이미지 파일만 허용됩니다"
invalid = { !! errorMessage}
errorMessage = {errorMessage}
onSelectFiles = {() => [pickCount.current ++ === 0 ? IMAGE_FILE : OTHER_FILE ]}
onAcceptedFileEntriesChange = {() => setErrorMessage ( undefined )}
onFileReject = {() => setErrorMessage ( "지원하지 않는 파일 형식입니다" )}
>
< AttachmentInput />
</ AttachmentField >
</ VStack >
</ view >
);
}
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.
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 (
< view className = {seedClassName}>
< VStack gap = "x4" p = "x6" width = "100%" >
< AttachmentField
disabled
maxFiles = { 5 }
defaultAcceptedFileEntries = { DEFAULT_FILES }
label = "파일 업로드"
description = "비활성화된 AttachmentField"
>
< AttachmentInput />
</ AttachmentField >
</ VStack >
</ view >
);
}
readOnly blocks trigger, add, delete, clear, and sort operations. Externally hydrating or updating controlled state is allowed.
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 (
< view className = {seedClassName}>
< VStack gap = "x4" p = "x6" width = "100%" >
< AttachmentField
readOnly
maxFiles = { 5 }
defaultAcceptedFileEntries = { DEFAULT_FILES }
label = "첨부 파일"
description = "읽기 전용 상태"
>
< AttachmentInput />
</ AttachmentField >
</ VStack >
</ view >
);
}
The list can be controlled externally using acceptedFileEntries and onAcceptedFileEntriesChange.
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 < AttachmentFileEntry []>([]);
function clearFiles () {
"background only" ;
setAcceptedFileEntries ([]);
}
return (
< view className = {seedClassName}>
< VStack gap = "x4" width = "100%" >
< AttachmentField
maxFiles = { 5 }
label = "Controlled"
description = "최대 5개까지 업로드할 수 있습니다"
acceptedFileEntries = {acceptedFileEntries}
onAcceptedFileEntriesChange = {setAcceptedFileEntries}
onSelectFiles = {() => [ PICKED_FILE ]}
>
< AttachmentInput />
</ AttachmentField >
< Text >
현재 파일: { JSON . stringify (acceptedFileEntries. map (( entry ) => entry.file.name))}
</ Text >
< HStack gap = "x2" >
< ActionButton bindtap = {clearFiles} variant = "neutralWeak" >
전체 삭제
</ ActionButton >
</ HStack >
</ VStack >
</ view >
);
}
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.
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 < React . ComponentProps < typeof AttachmentField>[ "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 (
< view className = {seedClassName}>
< VStack
px = "spacingX.globalGutter"
width = "400px"
maxWidth = "full"
bg = "palette.gray300"
borderWidth = { 1 }
borderColor = "stroke.neutralMuted"
>
< VStack gap = "spacingY.componentDefault" bg = "bg.layerDefault" >
< TextField label = "이름" >
< TextFieldInput placeholder = "홍길동" />
</ TextField >
< AttachmentField
maxFiles = { 8 }
label = "첨부파일"
defaultAcceptedFileEntries = { MOCKED_FILES . map (( file , index ) => ({
id: `${ index }` ,
file,
status: "pending" ,
}))}
style = { INSET_STYLE }
onSelectFiles = {() => [ MOCKED_FILES [ 0 ]]}
>
< AttachmentInput />
</ AttachmentField >
</ VStack >
</ VStack >
</ view >
);
}
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.
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 (
< view className = {seedClassName}>
< VStack gap = "x8" width = "100%" >
< AttachmentField
maxFiles = { 3 }
label = "첨부파일"
labelWeight = "bold"
required
showRequiredIndicator
invalid
errorMessage = "필수 항목입니다."
>
< AttachmentInput />
</ AttachmentField >
< Divider />
< AttachmentField
maxFiles = { 3 }
label = "첨부파일"
description = "파일을 선택하거나 호스트 파일 선택기를 여세요."
indicator = "선택"
onSelectFiles = {() => [ PICKED_FILE ]}
>
< AttachmentInput />
</ AttachmentField >
</ VStack >
</ view >
);
}
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.
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 (
< SeedAttachmentInput.Item fileEntry = {fileEntry}>
< SeedAttachmentInput.ItemSurface >
< SeedAttachmentInput.ItemImage />
{isCover ? < SeedAttachmentInput.ItemBadge >대표사진</ SeedAttachmentInput.ItemBadge > : null }
< SeedAttachmentInput.ItemBackdrop status = "uploading" >
{( entry ) => (
< ProgressCircle
size = "24"
tone = "staticWhite"
{ ... ( "progress" in entry ? { value: entry.progress } : {})}
/>
)}
</ SeedAttachmentInput.ItemBackdrop >
{onRetry ? (
< SeedAttachmentInput.ItemBackdrop status = "error" >
< SeedAttachmentInput.ItemActionButton bindtap = {onRetry}>
< Icon icon = {< IconArrowClockwiseCircularFill />} />
재시도
</ SeedAttachmentInput.ItemActionButton >
</ SeedAttachmentInput.ItemBackdrop >
) : null }
</ SeedAttachmentInput.ItemSurface >
< SeedAttachmentInput.ItemRemoveButton accessibility-label = "파일 제거" >
< Icon icon = {< IconXmarkFill />} />
</ SeedAttachmentInput.ItemRemoveButton >
</ SeedAttachmentInput.Item >
);
}
export default function AttachmentFieldCustomizingItems () {
const seedClassName = useSeedClassName ({ colorMode: "system" });
return (
< view className = {seedClassName}>
< VStack gap = "x4" p = "x6" width = "100%" >
< AttachmentField
accept = "image/*"
maxFiles = { 10 }
label = "이미지 업로드"
description = "첫 번째 이미지가 대표사진으로 설정됩니다"
onSelectFiles = {() => [ PICKED_FILE ]}
onFileAccept = {( entries , { updateFileEntryStatus }) => {
for ( const entry of entries) {
updateFileEntryStatus (entry.id, { status: "uploading" , progress: 0 });
setTimeout (() => updateFileEntryStatus (entry.id, { status: "success" }), 500 );
}
}}
>
< AttachmentInput >
{({ acceptedFileEntries , updateFileEntryStatus }) =>
acceptedFileEntries. map (( fileEntry , index ) => (
< CustomImageItem
key = {fileEntry.id}
fileEntry = {fileEntry}
isCover = {index === 0 }
onRetry = {() => {
updateFileEntryStatus (fileEntry.id, {
status: "uploading" ,
progress: 0 ,
} satisfies AttachmentFileStatusDetails );
setTimeout (
() => updateFileEntryStatus (fileEntry.id, { status: "success" }),
500 ,
);
}}
/>
))
}
</ AttachmentInput >
</ AttachmentField >
</ VStack >
</ view >
);
}
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.
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 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.
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.