A time typed part by part or as “930p”, on the reader's 12 or 24-hour clock, with a list of times at a step.
12:00 AM
12:30 AM
1:00 AM
1:30 AM
2:00 AM
2:30 AM
3:00 AM
3:30 AM
4:00 AM
4:30 AM
5:00 AM
5:30 AM
6:00 AM
6:30 AM
7:00 AM
7:30 AM
8:00 AM
8:30 AM
9:00 AM
9:30 AM
10:00 AM
10:30 AM
11:00 AM
11:30 AM
12:00 PM
12:30 PM
1:00 PM
1:30 PM
2:00 PM
2:30 PM
3:00 PM
3:30 PM
4:00 PM
4:30 PM
5:00 PM
5:30 PM
6:00 PM
6:30 PM
7:00 PM
7:30 PM
8:00 PM
8:30 PM
9:00 PM
9:30 PM
10:00 PM
10:30 PM
11:00 PM
11:30 PM
12:00 AM
12:30 AM
1:00 AM
1:30 AM
2:00 AM
2:30 AM
3:00 AM
3:30 AM
4:00 AM
4:30 AM
5:00 AM
5:30 AM
6:00 AM
6:30 AM
7:00 AM
7:30 AM
8:00 AM
8:30 AM
9:00 AM
9:30 AM
10:00 AM
10:30 AM
11:00 AM
11:30 AM
12:00 PM
12:30 PM
1:00 PM
1:30 PM
2:00 PM
2:30 PM
3:00 PM
3:30 PM
4:00 PM
4:30 PM
5:00 PM
5:30 PM
6:00 PM
6:30 PM
7:00 PM
7:30 PM
8:00 PM
8:30 PM
9:00 PM
9:30 PM
10:00 PM
10:30 PM
11:00 PM
11:30 PM
Customers see: Open 9:00 AM – 5:30 PM, Monday to Friday.
import { UiSchema } from "@effect/ui"import { Html } from "@effect/ui/html"import * as stylex from "@stylexjs/stylex"import { Schema } from "effect"import { formatTimeOfDay } from "./ui/uicontext/components/dates/DateMath.ts"import { sx } from "./ui/uicontext/components/Sx.ts"import { TimePicker } from "./ui/uicontext/components/TimePicker.ts"import { color, font, space } from "./ui/uicontext/components/tokens.stylex.ts"// A support team's hours. Type a time the way you'd write it ("930a", "17:30", "noon") or pick one// from the list. The end has to come after the start, which the app checks and says.const styles = stylex.create({ form: { display: "grid", gap: space.lg, inlineSize: "min(100%, 26rem)" }, row: { display: "grid", gridTemplateColumns: "repeat(auto-fit, minmax(10rem, 1fr))", gap: space.md, alignItems: "start" }, summary: { margin: 0, fontSize: font.sm, color: color.muted, fontVariantNumeric: "tabular-nums" },})const Message = UiSchema.TaggedEnum({ PickedOpens: { value: Schema.NullOr(Schema.String) }, PickedCloses: { value: Schema.NullOr(Schema.String) },})export const SupportHours = Html.component({ name: "SupportHours", model: Schema.Struct({ opens: Schema.NullOr(Schema.String), closes: Schema.NullOr(Schema.String) }), message: Message,}).make({ init: () => ({ opens: "09:00", closes: "17:30" }), update: { PickedOpens: ($, { value }) => $.evolve({ opens: value }), PickedCloses: ($, { value }) => $.evolve({ closes: value }), }, view: (h, { opens, closes }) => { const backwards = opens !== null && closes !== null && closes <= opens return h.div.attrs(sx(styles.form)).children( h.div.attrs(sx(styles.row)).children( TimePicker(h, { key: "opens", props: { label: "Opens", value: opens, step: 30, locale: "en-US", name: "opens" }, onEmit: { Picked: ({ value }) => Message.PickedOpens({ value }) }, }), TimePicker(h, { key: "closes", props: { label: "Closes", value: closes, step: 30, locale: "en-US", name: "closes", error: backwards ? "Closing time comes after opening time." : null }, onEmit: { Picked: ({ value }) => Message.PickedCloses({ value }) }, }), ), h.p.attrs(sx(styles.summary)).children( opens === null || closes === null || backwards ? "Set both times to publish your hours." : `Customers see: Open ${formatTimeOfDay(opens, "en-US")} – ${formatTimeOfDay(closes, "en-US")}, Monday to Friday.`, ), ) },})Installation
pnpm dlx shadcn@latest add checkfu/uicontext/time-pickerUsage
import { TimePicker } from "./ui/uicontext/components/TimePicker.ts"const Message = UiSchema.TaggedEnum({ PickedReminder: { value: Schema.NullOr(Schema.String) } })export const Reminder = (h: Html.H<typeof Message.Type>, at: string | null) => TimePicker(h, { props: { label: "Remind me at", value: at, step: 15 }, onEmit: { Picked: ({ value }) => Message.PickedReminder({ value }) }, })Examples
Time field
One time on three clocks. Arrow keys step 15 minutes; in the 12-hour field, typing 21 reads as 9 PM.
import { UiSchema } from "@effect/ui"import { Html } from "@effect/ui/html"import * as stylex from "@stylexjs/stylex"import { Schema } from "effect"import { sx } from "./ui/uicontext/components/Sx.ts"import { TimeField } from "./ui/uicontext/components/TimePicker.ts"import { space } from "./ui/uicontext/components/tokens.stylex.ts"// A time typed part by part, on each locale's clock. The arrow keys step the minutes by 15, and// typing 13 to 23 in a 12-hour field reads as PM.const styles = stylex.create({ row: { display: "grid", gridTemplateColumns: "repeat(auto-fit, minmax(11rem, 1fr))", gap: space.lg, inlineSize: "min(100%, 30rem)" },})const Message = UiSchema.TaggedEnum({ CommittedStart: { value: Schema.NullOr(Schema.String) } })export const ShiftStart = Html.component({ name: "ShiftStart", model: Schema.Struct({ start: Schema.NullOr(Schema.String) }), message: Message,}).make({ init: () => ({ start: "21:30" }), update: { CommittedStart: ($, { value }) => $.evolve({ start: value }) }, view: (h, { start }) => h.div.attrs(sx(styles.row)).children( (["en-US", "en-GB", "de-DE"] as const).map((locale) => TimeField(h, { key: locale, props: { label: `Night shift (${locale})`, id: `shift-${locale}`, value: start, locale, minuteStep: 15 }, onEmit: { Committed: ({ value }) => Message.CommittedStart({ value }), RequestedOpen: () => undefined }, }), ), ),})API reference
Props
| Name | Type | Default | Description |
|---|---|---|---|
valuerequired | IsoTime | null | — | The time, HH:mm on a 24-hour clock, or null for none |
locale | string | — | The reader's locale, for the clock and how times read |
hour12 | boolean | — | A 12-hour clock with AM and PM; the locale's clock when left out |
step | Int | 30 | Minutes between the times listed; 30 by default |
min | IsoTime | — | The first time allowed |
max | IsoTime | — | The last time allowed |
labelrequired | string | — | — |
hideLabel | boolean | — | — |
description | string | — | — |
error | string | null | — | The app's message about the value; it wins over the picker's own |
placeholder | string | — | — |
id | string | — | — |
name | string | — | — |
required | boolean | — | — |
disabled | boolean | — | — |
readOnly | boolean | — | — |
Events
| Event | Payload | Description |
|---|---|---|
Picked | { value: IsoTime | null } | A time was picked or typed, or cleared (null): store it and pass it back as value |
Agent actions
| Action | Description |
|---|---|
TypedTime | Set the time as a person types it: "9:30", "930p", "21:30", or "" to clear |