A first static page with React
step 1: yarn add @jetbrains/kotlin-css @jetbrains/kotlin-css-js @jetbrains/kotlin-styled inline-style-prefixer styled-components@4
step 2: import kotlinx.css.* import styled.*
example:
styledDiv {
css {
position = Position.absolute
top = 10.px
right = 10.px
}
h3 {
+"John Doe: Building and breaking things"
}
img {
attrs {
src = "https://via.placeholder.com/640x360.png?text=Video+Player+Placeholder"
}
}
}
Making It React: Our first Component
fun RBuilder.videoList(handler: VideoListProps.() -> Unit): ReactElement {
return child(VideoList::class) {
this.attrs(handler)
}
}
interface VideoListState: RState {
var selectedVideo: Video?
}
class VideoList(props: VideoListProps) : RComponent<VideoListProps, VideoListState>(props) {
override fun RBuilder.render() {
for (video in props.videos) {
p {
key = video.id.toString()
attrs {
onClickFunction = {
setState {
selectedVideo = video
}
}
}
if(video == state.selectedVideo) {
+"▶ "
}
+"${video.speaker}: ${video.title}"
}
}
}
}
Working together: Composing components
yarn add react-player
yarn add react-share
yarn add kotlinx-coroutines-core