UIViews
DatePicker
Choose a date, a time, or both.
A controlled picker for a JavaScript Date. children is the label.
import { DatePicker, useState } from "onescript/views"
function MeetingPicker() {
const [date, setDate] = useState(() => new Date())
return (
<DatePicker
selection={date}
onSelectionChange={setDate}
>
Meeting
</DatePicker>
)
}| Prop | Type | Description |
|---|---|---|
selection | Date | Current date. |
onSelectionChange | (date: Date) => void | Runs with a new Date when the user picks a value. |
min | Date | Optional earliest date. |
max | Date | Optional latest date. Must not be earlier than min. |
displayedComponents | ("date" | "hourAndMinute")[] | Parts to show. Defaults to both. |
children | ViewChild | The label. |
selection must be between min and max; otherwise DatePicker throws a TypeError, because SwiftUI would show the nearest bound instead of your value.
Styles and ranges
import { DatePicker, Modifier } from "onescript/views"
<DatePicker
selection={deadline}
onSelectionChange={setDeadline}
min={new Date()}
displayedComponents={["date"]}
modifier={Modifier.datePickerStyle("graphical")}
>
Deadline
</DatePicker>Use datePickerStyle to switch between the compact, graphical, and wheel styles. Also accepts Modifiers. It is only available in App and Action view sessions; widgets reject it with an unsupported view type error.
How is this guide?
Last updated on