Skip to content

Commit b5fdab1

Browse files
committed
library: Add disabled state to super component
1 parent 51a67ff commit b5fdab1

File tree

7 files changed

+53
-16
lines changed

7 files changed

+53
-16
lines changed

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

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,13 @@ fun TextComponent() {
205205
},
206206
)
207207

208+
SuperCheckbox(
209+
title = "Disabled Checkbox",
210+
checked = true,
211+
enabled = false,
212+
onCheckedChange = {},
213+
)
214+
208215
SuperSwitch(
209216
title = "Switch",
210217
summary = "Click to expand a Switch",
@@ -236,14 +243,27 @@ fun TextComponent() {
236243
)
237244
}
238245

246+
SuperSwitch(
247+
title = "Disabled Switch",
248+
checked = true,
249+
enabled = false,
250+
onCheckedChange = {},
251+
)
252+
239253
SuperArrow(
240-
title = "Dialog",
254+
title = "Arrow",
241255
summary = "Click to show Dialog 2",
242256
onClick = {
243257
showDialog2.value = true
244258
}
245259
)
246260

261+
SuperArrow(
262+
title = "Disabled Arrow",
263+
onClick = {},
264+
enabled = false
265+
)
266+
247267
SuperDropdown(
248268
title = "Dropdown",
249269
summary = "Popup near click",
@@ -261,6 +281,13 @@ fun TextComponent() {
261281
onSelectedIndexChange = { newOption -> dropdownSelectedOptionRight.value = newOption },
262282
)
263283

284+
SuperDropdown(
285+
title = "Disabled Dropdown",
286+
items = listOf("Option 1"),
287+
selectedIndex = 0,
288+
onSelectedIndexChange = {},
289+
enabled = false
290+
)
264291
}
265292

266293
dialog(showDialog)

miuix/src/commonMain/kotlin/top/yukonga/miuix/kmp/basic/Component.kt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,15 +48,17 @@ fun BasicComponent(
4848
rightActions: @Composable RowScope.() -> Unit = {},
4949
onClick: (() -> Unit)? = null,
5050
interactionSource: MutableInteractionSource? = null,
51-
indication: Indication? = null
51+
indication: Indication? = null,
52+
enabled: Boolean = true
5253
) {
5354
val interactionSource = interactionSource ?: remember { MutableInteractionSource() }
5455
val indication = indication ?: createRipple()
5556
val insideMargin = remember { insideMargin } ?: remember { DpSize(16.dp, 16.dp) }
5657
val paddingModifier = remember(insideMargin) {
5758
Modifier.padding(horizontal = insideMargin.width, vertical = insideMargin.height)
5859
}
59-
60+
val titleColor = if (enabled) titleColor else MiuixTheme.colorScheme.disabledOnSecondaryVariant
61+
val summaryColor = if (enabled) summaryColor else MiuixTheme.colorScheme.disabledOnSecondaryVariant
6062
Row(
6163
modifier = if (onClick != null) {
6264
modifier

miuix/src/commonMain/kotlin/top/yukonga/miuix/kmp/basic/Slider.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ fun Slider(
6767
(round(newValue * factor) / factor).coerceIn(minValue, maxValue)
6868
}
6969
}
70-
val color = rememberUpdatedState(if (enabled) MiuixTheme.colorScheme.primary else MiuixTheme.colorScheme.disabledPrimarySlider)
70+
val foregroundColor = rememberUpdatedState(if (enabled) MiuixTheme.colorScheme.primary else MiuixTheme.colorScheme.disabledPrimarySlider)
7171
val backgroundColor = rememberUpdatedState(MiuixTheme.colorScheme.tertiaryContainerVariant)
7272

7373
Box(
@@ -105,11 +105,11 @@ fun Slider(
105105
SliderBackground(
106106
modifier = Modifier.fillMaxWidth().height(height),
107107
backgroundColor = backgroundColor.value,
108+
foregroundColor = foregroundColor.value,
108109
effect = effect,
109110
progress = progress,
110111
minValue = minValue,
111112
maxValue = maxValue,
112-
color = color.value
113113
)
114114
}
115115
}
@@ -118,11 +118,11 @@ fun Slider(
118118
fun SliderBackground(
119119
modifier: Modifier,
120120
backgroundColor: Color,
121+
foregroundColor: Color,
121122
effect: Boolean,
122123
progress: Float,
123124
minValue: Float,
124125
maxValue: Float,
125-
color: Color
126126
) {
127127
Canvas(modifier = modifier.clip(SquircleShape(100.dp)).background(backgroundColor)) {
128128
val barHeight = size.height
@@ -131,7 +131,7 @@ fun SliderBackground(
131131
val cornerRadius = if (effect) CornerRadius(barHeight / 2) else CornerRadius.Zero
132132

133133
drawRoundRect(
134-
color = color,
134+
color = foregroundColor,
135135
size = Size(progressWidth, barHeight),
136136
topLeft = Offset(0f, center.y - barHeight / 2),
137137
cornerRadius = cornerRadius

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import top.yukonga.miuix.kmp.theme.MiuixTheme
3232
* @param rightText The text on the right side of the [SuperArrow].
3333
* @param onClick The callback when the [SuperArrow] is clicked.
3434
* @param insideMargin The margin inside the [SuperArrow].
35+
* @param enabled Whether the [SuperArrow] is clickable.
3536
*/
3637
@Composable
3738
fun SuperArrow(
@@ -43,7 +44,8 @@ fun SuperArrow(
4344
leftAction: @Composable (() -> Unit)? = null,
4445
rightText: String? = null,
4546
onClick: (() -> Unit)? = null,
46-
insideMargin: DpSize = DpSize(16.dp, 16.dp)
47+
insideMargin: DpSize = DpSize(16.dp, 16.dp),
48+
enabled: Boolean = true
4749
) {
4850
val updatedOnClick by rememberUpdatedState(onClick)
4951
BasicComponent(
@@ -55,7 +57,8 @@ fun SuperArrow(
5557
summaryColor = summaryColor,
5658
leftAction = leftAction,
5759
rightActions = { createRightActions(rightText) },
58-
onClick = updatedOnClick
60+
onClick = updatedOnClick,
61+
enabled = enabled
5962
)
6063
}
6164

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,8 @@ fun SuperCheckbox(
8181
isChecked = !isChecked
8282
updatedOnCheckedChange?.invoke(isChecked)
8383
}
84-
}
84+
},
85+
enabled = enabled
8586
)
8687
}
8788

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

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ expect fun modifierPlatform(modifier: Modifier, isHovered: MutableState<Boolean>
9090
* @param defaultWindowInsetsPadding Whether to apply default window insets padding to the [SuperDropdown].
9191
* @param selectedIndex The index of the selected option.
9292
* @param onSelectedIndexChange The callback when the index is selected.
93+
* @param enabled Whether the [SuperDropdown] is enabled.
9394
*/
9495
@Composable
9596
fun SuperDropdown(
@@ -103,7 +104,8 @@ fun SuperDropdown(
103104
insideMargin: DpSize = DpSize(16.dp, 16.dp),
104105
defaultWindowInsetsPadding: Boolean = true,
105106
selectedIndex: Int,
106-
onSelectedIndexChange: (Int) -> Unit
107+
onSelectedIndexChange: (Int) -> Unit,
108+
enabled: Boolean = true
107109
) {
108110
val hapticFeedback = LocalHapticFeedback.current
109111
val density = LocalDensity.current
@@ -157,7 +159,7 @@ fun SuperDropdown(
157159
}
158160
},
159161
onTap = { offset ->
160-
isDropdownExpanded.value = true
162+
isDropdownExpanded.value = enabled
161163
alignLeft = offset.x < (size.width / 2)
162164
}
163165
)
@@ -177,7 +179,7 @@ fun SuperDropdown(
177179
modifier = Modifier.padding(end = 6.dp),
178180
text = items[selectedIndex],
179181
fontSize = 15.sp,
180-
color = MiuixTheme.colorScheme.onSurfaceVariantActions,
182+
color = if (enabled) MiuixTheme.colorScheme.onSurfaceVariantActions else MiuixTheme.colorScheme.disabledOnSecondaryVariant,
181183
textAlign = TextAlign.End,
182184
)
183185
Image(
@@ -186,12 +188,13 @@ fun SuperDropdown(
186188
.align(Alignment.CenterVertically),
187189
imageVector = MiuixIcons.ArrowUpDown,
188190
colorFilter = BlendModeColorFilter(
189-
MiuixTheme.colorScheme.onSurfaceVariantActions,
191+
if (enabled) MiuixTheme.colorScheme.onSurfaceVariantActions else MiuixTheme.colorScheme.disabledOnSecondaryVariant,
190192
BlendMode.SrcIn
191193
),
192194
contentDescription = null
193195
)
194-
}
196+
},
197+
enabled = enabled
195198
)
196199
BackHandler(
197200
enabled = isDropdownExpanded.value

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ fun SuperSwitch(
7272
isChecked = !isChecked
7373
updatedOnCheckedChange?.invoke(isChecked)
7474
}
75-
}
75+
},
76+
enabled = enabled
7677
)
7778
}

0 commit comments

Comments
 (0)