CamoDocumentTabs
Editor-style tabs for open documents: a close button on hover and on the selected tab (a dot while the document is modified), middle-click to close, drag to reorder (Alt+Left and Alt+Right with the keyboard), pinned tabs at the start, and a row that scrolls with a "show all tabs" menu when the tabs don't fit.
documents and selected (a document id) are the app's; so is closing: onClose says the user asked, and the
app removes the document and picks the next selection. The order and pins live in state. onContextMenu
returns the entries of a tab's right-click menu ("Close others", "Close to the right", "Pin"). Ctrl+W is the
app's key. Screen readers get the tab-list semantics of CamoTabs plus "Close", "Move earlier", "Move later"
and "Pin" actions on every tab, and hear "modified" and "pinned" in its state.
Built from the skin's tab bar (every skin draws it), so it needs no renderer of its own.
Usage
- Kotlin
- Dart
val state = remember { CamoDocumentTabsState() } // order and pins; snapshot() and apply() to save them
var selected by remember { mutableStateOf<Any>(documents.first().id) }
CamoDocumentTabs(
documents = documents.map { CamoDocument(it.id, it.name, modified = it.unsaved) },
selected = selected,
onSelect = { selected = it },
onClose = { id -> closeDocument(id) }, // the app removes it and picks the next tab
state = state,
)
API
- Kotlin
- Dart
public fun CamoDocumentTabs(
documents: List<CamoDocument>,
selected: Any,
onSelect: (Any) -> Unit,
onClose: (Any) -> Unit,
state: CamoDocumentTabsState,
modifier: Modifier = Modifier,
onContextMenu: ((CamoDocument) -> List<CamoMenuEntry>)? = null,
appearance: Appearance? = null,
)
| Name | Type | Default |
|---|---|---|
documents | List<CamoDocument> | required |
selected | Any | required |
onSelect | (Any) -> Unit | required |
onClose | (Any) -> Unit | required |
state | CamoDocumentTabsState | required |
modifier | Modifier | Modifier |
onContextMenu | ((CamoDocument) -> List<CamoMenuEntry>)? | null |
appearance | Appearance? | null |
Why CamoDocumentTabs works this way, its states and its edge cases: contributor docs.