mirror of
https://github.com/InsanusMokrassar/JSUIKitKBindings.git
synced 2025-12-04 05:15:56 +00:00
Compare commits
144 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 5cfee9c4cc | |||
| c9a17fa92a | |||
| c36e8c58f4 | |||
| 67f083610a | |||
| 636280a982 | |||
| 415549b251 | |||
| 0d2672b679 | |||
| a511def014 | |||
| d783834aa4 | |||
| cf2b823765 | |||
| 0f6e2c9805 | |||
| 7b2810b206 | |||
| 0dff161ce6 | |||
| 0648ceed18 | |||
| 190b3ac53e | |||
| aa5015d079 | |||
| 752bf5bfcd | |||
| 8d05f7e020 | |||
| 5589d42f6d | |||
| 32d26a8e56 | |||
| 2f521a4584 | |||
| c47a140719 | |||
| fbb4fb16d7 | |||
| 8c5dca73fa | |||
| 429d3d4e77 | |||
| fed53cd8cd | |||
| b72937e907 | |||
| c88138a8ed | |||
| 214fb07362 | |||
| 589fc62364 | |||
| 767f5291a8 | |||
| 38819eba21 | |||
| e5223f8408 | |||
| 854bc9f8ca | |||
| 36f5d5661b | |||
| 2af001a4f1 | |||
| 68f1879114 | |||
| f16c93cf0d | |||
| 63dd8f1bf6 | |||
| fafb7e7e04 | |||
| 5afa92ef37 | |||
| 4377ec3969 | |||
| 674fbbd4d5 | |||
| efd9cb80e1 | |||
| 53b020ab8d | |||
| 67a6998f02 | |||
| abe44fe1c6 | |||
| b028b12103 | |||
| 816f341729 | |||
| 6a652249c0 | |||
| ec584798ad | |||
| faf238cf07 | |||
| d78acce3c5 | |||
| 3afe6c2815 | |||
| 29efe4b5cd | |||
| 990bd6385f | |||
| deb30957ac | |||
| 276eaddcac | |||
| 9b992cbda0 | |||
| e227d3c88e | |||
| fc4f937cc1 | |||
| 1ee9b8c4de | |||
| 90e27d0cab | |||
| 400724c918 | |||
| ea59ba1446 | |||
| a97898fe69 | |||
| 21d2ccf208 | |||
| fd6a122b40 | |||
| 6b4e141cd2 | |||
| fb5e0ade11 | |||
| 353314dd26 | |||
| 57ffe32b9f | |||
| c6bacffdb3 | |||
| 3e2aa22076 | |||
| 5842da03d0 | |||
| 6daa57fe8f | |||
| 8adbe8a1ca | |||
| 468f167ac6 | |||
| c41e2b8495 | |||
| 7cdd12e81e | |||
| f3ce0f6b6b | |||
| d24edcbaf7 | |||
| fdd98bab13 | |||
| ed6582c98d | |||
| 4b697938ac | |||
| ebb350c688 | |||
| 8c2ce7b75d | |||
| 2d62f9847a | |||
| 3746b614cf | |||
| 2ece25ef4e | |||
| 18ffabf76d | |||
| c5ef64ebe4 | |||
| ee1bea8ee1 | |||
| 4a7b125abe | |||
| a756bab2a6 | |||
| be4d63f0e0 | |||
| b177760c73 | |||
| 82f00fa23b | |||
| 33b1a7af65 | |||
| e6b0ca580a | |||
| d5045bdba7 | |||
| 186eff482d | |||
| 4a204f8971 | |||
| fa41022df5 | |||
| 04a94cfabe | |||
| c337dd2b2d | |||
| b4a0ff6ece | |||
| 061b55b164 | |||
| d93517bf83 | |||
| 8497739c10 | |||
| 7fb24d1999 | |||
| bdd955d6e9 | |||
| 6144ee5723 | |||
| 1f44f27fbb | |||
| c59c442a36 | |||
| e61f420dc4 | |||
| e0052950e9 | |||
| 47eab8821d | |||
| b89df98459 | |||
| f90055fa59 | |||
| 38a884cc16 | |||
| 43e3ed742d | |||
| 3ddb22341c | |||
| 475afeb78b | |||
| af289b3194 | |||
| 7bd5b26a1b | |||
| 4e22cfce1a | |||
| 60816700ea | |||
| 33fbd2c0be | |||
| b836fe744e | |||
| f77c21ac51 | |||
| c720973bfc | |||
| 0b11e2c1b9 | |||
| 556ab4e090 | |||
| a596516c79 | |||
| 8eeabc4b5d | |||
| 2a3f14593b | |||
| bfd6790014 | |||
| 27ad91be74 | |||
| 3c7f17523b | |||
| c81c1125a0 | |||
| 2e28334b41 | |||
| 7c33efa121 | |||
| 7b6a8c81b4 |
8
.github/workflows/build.yml
vendored
8
.github/workflows/build.yml
vendored
@@ -5,15 +5,11 @@ on: [push]
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- name: Set up JDK 1.8
|
||||
- name: Set up JDK 11
|
||||
uses: actions/setup-java@v1
|
||||
with:
|
||||
java-version: 1.8
|
||||
- name: Fix android 31.0.0 dx
|
||||
continue-on-error: true
|
||||
run: cd /usr/local/lib/android/sdk/build-tools/31.0.0/ && mv d8 dx && cd lib && mv d8.jar dx.jar
|
||||
java-version: 11
|
||||
- name: Build with Gradle
|
||||
run: ./gradlew build
|
||||
|
||||
144
CHANGELOG.md
144
CHANGELOG.md
@@ -1,5 +1,149 @@
|
||||
# Changelog
|
||||
|
||||
## 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
|
||||
|
||||
* `Tab` elements become supported
|
||||
|
||||
## 0.2.0
|
||||
|
||||
**ALL DEPRECATIONS HAVE BEEN REMOVED**
|
||||
|
||||
* `Kotlin`: `1.7.0`
|
||||
* `Compose`: `1.2.0-alpha01-dev753`
|
||||
|
||||
## 0.1.10
|
||||
|
||||
* `Grid` support improvements
|
||||
|
||||
## 0.1.9
|
||||
|
||||
* `Artile` elements become supported
|
||||
* `Iconnav` elements become supported
|
||||
* `Leader` elements become supported
|
||||
* `Grid` support improvements
|
||||
|
||||
## 0.1.8
|
||||
|
||||
* `Compose`: `1.2.0-alpha01-dev731`
|
||||
|
||||
## 0.1.7
|
||||
|
||||
Add Toggle builder
|
||||
|
||||
## 0.1.6
|
||||
|
||||
* Add support of UIKitButton size and group
|
||||
|
||||
## 0.1.5
|
||||
|
||||
* Fix access to `UIKitSticky`
|
||||
|
||||
## 0.1.4
|
||||
|
||||
* Improvements in `UIKitGrid`
|
||||
* Add support of `UIKitSticky`
|
||||
|
||||
## 0.1.3
|
||||
|
||||
* Add support of sections
|
||||
* Improve support of navbars
|
||||
|
||||
## 0.1.2
|
||||
|
||||
* New typealias `AttrsWithContentBuilder`
|
||||
* Old `DList` and related composable functions removed (they are built-in in compose)
|
||||
|
||||
## 0.1.1
|
||||
|
||||
* `Compose`: `1.2.0-alpha01-dev686`
|
||||
|
||||
## 0.1.0
|
||||
|
||||
* `Kotlin` = `1.6.21`
|
||||
* `Compose`: `1.2.0-alpha01-dev683`
|
||||
|
||||
## 0.0.53
|
||||
|
||||
* Improvements in `UIKitPadding`
|
||||
* Add support of UIKit lists
|
||||
|
||||
## 0.0.52
|
||||
|
||||
* Improve work with UIKitModifiers
|
||||
|
||||
## 0.0.51
|
||||
|
||||
* New interface `Dropdown` which will be used to create (or retrieve) dropdown for an element
|
||||
* New attribute in `NavItemElement` for configuration of `A` element
|
||||
|
||||
## 0.0.50
|
||||
|
||||
* Add opportunity to customize content in title of `Nav` after text
|
||||
|
||||
## 0.0.49
|
||||
|
||||
* Now it is possible to use optional title in navs builders
|
||||
|
||||
## 0.0.48
|
||||
|
||||
* Added support of `Breadcrumb`
|
||||
* Add opportunity to summarize `UIKitModifier`
|
||||
* Add opportunity to simply create attributes builder using `UIKitModifier` of array of them
|
||||
|
||||
## 0.0.47
|
||||
|
||||
* Add support of `Close` element
|
||||
|
||||
## 0.0.46
|
||||
|
||||
* Add support of `UIKitOverlay`
|
||||
* Add support of `UIKitInverse`
|
||||
|
||||
## 0.0.45
|
||||
|
||||
* Add support of containers in `UIKitContainer` modifiers and `Container` function
|
||||
|
||||
## 0.0.44
|
||||
|
||||
* `Versions`:
|
||||
* `Compose`: `1.1.0` -> `1.1.1`
|
||||
|
||||
## 0.0.43
|
||||
|
||||
* Several new extensions for `UIKitModifier` like `UIKitModifier#onSmallScreen`
|
||||
* Support of `Tile`
|
||||
|
||||
## 0.0.42
|
||||
|
||||
* Migration to compose 1.1.0
|
||||
* Replaces according to it
|
||||
|
||||
## 0.0.41
|
||||
|
||||
* Add `DropArea`
|
||||
* Add `UIKitPlaceholder`
|
||||
* `UIKitForm#Custom` now have nullable param target
|
||||
* Add `UIKitUtility#Link`
|
||||
* Add `DescriptionList` and several support composable functions
|
||||
|
||||
## 0.0.40
|
||||
|
||||
* All `DefaultTable` functions now use `Iterable` as data type
|
||||
|
||||
## 0.0.39
|
||||
|
||||
* Add support of `Notifications`
|
||||
|
||||
## 0.0.38
|
||||
|
||||
* Add support of `Toggle`
|
||||
|
||||
@@ -26,6 +26,7 @@ repositories {
|
||||
mavenLocal()
|
||||
mavenCentral()
|
||||
google()
|
||||
maven { url "https://maven.pkg.jetbrains.space/public/p/compose/dev" }
|
||||
}
|
||||
|
||||
kotlin {
|
||||
|
||||
@@ -21,7 +21,7 @@ if (new File(projectDir, "secret.gradle").exists()) {
|
||||
owner "InsanusMokrassar"
|
||||
repo "JSUIKitKBindings"
|
||||
|
||||
tagName "${project.version}"
|
||||
tagName "v${project.version}"
|
||||
releaseName "${project.version}"
|
||||
targetCommitish "${project.version}"
|
||||
|
||||
|
||||
@@ -9,4 +9,4 @@ android.enableJetifier=true
|
||||
# Project data
|
||||
|
||||
group=dev.inmo
|
||||
version=0.0.38
|
||||
version=0.4.0
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
[versions]
|
||||
|
||||
kt = "1.6.10"
|
||||
jb-compose = "1.0.1"
|
||||
jb-dokka = "1.6.10"
|
||||
gh-release = "2.2.12"
|
||||
kt = "1.7.20"
|
||||
jb-compose = "1.2.1"
|
||||
jb-dokka = "1.7.20"
|
||||
gh-release = "2.4.1"
|
||||
|
||||
[libraries]
|
||||
|
||||
|
||||
2
gradle/wrapper/gradle-wrapper.properties
vendored
2
gradle/wrapper/gradle-wrapper.properties
vendored
@@ -1,5 +1,5 @@
|
||||
distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.3-bin.zip
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5.1-bin.zip
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
zipStorePath=wrapper/dists
|
||||
|
||||
@@ -1,31 +1,12 @@
|
||||
package dev.inmo.jsuikit
|
||||
|
||||
import dev.inmo.jsuikit.modifiers.AttributeValue
|
||||
import dev.inmo.jsuikit.utils.AttributeBuilder
|
||||
import dev.inmo.jsuikit.utils.buildAttribute
|
||||
import org.jetbrains.compose.web.attributes.AttrsBuilder
|
||||
import dev.inmo.jsuikit.utils.*
|
||||
import org.jetbrains.compose.web.attributes.AttrsScope
|
||||
|
||||
@Deprecated("Will be removed soon")
|
||||
class UIKitAttributeValueBuilder {
|
||||
private val attrs = mutableListOf<Pair<String, String>>()
|
||||
|
||||
infix fun String.to(other: String?) {
|
||||
other ?.let {
|
||||
attrs.add(Pair(this, other))
|
||||
}
|
||||
}
|
||||
|
||||
infix fun String.to(other: AttributeValue?) {
|
||||
this to other ?.name
|
||||
}
|
||||
|
||||
fun build(): String = attrs.joinToString(";") { (k, v) -> "$k: $v" }
|
||||
}
|
||||
|
||||
fun AttrsBuilder<*>.buildAndAddAttribute(
|
||||
fun AttrsScope<*>.buildAndAddAttribute(
|
||||
attributeName: String,
|
||||
skipNullValues: Boolean = true,
|
||||
block: AttributeBuilder.() -> Unit
|
||||
block: ParametersBuilder.() -> Unit
|
||||
) {
|
||||
buildAttribute(attributeName, skipNullValues, block).let {
|
||||
attr(it.first, it.second)
|
||||
|
||||
@@ -4,7 +4,7 @@ import androidx.compose.runtime.Composable
|
||||
import dev.inmo.jsuikit.modifiers.UIKitAccordion
|
||||
import dev.inmo.jsuikit.modifiers.include
|
||||
import dev.inmo.jsuikit.utils.Attrs
|
||||
import org.jetbrains.compose.web.attributes.AttrsBuilder
|
||||
import org.jetbrains.compose.web.attributes.AttrsScope
|
||||
import org.jetbrains.compose.web.dom.*
|
||||
import org.w3c.dom.*
|
||||
|
||||
@@ -12,7 +12,7 @@ import org.w3c.dom.*
|
||||
fun <T> Accordion(
|
||||
data: Iterable<T>,
|
||||
attrs: Attrs<HTMLUListElement> = Attrs.empty(),
|
||||
itemAttrsBuilder: AttrsBuilder<HTMLLIElement>.(Int, T) -> Unit = { _, _ -> },
|
||||
itemAttrsBuilder: AttrsScope<HTMLLIElement>.(Int, T) -> Unit = { _, _ -> },
|
||||
itemContentBuilder: @Composable ElementScope<HTMLLIElement>.(Int, T) -> Unit
|
||||
) {
|
||||
Ul(
|
||||
@@ -33,13 +33,13 @@ fun <T> Accordion(
|
||||
fun <T> DefaultAccordion(
|
||||
data: Iterable<T>,
|
||||
attrs: Attrs<HTMLUListElement> = Attrs.empty(),
|
||||
itemAttrsBuilder: AttrsBuilder<HTMLLIElement>.(Int, T) -> Unit = { _, _ -> },
|
||||
titleAttrsBuilder: AttrsBuilder<HTMLAnchorElement>.(Int, T) -> Unit = { _, _ -> },
|
||||
itemAttrsBuilder: AttrsScope<HTMLLIElement>.(Int, T) -> Unit = { _, _ -> },
|
||||
titleAttrsBuilder: AttrsScope<HTMLAnchorElement>.(Int, T) -> Unit = { _, _ -> },
|
||||
titleContentBuilder: @Composable ElementScope<HTMLAnchorElement>.(Int, T) -> Unit = { _, _ -> },
|
||||
beforeTitleContentBuilder: @Composable ElementScope<HTMLLIElement>.(Int, T) -> Unit = { _, _ -> },
|
||||
afterTitleContentBuilder: @Composable ElementScope<HTMLLIElement>.(Int, T) -> Unit = { _, _ -> },
|
||||
afterContentContentBuilder: @Composable ElementScope<HTMLLIElement>.(Int, T) -> Unit = { _, _ -> },
|
||||
contentAttrsBuilder: AttrsBuilder<HTMLDivElement>.(Int, T) -> Unit = { _, _ -> },
|
||||
contentAttrsBuilder: AttrsScope<HTMLDivElement>.(Int, T) -> Unit = { _, _ -> },
|
||||
contentContentBuilder: @Composable ElementScope<HTMLDivElement>.(Int, T) -> Unit
|
||||
) = Accordion(
|
||||
data,
|
||||
@@ -72,9 +72,9 @@ fun <T> DefaultAccordion(
|
||||
data: Iterable<T>,
|
||||
titleResolver: (Int, T) -> String,
|
||||
attrs: Attrs<HTMLUListElement> = Attrs.empty(),
|
||||
itemAttrsBuilder: AttrsBuilder<HTMLLIElement>.(Int, T) -> Unit = { _, _ -> },
|
||||
titleAttrsBuilder: AttrsBuilder<HTMLAnchorElement>.(Int, T) -> Unit = { _, _ -> },
|
||||
contentAttrsBuilder: AttrsBuilder<HTMLDivElement>.(Int, T) -> Unit = { _, _ -> },
|
||||
itemAttrsBuilder: AttrsScope<HTMLLIElement>.(Int, T) -> Unit = { _, _ -> },
|
||||
titleAttrsBuilder: AttrsScope<HTMLAnchorElement>.(Int, T) -> Unit = { _, _ -> },
|
||||
contentAttrsBuilder: AttrsScope<HTMLDivElement>.(Int, T) -> Unit = { _, _ -> },
|
||||
contentContentBuilder: @Composable ElementScope<HTMLDivElement>.(Int, T) -> Unit
|
||||
) = DefaultAccordion(
|
||||
data,
|
||||
|
||||
57
src/jsMain/kotlin/dev/inmo/jsuikit/elements/Article.kt
Normal file
57
src/jsMain/kotlin/dev/inmo/jsuikit/elements/Article.kt
Normal file
@@ -0,0 +1,57 @@
|
||||
package dev.inmo.jsuikit.elements
|
||||
|
||||
import androidx.compose.runtime.Composable
|
||||
import dev.inmo.jsuikit.modifiers.UIKitArticle
|
||||
import dev.inmo.jsuikit.modifiers.include
|
||||
import dev.inmo.jsuikit.utils.Attrs
|
||||
import dev.inmo.jsuikit.utils.optionallyDraw
|
||||
import org.jetbrains.compose.web.dom.*
|
||||
import org.jetbrains.compose.web.dom.Text
|
||||
import org.w3c.dom.*
|
||||
|
||||
@Composable
|
||||
fun UIKitArticleElement (
|
||||
headerBuilder: ContentBuilder<HTMLHeadingElement>,
|
||||
headerAttrs: Attrs<HTMLHeadingElement> = Attrs.empty(),
|
||||
metaBuilder: ContentBuilder<HTMLParagraphElement>? = null,
|
||||
metaAttrs: Attrs<HTMLParagraphElement>? = null,
|
||||
otherContentBuilder: ContentBuilder<HTMLElement>
|
||||
) = Article(
|
||||
{
|
||||
include(UIKitArticle)
|
||||
}
|
||||
) {
|
||||
H1(
|
||||
{
|
||||
include(UIKitArticle.Title)
|
||||
headerAttrs.builder(this)
|
||||
},
|
||||
headerBuilder
|
||||
)
|
||||
optionallyDraw(metaAttrs, metaBuilder) {
|
||||
P(
|
||||
{
|
||||
include(UIKitArticle.Meta)
|
||||
metaAttrs ?.builder ?.invoke(this)
|
||||
},
|
||||
metaBuilder ?: {}
|
||||
)
|
||||
}
|
||||
|
||||
otherContentBuilder()
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun UIKitArticleElement (
|
||||
header: String,
|
||||
meta: String? = null,
|
||||
otherContentBuilder: ContentBuilder<HTMLElement>
|
||||
) = UIKitArticleElement(
|
||||
{ Text(header) },
|
||||
metaBuilder = meta ?.let {
|
||||
{
|
||||
Text(meta)
|
||||
}
|
||||
},
|
||||
otherContentBuilder = otherContentBuilder
|
||||
)
|
||||
50
src/jsMain/kotlin/dev/inmo/jsuikit/elements/Breadcrumb.kt
Normal file
50
src/jsMain/kotlin/dev/inmo/jsuikit/elements/Breadcrumb.kt
Normal file
@@ -0,0 +1,50 @@
|
||||
package dev.inmo.jsuikit.elements
|
||||
|
||||
import androidx.compose.runtime.Composable
|
||||
import dev.inmo.jsuikit.modifiers.UIKitBreadcrumb
|
||||
import dev.inmo.jsuikit.modifiers.include
|
||||
import dev.inmo.jsuikit.utils.Attrs
|
||||
import org.jetbrains.compose.web.dom.*
|
||||
import org.w3c.dom.*
|
||||
|
||||
@Composable
|
||||
fun <T> Breadcrumb(
|
||||
data: Iterable<T>,
|
||||
rootAttrs: Attrs<HTMLUListElement> = Attrs.empty(),
|
||||
elementAttrs: Attrs<HTMLLIElement> = Attrs.empty(),
|
||||
elementContent: @Composable ElementScope<HTMLLIElement>.(T) -> Unit = {},
|
||||
) {
|
||||
Ul(
|
||||
{
|
||||
include(UIKitBreadcrumb)
|
||||
rootAttrs.builder(this)
|
||||
}
|
||||
) {
|
||||
data.forEach {
|
||||
Li({ elementAttrs.builder(this) }) {
|
||||
elementContent(it)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun BreadcrumbActiveElement(
|
||||
href: String? = "#",
|
||||
elementAttrs: Attrs<HTMLAnchorElement> = Attrs.empty(),
|
||||
elementContent: @Composable ElementScope<HTMLAnchorElement>.() -> Unit = {},
|
||||
) {
|
||||
A(href, { elementAttrs.builder(this) }) {
|
||||
elementContent()
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun BreadcrumbInactiveElement(
|
||||
elementAttrs: Attrs<HTMLSpanElement> = Attrs.empty(),
|
||||
elementContent: @Composable ElementScope<HTMLSpanElement>.() -> Unit = {},
|
||||
) {
|
||||
Span({ elementAttrs.builder(this) }) {
|
||||
elementContent()
|
||||
}
|
||||
}
|
||||
@@ -4,7 +4,8 @@ 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.*
|
||||
import org.w3c.dom.HTMLDivElement
|
||||
import org.w3c.dom.HTMLHeadingElement
|
||||
|
||||
@Composable
|
||||
fun Card(
|
||||
|
||||
45
src/jsMain/kotlin/dev/inmo/jsuikit/elements/Close.kt
Normal file
45
src/jsMain/kotlin/dev/inmo/jsuikit/elements/Close.kt
Normal file
@@ -0,0 +1,45 @@
|
||||
package dev.inmo.jsuikit.elements
|
||||
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.web.events.SyntheticMouseEvent
|
||||
import dev.inmo.jsuikit.modifiers.UIKitClose
|
||||
import dev.inmo.jsuikit.modifiers.include
|
||||
import dev.inmo.jsuikit.utils.Attrs
|
||||
import org.jetbrains.compose.web.attributes.ButtonType
|
||||
import org.jetbrains.compose.web.attributes.type
|
||||
import org.jetbrains.compose.web.dom.*
|
||||
import org.w3c.dom.HTMLAnchorElement
|
||||
import org.w3c.dom.HTMLButtonElement
|
||||
|
||||
object Close {
|
||||
@Composable
|
||||
fun drawAsLink(
|
||||
href: String = "#",
|
||||
attrs: Attrs<HTMLAnchorElement> = Attrs.empty(),
|
||||
contentBuilder: ContentBuilder<HTMLAnchorElement> = {}
|
||||
) = A(
|
||||
href,
|
||||
{
|
||||
include(UIKitClose)
|
||||
attrs.builder(this)
|
||||
},
|
||||
contentBuilder
|
||||
)
|
||||
|
||||
@Composable
|
||||
fun drawAsButton(
|
||||
attrs: Attrs<HTMLButtonElement> = Attrs.empty(),
|
||||
contentBuilder: ContentBuilder<HTMLButtonElement> = {},
|
||||
onClick: ((SyntheticMouseEvent) -> Unit)? = null
|
||||
) = Button(
|
||||
{
|
||||
type(ButtonType.Button)
|
||||
include(UIKitClose)
|
||||
attrs.builder(this)
|
||||
onClick ?.let {
|
||||
onClick(onClick)
|
||||
}
|
||||
},
|
||||
contentBuilder
|
||||
)
|
||||
}
|
||||
21
src/jsMain/kotlin/dev/inmo/jsuikit/elements/Container.kt
Normal file
21
src/jsMain/kotlin/dev/inmo/jsuikit/elements/Container.kt
Normal file
@@ -0,0 +1,21 @@
|
||||
package dev.inmo.jsuikit.elements
|
||||
|
||||
import androidx.compose.runtime.Composable
|
||||
import dev.inmo.jsuikit.modifiers.UIKitContainer
|
||||
import dev.inmo.jsuikit.modifiers.include
|
||||
import dev.inmo.jsuikit.utils.Attrs
|
||||
import org.jetbrains.compose.web.dom.ContentBuilder
|
||||
import org.jetbrains.compose.web.dom.Div
|
||||
import org.w3c.dom.HTMLDivElement
|
||||
|
||||
@Composable
|
||||
fun Container(
|
||||
attrs: Attrs<HTMLDivElement> = Attrs.empty(),
|
||||
contentBuilder: ContentBuilder<HTMLDivElement> = {}
|
||||
) = Div(
|
||||
{
|
||||
include(UIKitContainer)
|
||||
attrs.builder.invoke(this)
|
||||
},
|
||||
contentBuilder
|
||||
)
|
||||
@@ -0,0 +1,56 @@
|
||||
package dev.inmo.jsuikit.elements
|
||||
|
||||
import androidx.compose.runtime.Composable
|
||||
import dev.inmo.jsuikit.modifiers.UIKitDescriptionList
|
||||
import dev.inmo.jsuikit.modifiers.include
|
||||
import dev.inmo.jsuikit.utils.*
|
||||
import org.jetbrains.compose.web.dom.*
|
||||
import org.w3c.dom.HTMLDListElement
|
||||
import org.w3c.dom.HTMLElement
|
||||
|
||||
@Composable
|
||||
fun DescriptionList(
|
||||
attrs: Attrs<HTMLDListElement>,
|
||||
contentBuilder: ContentBuilder<HTMLDListElement>
|
||||
) {
|
||||
DList(
|
||||
{
|
||||
include(UIKitDescriptionList)
|
||||
attrs.builder(this)
|
||||
},
|
||||
contentBuilder
|
||||
)
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun <T> DescriptionList(
|
||||
data: Iterable<T>,
|
||||
attrs: Attrs<HTMLDListElement>,
|
||||
beforeTermContent: (@Composable ElementScope<HTMLElement>.(Int, T) -> Unit)? = null,
|
||||
itemTermAttrs: ((Int, T) -> Attrs<HTMLElement>?)? = null,
|
||||
itemTermContent: (@Composable ElementScope<HTMLElement>.(Int, T) -> Unit)? = null,
|
||||
betweenTermAndDescriptionContent: (@Composable ElementScope<HTMLElement>.(Int, T) -> Unit)? = null,
|
||||
afterDescriptionContent: (@Composable ElementScope<HTMLElement>.(Int, T) -> Unit)? = null,
|
||||
itemDescriptionAttrs: ((Int, T) -> Attrs<HTMLElement>?)? = null,
|
||||
itemDescriptionContent: (@Composable ElementScope<HTMLElement>.(Int, T) -> Unit)? = null
|
||||
) {
|
||||
DescriptionList(attrs) {
|
||||
data.forEachIndexed { i, t ->
|
||||
beforeTermContent ?.invoke(this, i, t)
|
||||
if (itemTermAttrs != null || itemTermContent != null) {
|
||||
DTerm(
|
||||
itemTermAttrs ?.let { { it(i, t) } },
|
||||
itemTermContent ?.let { { it(i, t) } },
|
||||
)
|
||||
}
|
||||
betweenTermAndDescriptionContent ?.invoke(this, i, t)
|
||||
if (itemDescriptionAttrs != null || itemDescriptionContent != null) {
|
||||
DDescription(
|
||||
itemDescriptionAttrs ?.let { { it(i, t) } },
|
||||
itemDescriptionContent ?.let { { it(i, t) } },
|
||||
)
|
||||
}
|
||||
afterDescriptionContent ?.invoke(this, i, t)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -4,8 +4,8 @@ import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.DisposableEffectResult
|
||||
import dev.inmo.jsuikit.modifiers.*
|
||||
import org.jetbrains.compose.web.dom.*
|
||||
import org.jetbrains.compose.web.dom.Text
|
||||
import org.w3c.dom.*
|
||||
import org.w3c.dom.HTMLDivElement
|
||||
import org.w3c.dom.HTMLElement
|
||||
import org.w3c.dom.events.Event
|
||||
import kotlin.random.Random
|
||||
import kotlin.random.nextUInt
|
||||
@@ -17,7 +17,7 @@ private class DialogDisposableEffectResult(
|
||||
) : DisposableEffectResult {
|
||||
override fun dispose() {
|
||||
onDispose?.invoke()
|
||||
js("UIkit").modal("#${element.id}") ?.hide()
|
||||
UIKit.modal("#${element.id}") ?.hide()
|
||||
onDisposed?.invoke()
|
||||
}
|
||||
}
|
||||
@@ -99,9 +99,7 @@ fun Dialog(
|
||||
}
|
||||
htmlElement.addEventListener("hidden", wrapper)
|
||||
|
||||
val dialog = UIKit.modal("#${htmlElement.id}")
|
||||
dialog.show()
|
||||
Unit
|
||||
UIKit.modal("#${htmlElement.id}") ?.show()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
24
src/jsMain/kotlin/dev/inmo/jsuikit/elements/Drop.kt
Normal file
24
src/jsMain/kotlin/dev/inmo/jsuikit/elements/Drop.kt
Normal 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
|
||||
)
|
||||
}
|
||||
25
src/jsMain/kotlin/dev/inmo/jsuikit/elements/DropArea.kt
Normal file
25
src/jsMain/kotlin/dev/inmo/jsuikit/elements/DropArea.kt
Normal file
@@ -0,0 +1,25 @@
|
||||
package dev.inmo.jsuikit.elements
|
||||
|
||||
import androidx.compose.runtime.Composable
|
||||
import dev.inmo.jsuikit.modifiers.*
|
||||
import dev.inmo.jsuikit.utils.Attrs
|
||||
import dev.inmo.jsuikit.utils.InputAttrs
|
||||
import org.jetbrains.compose.web.dom.*
|
||||
import org.w3c.dom.HTMLDivElement
|
||||
|
||||
@Composable
|
||||
fun DropArea(
|
||||
attrs: Attrs<HTMLDivElement> = Attrs.empty(),
|
||||
inputAttrs: InputAttrs<String> = InputAttrs.empty(),
|
||||
contentBuilder: ContentBuilder<HTMLDivElement> = {}
|
||||
) = Div(
|
||||
{
|
||||
include(UIKitPlaceholder, UIKitForm.Custom())
|
||||
attrs.builder(this)
|
||||
}
|
||||
) {
|
||||
FileInput {
|
||||
inputAttrs.builder.invoke(this)
|
||||
}
|
||||
contentBuilder(this)
|
||||
}
|
||||
@@ -3,11 +3,26 @@ package dev.inmo.jsuikit.elements
|
||||
import androidx.compose.runtime.Composable
|
||||
import dev.inmo.jsuikit.buildAndAddAttribute
|
||||
import dev.inmo.jsuikit.modifiers.*
|
||||
import dev.inmo.jsuikit.types.DropdownOptions
|
||||
import dev.inmo.jsuikit.utils.Milliseconds
|
||||
import dev.inmo.jsuikit.utils.buildAttribute
|
||||
import org.jetbrains.compose.web.dom.*
|
||||
import org.w3c.dom.HTMLDivElement
|
||||
|
||||
@Composable
|
||||
fun Dropdown(
|
||||
vararg modifiers: UIKitModifier,
|
||||
dropdownOptions: DropdownOptions,
|
||||
attributesCustomizer: AttrBuilderContext<HTMLDivElement> = {},
|
||||
contentBuilder: ContentBuilder<HTMLDivElement>
|
||||
) {
|
||||
Div(
|
||||
{
|
||||
include(UIKitDropdown(dropdownOptions), *modifiers)
|
||||
attributesCustomizer()
|
||||
},
|
||||
contentBuilder
|
||||
)
|
||||
}
|
||||
@Composable
|
||||
fun Dropdown(
|
||||
vararg modifiers: UIKitModifier,
|
||||
@@ -27,21 +42,24 @@ fun Dropdown(
|
||||
) {
|
||||
Div(
|
||||
{
|
||||
buildAndAddAttribute("uk-dropdown") {
|
||||
"toggle" to toggle
|
||||
"pos" to pos
|
||||
"mode" to mode
|
||||
"delayShow" to delayShow
|
||||
"delayHide" to delayHide
|
||||
"boundary" to boundary
|
||||
"boundaryAlign" to boundaryAlign
|
||||
"flip" to flip
|
||||
"offset" to offset
|
||||
"animation" to animation
|
||||
"duration" to duration
|
||||
}
|
||||
classes("uk-dropdown")
|
||||
include(*modifiers)
|
||||
include(
|
||||
UIKitDropdown(
|
||||
DropdownOptions(
|
||||
toggle = toggle,
|
||||
pos = pos,
|
||||
mode = mode,
|
||||
delayShow = delayShow,
|
||||
delayHide = delayHide,
|
||||
boundary = boundary,
|
||||
boundaryAlign = boundaryAlign,
|
||||
flip = flip,
|
||||
offset = offset,
|
||||
animation = animation,
|
||||
duration = duration
|
||||
)
|
||||
),
|
||||
*modifiers
|
||||
)
|
||||
attributesCustomizer()
|
||||
},
|
||||
contentBuilder
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
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.buildAttribute
|
||||
import org.jetbrains.compose.web.dom.*
|
||||
import org.w3c.dom.HTMLDivElement
|
||||
|
||||
@@ -10,7 +10,7 @@ import org.w3c.dom.HTMLDivElement
|
||||
fun GridColumn(
|
||||
vararg modifiers: UIKitModifier,
|
||||
attributesCustomizer: AttrBuilderContext<HTMLDivElement> = {},
|
||||
builder: @Composable ElementScope<HTMLDivElement>.() -> Unit
|
||||
builder: @Composable ElementScope<HTMLDivElement>.() -> Unit = {}
|
||||
) {
|
||||
Div(
|
||||
{
|
||||
@@ -26,23 +26,18 @@ fun GridColumn(
|
||||
fun Grid(
|
||||
vararg modifiers: UIKitModifier,
|
||||
masonry: Boolean = false,
|
||||
parallax: Int? = null,
|
||||
marginClass: String? = null,
|
||||
parallax: UInt? = null,
|
||||
marginClass: UIKitMargin? = null,
|
||||
firstColumnClass: String? = null,
|
||||
attributesCustomizer: AttrBuilderContext<HTMLDivElement> = {},
|
||||
builder: @Composable ElementScope<HTMLDivElement>.() -> Unit
|
||||
builder: ContentBuilder<HTMLDivElement> = {}
|
||||
) {
|
||||
val attrs = listOfNotNull(
|
||||
if (masonry) "masonry" to "true" else null,
|
||||
parallax ?.let { "parallax" to it.toString() },
|
||||
marginClass ?.let { "margin" to it },
|
||||
firstColumnClass ?.let { "first-column" to it },
|
||||
)
|
||||
Div(
|
||||
{
|
||||
attr("uk-grid", attrs.joinToString(";") { (k, v) -> "$k: $v" })
|
||||
classes("uk-grid")
|
||||
include(*modifiers)
|
||||
include(
|
||||
UIKitGrid.invoke(marginClass, firstColumnClass, masonry, parallax),
|
||||
*modifiers
|
||||
)
|
||||
attributesCustomizer()
|
||||
}
|
||||
) {
|
||||
|
||||
@@ -77,15 +77,15 @@ sealed class Icon(val name: String) {
|
||||
object Grid : App("grid")
|
||||
sealed class More(iconName: String) : App("more${iconName.takeIf { it.isNotEmpty() } ?.let { "-$it" } ?: "" }") {
|
||||
object Vertical : More("vertical")
|
||||
companion object : More("more")
|
||||
companion object : More("")
|
||||
}
|
||||
sealed class Plus(iconName: String) : App("plus${iconName.takeIf { it.isNotEmpty() } ?.let { "-$it" } ?: "" }") {
|
||||
object Circle : Plus("circle")
|
||||
companion object : Plus("plus")
|
||||
companion object : Plus("")
|
||||
}
|
||||
sealed class Minus(iconName: String) : App("minus${iconName.takeIf { it.isNotEmpty() } ?.let { "-$it" } ?: "" }") {
|
||||
object Circle : Minus("circle")
|
||||
companion object : Minus("minus")
|
||||
companion object : Minus("")
|
||||
}
|
||||
object Close : App("close")
|
||||
object Check : App("check")
|
||||
@@ -93,7 +93,7 @@ sealed class Icon(val name: String) {
|
||||
object Refresh : App("refresh")
|
||||
sealed class Play(iconName: String) : App("play${iconName.takeIf { it.isNotEmpty() } ?.let { "-$it" } ?: "" }") {
|
||||
object Circle : Play("circle")
|
||||
companion object : Play("play")
|
||||
companion object : Play("")
|
||||
}
|
||||
}
|
||||
sealed class Devices(iconName: String) : Icon(iconName) {
|
||||
@@ -102,11 +102,11 @@ sealed class Icon(val name: String) {
|
||||
object Laptop : Devices("laptop")
|
||||
sealed class Tablet(iconName: String) : Devices("tablet${iconName.takeIf { it.isNotEmpty() } ?.let { "-$it" } ?: "" }") {
|
||||
object Landscape : Tablet("landscape")
|
||||
companion object : Tablet("tablet")
|
||||
companion object : Tablet("")
|
||||
}
|
||||
sealed class Phone(iconName: String) : Devices("phone${iconName.takeIf { it.isNotEmpty() } ?.let { "-$it" } ?: "" }") {
|
||||
object Landscape : Phone("landscape")
|
||||
companion object : Phone("phone")
|
||||
companion object : Phone("")
|
||||
}
|
||||
}
|
||||
sealed class Storage(iconName: String) : Icon(iconName) {
|
||||
@@ -114,7 +114,7 @@ sealed class Icon(val name: String) {
|
||||
object Text : File("text")
|
||||
object Pdf : File("pdf")
|
||||
object Edit : File("edit")
|
||||
companion object : File("file")
|
||||
companion object : File("")
|
||||
}
|
||||
object Copy : Storage("copy")
|
||||
object Folder : Storage("folder")
|
||||
@@ -177,7 +177,7 @@ sealed class Icon(val name: String) {
|
||||
object Foursquare : Brands("foursquare")
|
||||
sealed class Github(iconName: String) : Brands("github${iconName.takeIf { it.isNotEmpty() } ?.let { "-$it" } ?: "" }") {
|
||||
object Alt : Github("alt")
|
||||
companion object : Github("github")
|
||||
companion object : Github("")
|
||||
}
|
||||
object Gitter : Brands("gitter")
|
||||
object Google : Brands("google")
|
||||
|
||||
41
src/jsMain/kotlin/dev/inmo/jsuikit/elements/Iconnav.kt
Normal file
41
src/jsMain/kotlin/dev/inmo/jsuikit/elements/Iconnav.kt
Normal file
@@ -0,0 +1,41 @@
|
||||
package dev.inmo.jsuikit.elements
|
||||
|
||||
import androidx.compose.runtime.Composable
|
||||
import dev.inmo.jsuikit.modifiers.UIKitIconnav
|
||||
import dev.inmo.jsuikit.modifiers.include
|
||||
import dev.inmo.jsuikit.utils.Attrs
|
||||
import org.jetbrains.compose.web.attributes.AttrsScope
|
||||
import org.jetbrains.compose.web.dom.*
|
||||
import org.w3c.dom.HTMLLIElement
|
||||
import org.w3c.dom.HTMLUListElement
|
||||
|
||||
@Composable
|
||||
fun <T> IconNav(
|
||||
data: Iterable<T>,
|
||||
listAttrs: Attrs<HTMLUListElement> = Attrs.empty(),
|
||||
elementAttrsBuilder: AttrsScope<HTMLLIElement>.(T) -> Unit = {},
|
||||
elementBuilder: @Composable ElementScope<HTMLLIElement>.(T) -> Unit
|
||||
) {
|
||||
Ul(
|
||||
{
|
||||
include(UIKitIconnav)
|
||||
listAttrs.builder(this)
|
||||
}
|
||||
) {
|
||||
data.forEach {
|
||||
Li(
|
||||
{
|
||||
elementAttrsBuilder.invoke(this, it)
|
||||
}
|
||||
) { elementBuilder(this, it) }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@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)
|
||||
@@ -1,9 +1,11 @@
|
||||
package dev.inmo.jsuikit.elements
|
||||
|
||||
import androidx.compose.runtime.Composable
|
||||
import dev.inmo.jsuikit.modifiers.*
|
||||
import dev.inmo.jsuikit.modifiers.UIKitLabel
|
||||
import dev.inmo.jsuikit.modifiers.include
|
||||
import dev.inmo.jsuikit.utils.Attrs
|
||||
import org.jetbrains.compose.web.dom.*
|
||||
import org.jetbrains.compose.web.dom.Span
|
||||
import org.jetbrains.compose.web.dom.Text
|
||||
import org.w3c.dom.HTMLSpanElement
|
||||
|
||||
@Composable
|
||||
|
||||
@@ -2,14 +2,32 @@ package dev.inmo.jsuikit.elements
|
||||
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.snapshots.SnapshotStateList
|
||||
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.HTMLHeadingElement
|
||||
import org.w3c.dom.HTMLUListElement
|
||||
|
||||
@Composable
|
||||
fun <T> List(
|
||||
data: SnapshotStateList<T>,
|
||||
ukAttrs: Attrs<HTMLUListElement> = Attrs.empty(),
|
||||
elementAllocator: @Composable ElementScope<HTMLUListElement>.(T) -> Unit
|
||||
) {
|
||||
Ul(
|
||||
{
|
||||
include(UIKitList)
|
||||
ukAttrs.builder(this)
|
||||
}
|
||||
) {
|
||||
data.forEach {
|
||||
elementAllocator(it)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun <T> ListWithTitle(
|
||||
title: String,
|
||||
data: SnapshotStateList<T>,
|
||||
vararg titleModifiers: UIKitModifier,
|
||||
@@ -23,15 +41,5 @@ fun <T> List(
|
||||
Text(title)
|
||||
}
|
||||
besidesTitleAndList ?.invoke()
|
||||
Ul(
|
||||
{
|
||||
classes("uk-list")
|
||||
include(*ulModifiers)
|
||||
ulCustomizer()
|
||||
}
|
||||
) {
|
||||
data.forEach {
|
||||
elementAllocator(it)
|
||||
}
|
||||
}
|
||||
List(data, Attrs(*ulModifiers) { ulCustomizer(this) }, elementAllocator)
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package dev.inmo.jsuikit.elements
|
||||
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.snapshots.SnapshotStateList
|
||||
import dev.inmo.jsuikit.buildAndAddAttribute
|
||||
import dev.inmo.jsuikit.modifiers.*
|
||||
import dev.inmo.jsuikit.utils.Milliseconds
|
||||
@@ -94,8 +93,8 @@ fun SubNav(
|
||||
|
||||
@Composable
|
||||
fun <T> Nav(
|
||||
title: String,
|
||||
data: SnapshotStateList<T>,
|
||||
title: String?,
|
||||
data: Iterable<T>,
|
||||
vararg ulModifiers: UIKitModifier,
|
||||
titleModifiers: Array<UIKitModifier> = emptyArray(),
|
||||
multiple: Boolean? = null,
|
||||
@@ -104,6 +103,7 @@ fun <T> Nav(
|
||||
duration: Milliseconds? = null,
|
||||
besidesTitleAndList: ContentBuilder<HTMLUListElement>? = null,
|
||||
titleCustomizer: AttrBuilderContext<HTMLLIElement> = {},
|
||||
afterTitleContentBuilder: ContentBuilder<HTMLLIElement> = {},
|
||||
ulCustomizer: AttrBuilderContext<HTMLUListElement> = {},
|
||||
elementAllocator: @Composable ElementScope<HTMLUListElement>.(T) -> Unit
|
||||
) {
|
||||
@@ -119,11 +119,14 @@ fun <T> Nav(
|
||||
ulCustomizer()
|
||||
}
|
||||
) {
|
||||
NavHeader(
|
||||
title,
|
||||
*titleModifiers,
|
||||
attributesCustomizer = titleCustomizer
|
||||
)
|
||||
title ?.let {
|
||||
NavHeader(
|
||||
title,
|
||||
*titleModifiers,
|
||||
attributesCustomizer = titleCustomizer,
|
||||
afterTitleContentBuilder = afterTitleContentBuilder
|
||||
)
|
||||
}
|
||||
besidesTitleAndList ?.let { it() }
|
||||
data.forEach {
|
||||
elementAllocator(it)
|
||||
@@ -133,8 +136,8 @@ fun <T> Nav(
|
||||
|
||||
@Composable
|
||||
fun <T> DefaultNav(
|
||||
title: String,
|
||||
data: SnapshotStateList<T>,
|
||||
title: String?,
|
||||
data: Iterable<T>,
|
||||
vararg ulModifiers: UIKitModifier,
|
||||
titleModifiers: Array<UIKitModifier> = emptyArray(),
|
||||
multiple: Boolean? = null,
|
||||
@@ -143,6 +146,7 @@ fun <T> DefaultNav(
|
||||
duration: Milliseconds? = null,
|
||||
besidesTitleAndList: ContentBuilder<HTMLUListElement>? = null,
|
||||
titleCustomizer: AttrBuilderContext<HTMLLIElement> = {},
|
||||
afterTitleContentBuilder: ContentBuilder<HTMLLIElement> = {},
|
||||
ulCustomizer: AttrBuilderContext<HTMLUListElement> = {},
|
||||
elementAllocator: @Composable ElementScope<HTMLUListElement>.(T) -> Unit
|
||||
) = Nav(
|
||||
@@ -156,14 +160,15 @@ fun <T> DefaultNav(
|
||||
duration,
|
||||
besidesTitleAndList,
|
||||
titleCustomizer,
|
||||
afterTitleContentBuilder,
|
||||
ulCustomizer,
|
||||
elementAllocator
|
||||
)
|
||||
|
||||
@Composable
|
||||
fun <T> PrimaryNav(
|
||||
title: String,
|
||||
data: SnapshotStateList<T>,
|
||||
title: String?,
|
||||
data: Iterable<T>,
|
||||
vararg ulModifiers: UIKitModifier,
|
||||
titleModifiers: Array<UIKitModifier> = emptyArray(),
|
||||
multiple: Boolean? = null,
|
||||
@@ -172,6 +177,7 @@ fun <T> PrimaryNav(
|
||||
duration: Milliseconds? = null,
|
||||
besidesTitleAndList: ContentBuilder<HTMLUListElement>? = null,
|
||||
titleCustomizer: AttrBuilderContext<HTMLLIElement> = {},
|
||||
afterTitleContentBuilder: ContentBuilder<HTMLLIElement> = {},
|
||||
ulCustomizer: AttrBuilderContext<HTMLUListElement> = {},
|
||||
elementAllocator: @Composable ElementScope<HTMLUListElement>.(T) -> Unit
|
||||
) = Nav(
|
||||
@@ -185,14 +191,15 @@ fun <T> PrimaryNav(
|
||||
duration,
|
||||
besidesTitleAndList,
|
||||
titleCustomizer,
|
||||
afterTitleContentBuilder,
|
||||
ulCustomizer,
|
||||
elementAllocator
|
||||
)
|
||||
|
||||
@Composable
|
||||
fun <T> SubNav(
|
||||
title: String,
|
||||
data: SnapshotStateList<T>,
|
||||
title: String?,
|
||||
data: Iterable<T>,
|
||||
vararg ulModifiers: UIKitModifier,
|
||||
titleModifiers: Array<UIKitModifier> = emptyArray(),
|
||||
multiple: Boolean? = null,
|
||||
@@ -201,6 +208,7 @@ fun <T> SubNav(
|
||||
duration: Milliseconds? = null,
|
||||
besidesTitleAndList: ContentBuilder<HTMLUListElement>? = null,
|
||||
titleCustomizer: AttrBuilderContext<HTMLLIElement> = {},
|
||||
afterTitleContentBuilder: ContentBuilder<HTMLLIElement> = {},
|
||||
ulCustomizer: AttrBuilderContext<HTMLUListElement> = {},
|
||||
elementAllocator: @Composable ElementScope<HTMLUListElement>.(T) -> Unit
|
||||
) = Nav(
|
||||
@@ -214,6 +222,7 @@ fun <T> SubNav(
|
||||
duration,
|
||||
besidesTitleAndList,
|
||||
titleCustomizer,
|
||||
afterTitleContentBuilder,
|
||||
ulCustomizer,
|
||||
elementAllocator
|
||||
)
|
||||
@@ -223,6 +232,7 @@ fun NavHeader(
|
||||
text: String,
|
||||
vararg modifiers: UIKitModifier,
|
||||
attributesCustomizer: AttrBuilderContext<HTMLLIElement> = {},
|
||||
afterTitleContentBuilder: ContentBuilder<HTMLLIElement> = {}
|
||||
) {
|
||||
Li(
|
||||
{
|
||||
@@ -231,6 +241,7 @@ fun NavHeader(
|
||||
}
|
||||
) {
|
||||
Text(text)
|
||||
afterTitleContentBuilder()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -238,6 +249,7 @@ fun NavHeader(
|
||||
fun NavItemElement(
|
||||
vararg modifiers: UIKitModifier,
|
||||
attributesCustomizer: AttrBuilderContext<HTMLLIElement> = {},
|
||||
anchorAttributesCustomizer: AttrBuilderContext<HTMLAnchorElement> = {},
|
||||
contentAllocator: ContentBuilder<HTMLAnchorElement>
|
||||
) {
|
||||
Li(
|
||||
@@ -246,7 +258,7 @@ fun NavItemElement(
|
||||
attributesCustomizer()
|
||||
}
|
||||
) {
|
||||
A("#") {
|
||||
A("#", attrs = anchorAttributesCustomizer) {
|
||||
contentAllocator()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,35 +1,49 @@
|
||||
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.*
|
||||
import org.jetbrains.compose.web.dom.*
|
||||
import org.w3c.dom.HTMLDivElement
|
||||
import org.w3c.dom.HTMLElement
|
||||
|
||||
@Composable
|
||||
fun Navbar(
|
||||
leftBuilder: NavbarNavBuilder? = null,
|
||||
centerBuilder: NavbarNavBuilder? = null,
|
||||
rightBuilder: NavbarNavBuilder? = null,
|
||||
vararg navModifiers: UIKitModifier,
|
||||
attributesCustomizer: AttrBuilderContext<HTMLElement> = {},
|
||||
contentBuilder: ContentBuilder<HTMLElement>
|
||||
) {
|
||||
Nav(
|
||||
{
|
||||
attr("uk-navbar", "")
|
||||
classes("uk-navbar-container", "uk-navbar")
|
||||
include(UIKitNavbar, UIKitNavbar(), UIKitNavbar.Container)
|
||||
attributesCustomizer()
|
||||
}
|
||||
) {
|
||||
contentBuilder()
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun Navbar(
|
||||
leftBuilder: AttrsWithContentBuilder<HTMLDivElement>? = null,
|
||||
centerBuilder: AttrsWithContentBuilder<HTMLDivElement>? = null,
|
||||
rightBuilder: AttrsWithContentBuilder<HTMLDivElement>? = null,
|
||||
vararg navModifiers: UIKitModifier,
|
||||
attributesCustomizer: AttrBuilderContext<HTMLElement> = {},
|
||||
) {
|
||||
Navbar(
|
||||
attributesCustomizer = {
|
||||
include(*navModifiers)
|
||||
attributesCustomizer()
|
||||
}
|
||||
) {
|
||||
leftBuilder ?.let {
|
||||
Div({ classes("uk-navbar-left") }) { it.draw() }
|
||||
Div({ include(UIKitNavbar.Alignment.Left);leftBuilder.attributesBuilderContext(this) }, leftBuilder.builder)
|
||||
}
|
||||
centerBuilder ?.let {
|
||||
Div({ classes("uk-navbar-center") }) { it.draw() }
|
||||
Div({ include(UIKitNavbar.Alignment.Center);centerBuilder.attributesBuilderContext(this) }, centerBuilder.builder)
|
||||
}
|
||||
rightBuilder ?.let {
|
||||
Div({ classes("uk-navbar-right") }) { it.draw() }
|
||||
Div({ include(UIKitNavbar.Alignment.Right);rightBuilder.attributesBuilderContext(this) }, rightBuilder.builder)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,63 +1,45 @@
|
||||
package dev.inmo.jsuikit.elements
|
||||
|
||||
import androidx.compose.runtime.Composable
|
||||
import dev.inmo.jsuikit.modifiers.UIKitModifier
|
||||
import dev.inmo.jsuikit.modifiers.include
|
||||
import org.jetbrains.compose.web.attributes.AttrsBuilder
|
||||
import dev.inmo.jsuikit.modifiers.*
|
||||
import dev.inmo.jsuikit.utils.*
|
||||
import org.jetbrains.compose.web.attributes.AttrsScope
|
||||
import org.jetbrains.compose.web.dom.*
|
||||
import org.w3c.dom.HTMLLIElement
|
||||
import org.w3c.dom.HTMLUListElement
|
||||
import org.w3c.dom.*
|
||||
|
||||
interface NavbarNavElement {
|
||||
fun AttrsBuilder<HTMLLIElement>.setup() {}
|
||||
@Composable
|
||||
fun ElementScope<HTMLLIElement>.fill()
|
||||
|
||||
class Default(
|
||||
private val setupCallback: AttrsBuilder<HTMLLIElement>.() -> Unit,
|
||||
private val fillCallback: @Composable ElementScope<HTMLLIElement>.() -> Unit
|
||||
) : NavbarNavElement {
|
||||
override fun AttrsBuilder<HTMLLIElement>.setup() {
|
||||
setupCallback()
|
||||
}
|
||||
|
||||
@Composable
|
||||
override fun ElementScope<HTMLLIElement>.fill() {
|
||||
fillCallback()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class NavbarNavBuilder(
|
||||
private val modifiers: Array<UIKitModifier>,
|
||||
private val elements: List<NavbarNavElement>,
|
||||
private val attributesCustomizer: AttrBuilderContext<HTMLUListElement> = {}
|
||||
@Composable
|
||||
fun NavbarNav(
|
||||
elements: List<AttrsWithContentBuilder<HTMLLIElement>>,
|
||||
attrs: Attrs<HTMLUListElement> = Attrs.empty()
|
||||
) {
|
||||
constructor(
|
||||
modifiers: Array<UIKitModifier>,
|
||||
vararg elements: NavbarNavElement,
|
||||
attributesCustomizer: AttrBuilderContext<HTMLUListElement> = {}
|
||||
) : this(modifiers, elements.toList(), attributesCustomizer)
|
||||
constructor(
|
||||
vararg elements: NavbarNavElement,
|
||||
attributesCustomizer: AttrBuilderContext<HTMLUListElement> = {}
|
||||
) : this(emptyArray(), elements.toList(), attributesCustomizer)
|
||||
@Composable
|
||||
fun draw() {
|
||||
Ul(
|
||||
{
|
||||
classes("uk-navbar-nav")
|
||||
include(*modifiers)
|
||||
attributesCustomizer()
|
||||
}
|
||||
) {
|
||||
elements.forEach { element ->
|
||||
Li(
|
||||
{ element.apply { setup() } }
|
||||
) {
|
||||
element.apply { fill() }
|
||||
}
|
||||
}
|
||||
Ul(
|
||||
{
|
||||
include(UIKitNavbar.Nav)
|
||||
attrs.builder(this)
|
||||
}
|
||||
) {
|
||||
elements.forEach { element ->
|
||||
Li(element.attributesBuilderContext, element.builder)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun NavbarNav(
|
||||
vararg elements: AttrsWithContentBuilder<HTMLLIElement>,
|
||||
attrs: Attrs<HTMLUListElement> = Attrs.empty()
|
||||
) = 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)
|
||||
|
||||
13
src/jsMain/kotlin/dev/inmo/jsuikit/elements/Notification.kt
Normal file
13
src/jsMain/kotlin/dev/inmo/jsuikit/elements/Notification.kt
Normal file
@@ -0,0 +1,13 @@
|
||||
package dev.inmo.jsuikit.elements
|
||||
|
||||
import dev.inmo.jsuikit.modifiers.UIKit
|
||||
import dev.inmo.jsuikit.types.*
|
||||
import dev.inmo.jsuikit.utils.Milliseconds
|
||||
|
||||
fun Notification(
|
||||
message: String,
|
||||
status: UIKitNotificationParameter.Style? = null,
|
||||
timeout: Milliseconds? = null,
|
||||
group: NotificationsGroup? = null,
|
||||
position: UIKitNotificationParameter.Position? = null
|
||||
) = UIKit.notification.invoke(message, status, timeout, group, position)
|
||||
@@ -41,14 +41,3 @@ fun <T> StandardInput(
|
||||
attributesCustomizer()
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
@Deprecated("Renamed", ReplaceWith("StandardInput", "dev.inmo.jsuikit.elements.StandardInput"))
|
||||
fun <T> TextField(
|
||||
type: InputType<T>,
|
||||
state: MutableState<T>,
|
||||
disabledState: State<Boolean>? = null,
|
||||
placeholder: String? = null,
|
||||
vararg modifiers: UIKitModifier,
|
||||
attributesCustomizer: AttrBuilderContext<HTMLInputElement> = {},
|
||||
) = StandardInput(type, state, disabledState, placeholder, modifiers = modifiers, attributesCustomizer)
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
package dev.inmo.jsuikit.elements
|
||||
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.snapshots.SnapshotStateList
|
||||
import dev.inmo.jsuikit.modifiers.*
|
||||
import org.jetbrains.compose.web.attributes.AttrsBuilder
|
||||
import dev.inmo.jsuikit.modifiers.UIKitModifier
|
||||
import dev.inmo.jsuikit.modifiers.include
|
||||
import org.jetbrains.compose.web.attributes.AttrsScope
|
||||
import org.jetbrains.compose.web.dom.*
|
||||
import org.jetbrains.compose.web.dom.Text
|
||||
import org.w3c.dom.*
|
||||
@@ -11,13 +11,13 @@ import org.w3c.dom.*
|
||||
@Composable
|
||||
fun <T> DefaultTable(
|
||||
headerBuilders: List<ContentBuilder<HTMLTableCellElement>>,
|
||||
dataList: SnapshotStateList<T>,
|
||||
dataList: Iterable<T>,
|
||||
vararg tableModifiers: UIKitModifier,
|
||||
attributesCustomizer: AttrBuilderContext<HTMLTableElement> = {},
|
||||
headerCustomizer: AttrBuilderContext<HTMLTableSectionElement> = {},
|
||||
headerCellCustomizer: AttrsBuilder<HTMLTableCellElement>.(i: Int) -> Unit = {},
|
||||
rowAttributes: AttrsBuilder<HTMLTableRowElement>.(t: T) -> Unit = {},
|
||||
cellCustomizer: AttrsBuilder<HTMLTableCellElement>.(i: Int, t: T) -> Unit = { _, _ -> },
|
||||
headerCellCustomizer: AttrsScope<HTMLTableCellElement>.(i: Int) -> Unit = {},
|
||||
rowAttributes: AttrsScope<HTMLTableRowElement>.(t: T) -> Unit = {},
|
||||
cellCustomizer: AttrsScope<HTMLTableCellElement>.(i: Int, t: T) -> Unit = { _, _ -> },
|
||||
betweenHeaderAndBodyFiller: ContentBuilder<HTMLTableElement> = {},
|
||||
cellFiller: @Composable ElementScope<HTMLTableCellElement>.(i: Int, t: T) -> Unit
|
||||
) {
|
||||
@@ -68,18 +68,18 @@ fun <T> DefaultTable(
|
||||
@Composable
|
||||
fun <T> DefaultTable(
|
||||
heading: List<String>,
|
||||
dataList: SnapshotStateList<T>,
|
||||
dataList: Iterable<T>,
|
||||
vararg tableModifiers: UIKitModifier,
|
||||
attributesCustomizer: AttrBuilderContext<HTMLTableElement> = {},
|
||||
headerCustomizer: AttrBuilderContext<HTMLTableSectionElement> = {},
|
||||
headerCellCustomizer: AttrsBuilder<HTMLTableCellElement>.(i: Int, title: String) -> Unit = { _, _ -> },
|
||||
rowAttributes: AttrsBuilder<HTMLTableRowElement>.(t: T) -> Unit = {},
|
||||
cellCustomizer: AttrsBuilder<HTMLTableCellElement>.(i: Int, t: T) -> Unit = { _, _ -> },
|
||||
headerCellCustomizer: AttrsScope<HTMLTableCellElement>.(i: Int, title: String) -> Unit = { _, _ -> },
|
||||
rowAttributes: AttrsScope<HTMLTableRowElement>.(t: T) -> Unit = {},
|
||||
cellCustomizer: AttrsScope<HTMLTableCellElement>.(i: Int, t: T) -> Unit = { _, _ -> },
|
||||
betweenHeaderAndBodyFiller: ContentBuilder<HTMLTableElement> = {},
|
||||
cellFiller: @Composable ElementScope<HTMLTableCellElement>.(i: Int, t: T) -> Unit
|
||||
) {
|
||||
val headersByIndex = heading.mapIndexed { index, s -> index to s }.toMap()
|
||||
val headerCellCustomizer: AttrsBuilder<HTMLTableCellElement>.(i: Int) -> Unit = { i ->
|
||||
val headerCellCustomizer: AttrsScope<HTMLTableCellElement>.(i: Int) -> Unit = { i ->
|
||||
val header = headersByIndex[i]
|
||||
if (header != null) {
|
||||
headerCellCustomizer(i, header)
|
||||
|
||||
46
src/jsMain/kotlin/dev/inmo/jsuikit/elements/Tabs.kt
Normal file
46
src/jsMain/kotlin/dev/inmo/jsuikit/elements/Tabs.kt
Normal file
@@ -0,0 +1,46 @@
|
||||
package dev.inmo.jsuikit.elements
|
||||
|
||||
import androidx.compose.runtime.Composable
|
||||
import dev.inmo.jsuikit.modifiers.UIKitTab
|
||||
import dev.inmo.jsuikit.modifiers.include
|
||||
import dev.inmo.jsuikit.utils.optionallyDraw
|
||||
import org.jetbrains.compose.web.attributes.AttrsScope
|
||||
import org.jetbrains.compose.web.dom.*
|
||||
import org.w3c.dom.HTMLLIElement
|
||||
import org.w3c.dom.HTMLUListElement
|
||||
|
||||
@Composable
|
||||
fun <T> Tabs(
|
||||
data: Iterable<T>,
|
||||
tabsItemBuilder: @Composable ElementScope<HTMLLIElement>.(i: Int, data: T) -> Unit,
|
||||
tabsItemAttrs: AttrsScope<HTMLLIElement>.(i: Int, data: T) -> Unit = { _, _ -> },
|
||||
tabsContainerAttrs: AttrsScope<HTMLUListElement>.() -> Unit = {},
|
||||
contentContainerAttrs: (AttrsScope<HTMLUListElement>.() -> Unit)? = null,
|
||||
contentItemAttrs: (AttrsScope<HTMLLIElement>.(i: Int, data: T) -> Unit)? = null,
|
||||
contentItemBuilder: (@Composable ElementScope<HTMLLIElement>.(i: Int, data: T) -> Unit)? = null
|
||||
) {
|
||||
Ul({
|
||||
include(UIKitTab);
|
||||
tabsContainerAttrs()
|
||||
}) {
|
||||
data.forEachIndexed { i, data ->
|
||||
Li({ tabsItemAttrs(i, data) }) {
|
||||
tabsItemBuilder(i, data)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
optionallyDraw(contentItemAttrs != null, contentItemBuilder != null, contentContainerAttrs != null) {
|
||||
Ul({
|
||||
contentContainerAttrs ?.invoke(this)
|
||||
}) {
|
||||
optionallyDraw(contentItemAttrs != null, contentItemBuilder != null) {
|
||||
data.forEachIndexed { i, data ->
|
||||
Li({ contentItemAttrs ?.invoke(this, i, data) }) {
|
||||
contentItemBuilder ?.invoke(this, i, data)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
21
src/jsMain/kotlin/dev/inmo/jsuikit/elements/Tile.kt
Normal file
21
src/jsMain/kotlin/dev/inmo/jsuikit/elements/Tile.kt
Normal file
@@ -0,0 +1,21 @@
|
||||
package dev.inmo.jsuikit.elements
|
||||
|
||||
import androidx.compose.runtime.Composable
|
||||
import dev.inmo.jsuikit.modifiers.UIKitTile
|
||||
import dev.inmo.jsuikit.modifiers.include
|
||||
import dev.inmo.jsuikit.utils.Attrs
|
||||
import org.jetbrains.compose.web.dom.ContentBuilder
|
||||
import org.jetbrains.compose.web.dom.Div
|
||||
import org.w3c.dom.HTMLDivElement
|
||||
|
||||
@Composable
|
||||
fun Tile(
|
||||
attrs: Attrs<HTMLDivElement> = Attrs.empty(),
|
||||
contentBuilder: ContentBuilder<HTMLDivElement>
|
||||
) = Div(
|
||||
{
|
||||
include(UIKitTile)
|
||||
attrs.builder(this)
|
||||
},
|
||||
contentBuilder
|
||||
)
|
||||
26
src/jsMain/kotlin/dev/inmo/jsuikit/elements/Toggle.kt
Normal file
26
src/jsMain/kotlin/dev/inmo/jsuikit/elements/Toggle.kt
Normal file
@@ -0,0 +1,26 @@
|
||||
package dev.inmo.jsuikit.elements
|
||||
|
||||
import androidx.compose.runtime.Composable
|
||||
import dev.inmo.jsuikit.modifiers.UIKitToggle
|
||||
import dev.inmo.jsuikit.modifiers.include
|
||||
import dev.inmo.jsuikit.utils.Attrs
|
||||
import org.jetbrains.compose.web.attributes.ButtonType
|
||||
import org.jetbrains.compose.web.attributes.type
|
||||
import org.jetbrains.compose.web.dom.Button
|
||||
import org.jetbrains.compose.web.dom.ContentBuilder
|
||||
import org.w3c.dom.HTMLButtonElement
|
||||
|
||||
@Composable
|
||||
fun Toggle(
|
||||
attrs: Attrs<HTMLButtonElement>,
|
||||
contentBuilder: ContentBuilder<HTMLButtonElement>
|
||||
) {
|
||||
Button(
|
||||
{
|
||||
include(UIKitToggle)
|
||||
type(ButtonType.Button)
|
||||
attrs.builder(this)
|
||||
},
|
||||
contentBuilder
|
||||
)
|
||||
}
|
||||
@@ -1,3 +1,5 @@
|
||||
package dev.inmo.jsuikit.modifiers
|
||||
|
||||
sealed class AttributeValue(val name: String)
|
||||
sealed class AttributeValue(val name: String) {
|
||||
override fun toString(): String = name
|
||||
}
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
package dev.inmo.jsuikit.modifiers
|
||||
|
||||
inline val UIKit
|
||||
get() = js("UIkit")
|
||||
import dev.inmo.jsuikit.types.UIKit
|
||||
|
||||
inline val UIKit: UIKit
|
||||
get() = js("UIkit").unsafeCast<UIKit>()
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package dev.inmo.jsuikit.modifiers
|
||||
|
||||
import dev.inmo.jsuikit.utils.*
|
||||
import dev.inmo.jsuikit.utils.Milliseconds
|
||||
import dev.inmo.jsuikit.utils.buildAttribute
|
||||
import org.w3c.dom.PageTransitionEvent
|
||||
|
||||
sealed class UIKitAccordion(
|
||||
|
||||
12
src/jsMain/kotlin/dev/inmo/jsuikit/modifiers/UIKitArticle.kt
Normal file
12
src/jsMain/kotlin/dev/inmo/jsuikit/modifiers/UIKitArticle.kt
Normal file
@@ -0,0 +1,12 @@
|
||||
package dev.inmo.jsuikit.modifiers
|
||||
|
||||
sealed class UIKitArticle(
|
||||
override val classes: Array<String>
|
||||
) : UIKitModifier {
|
||||
|
||||
object Title : UIKitArticle(arrayOf("uk-article-title"))
|
||||
object Meta : UIKitArticle(arrayOf("uk-article-meta"))
|
||||
|
||||
companion object : UIKitArticle(arrayOf("uk-article"))
|
||||
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
package dev.inmo.jsuikit.modifiers
|
||||
|
||||
sealed class UIKitBreadcrumb(
|
||||
override val classes: Array<String> = emptyArray(),
|
||||
override val otherAttrs: Map<String, String> = emptyMap()
|
||||
) : UIKitModifier {
|
||||
companion object : UIKitBreadcrumb(arrayOf("uk-breadcrumb"))
|
||||
}
|
||||
@@ -12,5 +12,12 @@ sealed class UIKitButton(suffix: String?) : UIKitModifier {
|
||||
object Link : Type("link")
|
||||
}
|
||||
|
||||
sealed class Size(suffix: String) : UIKitButton(suffix) {
|
||||
object Small : Size("small")
|
||||
object Large : Size("large")
|
||||
}
|
||||
|
||||
object Group : UIKitButton("group")
|
||||
|
||||
companion object : UIKitButton(null)
|
||||
}
|
||||
|
||||
17
src/jsMain/kotlin/dev/inmo/jsuikit/modifiers/UIKitClose.kt
Normal file
17
src/jsMain/kotlin/dev/inmo/jsuikit/modifiers/UIKitClose.kt
Normal file
@@ -0,0 +1,17 @@
|
||||
package dev.inmo.jsuikit.modifiers
|
||||
|
||||
sealed class UIKitClose(
|
||||
override val classes: Array<String> = emptyArray(),
|
||||
override val otherAttrs: Map<String, String> = emptyMap()
|
||||
) : UIKitModifier {
|
||||
|
||||
object Large : UIKitClose(
|
||||
arrayOf("uk-close-large")
|
||||
)
|
||||
|
||||
companion object : UIKitClose(
|
||||
arrayOf("uk-close"),
|
||||
mapOf("uk-close" to "")
|
||||
)
|
||||
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package dev.inmo.jsuikit.modifiers
|
||||
|
||||
sealed class UIKitContainer(
|
||||
override val classes: Array<String> = emptyArray(),
|
||||
override val otherAttrs: Map<String, String> = emptyMap()
|
||||
) : UIKitModifier {
|
||||
|
||||
sealed class Size(size: String) : UIKitContainer(arrayOf("uk-container-$size")) {
|
||||
object XSmall : Size("xsmall")
|
||||
object Small : Size("small")
|
||||
object Large : Size("large")
|
||||
object XLarge : Size("xlarge")
|
||||
object Expand : Size("expand")
|
||||
}
|
||||
|
||||
companion object : UIKitContainer(
|
||||
arrayOf("uk-container")
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package dev.inmo.jsuikit.modifiers
|
||||
|
||||
sealed class UIKitDescriptionList(
|
||||
override val classes: Array<String>
|
||||
) : UIKitModifier {
|
||||
|
||||
object Divider : UIKitDescriptionList(arrayOf("uk-description-list-divider"))
|
||||
|
||||
companion object : UIKitDescriptionList(arrayOf("uk-description-list"))
|
||||
|
||||
}
|
||||
122
src/jsMain/kotlin/dev/inmo/jsuikit/modifiers/UIKitDrop.kt
Normal file
122
src/jsMain/kotlin/dev/inmo/jsuikit/modifiers/UIKitDrop.kt
Normal 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
|
||||
}
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,9 @@
|
||||
package dev.inmo.jsuikit.modifiers
|
||||
|
||||
import dev.inmo.jsuikit.types.DropdownOptions
|
||||
import dev.inmo.jsuikit.utils.Milliseconds
|
||||
import dev.inmo.jsuikit.utils.buildAttribute
|
||||
|
||||
sealed class UIKitDropdown(classname: String) : UIKitModifier {
|
||||
override val classes: Array<String> = arrayOf(classname)
|
||||
|
||||
@@ -50,6 +54,9 @@ sealed class UIKitDropdown(classname: String) : UIKitModifier {
|
||||
object Click : Mode("click")
|
||||
object Hover : Mode("hover")
|
||||
|
||||
object None : Mode("")
|
||||
object HoverAndClick : Mode("$Hover, $Click")
|
||||
|
||||
}
|
||||
|
||||
sealed class Flip(name: String) : AttributeValue(name) {
|
||||
@@ -61,4 +68,48 @@ sealed class UIKitDropdown(classname: String) : UIKitModifier {
|
||||
|
||||
}
|
||||
|
||||
class Custom(
|
||||
dropdownOptions: DropdownOptions
|
||||
) : UIKitDropdown("uk-dropdown") {
|
||||
override val otherAttrs: Map<String, String> = mapOf(
|
||||
buildAttribute(
|
||||
"uk-dropdown"
|
||||
) {
|
||||
dropdownOptions.includeParameters(this)
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
companion object {
|
||||
operator fun invoke(
|
||||
dropdownOptions: DropdownOptions
|
||||
) = Custom(dropdownOptions)
|
||||
operator fun invoke(
|
||||
toggle: String? = null,
|
||||
pos: Position? = null,
|
||||
mode: Mode? = null,
|
||||
delayShow: Milliseconds? = null,
|
||||
delayHide: Milliseconds? = null,
|
||||
boundary: String? = null,
|
||||
boundaryAlign: Boolean? = null,
|
||||
flip: Flip? = null,
|
||||
offset: Int? = null,
|
||||
animation: UIKitAnimation? = null,
|
||||
duration: Milliseconds? = null,
|
||||
) = Custom(
|
||||
DropdownOptions(
|
||||
toggle = toggle,
|
||||
pos = pos,
|
||||
mode = mode,
|
||||
delayShow = delayShow,
|
||||
delayHide = delayHide,
|
||||
boundary = boundary,
|
||||
boundaryAlign = boundaryAlign,
|
||||
flip = flip,
|
||||
offset = offset,
|
||||
animation = animation,
|
||||
duration = duration
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -47,8 +47,9 @@ sealed class UIKitForm(
|
||||
object Icon : UIKitForm("uk-form-icon")
|
||||
|
||||
class Custom(
|
||||
target: String = "true"
|
||||
target: String? = null
|
||||
) : UIKitForm(
|
||||
"uk-form-custom",
|
||||
otherAttrs = mapOf(
|
||||
buildAttribute("uk-form-custom") {
|
||||
"target" to target
|
||||
|
||||
@@ -1,20 +1,59 @@
|
||||
package dev.inmo.jsuikit.modifiers
|
||||
|
||||
sealed class UIKitGrid(suffix: String) : UIKitModifier {
|
||||
override val classes: Array<String> = arrayOf("uk-grid-$suffix")
|
||||
import dev.inmo.jsuikit.utils.buildAttribute
|
||||
|
||||
sealed class Gap(suffix: String) : UIKitGrid(suffix) {
|
||||
sealed class UIKitGrid(vararg classnames: String) : UIKitModifier {
|
||||
override val classes: Array<String> = classnames as Array<String>
|
||||
|
||||
object Small : Gap("small")
|
||||
object Medium : Gap("medium")
|
||||
object Large : Gap("large")
|
||||
object Collapse : Gap("collapse")
|
||||
sealed class Gap(classname: String) : UIKitGrid(classname) {
|
||||
|
||||
object Small : Gap("uk-grid-small")
|
||||
object Medium : Gap("uk-grid-medium")
|
||||
object Large : Gap("uk-grid-large")
|
||||
object Collapse : Gap("uk-grid-collapse")
|
||||
|
||||
}
|
||||
|
||||
object Divider : UIKitGrid("divider")
|
||||
sealed class Column(classname: String) : UIKitGrid(classname) {
|
||||
|
||||
object MatchHeight : UIKitGrid("match")
|
||||
object ItemMatchHeight : UIKitGrid("item-match")
|
||||
object Small : Column("uk-grid-column-small")
|
||||
object Medium : Column("uk-grid-column-medium")
|
||||
object Large : Column("uk-grid-column-large")
|
||||
object Collapse : Column("uk-grid-column-collapse")
|
||||
|
||||
}
|
||||
|
||||
sealed class Row(classname: String) : UIKitGrid(classname) {
|
||||
|
||||
object Small : Row("uk-grid-row-small")
|
||||
object Medium : Row("uk-grid-row-medium")
|
||||
object Large : Row("uk-grid-row-large")
|
||||
object Collapse : Row("uk-grid-row-collapse")
|
||||
|
||||
}
|
||||
|
||||
object Divider : UIKitGrid("uk-grid-divider")
|
||||
|
||||
object MatchHeight : UIKitGrid("uk-grid-match")
|
||||
object ItemMatchHeight : UIKitGrid("uk-grid-item-match")
|
||||
|
||||
class Custom internal constructor(override val otherAttrs: Map<String, String>) : UIKitGrid("uk-grid")
|
||||
|
||||
companion object : UIKitGrid("uk-grid") {
|
||||
operator fun invoke(
|
||||
margin: UIKitMargin? = null,
|
||||
firstColumnClass: String? = null,
|
||||
masonry: Boolean? = null,
|
||||
parallax: UInt? = null
|
||||
) = Custom(
|
||||
mapOf(
|
||||
buildAttribute("uk-grid") {
|
||||
margin to margin ?.classes ?.joinToString(" ")
|
||||
"first-column" to firstColumnClass
|
||||
"masonry" to masonry
|
||||
"parallax" to parallax
|
||||
}
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package dev.inmo.jsuikit.modifiers
|
||||
|
||||
import dev.inmo.jsuikit.utils.*
|
||||
import org.jetbrains.compose.web.css.CSSKeyframe
|
||||
|
||||
sealed class UIKitHeight(
|
||||
classname: String?,
|
||||
|
||||
11
src/jsMain/kotlin/dev/inmo/jsuikit/modifiers/UIKitIconnav.kt
Normal file
11
src/jsMain/kotlin/dev/inmo/jsuikit/modifiers/UIKitIconnav.kt
Normal file
@@ -0,0 +1,11 @@
|
||||
package dev.inmo.jsuikit.modifiers
|
||||
|
||||
sealed class UIKitIconnav(
|
||||
override val classes: Array<String>
|
||||
) : UIKitModifier {
|
||||
|
||||
object Vertical : UIKitIconnav(arrayOf("uk-iconnav-vertical"))
|
||||
|
||||
companion object : UIKitIconnav(arrayOf("uk-iconnav"))
|
||||
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
package dev.inmo.jsuikit.modifiers
|
||||
|
||||
sealed class UIKitInverse(classname: String) : UIKitModifier {
|
||||
override val classes: Array<String> = arrayOf(classname)
|
||||
|
||||
object Light : UIKitInverse("uk-light")
|
||||
object Dark : UIKitInverse("uk-dark")
|
||||
}
|
||||
28
src/jsMain/kotlin/dev/inmo/jsuikit/modifiers/UIKitLeader.kt
Normal file
28
src/jsMain/kotlin/dev/inmo/jsuikit/modifiers/UIKitLeader.kt
Normal file
@@ -0,0 +1,28 @@
|
||||
package dev.inmo.jsuikit.modifiers
|
||||
|
||||
import dev.inmo.jsuikit.utils.buildAttribute
|
||||
|
||||
sealed class UIKitLeader(
|
||||
override val classes: Array<String>,
|
||||
override val otherAttrs: Map<String, String>
|
||||
) : UIKitModifier {
|
||||
|
||||
class Custom(
|
||||
otherAttrs: Map<String, String>
|
||||
) : UIKitLeader(arrayOf("uk-leader"), otherAttrs)
|
||||
|
||||
companion object : UIKitLeader(arrayOf("uk-leader"), emptyMap()) {
|
||||
operator fun invoke(
|
||||
media: String? = null,
|
||||
fill: String? = null
|
||||
) = Custom(
|
||||
mapOf(
|
||||
buildAttribute("uk-leader") {
|
||||
"fill" to fill
|
||||
"media" to media
|
||||
}
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
}
|
||||
46
src/jsMain/kotlin/dev/inmo/jsuikit/modifiers/UIKitList.kt
Normal file
46
src/jsMain/kotlin/dev/inmo/jsuikit/modifiers/UIKitList.kt
Normal file
@@ -0,0 +1,46 @@
|
||||
package dev.inmo.jsuikit.modifiers
|
||||
|
||||
sealed class UIKitList(
|
||||
vararg classes: String,
|
||||
override val otherAttrs: Map<String, String> = emptyMap()
|
||||
) : UIKitModifier {
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
override val classes: Array<String> = classes as Array<String>
|
||||
|
||||
sealed class Style(vararg classes: String) : UIKitList(*classes) {
|
||||
|
||||
object Disc : Style("uk-list-disc")
|
||||
object Circle : Style("uk-list-circle")
|
||||
object Square : Style("uk-list-square")
|
||||
object Decimal : Style("uk-list-decimal")
|
||||
object Hyphen : Style("uk-list-hyphen")
|
||||
|
||||
}
|
||||
|
||||
sealed class Size(vararg classes: String) : UIKitList(*classes) {
|
||||
|
||||
object Large : Size("uk-list-large")
|
||||
object Collapse : Size("uk-list-collapse")
|
||||
|
||||
}
|
||||
|
||||
sealed class Color(vararg classes: String) : UIKitList(*classes) {
|
||||
|
||||
object Muted : Color("uk-list-muted")
|
||||
object Emphasis : Color("uk-list-emphasis")
|
||||
object Primary : Color("uk-list-primary")
|
||||
object Secondary : Color("uk-list-secondary")
|
||||
companion object {
|
||||
val Bullet = UIKitList.Bullet
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
object Bullet: UIKitList("uk-list-bullet")
|
||||
|
||||
object Divider: UIKitList("uk-list-divider")
|
||||
|
||||
object Striped: UIKitList("uk-list-striped")
|
||||
|
||||
companion object : UIKitList("uk-list")
|
||||
}
|
||||
@@ -1,6 +1,9 @@
|
||||
package dev.inmo.jsuikit.modifiers
|
||||
|
||||
import org.jetbrains.compose.web.attributes.AttrsBuilder
|
||||
import dev.inmo.jsuikit.utils.Attrs
|
||||
import org.jetbrains.compose.web.attributes.AttrsScope
|
||||
import org.jetbrains.compose.web.dom.AttrBuilderContext
|
||||
import org.w3c.dom.Element
|
||||
|
||||
interface UIKitModifier {
|
||||
val classes: Array<String>
|
||||
@@ -9,9 +12,22 @@ interface UIKitModifier {
|
||||
get() = emptyMap()
|
||||
}
|
||||
|
||||
fun AttrsBuilder<*>.include(vararg container: UIKitModifier?) {
|
||||
fun AttrsScope<*>.include(vararg container: UIKitModifier?) {
|
||||
container.forEach {
|
||||
it ?.classes ?.let { newClasses -> classes(*newClasses) }
|
||||
it ?.otherAttrs ?.let { attrs -> attrs.forEach { (k, v) -> attr(k, v) } }
|
||||
}
|
||||
}
|
||||
|
||||
fun <T : Element> UIKitModifier.asAttributesBuilder(): AttrBuilderContext<T> = {
|
||||
include(this@asAttributesBuilder)
|
||||
}
|
||||
operator fun UIKitModifier.plus(other: UIKitModifier): UIKitModifier = UIKitCustom(
|
||||
classes + other.classes,
|
||||
otherAttrs + other.otherAttrs
|
||||
)
|
||||
fun <T: Element> UIKitModifier?.builder() = Attrs<T>(this).builder
|
||||
fun <T: Element> Array<out UIKitModifier?>.builder() = Attrs<T>(*this).builder
|
||||
inline fun <T: Element> attrsBuilder(vararg modifiers: UIKitModifier?) = modifiers.builder<T>()
|
||||
@JsName("plusBuilder")
|
||||
operator fun <T: Element> UIKitModifier?.plus(other: UIKitModifier?): AttrBuilderContext<T> = Attrs<T>(this@plus, other).builder
|
||||
|
||||
@@ -14,6 +14,8 @@ sealed class UIKitNav(classname: String) : UIKitModifier {
|
||||
|
||||
object Center : UIKitNav("uk-nav-center")
|
||||
|
||||
object Sub : UIKitNav("uk-nav-sub")
|
||||
|
||||
companion object : UIKitNav("uk-nav") {
|
||||
val SubNav = UIKitSubNav
|
||||
}
|
||||
|
||||
@@ -1,17 +1,86 @@
|
||||
package dev.inmo.jsuikit.modifiers
|
||||
|
||||
sealed class UIKitNavbar(suffix: String) : UIKitModifier {
|
||||
override val classes: Array<String> = arrayOf("uk-navbar-$suffix")
|
||||
import dev.inmo.jsuikit.types.Dropdown
|
||||
import dev.inmo.jsuikit.utils.*
|
||||
|
||||
object Transparent : UIKitNavbar("transparent")
|
||||
sealed class Dropdown(suffix: String?) : UIKitNavbar("dropdown${suffix ?.let { "-$it" } ?: ""}") {
|
||||
sealed class UIKitNavbar(vararg classes: String) : UIKitModifier {
|
||||
override val classes: Array<String> = classes as Array<String>
|
||||
|
||||
object Transparent : UIKitNavbar("uk-navbar-transparent")
|
||||
object Container : UIKitNavbar("uk-navbar-container")
|
||||
sealed class Dropdown(suffix: String?) : UIKitNavbar("uk-navbar-dropdown${suffix ?.let { "-$it" } ?: ""}") {
|
||||
object Nav : Dropdown("nav")
|
||||
|
||||
sealed class Width(suffix: String) : Dropdown(suffix) {
|
||||
object Two : Width("width-2")
|
||||
object Three : Width("width-3")
|
||||
object Four : Width("width-4")
|
||||
object Five : Width("width-5")
|
||||
}
|
||||
|
||||
companion object : Dropdown(null)
|
||||
}
|
||||
object Item : UIKitNavbar("item")
|
||||
sealed class Alignment(val suffix: String) : UIKitNavbar("uk-navbar-$suffix") {
|
||||
object Left : Alignment("left")
|
||||
sealed class Center(suffix: String) : Alignment(suffix) {
|
||||
object Left : Center("center-left")
|
||||
object Right : Center("center-right")
|
||||
|
||||
companion object {
|
||||
companion object : Center("center")
|
||||
}
|
||||
object Right : Alignment("right")
|
||||
}
|
||||
object Item : UIKitNavbar("uk-navbar-item")
|
||||
object Nav : UIKitNavbar("uk-navbar-nav")
|
||||
object Subtitle : UIKitNavbar("uk-navbar-subtitle")
|
||||
object Toggle : UIKitNavbar("uk-navbar-toggle")
|
||||
object Sticky : UIKitNavbar("uk-navbar-sticky")
|
||||
|
||||
class Component internal constructor(
|
||||
override val otherAttrs: Map<String, String>
|
||||
) : UIKitNavbar(*UIKitNavbar.classes)
|
||||
|
||||
companion object : UIKitNavbar("uk-navbar") {
|
||||
val Logo = UIKitUtility.Logo
|
||||
|
||||
operator fun invoke(
|
||||
align: String?,
|
||||
mode: String? = null,
|
||||
delayShow: Milliseconds? = null,
|
||||
delayHide: Milliseconds? = null,
|
||||
boundary: String? = null,
|
||||
boundaryAlign: Boolean? = null,
|
||||
offset: Pixels? = null,
|
||||
dropbar: Boolean? = null,
|
||||
duration: Milliseconds? = null
|
||||
): Component {
|
||||
return Component(
|
||||
mapOf(
|
||||
buildAttribute(UIKitNavbar.classes.first()) {
|
||||
"align" to align
|
||||
"mode" to mode
|
||||
"delay-show" to delayShow
|
||||
"delay-hide" to delayHide
|
||||
"boundary" to boundary
|
||||
"boundary-align" to boundaryAlign
|
||||
"offset" to offset
|
||||
"dropbar" to dropbar
|
||||
"duration" to duration
|
||||
}
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
operator fun invoke(
|
||||
align: Alignment? = null,
|
||||
mode: UIKitDropdown.Mode? = null,
|
||||
delayShow: Milliseconds? = null,
|
||||
delayHide: Milliseconds? = null,
|
||||
boundary: String? = null,
|
||||
boundaryAlign: Boolean? = null,
|
||||
offset: Pixels? = null,
|
||||
dropbar: Boolean? = null,
|
||||
duration: Milliseconds? = null
|
||||
): Component = invoke(align ?.suffix, mode ?.name, delayShow, delayHide, boundary, boundaryAlign, offset, dropbar, duration)
|
||||
}
|
||||
}
|
||||
|
||||
16
src/jsMain/kotlin/dev/inmo/jsuikit/modifiers/UIKitOverlay.kt
Normal file
16
src/jsMain/kotlin/dev/inmo/jsuikit/modifiers/UIKitOverlay.kt
Normal file
@@ -0,0 +1,16 @@
|
||||
package dev.inmo.jsuikit.modifiers
|
||||
|
||||
sealed class UIKitOverlay(
|
||||
override val classes: Array<String> = emptyArray(),
|
||||
override val otherAttrs: Map<String, String> = emptyMap()
|
||||
) : UIKitModifier {
|
||||
|
||||
object Default : UIKitOverlay(arrayOf("uk-overlay-default"))
|
||||
object Primary : UIKitOverlay(arrayOf("uk-overlay-primary"))
|
||||
object Icon : UIKitOverlay(arrayOf("uk-overlay-icon"))
|
||||
|
||||
companion object : UIKitOverlay(
|
||||
arrayOf("uk-overlay")
|
||||
)
|
||||
|
||||
}
|
||||
@@ -8,7 +8,10 @@ sealed class UIKitPadding(suffix: String?) : UIKitModifier {
|
||||
object Small : Size("small")
|
||||
object Large : Size("large")
|
||||
|
||||
companion object : Size(null)
|
||||
companion object : Size(null) {
|
||||
val Default
|
||||
get() = this
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -25,5 +28,6 @@ sealed class UIKitPadding(suffix: String?) : UIKitModifier {
|
||||
|
||||
}
|
||||
|
||||
companion object : Size(null)
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
package dev.inmo.jsuikit.modifiers
|
||||
|
||||
object UIKitPlaceholder : UIKitModifier {
|
||||
override val classes: Array<String> = arrayOf("uk-placeholder")
|
||||
}
|
||||
@@ -20,3 +20,12 @@ sealed class UIKitScreenSizeModifier(val name: String) {
|
||||
}
|
||||
|
||||
fun UIKitModifier.applyWhenScreenSizeIs(size: UIKitScreenSizeModifier) = size.modify(this)
|
||||
|
||||
val UIKitModifier.onSmallScreens
|
||||
get() = applyWhenScreenSizeIs(UIKitScreenSizeModifier.Small)
|
||||
val UIKitModifier.onMediumScreens
|
||||
get() = applyWhenScreenSizeIs(UIKitScreenSizeModifier.Medium)
|
||||
val UIKitModifier.onLargeScreens
|
||||
get() = applyWhenScreenSizeIs(UIKitScreenSizeModifier.Large)
|
||||
val UIKitModifier.onXLargeScreens
|
||||
get() = applyWhenScreenSizeIs(UIKitScreenSizeModifier.XLarge)
|
||||
|
||||
23
src/jsMain/kotlin/dev/inmo/jsuikit/modifiers/UIKitSection.kt
Normal file
23
src/jsMain/kotlin/dev/inmo/jsuikit/modifiers/UIKitSection.kt
Normal file
@@ -0,0 +1,23 @@
|
||||
package dev.inmo.jsuikit.modifiers
|
||||
|
||||
sealed class UIKitSection(vararg classes: String) : UIKitModifier {
|
||||
override val classes: Array<String> = classes as Array<String>
|
||||
|
||||
sealed class Style(suffix: String) : UIKitSection("uk-section-$suffix") {
|
||||
object Default : Style("default")
|
||||
object Muted : Style("muted")
|
||||
object Primary : Style("primary")
|
||||
object Secondary : Style("secondary")
|
||||
}
|
||||
|
||||
sealed class Size(suffix: String) : UIKitSection("uk-section-$suffix") {
|
||||
object XSmall : Size("xsmall")
|
||||
object Small : Size("small")
|
||||
object Large : Size("large")
|
||||
object XLarge : Size("xlarge")
|
||||
}
|
||||
|
||||
object Overlap : UIKitSection("uk-section-overlap")
|
||||
|
||||
companion object : UIKitSection("uk-section")
|
||||
}
|
||||
47
src/jsMain/kotlin/dev/inmo/jsuikit/modifiers/UIKitSticky.kt
Normal file
47
src/jsMain/kotlin/dev/inmo/jsuikit/modifiers/UIKitSticky.kt
Normal file
@@ -0,0 +1,47 @@
|
||||
package dev.inmo.jsuikit.modifiers
|
||||
|
||||
import dev.inmo.jsuikit.utils.buildAttribute
|
||||
import org.jetbrains.compose.web.css.CSSUnitLengthOrPercentage
|
||||
import org.jetbrains.compose.web.css.CSSUnitValueTyped
|
||||
|
||||
class UIKitSticky(
|
||||
position: Position? = null,
|
||||
start: String? = null,
|
||||
end: String? = null,
|
||||
offset: CSSUnitValueTyped<CSSUnitLengthOrPercentage>? = null,
|
||||
overflowFlip: Boolean? = null,
|
||||
animation: UIKitAnimation? = null,
|
||||
classForActiveItems: String? = null,
|
||||
classForInactiveItems: String? = null,
|
||||
showOnUp: Boolean? = null,
|
||||
media: String? = null,
|
||||
targetOffset: CSSUnitValueTyped<CSSUnitLengthOrPercentage>? = null
|
||||
) : UIKitModifier {
|
||||
override val otherAttrs: Map<String, String> = mapOf(
|
||||
buildAttribute("uk-sticky") {
|
||||
"position" to position ?.name
|
||||
"start" to start
|
||||
"end" to end
|
||||
"offset" to offset ?.toString()
|
||||
"overflow-flip" to overflowFlip
|
||||
"animation" to animation
|
||||
"cls-active" to classForActiveItems
|
||||
"cls-inactive" to classForInactiveItems
|
||||
"show-on-up" to showOnUp
|
||||
"media" to media
|
||||
"target-offset" to targetOffset ?.toString()
|
||||
}
|
||||
)
|
||||
|
||||
sealed interface Position {
|
||||
val name: String
|
||||
object Top : Position {
|
||||
override val name: String
|
||||
get() = "top"
|
||||
}
|
||||
object Bottom : Position {
|
||||
override val name: String
|
||||
get() = "bottom"
|
||||
}
|
||||
}
|
||||
}
|
||||
51
src/jsMain/kotlin/dev/inmo/jsuikit/modifiers/UIKitTab.kt
Normal file
51
src/jsMain/kotlin/dev/inmo/jsuikit/modifiers/UIKitTab.kt
Normal file
@@ -0,0 +1,51 @@
|
||||
package dev.inmo.jsuikit.modifiers
|
||||
|
||||
import dev.inmo.jsuikit.utils.buildAttribute
|
||||
import org.jetbrains.compose.web.css.selectors.CSSSelector
|
||||
import kotlin.time.Duration
|
||||
|
||||
sealed class UIKitTab(
|
||||
override val classes: Array<String> = emptyArray(),
|
||||
override val otherAttrs: Map<String, String> = emptyMap()
|
||||
) : UIKitModifier {
|
||||
sealed class Position(
|
||||
classes: Array<String> = emptyArray(),
|
||||
otherAttrs: Map<String, String> = emptyMap()
|
||||
) : UIKitTab(classes, otherAttrs) {
|
||||
object Bottom : Position(arrayOf("uk-tab-bottom"))
|
||||
object Left : Position(arrayOf("uk-tab-left"))
|
||||
object Right : Position(arrayOf("uk-tab-right"))
|
||||
}
|
||||
|
||||
class Custom(
|
||||
connect: CSSSelector? = null,
|
||||
toggle: CSSSelector? = null,
|
||||
active: Int? = null,
|
||||
animationsIn: Array<UIKitAnimation>? = null,
|
||||
animationsOut: Array<UIKitAnimation>? = null,
|
||||
animationDuration: Duration? = null,
|
||||
swiping: Boolean? = null,
|
||||
media: String? = null
|
||||
) : UIKitTab(
|
||||
arrayOf("uk-tab"),
|
||||
mapOf(
|
||||
buildAttribute("uk-tab") {
|
||||
"connect" to connect
|
||||
"toggle" to toggle
|
||||
"active" to active
|
||||
"animation" to (
|
||||
(animationsIn ?.let {
|
||||
it.joinToString(" ") { it.name }
|
||||
} ?: "") + (animationsOut ?.let {
|
||||
it.joinToString(" ", ",") { it.name }
|
||||
} ?: "")
|
||||
).takeIf { it.isNotBlank() }
|
||||
"duration" to animationDuration
|
||||
"swiping" to swiping
|
||||
"media" to media
|
||||
}
|
||||
)
|
||||
)
|
||||
|
||||
companion object : UIKitTab(arrayOf("uk-tab"), mapOf("uk-tab" to ""))
|
||||
}
|
||||
15
src/jsMain/kotlin/dev/inmo/jsuikit/modifiers/UIKitTile.kt
Normal file
15
src/jsMain/kotlin/dev/inmo/jsuikit/modifiers/UIKitTile.kt
Normal file
@@ -0,0 +1,15 @@
|
||||
package dev.inmo.jsuikit.modifiers
|
||||
|
||||
sealed class UIKitTile(
|
||||
override val classes: Array<String> = emptyArray(),
|
||||
override val otherAttrs: Map<String, String> = emptyMap()
|
||||
) : UIKitModifier {
|
||||
|
||||
object Default : UIKitTile(arrayOf("uk-tile-default"))
|
||||
object Muted : UIKitTile(arrayOf("uk-tile-muted"))
|
||||
object Primary : UIKitTile(arrayOf("uk-tile-primary"))
|
||||
object Secondary : UIKitTile(arrayOf("uk-tile-secondary"))
|
||||
|
||||
companion object : UIKitTile(arrayOf("uk-tile"))
|
||||
|
||||
}
|
||||
@@ -38,7 +38,7 @@ sealed class UIKitToggle(
|
||||
|
||||
class Custom internal constructor(otherAttrs: Map<String, String>) : UIKitToggle(otherAttrs = otherAttrs)
|
||||
|
||||
companion object {
|
||||
companion object : UIKitToggle(otherAttrs = mapOf("uk-toggle" to "")) {
|
||||
operator fun invoke(
|
||||
target: String? = null,
|
||||
mode: Mode? = null,
|
||||
|
||||
@@ -38,7 +38,10 @@ sealed class UIKitUtility(classname: String) : UIKitModifier {
|
||||
object Width : Responsive("width")
|
||||
object Height : Responsive("height")
|
||||
}
|
||||
object PreserveWidth : UIKitUtility("uk-preserve-width")
|
||||
sealed class Preserve(suffix: String) : UIKitUtility("uk-preserve-$suffix") {
|
||||
object Width : Preserve("width")
|
||||
object Color : Preserve("color")
|
||||
}
|
||||
|
||||
sealed class Border(suffix: String) : UIKitUtility("uk-border-$suffix") {
|
||||
object Rounded : Border("rounded")
|
||||
@@ -111,4 +114,9 @@ sealed class UIKitUtility(classname: String) : UIKitModifier {
|
||||
object Active : UIKitUtility("uk-active")
|
||||
|
||||
object Open : UIKitUtility("uk-open")
|
||||
object Link : UIKitUtility("uk-link")
|
||||
|
||||
companion object {
|
||||
val PreserveWidth = Preserve.Width
|
||||
}
|
||||
}
|
||||
|
||||
44
src/jsMain/kotlin/dev/inmo/jsuikit/types/Dropdown.kt
Normal file
44
src/jsMain/kotlin/dev/inmo/jsuikit/types/Dropdown.kt
Normal file
@@ -0,0 +1,44 @@
|
||||
package dev.inmo.jsuikit.types
|
||||
|
||||
import dev.inmo.jsuikit.modifiers.UIKitAnimation
|
||||
import dev.inmo.jsuikit.modifiers.UIKitDropdown
|
||||
import dev.inmo.jsuikit.utils.*
|
||||
|
||||
external interface Dropdown {
|
||||
fun show()
|
||||
fun hide(delay: Boolean = definedExternally)
|
||||
fun hide(delay: Milliseconds)
|
||||
}
|
||||
|
||||
data class DropdownOptions(
|
||||
private val toggle: String? = null,
|
||||
private val pos: UIKitDropdown.Position? = null,
|
||||
private val mode: UIKitDropdown.Mode? = null,
|
||||
private val delayShow: Milliseconds? = null,
|
||||
private val delayHide: Milliseconds? = null,
|
||||
private val boundary: String? = null,
|
||||
private val boundaryAlign: Boolean? = null,
|
||||
private val flip: UIKitDropdown.Flip? = null,
|
||||
private val offset: Int? = null,
|
||||
private val animation: UIKitAnimation? = null,
|
||||
private val duration: Milliseconds? = null,
|
||||
) {
|
||||
fun includeParameters(parametersBuilder: ParametersBuilder) {
|
||||
with(parametersBuilder) {
|
||||
"toggle" to toggle
|
||||
"pos" to pos
|
||||
"mode" to mode
|
||||
"delayShow" to delayShow
|
||||
"delayHide" to delayHide
|
||||
"boundary" to boundary
|
||||
"boundaryAlign" to boundaryAlign
|
||||
"flip" to flip
|
||||
"offset" to offset
|
||||
"animation" to animation
|
||||
"duration" to duration
|
||||
}
|
||||
}
|
||||
fun parameters() = buildParametersWithoutNulls {
|
||||
includeParameters(this)
|
||||
}
|
||||
}
|
||||
19
src/jsMain/kotlin/dev/inmo/jsuikit/types/UIKit.kt
Normal file
19
src/jsMain/kotlin/dev/inmo/jsuikit/types/UIKit.kt
Normal file
@@ -0,0 +1,19 @@
|
||||
package dev.inmo.jsuikit.types
|
||||
|
||||
import org.w3c.dom.Element
|
||||
import kotlin.js.Json
|
||||
|
||||
external interface UIKit {
|
||||
val notification: UIKitNotifications
|
||||
val modal: UIKitDialogs
|
||||
|
||||
|
||||
fun notification(message: String, parameters: Json)
|
||||
fun notification(element: Element): UIKitNotification?
|
||||
|
||||
fun modal(element: Element): UIKitDialog
|
||||
fun modal(selector: String): UIKitDialog?
|
||||
|
||||
fun dropdown(element: Element, options: DropdownOptions = definedExternally): Dropdown
|
||||
fun dropdown(selector: String, options: DropdownOptions = definedExternally): Dropdown?
|
||||
}
|
||||
38
src/jsMain/kotlin/dev/inmo/jsuikit/types/UIKitDialog.kt
Normal file
38
src/jsMain/kotlin/dev/inmo/jsuikit/types/UIKitDialog.kt
Normal file
@@ -0,0 +1,38 @@
|
||||
package dev.inmo.jsuikit.types
|
||||
|
||||
import org.w3c.dom.Element
|
||||
import kotlin.js.Promise
|
||||
|
||||
external interface UIKitDialogs {
|
||||
fun alert(text: String): UIKitDialogPromiseAlert
|
||||
fun confirm(text: String): UIKitDialogPromiseConfirm
|
||||
fun prompt(title: String): UIKitDialogPromisePrompt
|
||||
fun prompt(title: String, preset: String): UIKitDialogPromisePrompt
|
||||
fun dialog(element: Element): UIKitDialog
|
||||
}
|
||||
|
||||
external class UIKitDialogPromiseConfirm : Promise<Unit> {
|
||||
val dialog: UIKitDialog
|
||||
|
||||
fun then(
|
||||
onConfirm: () -> Unit = definedExternally,
|
||||
onRejected: () -> Unit = definedExternally,
|
||||
)
|
||||
}
|
||||
|
||||
external class UIKitDialogPromisePrompt : Promise<Unit> {
|
||||
val dialog: UIKitDialog
|
||||
|
||||
fun then(onResult: (data: String?) -> Unit)
|
||||
}
|
||||
|
||||
external class UIKitDialogPromiseAlert : Promise<Unit> {
|
||||
val dialog: UIKitDialog
|
||||
|
||||
fun then(onClose: () -> Unit)
|
||||
}
|
||||
|
||||
external interface UIKitDialog {
|
||||
fun show()
|
||||
fun hide()
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
package dev.inmo.jsuikit.types
|
||||
|
||||
sealed class UIKitNotificationParameter {
|
||||
abstract val parameterName: String
|
||||
abstract val parameterValue: String
|
||||
|
||||
sealed class Style(override val parameterValue: String) : UIKitNotificationParameter() {
|
||||
override val parameterName: String
|
||||
get() = "status"
|
||||
|
||||
object Primary : Style("primary")
|
||||
object Success : Style("success")
|
||||
object Warning : Style("warning")
|
||||
object Danger : Style("danger")
|
||||
|
||||
}
|
||||
|
||||
sealed class Position(override val parameterValue: String) : UIKitNotificationParameter() {
|
||||
override val parameterName: String
|
||||
get() = "pos"
|
||||
|
||||
sealed class Top(parameterValue: String) : Position("top-$parameterValue") {
|
||||
|
||||
object Left : Top("left")
|
||||
object Center : Top("center")
|
||||
object Right : Top("right")
|
||||
|
||||
}
|
||||
|
||||
sealed class Bottom(parameterValue: String) : Position("bottom-$parameterValue") {
|
||||
|
||||
object Left : Bottom("left")
|
||||
object Center : Bottom("center")
|
||||
object Right : Bottom("right")
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
package dev.inmo.jsuikit.types
|
||||
|
||||
import dev.inmo.jsuikit.modifiers.UIKit
|
||||
import dev.inmo.jsuikit.utils.Milliseconds
|
||||
import kotlin.js.json
|
||||
|
||||
typealias NotificationsGroup = String
|
||||
|
||||
external interface UIKitNotifications {
|
||||
|
||||
fun closeAll(group: NotificationsGroup)
|
||||
}
|
||||
|
||||
external interface UIKitNotification {
|
||||
fun close(immediate: Boolean)
|
||||
}
|
||||
|
||||
data class UIKitNotificationsParameters(
|
||||
val status: UIKitNotificationParameter.Style? = null,
|
||||
val timeout: Milliseconds? = null,
|
||||
val group: NotificationsGroup? = null,
|
||||
val position: UIKitNotificationParameter.Position? = null
|
||||
) {
|
||||
fun parametersJson() = json(
|
||||
*listOfNotNull(
|
||||
status ?.let { it.parameterName to it.parameterValue },
|
||||
timeout ?.let { "timeout" to timeout.toString() },
|
||||
group ?.let { "group" to it },
|
||||
position ?.let { it.parameterName to it.parameterValue },
|
||||
).toTypedArray()
|
||||
)
|
||||
}
|
||||
|
||||
operator fun UIKitNotifications.invoke(
|
||||
message: String,
|
||||
parameters: UIKitNotificationsParameters
|
||||
) = UIKit.notification(message, parameters.parametersJson())
|
||||
|
||||
operator fun UIKitNotifications.invoke(
|
||||
message: String,
|
||||
status: UIKitNotificationParameter.Style? = null,
|
||||
timeout: Milliseconds? = null,
|
||||
group: NotificationsGroup? = null,
|
||||
position: UIKitNotificationParameter.Position? = null
|
||||
) = invoke(message, UIKitNotificationsParameters(status, timeout, group, position))
|
||||
@@ -2,26 +2,24 @@ package dev.inmo.jsuikit.utils
|
||||
|
||||
class AttributeBuilder (
|
||||
val attributeName: String,
|
||||
val skipNullValues: Boolean = true,
|
||||
private val parametersPreset: MutableMap<String, String?> = mutableMapOf()
|
||||
val parametersBuilder: ParametersBuilder
|
||||
) {
|
||||
|
||||
fun add(k: String, v: Any? = null) {
|
||||
if (v != null || !skipNullValues) {
|
||||
parametersPreset[k] = v ?.toString()
|
||||
}
|
||||
fun build(): Pair<String, String> = parametersBuilder.build().run {
|
||||
Pair(
|
||||
attributeName, toList().joinToString(";") {
|
||||
"${it.first}${it.second ?.let { ": $it" } ?: ""}"
|
||||
}
|
||||
)
|
||||
}
|
||||
infix fun String.to(value: Any?) = add(this, value)
|
||||
operator fun String.unaryPlus() = add(this, null)
|
||||
|
||||
fun build(): Pair<String, String> = Pair(
|
||||
attributeName, parametersPreset.toList().joinToString(";") {
|
||||
"${it.first}${it.second ?.let { ": $it" } ?: ""}"
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
inline fun buildAttribute(attributeName: String, skipNullValues: Boolean = true, block: AttributeBuilder.() -> Unit) = AttributeBuilder(
|
||||
inline fun buildAttribute(
|
||||
attributeName: String,
|
||||
skipNullValues: Boolean = true,
|
||||
block: ParametersBuilder.() -> Unit
|
||||
) = AttributeBuilder(
|
||||
attributeName,
|
||||
skipNullValues
|
||||
).apply(block).build()
|
||||
ParametersBuilder(skipNullValues)
|
||||
).apply {
|
||||
parametersBuilder.block()
|
||||
}.build()
|
||||
|
||||
@@ -2,20 +2,23 @@ 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.attributes.AttrsScope
|
||||
import org.jetbrains.compose.web.attributes.HtmlAttrMarker
|
||||
import org.jetbrains.compose.web.attributes.builders.InputAttrsScope
|
||||
import org.jetbrains.compose.web.dom.AttrBuilderContext
|
||||
import org.w3c.dom.Element
|
||||
import org.w3c.dom.HTMLInputElement
|
||||
|
||||
class AttributesCollection<T : Element> (
|
||||
private vararg val modifiers: UIKitModifier,
|
||||
private val attrs: AttrBuilderContext<T> = {}
|
||||
class AttributesCollection<T : Element, Builder : AttrsScope<T>> (
|
||||
private vararg val modifiers: UIKitModifier?,
|
||||
private val attrs: Builder.() -> Unit = {}
|
||||
) {
|
||||
val builder: AttrBuilderContext<T> = {
|
||||
val builder: Builder.() -> Unit = {
|
||||
include(*modifiers)
|
||||
attrs()
|
||||
}
|
||||
|
||||
operator fun plus(other: AttributesCollection<T>) = AttributesCollection<T>(
|
||||
operator fun plus(other: AttributesCollection<T, Builder>) = AttributesCollection<T, Builder>(
|
||||
*(modifiers + other.modifiers).distinct().toTypedArray()
|
||||
) {
|
||||
this@AttributesCollection.attrs.invoke(this)
|
||||
@@ -26,8 +29,9 @@ class AttributesCollection<T : Element> (
|
||||
val Empty = Attrs<Element>()
|
||||
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
fun <T : Element> empty() = Empty as Attrs<T>
|
||||
fun <T : Element, Builder : AttrsScope<T>> empty() = Empty as AttributesCollection<T, Builder>
|
||||
}
|
||||
}
|
||||
|
||||
typealias Attrs<T> = AttributesCollection<T>
|
||||
typealias Attrs<T> = AttributesCollection<T, AttrsScope<T>>
|
||||
typealias InputAttrs<T> = AttributesCollection<HTMLInputElement, InputAttrsScope<T>>
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
package dev.inmo.jsuikit.utils
|
||||
|
||||
import dev.inmo.jsuikit.modifiers.UIKitModifier
|
||||
import org.jetbrains.compose.web.attributes.AttrsScope
|
||||
import org.jetbrains.compose.web.dom.ContentBuilder
|
||||
import org.w3c.dom.Element
|
||||
|
||||
typealias AttrsWithContentBuilder<T> = Pair<Attrs<T>, ContentBuilder<T>>
|
||||
|
||||
@Suppress("NOTHING_TO_INLINE")
|
||||
inline fun <T : Element> AttrsWithContentBuilder(
|
||||
vararg modifiers: UIKitModifier?,
|
||||
noinline attrs: AttrsScope<T>.() -> Unit = {},
|
||||
noinline builder: ContentBuilder<T>
|
||||
) = AttrsWithContentBuilder(
|
||||
Attrs(*modifiers, attrs = attrs),
|
||||
builder
|
||||
)
|
||||
|
||||
@Suppress("NOTHING_TO_INLINE")
|
||||
inline fun <T : Element> AttrsWithContentBuilder(attrs: Attrs<T>) = AttrsWithContentBuilder(
|
||||
attrs
|
||||
) {}
|
||||
|
||||
inline val <T : Element> AttrsWithContentBuilder<T>.attrs
|
||||
get() = first
|
||||
|
||||
inline val <T : Element> AttrsWithContentBuilder<T>.attributesBuilderContext
|
||||
get() = attrs.builder
|
||||
|
||||
inline val <T : Element> AttrsWithContentBuilder<T>.builder
|
||||
get() = second
|
||||
@@ -4,13 +4,19 @@ import androidx.compose.runtime.Composable
|
||||
import org.jetbrains.compose.web.dom.ContentBuilder
|
||||
import org.w3c.dom.Element
|
||||
|
||||
@Composable
|
||||
inline fun optionallyDraw (
|
||||
vararg bools: Boolean,
|
||||
whatToDraw: @Composable () -> Unit
|
||||
) {
|
||||
if (bools.any { it }) {
|
||||
whatToDraw()
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
inline fun <T : Element> optionallyDraw (
|
||||
attrs: Attrs<T>? = null,
|
||||
noinline contentBuilder: ContentBuilder<T>? = null,
|
||||
whatToDraw: @Composable () -> Unit
|
||||
) {
|
||||
if (attrs != null || contentBuilder != null) {
|
||||
whatToDraw()
|
||||
}
|
||||
}
|
||||
) = optionallyDraw(attrs != null || contentBuilder != null, whatToDraw = whatToDraw)
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
package dev.inmo.jsuikit.utils
|
||||
|
||||
import dev.inmo.jsuikit.modifiers.AttributeValue
|
||||
|
||||
|
||||
class ParametersBuilder(
|
||||
val skipNullValues: Boolean = true,
|
||||
private val parameters: MutableMap<String, String?> = mutableMapOf()
|
||||
) {
|
||||
fun add(k: String, v: Any? = null) {
|
||||
when {
|
||||
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)
|
||||
operator fun String.unaryPlus() = add(this, null)
|
||||
|
||||
operator fun Map<String, String?>.unaryPlus() = forEach {
|
||||
|
||||
}
|
||||
|
||||
fun build() = parameters.toMap()
|
||||
fun buildNotNullable() = parameters.mapNotNull { (k, v) ->
|
||||
if (v != null) {
|
||||
Pair(k, v)
|
||||
} else {
|
||||
null
|
||||
}
|
||||
}.toMap()
|
||||
}
|
||||
|
||||
fun buildParameters(
|
||||
skipNullValues: Boolean = true,
|
||||
block: ParametersBuilder.() -> Unit
|
||||
) = ParametersBuilder(skipNullValues).apply(block).build()
|
||||
|
||||
fun buildParametersWithoutNulls(
|
||||
skipNullValues: Boolean = true,
|
||||
block: ParametersBuilder.() -> Unit
|
||||
) = ParametersBuilder(skipNullValues).apply(block).buildNotNullable()
|
||||
Reference in New Issue
Block a user