@@ -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,15 @@ 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
52+ import top.yukonga.miuix.kmp.extra.SuperSpinnerAsDialog
4253import top.yukonga.miuix.kmp.extra.SuperSwitch
4354import top.yukonga.miuix.kmp.theme.MiuixTheme
4455import top.yukonga.miuix.kmp.utils.MiuixPopupUtil.Companion.dismissDialog
@@ -52,8 +63,17 @@ fun TextComponent() {
5263 var switch by remember { mutableStateOf(false ) }
5364 var switchTrue by remember { mutableStateOf(true ) }
5465 val dropdownOptions = listOf (" Option 1" , " Option 2" , " Option 3" , " Option 4" )
55- val dropdownSelectedOption = remember { mutableStateOf(0 ) }
56- val dropdownSelectedOptionRight = remember { mutableStateOf(1 ) }
66+ val dropdownOptionSelected = remember { mutableStateOf(0 ) }
67+ val dropdownOptionSelectedRight = remember { mutableStateOf(1 ) }
68+ val spinnerOptions = listOf (
69+ SpinnerEntry (icon = { Icon (RoundedRectanglePainter (), " Icon" , Modifier .padding(end = 12 .dp), Color (0xFFFF5B29 )) }, " Option 1" , " Red" ),
70+ SpinnerEntry (icon = { Icon (RoundedRectanglePainter (), " Icon" , Modifier .padding(end = 12 .dp), Color (0xFF36D167 )) }, " Option 2" , " Green" ),
71+ SpinnerEntry (icon = { Icon (RoundedRectanglePainter (), " Icon" , Modifier .padding(end = 12 .dp), Color (0xFF3482FF )) }, " Option 3" , " Blue" ),
72+ SpinnerEntry (icon = { Icon (RoundedRectanglePainter (), " Icon" , Modifier .padding(end = 12 .dp), Color (0xFFFFB21D )) }, " Option 4" , " Yellow" ),
73+ )
74+ val spinnerOptionSelected = remember { mutableStateOf(0 ) }
75+ val spinnerOptionSelectedRight = remember { mutableStateOf(1 ) }
76+ val spinnerOptionSelectedDialog = remember { mutableStateOf(2 ) }
5777 var miuixSuperCheckbox by remember { mutableStateOf(" State: false" ) }
5878 var miuixSuperCheckboxState by remember { mutableStateOf(false ) }
5979 var miuixSuperRightCheckbox by remember { mutableStateOf(" false" ) }
@@ -295,7 +315,6 @@ fun TextComponent() {
295315 }
296316
297317 SmallTitle (text = " Dropdown" )
298-
299318 Card (
300319 modifier = Modifier
301320 .padding(horizontal = 12 .dp)
@@ -305,17 +324,17 @@ fun TextComponent() {
305324 title = " Dropdown" ,
306325 summary = " Popup near click" ,
307326 items = dropdownOptions,
308- selectedIndex = dropdownSelectedOption .value,
309- onSelectedIndexChange = { newOption -> dropdownSelectedOption .value = newOption },
327+ selectedIndex = dropdownOptionSelected .value,
328+ onSelectedIndexChange = { newOption -> dropdownOptionSelected .value = newOption },
310329 )
311330
312331 SuperDropdown (
313332 title = " Dropdown" ,
314333 summary = " Popup always on right" ,
315- alwaysRight = true ,
316334 items = dropdownOptions,
317- selectedIndex = dropdownSelectedOptionRight.value,
318- onSelectedIndexChange = { newOption -> dropdownSelectedOptionRight.value = newOption },
335+ selectedIndex = dropdownOptionSelectedRight.value,
336+ onSelectedIndexChange = { newOption -> dropdownOptionSelectedRight.value = newOption },
337+ mode = DropDownMode .AlwaysAtRight
319338 )
320339
321340 SuperDropdown (
@@ -327,6 +346,47 @@ fun TextComponent() {
327346 )
328347 }
329348
349+ SmallTitle (text = " Spinner" )
350+ Card (
351+ modifier = Modifier
352+ .padding(horizontal = 12 .dp)
353+ .padding(bottom = 6 .dp)
354+ ) {
355+ SuperSpinner (
356+ title = " Spinner" ,
357+ summary = " Spinner near click" ,
358+ items = spinnerOptions,
359+ selectedIndex = spinnerOptionSelected.value,
360+ onSelectedIndexChange = { newOption -> spinnerOptionSelected.value = newOption },
361+ )
362+
363+ SuperSpinner (
364+ title = " Spinner" ,
365+ summary = " Spinner always on right" ,
366+ items = spinnerOptions,
367+ selectedIndex = spinnerOptionSelectedRight.value,
368+ onSelectedIndexChange = { newOption -> spinnerOptionSelectedRight.value = newOption },
369+ mode = SpinnerMode .AlwaysAtRight ,
370+ )
371+
372+ SuperSpinnerAsDialog (
373+ title = " Spinner" ,
374+ summary = " Spinner as Dialog" ,
375+ dialogButtonString = " Cancel" ,
376+ items = spinnerOptions,
377+ selectedIndex = spinnerOptionSelectedDialog.value,
378+ onSelectedIndexChange = { newOption -> spinnerOptionSelectedDialog.value = newOption },
379+ )
380+
381+ SuperSpinner (
382+ title = " Disabled Spinner" ,
383+ items = listOf (SpinnerEntry (icon = null , title = " Option 4" )),
384+ selectedIndex = 0 ,
385+ onSelectedIndexChange = {},
386+ enabled = false
387+ )
388+ }
389+
330390 dialog(showDialog)
331391 dialog2(showDialog2)
332392}
@@ -424,3 +484,17 @@ fun dialog2(showDialog: MutableState<Boolean>) {
424484 }
425485 }
426486}
487+
488+ class RoundedRectanglePainter (
489+ private val cornerRadius : Dp = 6 .dp
490+ ) : Painter() {
491+ override val intrinsicSize = Size .Unspecified
492+
493+ override fun DrawScope.onDraw () {
494+ drawRoundRect(
495+ color = Color .White ,
496+ size = Size (size.width, size.height),
497+ cornerRadius = CornerRadius (cornerRadius.toPx(), cornerRadius.toPx())
498+ )
499+ }
500+ }
0 commit comments