diff options
author | Robert Jaros <rjaros@finn.pl> | 2020-05-09 23:53:57 +0200 |
---|---|---|
committer | Robert Jaros <rjaros@finn.pl> | 2020-05-09 23:53:57 +0200 |
commit | 134cb687c4e05fd81a03b682505f9fb9d741a8d7 (patch) | |
tree | f9f41f28c01dc29d1d4fdd576cc9b21958fd9c3b /kvision-modules/kvision-bootstrap-select/src/main/kotlin/pl/treksoft/kvision | |
parent | 4a2aa49e0e561c1bc25aa962449fa2fcce9207ba (diff) | |
download | kvision-134cb687c4e05fd81a03b682505f9fb9d741a8d7.tar.gz kvision-134cb687c4e05fd81a03b682505f9fb9d741a8d7.tar.bz2 kvision-134cb687c4e05fd81a03b682505f9fb9d741a8d7.zip |
Add new className parameter to all DSL builder functions.
Diffstat (limited to 'kvision-modules/kvision-bootstrap-select/src/main/kotlin/pl/treksoft/kvision')
4 files changed, 56 insertions, 13 deletions
diff --git a/kvision-modules/kvision-bootstrap-select/src/main/kotlin/pl/treksoft/kvision/form/select/Select.kt b/kvision-modules/kvision-bootstrap-select/src/main/kotlin/pl/treksoft/kvision/form/select/Select.kt index b3f5e1c1..4ffece7d 100644 --- a/kvision-modules/kvision-bootstrap-select/src/main/kotlin/pl/treksoft/kvision/form/select/Select.kt +++ b/kvision-modules/kvision-bootstrap-select/src/main/kotlin/pl/treksoft/kvision/form/select/Select.kt @@ -183,7 +183,7 @@ open class Select( this.id = idc this.name = name } - final override val flabel: FieldLabel = FieldLabel(idc, label, rich) + final override val flabel: FieldLabel = FieldLabel(idc, label, rich, setOf("control-label")) final override val invalidFeedback: InvalidFeedback = InvalidFeedback().apply { visible = false } init { diff --git a/kvision-modules/kvision-bootstrap-select/src/main/kotlin/pl/treksoft/kvision/form/select/SelectInput.kt b/kvision-modules/kvision-bootstrap-select/src/main/kotlin/pl/treksoft/kvision/form/select/SelectInput.kt index 01b35ed2..ced0945d 100644 --- a/kvision-modules/kvision-bootstrap-select/src/main/kotlin/pl/treksoft/kvision/form/select/SelectInput.kt +++ b/kvision-modules/kvision-bootstrap-select/src/main/kotlin/pl/treksoft/kvision/form/select/SelectInput.kt @@ -35,6 +35,7 @@ import pl.treksoft.kvision.html.ButtonStyle import pl.treksoft.kvision.panel.SimplePanel import pl.treksoft.kvision.utils.asString import pl.treksoft.kvision.utils.obj +import pl.treksoft.kvision.utils.set /** * Select width types. See [Bootstrap Select width](http://silviomoreto.github.io/bootstrap-select/examples/#width). @@ -77,18 +78,22 @@ open class SelectInput( * A list of options (value to label pairs) for the select control. */ var options by refreshOnUpdate(options) { setChildrenFromOptions() } + /** * A value of the selected option. */ var value by refreshOnUpdate(value) { refreshState() } + /** * The name attribute of the generated HTML select element. */ override var name: String? by refreshOnUpdate() + /** * Determines if multiple value selection is allowed. */ var multiple by refreshOnUpdate(multiple) + /** * Additional options for remote (AJAX) data source. */ @@ -98,50 +103,62 @@ open class SelectInput( } refresh() } + /** * Maximal number of selected options. */ var maxOptions: Int? by refreshOnUpdate() + /** * Determines if live search is available. */ var liveSearch by refreshOnUpdate(false) + /** * The placeholder for the select control. */ var placeholder: String? by refreshOnUpdate() + /** * The style of the select control. */ var style: ButtonStyle? by refreshOnUpdate() + /** * The width of the select control. */ var selectWidth: CssSize? by refreshOnUpdate() + /** * The width type of the select control. */ var selectWidthType: SelectWidthType? by refreshOnUpdate() + /** * The dropdown align of the select control. */ var dropdownAlign by refreshOnUpdate(SelectDropdownAlign.LEFT) + /** * Determines if an empty option is automatically generated. */ var emptyOption by refreshOnUpdate(false) { setChildrenFromOptions() } + /** * Determines if the field is disabled. */ override var disabled by refreshOnUpdate(false) + /** * Determines if the select is automatically focused. */ var autofocus: Boolean? by refreshOnUpdate() + /** * The size of the input. */ override var size: InputSize? by refreshOnUpdate() + /** * The validation status of the input. */ @@ -389,9 +406,12 @@ open class SelectInput( fun Container.selectInput( options: List<StringPair>? = null, value: String? = null, multiple: Boolean = false, ajaxOptions: AjaxOptions? = null, - classes: Set<String> = setOf(), init: (SelectInput.() -> Unit)? = null + classes: Set<String>? = null, + className: String? = null, + init: (SelectInput.() -> Unit)? = null ): SelectInput { - val selectInput = SelectInput(options, value, multiple, ajaxOptions, classes).apply { init?.invoke(this) } + val selectInput = + SelectInput(options, value, multiple, ajaxOptions, classes ?: className.set).apply { init?.invoke(this) } this.add(selectInput) return selectInput } diff --git a/kvision-modules/kvision-bootstrap-select/src/main/kotlin/pl/treksoft/kvision/form/select/SelectOptGroup.kt b/kvision-modules/kvision-bootstrap-select/src/main/kotlin/pl/treksoft/kvision/form/select/SelectOptGroup.kt index 7893f891..a265c35b 100644 --- a/kvision-modules/kvision-bootstrap-select/src/main/kotlin/pl/treksoft/kvision/form/select/SelectOptGroup.kt +++ b/kvision-modules/kvision-bootstrap-select/src/main/kotlin/pl/treksoft/kvision/form/select/SelectOptGroup.kt @@ -24,6 +24,7 @@ package pl.treksoft.kvision.form.select import com.github.snabbdom.VNode import pl.treksoft.kvision.core.StringPair import pl.treksoft.kvision.panel.SimplePanel +import pl.treksoft.kvision.utils.set /** * The helper container for adding option groups to [Select]. @@ -46,14 +47,17 @@ open class SelectOptGroup( * A label for the group. */ var label by refreshOnUpdate(label) + /** * A list of options (label to value pairs) for the group. */ var options by refreshOnUpdate(options) { setChildrenFromOptions() } + /** * Maximal number of selected options in the group. */ var maxOptions by refreshOnUpdate(maxOptions) + /** * Determines if the group is disabled. */ @@ -97,10 +101,13 @@ open class SelectOptGroup( */ fun Select.selectOptGroup( label: String, options: List<StringPair>? = null, maxOptions: Int? = null, - disabled: Boolean = false, classes: Set<String> = setOf(), init: (SelectOptGroup.() -> Unit)? = null + disabled: Boolean = false, + classes: Set<String>? = null, + className: String? = null, + init: (SelectOptGroup.() -> Unit)? = null ): SelectOptGroup { val selectOptGroup = - SelectOptGroup(label, options, maxOptions, disabled, classes).apply { init?.invoke(this) } + SelectOptGroup(label, options, maxOptions, disabled, classes ?: className.set).apply { init?.invoke(this) } this.add(selectOptGroup) return selectOptGroup } @@ -112,10 +119,13 @@ fun Select.selectOptGroup( */ fun SelectInput.selectOptGroup( label: String, options: List<StringPair>? = null, maxOptions: Int? = null, - disabled: Boolean = false, classes: Set<String> = setOf(), init: (SelectOptGroup.() -> Unit)? = null + disabled: Boolean = false, + classes: Set<String>? = null, + className: String? = null, + init: (SelectOptGroup.() -> Unit)? = null ): SelectOptGroup { val selectOptGroup = - SelectOptGroup(label, options, maxOptions, disabled, classes).apply { init?.invoke(this) } + SelectOptGroup(label, options, maxOptions, disabled, classes ?: className.set).apply { init?.invoke(this) } this.add(selectOptGroup) return selectOptGroup } diff --git a/kvision-modules/kvision-bootstrap-select/src/main/kotlin/pl/treksoft/kvision/form/select/SelectOption.kt b/kvision-modules/kvision-bootstrap-select/src/main/kotlin/pl/treksoft/kvision/form/select/SelectOption.kt index a9c7eda5..1c8689c0 100644 --- a/kvision-modules/kvision-bootstrap-select/src/main/kotlin/pl/treksoft/kvision/form/select/SelectOption.kt +++ b/kvision-modules/kvision-bootstrap-select/src/main/kotlin/pl/treksoft/kvision/form/select/SelectOption.kt @@ -24,6 +24,7 @@ package pl.treksoft.kvision.form.select import com.github.snabbdom.VNode import pl.treksoft.kvision.core.StringPair import pl.treksoft.kvision.core.Widget +import pl.treksoft.kvision.utils.set /** * The helper component for adding options to [Select] or [SelectOptGroup]. @@ -47,26 +48,32 @@ open class SelectOption( * The value of the option. */ var value by refreshOnUpdate(value) + /** * The label of the option. */ var label by refreshOnUpdate(label) + /** * The subtext after the label of the option. */ var subtext by refreshOnUpdate(subtext) + /** * The icon before the label of the option. */ var icon by refreshOnUpdate(icon) + /** * Determines if the option should be rendered as divider. */ var divider by refreshOnUpdate(divider) + /** * Determines if the option should be disabled. */ var disabled by refreshOnUpdate(disabled) + /** * Determines if the option is selected. */ @@ -114,10 +121,12 @@ open class SelectOption( 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 + classes: Set<String>? = null, + className: String? = null, + init: (SelectOption.() -> Unit)? = null ): SelectOption { val selectOption = - SelectOption(value, label, subtext, icon, divider, disabled, selected, classes).apply { + SelectOption(value, label, subtext, icon, divider, disabled, selected, classes ?: className.set).apply { init?.invoke( this ) @@ -134,10 +143,12 @@ fun Select.selectOption( 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 + classes: Set<String>? = null, + className: String? = null, + init: (SelectOption.() -> Unit)? = null ): SelectOption { val selectOption = - SelectOption(value, label, subtext, icon, divider, disabled, selected, classes).apply { + SelectOption(value, label, subtext, icon, divider, disabled, selected, classes ?: className.set).apply { init?.invoke( this ) @@ -154,10 +165,12 @@ fun SelectInput.selectOption( 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 + classes: Set<String>? = null, + className: String? = null, + init: (SelectOption.() -> Unit)? = null ): SelectOption { val selectOption = - SelectOption(value, label, subtext, icon, divider, disabled, selected, classes).apply { + SelectOption(value, label, subtext, icon, divider, disabled, selected, classes ?: className.set).apply { init?.invoke( this ) |