Skip to main content

DateTimeFabric component

Component for rendering a date/time input control.

📝 Signature​

DateTimeFabric(props: {
styles: {
backgroundColor: string;
borderColor: string;
borderSize?: number;
roundness?: number;
textColor?: string;
errorColor: string;
scale?: number;
};
l10n?: L10n.Namespace;
id?: string;
mode?: "date" | "datetime";
placeholder?: string;
required?: boolean;
disabled?: boolean;
readOnly?: boolean;
error?: boolean;
tabIndex?: number;
value?: Date | number | Value;
ariaDescribedBy?: string;
onChange?: (date: Date) => Date | void;
onFocus?: (e: FocusEvent) => string | void;
onBlur?: (e: FocusEvent) => string | void;
onAutoFocus?: (el: HTMLInputElement | null) => void;
onSubmit?: () => void;
onCancel?: () => void;
}): JSX.Element

📇 Props​

NameTypeOptionalDescription
stylesobjectNoSpecifies the styles for the input component. Supports the following styles:
- backgroundColor: Background color for the input control;
- borderColor: Border color for the input control;
- borderSize: Optional border size in pixels for the input control;
- roundness: Optional roundness in pixels for the input control;
- textColor: Optional text color for the input control;
- errorColor: Error color for the input control;
- scale: Optional scale factor for the input control (defaults to 1).
l10nL10n.NamespaceYesSpecifies the translations for the component labels.
idstringYesOptional identifier for the component.
mode"date" | "datetime"YesOptional mode to determine the component input type (defaults to date).
placeholderstringYesOptional placeholder that is shown when there is no value entered.
requiredbooleanYesSpecifies if the component is required.
disabledbooleanYesSpecifies if the component is disabled.
readOnlybooleanYesSpecifies if the component is read-only.
errorbooleanYesSpecifies if the component has an error.
tabIndexnumberYesSpecifies the tabindex for the component.
valueDate | number | ValueYesSpecifies the value for the component. When a Date or number is specified, this is the initial value for the date control. When a Value is supplied, this initial date/time is retrieved from the Value instance. Changes made in the date/time control are automatically reflected to the Value instance.
ariaDescribedBystringYesSpecifies the aria-describedby identifier of the element that describes the component.
onChange(date: Date) => Date | voidYesInvoked when the value of the component is changed.
onFocus(e: FocusEvent) => string | voidYesInvoked when the component gets focus.
onBlur(e: FocusEvent) => string | voidYesInvoked when the component loses focus.
onAutoFocus(el: HTMLInputElement | null) => voidYesInvoked when the HTML element of the component is available for auto-focus.
onSubmit() => voidYesInvoked when the user presses the Shift + Enter key combination or the Tab key (this event is often used to go to the next input control in a form).
onCancel() => voidYesInvoked when the user presses the Shift + Tab key combination (this event is often used to go to the previous input control in a form).

↩ī¸ Return value​

Returns the JSX.Element for the component.

👩‍đŸ’ģ Example​

import { DateTimeFabric } from "tripetto-runner-fabric/components/datetime";

const DateTimeFabricExample = () => (
<DateTimeFabric
styles={{
backgroundColor: "white",
borderColor: "black",
errorColor: "red"
}}
onChange={(date) => console.log(`Entered date: ${date.toString()}`)}
/>
);