Skip to content

SuperSpinner

SuperSpinner is a dropdown selector component in Miuix that provides titles, summaries, and a list of options with icons and text. It supports click interaction and various display modes, commonly used in option settings with visual aids. This component is similar to SuperDropdown but offers richer functionality and interaction experience.

Prerequisite

This component depends on Scaffold providing MiuixPopupHost to render popup content. It must be used within Scaffold, otherwise popup content will not render correctly.

Import

kotlin
import top.yukonga.miuix.kmp.extra.SuperSpinner
import top.yukonga.miuix.kmp.extra.SpinnerEntry

Basic Usage

The SuperSpinner component provides basic dropdown selector functionality:

kotlin
var selectedIndex by remember { mutableStateOf(0) }
val options = listOf(
    SpinnerEntry(title = "Option 1"),
    SpinnerEntry(title = "Option 2"),
    SpinnerEntry(title = "Option 3"),
)

Scaffold {
    SuperSpinner(
        title = "Dropdown Selector",
        items = options,
        selectedIndex = selectedIndex,
        onSelectedIndexChange = { selectedIndex = it }
    )
}

Options with Icons and Summaries

kotlin
// Create a rounded rectangle Painter
class RoundedRectanglePainter(
    private val cornerRadius: Dp = 6.dp
) : Painter() {
    override val intrinsicSize = Size.Unspecified

    override fun DrawScope.onDraw() {
        drawRoundRect(
            color = Color.White,
            size = Size(size.width, size.height),
            cornerRadius = CornerRadius(cornerRadius.toPx(), cornerRadius.toPx())
        )
    }
}

var selectedIndex by remember { mutableStateOf(0) }
val options = listOf(
    SpinnerEntry(
        icon = { Icon(RoundedRectanglePainter(), "Icon", Modifier.padding(end = 12.dp), Color(0xFFFF5B29)) },
        title = "Red Theme",
        summary = "Vibrant red"
    ),
    SpinnerEntry(
        icon = { Icon(RoundedRectanglePainter(), "Icon", Modifier.padding(end = 12.dp), Color(0xFF3482FF)) },
        title = "Blue Theme",
        summary = "Calm blue"
    ),
    SpinnerEntry(
        icon = { Icon(RoundedRectanglePainter(), "Icon", Modifier.padding(end = 12.dp), Color(0xFF36D167)) },
        title = "Green Theme",
        summary = "Fresh green"
    ),
    SpinnerEntry(
        icon = { Icon(RoundedRectanglePainter(), "Icon", Modifier.padding(end = 12.dp), Color(0xFFFFB21D)) },
        title = "Yellow Theme",
        summary = "Bright yellow"
    )
)

Scaffold {
    SuperSpinner(
        title = "Function Selection",
        summary = "Choose the action you want to perform",
        items = options,
        selectedIndex = selectedIndex,
        onSelectedIndexChange = { selectedIndex = it }
    )
}

Component States

Disabled State

kotlin
SuperSpinner(
    title = "Disabled Selector",
    summary = "This selector is currently unavailable",
    items = listOf(SpinnerEntry(title = "Option 1")),
    selectedIndex = 0,
    onSelectedIndexChange = {},
    enabled = false
)

Dialog Mode

SuperSpinner also supports dialog mode, suitable for displaying a larger number of options or when a more prominent selection interface is needed. This mode can be activated by providing the dialogButtonString parameter.

kotlin
var selectedIndex by remember { mutableStateOf(0) }
val options = listOf(
    SpinnerEntry(title = "Option 1"),
    SpinnerEntry(title = "Option 2"),
    SpinnerEntry(title = "Option 3")
)

Scaffold {
    SuperSpinner(
        title = "Dialog Mode",
        dialogButtonString = "Cancel",
        items = options,
        selectedIndex = selectedIndex,
        onSelectedIndexChange = { selectedIndex = it }
    )
}

Properties

SuperSpinner Properties (Dropdown Mode)

Property NameTypeDescriptionDefault ValueRequired
itemsList<SpinnerEntry>Options list-Yes
selectedIndexIntCurrent selected item index-Yes
titleStringSelector title-Yes
modifierModifierComponent modifierModifierNo
titleColorBasicComponentColorsTitle text color configBasicComponentDefaults.titleColor()No
summaryString?Selector descriptionnullNo
summaryColorBasicComponentColorsSummary text color configBasicComponentDefaults.summaryColor()No
spinnerColorsSpinnerColorsColor configuration for spinnerSpinnerDefaults.spinnerColors()No
startAction@Composable (() -> Unit)?Custom start side contentnullNo
bottomAction@Composable (() -> Unit)?Custom bottom side contentnullNo
insideMarginPaddingValuesInternal content paddingBasicComponentDefaults.InsideMarginNo
maxHeightDp?Maximum dropdown heightnullNo
enabledBooleanInteractive statetrueNo
showValueBooleanShow current selected valuetrueNo
onSelectedIndexChange((Int) -> Unit)?Selection change callback-No

SuperSpinner Properties (Dialog Mode)

Property NameTypeDescriptionDefault ValueRequired
itemsList<SpinnerEntry>Options list-Yes
selectedIndexIntCurrent selected item index-Yes
titleStringSelector title-Yes
dialogButtonStringStringDialog bottom button text-Yes
modifierModifierComponent modifierModifierNo
popupModifierModifierDialog popup modifierModifierNo
titleColorBasicComponentColorsTitle text color configBasicComponentDefaults.titleColor()No
summaryString?Selector descriptionnullNo
summaryColorBasicComponentColorsSummary text color configBasicComponentDefaults.summaryColor()No
spinnerColorsSpinnerColorsColor configuration for spinnerSpinnerDefaults.dialogSpinnerColors()No
startAction@Composable (() -> Unit)?Custom start side contentnullNo
bottomAction@Composable (() -> Unit)?Custom bottom side contentnullNo
insideMarginPaddingValuesInternal content paddingBasicComponentDefaults.InsideMarginNo
enabledBooleanInteractive statetrueNo
showValueBooleanShow current selected valuetrueNo
onSelectedIndexChange((Int) -> Unit)?Selection change callback-No

SpinnerEntry Properties

Property NameTypeDescription
icon@Composable ((Modifier) -> Unit)?Option icon
titleString?Option title
summaryString?Option description

SpinnerColors Properties

Property NameTypeDescription
contentColorColorOption title color
summaryColorColorOption summary color
containerColorColorOption background color
selectedContentColorColorSelected item title color
selectedSummaryColorColorSelected item summary color
selectedContainerColorColorSelected item background color
selectedIndicatorColorColorSelected check icon color

Changelog

Released under the Apache-2.0 License