From 44c35c6778eaf63d0be4de5193cb034824b51703 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Thu, 17 Feb 2022 19:31:31 +0600 Subject: [PATCH] support of UIKitForm --- CHANGELOG.md | 1 + .../kotlin/dev/inmo/jsuikit/elements/Icon.kt | 8 +++ .../dev/inmo/jsuikit/modifiers/UIKitForm.kt | 58 +++++++++++++++++++ 3 files changed, 67 insertions(+) create mode 100644 src/jsMain/kotlin/dev/inmo/jsuikit/modifiers/UIKitForm.kt diff --git a/CHANGELOG.md b/CHANGELOG.md index f1a49f4..646ea91 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ * Add `Vertical` and `Horizontal` members in margins * Add `afterHeaderBuilder` and `beforeFooterBuilder` properties in `Dialog` fun * Add `UIKitCustom` to be able for simple creating of custom modifiers +* Add support of `UIKitForm` ## 0.0.35 diff --git a/src/jsMain/kotlin/dev/inmo/jsuikit/elements/Icon.kt b/src/jsMain/kotlin/dev/inmo/jsuikit/elements/Icon.kt index ab923af..f4162af 100644 --- a/src/jsMain/kotlin/dev/inmo/jsuikit/elements/Icon.kt +++ b/src/jsMain/kotlin/dev/inmo/jsuikit/elements/Icon.kt @@ -250,4 +250,12 @@ sealed class Icon(val name: String) { attributesCustomizer: AttrBuilderContext = {}, onClick: ((Event) -> Unit)? = null ) = invoke(*modifiers, type = UIKitIconType.Link, ratio = ratio, onClick = onClick, attributesCustomizer = attributesCustomizer) + + @Composable + fun drawAsFormInputPart( + vararg modifiers: UIKitModifier, + ratio: Float? = null, + attributesCustomizer: AttrBuilderContext = {}, + onClick: ((Event) -> Unit)? = null + ) = invoke(*modifiers, UIKitForm.Icon, ratio = ratio, onClick = onClick, attributesCustomizer = attributesCustomizer) } diff --git a/src/jsMain/kotlin/dev/inmo/jsuikit/modifiers/UIKitForm.kt b/src/jsMain/kotlin/dev/inmo/jsuikit/modifiers/UIKitForm.kt new file mode 100644 index 0000000..341a09e --- /dev/null +++ b/src/jsMain/kotlin/dev/inmo/jsuikit/modifiers/UIKitForm.kt @@ -0,0 +1,58 @@ +package dev.inmo.jsuikit.modifiers + +import dev.inmo.jsuikit.utils.buildAttribute + +sealed class UIKitForm( + vararg classnames: String, + override val otherAttrs: Map = emptyMap() +) : UIKitModifier { + @Suppress("UNCHECKED_CAST") + override val classes: Array = classnames as Array + + object Fieldset : UIKitForm("uk-fieldset") + object Legend : UIKitForm("uk-legend") + + object Input : UIKitForm("uk-input") + object Select : UIKitForm("uk-select") + object TextArea : UIKitForm("uk-textarea") + object Radio : UIKitForm("uk-radio", otherAttrs = mapOf("type" to "radio")) + object Checkbox : UIKitForm("uk-checkbox", otherAttrs = mapOf("type" to "checkbox")) + object Range : UIKitForm("uk-range", otherAttrs = mapOf("type" to "range")) + + sealed class State(vararg classnames: String) : UIKitForm(*classnames) { + object Danger : State("uk-form-danger") + object Success : State("uk-form-success") + } + sealed class Size(vararg classnames: String) : UIKitForm(*classnames) { + object Large : Size("uk-form-large") + object Default : Size() // :) + object Small : Size("uk-form-small") + } + sealed class Width(vararg classnames: String) : UIKitForm(*classnames) { + object Large : Width("uk-form-width-large") + object Medium : Width("uk-form-width-medium") + object Small : Width("uk-form-width-small") + object XSmall : Width("uk-form-width-xsmall") + } + + object Blank : UIKitForm("uk-form-blank") + + sealed class Layout(vararg classnames: String) : UIKitForm(*classnames) { + object Stacked : Layout("uk-form-stacked") + object Horizontal : Layout("uk-form-horizontal") + object Label : Layout("uk-form-label") + object Controls : Layout("uk-form-controls") + } + + object Icon : UIKitForm("uk-form-icon") + + class Custom( + target: String = "true" + ) : UIKitForm( + otherAttrs = mapOf( + buildAttribute("uk-form-custom") { + "target" to target + } + ) + ) +}