Compare commits

...

22 Commits

Author SHA1 Message Date
e6ebc70578 Merge pull request #73 from InsanusMokrassar/0.4.2
0.4.2
2022-12-18 10:10:57 +06:00
0eba5d10f7 Update CHANGELOG.md 2022-12-18 10:07:51 +06:00
ffb7f41328 Update libs.versions.toml 2022-12-18 10:07:07 +06:00
77dabb5553 0.4.2 2022-12-18 10:06:45 +06:00
8c086eb3eb Merge pull request #71 from InsanusMokrassar/0.4.1
0.4.1
2022-11-16 00:57:42 +06:00
0d55505e09 fill changelog 2022-11-16 00:57:11 +06:00
eefdb5fda1 list may accept any iterable 2022-11-16 00:45:10 +06:00
0c281aa653 fixes for build 2022-11-16 00:17:03 +06:00
17ae0b119b StandardInput improvements 2022-11-15 21:50:15 +06:00
36214aeba5 start 0.4.1 2022-11-15 21:46:29 +06:00
19f3a59a79 Merge pull request #70 from InsanusMokrassar/0.4.0
0.4.0
2022-11-08 07:56:31 +06:00
5cfee9c4cc Update CHANGELOG.md 2022-11-08 07:54:53 +06:00
c9a17fa92a Update gradle-wrapper.properties 2022-11-08 07:53:42 +06:00
c36e8c58f4 Update libs.versions.toml 2022-11-08 07:52:33 +06:00
67f083610a start 0.4.0 2022-11-08 07:51:48 +06:00
636280a982 Merge pull request #69 from InsanusMokrassar/0.3.0
0.3.0
2022-09-19 20:54:03 +06:00
415549b251 Update libs.versions.toml 2022-09-17 00:55:20 +06:00
0d2672b679 start 0.3.0 2022-09-17 00:53:59 +06:00
a511def014 Merge pull request #68 from InsanusMokrassar/0.2.2
0.2.2
2022-09-14 14:07:24 +06:00
d783834aa4 Drop component and Navbar improvements 2022-09-14 13:54:48 +06:00
cf2b823765 start 0.2.2 2022-09-14 13:01:31 +06:00
0f6e2c9805 Merge pull request #67 from InsanusMokrassar/0.2.1
0.2.1
2022-08-20 18:24:02 +06:00
12 changed files with 285 additions and 75 deletions

View File

@@ -1,5 +1,24 @@
# Changelog # Changelog
## 0.4.2
* `Compose`: `1.2.2`
## 0.4.1
* Now it is possible to use `StandardInput` with simple `T` types instead of states
* `List` may accept any `Iterable`
## 0.4.0
* `Kotlin`: `1.7.20`
* `Compose`: `1.2.1`
## 0.2.2
* Add support of `Drop` component
* Improve support of `Navbar`s
## 0.2.1 ## 0.2.1
* `Tab` elements become supported * `Tab` elements become supported

View File

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

View File

@@ -1,8 +1,8 @@
[versions] [versions]
kt = "1.7.0" kt = "1.7.20"
jb-compose = "1.2.0-alpha01-dev753" jb-compose = "1.2.2"
jb-dokka = "1.7.0" jb-dokka = "1.7.20"
gh-release = "2.4.1" gh-release = "2.4.1"
[libraries] [libraries]

View File

@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5-bin.zip distributionUrl=https\://services.gradle.org/distributions/gradle-7.5.1-bin.zip
zipStoreBase=GRADLE_USER_HOME zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists zipStorePath=wrapper/dists

View File

@@ -0,0 +1,24 @@
package dev.inmo.jsuikit.elements
import androidx.compose.runtime.Composable
import dev.inmo.jsuikit.modifiers.UIKitDrop
import dev.inmo.jsuikit.modifiers.attrsBuilder
import dev.inmo.jsuikit.utils.*
import org.jetbrains.compose.web.dom.Div
import org.w3c.dom.HTMLButtonElement
import org.w3c.dom.HTMLDivElement
@Composable
fun Drop(
buttonBuilder: AttrsWithContentBuilder<HTMLButtonElement>,
dropBuilder: AttrsWithContentBuilder<HTMLDivElement>
) {
DefaultButton(
attributesCustomizer = buttonBuilder.attributesBuilderContext,
contentAllocator = buttonBuilder.builder
)
Div(
(Attrs<HTMLDivElement>(UIKitDrop.Custom()) + dropBuilder.attrs).builder,
dropBuilder.builder
)
}

View File

@@ -202,8 +202,13 @@ sealed class Icon(val name: String) {
object Youtube : Brands("youtube") object Youtube : Brands("youtube")
} }
class Custom(name: String) : Icon(name)
companion object {
}
}
@Composable @Composable
operator fun invoke( operator fun Icon.invoke(
vararg modifiers: UIKitModifier, vararg modifiers: UIKitModifier,
type: UIKitIconType = UIKitIconType.Default, type: UIKitIconType = UIKitIconType.Default,
ratio: Float? = null, ratio: Float? = null,
@@ -225,10 +230,8 @@ sealed class Icon(val name: String) {
} }
} }
class Custom(name: String) : Icon(name)
@Composable @Composable
fun drawAsButton( fun Icon.drawAsButton(
vararg modifiers: UIKitModifier, vararg modifiers: UIKitModifier,
ratio: Float? = null, ratio: Float? = null,
attributesCustomizer: AttrBuilderContext<out HTMLElement> = {}, attributesCustomizer: AttrBuilderContext<out HTMLElement> = {},
@@ -236,7 +239,7 @@ sealed class Icon(val name: String) {
) = invoke(*modifiers, type = UIKitIconType.Button, ratio = ratio, onClick = onClick, attributesCustomizer = attributesCustomizer) ) = invoke(*modifiers, type = UIKitIconType.Button, ratio = ratio, onClick = onClick, attributesCustomizer = attributesCustomizer)
@Composable @Composable
fun drawAsIcon( fun Icon.drawAsIcon(
vararg modifiers: UIKitModifier, vararg modifiers: UIKitModifier,
ratio: Float? = null, ratio: Float? = null,
attributesCustomizer: AttrBuilderContext<out HTMLElement> = {}, attributesCustomizer: AttrBuilderContext<out HTMLElement> = {},
@@ -244,7 +247,7 @@ sealed class Icon(val name: String) {
) = invoke(*modifiers, type = UIKitIconType.Default, ratio = ratio, onClick = onClick, attributesCustomizer = attributesCustomizer) ) = invoke(*modifiers, type = UIKitIconType.Default, ratio = ratio, onClick = onClick, attributesCustomizer = attributesCustomizer)
@Composable @Composable
fun drawAsLink( fun Icon.drawAsLink(
vararg modifiers: UIKitModifier, vararg modifiers: UIKitModifier,
ratio: Float? = null, ratio: Float? = null,
attributesCustomizer: AttrBuilderContext<out HTMLElement> = {}, attributesCustomizer: AttrBuilderContext<out HTMLElement> = {},
@@ -252,10 +255,9 @@ sealed class Icon(val name: String) {
) = invoke(*modifiers, type = UIKitIconType.Link, ratio = ratio, onClick = onClick, attributesCustomizer = attributesCustomizer) ) = invoke(*modifiers, type = UIKitIconType.Link, ratio = ratio, onClick = onClick, attributesCustomizer = attributesCustomizer)
@Composable @Composable
fun drawAsFormInputPart( fun Icon.drawAsFormInputPart(
vararg modifiers: UIKitModifier, vararg modifiers: UIKitModifier,
ratio: Float? = null, ratio: Float? = null,
attributesCustomizer: AttrBuilderContext<out HTMLElement> = {}, attributesCustomizer: AttrBuilderContext<out HTMLElement> = {},
onClick: ((Event) -> Unit)? = null onClick: ((Event) -> Unit)? = null
) = invoke(*modifiers, UIKitForm.Icon, ratio = ratio, onClick = onClick, attributesCustomizer = attributesCustomizer) ) = invoke(*modifiers, UIKitForm.Icon, ratio = ratio, onClick = onClick, attributesCustomizer = attributesCustomizer)
}

View File

@@ -10,7 +10,7 @@ import org.w3c.dom.HTMLLIElement
import org.w3c.dom.HTMLUListElement import org.w3c.dom.HTMLUListElement
@Composable @Composable
fun <T> Iconnav( fun <T> IconNav(
data: Iterable<T>, data: Iterable<T>,
listAttrs: Attrs<HTMLUListElement> = Attrs.empty(), listAttrs: Attrs<HTMLUListElement> = Attrs.empty(),
elementAttrsBuilder: AttrsScope<HTMLLIElement>.(T) -> Unit = {}, elementAttrsBuilder: AttrsScope<HTMLLIElement>.(T) -> Unit = {},
@@ -31,3 +31,11 @@ fun <T> Iconnav(
} }
} }
} }
@Composable
fun <T> Iconnav(
data: Iterable<T>,
listAttrs: Attrs<HTMLUListElement> = Attrs.empty(),
elementAttrsBuilder: AttrsScope<HTMLLIElement>.(T) -> Unit = {},
elementBuilder: @Composable ElementScope<HTMLLIElement>.(T) -> Unit
) = IconNav(data, listAttrs, elementAttrsBuilder, elementBuilder)

View File

@@ -10,7 +10,7 @@ import org.w3c.dom.HTMLUListElement
@Composable @Composable
fun <T> List( fun <T> List(
data: SnapshotStateList<T>, data: Iterable<T>,
ukAttrs: Attrs<HTMLUListElement> = Attrs.empty(), ukAttrs: Attrs<HTMLUListElement> = Attrs.empty(),
elementAllocator: @Composable ElementScope<HTMLUListElement>.(T) -> Unit elementAllocator: @Composable ElementScope<HTMLUListElement>.(T) -> Unit
) { ) {
@@ -29,7 +29,7 @@ fun <T> List(
@Composable @Composable
fun <T> ListWithTitle( fun <T> ListWithTitle(
title: String, title: String,
data: SnapshotStateList<T>, data: Iterable<T>,
vararg titleModifiers: UIKitModifier, vararg titleModifiers: UIKitModifier,
ulModifiers: Array<UIKitModifier> = emptyArray(), ulModifiers: Array<UIKitModifier> = emptyArray(),
besidesTitleAndList: (@Composable () -> Unit)? = null, besidesTitleAndList: (@Composable () -> Unit)? = null,

View File

@@ -5,8 +5,7 @@ import dev.inmo.jsuikit.modifiers.*
import dev.inmo.jsuikit.utils.* import dev.inmo.jsuikit.utils.*
import org.jetbrains.compose.web.attributes.AttrsScope import org.jetbrains.compose.web.attributes.AttrsScope
import org.jetbrains.compose.web.dom.* import org.jetbrains.compose.web.dom.*
import org.w3c.dom.HTMLLIElement import org.w3c.dom.*
import org.w3c.dom.HTMLUListElement
@Composable @Composable
fun NavbarNav( fun NavbarNav(
@@ -30,3 +29,17 @@ fun NavbarNav(
vararg elements: AttrsWithContentBuilder<HTMLLIElement>, vararg elements: AttrsWithContentBuilder<HTMLLIElement>,
attrs: Attrs<HTMLUListElement> = Attrs.empty() attrs: Attrs<HTMLUListElement> = Attrs.empty()
) = NavbarNav(elements.toList(), attrs) ) = NavbarNav(elements.toList(), attrs)
fun NavbarNavBuilder(
elements: List<AttrsWithContentBuilder<HTMLLIElement>>,
attrs: Attrs<HTMLUListElement> = Attrs.empty(),
containerAttrs: Attrs<HTMLDivElement> = Attrs.empty()
) = AttrsWithContentBuilder<HTMLDivElement>(containerAttrs) {
NavbarNav(elements, attrs)
}
fun NavbarNavBuilder(
vararg elements: AttrsWithContentBuilder<HTMLLIElement>,
attrs: Attrs<HTMLUListElement> = Attrs.empty(),
containerAttrs: Attrs<HTMLDivElement> = Attrs.empty()
) = NavbarNavBuilder(elements.toList(), attrs, containerAttrs)

View File

@@ -9,13 +9,14 @@ import org.jetbrains.compose.web.dom.Input
import org.w3c.dom.HTMLInputElement import org.w3c.dom.HTMLInputElement
@Composable @Composable
fun <T> StandardInput( fun <T> DefaultInput(
type: InputType<T>, type: InputType<T>,
state: MutableState<T>, value: T,
disabledState: State<Boolean>? = null, disabled: Boolean = false,
placeholder: String? = null, placeholder: String? = null,
vararg modifiers: UIKitModifier, vararg modifiers: UIKitModifier,
attributesCustomizer: AttrBuilderContext<HTMLInputElement> = {}, attributesCustomizer: AttrBuilderContext<HTMLInputElement> = {},
onChange: (T) -> Unit
) { ) {
Input(type) { Input(type) {
classes("uk-input") classes("uk-input")
@@ -23,7 +24,7 @@ fun <T> StandardInput(
placeholder ?.let(::placeholder) placeholder ?.let(::placeholder)
state.value.let { value.let {
when (it) { when (it) {
is String -> value(it) is String -> value(it)
is Number -> value(it) is Number -> value(it)
@@ -31,13 +32,30 @@ fun <T> StandardInput(
} }
} }
onInput { state.value = it.value } onInput { onChange(it.value) }
disabledState ?.let { if (disabled) {
if (it.value) {
disabled() disabled()
} }
}
attributesCustomizer() attributesCustomizer()
} }
} }
@Composable
fun <T> StandardInput(
type: InputType<T>,
state: MutableState<T>,
disabledState: State<Boolean>? = null,
placeholder: String? = null,
vararg modifiers: UIKitModifier,
attributesCustomizer: AttrBuilderContext<HTMLInputElement> = {},
) = DefaultInput(
type,
state.value,
disabledState ?.value == true,
placeholder,
modifiers = modifiers,
attributesCustomizer = attributesCustomizer
) {
state.value = it
}

View File

@@ -0,0 +1,122 @@
package dev.inmo.jsuikit.modifiers
import dev.inmo.jsuikit.utils.*
import org.jetbrains.compose.web.css.selectors.CSSSelector
sealed class UIKitDrop(
override val classes: Array<String> = emptyArray(),
override val otherAttrs: Map<String, String> = emptyMap()
) : UIKitModifier {
sealed class Position(name: String) : AttributeValue(name) {
sealed class Bottom(name: String) : Position("bottom-$name") {
object Left : Bottom("left")
object Center : Bottom("center")
object Right : Bottom("right")
object Justify : Bottom("justify")
}
sealed class Top(name: String) : Position("top-$name") {
object Left : Top("left")
object Center : Top("center")
object Right : Top("right")
object Justify : Top("justify")
}
sealed class Left(name: String) : Position("left-$name") {
object Top : Left("top")
object Center : Left("center")
object Bottom : Left("bottom")
}
sealed class Right(name: String) : Position("right-$name") {
object Top : Right("top")
object Center : Right("center")
object Bottom : Right("bottom")
}
}
sealed class Stretch(name: String) : AttributeValue(name) {
object True : Stretch("true")
object X : Stretch("x")
object Y : Stretch("y")
}
sealed class Mode(name: String) : AttributeValue(name) {
object Click : Mode("click")
object Hover : Mode("hover")
object None : Mode("")
object HoverAndClick : Mode("$Hover, $Click")
}
class Custom internal constructor(
classes: Array<String> = emptyArray(),
otherAttrs: Map<String, String> = emptyMap()
) : UIKitDrop(classes, otherAttrs)
companion object {
operator fun invoke(
toggle: CSSSelector? = null,
position: Position? = null,
stretch: Stretch? = null,
mode: Mode? = null,
delayShow: Milliseconds? = null,
delayHide: Milliseconds? = null,
autoUpdate: Boolean? = null,
boundary: CSSSelector? = null,
boundaryX: CSSSelector? = null,
boundaryY: CSSSelector? = null,
target: CSSSelector? = null,
targetX: CSSSelector? = null,
targetY: CSSSelector? = null,
inset: Boolean? = null,
flip: Boolean? = null,
shift: Boolean? = null,
offset: Pixels? = null,
animation: UIKitAnimation? = null,
animationOut: Boolean? = null,
bgScroll: Boolean? = null,
duration: Milliseconds? = null,
container: Boolean? = null
) = Custom(
arrayOf("uk-drop"),
mapOf(
buildAttribute("uk-drop") {
"toggle" to toggle
"position" to position
"stretch" to stretch
"mode" to mode
"delay-show" to delayShow
"delay-hide" to delayHide
"auto-update" to autoUpdate
"boundary" to boundary
"boundary-x" to boundaryX
"boundary-y" to boundaryY
"target" to target
"target-x" to targetX
"target-y" to targetY
"inset" to inset
"flip" to flip
"shift" to shift
"offset" to offset
"animation" to animation
"animation-out" to animationOut
"bg-scroll" to bgScroll
"duration" to duration
"container" to container
}
)
)
}
}

View File

@@ -1,13 +1,17 @@
package dev.inmo.jsuikit.utils package dev.inmo.jsuikit.utils
import dev.inmo.jsuikit.modifiers.AttributeValue
class ParametersBuilder( class ParametersBuilder(
val skipNullValues: Boolean = true, val skipNullValues: Boolean = true,
private val parameters: MutableMap<String, String?> = mutableMapOf() private val parameters: MutableMap<String, String?> = mutableMapOf()
) { ) {
fun add(k: String, v: Any? = null) { fun add(k: String, v: Any? = null) {
if (v != null || !skipNullValues) { when {
parameters[k] = v ?.toString() v is AttributeValue -> parameters[k] = v.name
v == null && skipNullValues -> return
else -> parameters[k] = v ?.toString()
} }
} }
infix fun String.to(value: Any?) = add(this, value) infix fun String.to(value: Any?) = add(this, value)