@@ -8,11 +8,11 @@ import androidx.compose.foundation.layout.padding
88import androidx.compose.foundation.layout.size
99import androidx.compose.material3.Card
1010import androidx.compose.material3.CardDefaults
11+ import androidx.compose.material3.DropdownMenuItem
1112import androidx.compose.material3.Icon
1213import androidx.compose.material3.MaterialTheme
1314import androidx.compose.material3.Text
1415import androidx.compose.runtime.Composable
15- import androidx.compose.runtime.remember
1616import androidx.compose.ui.Alignment
1717import androidx.compose.ui.Modifier
1818import androidx.compose.ui.graphics.Color
@@ -30,17 +30,14 @@ import androidx.compose.ui.unit.dp
3030 * @param optionData The [OptionBarData] object containing the icon, label, and enabled state for
3131 * this item.
3232 * @param onClick A lambda function that will be invoked when this option item is clicked.
33- * It receives the [OptionBarData] of the clicked item as a parameter.
3433 */
3534@Composable
3635internal fun OptionBarItem (
3736 modifier : Modifier = Modifier ,
3837 optionData : OptionBarData ,
39- onClick : (option: OptionBarData ) -> Unit = {}
38+ onClick : () -> Unit = {}
4039) {
4140
42- val onOptionClick = remember(optionData) { { onClick(optionData) } }
43-
4441 val cardColors = CardDefaults .cardColors(
4542 containerColor = Color .Transparent ,
4643 contentColor = MaterialTheme .colorScheme.onSurface,
@@ -53,7 +50,7 @@ internal fun OptionBarItem(
5350 shape = MaterialTheme .shapes.extraSmall,
5451 enabled = optionData.enabled,
5552 colors = cardColors,
56- onClick = onOptionClick
53+ onClick = onClick
5754 ) {
5855
5956 Column (
@@ -79,4 +76,47 @@ internal fun OptionBarItem(
7976 )
8077 }
8178 }
79+ }
80+
81+ /* *
82+ * A composable function that displays a single option item within a dropdown menu.
83+ *
84+ * This item typically consists of an icon, a label, and an action to be performed on click.
85+ * It's designed to be used as part of an `OptionBar` or similar dropdown structure.
86+ *
87+ * @param modifier Optional [Modifier] to be applied to the `DropdownMenuItem`.
88+ * @param optionData The [OptionBarData] containing the information for this menu item,
89+ * such as its label, icon, and enabled state.
90+ * @param onClick A lambda function that will be invoked when this menu item is clicked.
91+ */
92+ @Composable
93+ internal fun OptionMenuItem (
94+ modifier : Modifier = Modifier ,
95+ optionData : OptionBarData ,
96+ onClick : () -> Unit = {}
97+ ) {
98+
99+ DropdownMenuItem (
100+ modifier = modifier,
101+ enabled = optionData.enabled,
102+ text = {
103+
104+ Text (
105+ text = optionData.label,
106+ textAlign = TextAlign .Start ,
107+ maxLines = 1 ,
108+ style = MaterialTheme .typography.bodyMedium,
109+ overflow = TextOverflow .Ellipsis
110+ )
111+ },
112+ leadingIcon = {
113+
114+ Icon (
115+ modifier = Modifier .size(size = 20 .dp),
116+ imageVector = optionData.icon,
117+ contentDescription = optionData.label
118+ )
119+ },
120+ onClick = onClick
121+ )
82122}
0 commit comments