This commit is contained in:
Ваше Имя 2025-05-26 14:55:35 +03:00
parent 330f742a7a
commit 7983439890
3 changed files with 155 additions and 0 deletions

View File

@ -0,0 +1,130 @@
package com.example.libary
import androidx.compose.foundation.Image
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.shape.AbsoluteRoundedCornerShape
import androidx.compose.material3.OutlinedTextField
import androidx.compose.material3.Text
import androidx.compose.material3.TextFieldDefaults
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.input.PasswordVisualTransformation
import androidx.compose.ui.text.input.VisualTransformation
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import com.example.libary.theme.AccentColor
@Composable
fun Input(
modifier: Modifier = Modifier,
value: String = "",
placeholder: String = "",
topText: String = "",
errorText: String = "",
pasMode: Boolean = false,
onValueChange: (String) -> Unit,
) {
var vis by remember { mutableStateOf(false) }
Column {
if (topText.isNotEmpty()) {
Text(
text = topText,
color = Color(0xFF7E7E9A),
fontWeight = FontWeight.W400,
fontSize = 14.sp
)
Spacer(Modifier.height(8.dp))
}
OutlinedTextField(
value = value,
modifier = modifier,
onValueChange = onValueChange,
placeholder = {
Text(
text = placeholder,
color = Color(0xFF939396),
fontWeight = FontWeight.W400,
fontSize = 16.sp
)
},
trailingIcon = {
if (pasMode) {
if (vis) {
Image(
painter = painterResource(R.drawable.gl_2),
contentDescription = null,
modifier = Modifier.clickable {
vis = false
}
)
}else {
Image(
painter = painterResource(R.drawable.gl_1),
contentDescription = null,
modifier = Modifier.clickable {
vis = true
}
)
}
}
},
shape = AbsoluteRoundedCornerShape(10.dp),
colors = TextFieldDefaults.colors(
cursorColor = AccentColor,
focusedPlaceholderColor = Color(0xFF939396),
unfocusedPlaceholderColor = Color(0xFF939396),
focusedTextColor = Color.Black,
unfocusedTextColor = Color.Black,
focusedIndicatorColor = if (errorText.isNotEmpty()) Color(0xFFFD3535) else Color(0xFFEBEBEB),
unfocusedIndicatorColor = if (errorText.isNotEmpty()) Color(0xFFFD3535) else Color(0xFFEBEBEB),
focusedContainerColor = if (errorText.isNotEmpty()) Color(0xFFFD3535).copy(0.1f) else Color(0xFFF5F5F9),
unfocusedContainerColor = if (errorText.isNotEmpty()) Color(0xFFFD3535).copy(0.1f) else Color(0xFFF5F5F9)
),
visualTransformation = if (!vis && pasMode) PasswordVisualTransformation('*') else VisualTransformation.None
)
if (errorText.isNotEmpty()) {
Spacer(Modifier.height(8.dp))
Text(
text = errorText,
color = Color(0xFFFD3535),
fontSize = 14.sp,
fontWeight = FontWeight.W400
)
}
}
}
@Preview
@Composable
private fun InputPrev() {
var value by remember { mutableStateOf("") }
Input(
value = value,
placeholder = "Введите имя",
topText = "Вве имя",
pasMode = true,
onValueChange = {
value = it
}
)
}

View File

@ -0,0 +1,13 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="20dp"
android:height="20dp"
android:viewportWidth="20"
android:viewportHeight="20">
<group>
<clip-path
android:pathData="M0,0h20v20h-20z"/>
<path
android:pathData="M0.818,0.14C0.632,-0.047 0.33,-0.047 0.144,0.14C-0.042,0.326 -0.042,0.628 0.144,0.814L4.255,4.925C2.555,6.245 1.131,7.887 0.066,9.757C-0.022,9.907 -0.022,10.093 0.066,10.243C2.235,13.906 4.999,16.215 8.064,16.921C8.7,17.068 9.35,17.142 10.002,17.142C11.763,17.118 13.481,16.592 14.954,15.627L19.185,19.86V19.86C19.372,20.046 19.673,20.046 19.86,19.86C20.046,19.674 20.046,19.372 19.86,19.186L0.818,0.14ZM8.019,8.689L11.313,11.984H11.314C10.699,12.386 9.933,12.481 9.239,12.243C8.545,12.004 7.999,11.458 7.761,10.764C7.523,10.07 7.618,9.304 8.019,8.689L8.019,8.689ZM8.281,15.993C5.544,15.362 3.044,13.292 1.036,10H1.036C2.034,8.293 3.357,6.798 4.931,5.601L7.344,8.014C6.694,8.873 6.501,9.994 6.827,11.02C7.153,12.047 7.957,12.851 8.983,13.177C10.009,13.503 11.13,13.31 11.989,12.66L14.266,14.938H14.266C12.488,16.065 10.337,16.444 8.281,15.993L8.281,15.993ZM10.35,7.655L9.421,6.726C9.613,6.687 9.807,6.668 10.002,6.667C10.886,6.667 11.734,7.018 12.359,7.643C12.984,8.268 13.335,9.116 13.335,10C13.334,10.195 13.315,10.39 13.276,10.581L12.347,9.652H12.348C12.273,9.149 12.038,8.683 11.679,8.324C11.319,7.964 10.853,7.729 10.35,7.655ZM19.934,9.757V9.757C20.022,9.907 20.022,10.093 19.934,10.243C19.096,11.686 18.057,13.003 16.849,14.155L16.174,13.479V13.479C17.26,12.452 18.2,11.281 18.969,10C16.532,6.006 13.356,3.81 10.002,3.81C9.005,3.82 8.019,4.021 7.097,4.401L6.359,3.663C7.503,3.141 8.745,2.867 10.002,2.858C13.774,2.858 17.301,5.308 19.934,9.757L19.934,9.757Z"
android:fillColor="#000000"/>
</group>
</vector>

View File

@ -0,0 +1,12 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="20dp"
android:height="19dp"
android:viewportWidth="20"
android:viewportHeight="19">
<path
android:pathData="M10,6.955C9.216,6.955 8.464,7.266 7.909,7.82C7.355,8.374 7.043,9.126 7.042,9.91C7.042,10.694 7.353,11.446 7.908,12C8.462,12.555 9.214,12.867 9.998,12.867C10.781,12.867 11.533,12.556 12.088,12.001C12.642,11.447 12.954,10.695 12.954,9.911C12.953,9.128 12.642,8.376 12.088,7.822C11.534,7.268 10.783,6.956 10,6.956L10,6.955ZM10,11.225C9.651,11.226 9.316,11.087 9.069,10.84C8.821,10.594 8.683,10.259 8.682,9.91C8.682,9.561 8.821,9.226 9.068,8.979C9.315,8.732 9.65,8.593 9.999,8.594C10.348,8.594 10.683,8.733 10.929,8.98C11.176,9.227 11.314,9.562 11.314,9.911C11.313,10.259 11.175,10.594 10.928,10.84C10.682,11.086 10.348,11.225 10,11.225L10,11.225Z"
android:fillColor="#000000"/>
<path
android:pathData="M17.471,7.507L18.225,6.666C18.421,6.447 18.485,6.141 18.393,5.863C18.302,5.584 18.069,5.376 17.782,5.316C17.495,5.256 17.198,5.354 17.003,5.572L16.274,6.381V6.381C15.722,5.933 15.124,5.544 14.49,5.222L14.982,4.311V4.311C15.087,4.059 15.06,3.771 14.909,3.543C14.759,3.315 14.505,3.177 14.231,3.175C13.958,3.173 13.702,3.307 13.548,3.533L12.967,4.605C12.268,4.393 11.548,4.258 10.82,4.204V3.169C10.82,2.876 10.664,2.605 10.41,2.459C10.156,2.312 9.844,2.312 9.59,2.459C9.336,2.605 9.18,2.876 9.18,3.169V4.202C8.452,4.256 7.732,4.391 7.033,4.603L6.452,3.533C6.313,3.275 6.046,3.112 5.754,3.103C5.461,3.095 5.186,3.244 5.032,3.493C4.878,3.743 4.87,4.055 5.009,4.313L5.501,5.224C4.867,5.546 4.269,5.935 3.717,6.383L2.988,5.574V5.574C2.793,5.356 2.496,5.258 2.209,5.318C1.922,5.378 1.689,5.586 1.598,5.865C1.506,6.143 1.57,6.449 1.765,6.667L2.529,7.507C1.959,8.123 1.469,8.808 1.071,9.546C0.957,9.776 0.957,10.046 1.071,10.275C1.182,10.496 3.83,15.649 10,15.649C16.17,15.649 18.823,10.496 18.929,10.275C19.043,10.046 19.043,9.776 18.929,9.546C18.531,8.808 18.041,8.123 17.471,7.507L17.471,7.507ZM10,14.009C5.683,14.009 3.416,10.988 2.746,9.911C3.418,8.847 5.712,5.809 10,5.809C11.033,5.802 12.059,5.988 13.025,6.356L13.098,6.385H13.098C14.068,6.775 14.957,7.341 15.72,8.056C15.745,8.085 15.771,8.116 15.8,8.144C15.829,8.171 15.84,8.173 15.858,8.187L15.858,8.187C16.391,8.704 16.86,9.282 17.254,9.911C16.582,10.974 14.288,14.009 10,14.009L10,14.009Z"
android:fillColor="#000000"/>
</vector>