Merge pull request #30 from InsanusMokrassar/0.0.30

0.0.30
This commit is contained in:
InsanusMokrassar 2022-01-28 14:01:31 +06:00 committed by GitHub
commit 36ab3fe52e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 170 additions and 3 deletions

View File

@ -1,5 +1,11 @@
# Changelog
## 0.0.30
* Add `UIKitComment`
* Including of `Comment` element
* Upfill `UIKitSubNav`
## 0.0.29
* Unfilling of `UIKitText`

View File

@ -9,4 +9,4 @@ android.enableJetifier=true
# Project data
group=dev.inmo
version=0.0.29
version=0.0.30

View 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
)
}

View 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)
}

View File

@ -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
}
}

View 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")
}

View 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
}

View 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()
}
}