-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add category dropdown component
This commit introduces a new CategoryDropDown component that allows users to select a job category from a dropdown list. - The component displays an outlined text field with a dropdown icon. - When clicked, it expands to show a list of available categories. - Selecting a category triggers an event to update the selected category state.
- Loading branch information
1 parent
5399c77
commit fae89f5
Showing
1 changed file
with
63 additions
and
0 deletions.
There are no files selected for viewing
63 changes: 63 additions & 0 deletions
63
...n/java/com/samuelokello/kazihub/presentation/business/home/components/CategoryDropDown.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package com.samuelokello.kazihub.presentation.business.home.components | ||
|
||
import androidx.compose.foundation.layout.fillMaxWidth | ||
import androidx.compose.foundation.shape.RoundedCornerShape | ||
import androidx.compose.material3.DropdownMenuItem | ||
import androidx.compose.material3.ExperimentalMaterial3Api | ||
import androidx.compose.material3.ExposedDropdownMenuBox | ||
import androidx.compose.material3.ExposedDropdownMenuDefaults | ||
import androidx.compose.material3.OutlinedTextField | ||
import androidx.compose.material3.Text | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.getValue | ||
import androidx.compose.runtime.mutableStateOf | ||
import androidx.compose.runtime.remember | ||
import androidx.compose.runtime.setValue | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.unit.dp | ||
import com.samuelokello.kazihub.domain.model.job.category.Category | ||
import com.samuelokello.kazihub.presentation.business.job.event.CreateJobUiEvent | ||
|
||
@OptIn(ExperimentalMaterial3Api::class) | ||
@Composable | ||
fun CategoryDropDown( | ||
categories: List<Category>, | ||
selectedCategory: Category?, | ||
onCreateJobUiEvent: (CreateJobUiEvent) -> Unit, | ||
) { | ||
var expanded by remember { mutableStateOf(false) } | ||
ExposedDropdownMenuBox( | ||
expanded = expanded, | ||
onExpandedChange = { expanded = !expanded }, | ||
) { | ||
OutlinedTextField( | ||
value = selectedCategory?.name?:"Select Category", | ||
onValueChange = { }, | ||
readOnly = true, | ||
trailingIcon = { ExposedDropdownMenuDefaults.TrailingIcon(expanded = expanded) }, | ||
colors = ExposedDropdownMenuDefaults.outlinedTextFieldColors(), | ||
shape = RoundedCornerShape(10.dp), | ||
modifier = Modifier | ||
.menuAnchor() | ||
.fillMaxWidth(), | ||
) | ||
|
||
ExposedDropdownMenu( | ||
expanded = expanded, | ||
onDismissRequest = { expanded = false }, | ||
modifier = Modifier.exposedDropdownSize(), | ||
) { | ||
categories.forEach { category -> | ||
DropdownMenuItem( | ||
onClick = { | ||
onCreateJobUiEvent(CreateJobUiEvent.OnCategoryChange(category)) | ||
expanded = false | ||
}, | ||
text = { | ||
Text(text = category.name) | ||
}, | ||
) | ||
} | ||
} | ||
} | ||
} |