mirror of
https://github.com/InsanusMokrassar/JSUIKitKBindings.git
synced 2024-12-28 03:27:15 +00:00
add UIKitComment, Comment element, upfill UIKitSubNav
This commit is contained in:
parent
7edea7bf74
commit
029a7804ad
@ -2,6 +2,10 @@
|
||||
|
||||
## 0.0.30
|
||||
|
||||
* Add `UIKitComment`
|
||||
* Including of `Comment` element
|
||||
* Upfill `UIKitSubNav`
|
||||
|
||||
## 0.0.29
|
||||
|
||||
* Unfilling of `UIKitText`
|
||||
|
106
src/jsMain/kotlin/dev/inmo/jsuikit/elements/Comment.kt
Normal file
106
src/jsMain/kotlin/dev/inmo/jsuikit/elements/Comment.kt
Normal file
@ -0,0 +1,106 @@
|
||||
package dev.inmo.jsuikit.elements
|
||||
|
||||
import androidx.compose.runtime.Composable
|
||||
import dev.inmo.jsuikit.modifiers.*
|
||||
import dev.inmo.jsuikit.utils.*
|
||||
import org.jetbrains.compose.web.dom.*
|
||||
import org.w3c.dom.*
|
||||
|
||||
@Composable
|
||||
fun Comment(
|
||||
rootAttrs: Attrs<HTMLElement> = Attrs.empty(),
|
||||
headerAttrs: Attrs<HTMLElement>? = null,
|
||||
headerContent: ContentBuilder<HTMLElement>? = null,
|
||||
bodyAttrs: Attrs<HTMLDivElement>? = null,
|
||||
bodyContent: ContentBuilder<HTMLDivElement>? = null,
|
||||
) {
|
||||
Article(
|
||||
{
|
||||
include(UIKitComment)
|
||||
rootAttrs.builder(this)
|
||||
}
|
||||
) {
|
||||
if (headerAttrs != null || headerContent != null) {
|
||||
Header (
|
||||
{
|
||||
include(UIKitComment.Header)
|
||||
headerAttrs ?.builder ?.invoke(this)
|
||||
}
|
||||
) {
|
||||
headerContent ?.let { it(this) }
|
||||
}
|
||||
}
|
||||
if (bodyAttrs != null || bodyContent != null) {
|
||||
Div(
|
||||
{
|
||||
include(UIKitComment.Body)
|
||||
bodyAttrs ?.builder ?.invoke(this)
|
||||
}
|
||||
) {
|
||||
bodyContent ?.let { it(this) }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun DefaultComment(
|
||||
headerGridAttrs: Attrs<HTMLDivElement>? = null,
|
||||
avatarUrl: String? = null,
|
||||
avatarAttrs: Attrs<HTMLImageElement>? = null,
|
||||
titleAttrs: Attrs<HTMLHeadingElement>? = null,
|
||||
titleContent: ContentBuilder<HTMLHeadingElement>? = null,
|
||||
metaAttrs: Attrs<HTMLUListElement>? = null,
|
||||
metaContent: ContentBuilder<HTMLUListElement>? = null,
|
||||
rootAttrs: Attrs<HTMLElement> = Attrs.empty(),
|
||||
headerAttrs: Attrs<HTMLElement>? = null,
|
||||
additionalHeaderContent: ContentBuilder<HTMLElement>? = null,
|
||||
bodyAttrs: Attrs<HTMLDivElement>? = null,
|
||||
bodyContent: ContentBuilder<HTMLDivElement>? = null,
|
||||
) {
|
||||
Comment(
|
||||
rootAttrs = rootAttrs,
|
||||
headerAttrs = headerAttrs,
|
||||
headerContent = {
|
||||
if (arrayOf(headerGridAttrs, avatarUrl, avatarAttrs, titleAttrs, titleContent, metaAttrs, metaContent).anyNotNull()) {
|
||||
Grid(
|
||||
UIKitGrid.Gap.Medium, UIKitFlex.Alignment.Vertical.Middle,
|
||||
attributesCustomizer = headerGridAttrs ?.builder ?: {}
|
||||
) {
|
||||
if (avatarUrl != null) {
|
||||
Div({ include(UIKitWidth.Auto) }) {
|
||||
Img(avatarUrl, attrs = avatarAttrs ?.builder)
|
||||
}
|
||||
}
|
||||
if (arrayOf(titleAttrs, titleContent, metaAttrs, metaContent).anyNotNull()) {
|
||||
Div({ include(UIKitWidth.Expand) }) {
|
||||
optionallyDraw(titleAttrs, titleContent) {
|
||||
H4(
|
||||
{
|
||||
include(UIKitComment.Title, UIKitMargin.Remove)
|
||||
titleAttrs ?.builder ?.invoke(this)
|
||||
}
|
||||
) {
|
||||
titleContent ?.invoke(this)
|
||||
}
|
||||
}
|
||||
optionallyDraw(metaAttrs, metaContent) {
|
||||
Ul (
|
||||
{
|
||||
include(UIKitComment.Meta, UIKitSubNav, UIKitSubNav.Divider, UIKitMargin.Remove.Top)
|
||||
metaAttrs ?.builder ?.invoke(this)
|
||||
}
|
||||
) {
|
||||
metaContent ?.invoke(this)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
additionalHeaderContent ?.let { it(this) }
|
||||
},
|
||||
bodyAttrs = bodyAttrs,
|
||||
bodyContent = bodyContent
|
||||
)
|
||||
}
|
17
src/jsMain/kotlin/dev/inmo/jsuikit/modifiers/UIKitComment.kt
Normal file
17
src/jsMain/kotlin/dev/inmo/jsuikit/modifiers/UIKitComment.kt
Normal file
@ -0,0 +1,17 @@
|
||||
package dev.inmo.jsuikit.modifiers
|
||||
|
||||
sealed class UIKitComment(suffix: String?) : UIKitModifier {
|
||||
override val classes: Array<String> = arrayOf("uk-comment${suffix ?.let { "-$it" } ?: ""}")
|
||||
|
||||
object Body : UIKitComment("body")
|
||||
object Header : UIKitComment("header")
|
||||
object Title : UIKitComment("title")
|
||||
object Meta : UIKitComment("meta")
|
||||
object Avatar : UIKitComment("avatar")
|
||||
|
||||
object Primary : UIKitComment("primary")
|
||||
|
||||
object List : UIKitComment("list")
|
||||
|
||||
companion object : UIKitComment(null)
|
||||
}
|
@ -4,7 +4,6 @@ sealed class UIKitNav(classname: String) : UIKitModifier {
|
||||
override val classes: Array<String> = arrayOf(classname)
|
||||
|
||||
object ParentIcon : UIKitNav("uk-nav-parent-icon")
|
||||
object SubNav : UIKitNav("uk-nav-sub")
|
||||
|
||||
object Header : UIKitNav("uk-nav-header")
|
||||
object Divider : UIKitNav("uk-nav-divider")
|
||||
@ -15,5 +14,7 @@ sealed class UIKitNav(classname: String) : UIKitModifier {
|
||||
|
||||
object Center : UIKitNav("uk-nav-center")
|
||||
|
||||
companion object : UIKitNav("uk-nav")
|
||||
companion object : UIKitNav("uk-nav") {
|
||||
val SubNav = UIKitSubNav
|
||||
}
|
||||
}
|
||||
|
10
src/jsMain/kotlin/dev/inmo/jsuikit/modifiers/UIKitSubNav.kt
Normal file
10
src/jsMain/kotlin/dev/inmo/jsuikit/modifiers/UIKitSubNav.kt
Normal file
@ -0,0 +1,10 @@
|
||||
package dev.inmo.jsuikit.modifiers
|
||||
|
||||
sealed class UIKitSubNav(classname: String) : UIKitModifier {
|
||||
override val classes: Array<String> = arrayOf(classname)
|
||||
|
||||
object Divider : UIKitSubNav("uk-subnav-divider")
|
||||
object Pill : UIKitSubNav("uk-subnav-pill")
|
||||
|
||||
companion object : UIKitSubNav("uk-subnav")
|
||||
}
|
11
src/jsMain/kotlin/dev/inmo/jsuikit/utils/AnyNotNull.kt
Normal file
11
src/jsMain/kotlin/dev/inmo/jsuikit/utils/AnyNotNull.kt
Normal file
@ -0,0 +1,11 @@
|
||||
package dev.inmo.jsuikit.utils
|
||||
|
||||
fun <T> Array<T>.anyNotNull(): Boolean {
|
||||
for (item in this) {
|
||||
if (item != null) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
16
src/jsMain/kotlin/dev/inmo/jsuikit/utils/OptionallyDraw.kt
Normal file
16
src/jsMain/kotlin/dev/inmo/jsuikit/utils/OptionallyDraw.kt
Normal file
@ -0,0 +1,16 @@
|
||||
package dev.inmo.jsuikit.utils
|
||||
|
||||
import androidx.compose.runtime.Composable
|
||||
import org.jetbrains.compose.web.dom.ContentBuilder
|
||||
import org.w3c.dom.Element
|
||||
|
||||
@Composable
|
||||
inline fun <T : Element> optionallyDraw (
|
||||
attrs: Attrs<T>? = null,
|
||||
noinline contentBuilder: ContentBuilder<T>? = null,
|
||||
whatToDraw: @Composable () -> Unit
|
||||
) {
|
||||
if (attrs != null || contentBuilder != null) {
|
||||
whatToDraw()
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user