Skip to content

Commit

Permalink
Merge pull request #171 from tarkalabs/sheshu/component/tui_divider
Browse files Browse the repository at this point in the history
Tui divider component is created
  • Loading branch information
rajajawahar authored Jan 29, 2024
2 parents e38c41b + 759a952 commit 3f17d2f
Show file tree
Hide file tree
Showing 10 changed files with 270 additions and 15 deletions.
17 changes: 15 additions & 2 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 @@ -64,7 +64,7 @@ publishing {
run {
groupId = "com.tarkalabs"
artifactId = getLibraryArtifactId()
version = "1.0.1"
version = "1.0.2"
artifact("$buildDir/outputs/aar/${getLibraryArtifactId()}-release.aar")
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.tarkalabs.uicomponents

import androidx.compose.ui.test.assertIsDisplayed
import androidx.compose.ui.test.junit4.createComposeRule
import androidx.compose.ui.test.onNodeWithTag
import com.tarkalabs.uicomponents.components.Orientation.HORIZONTAL
import com.tarkalabs.uicomponents.components.TUIDivider
import com.tarkalabs.uicomponents.components.TUIDividerTags
import org.junit.Rule
import org.junit.Test

class TUIDividerTest {
@get:Rule val composeTestRule = createComposeRule()

private val tags = TUIDividerTags(parentTag = "testTag")

@Test fun divider_Displayed() {
composeTestRule.setContent {
TUIDivider(
tags = tags, orientation = HORIZONTAL
)
}
composeTestRule.onNodeWithTag(tags.parentTag).assertIsDisplayed()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
package com.tarkalabs.uicomponents.screenshots

import com.tarkalabs.uicomponents.components.HorizontalPaddingSize
import com.tarkalabs.uicomponents.components.HorizontalPaddingSize.L
import com.tarkalabs.uicomponents.components.HorizontalPaddingSize.M
import com.tarkalabs.uicomponents.components.HorizontalPaddingSize.S
import com.tarkalabs.uicomponents.components.HorizontalPaddingSize.XL
import com.tarkalabs.uicomponents.components.HorizontalPaddingSize.NONE
import com.tarkalabs.uicomponents.components.Orientation
import com.tarkalabs.uicomponents.components.Orientation.HORIZONTAL
import com.tarkalabs.uicomponents.components.Orientation.VERTICAL
import com.tarkalabs.uicomponents.components.TUIDivider
import com.tarkalabs.uicomponents.components.TUIDividerTags
import com.tarkalabs.uicomponents.components.VerticalPaddingSize
import org.junit.Test
import org.junit.runner.RunWith
import org.junit.runners.Parameterized

@RunWith(Parameterized::class)
class TUIDividerScreenshotTest(
private val darkTheme: Boolean,
private val orientation: Orientation,
private val tuiDividerTags: TUIDividerTags,
private val horizontalPaddingSize: HorizontalPaddingSize,
private val verticalPaddingSize: VerticalPaddingSize,
private val testName: String,
) : ComposeScreenshotComparator() {

companion object {
@JvmStatic
@Parameterized.Parameters
fun data(): Collection<Array<Any?>> {
val darkThemeValues = listOf(true, false)
val orientationValues = listOf(HORIZONTAL, VERTICAL)
val tuiDividerTags = TUIDividerTags("TUIDivider")
val horizontalPaddingSize = listOf(NONE, S, M, L, XL)
val verticalPaddingSize = listOf(VerticalPaddingSize.NONE, VerticalPaddingSize.M)

val testData = arrayListOf<Array<Any?>>()

for (darkTheme in darkThemeValues) {
for (orientation in orientationValues) {
for (horizontalPadding in horizontalPaddingSize) {
for (verticalPadding in verticalPaddingSize) {

val testName =
"darkTheme_${darkTheme}_orientationValues_${orientation}" +
"_horizontalPadding_${horizontalPadding}_verticalPadding_${verticalPadding}"
testData.add(
arrayOf(
darkTheme,
orientation,
tuiDividerTags,
horizontalPadding,
verticalPadding,
testName
)
)
}
}
}
}
return testData
}
}

@Test
fun test_tui_divider_with_all_possible_params() {
compareScreenshotFor(darkTheme = darkTheme, imageName = testName) {
TUIDivider(
orientation = orientation, tags = tuiDividerTags,
horizontalPadding = horizontalPaddingSize, verticalPadding = verticalPaddingSize
)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.wrapContentHeight
import androidx.compose.material3.Divider
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.Text
import androidx.compose.material3.TopAppBar
Expand Down Expand Up @@ -200,7 +199,7 @@ import com.tarkalabs.uicomponents.theme.TUITheme
scrollBehavior = scrollBehavior,
)
}
Divider(modifier = Modifier.fillMaxWidth(), color = TUITheme.colors.surfaceVariant)
TUIDivider()
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
package com.tarkalabs.uicomponents.components

import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxHeight
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.width
import androidx.compose.material3.Divider
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.platform.testTag
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import com.tarkalabs.uicomponents.components.HorizontalPaddingSize.L
import com.tarkalabs.uicomponents.components.HorizontalPaddingSize.NONE
import com.tarkalabs.uicomponents.components.Orientation.HORIZONTAL
import com.tarkalabs.uicomponents.components.Orientation.VERTICAL
import com.tarkalabs.uicomponents.components.VerticalPaddingSize.M
import com.tarkalabs.uicomponents.theme.TUITheme

/**
*
* TUIDivider creates a divider , in two orientations Horizontal and Vertical.
*
* @param orientation: The orientation of divider is passed as param (Horizontal or Vertical)
* @param thickness: The thickness of divider , default is one.
* @param horizontalPadding: Horizontal padding of this divider.
* @param verticalPadding: The Vertical padding of this divider.
* @param tags: The test tag for the row.
* @param color: The color of the divider, by default we're using surfaceVariantHover.
*
* Example usage:
*
* TUIDivider(
* orientation = HORIZONTAL,
* thickness = 2,
* horizontalPadding = L,
* verticalPadding = M,
* )
*
*/

@Composable
fun TUIDivider(
modifier: Modifier = Modifier,
orientation: Orientation = HORIZONTAL,
thickness: Int = 1,
color: Color = TUITheme.colors.surfaceVariantHover,
horizontalPadding: HorizontalPaddingSize = NONE,
verticalPadding: VerticalPaddingSize = VerticalPaddingSize.NONE,
tags: TUIDividerTags = TUIDividerTags(),
) {
when (orientation) {
VERTICAL -> {
//todo vertical divider is not yet implemented in any of the components so we don't know height
// .height(40.dp)
Row {
HorizontalSpacer(space = horizontalPadding.size)
Divider(
modifier = modifier
.fillMaxHeight()
.width(thickness.dp)
.padding(vertical = verticalPadding.size.dp)
.testTag(tag = tags.parentTag),
color = color
)
HorizontalSpacer(space = horizontalPadding.size)
}
}

HORIZONTAL -> {
Column {
VerticalSpacer(space = verticalPadding.size)
Divider(
modifier = modifier
.fillMaxWidth()
.height(thickness.dp)
.padding(horizontal = horizontalPadding.size.dp)
.testTag(tag = tags.parentTag),
color = color,
)
VerticalSpacer(space = verticalPadding.size)
}
}
}
}

@Preview
@Composable
fun TestTUIDivider() {
TUIDivider(
orientation = VERTICAL,
thickness = 20,
horizontalPadding = L,
verticalPadding = M,
)
TUIDivider(
orientation = HORIZONTAL,
thickness = 20,
horizontalPadding = L,
verticalPadding = M,
)
}

data class TUIDividerTags(
val parentTag: String = "TUIDivider",
)

enum class Orientation {
VERTICAL,
HORIZONTAL
}

enum class HorizontalPaddingSize(val size: Int) {
XL(32),
L(24),
M(16),
S(8),
NONE(0);
}

enum class VerticalPaddingSize(val size: Int) {
M(8),
NONE(0)
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ fun TUIMobileButtonBlock(
tags: TUIMobileButtonBlockTags = TUIMobileButtonBlockTags()
) {
Column(modifier.fillMaxWidth()) {
Divider(color = TUITheme.colors.surfaceVariant, thickness = 1.dp)
TUIDivider()
Row(
Modifier
.background(TUITheme.colors.surface50)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,9 @@ fun TUIMobileOverlayHeader(

is HeaderWithTrailingIcon -> {
HeaderText(
title = style.title, textAlign = TextAlign.Start, modifier = Modifier.weight(1f).padding(start = 16.dp)
title = style.title, textAlign = TextAlign.Start, modifier = Modifier
.weight(1f)
.padding(start = 16.dp)

)
TUIIconButton(
Expand All @@ -153,6 +155,21 @@ fun TUIMobileOverlayHeader(
}
}
}
when(style) {
is HeaderWithBackIcon -> {
VerticalSpacer(space = 8)
TUIDivider()
}
is HeaderWithTitle -> {
VerticalSpacer(space = 16)
TUIDivider()
}
is HeaderWithTrailingIcon -> {
VerticalSpacer(space = 12)
TUIDivider()
}
None -> {}
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@ object TUIMultiLevelSelectorHeader {
* @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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import androidx.compose.foundation.text.BasicTextField
import androidx.compose.foundation.text.KeyboardActions
import androidx.compose.foundation.text.KeyboardOptions
import androidx.compose.material3.Button
import androidx.compose.material3.Divider
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.Text
import androidx.compose.material3.TextField
Expand All @@ -33,7 +32,6 @@ import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.ExperimentalComposeUiApi
import androidx.compose.ui.Modifier
import androidx.compose.ui.focus.FocusRequester
import androidx.compose.ui.focus.focusRequester
Expand All @@ -54,6 +52,7 @@ import com.tarkalabs.tarkaicons.TarkaIcons.Filled
import com.tarkalabs.uicomponents.components.ChipType.Input
import com.tarkalabs.uicomponents.components.TUIChip
import com.tarkalabs.uicomponents.components.TUIChipTags
import com.tarkalabs.uicomponents.components.TUIDivider
import com.tarkalabs.uicomponents.components.base.IconButtonStyle.GHOST
import com.tarkalabs.uicomponents.components.base.TUIIconButton
import com.tarkalabs.uicomponents.components.base.TUIIconButtonTags
Expand All @@ -75,7 +74,7 @@ import kotlinx.coroutines.launch
* @param onInvalidEmail The callback function to be invoked when user enter a invalid email address.
*/
@OptIn(
ExperimentalLayoutApi::class, ExperimentalMaterial3Api::class, ExperimentalComposeUiApi::class
ExperimentalLayoutApi::class, ExperimentalMaterial3Api::class
) @Composable fun TUIEmailField(
modifier: Modifier = Modifier,
title: String,
Expand Down Expand Up @@ -219,9 +218,9 @@ import kotlinx.coroutines.launch
)
}

Divider(
color = if (showTextField ) TUITheme.colors.primary else TUITheme.colors.surfaceVariant,
thickness = 2.dp,
TUIDivider(
color = if (showTextField) TUITheme.colors.primary else TUITheme.colors.surfaceVariant,
thickness = 2,
modifier = Modifier.padding(top = 10.dp)
)

Expand Down

0 comments on commit 3f17d2f

Please sign in to comment.