Skip to content

Commit

Permalink
Sync Orientation generating
Browse files Browse the repository at this point in the history
  • Loading branch information
aerialist7 committed Jan 21, 2024
1 parent 67ecd95 commit 7f9545a
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 26 deletions.
21 changes: 16 additions & 5 deletions buildSrc/src/main/kotlin/karakum/mui/Generator.kt
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,12 @@ typealias ShapeOptions = Shape
""".trimIndent()

private val MATERIAL_PALETTE_MODE = convertUnion("PaletteMode = 'light' | 'dark'")!!
private val BASE_ORIENTATION = convertUnion("Orientation = 'horizontal' | 'vertical'")!!

// language=kotlin
private val MATERIAL_ORIENTATION = """
typealias Orientation = mui.base.Orientation
""".trimIndent()

// language=kotlin
private val STYLE_TRANSITION_CREATE_OPTIONS = """
Expand Down Expand Up @@ -327,6 +333,13 @@ private fun generateBaseDeclarations(
}
}
.forEach { generate(it, targetDir, Package.base) }

sequenceOf(
"Orientation" to BASE_ORIENTATION,
).forEach { (name, body) ->
targetDir.resolve("$name.kt")
.writeText(fileContent("", body, Package.base))
}
}

private fun generateSystemDeclarations(
Expand Down Expand Up @@ -414,6 +427,7 @@ private fun generateMaterialDeclarations(
MUI to MUI_BODY,
"PaletteMode" to MATERIAL_PALETTE_MODE,
"Size" to MATERIAL_SIZE,
"Orientation" to MATERIAL_ORIENTATION,
).forEach { (name, body) ->
val annotations = if (name == MUI) {
"@file:Suppress(\n\"NESTED_CLASS_IN_EXTERNAL_INTERFACE\",\n\"NAME_CONTAINS_ILLEGAL_CHARS\",)"
Expand Down Expand Up @@ -670,11 +684,8 @@ private fun generate(
.writeText(fileContent(annotations.joinToString("\n\n"), finalBody, pkg))
}

if (extensions.isNotEmpty()) {
val fileName = when (componentName) {
"Stepper" -> "Orientation"
else -> "$componentName.ext"
}
if (extensions.isNotEmpty() && componentName != "Stepper") {
val fileName = "$componentName.ext"

val extensionsAnnotations = if ("inline fun " in extensions) {
"@file:Suppress(\n" +
Expand Down
4 changes: 2 additions & 2 deletions buildSrc/src/main/kotlin/karakum/mui/KotlinType.kt
Original file line number Diff line number Diff line change
Expand Up @@ -216,8 +216,8 @@ private val STANDARD_TYPE_MAP = mapOf(
SWIPEABLE_DRAWER_PROPS_ALLOW_SWIPE_IN_CHILDREN to "Boolean /* or (e: TouchEvent, swipeArea: HTMLDivElement, paper: HTMLDivElement) -> Boolean*/",
USE_TAB_PANEL_RETURN_VALUE_GET_ROOT_PROPS to "() -> UseTabPanelRootSlotProps",

"'horizontal' | 'vertical'" to "mui.material.Orientation",
"'vertical' | 'horizontal'" to "mui.material.Orientation",
"'horizontal' | 'vertical'" to "Orientation",
"'vertical' | 'horizontal'" to "Orientation",

"typeof window.matchMedia" to "(query: String) -> web.cssom.MediaQueryList",

Expand Down
20 changes: 20 additions & 0 deletions mui-kotlin/src/jsMain/kotlin/mui/base/Orientation.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Automatically generated - do not modify!

package mui.base

import seskar.js.JsValue
import seskar.js.JsVirtual

@Suppress(
"NESTED_CLASS_IN_EXTERNAL_INTERFACE",
)
@JsVirtual
sealed external interface Orientation {
companion object {
@JsValue("horizontal")
val horizontal: Orientation

@JsValue("vertical")
val vertical: Orientation
}
}
2 changes: 1 addition & 1 deletion mui-kotlin/src/jsMain/kotlin/mui/base/useSlider.types.kt
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ external interface UseSliderParameters {
* The component orientation.
* @default 'horizontal'
*/
var orientation: mui.material.Orientation?
var orientation: Orientation?

/**
* The ref attached to the root of the Slider.
Expand Down
2 changes: 1 addition & 1 deletion mui-kotlin/src/jsMain/kotlin/mui/base/useTabs.types.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ external interface UseTabsParameters {
* The component orientation (layout flow direction).
* @default 'horizontal'
*/
var orientation: mui.material.Orientation?
var orientation: Orientation?

/**
* The direction of the text.
Expand Down
2 changes: 1 addition & 1 deletion mui-kotlin/src/jsMain/kotlin/mui/base/useTabsList.types.kt
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ external interface UseTabsListReturnValue {
/**
* The component orientation (layout flow direction).
*/
var orientation: mui.material.Orientation
var orientation: Orientation

var rootRef: react.RefCallback<web.dom.Element>?

Expand Down
17 changes: 1 addition & 16 deletions mui-kotlin/src/jsMain/kotlin/mui/material/Orientation.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,4 @@

package mui.material

import seskar.js.JsValue
import seskar.js.JsVirtual

@Suppress(
"NESTED_CLASS_IN_EXTERNAL_INTERFACE",
)
@JsVirtual
sealed external interface Orientation {
companion object {
@JsValue("horizontal")
val horizontal: Orientation

@JsValue("vertical")
val vertical: Orientation
}
}
typealias Orientation = mui.base.Orientation

0 comments on commit 7f9545a

Please sign in to comment.