CamoFileUploader
Concept
1. Why
A file uploader is a drop zone and a button that start choosing files, with a list showing each file's progress: attachments, imports (Carbon's file uploader, Fluent patterns). Core never touches the filesystem (ADR-27): it reports the user's intent (onPick, onDrop) and the app opens the system picker and runs the upload, feeding progress back.
2. Shape
Split of duties
| Core | Skin (renderer) |
|---|---|
the zone's states (idle, drag-over, disabled), onPick on click, Enter and Space, onFilesDropped on desktop and web (the platform's drop target, as a list of names and sizes plus an opaque handle), the file list model, remove and retry actions, semantics | the zone's look (dashed border, fill, icon, text), the file row (name, size, progress bar, error), the state colors |
Material mapping preview: the M3 has none.
- A dashed
outlinezone,shapes.medium,surfaceContainerLow; rows withCamoProgressBar.
3. API
Contract
data class UploadFile(
val id: Any, val name: String, val sizeBytes: Long? = null,
val progress: Float? = null, // 0..1; null: waiting
val status: UploadStatus = Uploading, // Uploading | Done | Failed(message)
)
fun CamoFileUploader(
files: List<UploadFile>,
onPick: () -> Unit, // open the app's picker
onFilesDropped: ((List<DroppedFile>) -> Unit)? = null, // null: no drop target
onRemove: (UploadFile) -> Unit, onRetry: ((UploadFile) -> Unit)? = null,
hint: String? = null, // "PNG or JPG, up to 5 MB"
enabled: Boolean = true, multiple: Boolean = true,
label: String,
)
State → renderer: UploaderZoneState(dragOver, enabled, interaction) and UploadRowState(status, progress, interaction). Slots: icon, title, hint; the row's name, size, actions. Rows use skin.progressBar for the bar.
Tokens used
colors.surfaceContainerLow,outline,primary(drag-over),errorshapes.medium,spacing.l,typography.bodyMedium
Component theme
theme.components.file uploader. Every field is nullable in the theme. The skin's defaults(theme) fills whatever isn't set (Material defaults shown). See Theme §3.10.
| Field | Type | Material default | What it's for |
|---|---|---|---|
zoneShape | Shape | shapes.medium | |
dashed | Boolean | true | the border style |
zoneHeight | Dp | 120 | |
icon | IconSource | upload | |
colors | UploaderColors(zone, border, dragBorder, error, text) | M3 values | every color it uses |
strings | UploaderStrings | English | "Drop files here or", "Remove", "Retry", progress words |
Accessibility
- The zone is one button ("Upload files, button") with the hint as its description; Enter and Space call
onPick. - Each file row announces name, size and state ("report.pdf, 45%" with the bar's progress value); remove and retry are buttons. A failure is announced as an alert once.
4. Build steps
UploadFile,DroppedFile, the drop-target expect/actual (desktop, web; none on mobile), theme, state, renderer, theCamoSkinfield.CamoFileUploader, the DebugSkin renderer.- Tests: pick by click and keys, drop, rows and progress, remove and retry, disabled, semantics.
Done when
- The upload wizard sample drives it with fake progress.
5. Edge cases
| Case | Decided behavior |
|---|---|
| Case | Decided behavior |
| --- | --- |
| Types and sizes | The app validates; Failed(message) shows the reason. |
| No drop target (mobile) | The zone is just the button. |
| Many files | The list scrolls inside the parent's constraints. |
- The renderer has two parts,
ZoneandRow; core builds each row's remove and retry buttons (ghost icon buttons) and the renderer draws the progress with the skin's progress bar.UploaderThemehaszoneShape,dashed,zoneHeight, the zone, remove and retry icons,titleStyle,hintStyleandUploaderColors(zone, border, dragBorder, error, text, mutedText). - The app's picker and drop API stay outside core (ADR-27):
onPickopens the picker, anddropTarget(Kotlin, a function fromDropTargetCallbacksto aModifier) ordropTargetBuilder(Flutter, a wrapper around the zone) lets the app attach its platform's drop API, reporting throughsetDragOverandonDropped;onFilesDroppedreceivesDroppedFile(name, sizeBytes, handle). There is nomultipleparameter: the app's picker decides. - A row announces "1.0 MB, 45%", "Too large" or "Done"; a failed row is an assertive live region. The words ("Remove", "Retry", "Waiting") are English constants, not theme strings.
- Which drop-target APIs per platform (Compose's
dragAndDropTarget, the web drop event, Flutter's desktop drop plugin) are decided in the build; v0.1 may ship drop on desktop and web only.
Implementation
1. Why
Compose Multiplatform's dragAndDropTarget (desktop, web) turns drops into DroppedFile (name, size, the platform handle); on Android and iOS only the button.
2. Shape
3. API
@Composable public fun CamoFileUploader(files: List<UploadFile>, onPick: () -> Unit, onRemove: (UploadFile) -> Unit,
label: String, modifier: Modifier = Modifier, onFilesDropped: ((List<DroppedFile>) -> Unit)? = null,
onRetry: ((UploadFile) -> Unit)? = null, hint: String? = null, enabled: Boolean = true, multiple: Boolean = true)
4. Build steps
- Zone, drop target, rows, renderer.
- Tests: pick, drop (desktop), rows, semantics.
Done when
- Works by touch, mouse, keyboard and screen reader on all targets.
5. Edge cases
| Case | Decided behavior |
|---|---|
| Drop on Flutter | Via the app's dropTargetBuilder; the example uses none (button only) so core stays plugin-free. |
- The zone is a
clickablebutton with the label as its description; rows merge their content and carry the state asstateDescription.
- None specific.