51 lines
1.8 KiB
Kotlin
51 lines
1.8 KiB
Kotlin
|
|
package com.taskttl.ui.components
|
||
|
|
|
||
|
|
import androidx.compose.material.icons.Icons
|
||
|
|
import androidx.compose.material.icons.filled.Clear
|
||
|
|
import androidx.compose.material.icons.filled.Search
|
||
|
|
import androidx.compose.material3.ExperimentalMaterial3Api
|
||
|
|
import androidx.compose.material3.Icon
|
||
|
|
import androidx.compose.material3.IconButton
|
||
|
|
import androidx.compose.material3.OutlinedTextField
|
||
|
|
import androidx.compose.material3.Text
|
||
|
|
import androidx.compose.runtime.Composable
|
||
|
|
import androidx.compose.ui.Modifier
|
||
|
|
import org.jetbrains.compose.resources.StringResource
|
||
|
|
import org.jetbrains.compose.resources.stringResource
|
||
|
|
import taskttl.composeapp.generated.resources.Res
|
||
|
|
import taskttl.composeapp.generated.resources.clear_text
|
||
|
|
import taskttl.composeapp.generated.resources.search
|
||
|
|
import taskttl.composeapp.generated.resources.search_placeholder
|
||
|
|
|
||
|
|
@OptIn(ExperimentalMaterial3Api::class)
|
||
|
|
@Composable
|
||
|
|
fun SearchBar(
|
||
|
|
query: String,
|
||
|
|
onQueryChange: (String) -> Unit,
|
||
|
|
modifier: Modifier = Modifier,
|
||
|
|
placeholder: StringResource = Res.string.search_placeholder
|
||
|
|
) {
|
||
|
|
OutlinedTextField(
|
||
|
|
value = query,
|
||
|
|
onValueChange = onQueryChange,
|
||
|
|
modifier = modifier,
|
||
|
|
placeholder = { Text(stringResource(placeholder)) },
|
||
|
|
leadingIcon = {
|
||
|
|
Icon(
|
||
|
|
imageVector = Icons.Default.Search,
|
||
|
|
contentDescription = stringResource(Res.string.search)
|
||
|
|
)
|
||
|
|
},
|
||
|
|
trailingIcon = {
|
||
|
|
if (query.isNotEmpty()) {
|
||
|
|
IconButton(onClick = { onQueryChange("") }) {
|
||
|
|
Icon(
|
||
|
|
imageVector = Icons.Default.Clear,
|
||
|
|
contentDescription = stringResource(Res.string.clear_text)
|
||
|
|
)
|
||
|
|
}
|
||
|
|
}
|
||
|
|
},
|
||
|
|
singleLine = true
|
||
|
|
)
|
||
|
|
}
|