@@ -22,6 +22,12 @@ import androidx.compose.runtime.remember
2222import androidx.compose.runtime.setValue
2323import androidx.compose.ui.Alignment
2424import androidx.compose.ui.Modifier
25+ import androidx.compose.ui.geometry.CornerRadius
26+ import androidx.compose.ui.geometry.Size
27+ import androidx.compose.ui.graphics.Color
28+ import androidx.compose.ui.graphics.drawscope.DrawScope
29+ import androidx.compose.ui.graphics.painter.Painter
30+ import androidx.compose.ui.unit.Dp
2531import androidx.compose.ui.unit.dp
2632import top.yukonga.miuix.kmp.basic.BasicComponent
2733import top.yukonga.miuix.kmp.basic.Box
@@ -35,10 +41,14 @@ import top.yukonga.miuix.kmp.basic.Text
3541import top.yukonga.miuix.kmp.basic.TextButton
3642import top.yukonga.miuix.kmp.basic.TextField
3743import top.yukonga.miuix.kmp.extra.CheckboxLocation
44+ import top.yukonga.miuix.kmp.extra.DropDownMode
45+ import top.yukonga.miuix.kmp.extra.SpinnerEntry
46+ import top.yukonga.miuix.kmp.extra.SpinnerMode
3847import top.yukonga.miuix.kmp.extra.SuperArrow
3948import top.yukonga.miuix.kmp.extra.SuperCheckbox
4049import top.yukonga.miuix.kmp.extra.SuperDialog
4150import top.yukonga.miuix.kmp.extra.SuperDropdown
51+ import top.yukonga.miuix.kmp.extra.SuperSpinner
4252import top.yukonga.miuix.kmp.extra.SuperSwitch
4353import top.yukonga.miuix.kmp.theme.MiuixTheme
4454import top.yukonga.miuix.kmp.utils.MiuixPopupUtil.Companion.dismissDialog
@@ -52,8 +62,17 @@ fun TextComponent() {
5262 var switch by remember { mutableStateOf(false ) }
5363 var switchTrue by remember { mutableStateOf(true ) }
5464 val dropdownOptions = listOf (" Option 1" , " Option 2" , " Option 3" , " Option 4" )
55- val dropdownSelectedOption = remember { mutableStateOf(0 ) }
56- val dropdownSelectedOptionRight = remember { mutableStateOf(1 ) }
65+ val dropdownOptionSelected = remember { mutableStateOf(0 ) }
66+ val dropdownOptionSelectedRight = remember { mutableStateOf(1 ) }
67+ val spinnerOptions = listOf (
68+ SpinnerEntry (icon = { Icon (RoundedRectanglePainter (), " Icon" , Modifier .padding(end = 12 .dp), Color (0xFFFF5B29 )) }, " Option 1" , " Red" ),
69+ SpinnerEntry (icon = { Icon (RoundedRectanglePainter (), " Icon" , Modifier .padding(end = 12 .dp), Color (0xFF36D167 )) }, " Option 2" , " Green" ),
70+ SpinnerEntry (icon = { Icon (RoundedRectanglePainter (), " Icon" , Modifier .padding(end = 12 .dp), Color (0xFF3482FF )) }, " Option 3" , " Blue" ),
71+ SpinnerEntry (icon = { Icon (RoundedRectanglePainter (), " Icon" , Modifier .padding(end = 12 .dp), Color (0xFFFFB21D )) }, " Option 4" , " Yellow" ),
72+ )
73+ val spinnerOptionSelected = remember { mutableStateOf(0 ) }
74+ val spinnerOptionSelectedRight = remember { mutableStateOf(1 ) }
75+ val spinnerOptionSelectedDialog = remember { mutableStateOf(2 ) }
5776 var miuixSuperCheckbox by remember { mutableStateOf(" State: false" ) }
5877 var miuixSuperCheckboxState by remember { mutableStateOf(false ) }
5978 var miuixSuperRightCheckbox by remember { mutableStateOf(" false" ) }
@@ -295,7 +314,6 @@ fun TextComponent() {
295314 }
296315
297316 SmallTitle (text = " Dropdown" )
298-
299317 Card (
300318 modifier = Modifier
301319 .padding(horizontal = 12 .dp)
@@ -305,17 +323,17 @@ fun TextComponent() {
305323 title = " Dropdown" ,
306324 summary = " Popup near click" ,
307325 items = dropdownOptions,
308- selectedIndex = dropdownSelectedOption .value,
309- onSelectedIndexChange = { newOption -> dropdownSelectedOption .value = newOption },
326+ selectedIndex = dropdownOptionSelected .value,
327+ onSelectedIndexChange = { newOption -> dropdownOptionSelected .value = newOption },
310328 )
311329
312330 SuperDropdown (
313331 title = " Dropdown" ,
314332 summary = " Popup always on right" ,
315- alwaysRight = true ,
316333 items = dropdownOptions,
317- selectedIndex = dropdownSelectedOptionRight.value,
318- onSelectedIndexChange = { newOption -> dropdownSelectedOptionRight.value = newOption },
334+ selectedIndex = dropdownOptionSelectedRight.value,
335+ onSelectedIndexChange = { newOption -> dropdownOptionSelectedRight.value = newOption },
336+ mode = DropDownMode .AlwaysOnRight
319337 )
320338
321339 SuperDropdown (
@@ -327,6 +345,47 @@ fun TextComponent() {
327345 )
328346 }
329347
348+ SmallTitle (text = " Spinner" )
349+ Card (
350+ modifier = Modifier
351+ .padding(horizontal = 12 .dp)
352+ .padding(bottom = 6 .dp)
353+ ) {
354+ SuperSpinner (
355+ title = " Spinner" ,
356+ summary = " Spinner near click" ,
357+ items = spinnerOptions,
358+ selectedIndex = spinnerOptionSelected.value,
359+ onSelectedIndexChange = { newOption -> spinnerOptionSelected.value = newOption },
360+ )
361+
362+ SuperSpinner (
363+ title = " Spinner" ,
364+ summary = " Spinner always on right" ,
365+ items = spinnerOptions,
366+ selectedIndex = spinnerOptionSelectedRight.value,
367+ onSelectedIndexChange = { newOption -> spinnerOptionSelectedRight.value = newOption },
368+ mode = SpinnerMode .AlwaysOnRight ,
369+ )
370+
371+ SuperSpinner (
372+ title = " Spinner" ,
373+ summary = " Spinner as Dialog" ,
374+ dialogButtonString = " Cancel" ,
375+ items = spinnerOptions,
376+ selectedIndex = spinnerOptionSelectedDialog.value,
377+ onSelectedIndexChange = { newOption -> spinnerOptionSelectedDialog.value = newOption },
378+ )
379+
380+ SuperSpinner (
381+ title = " Disabled Spinner" ,
382+ items = listOf (SpinnerEntry (icon = null , title = " Option 4" )),
383+ selectedIndex = 0 ,
384+ onSelectedIndexChange = {},
385+ enabled = false
386+ )
387+ }
388+
330389 dialog(showDialog)
331390 dialog2(showDialog2)
332391}
@@ -424,3 +483,17 @@ fun dialog2(showDialog: MutableState<Boolean>) {
424483 }
425484 }
426485}
486+
487+ class RoundedRectanglePainter (
488+ private val cornerRadius : Dp = 6 .dp
489+ ) : Painter() {
490+ override val intrinsicSize = Size .Unspecified
491+
492+ override fun DrawScope.onDraw () {
493+ drawRoundRect(
494+ color = Color .White ,
495+ size = Size (size.width, size.height),
496+ cornerRadius = CornerRadius (cornerRadius.toPx(), cornerRadius.toPx())
497+ )
498+ }
499+ }
0 commit comments