From e2d926e4f81d86faf6c326130c3b7629823347d0 Mon Sep 17 00:00:00 2001 From: priyacs651 Date: Tue, 21 May 2024 21:51:11 +0530 Subject: [PATCH] "Implemented utilityDisabledContent in TUIDateStyle " --- example/build.gradle.kts | 2 +- tarka-ui/build.gradle.kts | 3 +- .../tarkaui/components/TUITextRow.kt | 469 +++++++++--------- 3 files changed, 251 insertions(+), 223 deletions(-) diff --git a/example/build.gradle.kts b/example/build.gradle.kts index ca7c4cd7..bb44bae3 100644 --- a/example/build.gradle.kts +++ b/example/build.gradle.kts @@ -49,7 +49,7 @@ android { dependencies { val composeUiVersion = "1.4.1" - implementation("com.tarkalabs:tarkaui:1.1.24") + implementation("com.tarkalabs:tarkaui:1.1.28") implementation("com.tarkalabs:tarkaui-icons:1.0.5") implementation("com.microsoft.design:fluent-system-icons:1.1.239@aar") implementation("androidx.core:core-ktx:1.10.0") diff --git a/tarka-ui/build.gradle.kts b/tarka-ui/build.gradle.kts index d10dadaf..beda6a31 100644 --- a/tarka-ui/build.gradle.kts +++ b/tarka-ui/build.gradle.kts @@ -65,7 +65,7 @@ publishing { run { groupId = "com.tarkalabs" artifactId = getLibraryArtifactId() - version = "1.1.26" + version = "1.1.28" artifact("$buildDir/outputs/aar/tarka-ui-release.aar") } } @@ -97,6 +97,7 @@ dependencies { androidTestImplementation("androidx.test.ext:junit:1.1.5") androidTestImplementation("androidx.test.espresso:espresso-core:3.5.1") androidTestImplementation("org.mockito.kotlin:mockito-kotlin:4.0.0") + api("com.microsoft.design:fluent-system-icons:1.1.239@aar") androidTestImplementation("androidx.compose.ui:ui-test-junit4:1.4.3") androidTestImplementation("org.mockito:mockito-android:4.5.1") diff --git a/tarka-ui/src/main/java/com/tarkalabs/tarkaui/components/TUITextRow.kt b/tarka-ui/src/main/java/com/tarkalabs/tarkaui/components/TUITextRow.kt index a3d9e6c6..c5ce533d 100644 --- a/tarka-ui/src/main/java/com/tarkalabs/tarkaui/components/TUITextRow.kt +++ b/tarka-ui/src/main/java/com/tarkalabs/tarkaui/components/TUITextRow.kt @@ -32,6 +32,7 @@ import androidx.compose.ui.res.painterResource import androidx.compose.ui.res.stringResource import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.unit.dp +import com.tarkalabs.tarkaui.R import com.tarkalabs.tarkaui.components.TextRowStyle.DateStyle import com.tarkalabs.tarkaui.components.TextRowStyle.Title import com.tarkalabs.tarkaui.components.TextRowStyle.TitleWithDescription @@ -80,266 +81,292 @@ import com.tarkalabs.tarkaui.theme.TUITheme * */ -@Composable fun TUITextRow( - modifier: Modifier = Modifier, - title: String, - style: TextRowStyle = Title, - iconOne: TarkaIcon? = null, - iconTwo: TarkaIcon? = null, - buttonTitle: String? = null, - infoIcon: TarkaIcon? = null, - onIconOneClick: () -> Unit = {}, - onIconTwoClick: () -> Unit = {}, - onButtonClick: () -> Unit = {}, - onInfoIconClick: (() -> Unit)? = {}, - onTextRowClick: (() -> Unit)? = null, - menuItemList: List? = null, - onMenuItemClick: ((TUIPopUpMenu) -> Unit)? = null, - paddingValues: PaddingValues = PaddingValues(), - tags: TUITextRowTags = TUITextRowTags(), +@Composable +fun TUITextRow( + modifier: Modifier = Modifier, + title: String, + style: TextRowStyle = Title, + iconOne: TarkaIcon? = null, + iconTwo: TarkaIcon? = null, + buttonTitle: String? = null, + infoIcon: TarkaIcon? = null, + onIconOneClick: () -> Unit = {}, + onIconTwoClick: () -> Unit = {}, + onButtonClick: () -> Unit = {}, + onInfoIconClick: (() -> Unit)? = {}, + onTextRowClick: (() -> Unit)? = null, + menuItemList: List? = null, + onMenuItemClick: ((TUIPopUpMenu) -> Unit)? = null, + paddingValues: PaddingValues = PaddingValues(), + tags: TUITextRowTags = TUITextRowTags(), ) { - var expanded by remember { mutableStateOf(false) } - - Row( - modifier - .defaultMinSize(minHeight = 40.dp) - .testTag(tags.parentTag) - .then(if (onTextRowClick == null) Modifier else Modifier.clickable { onTextRowClick() }) - .padding(paddingValues), - verticalAlignment = Alignment.CenterVertically - ) { - Column(Modifier.weight(1f)) { - when (style) { - is TitleWithDescription -> { - TUITextRowTitleWithDescription(title, style) - } + var expanded by remember { mutableStateOf(false) } - is Title -> { - TUITextRowTitle(title) - } + Row( + modifier + .defaultMinSize(minHeight = 40.dp) + .testTag(tags.parentTag) + .then(if (onTextRowClick == null) Modifier else Modifier.clickable { onTextRowClick() }) + .padding(paddingValues), + verticalAlignment = Alignment.CenterVertically + ) { + Column(Modifier.weight(1f)) { + when (style) { + is TitleWithDescription -> { + TUITextRowTitleWithDescription(title, style) + } - is DateStyle -> { - TUIDateStyle(title, style) - } + is Title -> { + TUITextRowTitle(title) + } - is TitleWithNotAvailable -> { - TUITextRowTitleWithNotAvailable(title, style) - } - } + is DateStyle -> { + TUIDateStyle(title, style) + } - } - Row(verticalAlignment = Alignment.CenterVertically) { - if (iconOne != null) TUIIconButton( - icon = iconOne, - onIconClick = onIconOneClick, - iconButtonStyle = Ghost, - tags = tags.iconOneTags - ) - if (iconTwo != null) TUIIconButton( - icon = iconTwo, - onIconClick = onIconTwoClick, - iconButtonStyle = Ghost, - tags = tags.iconTwoTags + is TitleWithNotAvailable -> { + TUITextRowTitleWithNotAvailable(title, style) + } + } - ) - if (buttonTitle != null) { - OutlinedButton( - modifier = Modifier - .height(40.dp) - .width(90.dp) - .testTag(tags.buttonTag), - onClick = onButtonClick - ) { - Text(text = buttonTitle) } - } - if (infoIcon != null) { - 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 && menuItemList.isNullOrEmpty()) Modifier else Modifier.clickable( - onClick = { - if (!menuItemList.isNullOrEmpty()) { - expanded = !expanded - } else { - onInfoIconClick?.invoke() + Row(verticalAlignment = Alignment.CenterVertically) { + if (iconOne != null) TUIIconButton( + icon = iconOne, + onIconClick = onIconOneClick, + iconButtonStyle = Ghost, + tags = tags.iconOneTags + ) + if (iconTwo != null) TUIIconButton( + icon = iconTwo, + onIconClick = onIconTwoClick, + iconButtonStyle = Ghost, + tags = tags.iconTwoTags + + ) + if (buttonTitle != null) { + OutlinedButton( + modifier = Modifier + .height(40.dp) + .width(90.dp) + .testTag(tags.buttonTag), + onClick = onButtonClick + ) { + Text(text = buttonTitle) + } + } + if (infoIcon != null) { + 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 && menuItemList.isNullOrEmpty()) Modifier else Modifier.clickable( + onClick = { + if (!menuItemList.isNullOrEmpty()) { + expanded = !expanded + } else { + onInfoIconClick?.invoke() + } + }) + ) + .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?.forEach { item -> + TUIMobileOverlayMenuItem( + title = stringResource(id = item.title), + isSelected = false, + style = MobileOverlayMenuItemStyle.Title, + onMobileOverlayMenuItemClick = { + expanded = false + onMenuItemClick?.invoke(item) + }, + modifier = Modifier.defaultMinSize(minWidth = 160.dp), + leadingContent = MobileOverlayMenuItemLeadingContentType.Icon(item.icon) + ) + } } - }) - ) - .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?.forEach { item -> - TUIMobileOverlayMenuItem( - title = stringResource(id = item.title), - isSelected = false, - style = MobileOverlayMenuItemStyle.Title, - onMobileOverlayMenuItemClick = { - expanded = false - onMenuItemClick?.invoke(item) - }, - modifier = Modifier.defaultMinSize(minWidth = 160.dp), - leadingContent = MobileOverlayMenuItemLeadingContentType.Icon(item.icon) - ) + } } - } } - } } - } } -@Composable fun TUIDateStyle( - title: String, - style: DateStyle, +@Composable +fun TUIDateStyle( + title: String, + style: DateStyle, ) { - Text( - text = title, - style = TUITheme.typography.body8, - color = TUITheme.colors.inputTextDim - ) - VerticalSpacer(space = 4) - Box(modifier = Modifier) { - val color = TUITheme.colors.utilityOutline - val pathEffect = PathEffect.dashPathEffect(floatArrayOf(4f, 4f), 0f) - Canvas( - Modifier - .width(0.dp) - .height(5.dp) - .align(Alignment.CenterStart) - ) { - drawLine( - color = color, - start = Offset(16f, -2f), - end = Offset(16f, 20f), - pathEffect = pathEffect - ) - } - Column(modifier = Modifier) { - Row { - Icon( - painter = painterResource(id = TarkaIcons.Regular.Circle24.iconRes), - contentDescription = TarkaIcons.Regular.Circle24.contentDescription, - modifier = Modifier - .height(18.dp) - .width(12.dp) - .align(Alignment.CenterVertically), - tint = TUITheme.colors.utilityOutline - ) - Text( - text = style.startDate, - style = TUITheme.typography.body7, - color = TUITheme.colors.onSurface, - modifier = Modifier.padding(start = 4.dp) - ) + Text( + text = title, + style = TUITheme.typography.body8, + color = TUITheme.colors.inputTextDim + ) + VerticalSpacer(space = 4) + Box(modifier = Modifier) { + val color = TUITheme.colors.utilityOutline + val pathEffect = PathEffect.dashPathEffect(floatArrayOf(4f, 4f), 0f) + Canvas( + Modifier + .width(0.dp) + .height(5.dp) + .align(Alignment.CenterStart) + ) { + drawLine( + color = color, + start = Offset(16f, -2f), + end = Offset(16f, 20f), + pathEffect = pathEffect + ) + } + Column(modifier = Modifier) { + Row { + Icon( + painter = painterResource(id = TarkaIcons.Regular.Circle24.iconRes), + contentDescription = TarkaIcons.Regular.Circle24.contentDescription, + modifier = Modifier + .height(18.dp) + .width(12.dp) + .align(Alignment.CenterVertically), + tint = TUITheme.colors.utilityOutline + ) + if (style.startDate.isEmpty()) { + Text( + text = stringResource(id = style.primaryNotAvailableText), + style = TUITheme.typography.body7, + color = TUITheme.colors.utilityDisabledContent, + modifier = Modifier.padding(start = 4.dp) + ) + } else { + Text( + text = style.startDate, + style = TUITheme.typography.body7, + color = TUITheme.colors.onSurface, + modifier = Modifier.padding(start = 4.dp) + ) + } - } - Row { - Icon( - painter = painterResource(id = TarkaIcons.Regular.Circle24.iconRes), - contentDescription = TarkaIcons.Regular.Circle24.contentDescription, - modifier = Modifier - .height(18.dp) - .width(12.dp) - .align(Alignment.CenterVertically), - tint = TUITheme.colors.utilityOutline - ) - Text( - text = style.endDate, - style = TUITheme.typography.body7, - color = TUITheme.colors.onSurface, - modifier = Modifier.padding(start = 4.dp) - ) - } - } + } + Row { + Icon( + painter = painterResource(id = TarkaIcons.Regular.Circle24.iconRes), + contentDescription = TarkaIcons.Regular.Circle24.contentDescription, + modifier = Modifier + .height(18.dp) + .width(12.dp) + .align(Alignment.CenterVertically), + tint = TUITheme.colors.utilityOutline + ) + if (style.endDate.isEmpty()) { + Text( + text = stringResource(id = style.primaryNotAvailableText), + style = TUITheme.typography.body7, + color = TUITheme.colors.utilityDisabledContent, + modifier = Modifier.padding(start = 4.dp) + ) + } else { + Text( + text = style.endDate, + style = TUITheme.typography.body7, + color = TUITheme.colors.onSurface, + modifier = Modifier.padding(start = 4.dp) + ) + } + } + } - } + } } @Composable private fun TUITextRowTitle(title: String) { - Text( - text = title, - style = TUITheme.typography.heading7, - color = TUITheme.colors.onSurface - ) + Text( + text = title, + style = TUITheme.typography.heading7, + color = TUITheme.colors.onSurface + ) } -@Composable private fun TUITextRowTitleWithDescription(title: String, style: TitleWithDescription) { - Text( - text = title, - style = TUITheme.typography.body8, - color = TUITheme.colors.onSurface.copy(alpha = 0.7f) - ) - VerticalSpacer(space = 4) - Text( - text = style.description, style = TUITheme.typography.body7, color = TUITheme.colors.onSurface - ) +@Composable +private fun TUITextRowTitleWithDescription(title: String, style: TitleWithDescription) { + Text( + text = title, + style = TUITheme.typography.body8, + color = TUITheme.colors.onSurface.copy(alpha = 0.7f) + ) + VerticalSpacer(space = 4) + Text( + text = style.description, + style = TUITheme.typography.body7, + color = TUITheme.colors.onSurface + ) } -@Composable private fun TUITextRowTitleWithNotAvailable( - title: String, style: TitleWithNotAvailable +@Composable +private fun TUITextRowTitleWithNotAvailable( + title: String, style: TitleWithNotAvailable ) { - Text( - text = title, - style = TUITheme.typography.body8, - color = TUITheme.colors.onSurface.copy(alpha = 0.7f) - ) - VerticalSpacer(space = 4) - Text( - text = style.text, - style = TUITheme.typography.body7, - color = TUITheme.colors.utilityDisabledContent - ) + Text( + text = title, + style = TUITheme.typography.body8, + color = TUITheme.colors.onSurface.copy(alpha = 0.7f) + ) + VerticalSpacer(space = 4) + Text( + text = style.text, + style = TUITheme.typography.body7, + color = TUITheme.colors.utilityDisabledContent + ) } sealed class TextRowStyle { - data class TitleWithDescription(val description: String) : TextRowStyle() + data class TitleWithDescription(val description: String) : TextRowStyle() - data class DateStyle( - val startDate: String, - val endDate: String, - ) : - TextRowStyle() + data class DateStyle( + val startDate: String = "", + val endDate: String = "", + @StringRes val primaryNotAvailableText: Int = R.string.not_availble, + ) : TextRowStyle() - data class TitleWithNotAvailable(val text: String) : TextRowStyle() + data class TitleWithNotAvailable(val text: String) : TextRowStyle() - object Title : TextRowStyle() + object Title : TextRowStyle() } interface TUIPopUpMenu { - @get:StringRes val title: Int - val icon: TarkaIcon + @get:StringRes + val title: Int + val icon: TarkaIcon } data class TUITextRowTags( - val parentTag: String = "TUITextRow", - val iconOneTags: TUIIconButtonTags = TUIIconButtonTags(parentTag = "TUITextRow_IconOne"), - val iconTwoTags: TUIIconButtonTags = TUIIconButtonTags(parentTag = "TUITextRow_IconTwo"), - val buttonTag: String = "TUITextRow_Button", - val infoIconTag: String = "TUITextRow_InfoIcon", + val parentTag: String = "TUITextRow", + val iconOneTags: TUIIconButtonTags = TUIIconButtonTags(parentTag = "TUITextRow_IconOne"), + val iconTwoTags: TUIIconButtonTags = TUIIconButtonTags(parentTag = "TUITextRow_IconTwo"), + val buttonTag: String = "TUITextRow_Button", + val infoIconTag: String = "TUITextRow_InfoIcon", ) @Preview(showBackground = true) -@Composable fun TUITextRowPreview() { - TUITextRow( - title = "Duration", style = DateStyle( - "Jan 20 3000 friday march 32", "Jan 20 3000 friday march 32" - ), onTextRowClick = { - Log.d("TAG", "TUITextRowPreview: ") - }, onInfoIconClick = null - ) +@Composable +fun TUITextRowPreview() { + TUITextRow( + title = "Duration", style = DateStyle( + "Jan 20 3000 friday march 32", "Jan 20 3000 friday march 32" + ), onTextRowClick = { + Log.d("TAG", "TUITextRowPreview: ") + }, onInfoIconClick = null + ) }