跳转到内容

SuperSpinner

SuperSpinner 是 Miuix 中的下拉选择器组件,提供了标题、摘要和带有图标、文本的选项列表,支持点击交互和多种显示模式,常用于具有视觉辅助的选项设置中。该组件与 SuperDropdown 组件类似,但提供更丰富的功能和交互体验。

使用前提

此组件依赖 Scaffold 提供的 MiuixPopupHost 以显示弹出内容。必须在 Scaffold 中使用,否则弹出内容无法正常渲染。

引入

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

基本用法

SuperSpinner 组件提供了基础的下拉选择器功能:

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

Scaffold {
    SuperSpinner(
        title = "下拉选择器",
        items = options,
        selectedIndex = selectedIndex,
        onSelectedIndexChange = { selectedIndex = it }
    )
}

带图标和摘要的选项

kotlin
// 创建一个圆角矩形的 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 = "红色主题",
        summary = "活力四射的红色"
    ),
    SpinnerEntry(
        icon = { Icon(RoundedRectanglePainter(), "Icon", Modifier.padding(end = 12.dp), Color(0xFF3482FF)) },
        title = "蓝色主题",
        summary = "沉稳冷静的蓝色"
    ),
)

Scaffold {
    SuperSpinner(
        title = "功能选择",
        summary = "选择您要执行的操作",
        items = options,
        selectedIndex = selectedIndex,
        onSelectedIndexChange = { selectedIndex = it }
    )
}

组件状态

禁用状态

kotlin
SuperSpinner(
    title = "禁用选择器",
    summary = "此选择器当前不可用",
    items = listOf(SpinnerEntry(title = "选项 1")),
    selectedIndex = 0,
    onSelectedIndexChange = {},
    enabled = false
)

对话框模式

SuperSpinner 还支持对话框模式,适用于显示较多选项或需要更醒目的选择界面时。通过提供 dialogButtonString 参数即可激活此模式。

kotlin
var selectedIndex by remember { mutableStateOf(0) }
val options = listOf(
    SpinnerEntry(title = "选项 A"),
    SpinnerEntry(title = "选项 B"),
    SpinnerEntry(title = "选项 C")
)

Scaffold {
    SuperSpinner(
        title = "对话框模式",
        dialogButtonString = "取消",
        items = options,
        selectedIndex = selectedIndex,
        onSelectedIndexChange = { selectedIndex = it }
    )
}

属性

SuperSpinner 属性(下拉列表模式)

属性名类型说明默认值是否必须
itemsList<SpinnerEntry>选项列表-
selectedIndexInt当前选中项的索引-
titleString选择器的标题-
modifierModifier应用于组件的修饰符Modifier
titleColorBasicComponentColors标题文本的颜色配置BasicComponentDefaults.titleColor()
summaryString?选择器的摘要说明null
summaryColorBasicComponentColors摘要文本的颜色配置BasicComponentDefaults.summaryColor()
spinnerColorsSpinnerColors选择器的颜色配置SpinnerDefaults.spinnerColors()
startAction@Composable (() -> Unit)?左侧显示的自定义内容null
bottomAction@Composable (() -> Unit)?底部显示的自定义内容null
insideMarginPaddingValues组件内部内容的边距BasicComponentDefaults.InsideMargin
maxHeightDp?下拉菜单的最大高度null
enabledBoolean组件是否可交互true
showValueBoolean是否显示当前选中的值true
onSelectedIndexChange((Int) -> Unit)?选中项变化时的回调-

SuperSpinner 属性(对话框模式)

属性名类型说明默认值是否必须
itemsList<SpinnerEntry>选项列表-
selectedIndexInt当前选中项的索引-
titleString选择器的标题-
dialogButtonStringString对话框底部按钮的文本-
modifierModifier应用于组件的修饰符Modifier
popupModifierModifier应用于弹出对话框的修饰符Modifier
titleColorBasicComponentColors标题文本的颜色配置BasicComponentDefaults.titleColor()
summaryString?选择器的摘要说明null
summaryColorBasicComponentColors摘要文本的颜色配置BasicComponentDefaults.summaryColor()
spinnerColorsSpinnerColors选择器的颜色配置SpinnerDefaults.dialogSpinnerColors()
startAction@Composable (() -> Unit)?左侧显示的自定义内容null
bottomAction@Composable (() -> Unit)?底部显示的自定义内容null
insideMarginPaddingValues组件内部内容的边距BasicComponentDefaults.InsideMargin
enabledBoolean组件是否可交互true
showValueBoolean是否显示当前选中的值true
onSelectedIndexChange((Int) -> Unit)?选中项变化时的回调-

SpinnerEntry 属性

属性名类型说明
icon@Composable ((Modifier) -> Unit)?选项的图标组件
titleString?选项的标题
summaryString?选项的摘要描述

SpinnerColors 属性

属性名类型说明
contentColorColor选项标题颜色
summaryColorColor选项摘要颜色
containerColorColor选项背景颜色
selectedContentColorColor选中项标题颜色
selectedSummaryColorColor选中项摘要颜色
selectedContainerColorColor选中项背景颜色
selectedIndicatorColorColor选中指示图标颜色

变更日志

基于 Apache-2.0 许可发布