@@ -24,6 +24,7 @@ import androidx.compose.runtime.getValue
2424import androidx.compose.runtime.remember
2525import androidx.compose.ui.Alignment
2626import androidx.compose.ui.Modifier
27+ import androidx.compose.ui.graphics.Brush
2728import androidx.compose.ui.graphics.Color
2829import androidx.compose.ui.graphics.SolidColor
2930import androidx.compose.ui.text.TextLayoutResult
@@ -51,6 +52,7 @@ import top.yukonga.miuix.kmp.utils.SmoothRoundedCornerShape
5152 * @param cornerRadius The corner radius of the [TextField].
5253 * @param label The label to be displayed when the [TextField] is empty.
5354 * @param labelColor The color of the label.
55+ * @param borderColor The color of the border when the [TextField] is focused.
5456 * @param useLabelAsPlaceholder Whether to use the label as a placeholder.
5557 * @param enabled Whether the [TextField] is enabled.
5658 * @param readOnly Whether the [TextField] is read-only.
@@ -66,6 +68,7 @@ import top.yukonga.miuix.kmp.utils.SmoothRoundedCornerShape
6668 * @param visualTransformation The visual transformation to be applied to the [TextField].
6769 * @param onTextLayout The callback to be called when the text layout changes.
6870 * @param interactionSource The interaction source to be applied to the [TextField].
71+ * @param cursorBrush The brush to be used for the cursor.
6972 */
7073@Composable
7174fun TextField (
@@ -74,9 +77,10 @@ fun TextField(
7477 modifier : Modifier = Modifier ,
7578 insideMargin : DpSize = DpSize (16.dp, 16.dp),
7679 backgroundColor : Color = MiuixTheme .colorScheme.secondaryContainer,
77- cornerRadius : Dp = 18 .dp,
80+ cornerRadius : Dp = 16 .dp,
7881 label : String = "",
7982 labelColor : Color = MiuixTheme .colorScheme.onSecondaryContainer,
83+ borderColor : Color = MiuixTheme .colorScheme.primary,
8084 useLabelAsPlaceholder : Boolean = false,
8185 enabled : Boolean = true,
8286 readOnly : Boolean = false,
@@ -90,7 +94,8 @@ fun TextField(
9094 minLines : Int = 1,
9195 visualTransformation : VisualTransformation = VisualTransformation .None ,
9296 onTextLayout : (TextLayoutResult ) -> Unit = {},
93- interactionSource : MutableInteractionSource ? = null
97+ interactionSource : MutableInteractionSource ? = null,
98+ cursorBrush : Brush = SolidColor (MiuixTheme .colorScheme.primary)
9499) {
95100 @Suppress(" NAME_SHADOWING" )
96101 val interactionSource = interactionSource ? : remember { MutableInteractionSource () }
@@ -102,7 +107,7 @@ fun TextField(
102107 }
103108 val isFocused by interactionSource.collectIsFocusedAsState()
104109 val borderWidth by animateDpAsState(if (isFocused) 2 .dp else 0 .dp)
105- val borderColor by animateColorAsState(if (isFocused) MiuixTheme .colorScheme.primary else backgroundColor)
110+ val borderColor by animateColorAsState(if (isFocused) borderColor else backgroundColor)
106111 val labelOffsetY by animateDpAsState(if (value.text.isNotEmpty() && ! useLabelAsPlaceholder) - (insideMargin.height / 2 ) else 0 .dp)
107112 val innerTextOffsetY by animateDpAsState(if (value.text.isNotEmpty() && ! useLabelAsPlaceholder) (insideMargin.height / 2 ) else 0 .dp)
108113 val labelFontSize by animateDpAsState(if (value.text.isNotEmpty() && ! useLabelAsPlaceholder) 10 .dp else 17 .dp)
@@ -125,7 +130,7 @@ fun TextField(
125130 visualTransformation = visualTransformation,
126131 onTextLayout = onTextLayout,
127132 interactionSource = interactionSource,
128- cursorBrush = SolidColor ( MiuixTheme .colorScheme.primary) ,
133+ cursorBrush = cursorBrush ,
129134 decorationBox =
130135 @Composable { innerTextField ->
131136 val shape = remember { derivedStateOf { SmoothRoundedCornerShape (cornerRadius) } }
@@ -196,6 +201,7 @@ fun TextField(
196201 * @param cornerRadius The corner radius of the [TextField].
197202 * @param label The label to be displayed when the [TextField] is empty.
198203 * @param labelColor The color of the label.
204+ * @param borderColor The color of the border when the [TextField] is focused.
199205 * @param useLabelAsPlaceholder Whether to use the label as a placeholder.
200206 * @param enabled Whether the [TextField] is enabled.
201207 * @param readOnly Whether the [TextField] is read-only.
@@ -211,6 +217,7 @@ fun TextField(
211217 * @param visualTransformation The visual transformation to be applied to the [TextField].
212218 * @param onTextLayout The callback to be called when the text layout changes.
213219 * @param interactionSource The interaction source to be applied to the [TextField].
220+ * @param cursorBrush The brush to be used for the cursor.
214221 */
215222@Composable
216223fun TextField (
@@ -222,6 +229,7 @@ fun TextField(
222229 cornerRadius : Dp = 16.dp,
223230 label : String = "",
224231 labelColor : Color = MiuixTheme .colorScheme.onSecondaryContainer,
232+ borderColor : Color = MiuixTheme .colorScheme.primary,
225233 useLabelAsPlaceholder : Boolean = false,
226234 enabled : Boolean = true,
227235 readOnly : Boolean = false,
@@ -235,7 +243,8 @@ fun TextField(
235243 minLines : Int = 1,
236244 visualTransformation : VisualTransformation = VisualTransformation .None ,
237245 onTextLayout : (TextLayoutResult ) -> Unit = {},
238- interactionSource : MutableInteractionSource ? = null
246+ interactionSource : MutableInteractionSource ? = null,
247+ cursorBrush : Brush = SolidColor (MiuixTheme .colorScheme.primary)
239248) {
240249 @Suppress(" NAME_SHADOWING" )
241250 val interactionSource = interactionSource ? : remember { MutableInteractionSource () }
@@ -247,7 +256,7 @@ fun TextField(
247256 }
248257 val isFocused by interactionSource.collectIsFocusedAsState()
249258 val borderWidth by animateDpAsState(if (isFocused) 2.0 .dp else 0 .dp)
250- val borderColor by animateColorAsState(if (isFocused) MiuixTheme .colorScheme.primary else backgroundColor)
259+ val borderColor by animateColorAsState(if (isFocused) borderColor else backgroundColor)
251260 val labelOffsetY by animateDpAsState(if (value.isNotEmpty() && ! useLabelAsPlaceholder) - (insideMargin.height / 2 ) else 0 .dp)
252261 val innerTextOffsetY by animateDpAsState(if (value.isNotEmpty() && ! useLabelAsPlaceholder) (insideMargin.height / 2 ) else 0 .dp)
253262 val labelFontSize by animateDpAsState(if (value.isNotEmpty() && ! useLabelAsPlaceholder) 10 .dp else 17 .dp)
@@ -270,7 +279,7 @@ fun TextField(
270279 visualTransformation = visualTransformation,
271280 onTextLayout = onTextLayout,
272281 interactionSource = interactionSource,
273- cursorBrush = SolidColor ( MiuixTheme .colorScheme.primary) ,
282+ cursorBrush = cursorBrush ,
274283 decorationBox =
275284 @Composable { innerTextField ->
276285 Box (
0 commit comments