import { DurationInput } from "@vitality-ds/components";
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
30
-->30m
60
-->1h
90
-->1h 30m
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> ); };
Description
Content to "adorn" the start of the input - typically text, icons or buttons.
Type
{ type: "text"; props: TextAdornmentProps; }
Type
never
Description
Determines whether the user has the ability to interact with the input.
Type
boolean
Default Value
false
Description
Adds additional styling to indicate failed validation.
Type
boolean
Default Value
false
Description
The id of the input. Used to connect label to input.
Type
string
Description
Mask Props
Type
MaskProps
Description
The name of the text input. Submitted with its owning form as part of a name/value pair.
Type
string
Description
The callback function. Triggered when any character is added or removed from the input.
Type
ChangeEventHandler<HTMLInputElement> & ((e: ChangeEvent<HTMLInputElement>) => void)
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
Type
never
Description
aligns the Text of the input
Type
("left" | "right"
Description
The inputted value. Can be used to prepopulate data.
Type
(string | number | readonly string[]) & string