scoop:scoop.ui.component:0.1.0
src/date_picker/values.scoop
Selected production source · src/date_picker/values.scoop
1
package scoop.ui.component3
import scoop.datetime.*4
import scoop.graphics.text.FontCollection5
import scoop.surface.AnimationSpec6
import scoop.ui.*7
import scoop.ui.style.*8
import scoop.ui.text.TextEditorState10
/** A draft is the text editor itself, plus its last explicit validation result. */11
public class DatePickerDraft public constructor(12
public val editor: TextEditorState = TextEditorState()13
) {14
internal val problem = state<String?>(None)15
public val error: String? get() = problem.value16
public fun reset(text: String): Boolean {17
if (editor.isComposing)18
return false19
editor.replaceAll(text)20
if (problem.value != None)21
problem.value = None22
return true23
}24
}26
public enum DatePickerParse {27
Date(LocalDate), Range(DateRange), Empty, Invalid(String)28
}30
public class DatePickerPreset public constructor(31
public val label: String,32
public val value: CalendarValue33
)35
public class DatePickerProps public constructor(36
public val selection: CalendarSelection,37
public val initialPage: LocalDate,38
public val draft: DatePickerDraft? = None,39
public val open: Binding<Boolean>? = None,40
public val calendar: CalendarOptions = CalendarOptions(),41
public val referenceDate: LocalDate? = None,42
public val parser: ((String, LocalDate, CalendarLocale) -> DatePickerParse)? = None,43
public val format: ((CalendarValue, CalendarLocale) -> String)? = None,44
public val presets: Array<DatePickerPreset> = [],45
public val placeholder: String = "Pick a date",46
public val enabled: Boolean = true,47
public val readOnly: Boolean = false,48
public val invalid: Boolean = false,49
public val commitOnBlur: Boolean = false,50
public val closeOnSelect: Boolean = true,51
public val handle: DatePickerHandle? = None,52
public val focus: FocusOptions = FocusOptions(),53
public val labelTarget: FieldTarget? = None,54
public val fonts: FontCollection? = None,55
public val theme: ThemeSource? = None,56
public val inputStyle: TextFieldStyle = textFieldStyle(),57
public val buttonStyle: ButtonStyle = buttonStyle(),58
public val popupStyle: StyleOverride = styleOverride(),59
public val mode: OverlayMode = OverlayMode.NonModal,60
public val transition: StyleValue<AnimationSpec?> = StyleValue.Inherit,61
public val day: ((CalendarDay, ActionContentStyle) -> View)? = None,62
public val footer: View? = None,63
public val onValueChange: (CalendarValue) -> Unit = {},64
public val onOpenChange: (Boolean) -> Unit = {},65
public val onCloseRequest: (OverlayCloseReason) -> Boolean = { _ -> true },66
public val onClosed: (OverlayCloseReason) -> Unit = {},67
public val semantics: ComponentSemantics = ComponentSemantics(),68
public val popupSemantics: ComponentSemantics = ComponentSemantics(),69
public val calendarButtonSemantics: ComponentSemantics =70
ComponentSemantics(name = Some("Open calendar"))71
) {72
init {73
when (selection) {74
case Multiple(_) -> throw IllegalArgumentException(75
Some("date picker supports single dates and ranges")76
);77
else -> {}78
}79
}80
internal val mutable: Boolean get() = enabled && !readOnly81
}83
public class DatePickerHandle public constructor() {84
internal var owner: DatePickerControl? = None85
public val isAttached: Boolean get() = owner?.active ?: false86
public val isOpen: Boolean get() = owner?.open?.value ?: false87
public fun commit(): Boolean = owner?.commit() ?: false88
public fun reset(): Boolean = owner?.reset() ?: false89
public fun openCalendar(): Boolean = owner?.show() ?: false90
public fun closeCalendar(): Boolean = owner?.close() ?: false91
internal fun bind(control: DatePickerControl) {92
when (owner) {93
case Some(val previous) -> requireComponent(94
previous === control || !previous.active,95
"date picker handle is already attached"96
);97
case None -> {}98
}99
owner = Some(control)100
}101
internal fun release(control: DatePickerControl) {102
when (owner) {103
case Some(val previous) -> if (previous === control)104
owner = None;105
case None -> {}106
}107
}108
}