-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #171 from tarkalabs/sheshu/component/tui_divider
Tui divider component is created
- Loading branch information
Showing
10 changed files
with
270 additions
and
15 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
tarkaui/src/androidTest/java/com/tarkalabs/uicomponents/TUIDividerTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
} | ||
} |
76 changes: 76 additions & 0 deletions
76
...i/src/androidTest/java/com/tarkalabs/uicomponents/screenshots/TUIDividerScreenshotTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
128 changes: 128 additions & 0 deletions
128
tarkaui/src/main/java/com/tarkalabs/uicomponents/components/TUIDivider.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters