Skip to content

Menu ​

A dropdown / context menu of rows with optional leading icons, danger styling, and separators. Built on Material 3 DropdownMenu and controlled via expanded. Selecting a row runs its onSelect, then requests dismissal. Anchor it by placing it inside the Box that holds the trigger.

Import ​

kotlin
import io.github.heartcoolman.prism.ui.PrismMenu
import io.github.heartcoolman.prism.ui.PrismMenuItem
import io.github.heartcoolman.prism.ui.PrismMenuSeparator

Basic usage ​

kotlin
var open by remember { mutableStateOf(false) }

Box {
    PrismButton(onClick = { open = true }) { Text("Menu") }
    PrismMenu(
        expanded = open,
        onDismissRequest = { open = false },
        items = listOf(
            PrismMenuItem(label = "Edit", onSelect = {}),
            PrismMenuItem(label = "Duplicate", onSelect = {}),
        ),
    )
}

Icons, separators and danger rows ​

Mix PrismMenuItems with PrismMenuSeparator. Set danger = true for destructive rows and enabled = false to disable one.

kotlin
PrismMenu(
    expanded = open,
    onDismissRequest = { open = false },
    items = listOf(
        PrismMenuItem(
            label = "Edit",
            icon = { PrismIcon(PrismIcons.Edit, contentDescription = null, size = 18.dp) },
            onSelect = {},
        ),
        PrismMenuItem(label = "Archive", enabled = false),
        PrismMenuSeparator,
        PrismMenuItem(label = "Delete", danger = true, onSelect = {}),
    ),
)

API ​

ParameterTypeDefaultDescription
expandedBoolean—Whether the menu is shown.
onDismissRequest() -> Unit—Called on outside click, Escape, or after a row is selected.
itemsList<PrismMenuEntry>—Rows and separators, top to bottom.
modifierModifierModifierModifier applied to the dropdown.

PrismMenuEntry ​

kotlin
sealed interface PrismMenuEntry

data class PrismMenuItem(
    val label: String,
    val icon: (@Composable () -> Unit)? = null,
    val danger: Boolean = false,
    val enabled: Boolean = true,
    val onSelect: () -> Unit = {},
) : PrismMenuEntry

object PrismMenuSeparator : PrismMenuEntry
FieldTypeDefaultDescription
labelString—Row text.
icon(@Composable () -> Unit)?nullOptional leading glyph (secondary tint, or danger tint).
dangerBooleanfalseRender the row in the destructive color.
enabledBooleantrueBlock interaction and dim the row when false.
onSelect() -> Unit{}Invoked when the row is chosen, before dismissal.

Released under the MIT License.