in ui-components/src/commonMain/kotlin/org/jetbrains/kotlinconf/ui/components/MainHeader.kt [47:124]
fun MainHeaderSearchBar(
searchValue: String,
onSearchValueChange: (String) -> Unit,
onClear: () -> Unit,
onClose: () -> Unit,
modifier: Modifier = Modifier,
hasAdditionalInputs: Boolean = false,
) {
Row(
modifier = modifier
.height(48.dp)
.fillMaxWidth()
.background(KotlinConfTheme.colors.mainBackground),
verticalAlignment = Alignment.CenterVertically,
) {
TopMenuButton(
icon = UiRes.drawable.arrow_left_24,
onClick = {
onClose()
onSearchValueChange("")
},
contentDescription = stringResource(UiRes.string.main_header_back),
)
var focusRequested by rememberSaveable { mutableStateOf(false) }
val focusRequester = remember { FocusRequester() }
if (!focusRequested) {
LaunchedEffect(Unit) {
focusRequester.requestFocus()
focusRequested = true
}
}
Box(
modifier = Modifier.weight(1f).fillMaxHeight(),
contentAlignment = Alignment.CenterStart,
) {
BasicTextField(
value = searchValue,
onValueChange = { onSearchValueChange(it) },
modifier = Modifier
.fillMaxWidth()
.focusRequester(focusRequester),
singleLine = true,
textStyle = KotlinConfTheme.typography.text1
.copy(color = KotlinConfTheme.colors.primaryText),
cursorBrush = SolidColor(KotlinConfTheme.colors.primaryText),
)
androidx.compose.animation.AnimatedVisibility(
searchValue.isEmpty(),
enter = fadeIn(tween(10)),
exit = fadeOut(tween(10)),
) {
Text(
text = stringResource(UiRes.string.main_header_search_hint),
style = KotlinConfTheme.typography.text1,
color = KotlinConfTheme.colors.placeholderText
)
}
}
AnimatedVisibility(
visible = searchValue.isNotEmpty() || hasAdditionalInputs,
enter = fadeIn(tween(200)),
exit = fadeOut(tween(100)),
) {
TopMenuButton(
icon = UiRes.drawable.close_24,
onClick = {
onSearchValueChange("")
onClear()
focusRequester.requestFocus()
},
contentDescription = stringResource(UiRes.string.main_header_search_clear),
)
}
}
}