-
Notifications
You must be signed in to change notification settings - Fork 22
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 #161 from kiwicom/key_value
Implement `KeyValue` and `KeyValueLarge` components
- Loading branch information
Showing
7 changed files
with
168 additions
and
0 deletions.
There are no files selected for viewing
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
52 changes: 52 additions & 0 deletions
52
catalog/src/main/java/kiwi/orbit/compose/catalog/screens/KeyValueScreen.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,52 @@ | ||
package kiwi.orbit.compose.catalog.screens | ||
|
||
import androidx.compose.foundation.layout.Box | ||
import androidx.compose.foundation.layout.Column | ||
import androidx.compose.foundation.layout.Spacer | ||
import androidx.compose.foundation.layout.fillMaxSize | ||
import androidx.compose.foundation.layout.height | ||
import androidx.compose.foundation.layout.padding | ||
import androidx.compose.foundation.rememberScrollState | ||
import androidx.compose.foundation.verticalScroll | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.tooling.preview.Preview | ||
import androidx.compose.ui.unit.dp | ||
import kiwi.orbit.compose.catalog.Screen | ||
import kiwi.orbit.compose.ui.controls.KeyValue | ||
import kiwi.orbit.compose.ui.controls.KeyValueLarge | ||
|
||
@Composable | ||
fun KeyValueScreen(onNavigateUp: () -> Unit) { | ||
Screen( | ||
title = "KeyValue", | ||
onNavigateUp = onNavigateUp, | ||
) { contentPadding -> | ||
Box( | ||
Modifier | ||
.fillMaxSize() | ||
.verticalScroll(rememberScrollState()) | ||
.padding(contentPadding) | ||
) { | ||
KeyValueScreenInner() | ||
} | ||
} | ||
} | ||
|
||
@Preview | ||
@Composable | ||
private fun KeyValueScreenInner() { | ||
Column( | ||
modifier = Modifier.padding(16.dp), | ||
) { | ||
KeyValue( | ||
key = "Key", | ||
value = "Value", | ||
) | ||
Spacer(modifier = Modifier.height(16.dp)) | ||
KeyValueLarge( | ||
key = "Large key", | ||
value = "Large value", | ||
) | ||
} | ||
} |
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
Binary file added
BIN
+11.6 KB
ui/screenshots/debug/kiwi.orbit.compose.ui.ScreenshotTest_keyValue.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
97 changes: 97 additions & 0 deletions
97
ui/src/main/java/kiwi/orbit/compose/ui/controls/KeyValue.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,97 @@ | ||
package kiwi.orbit.compose.ui.controls | ||
|
||
import androidx.compose.foundation.layout.Column | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.CompositionLocalProvider | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.tooling.preview.Preview | ||
import kiwi.orbit.compose.ui.OrbitTheme | ||
import kiwi.orbit.compose.ui.controls.internal.Preview | ||
import kiwi.orbit.compose.ui.foundation.ContentEmphasis | ||
import kiwi.orbit.compose.ui.foundation.LocalContentEmphasis | ||
import kiwi.orbit.compose.ui.foundation.LocalTextStyle | ||
|
||
@Composable | ||
public fun KeyValue( | ||
key: @Composable () -> Unit, | ||
value: @Composable () -> Unit, | ||
modifier: Modifier = Modifier, | ||
) { | ||
Column(modifier = modifier) { | ||
CompositionLocalProvider( | ||
LocalTextStyle provides OrbitTheme.typography.bodySmall, | ||
LocalContentEmphasis provides ContentEmphasis.Minor, | ||
) { | ||
key() | ||
} | ||
CompositionLocalProvider( | ||
LocalTextStyle provides OrbitTheme.typography.bodyNormalMedium, | ||
LocalContentEmphasis provides ContentEmphasis.Normal, | ||
) { | ||
value() | ||
} | ||
} | ||
} | ||
|
||
@Composable | ||
public fun KeyValueLarge( | ||
key: @Composable () -> Unit, | ||
value: @Composable () -> Unit, | ||
modifier: Modifier = Modifier, | ||
) { | ||
Column(modifier = modifier) { | ||
CompositionLocalProvider( | ||
LocalTextStyle provides OrbitTheme.typography.bodyNormal, | ||
LocalContentEmphasis provides ContentEmphasis.Minor, | ||
) { | ||
key() | ||
} | ||
CompositionLocalProvider( | ||
LocalTextStyle provides OrbitTheme.typography.bodyLargeMedium, | ||
LocalContentEmphasis provides ContentEmphasis.Normal, | ||
) { | ||
value() | ||
} | ||
} | ||
} | ||
|
||
@Composable | ||
public fun KeyValue( | ||
key: String, | ||
value: String, | ||
modifier: Modifier = Modifier, | ||
) { | ||
KeyValue( | ||
key = { Text(text = key) }, | ||
value = { Text(text = value) }, | ||
modifier = modifier, | ||
) | ||
} | ||
|
||
@Composable | ||
public fun KeyValueLarge( | ||
key: String, | ||
value: String, | ||
modifier: Modifier = Modifier, | ||
) { | ||
KeyValueLarge( | ||
key = { Text(text = key) }, | ||
value = { Text(text = value) }, | ||
modifier = modifier, | ||
) | ||
} | ||
|
||
@Preview | ||
@Composable | ||
internal fun KeyValuePreview() { | ||
Preview { | ||
KeyValue( | ||
key = "Key", | ||
value = "Value", | ||
) | ||
KeyValueLarge( | ||
key = "Large key", | ||
value = "Large value", | ||
) | ||
} | ||
} |