mirror of
https://github.com/InsanusMokrassar/JSUIKitKBindings.git
synced 2024-11-26 20:18:49 +00:00
commit
f1dedf1e09
@ -1,5 +1,10 @@
|
||||
# Changelog
|
||||
|
||||
## 0.0.19
|
||||
|
||||
* Create `Card`s implementation
|
||||
* Upgrade `Label` composable draw and create `UIKitLabel` modifiers
|
||||
|
||||
## 0.0.18
|
||||
|
||||
* Add base companion for `UIKitFlex` with result class `uk-flex`
|
||||
|
@ -9,4 +9,4 @@ android.enableJetifier=true
|
||||
# Project data
|
||||
|
||||
group=dev.inmo
|
||||
version=0.0.18
|
||||
version=0.0.19
|
||||
|
79
src/jsMain/kotlin/dev/inmo/jsuikit/elements/Card.kt
Normal file
79
src/jsMain/kotlin/dev/inmo/jsuikit/elements/Card.kt
Normal file
@ -0,0 +1,79 @@
|
||||
package dev.inmo.jsuikit.elements
|
||||
|
||||
import androidx.compose.runtime.Composable
|
||||
import dev.inmo.jsuikit.modifiers.*
|
||||
import dev.inmo.jsuikit.utils.Attrs
|
||||
import org.jetbrains.compose.web.dom.*
|
||||
import org.w3c.dom.*
|
||||
|
||||
@Composable
|
||||
fun Card(
|
||||
cardAttrs: Attrs<HTMLDivElement> = Attrs.empty(),
|
||||
headerAttrs: Attrs<HTMLDivElement> = Attrs.empty(),
|
||||
header: ContentBuilder<HTMLDivElement>? = null,
|
||||
footerAttrs: Attrs<HTMLDivElement> = Attrs.empty(),
|
||||
footer: ContentBuilder<HTMLDivElement>? = null,
|
||||
bodyAttrs: Attrs<HTMLDivElement> = Attrs.empty(),
|
||||
body: ContentBuilder<HTMLDivElement>
|
||||
) {
|
||||
Div(
|
||||
{
|
||||
include(UIKitCard)
|
||||
cardAttrs.builder(this)
|
||||
}
|
||||
) {
|
||||
header ?.let {
|
||||
Div(
|
||||
{
|
||||
include(UIKitCard.Parts.Header)
|
||||
headerAttrs.builder(this)
|
||||
},
|
||||
header
|
||||
)
|
||||
}
|
||||
Div(
|
||||
{
|
||||
include(UIKitCard.Parts.Body)
|
||||
bodyAttrs.builder(this)
|
||||
},
|
||||
body
|
||||
)
|
||||
footer ?.let {
|
||||
Div(
|
||||
{
|
||||
include(UIKitCard.Parts.Footer)
|
||||
footerAttrs.builder(this)
|
||||
},
|
||||
footer
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun CardTitle(
|
||||
titleAttrs: Attrs<HTMLHeadingElement> = Attrs.empty(),
|
||||
title: ContentBuilder<HTMLHeadingElement>
|
||||
) {
|
||||
H3(
|
||||
{
|
||||
include(UIKitCard.Title)
|
||||
titleAttrs.builder(this)
|
||||
},
|
||||
title
|
||||
)
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun CardBadge(
|
||||
badgeAttrs: Attrs<HTMLDivElement> = Attrs.empty(),
|
||||
badge: ContentBuilder<HTMLDivElement>
|
||||
) {
|
||||
Div(
|
||||
{
|
||||
include(UIKitCard.Badge, UIKitLabel)
|
||||
badgeAttrs.builder(this)
|
||||
},
|
||||
badge
|
||||
)
|
||||
}
|
@ -1,41 +1,20 @@
|
||||
package dev.inmo.jsuikit.elements
|
||||
|
||||
import androidx.compose.runtime.Composable
|
||||
import dev.inmo.jsuikit.modifiers.UIKitModifier
|
||||
import dev.inmo.jsuikit.modifiers.include
|
||||
import dev.inmo.jsuikit.modifiers.*
|
||||
import dev.inmo.jsuikit.utils.Attrs
|
||||
import org.jetbrains.compose.web.dom.*
|
||||
import org.w3c.dom.HTMLSpanElement
|
||||
|
||||
sealed interface Label {
|
||||
val suffix: String
|
||||
|
||||
@Composable
|
||||
fun draw(
|
||||
@Composable
|
||||
fun Label(
|
||||
text: String,
|
||||
vararg modifiers: UIKitModifier,
|
||||
attributesCustomizer: AttrBuilderContext<HTMLSpanElement> = {},
|
||||
) = Span(
|
||||
attrs: Attrs<HTMLSpanElement>
|
||||
) = Span(
|
||||
{
|
||||
classes("uk-label", "uk-label-$suffix")
|
||||
include(*modifiers)
|
||||
attributesCustomizer()
|
||||
include(UIKitLabel)
|
||||
attrs.builder(this)
|
||||
}
|
||||
) {
|
||||
) {
|
||||
Text(text)
|
||||
}
|
||||
|
||||
object Success : Label {
|
||||
override val suffix: String
|
||||
get() = "success"
|
||||
}
|
||||
|
||||
object Warning : Label {
|
||||
override val suffix: String
|
||||
get() = "warning"
|
||||
}
|
||||
|
||||
object Error : Label {
|
||||
override val suffix: String
|
||||
get() = "danger"
|
||||
}
|
||||
}
|
||||
|
35
src/jsMain/kotlin/dev/inmo/jsuikit/modifiers/UIKitCard.kt
Normal file
35
src/jsMain/kotlin/dev/inmo/jsuikit/modifiers/UIKitCard.kt
Normal file
@ -0,0 +1,35 @@
|
||||
package dev.inmo.jsuikit.modifiers
|
||||
|
||||
sealed class UIKitCard(suffix: String?) : UIKitModifier {
|
||||
override val classes: Array<String> = arrayOf("uk-card${suffix ?.let { "-$it" } ?: ""}")
|
||||
|
||||
object Title : UIKitCard("title")
|
||||
object Hover : UIKitCard("hover")
|
||||
object Badge : Parts("badge")
|
||||
|
||||
sealed class Parts(suffix: String) : UIKitCard(suffix) {
|
||||
object Header : Parts("header")
|
||||
object Body : Parts("body")
|
||||
object Footer : Parts("footer")
|
||||
}
|
||||
|
||||
sealed class Style(suffix: String) : UIKitCard(suffix) {
|
||||
object Default : Style("default")
|
||||
object Primary : Style("primary")
|
||||
object Secondary : Style("secondary")
|
||||
}
|
||||
|
||||
sealed class Size(suffix: String) : UIKitCard(suffix) {
|
||||
object Small : Size("small")
|
||||
object Large : Size("large")
|
||||
}
|
||||
|
||||
sealed class Media(suffix: String) : UIKitCard("media-$suffix") {
|
||||
object Top : Media("top")
|
||||
object Right : Media("right")
|
||||
object Bottom : Media("bottom")
|
||||
object Left : Media("left")
|
||||
}
|
||||
|
||||
companion object : UIKitCard(null)
|
||||
}
|
11
src/jsMain/kotlin/dev/inmo/jsuikit/modifiers/UIKitLabel.kt
Normal file
11
src/jsMain/kotlin/dev/inmo/jsuikit/modifiers/UIKitLabel.kt
Normal file
@ -0,0 +1,11 @@
|
||||
package dev.inmo.jsuikit.modifiers
|
||||
|
||||
sealed class UIKitLabel(suffix: String?) : UIKitModifier {
|
||||
override val classes: Array<String> = arrayOf("uk-label${suffix?.let { "-$it" } ?: ""}")
|
||||
|
||||
object Success : UIKitLabel("success")
|
||||
object Warning : UIKitLabel("warning")
|
||||
object Error : UIKitLabel("danger")
|
||||
|
||||
companion object : UIKitLabel(null)
|
||||
}
|
@ -0,0 +1,26 @@
|
||||
package dev.inmo.jsuikit.utils
|
||||
|
||||
import dev.inmo.jsuikit.modifiers.UIKitModifier
|
||||
import dev.inmo.jsuikit.modifiers.include
|
||||
import org.jetbrains.compose.web.attributes.AttrsBuilder
|
||||
import org.jetbrains.compose.web.dom.AttrBuilderContext
|
||||
import org.w3c.dom.Element
|
||||
|
||||
class AttributesCollection<T : Element> (
|
||||
private vararg val modifiers: UIKitModifier,
|
||||
private val attrs: AttrBuilderContext<T> = {}
|
||||
) {
|
||||
val builder: AttrBuilderContext<T> = {
|
||||
include(*modifiers)
|
||||
attrs()
|
||||
}
|
||||
|
||||
companion object {
|
||||
val Empty = Attrs<Element>()
|
||||
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
fun <T : Element> empty() = Empty as Attrs<T>
|
||||
}
|
||||
}
|
||||
|
||||
typealias Attrs<T> = AttributesCollection<T>
|
Loading…
Reference in New Issue
Block a user