Skip to content

Commit bc409b2

Browse files
committed
1 parent 69e1d7f commit bc409b2

File tree

1 file changed

+27
-22
lines changed
  • libraries/designsystem/src/main/kotlin/io/element/android/libraries/designsystem/theme/components

1 file changed

+27
-22
lines changed

libraries/designsystem/src/main/kotlin/io/element/android/libraries/designsystem/theme/components/SearchBar.kt

Lines changed: 27 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import androidx.compose.material3.ExperimentalMaterial3Api
1919
import androidx.compose.material3.SearchBar
2020
import androidx.compose.material3.SearchBarColors
2121
import androidx.compose.material3.SearchBarDefaults
22-
import androidx.compose.material3.TextFieldColors
2322
import androidx.compose.material3.TextFieldDefaults
2423
import androidx.compose.runtime.Composable
2524
import androidx.compose.runtime.Immutable
@@ -44,6 +43,9 @@ import io.element.android.libraries.designsystem.preview.ElementThemedPreview
4443
import io.element.android.libraries.designsystem.preview.PreviewGroup
4544
import io.element.android.libraries.ui.strings.CommonStrings
4645

46+
/**
47+
* Ref: https://www.figma.com/design/G1xy0HDZKJf5TCRFmKb5d5/Compound-Android-Components?node-id=1992-8350
48+
*/
4749
@OptIn(ExperimentalMaterial3Api::class)
4850
@Composable
4951
fun <T> SearchBar(
@@ -62,14 +64,12 @@ fun <T> SearchBar(
6264
interactionSource: MutableInteractionSource = remember { MutableInteractionSource() },
6365
inactiveBarColors: SearchBarColors = ElementSearchBarDefaults.inactiveColors(),
6466
activeBarColors: SearchBarColors = ElementSearchBarDefaults.activeColors(),
65-
inactiveTextInputColors: TextFieldColors = ElementSearchBarDefaults.inactiveInputFieldColors(),
66-
activeTextInputColors: TextFieldColors = ElementSearchBarDefaults.activeInputFieldColors(),
6767
contentPrefix: @Composable ColumnScope.() -> Unit = {},
6868
contentSuffix: @Composable ColumnScope.() -> Unit = {},
6969
resultHandler: @Composable ColumnScope.(T) -> Unit = {},
7070
) {
7171
val focusManager = LocalFocusManager.current
72-
72+
val colors = if (active) activeBarColors else inactiveBarColors
7373
val updatedOnQueryChange by rememberUpdatedState(onQueryChange)
7474
LaunchedEffect(active) {
7575
if (!active) {
@@ -106,28 +106,25 @@ fun <T> SearchBar(
106106
}
107107
}
108108
}
109-
110109
!active -> {
111110
{
112111
Icon(
113112
imageVector = CompoundIcons.Search(),
114113
contentDescription = stringResource(CommonStrings.action_search),
115-
tint = ElementTheme.colors.iconTertiary,
116114
)
117115
}
118116
}
119-
120117
else -> null
121118
},
122119
interactionSource = interactionSource,
123-
colors = if (active) activeTextInputColors else inactiveTextInputColors,
120+
colors = colors.inputFieldColors,
124121
)
125122
},
126123
expanded = active,
127124
onExpandedChange = onActiveChange,
128125
modifier = modifier.padding(horizontal = if (!active) 16.dp else 0.dp),
129126
shape = shape,
130-
colors = if (active) activeBarColors else inactiveBarColors,
127+
colors = colors,
131128
tonalElevation = tonalElevation,
132129
windowInsets = windowInsets,
133130
content = {
@@ -162,35 +159,43 @@ object ElementSearchBarDefaults {
162159
@OptIn(ExperimentalMaterial3Api::class)
163160
@Composable
164161
fun inactiveColors() = SearchBarDefaults.colors(
165-
containerColor = ElementTheme.materialColors.surfaceVariant,
166-
dividerColor = ElementTheme.materialColors.outline,
162+
containerColor = Color.Transparent,
163+
dividerColor = ElementTheme.colors.borderInteractivePrimary,
164+
inputFieldColors = inactiveInputFieldColors(),
167165
)
168166

169167
@Composable
170168
fun inactiveInputFieldColors() = TextFieldDefaults.colors(
171169
unfocusedPlaceholderColor = ElementTheme.colors.textDisabled,
172170
focusedPlaceholderColor = ElementTheme.colors.textDisabled,
173-
unfocusedLeadingIconColor = ElementTheme.materialColors.primary,
174-
focusedLeadingIconColor = ElementTheme.materialColors.primary,
175-
unfocusedTrailingIconColor = ElementTheme.materialColors.primary,
176-
focusedTrailingIconColor = ElementTheme.materialColors.primary,
171+
unfocusedTrailingIconColor = ElementTheme.colors.iconDisabled,
172+
focusedTrailingIconColor = ElementTheme.colors.iconDisabled,
173+
focusedContainerColor = Color.Transparent,
174+
unfocusedContainerColor = Color.Transparent,
175+
disabledContainerColor = Color.Transparent,
176+
errorContainerColor = Color.Transparent,
177177
)
178178

179179
@OptIn(ExperimentalMaterial3Api::class)
180180
@Composable
181181
fun activeColors() = SearchBarDefaults.colors(
182182
containerColor = Color.Transparent,
183-
dividerColor = ElementTheme.materialColors.outline,
183+
dividerColor = ElementTheme.colors.borderInteractivePrimary,
184+
inputFieldColors = activeInputFieldColors(),
184185
)
185186

186187
@Composable
187188
fun activeInputFieldColors() = TextFieldDefaults.colors(
188-
unfocusedPlaceholderColor = ElementTheme.colors.textDisabled,
189-
focusedPlaceholderColor = ElementTheme.colors.textDisabled,
190-
unfocusedLeadingIconColor = ElementTheme.materialColors.primary,
191-
focusedLeadingIconColor = ElementTheme.materialColors.primary,
192-
unfocusedTrailingIconColor = ElementTheme.materialColors.primary,
193-
focusedTrailingIconColor = ElementTheme.materialColors.primary,
189+
unfocusedPlaceholderColor = ElementTheme.colors.textSecondary,
190+
focusedPlaceholderColor = ElementTheme.colors.textSecondary,
191+
unfocusedLeadingIconColor = ElementTheme.colors.iconPrimary,
192+
focusedLeadingIconColor = ElementTheme.colors.iconPrimary,
193+
unfocusedTrailingIconColor = ElementTheme.colors.iconTertiary,
194+
focusedTrailingIconColor = ElementTheme.colors.iconTertiary,
195+
focusedContainerColor = Color.Transparent,
196+
unfocusedContainerColor = Color.Transparent,
197+
disabledContainerColor = Color.Transparent,
198+
errorContainerColor = Color.Transparent,
194199
)
195200
}
196201

0 commit comments

Comments
 (0)