Duration Input

Jump to Props

Custom end adornment to display human readable durations

Import

import { DurationInput } from "@vitality-ds/components";

Usage

When requesting the user to input duration data it is important that users are utilising a consistant format such as minutes to represent the data. However, writing out multiple hours as minutes can be difficult to understand. To reduce this confusion this is a built in duration input which automatically adorns the text input the inputted minutes converted into a more human-readable state

  1. 30 --> 30m
  2. 60 --> 1h
  3. 90 --> 1h 30m
  4. 9999 --> 166h 39m (Avoid long durations, there are plans to improve this input to allow for different assumed units)

This is not validation, nor does it manipulate the value. This converts the text to an adornment based on the value parsed through the component.

() => {
  const [duration, setDuration] = React.useState("");

  const changeHandler = (event) => {
    setDuration(event.target.value);
  };

  return (
    <Stack>
      <DurationInput
        value={duration}
        name="cost"
        id="cost"
        onChange={changeHandler}
      />
    </Stack>
  );
};
() => {
  const [duration, setDuration] = React.useState("90");

  const changeHandler = (event) => {
    setDuration(event.target.value);
  };

  return (
    <DocsBox
      css={{
        padding: 64,
        maxWidth: 400,
        boxShadow: "$md",
        backgroundColor: "$neutral1",
        borderRadius: "$default",
      }}
    >
      <Stack align="stretch" spacing="lg">
        <Typography variant="pageTitle">New Appointment</Typography>
        <Typography color="lowContrast">
          Please add the Duration of the appointment and the name of the patient
        </Typography>
        <FormField type="text" label="Patient name" />
        <FormField
          type="duration"
          label="Duration (minutes)"
          value={duration}
          onChange={changeHandler}
        />
        <Button appearance="primary">Save</Button>
      </Stack>
    </DocsBox>
  );
};

Figma Library

Figma.logo

Props

adornStart

Description

Content to "adorn" the start of the input - typically text, icons or buttons.

Type

{ type: "text"; props: TextAdornmentProps; }

className

Type

never

disabled

Description

Determines whether the user has the ability to interact with the input.

Type

boolean

Default Value

false

hasError

Description

Adds additional styling to indicate failed validation.

Type

boolean

Default Value

false

id

Description

The id of the input. Used to connect label to input.

Type

string

maskProps

Description

Mask Props

Type

MaskProps

name

Description

The name of the text input. Submitted with its owning form as part of a name/value pair.

Type

string

onChange

Description

The callback function. Triggered when any character is added or removed from the input.

Type

ChangeEventHandler<HTMLInputElement> & ((e: ChangeEvent<HTMLInputElement>) => void)

placeholder

Description

Shows an example of what could be inputted. Only visible when no value is present. Commonly used as a "pseudo" helper message.

Type

string

style

Type

never

textAlign

Description

aligns the Text of the input

Type

("left" | "right"

value

Description

The inputted value. Can be used to prepopulate data.

Type

(string | number | readonly string[]) & string

© 2025