Skip to content

Commit 52c3cd7

Browse files
committed
Add height and width in StyleScope
There is a bug that the list extends beyond the card in the web demo.
1 parent 4845e36 commit 52c3cd7

File tree

4 files changed

+21
-0
lines changed

4 files changed

+21
-0
lines changed

compose-multiplatform-common/src/commonMain/kotlin/com/huanshankeji/compose/ui/ModifierOrAttrsScope.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ expect class ModifierOrAttrsScope<out TElement : Element> {
1313

1414
expect class StyleScope {
1515
fun margin(value: SizeValue)
16+
fun height(value: SizeValue)
17+
fun width(value: SizeValue)
1618
}
1719

1820
private const val PADDING_MESSAGE =

compose-multiplatform-common/src/jsMain/kotlin/com/huanshankeji/compose/ui/ModifierOrAttrsScope.kt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ package com.huanshankeji.compose.ui
22

33
import com.huanshankeji.compose.ui.unit.SizeValue
44
import org.jetbrains.compose.web.attributes.AttrsScope
5+
import org.jetbrains.compose.web.css.height
56
import org.jetbrains.compose.web.css.margin
7+
import org.jetbrains.compose.web.css.width
68
import org.jetbrains.compose.web.dom.AttrBuilderContext
79
import org.w3c.dom.HTMLElement
810

@@ -22,4 +24,10 @@ actual class ModifierOrAttrsScope<out TElement : Element>(val attrsScope: AttrsS
2224
actual class StyleScope(val styleScope: org.jetbrains.compose.web.css.StyleScope) {
2325
actual fun margin(value: SizeValue) =
2426
styleScope.margin(value.platformValue)
27+
28+
actual fun height(value: SizeValue) =
29+
styleScope.height(value.platformValue)
30+
31+
actual fun width(value: SizeValue) =
32+
styleScope.width(value.platformValue)
2533
}

compose-multiplatform-common/src/jvmMain/kotlin/com/huanshankeji/compose/ui/ModifierOrAttrsScopeJvm.kt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package com.huanshankeji.compose.ui
22

3+
import androidx.compose.foundation.layout.height
34
import androidx.compose.foundation.layout.padding
5+
import androidx.compose.foundation.layout.width
46
import androidx.compose.ui.Modifier
57
import com.huanshankeji.compose.ui.unit.SizeValue
68

@@ -33,4 +35,12 @@ actual class StyleScope(val modifierOrAttrsScope: ModifierOrAttrsScope<*>) {
3335
actual fun margin(value: SizeValue) = modifierOrAttrsScope.modify {
3436
padding(value.platformValue)
3537
}
38+
39+
actual fun height(value: SizeValue) = modifierOrAttrsScope.modify {
40+
height(value.platformValue)
41+
}
42+
43+
actual fun width(value: SizeValue) = modifierOrAttrsScope.modify {
44+
width(value.platformValue)
45+
}
3646
}

demo/src/commonMain/kotlin/com/huanshankeji/compose/material/demo/Composables.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ fun App() {
2222
Card({
2323
style {
2424
margin(16.dpOrPx)
25+
height(400.dpOrPx)
2526
}
2627
}) {
2728
Column({

0 commit comments

Comments
 (0)