SearchCtrlK

  • ↑↓navigate
  • ↵open
  • escclose

Can’t find it? Contact us

TimeField

A labeled, described and validated time field.

Thursday 24 September

Front desk · Ana Ruiz

Between 09:00 and 17:00, in quarter-hour steps.

The shift ends before it starts.
View code
tsx
<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.

Terminal
npm add @sdxc/ui remix
typescript
import "@sdxc/ui/theme.css";

Or copy it into your project to edit it:

Terminal
sdxc ui add time-field

Usage

typescript
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
tsx
<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
tsx
<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.

PropTypeDefaultRequiredDescription
color"brand" | "neutral" | "success" | "warning" | "danger"—NoSemantic color role for the control's focus ring. Defaults to "neutral" when omitted.
autoFocusboolean—NoNative 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.
namestring—NoNative name; it also finds the enclosing Form's issue for this field.
valuestring—NoCurrent value, in the platform's "HH:mm" (or "HH:mm:ss") format, for a control a consumer tracks itself.
defaultValuestring—NoInitial value, in that same format, for a control left to the platform's own uncontrolled state.
minstring—NoEarliest accepted time, in the same "HH:mm"/"HH:mm:ss" format.
maxstring—NoLatest accepted time, in the same "HH:mm"/"HH:mm:ss" format.
stepnumber—NoGranularity of the accepted value, in seconds; 1 surfaces a seconds digit beside hours and minutes.
requiredboolean—No
disabledboolean—No
readOnlyboolean—No
autoCompletestring—NoNative autofill hint.
childrenRemixNode—NoThe 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

NameValuesWhat 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.
@sdxc/ui

Can’t find it? Contact us