PreviewFile

fun PreviewFile(file: UploadedFile, onClear: () -> Unit, modifier: Modifier = Modifier, clearContentDescription: String? = null, onClick: () -> Unit? = null, clearIcon: SparkIcon = LeboncoinIcons.Cross)(source)

Visual representation of a single uploaded file.

Layout:

  • Icon representing the file type or error state.

  • Filename as primary text (with middle ellipsis if needed).

  • File size as secondary text.

  • Progress indicator (optional, linear or indeterminate) - shown when UploadedFile.progress or UploadedFile.isLoading is set.

  • Error message (optional) - shown when UploadedFile.errorMessage is set.

  • Clear button at the end to remove the file.

The component automatically displays progress, loading states, and error messages based on the file's properties. Progress and loading states disable the clear button automatically.

Parameters

file

The uploaded file to display. The file's UploadedFile.progress, UploadedFile.isLoading, UploadedFile.errorMessage, and UploadedFile.enabled properties control the component's visual state.

onClear

Callback invoked when the clear button is clicked.

modifier

Modifier to be applied to the component.

clearContentDescription

Content description for the clear button. If null, defaults to "Remove ${file.name}".

onClick

Optional callback invoked when the file preview is clicked. If null, the preview is not clickable.

clearIcon

Icon to use for the clear button. Defaults to LeboncoinIcons.Cross.

Samples

val defaultFile = remember { UploadedFile(file = PlatformFile(file = File("document.pdf"))) }
val progressFile = remember { UploadedFile(file = PlatformFile(file = File("image.jpg")), progress = { 0.65f }) }
val loadingFile = remember { UploadedFile(file = PlatformFile(file = File("video.mp4")), isLoading = true) }
val errorFile = remember {
    UploadedFile(
        file = PlatformFile(file = File("large-file.zip")),
        errorMessage = "File size exceeds maximum limit of 10MB",
    )
}
val disabledFile = remember { UploadedFile(file = PlatformFile(file = File("archive.rar")), enabled = false) }

Column(modifier = Modifier.fillMaxWidth()) {
    PreviewFile(file = defaultFile, onClear = {}, modifier = Modifier.fillMaxWidth())
    VerticalSpacer(16.dp)
    PreviewFile(file = progressFile, onClear = {}, modifier = Modifier.fillMaxWidth())
    VerticalSpacer(16.dp)
    PreviewFile(file = loadingFile, onClear = {}, modifier = Modifier.fillMaxWidth())
    VerticalSpacer(16.dp)
    PreviewFile(file = errorFile, onClear = {}, modifier = Modifier.fillMaxWidth())
    VerticalSpacer(16.dp)
    PreviewFile(file = disabledFile, onClear = {}, modifier = Modifier.fillMaxWidth())
}