diff options
author | Robert Jaros <rjaros@finn.pl> | 2019-01-16 18:34:59 +0100 |
---|---|---|
committer | Robert Jaros <rjaros@finn.pl> | 2019-01-16 18:34:59 +0100 |
commit | 9f70d8151c4c47c6ae250ec21d579ed3ba7faf14 (patch) | |
tree | 2c5369adaf342b60ef17fede28587546f4f1582e /kvision-modules/kvision-select/src/main/kotlin/pl/treksoft | |
parent | d949053896fd832b4d45e1ca57de802000674767 (diff) | |
download | kvision-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/main/kotlin/pl/treksoft')
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 + } + + } } |