Skip to content

Commit

Permalink
Merge pull request #189 from tarkalabs/mahi/enhance/TUiTextRowMenuOpt…
Browse files Browse the repository at this point in the history
…ions

Drop Menu Options Implemented in TUITextRow.
  • Loading branch information
rajajawahar authored Feb 19, 2024
2 parents 0c17320 + f25b83f commit 86a2241
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 11 deletions.
2 changes: 1 addition & 1 deletion tarka-ui/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ publishing {
run {
groupId = "com.tarkalabs"
artifactId = getLibraryArtifactId()
version = "1.1.0"
version = "1.1.1"
artifact("$buildDir/outputs/aar/tarka-ui-release.aar")
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,26 @@
package com.tarkalabs.tarkaui.components

import android.util.Log
import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.defaultMinSize
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.layout.wrapContentSize
import androidx.compose.material3.DropdownMenu
import androidx.compose.material3.Icon
import androidx.compose.material3.OutlinedButton
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.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.testTag
Expand Down Expand Up @@ -77,9 +85,14 @@ import com.tarkalabs.tarkaui.theme.TUITheme
onButtonClick: () -> Unit = {},
onInfoIconClick: (() -> Unit)? = {},
onTextRowClick: (() -> Unit)? = null,
menuItemList: List<TUIPopUpMenuItem>? = null,
onMenuItemClick: ((Int) -> Unit)? = null,
paddingValues: PaddingValues = PaddingValues(),
tags: TUITextRowTags = TUITextRowTags()
) {

var expanded by remember { mutableStateOf(false) }

Row(
modifier
.defaultMinSize(minHeight = 40.dp)
Expand Down Expand Up @@ -125,16 +138,45 @@ import com.tarkalabs.tarkaui.theme.TUITheme
}
}
if (infoIcon != null) {
Icon(
painter = painterResource(id = infoIcon.iconRes),
contentDescription = infoIcon.contentDescription,
tint = TUITheme.colors.utilityOutline,
modifier = Modifier
.then(if(onInfoIconClick == null) Modifier else Modifier.clickable(onClick = onInfoIconClick))
.height(40.dp)
.width(24.dp)
.testTag(tags.infoIconTag)
)
Box(modifier = Modifier.wrapContentSize(Alignment.BottomEnd)) {
Icon(
painter = painterResource(id = infoIcon.iconRes),
contentDescription = infoIcon.contentDescription,
tint = TUITheme.colors.utilityOutline,
modifier = Modifier
.then(if (onInfoIconClick == null) Modifier else Modifier.clickable(onClick = {
if (menuItemList.isNullOrEmpty()) {
onInfoIconClick()
} else {
expanded = expanded.not()
}
}))
.height(40.dp)
.width(24.dp)
.testTag(tags.infoIconTag)
)
DropdownMenu(
expanded = expanded,
onDismissRequest = { expanded = false },
modifier = Modifier
.background(TUITheme.colors.surface)
.align(Alignment.TopEnd),
) {
menuItemList?.forEachIndexed { index, item ->
TUIMobileOverlayMenuItem(
title = item.title,
isSelected = false,
style = MobileOverlayMenuItemStyle.Title,
onMobileOverlayMenuItemClick = {
expanded = false
onMenuItemClick?.invoke(index)
},
modifier = Modifier.width(160.dp),
leadingContent = MobileOverlayMenuItemLeadingContentType.Icon(item.icon)
)
}
}
}
}
}
}
Expand Down Expand Up @@ -168,6 +210,11 @@ sealed class TextRowStyle {
object Title : TextRowStyle()
}

data class TUIPopUpMenuItem(
val title: String,
val icon: TarkaIcon,
)

data class TUITextRowTags(
val parentTag: String = "TUITextRow",
val iconOneTags: TUIIconButtonTags = TUIIconButtonTags(parentTag = "TUITextRow_IconOne"),
Expand Down

0 comments on commit 86a2241

Please sign in to comment.