aboutsummaryrefslogtreecommitdiff
path: root/kvision-modules/kvision-select/src
diff options
context:
space:
mode:
authorRobert Jaros <rjaros@finn.pl>2019-01-16 18:34:59 +0100
committerRobert Jaros <rjaros@finn.pl>2019-01-16 18:34:59 +0100
commit9f70d8151c4c47c6ae250ec21d579ed3ba7faf14 (patch)
tree2c5369adaf342b60ef17fede28587546f4f1582e /kvision-modules/kvision-select/src
parentd949053896fd832b4d45e1ca57de802000674767 (diff)
downloadkvision-9f70d8151c4c47c6ae250ec21d579ed3ba7faf14.tar.gz
kvision-9f70d8151c4c47c6ae250ec21d579ed3ba7faf14.tar.bz2
kvision-9f70d8151c4c47c6ae250ec21d579ed3ba7faf14.zip
DSL builder functions for SelectOption and SelectOptGroup.
Diffstat (limited to 'kvision-modules/kvision-select/src')
-rw-r--r--kvision-modules/kvision-select/src/main/kotlin/pl/treksoft/kvision/form/select/SelectOptGroup.kt32
-rw-r--r--kvision-modules/kvision-select/src/main/kotlin/pl/treksoft/kvision/form/select/SelectOption.kt63
2 files changed, 95 insertions, 0 deletions
diff --git a/kvision-modules/kvision-select/src/main/kotlin/pl/treksoft/kvision/form/select/SelectOptGroup.kt b/kvision-modules/kvision-select/src/main/kotlin/pl/treksoft/kvision/form/select/SelectOptGroup.kt
index d90f0e6d..3f07a9bf 100644
--- a/kvision-modules/kvision-select/src/main/kotlin/pl/treksoft/kvision/form/select/SelectOptGroup.kt
+++ b/kvision-modules/kvision-select/src/main/kotlin/pl/treksoft/kvision/form/select/SelectOptGroup.kt
@@ -88,4 +88,36 @@ open class SelectOptGroup(
}
return sn
}
+
+ companion object {
+ /**
+ * DSL builder extension function.
+ *
+ * It takes the same parameters as the constructor of the built component.
+ */
+ fun Select.selectOptGroup(
+ label: String, options: List<StringPair>? = null, maxOptions: Int? = null,
+ disabled: Boolean = false, classes: Set<String> = setOf(), init: (SelectOptGroup.() -> Unit)? = null
+ ): SelectOptGroup {
+ val selectOptGroup =
+ SelectOptGroup(label, options, maxOptions, disabled, classes).apply { init?.invoke(this) }
+ this.add(selectOptGroup)
+ return selectOptGroup
+ }
+
+ /**
+ * DSL builder extension function.
+ *
+ * It takes the same parameters as the constructor of the built component.
+ */
+ fun SelectInput.selectOptGroup(
+ label: String, options: List<StringPair>? = null, maxOptions: Int? = null,
+ disabled: Boolean = false, classes: Set<String> = setOf(), init: (SelectOptGroup.() -> Unit)? = null
+ ): SelectOptGroup {
+ val selectOptGroup =
+ SelectOptGroup(label, options, maxOptions, disabled, classes).apply { init?.invoke(this) }
+ this.add(selectOptGroup)
+ return selectOptGroup
+ }
+ }
}
diff --git a/kvision-modules/kvision-select/src/main/kotlin/pl/treksoft/kvision/form/select/SelectOption.kt b/kvision-modules/kvision-select/src/main/kotlin/pl/treksoft/kvision/form/select/SelectOption.kt
index da6ac405..f51daafb 100644
--- a/kvision-modules/kvision-select/src/main/kotlin/pl/treksoft/kvision/form/select/SelectOption.kt
+++ b/kvision-modules/kvision-select/src/main/kotlin/pl/treksoft/kvision/form/select/SelectOption.kt
@@ -107,4 +107,67 @@ open class SelectOption(
}
return sn
}
+
+ companion object {
+ /**
+ * DSL builder extension function.
+ *
+ * It takes the same parameters as the constructor of the built component.
+ */
+ fun Select.selectOption(
+ value: String? = null, label: String? = null, subtext: String? = null, icon: String? = null,
+ divider: Boolean = false, disabled: Boolean = false, selected: Boolean = false,
+ classes: Set<String> = setOf(), init: (SelectOption.() -> Unit)? = null
+ ): SelectOption {
+ val selectOption =
+ SelectOption(value, label, subtext, icon, divider, disabled, selected, classes).apply {
+ init?.invoke(
+ this
+ )
+ }
+ this.add(selectOption)
+ return selectOption
+ }
+
+ /**
+ * DSL builder extension function.
+ *
+ * It takes the same parameters as the constructor of the built component.
+ */
+ fun SelectInput.selectOption(
+ value: String? = null, label: String? = null, subtext: String? = null, icon: String? = null,
+ divider: Boolean = false, disabled: Boolean = false, selected: Boolean = false,
+ classes: Set<String> = setOf(), init: (SelectOption.() -> Unit)? = null
+ ): SelectOption {
+ val selectOption =
+ SelectOption(value, label, subtext, icon, divider, disabled, selected, classes).apply {
+ init?.invoke(
+ this
+ )
+ }
+ this.add(selectOption)
+ return selectOption
+ }
+
+ /**
+ * DSL builder extension function.
+ *
+ * It takes the same parameters as the constructor of the built component.
+ */
+ fun SelectOptGroup.selectOption(
+ value: String? = null, label: String? = null, subtext: String? = null, icon: String? = null,
+ divider: Boolean = false, disabled: Boolean = false, selected: Boolean = false,
+ classes: Set<String> = setOf(), init: (SelectOption.() -> Unit)? = null
+ ): SelectOption {
+ val selectOption =
+ SelectOption(value, label, subtext, icon, divider, disabled, selected, classes).apply {
+ init?.invoke(
+ this
+ )
+ }
+ this.add(selectOption)
+ return selectOption
+ }
+
+ }
}