feat(compose): add a password item composable
This commit is contained in:
parent
1b936f623a
commit
68d735c28e
1 changed files with 81 additions and 0 deletions
|
@ -0,0 +1,81 @@
|
||||||
|
package app.passwordstore.ui.compose
|
||||||
|
|
||||||
|
import androidx.compose.foundation.background
|
||||||
|
import androidx.compose.foundation.clickable
|
||||||
|
import androidx.compose.foundation.layout.Arrangement
|
||||||
|
import androidx.compose.foundation.layout.Row
|
||||||
|
import androidx.compose.foundation.layout.fillMaxWidth
|
||||||
|
import androidx.compose.foundation.layout.padding
|
||||||
|
import androidx.compose.foundation.layout.wrapContentWidth
|
||||||
|
import androidx.compose.foundation.lazy.LazyColumn
|
||||||
|
import androidx.compose.material.icons.Icons
|
||||||
|
import androidx.compose.material.icons.automirrored.filled.KeyboardArrowRight
|
||||||
|
import androidx.compose.material3.HorizontalDivider
|
||||||
|
import androidx.compose.material3.Icon
|
||||||
|
import androidx.compose.material3.MaterialTheme
|
||||||
|
import androidx.compose.material3.Text
|
||||||
|
import androidx.compose.material3.minimumInteractiveComponentSize
|
||||||
|
import androidx.compose.runtime.Composable
|
||||||
|
import androidx.compose.ui.Alignment
|
||||||
|
import androidx.compose.ui.Modifier
|
||||||
|
import androidx.compose.ui.graphics.vector.rememberVectorPainter
|
||||||
|
import androidx.compose.ui.unit.dp
|
||||||
|
import app.passwordstore.ui.compose.preview.DevicePreviews
|
||||||
|
import app.passwordstore.ui.compose.preview.ThemePreviews
|
||||||
|
import app.passwordstore.ui.compose.theme.APSTheme
|
||||||
|
|
||||||
|
public enum class ItemType {
|
||||||
|
File,
|
||||||
|
Folder,
|
||||||
|
}
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
public fun PasswordItem(
|
||||||
|
label: String,
|
||||||
|
type: ItemType,
|
||||||
|
onClick: () -> Unit,
|
||||||
|
modifier: Modifier = Modifier
|
||||||
|
) {
|
||||||
|
Row(
|
||||||
|
modifier =
|
||||||
|
modifier
|
||||||
|
.clickable(enabled = true, onClick = onClick)
|
||||||
|
.background(MaterialTheme.colorScheme.background)
|
||||||
|
.minimumInteractiveComponentSize()
|
||||||
|
.padding(horizontal = 16.dp)
|
||||||
|
.fillMaxWidth(),
|
||||||
|
horizontalArrangement = Arrangement.SpaceBetween,
|
||||||
|
verticalAlignment = Alignment.CenterVertically,
|
||||||
|
) {
|
||||||
|
Text(
|
||||||
|
text = label,
|
||||||
|
modifier = Modifier.wrapContentWidth(),
|
||||||
|
style = MaterialTheme.typography.titleMedium,
|
||||||
|
color = MaterialTheme.colorScheme.onBackground,
|
||||||
|
)
|
||||||
|
when (type) {
|
||||||
|
ItemType.File -> {}
|
||||||
|
ItemType.Folder -> {
|
||||||
|
Icon(
|
||||||
|
painter = rememberVectorPainter(Icons.AutoMirrored.Filled.KeyboardArrowRight),
|
||||||
|
contentDescription = "Folder indicator",
|
||||||
|
tint = MaterialTheme.colorScheme.onBackground,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@ThemePreviews
|
||||||
|
@DevicePreviews
|
||||||
|
@Composable
|
||||||
|
private fun PasswordItemPreview() {
|
||||||
|
APSTheme {
|
||||||
|
LazyColumn {
|
||||||
|
items(20) {
|
||||||
|
PasswordItem(label = "Title $it", type = ItemType.entries.random(), onClick = {})
|
||||||
|
HorizontalDivider()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue