Skip to content

Commit b665cfd

Browse files
committed
library: Allows other actions to be performed onClick
1 parent f8502f8 commit b665cfd

File tree

4 files changed

+15
-0
lines changed

4 files changed

+15
-0
lines changed

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import top.yukonga.miuix.kmp.basic.CheckboxDefaults
3030
* @param summaryColor The color of the summary.
3131
* @param checkboxColors The [CheckboxColors] of the [SuperCheckbox].
3232
* @param rightActions The [Composable] content that on the right side of the [SuperCheckbox].
33+
* @param onClick The callback when the [SuperCheckbox] is clicked.
3334
* @param insideMargin The margin inside the [SuperCheckbox].
3435
* @param enabled Whether the [SuperCheckbox] is clickable.
3536
*/
@@ -45,6 +46,7 @@ fun SuperCheckbox(
4546
checkboxColors: CheckboxColors = CheckboxDefaults.checkboxColors(),
4647
rightActions: @Composable RowScope.() -> Unit = {},
4748
checkboxLocation: CheckboxLocation = CheckboxLocation.Left,
49+
onClick: (() -> Unit)? = null,
4850
insideMargin: PaddingValues = BasicComponentDefaults.InsideMargin,
4951
enabled: Boolean = true
5052
) {
@@ -84,6 +86,7 @@ fun SuperCheckbox(
8486
},
8587
onClick = {
8688
if (enabled) {
89+
onClick?.invoke()
8790
isChecked = !isChecked
8891
updatedOnCheckedChange?.invoke(isChecked)
8992
}

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ import top.yukonga.miuix.kmp.utils.MiuixPopupUtil.Companion.dismissPopup
6363
* @param maxHeight The maximum height of the [ListPopup].
6464
* @param enabled Whether the [SuperDropdown] is enabled.
6565
* @param showValue Whether to show the selected value of the [SuperDropdown].
66+
* @param onClick The callback when the [SuperDropdown] is clicked.
6667
* @param onSelectedIndexChange The callback when the selected index of the [SuperDropdown] is changed.
6768
*/
6869
@Composable
@@ -79,6 +80,7 @@ fun SuperDropdown(
7980
maxHeight: Dp? = null,
8081
enabled: Boolean = true,
8182
showValue: Boolean = true,
83+
onClick: (() -> Unit)? = null,
8284
onSelectedIndexChange: ((Int) -> Unit)?,
8385
) {
8486
val interactionSource = remember { MutableInteractionSource() }
@@ -185,6 +187,7 @@ fun SuperDropdown(
185187
},
186188
onClick = {
187189
if (enabled) {
190+
onClick?.invoke()
188191
isDropdownExpanded.value = enabled
189192
hapticFeedback.performHapticFeedback(HapticFeedbackType.LongPress)
190193
coroutineScope.launch {

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ import top.yukonga.miuix.kmp.utils.MiuixPopupUtil.Companion.dismissPopup
7676
* @param maxHeight The maximum height of the [ListPopup].
7777
* @param enabled Whether the [SuperSpinner] is enabled.
7878
* @param showValue Whether to show the value of the [SuperSpinner].
79+
* @param onClick The callback when the [SuperSpinner] is clicked.
7980
* @param onSelectedIndexChange The callback to be invoked when the selected index of the [SuperSpinner] is changed.
8081
*/
8182
@Composable
@@ -93,6 +94,7 @@ fun SuperSpinner(
9394
maxHeight: Dp? = null,
9495
enabled: Boolean = true,
9596
showValue: Boolean = true,
97+
onClick: (() -> Unit)? = null,
9698
onSelectedIndexChange: ((Int) -> Unit)?,
9799
) {
98100
val interactionSource = remember { MutableInteractionSource() }
@@ -200,6 +202,7 @@ fun SuperSpinner(
200202
},
201203
onClick = {
202204
if (enabled) {
205+
onClick?.invoke()
203206
isDropdownExpanded.value = enabled
204207
hapticFeedback.performHapticFeedback(HapticFeedbackType.LongPress)
205208
coroutineScope.launch {
@@ -229,6 +232,7 @@ fun SuperSpinner(
229232
* @param insideMargin the [PaddingValues] to be applied inside the [SuperSpinner].
230233
* @param enabled whether the [SuperSpinner] is enabled.
231234
* @param showValue whether to show the value of the [SuperSpinner].
235+
* @param onClick the callback when the [SuperSpinner] is clicked.
232236
* @param onSelectedIndexChange the callback to be invoked when the selected index of the [SuperSpinner] is changed.
233237
*/
234238
@Composable
@@ -246,6 +250,7 @@ fun SuperSpinner(
246250
insideMargin: PaddingValues = BasicComponentDefaults.InsideMargin,
247251
enabled: Boolean = true,
248252
showValue: Boolean = true,
253+
onClick: (() -> Unit)? = null,
249254
onSelectedIndexChange: ((Int) -> Unit)?,
250255
) {
251256
val interactionSource = remember { MutableInteractionSource() }
@@ -328,6 +333,7 @@ fun SuperSpinner(
328333
},
329334
onClick = {
330335
if (enabled) {
336+
onClick?.invoke()
331337
isDropdownExpanded.value = true
332338
hapticFeedback.performHapticFeedback(HapticFeedbackType.LongPress)
333339
coroutineScope.launch {

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import top.yukonga.miuix.kmp.basic.SwitchDefaults
3232
* @param leftAction The [Composable] content that on the left side of the [SuperSwitch].
3333
* @param rightActions The [Composable] content on the right side of the [SuperSwitch].
3434
* @param insideMargin The margin inside the [SuperSwitch].
35+
* @param onClick The callback when the [SuperSwitch] is clicked.
3536
* @param enabled Whether the [SuperSwitch] is clickable.
3637
*/
3738
@Composable
@@ -47,6 +48,7 @@ fun SuperSwitch(
4748
leftAction: @Composable (() -> Unit)? = null,
4849
rightActions: @Composable RowScope.() -> Unit = {},
4950
insideMargin: PaddingValues = BasicComponentDefaults.InsideMargin,
51+
onClick: (() -> Unit)? = null,
5052
enabled: Boolean = true
5153
) {
5254
var isChecked by remember { mutableStateOf(checked) }
@@ -74,6 +76,7 @@ fun SuperSwitch(
7476
},
7577
onClick = {
7678
if (enabled) {
79+
onClick?.invoke()
7780
isChecked = !isChecked
7881
updatedOnCheckedChange?.invoke(isChecked)
7982
localHapticFeedback.performHapticFeedback(HapticFeedbackType.LongPress)

0 commit comments

Comments
 (0)