Skip to content

Commit

Permalink
Merge pull request #139 from tarkalabs/mohan/enhancement/button_block…
Browse files Browse the repository at this point in the history
…_updation

Leading and trailing icon added and minor changes in TableUICell component
  • Loading branch information
rajajawahar authored Nov 21, 2023
2 parents 29913b3 + 5bcd8c9 commit 0f5309d
Show file tree
Hide file tree
Showing 20 changed files with 107 additions and 45 deletions.
2 changes: 1 addition & 1 deletion tarkaui/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ publishing {
run {
groupId = "com.tarkalabs"
artifactId = getLibraryArtifactId()
version = "0.57-alpha"
version = "0.58-alpha"
artifact("$buildDir/outputs/aar/${getLibraryArtifactId()}-release.aar")
}
}
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -1,58 +1,80 @@
@file:OptIn(ExperimentalMaterial3Api::class)

package com.tarkalabs.uicomponents.screenshots

import androidx.compose.material3.ExperimentalMaterial3Api
import com.tarkalabs.tarkaicons.ChevronDown24
import com.tarkalabs.tarkaicons.ChevronUp24
import com.tarkalabs.tarkaicons.TarkaIcons
import com.tarkalabs.uicomponents.components.TUIMobileButtonBlock
import org.junit.Test
import org.junit.runner.RunWith
import org.junit.runners.Parameterized


@RunWith(Parameterized::class)
class TUIMobileButtonBlocksScreenShotTest(
private val testName: String,
private val darkTheme: Boolean
private val darkTheme: Boolean,
) : ComposeScreenshotComparator() {

companion object {
@JvmStatic
@Parameterized.Parameters
fun data(): Collection<Array<Any>> {
return mutableListOf<Array<Any>>().apply {
fun data(): Collection<Array<Any?>> {
return mutableListOf<Array<Any?>>().apply {
for (darkTheme in listOf(true, false)) {
val testName = "darkTheme_${darkTheme}"
val testName = "_darkTheme_${darkTheme}"
add(arrayOf(testName, darkTheme))
}
}
}
}

@Test fun oneButtonOnly() = compareScreenshotFor(darkTheme, "_oneButtonOnly_$testName") {
@Test fun oneButtonOnlyWithoutIcon() = compareScreenshotFor(darkTheme, "_oneButtonOnlyWithoutIcon_$testName") {
TUIMobileButtonBlock(
primaryButtonLabel = "Label",
primaryButtonOnClick = { /*TODO*/ },
outlineButtonLabel = null,
outlineButtonOnClick = null
outlineButtonOnClick = null,
)
}

@Test fun twoButtons() = compareScreenshotFor(darkTheme, "_twoButtons_$testName") {
@Test fun oneButtonOnlyWithPrimaryLeadingIcon() = compareScreenshotFor(darkTheme, "_oneButtonOnlyWithPrimaryLeadingIcon_$testName") {
TUIMobileButtonBlock(
primaryButtonLabel = "Label",
primaryButtonOnClick = { /*TODO*/ },
outlineButtonLabel = "Label",
outlineButtonOnClick = { /*TODO*/ }
outlineButtonLabel = null,
outlineButtonOnClick = null,
primaryLeadingIcon = TarkaIcons.Regular.ChevronDown24,
primaryTrailingIcon = null
)
}

@Test fun twoButtonsWithWeight() = compareScreenshotFor(darkTheme, "_twoButtonsWithWeight_$testName") {
@Test fun oneButtonOnlyWithPrimaryTrailingIcon() = compareScreenshotFor(darkTheme, "_oneButtonOnlyWithPrimaryTrailingIcon_$testName") {
TUIMobileButtonBlock(
primaryButtonLabel = "Label",
primaryButtonOnClick = { /*TODO*/ },
outlineButtonLabel = null,
outlineButtonOnClick = null,
primaryLeadingIcon = null,
primaryTrailingIcon = TarkaIcons.Regular.ChevronUp24
)
}

@Test fun twoButtons() = compareScreenshotFor(darkTheme, "_twoButtons_$testName") {
TUIMobileButtonBlock(
primaryButtonLabel = "Label",
primaryButtonOnClick = { /*TODO*/ },
outlineButtonLabel = "Label",
outlineButtonOnClick = { /*TODO*/ },
primaryButtonWeight = 3f
)
}

@Test fun twoButtonsWithWeight() =
compareScreenshotFor(darkTheme, "_twoButtonsWithWeight_$testName") {
TUIMobileButtonBlock(
primaryButtonLabel = "Label",
primaryButtonOnClick = { /*TODO*/ },
outlineButtonLabel = "Label",
outlineButtonOnClick = { /*TODO*/ },
primaryButtonWeight = 3f,
)
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
package com.tarkalabs.uicomponents.components

import com.tarkalabs.uicomponents.components.base.ButtonSize.XL
import com.tarkalabs.uicomponents.components.base.ButtonStyle.OUTLINE
import com.tarkalabs.uicomponents.components.base.ButtonStyle.PRIMARY
import com.tarkalabs.uicomponents.components.base.TUIButtonTags
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
Expand All @@ -15,7 +11,14 @@ import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import com.tarkalabs.tarkaicons.ChevronDown24
import com.tarkalabs.tarkaicons.TarkaIcon
import com.tarkalabs.tarkaicons.TarkaIcons.Regular
import com.tarkalabs.uicomponents.components.base.ButtonSize.XL
import com.tarkalabs.uicomponents.components.base.ButtonStyle.OUTLINE
import com.tarkalabs.uicomponents.components.base.ButtonStyle.PRIMARY
import com.tarkalabs.uicomponents.components.base.TUIButton
import com.tarkalabs.uicomponents.components.base.TUIButtonTags
import com.tarkalabs.uicomponents.theme.TUITheme

/**
Expand All @@ -27,8 +30,12 @@ import com.tarkalabs.uicomponents.theme.TUITheme
* @param outlineButtonLabel The optional label text for the outline button. If null, the outline button will not be displayed.
* @param outlineButtonOnClick The optional callback function to be invoked when the outline button is clicked.
* @param primaryButtonWeight The optional weight of the primary button relative to the outline button.
* If null, the primary button will occupy all available space.
* @param leadingIcon The drawable resource for the leading icon, if any. Default is null.
* @param trailingIcon The drawable resource for the trailing icon, if any. Default is null.
*
* If null, the primary button will occupy all available space.
*/

@Composable
fun TUIMobileButtonBlock(
modifier: Modifier = Modifier,
Expand All @@ -37,9 +44,10 @@ fun TUIMobileButtonBlock(
outlineButtonLabel: String?,
outlineButtonOnClick: (() -> Unit)?,
primaryButtonWeight: Float? = null,
primaryLeadingIcon: TarkaIcon? = null,
primaryTrailingIcon: TarkaIcon? = null,
tags: TUIMobileButtonBlockTags = TUIMobileButtonBlockTags()
) {

Column(modifier.fillMaxWidth()) {
Divider(color = TUITheme.colors.surfaceVariant, thickness = 1.dp)
Row(
Expand All @@ -53,6 +61,8 @@ fun TUIMobileButtonBlock(
label = outlineButtonLabel,
onClick = { outlineButtonOnClick?.invoke() },
buttonStyle = OUTLINE,
leadingIcon = null,
trailingIcon = null,
modifier = if (primaryButtonWeight == null) Modifier.weight(1f) else Modifier.wrapContentWidth(),
tags = TUIButtonTags(parentTag = tags.outlineButtonTag)
)
Expand All @@ -64,10 +74,15 @@ fun TUIMobileButtonBlock(
label = it,
onClick = { primaryButtonOnClick?.invoke() },
buttonStyle = PRIMARY,
leadingIcon = primaryLeadingIcon,
trailingIcon = primaryTrailingIcon,
modifier = Modifier.weight(
if (outlineButtonLabel == null) 1f else primaryButtonWeight ?: 1f
),
tags = TUIButtonTags(parentTag = tags.primaryButtonTag)
tags = TUIButtonTags(
parentTag = tags.primaryButtonTag,
trailingIconTag = tags.primaryTrailingIconTag
)
)
}
}
Expand All @@ -77,7 +92,10 @@ fun TUIMobileButtonBlock(
data class TUIMobileButtonBlockTags(
val primaryButtonTag: String = "TUIMobileButtonBlock_Primary",
val outlineButtonTag: String = "TUIMobileButtonBlock_Outline",
)
val primaryLeadingIconTag: String = "TUIMobileButtonBlock_PrimaryLeadingIcon",
val primaryTrailingIconTag: String = "TUIMobileButtonBlock_PrimaryTrailingIcon",

)

@Preview @Composable fun TUIMobileButtonPreview() {
TUIMobileButtonBlock(
Expand All @@ -99,26 +117,49 @@ fun TUIMobileButtonPreview1() {
)
}

@Preview
@Composable
fun TUIMobileButtonPreview2() {
TUIMobileButtonBlock(
primaryButtonLabel = "Label",
primaryButtonOnClick = { /*TODO*/ },
outlineButtonLabel = null,
outlineButtonOnClick = { /*TODO*/ },
primaryTrailingIcon = Regular.ChevronDown24
)
}

@Preview
@Composable
fun TUIMobileButtonPreview3() {
TUITheme {
Column {
TUIMobileButtonBlock(
primaryButtonLabel = "Label",
primaryButtonOnClick = { /*TODO*/ },
outlineButtonLabel = "Label",
outlineButtonOnClick = { /*TODO*/ },
primaryButtonWeight = 3f
)
TUIMobileButtonBlock(
primaryButtonLabel = null,
primaryButtonOnClick = null,
outlineButtonLabel = "Label",
outlineButtonOnClick = { /*TODO*/ },
primaryButtonWeight = null
)
TUIMobileButtonBlock(
primaryButtonLabel = "Label",
primaryButtonOnClick = { /*TODO*/ },
outlineButtonLabel = null,
outlineButtonOnClick = { /*TODO*/ },
primaryLeadingIcon = Regular.ChevronDown24
)
}

}
}
@Preview
@Composable
fun TUIMobileButtonPreview4() {
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
Expand Up @@ -15,7 +15,6 @@ import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.drawBehind
import androidx.compose.ui.geometry.Offset
import androidx.compose.ui.graphics.drawscope.Stroke
import androidx.compose.ui.platform.testTag
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
Expand Down Expand Up @@ -51,15 +50,15 @@ import com.tarkalabs.uicomponents.theme.TUITheme
color = borderColor,
start = Offset(x = 0f, y = 0f),
end = Offset(x = size.width, y = 0f),
strokeWidth = Stroke.HairlineWidth
strokeWidth = 1.dp.toPx()
)
}
if (isBottomBorderVisible) {
drawLine(
color = borderColor,
start = Offset(x = 0f, y = size.height),
end = Offset(x = size.width, y = size.height),
strokeWidth = Stroke.HairlineWidth
strokeWidth = 1.dp.toPx()
)
}
}
Expand Down

0 comments on commit 0f5309d

Please sign in to comment.