TimeField
A labeled, described and validated time field.
View code
<form
method="post"
action="/examples/rota"
mix={[on<HTMLFormElement, "submit">("submit", (event) => event.preventDefault())]}
>
<Card>
<Card.Header>
<Card.Title>Thursday 24 September</Card.Title>
<Card.Description>Front desk · Ana Ruiz</Card.Description>
</Card.Header>
<Card.Content mix={[vstack({ gap: 4, align: "stretch" })]}>
<TimeField name="startTime" required min="09:00" max="17:00" step={900} defaultValue="09:30">
<TimeField.Label>Shift starts</TimeField.Label>
<TimeField.Description>Between 09:00 and 17:00, in quarter-hour steps.</TimeField.Description>
</TimeField>
<TimeField name="endTime" required min="09:00" max="17:00" step={900} defaultValue="09:00">
<TimeField.Label>Shift ends</TimeField.Label>
<TimeField.Error>{issues.endTime}</TimeField.Error>
</TimeField>
</Card.Content>
<Card.Footer mix={[hstack({ gap: 2, align: "center", justify: "end" })]}>
<Button type="submit">Save the shift</Button>
</Card.Footer>
</Card>
</form>Installation
An ordinary dependency: install it, import the theme once, and import the component where it is used.
npm add @sdxc/ui remiximport "@sdxc/ui/theme.css";Or copy it into your project to edit it:
sdxc ui add time-fieldUsage
import { TimeField } from "@sdxc/ui";Renders a time field: the native time control, laid out with the parts the caller
writes. An error, from .Error or an enclosing Form's issue for name, marks
the control invalid and recolors its border and ring to the danger tone.
Examples
Bounded with a hint
Acme sends reminders between 09:00 and 18:00.
View code
<TimeField name="reminderTime" min="09:00" max="18:00">
<TimeField.Label>Reminder time</TimeField.Label>
<TimeField.Description>Acme sends reminders between 09:00 and 18:00.</TimeField.Description>
</TimeField>Invalid value
The meeting ends before it starts at 10:00.
View code
<TimeField name="endTime" defaultValue="09:00">
<TimeField.Label>End time</TimeField.Label>
<TimeField.Error>The meeting ends before it starts at 10:00.</TimeField.Error>
</TimeField>Props
Read from the component's own types, so every prop, every default and every allowed value is listed.
| Prop | Type | Default | Required | Description |
|---|---|---|---|---|
color | "brand" | "neutral" | "success" | "warning" | "danger" | — | No | Semantic color role for the control's focus ring. Defaults to "neutral" when omitted. |
autoFocus | boolean | — | No | Native autofocus. Defaults to true for the first invalid field of an enclosing Form's issues, landing keyboard focus on the problem after a server round-trip; pass it explicitly to override for this field. |
name | string | — | No | Native name; it also finds the enclosing Form's issue for this field. |
value | string | — | No | Current value, in the platform's "HH:mm" (or "HH:mm:ss") format, for a control a consumer tracks itself. |
defaultValue | string | — | No | Initial value, in that same format, for a control left to the platform's own uncontrolled state. |
min | string | — | No | Earliest accepted time, in the same "HH:mm"/"HH:mm:ss" format. |
max | string | — | No | Latest accepted time, in the same "HH:mm"/"HH:mm:ss" format. |
step | number | — | No | Granularity of the accepted value, in seconds; 1 surfaces a seconds digit beside hours and minutes. |
required | boolean | — | No | |
disabled | boolean | — | No | |
readOnly | boolean | — | No | |
autoComplete | string | — | No | Native autofill hint. |
children | RemixNode | — | No | The field's parts: .Label, .Description and .Error. The control follows the caption, and the rest keep their order. |
Also accepts everything in TagProps<"div">.
Types
| Name | Values | What it decides |
|---|---|---|
Color | "brand" | "neutral" | "success" | "warning" | "danger" | Semantic color role for the control's keyboard focus ring, each mapped to its matching --ui-* variables. |