I'm trying to use this lib in my create-react-kotlin-app:
I want to generate bunch of type safe wrappers. I started like this:
@file:JsModule("material-ui")
package material
import react.RState
import react.React
import react.ReactElement
external class Typography : React.Component<dynamic, RState> {
override fun render(): ReactElement
}
...
fun RBuilder.typography(
classes: String = "",
variant: Variant = Variant.body1,
align: Align = Align.inherit,
color: Color = Color.default,
gutterBottom: Boolean = false,
noWrap: Boolean = false,
paragraph: Boolean = false,
handler: RHandler<dynamic>
) = child(Typography::class) {
attrs {
this.className = classes
this.align = align.name
this.color = color.name
this.variant = variant.name
this.gutterBottom = gutterBottom
this.noWrap = noWrap
this.paragraph = paragraph
}
handler()
}
And use it like:
typography(variant = Variant.title, color = Color.inherit) {
+"Hello World"
}
Is it correct approach?
Indeed that is the correct way but can make it to be the best as follows
MaterialUi.kt
And then create another file, say
MaterialUiDsl.kt
If the above file already seems verbose to you (Like how I often feel), you can change it to just
MaterialUiDsl.kt
The you can use it whenever like this
Easy peasy