Time picker
Type or choose a local time with configurable intervals, bounds and 12/24-hour display.
Default
open System
open FSharp.ViewEngine
open Acme.Components
open type Html
open type Svg
open type Datastar
let defaultTimePicker =
fveField {
fveLabel { _for "default-time"; "Time" }
fveTimePicker { _id "default-time"; _name "time"; _ariaLabel "Time"; _value (TimeOnly(9, 30)) }
}This example also uses Field. See their Installation sections for any additional setup.
On this page
Installation
Copy this component and its required dependencies into the consumer-owned Components project.
dotnet fve add time-picker --config src/Acme.Components/fve.jsonAdd to src/Acme.Web/js/app.js once, alongside your other component imports:
import '../../Acme.Components/Components/Assets/popover.js';
import '../../Acme.Components/Components/Assets/time-picker.js';The CLI resolves dependencies and preserves consumer-authored files. See Installation for project initialization, Tailwind, the shared runtime, and building/loading your app entry.
Usage
open System
open FSharp.ViewEngine
open Acme.Components
open type Html
open type Svg
open type Datastar
let defaultTimePicker =
fveField {
fveLabel { _for "default-time"; "Time" }
fveTimePicker { _id "default-time"; _name "time"; _ariaLabel "Time"; _value (TimeOnly(9, 30)) }
}24-hour display and bounds
open System
open FSharp.ViewEngine
open Acme.Components
open type Html
open type Svg
open type Datastar
let boundedTimePicker =
fveField {
fveLabel { _for "office-time"; "Office visit" }
fveTimePicker {
_id "office-time"; _name "office-time"; _ariaLabel "Office visit"
_value (TimeOnly(13, 15)); _min (TimeOnly(8, 15)); _max (TimeOnly(18, 15))
_interval 15; _format TimeFormat.TwentyFourHour
}
fveFieldDescription { "24-hour display, in 15-minute intervals from 08:15 to 18:15." }
}This example also uses Field. See their Installation sections for any additional setup.
Disabled and read-only
open System
open FSharp.ViewEngine
open Acme.Components
open type Html
open type Svg
open type Datastar
let timePickerStates =
div {
_class "grid w-full min-w-0 gap-4 sm:grid-cols-2"
for id, label, disabled, readOnly in ["disabled-time", "Disabled", true, false; "readonly-time", "Read-only", false, true] do
fveField {
fveLabel { _for id; label }
fveTimePicker { _id id; _name id; _ariaLabel label; _value (TimeOnly(9, 0)); _disabled disabled; _readonly readOnly }
}
}This example also uses Field. See their Installation sections for any additional setup.
Import Assets/time-picker.js and Assets/popover.js. TimeOnly values submit as HH:mm; the native time input remains usable without JavaScript. Availability and time zones belong to the application.
API reference
type TimeFormat =
| TwelveHour
| TwentyFourHour
module TimePickerDsl =
val fveTimePicker : ComponentElementBuilder
module TimePickerAttributes =
val Html._value.Static : value:TimeOnly -> HtmlAttribute
val Html._min.Static : value:TimeOnly -> HtmlAttribute
val Html._max.Static : value:TimeOnly -> HtmlAttribute
val Html._interval.Static : minutes:int -> HtmlAttribute
val Html._format.Static : value:TimeFormat -> HtmlAttribute