Skip to content

Commit

Permalink
Switch & SwitchWithText param renaming
Browse files Browse the repository at this point in the history
`isChecked` renamed to `checked` for consistency across the library.
  • Loading branch information
Tweener committed Aug 28, 2024
1 parent 034509c commit eeae156
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 21 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package com.tweener.czan.preview.designsystem.atom.switch

import androidx.compose.runtime.Composable
import com.tweener.czan.preview.UiModePreviews
import com.tweener.czan.designsystem.atom.switch.Switch
import com.tweener.czan.designsystem.atom.switch.SwitchStyle
import com.tweener.czan.preview.CzanThemePreview
import com.tweener.czan.preview.UiModePreviews

/**
* @author Vivien Mahe
Expand All @@ -17,15 +17,15 @@ import com.tweener.czan.preview.CzanThemePreview
@Composable
private fun SwitchPrimaryCheckedPreview() {
CzanThemePreview {
Switch(isChecked = true)
Switch(checked = true)
}
}

@UiModePreviews
@Composable
private fun SwitchPrimaryNotCheckedPreview() {
CzanThemePreview {
Switch(isChecked = false)
Switch(checked = false)
}
}

Expand All @@ -37,15 +37,15 @@ private fun SwitchPrimaryNotCheckedPreview() {
@Composable
private fun SwitchSecondaryCheckedPreview() {
CzanThemePreview {
Switch(isChecked = true, style = SwitchStyle.SECONDARY)
Switch(checked = true, style = SwitchStyle.SECONDARY)
}
}

@UiModePreviews
@Composable
private fun SwitchSecondaryNotCheckedPreview() {
CzanThemePreview {
Switch(isChecked = false, style = SwitchStyle.SECONDARY)
Switch(checked = false, style = SwitchStyle.SECONDARY)
}
}

Expand All @@ -57,15 +57,15 @@ private fun SwitchSecondaryNotCheckedPreview() {
@Composable
private fun SwitchTertiaryCheckedPreview() {
CzanThemePreview {
Switch(isChecked = true, style = SwitchStyle.TERTIARY)
Switch(checked = true, style = SwitchStyle.TERTIARY)
}
}

@UiModePreviews
@Composable
private fun SwitchTertiaryNotCheckedPreview() {
CzanThemePreview {
Switch(isChecked = false, style = SwitchStyle.TERTIARY)
Switch(checked = false, style = SwitchStyle.TERTIARY)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ import com.tweener.czan.preview.CzanThemePreview
@Composable
private fun SwitchWithTextCheckedPreview() {
CzanThemePreview {
SwitchWithText(text = "Switch checked with text", isChecked = true)
SwitchWithText(text = "Switch checked with text", checked = true)
}
}

@UiModePreviews
@Composable
private fun SwitchWithTextNotCheckedPreview() {
CzanThemePreview {
SwitchWithText(text = "Switch not checked with text", isChecked = false)
SwitchWithText(text = "Switch not checked with text", checked = false)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,6 @@ import androidx.compose.material.icons.outlined.Close
import androidx.compose.material3.Icon
import androidx.compose.material3.SwitchDefaults
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import io.github.alexzhirkevich.cupertino.adaptive.AdaptiveSwitch
import io.github.alexzhirkevich.cupertino.adaptive.ExperimentalAdaptiveApi
Expand All @@ -30,19 +26,15 @@ import io.github.alexzhirkevich.cupertino.adaptive.ExperimentalAdaptiveApi
fun Switch(
modifier: Modifier = Modifier,
style: SwitchStyle = SwitchStyle.PRIMARY,
isChecked: Boolean = false,
checked: Boolean = false,
onCheckedChange: ((Boolean) -> Unit)? = null
) {
var checked by remember { mutableStateOf(isChecked) }
val iconVector = if (checked) Icons.Outlined.Check else Icons.Outlined.Close

AdaptiveSwitch(
modifier = modifier,
checked = checked,
onCheckedChange = {
checked = it
onCheckedChange?.invoke(it)
},
onCheckedChange = { onCheckedChange?.invoke(it) },
thumbContent = {
Icon(
modifier = Modifier.size(SwitchDefaults.IconSize),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import com.tweener.czan.theme.Size
fun SwitchWithText(
text: String,
modifier: Modifier = Modifier,
isChecked: Boolean = false,
checked: Boolean = false,
onCheckedChange: ((Boolean) -> Unit)? = null
) {
Row(
Expand All @@ -39,7 +39,7 @@ fun SwitchWithText(
Spacer(modifier = Modifier.padding(horizontal = Size.Padding.Default))

Switch(
isChecked = isChecked,
checked = checked,
onCheckedChange = { onCheckedChange?.invoke(it) },
)
}
Expand Down

0 comments on commit eeae156

Please sign in to comment.