Skip to content

Commit

Permalink
Create Switch component
Browse files Browse the repository at this point in the history
  • Loading branch information
yasanglass committed Jan 17, 2024
1 parent cd1cae8 commit b4985a1
Showing 1 changed file with 83 additions and 0 deletions.
83 changes: 83 additions & 0 deletions concrete/src/main/kotlin/glass/yasan/concrete/component/Switch.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
package glass.yasan.concrete.component

import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.tooling.preview.PreviewParameter
import androidx.compose.ui.tooling.preview.PreviewParameterProvider
import androidx.compose.ui.unit.sp
import glass.yasan.concrete.theme.ConcreteTheme
import androidx.compose.material3.Switch as Material3Switch

@Composable
public fun Switch(
title: String,
checked: Boolean,
modifier: Modifier = Modifier,
description: String? = null,
onCheckedChange: (Boolean) -> Unit,
) {
Preference(
title = {
Text(
text = title,
color = ConcreteTheme.colors.content.major,
fontSize = 16.sp,
)
},
description = description?.let {
{
Text(
text = it,
color = ConcreteTheme.colors.content.minor,
fontSize = 14.sp,
)
}
},
modifier = modifier,
end = {
Material3Switch(
checked = checked,
onCheckedChange = onCheckedChange,
)
},
)
}

// region Preview

internal enum class SwitchPreviewParams(
val title: String = "Title",
val description: String? = "Description",
val checked: Boolean = true
) {
Unchecked(
checked = false,
),
WithoutDescription(
description = null,
),
}

internal class SwitchPreviewParamsProvider : PreviewParameterProvider<SwitchPreviewParams> {
override val values: Sequence<SwitchPreviewParams> = SwitchPreviewParams.entries.asSequence()
}

@Preview
@Composable
internal fun SwitchPreview(
@PreviewParameter(SwitchPreviewParamsProvider::class) params: SwitchPreviewParams,
) {
ConcreteTheme {
with(params) {
Switch(
title = title,
description = description,
checked = checked,
onCheckedChange = {},
)
}
}
}

// endregion Preview

0 comments on commit b4985a1

Please sign in to comment.