@intility/bifrost-react
Version:
React library for Intility's design system, Bifrost.
29 lines (28 loc) • 1.03 kB
TypeScript
export type DateTimeFormatterOptions = {
/** Date object */
date: Date | string;
/** Display either 'date' (default), 'datetime', or 'time' */
show?: "date" | "datetime" | "time";
/** Optional Intl.DateTimeFormatOptions object (overrides default bifrost format) */
options?: Intl.DateTimeFormatOptions;
/** Optional Intl.LocalesArgument (overrides current bifrost locale, "en-us" or "nb-no") */
locale?: Intl.LocalesArgument;
};
/**
* Context-aware date and time formatter using locale and options from the
* current Bifrost context unless specified
*
* @returns A function that formats a date and/or time
*
* @see https://bifrost.intility.com/react/useDateTimeFormatter
*
* @example
* const dateTimeFormatter = useDateTimeFormatter();
*
* // "04/03/2024"
* const formattedDate = dateTimeFormatter({
* show: "date",
* date: "2024-03-04T10:23:11.408Z",
* });
*/
export default function useDateTimeFormatter(): ({ date, show, locale, options, }: DateTimeFormatterOptions) => string;