-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathPanelSearchBar.kt
More file actions
94 lines (91 loc) · 3.48 KB
/
Copy pathPanelSearchBar.kt
File metadata and controls
94 lines (91 loc) · 3.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
package com.redmadrobot.debug.uikit.components
import androidx.compose.animation.core.animateDpAsState
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.heightIn
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.text.BasicTextField
import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.SolidColor
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.unit.dp
import com.redmadrobot.debug.uikit.R
import com.redmadrobot.debug.uikit.theme.DebugPanelDimensions
import com.redmadrobot.debug.uikit.theme.DebugPanelShapes
import com.redmadrobot.debug.uikit.theme.DebugPanelTheme
import com.redmadrobot.debug.uikit.theme.MonoFontFamily
@Suppress("LongMethod")
@Composable
public fun PanelSearchBar(
query: String,
placeholder: String,
onQueryChange: (String) -> Unit,
modifier: Modifier = Modifier,
) {
val minHeight by animateDpAsState(
targetValue = if (query.isNotEmpty()) 48.dp else 40.dp,
label = "",
)
Row(
modifier = modifier
.fillMaxWidth()
.heightIn(min = minHeight)
.background(
color = DebugPanelTheme.colors.surface.secondary,
shape = DebugPanelShapes.medium,
)
.padding(horizontal = 12.dp, vertical = 8.dp),
verticalAlignment = Alignment.CenterVertically,
) {
Icon(
painter = painterResource(R.drawable.icon_search),
contentDescription = null,
tint = DebugPanelTheme.colors.content.tertiary,
modifier = Modifier.size(size = DebugPanelDimensions.iconSizeSmall),
)
BasicTextField(
value = query,
onValueChange = onQueryChange,
modifier = Modifier
.weight(weight = 1f)
.padding(horizontal = 8.dp),
textStyle = DebugPanelTheme.typography.bodyMedium.copy(
fontFamily = MonoFontFamily,
color = DebugPanelTheme.colors.content.primary,
),
singleLine = true,
cursorBrush = SolidColor(value = DebugPanelTheme.colors.content.accent),
decorationBox = { innerTextField ->
if (query.isEmpty()) {
Text(
text = placeholder,
style = DebugPanelTheme.typography.bodyMedium,
color = DebugPanelTheme.colors.content.tertiary,
)
}
innerTextField()
},
)
if (query.isNotEmpty()) {
IconButton(
onClick = { onQueryChange("") },
modifier = Modifier.size(size = DebugPanelDimensions.iconSizeLarge),
) {
Icon(
painter = painterResource(R.drawable.icon_clear),
contentDescription = null,
tint = DebugPanelTheme.colors.content.tertiary,
modifier = Modifier.size(size = DebugPanelDimensions.iconSizeSmall),
)
}
}
}
}