diff --git a/src/main/kotlin/main/Home.kt b/src/main/kotlin/main/Home.kt index b0af6ba..e4e95b8 100644 --- a/src/main/kotlin/main/Home.kt +++ b/src/main/kotlin/main/Home.kt @@ -125,6 +125,26 @@ fun homePage( } } } + + // Example usage with text options + dropdownButtonComponent( + items = listOf("Glossaire", "Code à vérifier", "Comparer") + ) { selectedOption -> + // Handle the selected option + when (selectedOption) { + "Glossaire" -> onProjectClick() + "Code à vérifier" -> onCodeToVerifyClick() + "Comparer" -> { + if (mostUsedWordList.isEmpty()) { + noFileSnackbarVisibleState.value = true + println("Veuillez d'abord importer un fichier") + return@dropdownButtonComponent + } else { + isCompareClicked = true + } + } + } + } } var selectedProject by remember { mutableStateOf(null) } diff --git a/src/main/kotlin/main/MenuButton.kt b/src/main/kotlin/main/MenuButton.kt new file mode 100644 index 0000000..55f7c01 --- /dev/null +++ b/src/main/kotlin/main/MenuButton.kt @@ -0,0 +1,56 @@ +package main + +import androidx.compose.foundation.layout.* +import androidx.compose.material.* +import androidx.compose.material.icons.Icons +import androidx.compose.material.icons.filled.Menu +import androidx.compose.runtime.* +import androidx.compose.ui.Modifier +import androidx.compose.ui.graphics.Color +import androidx.compose.ui.unit.dp + +@Composable +fun dropdownButtonComponent( + modifier: Modifier = Modifier, + items: List, + onItemSelected: (String) -> Unit +) { + var expanded by remember { mutableStateOf(false) } + var selectedIndex by remember { mutableStateOf(0) } + + Box(modifier = modifier) { + Button( + onClick = { expanded = true }, + modifier = Modifier + .padding(16.dp), + contentPadding = PaddingValues(8.dp), + colors = ButtonDefaults.buttonColors( + backgroundColor = customRedColor + ) + ) { + Icon( + imageVector = Icons.Default.Menu, // Use Menu icon for hamburger + contentDescription = "Menu", + tint = Color.White + ) + Spacer(modifier = Modifier.width(8.dp)) + Text(text = "Menu", color = Color.White) + Spacer(modifier = Modifier.width(8.dp)) + } + DropdownMenu( + modifier = Modifier.width(200.dp), + expanded = expanded, + onDismissRequest = { expanded = false } + ) { + items.forEachIndexed { index, s -> + DropdownMenuItem(onClick = { + selectedIndex = index + expanded = false + onItemSelected(s) + }) { + Text(text = s) + } + } + } + } +}