Skip to content

Commit

Permalink
React. Use ToggleState type for ToggleEvent members
Browse files Browse the repository at this point in the history
  • Loading branch information
porotkin committed Dec 26, 2024
1 parent 20efe34 commit 2e442a2
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 2 deletions.
1 change: 1 addition & 0 deletions buildSrc/src/main/kotlin/karakum/react/Converter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ internal fun convertDefinitions(
.plus(convertNativeEvents(content))
.plus(convertEventHandlers(reactContent))
.plus(FormAction())
.plus(ToggleState())
}

private val EXCLUDED_UNIONS = setOf(
Expand Down
7 changes: 5 additions & 2 deletions buildSrc/src/main/kotlin/karakum/react/EventConverter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,6 @@ internal fun convertEventHandlers(
}

private const val DEFAULT_EVENT_IMPORTS = """
import react.dom.html.OldState
import react.dom.html.NewState
import web.dom.Element
import web.window.Window
import web.events.Event
Expand Down Expand Up @@ -98,6 +96,11 @@ internal fun convertEventInterface(
"BaseSyntheticEvent",
-> members = members
.replaceFirst("val type: String", "val type: EventType<E>")

"ToggleEvent",
-> members = members
.replaceFirst("val oldState: OldState", "val oldState: ToggleState")
.replaceFirst("val newState: NewState", "val newState: ToggleState")
}

val body = DEFAULT_EVENT_IMPORTS.removePrefix("\n") +
Expand Down
2 changes: 2 additions & 0 deletions buildSrc/src/main/kotlin/karakum/react/Generator.kt
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ private val EXCLUDED_TYPES = setOf(
"AutoFillAddressKind",
"HTMLElementType",
"SVGElementType",
"OldState",
"NewState",
)

fun generateKotlinDeclarations(
Expand Down
10 changes: 10 additions & 0 deletions buildSrc/src/main/kotlin/karakum/react/ToggleState.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package karakum.react

internal const val TOGGLE_STATE = "ToggleState"

internal fun ToggleState(): ConversionResult =
ConversionResult(
name = TOGGLE_STATE,
body = "typealias ToggleState = String /* 'open' | 'closed' */",
pkg = Package.EVENTS,
)

0 comments on commit 2e442a2

Please sign in to comment.