Skip to content

Commit

Permalink
Merge branch 'preference'
Browse files Browse the repository at this point in the history
  • Loading branch information
yasanglass committed Feb 3, 2024
2 parents bc427d2 + 7e33540 commit 3420d98
Show file tree
Hide file tree
Showing 2 changed files with 167 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
package glass.yasan.concrete.component

import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.tooling.preview.Preview
import glass.yasan.concrete.theme.ConcreteTheme
import glass.yasan.spine.compose.foundation.grid

@Composable
public fun Preference(
title: @Composable () -> Unit,
modifier: Modifier = Modifier,
description: @Composable (() -> Unit)? = null,
applyPaddings: Boolean = true,
start: @Composable (() -> Unit)? = null,
end: @Composable (() -> Unit)? = null,
) {
val paddingValue = if (applyPaddings) 2.grid else 0.grid

TopBar(
modifier = modifier,
) {
Row(
modifier = Modifier
.fillMaxWidth()
.padding(paddingValue),
verticalAlignment = Alignment.CenterVertically,
) {
start?.let { it() }
Column(
modifier = Modifier.weight(1f),
){
title()
description?.let { it() }
}
end?.let { it() }
}
}
}

// region Preview

@Preview
@Composable
private fun PreferenceLayoutPreview() {
ConcreteTheme {
Preference(
start = {
Text(
modifier = Modifier.background(Color.Red),
text = "Start",
)
},
title = {
Text(
modifier = Modifier.background(Color.Green),
text = "Title",
)
},
description = {
Text(
modifier = Modifier.background(Color.Blue),
text = "Description",
)
},
end = {
Text(
modifier = Modifier.background(Color.Red),
text = "End",
)
},
)
}
}

// endregion Preview
84 changes: 84 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,84 @@
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 3420d98

Please sign in to comment.