diff options
| author | Robert Jaros <rjaros@finn.pl> | 2018-02-12 10:50:42 +0100 |
|---|---|---|
| committer | Robert Jaros <rjaros@finn.pl> | 2018-02-12 10:50:42 +0100 |
| commit | bafcdb6fc3f1d4ec4f1a0f4fcce776ba10d8136c (patch) | |
| tree | 39288bdcb59ec48cb70f1c5820fc1854949744da /src/main/kotlin/pl/treksoft/kvision/form/text | |
| parent | 2feea5e7cf8d492663e826ebcfb0a58e61820352 (diff) | |
| download | kvision-bafcdb6fc3f1d4ec4f1a0f4fcce776ba10d8136c.tar.gz kvision-bafcdb6fc3f1d4ec4f1a0f4fcce776ba10d8136c.tar.bz2 kvision-bafcdb6fc3f1d4ec4f1a0f4fcce776ba10d8136c.zip | |
Type safe DSL builders
Diffstat (limited to 'src/main/kotlin/pl/treksoft/kvision/form/text')
7 files changed, 107 insertions, 1 deletions
diff --git a/src/main/kotlin/pl/treksoft/kvision/form/text/Password.kt b/src/main/kotlin/pl/treksoft/kvision/form/text/Password.kt index f3f50a63..39c9a306 100644 --- a/src/main/kotlin/pl/treksoft/kvision/form/text/Password.kt +++ b/src/main/kotlin/pl/treksoft/kvision/form/text/Password.kt @@ -21,6 +21,8 @@ */ package pl.treksoft.kvision.form.text +import pl.treksoft.kvision.core.Container + /** * Form field password component. * @@ -32,4 +34,17 @@ package pl.treksoft.kvision.form.text open class Password(value: String? = null, label: String? = null, rich: Boolean = false) : Text( TEXTINPUTTYPE.PASSWORD, value, label, rich -) +) { + companion object { + /** + * DSL builder extension function + * + * It takes the same parameters as the constructor of the built component. + */ + fun Container.password( + value: String? = null, label: String? = null, rich: Boolean = false, init: (Password.() -> Unit)? = null + ) { + this.add(Password(value, label, rich).apply { init?.invoke(this) }) + } + } +} diff --git a/src/main/kotlin/pl/treksoft/kvision/form/text/RichText.kt b/src/main/kotlin/pl/treksoft/kvision/form/text/RichText.kt index 39083577..9d5c8c49 100644 --- a/src/main/kotlin/pl/treksoft/kvision/form/text/RichText.kt +++ b/src/main/kotlin/pl/treksoft/kvision/form/text/RichText.kt @@ -21,6 +21,8 @@ */ package pl.treksoft.kvision.form.text +import pl.treksoft.kvision.core.Container + /** * Form field rich text component. * @@ -51,4 +53,17 @@ open class RichText( this.addInternal(input) this.addInternal(validationInfo) } + + companion object { + /** + * DSL builder extension function + * + * It takes the same parameters as the constructor of the built component. + */ + fun Container.richText( + value: String? = null, label: String? = null, rich: Boolean = false, init: (RichText.() -> Unit)? = null + ) { + this.add(RichText(value, label, rich).apply { init?.invoke(this) }) + } + } } diff --git a/src/main/kotlin/pl/treksoft/kvision/form/text/RichTextInput.kt b/src/main/kotlin/pl/treksoft/kvision/form/text/RichTextInput.kt index d90c5769..f802cc2a 100644 --- a/src/main/kotlin/pl/treksoft/kvision/form/text/RichTextInput.kt +++ b/src/main/kotlin/pl/treksoft/kvision/form/text/RichTextInput.kt @@ -23,6 +23,7 @@ package pl.treksoft.kvision.form.text import com.github.snabbdom.VNode import pl.treksoft.jquery.jQuery +import pl.treksoft.kvision.core.Container import pl.treksoft.kvision.core.StringPair import kotlin.browser.document @@ -108,4 +109,17 @@ open class RichTextInput(value: String? = null, classes: Set<String> = setOf()) override fun changeValue() { // disabled parent class functionality } + + companion object { + /** + * DSL builder extension function + * + * It takes the same parameters as the constructor of the built component. + */ + fun Container.richTextInput( + value: String? = null, classes: Set<String> = setOf(), init: (RichTextInput.() -> Unit)? = null + ) { + this.add(RichTextInput(value, classes).apply { init?.invoke(this) }) + } + } } diff --git a/src/main/kotlin/pl/treksoft/kvision/form/text/Text.kt b/src/main/kotlin/pl/treksoft/kvision/form/text/Text.kt index 298a3209..2878dc66 100644 --- a/src/main/kotlin/pl/treksoft/kvision/form/text/Text.kt +++ b/src/main/kotlin/pl/treksoft/kvision/form/text/Text.kt @@ -21,6 +21,8 @@ */ package pl.treksoft.kvision.form.text +import pl.treksoft.kvision.core.Container + /** * Form field text component. * @@ -60,4 +62,18 @@ open class Text( this.addInternal(input) this.addInternal(validationInfo) } + + companion object { + /** + * DSL builder extension function + * + * It takes the same parameters as the constructor of the built component. + */ + fun Container.text( + type: TEXTINPUTTYPE = TEXTINPUTTYPE.TEXT, value: String? = null, + label: String? = null, rich: Boolean = false, init: (Text.() -> Unit)? = null + ) { + this.add(Text(type, value, label, rich).apply { init?.invoke(this) }) + } + } } diff --git a/src/main/kotlin/pl/treksoft/kvision/form/text/TextArea.kt b/src/main/kotlin/pl/treksoft/kvision/form/text/TextArea.kt index 02a64136..e9575264 100644 --- a/src/main/kotlin/pl/treksoft/kvision/form/text/TextArea.kt +++ b/src/main/kotlin/pl/treksoft/kvision/form/text/TextArea.kt @@ -21,6 +21,8 @@ */ package pl.treksoft.kvision.form.text +import pl.treksoft.kvision.core.Container + /** * Form field textarea component. * @@ -69,4 +71,18 @@ open class TextArea( this.addInternal(input) this.addInternal(validationInfo) } + + companion object { + /** + * DSL builder extension function + * + * It takes the same parameters as the constructor of the built component. + */ + fun Container.textArea( + cols: Int? = null, rows: Int? = null, value: String? = null, + label: String? = null, rich: Boolean = false, init: (TextArea.() -> Unit)? = null + ) { + this.add(TextArea(cols, rows, value, label, rich).apply { init?.invoke(this) }) + } + } } diff --git a/src/main/kotlin/pl/treksoft/kvision/form/text/TextAreaInput.kt b/src/main/kotlin/pl/treksoft/kvision/form/text/TextAreaInput.kt index fd42de9c..64e0f17d 100644 --- a/src/main/kotlin/pl/treksoft/kvision/form/text/TextAreaInput.kt +++ b/src/main/kotlin/pl/treksoft/kvision/form/text/TextAreaInput.kt @@ -22,6 +22,7 @@ package pl.treksoft.kvision.form.text import com.github.snabbdom.VNode +import pl.treksoft.kvision.core.Container import pl.treksoft.kvision.core.StringPair /** @@ -80,4 +81,18 @@ open class TextAreaInput(cols: Int? = null, rows: Int? = null, value: String? = } return sn } + + companion object { + /** + * DSL builder extension function + * + * It takes the same parameters as the constructor of the built component. + */ + fun Container.textAreaInput( + cols: Int? = null, rows: Int? = null, value: String? = null, classes: Set<String> = setOf(), + init: (TextAreaInput.() -> Unit)? = null + ) { + this.add(TextAreaInput(cols, rows, value, classes).apply { init?.invoke(this) }) + } + } } diff --git a/src/main/kotlin/pl/treksoft/kvision/form/text/TextInput.kt b/src/main/kotlin/pl/treksoft/kvision/form/text/TextInput.kt index 72791239..cc443aa5 100644 --- a/src/main/kotlin/pl/treksoft/kvision/form/text/TextInput.kt +++ b/src/main/kotlin/pl/treksoft/kvision/form/text/TextInput.kt @@ -22,6 +22,7 @@ package pl.treksoft.kvision.form.text import com.github.snabbdom.VNode +import pl.treksoft.kvision.core.Container import pl.treksoft.kvision.core.StringPair /** @@ -84,4 +85,18 @@ open class TextInput(type: TEXTINPUTTYPE = TEXTINPUTTYPE.TEXT, value: String? = } return sn } + + companion object { + /** + * DSL builder extension function + * + * It takes the same parameters as the constructor of the built component. + */ + fun Container.textInput( + type: TEXTINPUTTYPE = TEXTINPUTTYPE.TEXT, value: String? = null, classes: Set<String> = setOf(), + init: (TextInput.() -> Unit)? = null + ) { + this.add(TextInput(type, value, classes).apply { init?.invoke(this) }) + } + } } |
