|
|
@@ -0,0 +1,62 @@
|
|
|
+package io.legado.app.ui.widget.components
|
|
|
+
|
|
|
+import androidx.compose.foundation.layout.Row
|
|
|
+import androidx.compose.foundation.layout.fillMaxWidth
|
|
|
+import androidx.compose.foundation.layout.padding
|
|
|
+import androidx.compose.foundation.shape.RoundedCornerShape
|
|
|
+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.MaterialTheme
|
|
|
+import androidx.compose.material3.Surface
|
|
|
+import androidx.compose.material3.Text
|
|
|
+import androidx.compose.material3.TextField
|
|
|
+import androidx.compose.material3.TextFieldDefaults
|
|
|
+import androidx.compose.runtime.Composable
|
|
|
+import androidx.compose.ui.Alignment
|
|
|
+import androidx.compose.ui.Modifier
|
|
|
+import androidx.compose.ui.graphics.Color
|
|
|
+import androidx.compose.ui.unit.dp
|
|
|
+
|
|
|
+@OptIn(ExperimentalMaterial3Api::class)
|
|
|
+@Composable
|
|
|
+fun SearchBarSection(
|
|
|
+ query: String,
|
|
|
+ onQueryChange: (String) -> Unit
|
|
|
+) {
|
|
|
+ Surface(
|
|
|
+ modifier = Modifier
|
|
|
+ .fillMaxWidth()
|
|
|
+ .padding(horizontal = 16.dp, vertical = 8.dp),
|
|
|
+ shape = RoundedCornerShape(32.dp),
|
|
|
+ color = MaterialTheme.colorScheme.surfaceContainerLow
|
|
|
+ ) {
|
|
|
+
|
|
|
+ TextField(
|
|
|
+ value = query,
|
|
|
+ onValueChange = onQueryChange,
|
|
|
+ placeholder = { Text("搜索书名…") },
|
|
|
+ leadingIcon = { Icon(Icons.Default.Search, null) },
|
|
|
+ trailingIcon = {
|
|
|
+ Row(verticalAlignment = Alignment.CenterVertically) {
|
|
|
+ if (query.isNotEmpty()) {
|
|
|
+ IconButton(onClick = { onQueryChange("") }) {
|
|
|
+ Icon(Icons.Default.Clear, contentDescription = null)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ },
|
|
|
+ singleLine = true,
|
|
|
+ colors = TextFieldDefaults.colors(
|
|
|
+ focusedContainerColor = Color.Transparent,
|
|
|
+ unfocusedContainerColor = Color.Transparent,
|
|
|
+ disabledContainerColor = Color.Transparent,
|
|
|
+ focusedIndicatorColor = Color.Transparent,
|
|
|
+ unfocusedIndicatorColor = Color.Transparent,
|
|
|
+ )
|
|
|
+ )
|
|
|
+ }
|
|
|
+}
|