kotlin - 在 Kotlin React 应用程序中导入外部 css

标签 kotlin kotlin-js kotlin-frontend

我想在我的 Kotlin-React 应用程序中使用类似 bootstrap/material 的 css 库。有没有办法导入这些外部 css 库?有一个Kotlin-Styled包装器,但不确定如何使用它来导入 css。

最佳答案

如何导入一段外部 CSS 不是直接的答案,但让我向您展示我如何成功使用 Material UI带有 Kotlin 和 React 的库。这是该项目的演示:https://krzema12.github.io/fsynth/

请参阅 Material UI 组件的 Kotlin 类型示例:

@file:JsModule("@material-ui/core/ListItem")

package it.krzeminski.fsynth.typings.materialui.widgets

import react.RProps
import react.RState
import react.ReactElement

@JsName("default")
external class ListItem : react.Component<RProps, RState> {
    override fun render(): ReactElement?
}

(来源:https://github.com/krzema12/fsynth/blob/master/web/src/main/kotlin/it/krzeminski/fsynth/typings/materialui/widgets/ListItem.kt)

和一个方便的包装器:
fun RBuilder.materialListItem(handler: RHandler<RProps>) = child(ListItem::class) {
    handler()
}

(来源:https://github.com/krzema12/fsynth/blob/master/web/src/main/kotlin/it/krzeminski/fsynth/typings/MaterialUiBuilders.kt#L42)

然后我可以通过以下方式使用这个组件:
materialListItem {
...children...
}

(来源:https://github.com/krzema12/fsynth/blob/master/web/src/main/kotlin/it/krzeminski/fsynth/App.kt)

据我了解this docs page of Material UI ,它可以工作并且足够了,因为 CSS 嵌入在 JavaScript 中。

关于kotlin - 在 Kotlin React 应用程序中导入外部 css,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52904255/

相关文章:

android - Fragment 与 Fragment(或 Activity)之间的监听器

kotlin - List <List <Char >> + List <Char> = List <任何>?

typescript - Uncaught ReferenceError : firebase is not defined in Kotlin/JS project with Dukat generated declarations

reactjs - Kotlin JS 中的单元测试

html - Kotlin Javascript : Assigning to element property inside event handler gives "Expected a value of type dynamic"

gradle - 使用 gradle 创建 Kotlin React 应用程序

android - 输入字符串错误 : "sayısı 0x7f070042" Android Studio

kotlin - Kotlin中的引用平等