From 20ed66298803894859336cd3c2d2e3b6f6322ddc Mon Sep 17 00:00:00 2001 From: apolostudio Date: Wed, 4 Dec 2024 16:58:46 +0100 Subject: [PATCH] Adds experimental PointerIcon.fromKeyword function to change the browser cursor in Web source set (#1704) Adds remaining cursors pointer icons in Web source set which are available in https://developer.mozilla.org/en-US/docs/Web/CSS/cursor Note that not all of the cursors are available in all browsers and OS's but they default to default one if not available If you were planning a different approach, i'm open to feedback Fixes [https://youtrack.jetbrains.com/issue/CMP-6951/Consider-making-BrowserCursor-dataclass-public-or-add-more-PointerIcons-to-WasmJs-target](https://youtrack.jetbrains.com/issue/CMP-6951/Consider-making-BrowserCursor-dataclass-public-or-add-more-PointerIcons-to-WasmJs-target) ## Release Notes ### Features - Web - Adds experimental PointerIcon.fromKeyword function to change the browser cursor --------- Signed-off-by: Apolo Studio --- .../compose/ui/input/pointer/PointerIcon.js.kt | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/compose/ui/ui/src/jsWasmMain/kotlin/androidx/compose/ui/input/pointer/PointerIcon.js.kt b/compose/ui/ui/src/jsWasmMain/kotlin/androidx/compose/ui/input/pointer/PointerIcon.js.kt index c3c9170dddd78..b9ba7f8dfeb0e 100644 --- a/compose/ui/ui/src/jsWasmMain/kotlin/androidx/compose/ui/input/pointer/PointerIcon.js.kt +++ b/compose/ui/ui/src/jsWasmMain/kotlin/androidx/compose/ui/input/pointer/PointerIcon.js.kt @@ -16,10 +16,22 @@ package androidx.compose.ui.input.pointer +import androidx.compose.ui.ExperimentalComposeUiApi + object DummyPointerIcon : PointerIcon internal data class BrowserCursor(val id: String): PointerIcon +/** + * Creates [PointerIcon] from provided cursor keyword. + * @param keyword one of the values representing the cursor appearance in a browser. + * @see https://developer.mozilla.org/en-US/docs/Web/CSS/cursor + */ +@ExperimentalComposeUiApi +fun PointerIcon.Companion.fromKeyword(keyword: String): PointerIcon { + return BrowserCursor(keyword) +} + internal actual val pointerIconDefault: PointerIcon = BrowserCursor("default") internal actual val pointerIconCrosshair: PointerIcon = BrowserCursor("crosshair") internal actual val pointerIconText: PointerIcon = BrowserCursor("text")