|
| 1 | +package com.redmadrobot.debug.uikit.components |
| 2 | + |
| 3 | +import androidx.compose.foundation.layout.Column |
| 4 | +import androidx.compose.foundation.layout.fillMaxWidth |
| 5 | +import androidx.compose.foundation.layout.padding |
| 6 | +import androidx.compose.foundation.text.KeyboardOptions |
| 7 | +import androidx.compose.material3.OutlinedTextField |
| 8 | +import androidx.compose.material3.OutlinedTextFieldDefaults |
| 9 | +import androidx.compose.material3.Text |
| 10 | +import androidx.compose.material3.TextFieldColors |
| 11 | +import androidx.compose.runtime.Composable |
| 12 | +import androidx.compose.ui.Modifier |
| 13 | +import androidx.compose.ui.text.TextStyle |
| 14 | +import androidx.compose.ui.unit.dp |
| 15 | +import com.redmadrobot.debug.uikit.theme.DebugPanelTheme |
| 16 | + |
| 17 | +private val defaultTextStyle: TextStyle |
| 18 | + @Composable get() = DebugPanelTheme.typography.bodyMedium.copy( |
| 19 | + color = DebugPanelTheme.colors.content.primary, |
| 20 | + ) |
| 21 | + |
| 22 | +private val defaultColors: TextFieldColors |
| 23 | + @Composable get() = OutlinedTextFieldDefaults.colors( |
| 24 | + focusedBorderColor = DebugPanelTheme.colors.content.accent, |
| 25 | + unfocusedBorderColor = DebugPanelTheme.colors.stroke.secondary, |
| 26 | + focusedLabelColor = DebugPanelTheme.colors.content.accent, |
| 27 | + unfocusedLabelColor = DebugPanelTheme.colors.content.tertiary, |
| 28 | + errorBorderColor = DebugPanelTheme.colors.content.error, |
| 29 | + cursorColor = DebugPanelTheme.colors.content.accent, |
| 30 | + ) |
| 31 | + |
| 32 | +@Composable |
| 33 | +public fun PanelTextField( |
| 34 | + value: String, |
| 35 | + label: String, |
| 36 | + onValueChange: (String) -> Unit, |
| 37 | + modifier: Modifier = Modifier, |
| 38 | + isError: Boolean = false, |
| 39 | + errorMessage: String? = null, |
| 40 | + keyboardOptions: KeyboardOptions = KeyboardOptions.Default, |
| 41 | + textStyle: TextStyle = defaultTextStyle, |
| 42 | + colors: TextFieldColors = defaultColors |
| 43 | +) { |
| 44 | + Column(modifier = modifier.fillMaxWidth()) { |
| 45 | + OutlinedTextField( |
| 46 | + value = value, |
| 47 | + onValueChange = onValueChange, |
| 48 | + modifier = Modifier.fillMaxWidth(), |
| 49 | + label = { Text(text = label, style = DebugPanelTheme.typography.bodyMedium) }, |
| 50 | + isError = isError, |
| 51 | + singleLine = true, |
| 52 | + keyboardOptions = keyboardOptions, |
| 53 | + textStyle = textStyle, |
| 54 | + colors = colors, |
| 55 | + ) |
| 56 | + if (isError && errorMessage != null) { |
| 57 | + Text( |
| 58 | + text = errorMessage, |
| 59 | + style = DebugPanelTheme.typography.bodySmall, |
| 60 | + color = DebugPanelTheme.colors.content.error, |
| 61 | + modifier = Modifier.padding(top = 4.dp), |
| 62 | + ) |
| 63 | + } |
| 64 | + } |
| 65 | +} |
0 commit comments