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 | |
| 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')
32 files changed, 329 insertions, 94 deletions
diff --git a/kvision-modules/kvision-bootstrap-datetime/src/main/kotlin/pl/treksoft/kvision/form/time/DateTime.kt b/kvision-modules/kvision-bootstrap-datetime/src/main/kotlin/pl/treksoft/kvision/form/time/DateTime.kt index aa3e77b2..68ec96a2 100644 --- a/kvision-modules/kvision-bootstrap-datetime/src/main/kotlin/pl/treksoft/kvision/form/time/DateTime.kt +++ b/kvision-modules/kvision-bootstrap-datetime/src/main/kotlin/pl/treksoft/kvision/form/time/DateTime.kt @@ -196,7 +196,7 @@ open class DateTime( this.input.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-datetime/src/main/kotlin/pl/treksoft/kvision/form/time/DateTimeInput.kt b/kvision-modules/kvision-bootstrap-datetime/src/main/kotlin/pl/treksoft/kvision/form/time/DateTimeInput.kt index daeda692..967ca9db 100644 --- a/kvision-modules/kvision-bootstrap-datetime/src/main/kotlin/pl/treksoft/kvision/form/time/DateTimeInput.kt +++ b/kvision-modules/kvision-bootstrap-datetime/src/main/kotlin/pl/treksoft/kvision/form/time/DateTimeInput.kt @@ -36,6 +36,7 @@ import pl.treksoft.kvision.panel.SimplePanel import pl.treksoft.kvision.types.toDateF import pl.treksoft.kvision.types.toStringF import pl.treksoft.kvision.utils.obj +import pl.treksoft.kvision.utils.set import kotlin.js.Date internal const val DEFAULT_STEPPING = 5 @@ -78,10 +79,12 @@ open class DateTimeInput( input.value = value?.toStringF(format) refreshState() } + /** * Date/time format. */ var format by refreshOnUpdate(format) { refreshDatePicker() } + /** * The placeholder for the date/time input. */ @@ -90,6 +93,7 @@ open class DateTimeInput( set(value) { input.placeholder = value } + /** * The name attribute of the generated HTML input element. */ @@ -98,6 +102,7 @@ open class DateTimeInput( set(value) { input.name = value } + /** * Determines if the field is disabled. */ @@ -106,6 +111,7 @@ open class DateTimeInput( set(value) { input.disabled = value } + /** * Determines if the text input is automatically focused. */ @@ -114,6 +120,7 @@ open class DateTimeInput( set(value) { input.autofocus = value } + /** * Determines if the date/time input is read-only. */ @@ -122,6 +129,7 @@ open class DateTimeInput( set(value) { input.readonly = value } + /** * The size of the input. */ @@ -130,6 +138,7 @@ open class DateTimeInput( set(value) { input.size = value } + /** * The validation status of the input. */ @@ -139,46 +148,57 @@ open class DateTimeInput( input.validationStatus = value refresh() } + /** * Days of the week that should be disabled. Multiple values should be comma separated. */ var daysOfWeekDisabled by refreshOnUpdate(arrayOf<Int>()) { refreshDatePicker() } + /** * Determines if *Clear* button should be visible. */ var showClear by refreshOnUpdate(true) { refreshDatePicker() } + /** * Determines if *Close* button should be visible. */ var showClose by refreshOnUpdate(true) { refreshDatePicker() } + /** * Determines if *Today* button should be visible. */ var showTodayButton by refreshOnUpdate(true) { refreshDatePicker() } + /** * The increment used to build the hour view. */ var stepping by refreshOnUpdate(DEFAULT_STEPPING) { refreshDatePicker() } + /** * Prevents date selection before this date. */ var minDate: Date? by refreshOnUpdate { refreshDatePicker() } + /** * Prevents date selection after this date. */ var maxDate: Date? by refreshOnUpdate { refreshDatePicker() } + /** * Shows date and time pickers side by side. */ var sideBySide by refreshOnUpdate(false) { refreshDatePicker() } + /** * An array of enabled dates. */ var enabledDates by refreshOnUpdate(arrayOf<Date>()) { refreshDatePicker() } + /** * An array of disabled dates. */ var disabledDates by refreshOnUpdate(arrayOf<Date>()) { refreshDatePicker() } + /** * Allow date picker for readonly component. */ @@ -392,10 +412,12 @@ open class DateTimeInput( * It takes the same parameters as the constructor of the built component. */ fun Container.dateTimeInput( - value: Date? = null, format: String = "YYYY-MM-DD HH:mm", classes: Set<String> = setOf(), + value: Date? = null, format: String = "YYYY-MM-DD HH:mm", + classes: Set<String>? = null, + className: String? = null, init: (DateTimeInput.() -> Unit)? = null ): DateTimeInput { - val dateTimeInput = DateTimeInput(value, format, classes).apply { init?.invoke(this) } + val dateTimeInput = DateTimeInput(value, format, classes ?: className.set).apply { init?.invoke(this) } this.add(dateTimeInput) return dateTimeInput } diff --git a/kvision-modules/kvision-bootstrap-select-remote/src/main/kotlin/pl/treksoft/kvision/form/select/SelectRemote.kt b/kvision-modules/kvision-bootstrap-select-remote/src/main/kotlin/pl/treksoft/kvision/form/select/SelectRemote.kt index dbd0aa70..b4e4738c 100644 --- a/kvision-modules/kvision-bootstrap-select-remote/src/main/kotlin/pl/treksoft/kvision/form/select/SelectRemote.kt +++ b/kvision-modules/kvision-bootstrap-select-remote/src/main/kotlin/pl/treksoft/kvision/form/select/SelectRemote.kt @@ -166,7 +166,7 @@ open class SelectRemote<T : Any>( 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-remote/src/main/kotlin/pl/treksoft/kvision/form/select/SelectRemoteInput.kt b/kvision-modules/kvision-bootstrap-select-remote/src/main/kotlin/pl/treksoft/kvision/form/select/SelectRemoteInput.kt index e7fd384c..b6319a6b 100644 --- a/kvision-modules/kvision-bootstrap-select-remote/src/main/kotlin/pl/treksoft/kvision/form/select/SelectRemoteInput.kt +++ b/kvision-modules/kvision-bootstrap-select-remote/src/main/kotlin/pl/treksoft/kvision/form/select/SelectRemoteInput.kt @@ -36,6 +36,7 @@ import pl.treksoft.kvision.remote.KVServiceManager import pl.treksoft.kvision.remote.RemoteOption import pl.treksoft.kvision.utils.JSON import pl.treksoft.kvision.utils.obj +import pl.treksoft.kvision.utils.set import kotlin.browser.window external fun decodeURIComponent(encodedURI: String): String @@ -197,7 +198,9 @@ fun <T : Any> Container.selectRemoteInput( multiple: Boolean = false, ajaxOptions: AjaxOptions? = null, preload: Boolean = false, - classes: Set<String> = setOf(), init: (SelectRemoteInput<T>.() -> Unit)? = null + classes: Set<String>? = null, + className: String? = null, + init: (SelectRemoteInput<T>.() -> Unit)? = null ): SelectRemoteInput<T> { val selectRemoteInput = SelectRemoteInput( @@ -208,7 +211,7 @@ fun <T : Any> Container.selectRemoteInput( multiple, ajaxOptions, preload, - classes + classes ?: className.set ).apply { init?.invoke(this) } 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 ) diff --git a/kvision-modules/kvision-bootstrap-spinner/src/main/kotlin/pl/treksoft/kvision/form/spinner/Spinner.kt b/kvision-modules/kvision-bootstrap-spinner/src/main/kotlin/pl/treksoft/kvision/form/spinner/Spinner.kt index a842a37f..3901cc4f 100644 --- a/kvision-modules/kvision-bootstrap-spinner/src/main/kotlin/pl/treksoft/kvision/form/spinner/Spinner.kt +++ b/kvision-modules/kvision-bootstrap-spinner/src/main/kotlin/pl/treksoft/kvision/form/spinner/Spinner.kt @@ -180,7 +180,7 @@ open class Spinner( 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-spinner/src/main/kotlin/pl/treksoft/kvision/form/spinner/SpinnerInput.kt b/kvision-modules/kvision-bootstrap-spinner/src/main/kotlin/pl/treksoft/kvision/form/spinner/SpinnerInput.kt index 3a52fed2..98b7be62 100644 --- a/kvision-modules/kvision-bootstrap-spinner/src/main/kotlin/pl/treksoft/kvision/form/spinner/SpinnerInput.kt +++ b/kvision-modules/kvision-bootstrap-spinner/src/main/kotlin/pl/treksoft/kvision/form/spinner/SpinnerInput.kt @@ -32,6 +32,7 @@ import pl.treksoft.kvision.form.InputSize import pl.treksoft.kvision.form.ValidationStatus import pl.treksoft.kvision.html.ButtonStyle import pl.treksoft.kvision.utils.obj +import pl.treksoft.kvision.utils.set /** * Spinner buttons layout types. @@ -80,6 +81,7 @@ open class SpinnerInput( * Spinner value. */ var value by refreshOnUpdate(value) { refreshState() } + /** * The value attribute of the generated HTML input element. * @@ -87,54 +89,67 @@ open class SpinnerInput( * bound to the spinner input value. */ var startValue by refreshOnUpdate(value) { this.value = it; refresh() } + /** * Minimal value. */ var min by refreshOnUpdate(min) { refreshSpinner() } + /** * Maximal value. */ var max by refreshOnUpdate(max) { refreshSpinner() } + /** * Step value. */ var step by refreshOnUpdate(step) { refreshSpinner() } + /** * Number of decimal digits value. */ var decimals by refreshOnUpdate(decimals) { refreshSpinner() } + /** * Spinner force rounding type. */ var forceType by refreshOnUpdate(forceType) { refreshSpinner() } + /** * The style of the up/down buttons. */ var buttonStyle by refreshOnUpdate(buttonStyle) { refreshSpinner() } + /** * The placeholder for the spinner input. */ var placeholder: String? by refreshOnUpdate() + /** * The name attribute of the generated HTML input element. */ override var name: String? by refreshOnUpdate() + /** * Determines if the field is disabled. */ override var disabled by refreshOnUpdate(false) + /** * Determines if the spinner is automatically focused. */ var autofocus: Boolean? by refreshOnUpdate() + /** * Determines if the spinner is read-only. */ var readonly: Boolean? by refreshOnUpdate() + /** * The size of the input. */ override var size: InputSize? by refreshOnUpdate() + /** * The validation status of the input. */ @@ -323,11 +338,23 @@ open class SpinnerInput( fun Container.spinnerInput( value: Number? = null, min: Number? = null, max: Number? = null, step: Number = DEFAULT_STEP, decimals: Int = 0, buttonsType: ButtonsType = ButtonsType.VERTICAL, - forceType: ForceType = ForceType.NONE, buttonStyle: ButtonStyle? = null, classes: Set<String> = setOf(), + forceType: ForceType = ForceType.NONE, buttonStyle: ButtonStyle? = null, + classes: Set<String>? = null, + className: String? = null, init: (SpinnerInput.() -> Unit)? = null ): SpinnerInput { val spinnerInput = - SpinnerInput(value, min, max, step, decimals, buttonsType, forceType, buttonStyle, classes).apply { + SpinnerInput( + value, + min, + max, + step, + decimals, + buttonsType, + forceType, + buttonStyle, + classes ?: className.set + ).apply { init?.invoke( this ) diff --git a/kvision-modules/kvision-bootstrap-typeahead-remote/src/main/kotlin/pl/treksoft/kvision/form/text/TypeaheadRemoteInput.kt b/kvision-modules/kvision-bootstrap-typeahead-remote/src/main/kotlin/pl/treksoft/kvision/form/text/TypeaheadRemoteInput.kt index 42412ae4..0693756b 100644 --- a/kvision-modules/kvision-bootstrap-typeahead-remote/ |
