Advertisement
BojanNovakovic

outline_mrmak

May 3rd, 2024
1,398
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Kotlin 2.93 KB | None | 0 0
  1. package ui.commonUi
  2.  
  3. import androidx.compose.foundation.ExperimentalFoundationApi
  4. import androidx.compose.foundation.Image
  5. import androidx.compose.foundation.basicMarquee
  6. import androidx.compose.foundation.layout.Column
  7. import androidx.compose.foundation.layout.padding
  8. import androidx.compose.material.IconButton
  9. import androidx.compose.material.OutlinedTextField
  10. import androidx.compose.material.Text
  11. import androidx.compose.runtime.Composable
  12. import androidx.compose.ui.Modifier
  13. import androidx.compose.ui.graphics.ColorFilter
  14. import androidx.compose.ui.text.TextStyle
  15. import androidx.compose.ui.text.style.TextAlign
  16. import androidx.compose.ui.unit.dp
  17. import androidx.compose.ui.unit.sp
  18. import com.bojan.moveset.MR
  19. import dev.icerock.moko.resources.compose.colorResource
  20. import dev.icerock.moko.resources.compose.painterResource
  21. import dev.icerock.moko.resources.compose.stringResource
  22.  
  23. @OptIn(ExperimentalFoundationApi::class)
  24. @Composable
  25. fun MovesetOutlineTextField(
  26.     value: String,
  27.     onValueChange: (String) -> Unit,
  28.     onClear: () -> Unit,
  29.     modifier: Modifier = Modifier,
  30.     enabled: Boolean = true,
  31.     label: String? = null,
  32.     placeholder: String? = null,
  33.     errorText: String? = null
  34. ) {
  35.     Column {
  36.         OutlinedTextField(
  37.             value = value,
  38.             onValueChange = onValueChange,
  39.             singleLine = true,
  40.             label = { label?.let { Text(it) } },
  41.             enabled = enabled,
  42.             readOnly = !enabled,
  43.             placeholder = { placeholder?.let { Text(it) } },
  44.             modifier = modifier,
  45.             textStyle = TextStyle(color = colorResource(MR.colors.font_on_surface_color)),
  46.             trailingIcon = {
  47.                 if (enabled) {
  48.                     val trailingIconEnabled = value.isNotEmpty() && enabled
  49.                     InputCloseIcon(onClick = onClear, trailingIconEnabled)
  50.                 }
  51.             },
  52.             isError = !errorText.isNullOrEmpty()
  53.         )
  54.          val errorString = errorText ?: ""
  55.  
  56.         Text(
  57.             text = errorString,
  58.             style = TextStyle(color = colorResource(MR.colors.alert_text_on_surface_color)),
  59.             fontSize = 14.sp,
  60.             maxLines = 1,
  61.             modifier = Modifier.basicMarquee(delayMillis = 0, initialDelayMillis = 1200)
  62.         )
  63.  
  64.     }
  65. }
  66.  
  67. @Composable
  68. private fun InputCloseIcon(onClick: () -> Unit, enabled: Boolean) {
  69.     val resource = if (enabled) MR.colors.secondary_button_content_color else MR.colors.disabled_element_tint
  70.     IconButton(onClick = onClick, enabled = enabled) {
  71.         Image(
  72.             painter = painterResource(MR.images.close_image),
  73.             contentDescription = stringResource(MR.strings.close),
  74.             colorFilter = ColorFilter.tint(colorResource(resource))
  75.         )
  76.     }
  77. }
  78.  
  79. @Composable
  80. fun NoItemsText() {
  81.     Text(stringResource(MR.strings.no_items), textAlign = TextAlign.Center, modifier = Modifier.padding(16.dp))
  82. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement