AdditionalUrlsEditor.kt

4.7 KB · raw

1package com.peachpasswords.ui.vault23import androidx.compose.foundation.background4import androidx.compose.foundation.border5import androidx.compose.foundation.clickable6import androidx.compose.foundation.layout.Arrangement7import androidx.compose.foundation.layout.Box8import androidx.compose.foundation.layout.Column9import androidx.compose.foundation.layout.Row10import androidx.compose.foundation.layout.Spacer11import androidx.compose.foundation.layout.fillMaxWidth12import androidx.compose.foundation.layout.height13import androidx.compose.foundation.layout.padding14import androidx.compose.foundation.layout.width15import androidx.compose.foundation.shape.RoundedCornerShape16import androidx.compose.foundation.text.BasicTextField17import androidx.compose.material3.Text18import androidx.compose.runtime.Composable19import androidx.compose.ui.Alignment20import androidx.compose.ui.Modifier21import androidx.compose.ui.draw.clip22import androidx.compose.ui.graphics.Color23import androidx.compose.ui.graphics.SolidColor24import androidx.compose.ui.text.TextStyle25import androidx.compose.ui.unit.dp26import androidx.compose.ui.unit.sp27import com.peachpasswords.ui.theme.LocalPeachAccent28import com.peachpasswords.ui.theme.PeachColors29import com.peachpasswords.ui.theme.PeachType3031/** E3 — hard cap on additional URLs, matching the spec. */32const val MAX_ADDITIONAL_URLS = 53334/**35 * E3 — editor block for the additional-URLs list. Self-contained (mirrors the36 * underline `Field` style in EntryEditScreen) so it drops into the login branch37 * below the main `url` field without depending on the screen's private `Field`.38 *39 * Each row is an underlined input labeled "URL N" with an "×" remove control.40 * A ghost "+ add URL" affordance appends an empty entry; it disappears at the41 * cap and is replaced by the limit hint.42 */43@Composable44fun AdditionalUrlsEditor(45    urls: List<String>,46    onChange: (Int, String) -> Unit,47    onAdd: () -> Unit,48    onRemove: (Int) -> Unit,49) {50    val accent = LocalPeachAccent.current51    Column(Modifier.fillMaxWidth()) {52        urls.forEachIndexed { index, value ->53            // Label numbering starts at 2 so it reads as a continuation of the54            // primary URL field (which is conceptually "URL 1").55            Column(Modifier.fillMaxWidth().padding(bottom = 14.dp)) {56                Text(57                    "URL ${index + 2}",58                    color = PeachColors.T1,59                    fontFamily = PeachType.Mono,60                    fontSize = 8.sp,61                )62                Spacer(Modifier.height(6.dp))63                Row(verticalAlignment = Alignment.CenterVertically) {64                    Box(65                        Modifier.weight(1f)66                            .border(1.dp, PeachColors.T3, RoundedCornerShape(10.dp))67                            .padding(horizontal = 12.dp, vertical = 12.dp),68                    ) {69                        BasicTextField(70                            value = value,71                            onValueChange = { onChange(index, it) },72                            singleLine = true,73                            textStyle = TextStyle(74                                color = PeachColors.T0,75                                fontFamily = PeachType.Mono,76                                fontSize = 13.sp,77                            ),78                            cursorBrush = SolidColor(accent),79                            modifier = Modifier.fillMaxWidth(),80                        )81                    }82                    Spacer(Modifier.width(8.dp))83                    Text(84                        "×",85                        color = PeachColors.T2,86                        fontFamily = PeachType.Mono,87                        fontSize = 16.sp,88                        modifier = Modifier89                            .clip(RoundedCornerShape(6.dp))90                            .clickable { onRemove(index) }91                            .padding(horizontal = 8.dp, vertical = 4.dp),92                    )93                }94            }95        }9697        if (urls.size < MAX_ADDITIONAL_URLS) {98            Text(99                "+ add URL",100                color = accent,101                fontFamily = PeachType.Mono,102                fontSize = 11.sp,103                modifier = Modifier104                    .clip(RoundedCornerShape(6.dp))105                    .clickable(onClick = onAdd)106                    .padding(vertical = 4.dp),107            )108            Spacer(Modifier.height(14.dp))109        } else {110            Text(111                "Max $MAX_ADDITIONAL_URLS additional URLs",112                color = PeachColors.T2,113                fontFamily = PeachType.Mono,114                fontSize = 9.sp,115            )116            Spacer(Modifier.height(14.dp))117        }118    }119}