Browse Source

Introduce basic support for flex in CSS API

pull/893/head
Shagen Ogandzhanian 3 years ago
parent
commit
8dd5e17338
  1. 26
      web/core/src/jsMain/kotlin/org/jetbrains/compose/web/css/properties/flex.kt
  2. 97
      web/core/src/jsTest/kotlin/css/CSSFlexTests.kt

26
web/core/src/jsMain/kotlin/org/jetbrains/compose/web/css/properties/flex.kt

@ -69,3 +69,29 @@ fun StyleBuilder.flexBasis(value: String) {
fun StyleBuilder.flexBasis(value: CSSNumeric) { fun StyleBuilder.flexBasis(value: CSSNumeric) {
property("flex-basis", value) property("flex-basis", value)
} }
// https://developer.mozilla.org/en-US/docs/Web/CSS/flex
fun StyleBuilder.flex(value: String) {
property("flex", value)
}
fun StyleBuilder.flex(value: Int) {
property("flex", value)
}
fun StyleBuilder.flex(value: CSSNumeric) {
property("flex", value)
}
fun StyleBuilder.flex(flexGrow: Int, flexBasis: CSSNumeric) {
property("flex", "${flexGrow} ${flexBasis}")
}
fun StyleBuilder.flex(flexGrow: Int, flexShrink: Int) {
property("flex", "${flexGrow} ${flexShrink}")
}
fun StyleBuilder.flex(flexGrow: Int, flexShrink: Int, flexBasis: CSSNumeric) {
property("flex", "${flexGrow} ${flexShrink} ${flexBasis}")
}

97
web/core/src/jsTest/kotlin/css/CSSFlexTests.kt

@ -18,7 +18,7 @@ import kotlin.test.assertEquals
class CSSFlexTests { class CSSFlexTests {
@Test @Test
fun stylesOrder() = runTest { fun order() = runTest {
composition { composition {
Div( Div(
{ {
@ -41,7 +41,7 @@ class CSSFlexTests {
} }
@Test @Test
fun stylesFlexGrow() = runTest { fun flexGrow() = runTest {
composition { composition {
Div( Div(
{ {
@ -80,7 +80,7 @@ class CSSFlexTests {
} }
@Test @Test
fun stylesFlexShrink() = runTest { fun flexShrink() = runTest {
composition { composition {
Div( Div(
{ {
@ -119,7 +119,7 @@ class CSSFlexTests {
} }
@Test @Test
fun stylesFlexFlow() = runTest { fun flexFlow() = runTest {
val flexWraps = FlexWrap.values() val flexWraps = FlexWrap.values()
val flexDirections = FlexDirection.values() val flexDirections = FlexDirection.values()
composition { composition {
@ -147,7 +147,7 @@ class CSSFlexTests {
} }
@Test @Test
fun stylesJustifyContent() = runTest { fun justifyContent() = runTest {
val enumValues = JustifyContent.values() val enumValues = JustifyContent.values()
composition { composition {
enumValues.forEach { justifyContent -> enumValues.forEach { justifyContent ->
@ -170,7 +170,7 @@ class CSSFlexTests {
} }
@Test @Test
fun stylesAlignSelf() = runTest { fun alignSelf() = runTest {
val enumValues = AlignSelf.values() val enumValues = AlignSelf.values()
composition { composition {
enumValues.forEach { alignSelf -> enumValues.forEach { alignSelf ->
@ -193,7 +193,7 @@ class CSSFlexTests {
} }
@Test @Test
fun stylesAlignItems() = runTest { fun alignItems() = runTest {
val enumValues = AlignItems.values() val enumValues = AlignItems.values()
composition { composition {
enumValues.forEach { alignItems -> enumValues.forEach { alignItems ->
@ -216,7 +216,7 @@ class CSSFlexTests {
} }
@Test @Test
fun stylesAlignContent() = runTest { fun alignContent() = runTest {
val enumValues = AlignContent.values() val enumValues = AlignContent.values()
composition { composition {
enumValues.forEach { alignContent -> enumValues.forEach { alignContent ->
@ -239,7 +239,7 @@ class CSSFlexTests {
} }
@Test @Test
fun stylesFlexDirection() = runTest { fun flexDirection() = runTest {
val enumValues = FlexDirection.values() val enumValues = FlexDirection.values()
composition { composition {
enumValues.forEach { flexDirection -> enumValues.forEach { flexDirection ->
@ -263,7 +263,7 @@ class CSSFlexTests {
@Test @Test
fun stylesFlexWrap() = runTest { fun flexWrap() = runTest {
val enumValues = FlexWrap.values() val enumValues = FlexWrap.values()
composition { composition {
enumValues.forEach { flexWrap -> enumValues.forEach { flexWrap ->
@ -286,7 +286,7 @@ class CSSFlexTests {
} }
@Test @Test
fun stylesFlexBasis() = runTest { fun flexBasis() = runTest {
composition { composition {
Span({ Span({
style { style {
@ -303,4 +303,79 @@ class CSSFlexTests {
assertEquals("10em", (root.children[0] as HTMLElement).style.flexBasis) assertEquals("10em", (root.children[0] as HTMLElement).style.flexBasis)
assertEquals("auto", (root.children[1] as HTMLElement).style.flexBasis) assertEquals("auto", (root.children[1] as HTMLElement).style.flexBasis)
} }
@Test
fun flexOneValue() = runTest {
composition {
Span({
style {
flex("auto")
}
})
Span({
style {
flex("initial")
}
})
Span({
style {
flex(2)
}
})
Span({
style {
flex(10.em)
}
})
}
assertEquals("auto", (root.children[0] as HTMLElement).style.flexBasis)
assertEquals("initial", (root.children[1] as HTMLElement).style.flexBasis)
assertEquals("2", (root.children[2] as HTMLElement).style.flexGrow)
assertEquals("10em", (root.children[3] as HTMLElement).style.flexBasis)
}
@Test
fun flexTwoValues() = runTest {
composition {
Span({
style {
flex(3, 30.px)
}
})
Span({
style {
flex(3, 5)
}
})
}
(root.children[0] as HTMLElement).let {
assertEquals("3", it.style.flexGrow)
assertEquals("30px", it.style.flexBasis)
}
(root.children[1] as HTMLElement).let {
assertEquals("3", it.style.flexGrow)
assertEquals("5", it.style.flexShrink)
}
}
@Test
fun flexThreeValues() = runTest {
composition {
Span({
style {
flex(2, 3, 10.percent)
}
})
}
(root.children[0] as HTMLElement).let {
assertEquals("2", it.style.flexGrow)
assertEquals("3", it.style.flexShrink)
assertEquals("10%", it.style.flexBasis)
}
}
} }
Loading…
Cancel
Save