Skip to content

Commit 9557b18

Browse files
committed
3
1 parent 0ce64a9 commit 9557b18

File tree

3 files changed

+18
-15
lines changed

3 files changed

+18
-15
lines changed

composeApp/src/commonMain/kotlin/component/TextComponent.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ import top.yukonga.miuix.kmp.extra.SuperCheckbox
4949
import top.yukonga.miuix.kmp.extra.SuperDialog
5050
import top.yukonga.miuix.kmp.extra.SuperDropdown
5151
import top.yukonga.miuix.kmp.extra.SuperSpinner
52-
import top.yukonga.miuix.kmp.extra.SuperSpinnerAsDialog
5352
import top.yukonga.miuix.kmp.extra.SuperSwitch
5453
import top.yukonga.miuix.kmp.theme.MiuixTheme
5554
import top.yukonga.miuix.kmp.utils.MiuixPopupUtil.Companion.dismissDialog
@@ -369,7 +368,7 @@ fun TextComponent() {
369368
mode = SpinnerMode.AlwaysOnRight,
370369
)
371370

372-
SuperSpinnerAsDialog(
371+
SuperSpinner(
373372
title = "Spinner",
374373
summary = "Spinner as Dialog",
375374
dialogButtonString = "Cancel",

miuix/src/commonMain/kotlin/top/yukonga/miuix/kmp/extra/SuperDropdown.kt

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,6 @@ import kotlin.math.roundToInt
8686
* @param title The title of the [SuperDropdown].
8787
* @param items The options of the [SuperDropdown].
8888
* @param selectedIndex The index of the selected option.
89-
* @param onSelectedIndexChange The callback when the index is selected.
9089
* @param modifier The modifier to be applied to the [SuperDropdown].
9190
* @param popupModifier The modifier to be applied to the popup of the [SuperDropdown].
9291
* @param titleColor The color of the title.
@@ -97,13 +96,14 @@ import kotlin.math.roundToInt
9796
* @param insideMargin The margin inside the [SuperDropdown].
9897
* @param defaultWindowInsetsPadding Whether to apply default window insets padding to the [SuperDropdown].
9998
* @param enabled Whether the [SuperDropdown] is enabled.
99+
* @param showValue Whether to show the selected value of the [SuperDropdown].
100+
* @param onSelectedIndexChange The callback when the selected index of the [SuperDropdown] is changed.
100101
*/
101102
@Composable
102103
fun SuperDropdown(
103104
title: String,
104105
items: List<String>,
105106
selectedIndex: Int,
106-
onSelectedIndexChange: (Int) -> Unit,
107107
modifier: Modifier = Modifier,
108108
popupModifier: Modifier = Modifier,
109109
titleColor: BasicComponentColors = BasicComponentDefaults.titleColor(),
@@ -113,7 +113,9 @@ fun SuperDropdown(
113113
horizontalPadding: Dp = 0.dp,
114114
insideMargin: PaddingValues = BasicComponentDefaults.InsideMargin,
115115
defaultWindowInsetsPadding: Boolean = true,
116-
enabled: Boolean = true
116+
enabled: Boolean = true,
117+
showValue: Boolean = true,
118+
onSelectedIndexChange: ((Int) -> Unit)?,
117119
) {
118120
val interactionSource = remember { MutableInteractionSource() }
119121
val isDropdownExpanded = remember { mutableStateOf(false) }
@@ -171,13 +173,15 @@ fun SuperDropdown(
171173
summary = summary,
172174
summaryColor = summaryColor,
173175
rightActions = {
174-
Text(
175-
modifier = Modifier.widthIn(max = 130.dp),
176-
text = items[selectedIndex],
177-
fontSize = MiuixTheme.textStyles.body2.fontSize,
178-
color = actionColor,
179-
textAlign = TextAlign.End,
180-
)
176+
if (showValue) {
177+
Text(
178+
modifier = Modifier.widthIn(max = 130.dp),
179+
text = items[selectedIndex],
180+
fontSize = MiuixTheme.textStyles.body2.fontSize,
181+
color = actionColor,
182+
textAlign = TextAlign.End,
183+
)
184+
}
181185
Image(
182186
modifier = Modifier
183187
.padding(start = 8.dp)
@@ -310,7 +314,7 @@ fun SuperDropdown(
310314
isSelected = selectedIndex == index,
311315
onSelectedIndexChange = {
312316
hapticFeedback.performHapticFeedback(HapticFeedbackType.LongPress)
313-
onSelectedIndexChange(it)
317+
onSelectedIndexChange?.let { it1 -> it1(it) }
314318
dismissPopup(isDropdownExpanded)
315319
},
316320
textWidthDp = textWidthDp,

miuix/src/commonMain/kotlin/top/yukonga/miuix/kmp/extra/SuperSpinner.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,7 @@ fun SuperSpinner(
342342
}
343343

344344
/**
345-
* A [SuperSpinnerAsDialog] component with Miuix style.
345+
* A [SuperSpinner] component with Miuix style, show Spinner as dialog.
346346
*
347347
* @param title the title of the [SuperSpinner].
348348
* @param items the list of [SpinnerEntry] to be shown in the [SuperSpinner].
@@ -362,7 +362,7 @@ fun SuperSpinner(
362362
* @param onSelectedIndexChange the callback to be invoked when the selected index of the [SuperSpinner] is changed.
363363
*/
364364
@Composable
365-
fun SuperSpinnerAsDialog(
365+
fun SuperSpinner(
366366
title: String,
367367
items: List<SpinnerEntry>,
368368
selectedIndex: Int,

0 commit comments

Comments
 (0)