Skip to content

Commit

Permalink
Merge pull request #125 from tarkalabs/nilesh/tuiMultiLevelSelectorHe…
Browse files Browse the repository at this point in the history
…ader

UIComponent : TUIMultiLevelSelectorHeader
  • Loading branch information
askNilesh authored Sep 22, 2023
2 parents a78ca02 + d761cba commit 40cd002
Show file tree
Hide file tree
Showing 6 changed files with 250 additions and 20 deletions.
26 changes: 26 additions & 0 deletions .idea/androidTestResultsUserPreferences.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion tarkaui/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 = "0.45-alpha"
version = "0.46-alpha"
artifact("$buildDir/outputs/aar/${getLibraryArtifactId()}-release.aar")
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package com.tarkalabs.uicomponents

import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.ui.Modifier
import androidx.compose.ui.test.assertIsDisplayed
import androidx.compose.ui.test.junit4.createComposeRule
import androidx.compose.ui.test.onNodeWithContentDescription
import androidx.compose.ui.test.onNodeWithTag
import androidx.compose.ui.test.onNodeWithText
import androidx.compose.ui.test.performClick
import com.tarkalabs.tarkaicons.ApprovalsApp24
import com.tarkalabs.tarkaicons.TarkaIcons.Filled
import com.tarkalabs.uicomponents.components.TUIMultiLevelSelectorHeader
import com.tarkalabs.uicomponents.components.TUIMultiLevelSelectorHeader.TUIMultiLevelSelectorHeaderTags
import org.junit.Rule
import org.junit.Test
import org.mockito.kotlin.mock
import org.mockito.kotlin.verify

class TUIMultiLevelSelectorHeaderTest {

@get:Rule val composable = createComposeRule()

private val tags = TUIMultiLevelSelectorHeaderTags()

@Test fun multiLevelSelectorHeader_Displayed() {
composable.setContent {
TUIMultiLevelSelectorHeader(
modifier = Modifier.fillMaxWidth(),
isSelected = true,
leadingIcon = Filled.ApprovalsApp24.copy(contentDescription = "leadingIcon"),
trailingIcon = Filled.ApprovalsApp24.copy(contentDescription = "trailingIcon"),
title = "Hello There",
tags = tags
) {}

}
composable.onNodeWithText("Hello There").assertIsDisplayed()
composable.onNodeWithTag(tags.parentTag, useUnmergedTree = true).assertIsDisplayed()
composable.onNodeWithContentDescription("leadingIcon", useUnmergedTree = true).assertIsDisplayed()
composable.onNodeWithContentDescription("trailingIcon", useUnmergedTree = true).assertIsDisplayed()
}

@Test fun multiLevelSelectorHeader_Click_Triggered() {
val onClick: () -> Unit = mock()

composable.setContent {
TUIMultiLevelSelectorHeader(
modifier = Modifier.fillMaxWidth(),
isSelected = true,
leadingIcon = Filled.ApprovalsApp24,
trailingIcon = Filled.ApprovalsApp24,
title = "Hello There",
tags = tags,
onClick = onClick
)

}
composable.onNodeWithTag(tags.parentTag, useUnmergedTree = true).performClick()
verify(onClick).invoke()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import com.tarkalabs.tarkaicons.Tabs24
import com.tarkalabs.tarkaicons.TarkaIcons
import com.tarkalabs.uicomponents.components.TUITabBar
import com.tarkalabs.uicomponents.components.TUITabBarTags
import com.tarkalabs.uicomponents.components.TUITabTags
import com.tarkalabs.uicomponents.components.TabItem
import org.junit.Rule
import org.junit.Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ import com.tarkalabs.uicomponents.theme.TUITheme
@Composable
fun TUIMobileButtonBlock(
modifier: Modifier = Modifier,
primaryButtonLabel: String,
primaryButtonOnClick: () -> Unit,
primaryButtonLabel: String?,
primaryButtonOnClick: (() -> Unit)?,
outlineButtonLabel: String?,
outlineButtonOnClick: (() -> Unit)?,
primaryButtonWeight: Float? = null,
Expand All @@ -58,16 +58,18 @@ fun TUIMobileButtonBlock(
)
HorizontalSpacer(space = 8)
}
TUIButton(
height = XL,
label = primaryButtonLabel,
onClick = primaryButtonOnClick,
buttonStyle = PRIMARY,
modifier = Modifier.weight(
if (outlineButtonLabel == null) 1f else primaryButtonWeight ?: 1f
),
tags = TUIButtonTags(parentTag = tags.primaryButtonTag)
)
primaryButtonLabel?.let {
TUIButton(
height = XL,
label = it,
onClick = { primaryButtonOnClick?.invoke() },
buttonStyle = PRIMARY,
modifier = Modifier.weight(
if (outlineButtonLabel == null) 1f else primaryButtonWeight ?: 1f
),
tags = TUIButtonTags(parentTag = tags.primaryButtonTag)
)
}
}
}
}
Expand Down Expand Up @@ -100,11 +102,23 @@ fun TUIMobileButtonPreview1() {
@Preview
@Composable
fun TUIMobileButtonPreview3() {
TUIMobileButtonBlock(
primaryButtonLabel = "Label",
primaryButtonOnClick = { /*TODO*/ },
outlineButtonLabel = "Label",
outlineButtonOnClick = { /*TODO*/ },
primaryButtonWeight = 3f
)
TUITheme {
Column {
TUIMobileButtonBlock(
primaryButtonLabel = "Label",
primaryButtonOnClick = { /*TODO*/ },
outlineButtonLabel = "Label",
outlineButtonOnClick = { /*TODO*/ },
primaryButtonWeight = 3f
)
TUIMobileButtonBlock(
primaryButtonLabel = null,
primaryButtonOnClick = null,
outlineButtonLabel = "Label",
outlineButtonOnClick = { /*TODO*/ },
primaryButtonWeight = null
)

}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
package com.tarkalabs.uicomponents.components

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.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.material3.Icon
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.testTag
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import com.tarkalabs.tarkaicons.ApprovalsApp24
import com.tarkalabs.tarkaicons.TarkaIcon
import com.tarkalabs.tarkaicons.TarkaIcons
import com.tarkalabs.uicomponents.extentions.maxHeight
import com.tarkalabs.uicomponents.extentions.maxWidth
import com.tarkalabs.uicomponents.theme.TUITheme

object TUIMultiLevelSelectorHeader {

/**
* Composable representing a header for a multi-level selector.
*
* This composable function creates a header with a title, icons, and interactive behavior.
* It is typically used in multi-level selection components.
*
* @param modifier Modifier for the header layout and appearance.
* @param isSelected Boolean indicating whether the header is selected.
* @param title Title text to be displayed in the header.
* @param leadingIcon Icon to be displayed on the leading (left) side of the header.
* @param trailingIcon Icon to be displayed on the trailing (right) side of the header (optional).
* @param paddingValues Padding values for the header content.
* @param tags Tags used for testing and identifying this Composable.
* @param onClick Lambda function invoked when the header is clicked.
*/
@Composable operator fun invoke(
modifier: Modifier = Modifier,
isSelected: Boolean,
title: String,
leadingIcon: TarkaIcon,
trailingIcon: TarkaIcon? = null,
paddingValues: PaddingValues = PaddingValues(),
tags: TUIMultiLevelSelectorHeaderTags = TUIMultiLevelSelectorHeaderTags(),
onClick: () -> Unit,
) {
val color = if (isSelected) TUITheme.colors.onPrimaryAlt else TUITheme.colors.onSurface

Box(modifier = modifier
.background(color = if (isSelected) TUITheme.colors.primaryAlt else TUITheme.colors.surface)
.clickable { onClick() }
.padding(paddingValues)
.testTag(tags.parentTag)) {
Row(
modifier = Modifier.padding(horizontal = 12.dp, vertical = 8.dp),
verticalAlignment = Alignment.CenterVertically
) {
Icon(
painter = painterResource(id = leadingIcon.iconRes),
contentDescription = leadingIcon.contentDescription,
modifier = Modifier
.maxHeight(24)
.maxWidth(24),
tint = color
)
HorizontalSpacer(space = 4)
Text(
modifier = Modifier
.weight(1f)
.padding(vertical = 8.dp),
text = title,
style = TUITheme.typography.heading6,
color = color
)
HorizontalSpacer(space = 12)
if (trailingIcon != null) {
Icon(
painter = painterResource(id = trailingIcon.iconRes),
contentDescription = trailingIcon.contentDescription,
modifier = Modifier
.maxHeight(24)
.maxWidth(24),
tint = color
)
HorizontalSpacer(space = 12)
}
}

}
}

data class TUIMultiLevelSelectorHeaderTags(
val parentTag: String = "TUIMultiLevelSelectorHeader_ParentTag",
)
}

@Preview @Composable fun TUIMultiLevelSelectorHeaderPreview() {
TUITheme {
Column {
VerticalSpacer(space = 40)
TUIMultiLevelSelectorHeader(
modifier = Modifier.fillMaxWidth(),
isSelected = true,
leadingIcon = TarkaIcons.Filled.ApprovalsApp24,
trailingIcon = TarkaIcons.Filled.ApprovalsApp24,
title = "Hello There",
) {}

VerticalSpacer(space = 20)

TUIMultiLevelSelectorHeader(
modifier = Modifier.fillMaxWidth(),
isSelected = false,
title = "Hello There",
leadingIcon = TarkaIcons.Filled.ApprovalsApp24,
) {}

}
}
}

0 comments on commit 40cd002

Please sign in to comment.