Scoop API

scoop:scoop.ui.component:0.1.0

src/date_picker/builder.scoop

Selected production source · src/date_picker/builder.scoop

1package scoop.ui.component
3import scoop.datetime.LocalDate
4import scoop.graphics.text.FontCollection
5import scoop.surface.AnimationSpec
6import scoop.ui.*
7import scoop.ui.style.*
9public class DatePickerBuilder internal constructor() {
10 public var key: ViewKey = ViewKey.Position
11 public var semantics: ComponentSemantics = ComponentSemantics()
12 public var popupSemantics: ComponentSemantics = ComponentSemantics()
13 public var calendarButtonSemantics: ComponentSemantics =
14 ComponentSemantics(name = Some("Open calendar"))
15 public var draft: DatePickerDraft? = None
16 public var open: Binding<Boolean>? = None
17 public var calendar: CalendarOptions = defaultCalendarOptions
18 public var referenceDate: LocalDate? = None
19 public var parser: ((String, LocalDate, CalendarLocale) -> DatePickerParse)? = None
20 public var format: ((CalendarValue, CalendarLocale) -> String)? = None
21 public var presets: Array<DatePickerPreset> = []
22 public var placeholder: String = "Pick a date"
23 public var enabled: Boolean = true
24 public var readOnly: Boolean = false
25 public var invalid: Boolean = false
26 public var commitOnBlur: Boolean = false
27 public var closeOnSelect: Boolean = true
28 public var handle: DatePickerHandle? = None
29 public var focus: FocusOptions = FocusOptions()
30 public var labelTarget: FieldTarget? = None
31 public var fonts: FontCollection? = None
32 public var theme: ThemeSource? = None
33 public var inputStyle: TextFieldStyle = textFieldStyle()
34 public var buttonStyle: ButtonStyle = defaultButtonStyle
35 public var popupStyle: StyleOverride = styleOverride()
36 public var mode: OverlayMode = OverlayMode.NonModal
37 public var transition: StyleValue<AnimationSpec?> = StyleValue.Inherit
38 public var day: ((CalendarDay, ActionContentStyle) -> View)? = None
39 public var footer: View? = None
40 public var onValueChange: (CalendarValue) -> Unit = {}
41 public var onOpenChange: (Boolean) -> Unit = {}
42 public var onCloseRequest: (OverlayCloseReason) -> Boolean = { _ -> true }
43 public var onClosed: (OverlayCloseReason) -> Unit = {}
44 public fun calendar(configure: CalendarOptionsBuilder.() -> Unit) {
45 calendar = calendar.copy(configure)
46 }
47 public fun focus(configure: FocusOptionsBuilder.() -> Unit) {
48 focus = focus.copy(configure)
49 }
50 public fun inputStyle(configure: TextFieldStyleBuilder.() -> Unit) {
51 inputStyle = inputStyle.copy(configure)
52 }
53 public fun buttonStyle(configure: ButtonStyleBuilder.() -> Unit) {
54 buttonStyle = buttonStyle.copy(configure)
55 }
56 public fun popupStyle(configure: StyleOverrideBuilder.() -> Unit) {
57 popupStyle = popupStyle.copy(configure)
58 }
59 public fun transition(value: AnimationSpec?) {
60 transition = StyleValue.Set(value)
61 }
62 internal fun snapshot(selection: CalendarSelection, initialPage: LocalDate): DatePickerProps =
63 DatePickerProps(
64 selection,
65 initialPage,
66 draft,
67 open,
68 calendar,
69 referenceDate,
70 parser,
71 format,
72 presets,
73 placeholder,
74 enabled,
75 readOnly,
76 invalid,
77 commitOnBlur,
78 closeOnSelect,
79 handle,
80 focus,
81 labelTarget,
82 fonts,
83 theme,
84 inputStyle,
85 buttonStyle,
86 popupStyle,
87 mode,
88 transition,
89 day,
90 footer,
91 onValueChange,
92 onOpenChange,
93 onCloseRequest,
94 onClosed,
95 semantics,
96 popupSemantics,
97 calendarButtonSemantics
98 )
101public fun datePicker(
102 value: Binding<LocalDate?>,
103 initialPage: LocalDate,
104 configure: DatePickerBuilder.() -> Unit = {}
105): View = makeDatePicker(CalendarSelection.Single(value), initialPage, configure)
107public fun dateRangePicker(
108 value: Binding<DateRange?>,
109 initialPage: LocalDate,
110 configure: DatePickerBuilder.() -> Unit = {}
111): View = makeDatePicker(CalendarSelection.Range(value), initialPage, configure)
113internal fun makeDatePicker(
114 selection: CalendarSelection,
115 initialPage: LocalDate,
116 configure: DatePickerBuilder.() -> Unit
117): View {
118 val b = DatePickerBuilder()
119 if (datePickerRange(selection))
120 b.placeholder = "Pick a date range"
121 b.configure()
122 return component(
123 b.snapshot(selection, initialPage),
124 { props, scope -> DatePicker(props, scope) },
125 b.key
126 )