PaackEng / elm-datetime-picker / SingleDatePicker

A date picker component for a single datetime.

Architecture


type DatePicker

The opaque type representing a particular date picker instance.

init : DatePicker

Instantiates and returns a date picker.

view : Settings msg -> DatePicker -> Html msg

The date picker view. Simply pass it the configured settings and the date picker instance you wish to view.

subscriptions : Settings msg -> (( DatePicker, Maybe Time.Posix ) -> msg) -> DatePicker -> Platform.Sub.Sub msg

Events external to the picker to which it is subscribed.

Settings


type alias Settings msg =
{ formattedDay : Time.Weekday -> String
, formattedMonth : Time.Month -> String
, focusedDate : Maybe Time.Posix
, dateTimeProcessor : { isDayDisabled : Time.Zone -> Time.Posix -> Basics.Bool
, allowedTimesOfDay : Time.Zone -> Time.Posix -> { startHour : Basics.Int
, startMinute : Basics.Int
, endHour : Basics.Int
, endMinute : Basics.Int } }
, internalMsg : ( DatePicker
, Maybe Time.Posix ) -> msg
, dateStringFn : Time.Zone -> Time.Posix -> String
, timeStringFn : Time.Zone -> Time.Posix -> String
, zone : Time.Zone
, isFooterDisabled : Basics.Bool 
}

The type facilitating the configuration of the datepicker settings.

Because it could be the case that a picker is being used in a different timezone than the home timezone of the implementor, the subfunctions of the dateTimeProcessor both ingest a Zone in addition to a Posix. The Zone represents the time zone in which the picker is being used. An implementor can leverage this to compare against a base time zone when enforcing allowable times of day, etc. You SHOULD assume that the Posix passed into these functions is floored to the start of its respective Day.

More information can be found in the examples.

defaultSettings : Time.Zone -> (( DatePicker, Maybe Time.Posix ) -> msg) -> Settings msg

A record of default settings for the date picker. Extend this if you want to further customize the date picker.

Requires a Zone to inform the picker in which time zone it should display the picked time as well as a msg that expects a tuple containing a datepicker instance and a Maybe Posix representing a selected datetime.

( DatePicker, Maybe ( Posix, Posix ) ) -> msg

Externally Triggered Actions

openPicker : Time.Zone -> Time.Posix -> Maybe Time.Posix -> DatePicker -> DatePicker

Open the provided date picker and receive the updated picker instance. Also takes a default time the picker should center on (in the event a time has not yet been picked) as well as the picked time. A common example of a default time would be the datetime for the current day.

closePicker : DatePicker -> DatePicker

Close the provided date picker and receive the updated picker instance.

Query

isOpen : DatePicker -> Basics.Bool

Indicates whether the DatePicker is open