From 6dd06d4d18e75b7dbf0ec555e618d7aff0113c7d Mon Sep 17 00:00:00 2001 From: Shagen Ogandzhanian Date: Mon, 12 Jul 2021 20:05:40 +0200 Subject: [PATCH] Introduce basic support for text-align in CSS API --- .../web/css/properties/{font.kt => text.kt} | 5 +++ .../css/{CSSFontTests.kt => CSSTextTests.kt} | 45 ++++++++++++++++++- 2 files changed, 49 insertions(+), 1 deletion(-) rename web/core/src/jsMain/kotlin/org/jetbrains/compose/web/css/properties/{font.kt => text.kt} (91%) rename web/core/src/jsTest/kotlin/css/{CSSFontTests.kt => CSSTextTests.kt} (76%) diff --git a/web/core/src/jsMain/kotlin/org/jetbrains/compose/web/css/properties/font.kt b/web/core/src/jsMain/kotlin/org/jetbrains/compose/web/css/properties/text.kt similarity index 91% rename from web/core/src/jsMain/kotlin/org/jetbrains/compose/web/css/properties/font.kt rename to web/core/src/jsMain/kotlin/org/jetbrains/compose/web/css/properties/text.kt index 5dc0d725de..3b6f50a4a4 100644 --- a/web/core/src/jsMain/kotlin/org/jetbrains/compose/web/css/properties/font.kt +++ b/web/core/src/jsMain/kotlin/org/jetbrains/compose/web/css/properties/text.kt @@ -50,4 +50,9 @@ fun StyleBuilder.letterSpacing(value: String) { fun StyleBuilder.letterSpacing(value: CSSNumeric) { property("letter-spacing", value) +} + +// https://developer.mozilla.org/en-US/docs/Web/CSS/text-align +fun StyleBuilder.textAlign(value: String) { + property("text-align", value) } \ No newline at end of file diff --git a/web/core/src/jsTest/kotlin/css/CSSFontTests.kt b/web/core/src/jsTest/kotlin/css/CSSTextTests.kt similarity index 76% rename from web/core/src/jsTest/kotlin/css/CSSFontTests.kt rename to web/core/src/jsTest/kotlin/css/CSSTextTests.kt index 78534b041b..9d9d6d9b0b 100644 --- a/web/core/src/jsTest/kotlin/css/CSSFontTests.kt +++ b/web/core/src/jsTest/kotlin/css/CSSTextTests.kt @@ -14,7 +14,7 @@ import org.w3c.dom.get import kotlin.test.Test import kotlin.test.assertEquals -class CSSFontTests { +class CSSTextTests { @Test fun fontSize() = runTest { @@ -155,5 +155,48 @@ class CSSFontTests { assertEquals("italic bold 0.8em / 1.2 Arial, sans-serif", (root.children[0] as HTMLElement).style.font) } + @Test + fun textAlign() = runTest { + composition { + Div({ + style { + textAlign("left") + } + }) + Div({ + style { + textAlign("right") + } + }) + Div({ + style { + textAlign("center") + } + }) + Div({ + style { + textAlign("justify") + } + }) + Div({ + style { + textAlign("start") + } + }) + Div({ + style { + textAlign("end") + } + }) + } + + assertEquals("left", (root.children[0] as HTMLElement).style.textAlign) + assertEquals("right", (root.children[1] as HTMLElement).style.textAlign) + assertEquals("center", (root.children[2] as HTMLElement).style.textAlign) + assertEquals("justify", (root.children[3] as HTMLElement).style.textAlign) + assertEquals("start", (root.children[4] as HTMLElement).style.textAlign) + assertEquals("end", (root.children[5] as HTMLElement).style.textAlign) + } + } \ No newline at end of file