ButtonSingleSelect
High level file upload component for single file selection.
This component provides a button to trigger file selection. To display selected files, manage state yourself and use PreviewFile or FileUploadList.
Parameters
Callback invoked when a file is selected or cleared (null)
Text label for the default button
Modifier to be applied to the button
The size of the button. Only applies when using the default buttonContent.
The optional icon to be displayed at the start or the end of the button container. Only applies when using the default buttonContent.
If an icon is added, you can configure the side where is should be displayed, at the start or end of the button. Only applies when using the default buttonContent.
Type of files to select (image, video, file, etc.)
Optional title for the file picker dialog
Optional directory to open the picker in
Optional settings for the file picker dialog
Whether the button is enabled
If provided, it'll be spoken in place of the default "double tap to activate".
Composable lambda for custom button. Receives onClick callback. Defaults to a filled button with the label.
Samples
var selectedFile by rememberSaveable { mutableStateOf<UploadedFile?>(null) }
Column(modifier = Modifier.fillMaxWidth()) {
FileUpload.ButtonSingleSelect(
onResult = { file -> selectedFile = file },
label = "Select a file",
modifier = Modifier.fillMaxWidth(),
)
VerticalSpacer(16.dp)
selectedFile?.let { file ->
PreviewFile(
file = file,
onClear = { selectedFile = null },
modifier = Modifier.fillMaxWidth(),
onClick = { FileUploadDefaults.openFile(file) },
)
}
}var selectedFile by rememberSaveable { mutableStateOf<UploadedFile?>(null) }
Column(modifier = Modifier.fillMaxWidth()) {
FileUpload.ButtonSingleSelect(
onResult = { file -> selectedFile = file },
label = "Select file",
modifier = Modifier.fillMaxWidth(),
buttonContent = { onClick ->
ButtonTinted(
onClick = onClick,
text = "Upload with Tinted Button",
icon = LeboncoinIcons.ImageOutline,
iconSide = IconSide.START,
)
},
)
VerticalSpacer(16.dp)
selectedFile?.let { file ->
PreviewFile(
file = file,
onClear = { selectedFile = null },
modifier = Modifier.fillMaxWidth(),
)
}
}