Skip to content
This repository was archived by the owner on Mar 6, 2024. It is now read-only.

Commit a23ce65

Browse files
authored
Merge pull request #24 from dropbox/surface
Add surface component
2 parents cb88fb4 + 5034a25 commit a23ce65

File tree

207 files changed

+1655
-736
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

207 files changed

+1655
-736
lines changed

componentbox/build.gradle.kts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ kotlin {
4949
dependencies {
5050
api(compose.material)
5151
api(compose.ui)
52+
api(compose.foundation)
53+
implementation(Deps.Compose.coilCompose)
5254
}
5355
}
5456

componentbox/src/androidMain/kotlin/com/dropbox/componentbox/foundation/Themer.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,5 @@ actual abstract class Themer {
2121
abstract fun getColorResId(name: String?): Int?
2222

2323
@Composable
24-
abstract fun getTextStyle(name: String?): TextStyle
24+
abstract fun getTextStyle(name: String?): TextStyle?
2525
}

componentbox/src/androidMain/kotlin/com/dropbox/componentbox/material/box/Inflate.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ import com.dropbox.componentbox.foundation.Context
77
import com.dropbox.componentbox.material.Inflate
88
import com.dropbox.componentbox.util.build
99

10+
// This module targets JS
11+
// Until material and foundation are supported on JS
12+
// Changes to this file should be duplicated in jvmMain
13+
// TODO(https://github.com/dropbox/componentbox/issues/25)
14+
1015
@Composable
1116
fun Component.Box.Inflate(context: Context?) {
1217
Box(modifier = modifier.build()) {

componentbox/src/androidMain/kotlin/com/dropbox/componentbox/material/button/Contained.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@ import com.dropbox.componentbox.foundation.Context
99
import com.dropbox.componentbox.material.Inflate
1010
import com.dropbox.componentbox.util.build
1111

12+
// This module targets JS
13+
// Until material and foundation are supported on JS
14+
// Changes to this file should be duplicated in jvmMain
15+
// TODO(https://github.com/dropbox/componentbox/issues/25)
16+
1217
@Composable
1318
fun Component.Button.Contained(context: Context? = null) {
1419
Button(

componentbox/src/androidMain/kotlin/com/dropbox/componentbox/material/button/Inflate.kt

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,16 @@ import androidx.compose.runtime.Composable
44
import com.dropbox.componentbox.foundation.ButtonVariant
55
import com.dropbox.componentbox.foundation.Component
66
import com.dropbox.componentbox.foundation.Context
7-
import com.dropbox.componentbox.util.buttonVariant
7+
import com.dropbox.componentbox.util.translate
8+
9+
// This module targets JS
10+
// Until material and foundation are supported on JS
11+
// Changes to this file should be duplicated in jvmMain
12+
// TODO(https://github.com/dropbox/componentbox/issues/25)
813

914
@Composable
1015
fun Component.Button.Inflate(context: Context?) {
11-
when (this.variant.buttonVariant()) {
16+
when (this.variant.translate<ButtonVariant>()) {
1217
ButtonVariant.Contained -> Contained(context)
1318
ButtonVariant.Text -> TODO()
1419
ButtonVariant.Outlined -> TODO()

componentbox/src/androidMain/kotlin/com/dropbox/componentbox/material/column/Inflate.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@ import com.dropbox.componentbox.util.build
1414
import com.dropbox.componentbox.util.horizontal
1515
import com.dropbox.componentbox.util.vertical
1616

17+
// This module targets JS
18+
// Until material and foundation are supported on JS
19+
// Changes to this file should be duplicated in jvmMain
20+
// TODO(https://github.com/dropbox/componentbox/issues/25)
21+
1722
@Composable
1823
fun Component.Column.Inflate(context: Context?) {
1924
when (this.isLazy) {

componentbox/src/androidMain/kotlin/com/dropbox/componentbox/material/drawable/Inflate.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@ import com.dropbox.componentbox.foundation.Context
1111
import com.dropbox.componentbox.util.build
1212
import com.dropbox.componentbox.util.translate
1313

14+
// This module targets JS
15+
// Until material and foundation are supported on JS
16+
// Changes to this file should be duplicated in jvmMain
17+
// TODO(https://github.com/dropbox/componentbox/issues/25)
18+
1419
@Composable
1520
fun Component.Drawable.Inflate(context: Context?) {
1621
@DrawableRes

componentbox/src/androidMain/kotlin/com/dropbox/componentbox/material/inflate.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@ import com.dropbox.componentbox.material.text.Inflate
1717
import com.dropbox.componentbox.util.horizontal
1818
import com.dropbox.componentbox.util.vertical
1919

20+
// This module targets JS
21+
// Until material and foundation are supported on JS
22+
// Changes to this file should be duplicated in jvmMain
23+
// TODO(https://github.com/dropbox/componentbox/issues/25)
24+
2025
@Composable
2126
actual fun Component.Inflate(context: Context?) {
2227
when (this) {
@@ -28,6 +33,7 @@ actual fun Component.Inflate(context: Context?) {
2833
is Component.Switch -> TODO()
2934
is Component.Text -> Inflate(context)
3035
is Component.Vector -> TODO()
36+
is Component.Surface -> Inflate(context)
3137
}
3238
}
3339

componentbox/src/androidMain/kotlin/com/dropbox/componentbox/material/row/Inflate.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@ import com.dropbox.componentbox.util.build
1414
import com.dropbox.componentbox.util.horizontal
1515
import com.dropbox.componentbox.util.vertical
1616

17+
// This module targets JS
18+
// Until material and foundation are supported on JS
19+
// Changes to this file should be duplicated in jvmMain
20+
// TODO(https://github.com/dropbox/componentbox/issues/25)
21+
1722
@Composable
1823
fun Component.Row.Inflate(context: Context?) {
1924
when (this.isLazy) {
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
package com.dropbox.componentbox.material.surface
2+
3+
import androidx.compose.foundation.isSystemInDarkTheme
4+
import androidx.compose.material.MaterialTheme
5+
import androidx.compose.material.Surface
6+
import androidx.compose.runtime.Composable
7+
import androidx.compose.ui.graphics.Color
8+
import androidx.compose.ui.unit.dp
9+
import com.dropbox.componentbox.foundation.Component
10+
import com.dropbox.componentbox.foundation.Context
11+
import com.dropbox.componentbox.material.Inflate
12+
import com.dropbox.componentbox.util.build
13+
import com.dropbox.componentbox.util.translate
14+
15+
// This module targets JS
16+
// Until material and foundation are supported on JS
17+
// Changes to this file should be duplicated in jvmMain
18+
// TODO(https://github.com/dropbox/componentbox/issues/25)
19+
20+
@Composable
21+
fun Component.Surface.Inflate(context: Context?) {
22+
val isDark = isSystemInDarkTheme() || !MaterialTheme.colors.isLight
23+
24+
val color = if (this.color?.dark != null && this.color?.light != null) {
25+
if (isDark) Color(this.color!!.dark) else Color(this.color!!.light)
26+
} else {
27+
MaterialTheme.colors.surface
28+
}
29+
30+
val contentColor = if (this.contentColor?.dark != null && this.contentColor?.light != null) {
31+
if (isDark) Color(this.contentColor!!.dark) else Color(this.contentColor!!.light)
32+
} else {
33+
MaterialTheme.colors.onSurface
34+
}
35+
36+
val shape = this.shape.translate()
37+
val elevation = this.elevation?.dp ?: 0.dp
38+
39+
Surface(
40+
modifier = modifier.build(),
41+
shape = shape,
42+
color = color,
43+
contentColor = contentColor,
44+
elevation = elevation
45+
) {
46+
components?.forEach { component ->
47+
component.Inflate(context)
48+
}
49+
}
50+
}

0 commit comments

Comments
 (0)