Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package ui.commonUi
- import androidx.compose.foundation.ExperimentalFoundationApi
- import androidx.compose.foundation.Image
- import androidx.compose.foundation.basicMarquee
- import androidx.compose.foundation.layout.Column
- import androidx.compose.foundation.layout.padding
- import androidx.compose.material.IconButton
- import androidx.compose.material.OutlinedTextField
- import androidx.compose.material.Text
- import androidx.compose.runtime.Composable
- import androidx.compose.ui.Modifier
- import androidx.compose.ui.graphics.ColorFilter
- import androidx.compose.ui.text.TextStyle
- import androidx.compose.ui.text.style.TextAlign
- import androidx.compose.ui.unit.dp
- import androidx.compose.ui.unit.sp
- import com.bojan.moveset.MR
- import dev.icerock.moko.resources.compose.colorResource
- import dev.icerock.moko.resources.compose.painterResource
- import dev.icerock.moko.resources.compose.stringResource
- @OptIn(ExperimentalFoundationApi::class)
- @Composable
- fun MovesetOutlineTextField(
- value: String,
- onValueChange: (String) -> Unit,
- onClear: () -> Unit,
- modifier: Modifier = Modifier,
- enabled: Boolean = true,
- label: String? = null,
- placeholder: String? = null,
- errorText: String? = null
- ) {
- Column {
- OutlinedTextField(
- value = value,
- onValueChange = onValueChange,
- singleLine = true,
- label = { label?.let { Text(it) } },
- enabled = enabled,
- readOnly = !enabled,
- placeholder = { placeholder?.let { Text(it) } },
- modifier = modifier,
- textStyle = TextStyle(color = colorResource(MR.colors.font_on_surface_color)),
- trailingIcon = {
- if (enabled) {
- val trailingIconEnabled = value.isNotEmpty() && enabled
- InputCloseIcon(onClick = onClear, trailingIconEnabled)
- }
- },
- isError = !errorText.isNullOrEmpty()
- )
- val errorString = errorText ?: ""
- Text(
- text = errorString,
- style = TextStyle(color = colorResource(MR.colors.alert_text_on_surface_color)),
- fontSize = 14.sp,
- maxLines = 1,
- modifier = Modifier.basicMarquee(delayMillis = 0, initialDelayMillis = 1200)
- )
- }
- }
- @Composable
- private fun InputCloseIcon(onClick: () -> Unit, enabled: Boolean) {
- val resource = if (enabled) MR.colors.secondary_button_content_color else MR.colors.disabled_element_tint
- IconButton(onClick = onClick, enabled = enabled) {
- Image(
- painter = painterResource(MR.images.close_image),
- contentDescription = stringResource(MR.strings.close),
- colorFilter = ColorFilter.tint(colorResource(resource))
- )
- }
- }
- @Composable
- fun NoItemsText() {
- Text(stringResource(MR.strings.no_items), textAlign = TextAlign.Center, modifier = Modifier.padding(16.dp))
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement