OneScript

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>
  )
}
PropTypeDescription
selectionDateCurrent date.
onSelectionChange(date: Date) => voidRuns with a new Date when the user picks a value.
minDateOptional earliest date.
maxDateOptional latest date. Must not be earlier than min.
displayedComponents("date" | "hourAndMinute")[]Parts to show. Defaults to both.
childrenViewChildThe 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

On this page