UNPKG

@postnord/web-components

Version:

PostNord Web Components

104 lines (103 loc) 3.85 kB
import dayjs from 'dayjs'; import 'dayjs/locale/sv.js'; import 'dayjs/locale/en.js'; import 'dayjs/locale/da.js'; import 'dayjs/locale/fi.js'; import 'dayjs/locale/nb.js'; import { PnLanguages } from '../types'; declare const CALENDAR = "calendar"; declare const MONTHS = "months"; declare const YEARS = "years"; export type DateType = 'date' | 'month' | 'year'; type GridDay = { day: number; date?: number; blank?: boolean; }; type GridWeek = { week: string; list: GridDay[]; }; export type GridDate = GridWeek[]; export type DateObject = { year?: number; month?: number; date?: number; day?: number; }; export type DateObjectStrict = { year: number; month: number; date: number; day?: number; }; export type CalendarView = typeof CALENDAR | typeof MONTHS | typeof YEARS; export type PnDatePickerSelectEvent = { start: string; end?: string; days?: number; }; export type PnDatePickerFocusOptions = { /** Select the first focusable element. */ first?: boolean; /** Select the focusable element in the grid view. */ grid?: boolean; }; export { CALENDAR, MONTHS, YEARS }; export declare function getToday(): dayjs.Dayjs; export declare function getDayjsObject({ year, month, date }: DateObjectStrict): dayjs.Dayjs; /** Validate the date. */ export declare function validateDate(value: string | DateObjectStrict, format: string): boolean; /** * Get the Dayjs object with the value & format param. **/ export declare function getDate(value: string | DateObjectStrict, format: string): dayjs.Dayjs; /** Get a readable i18n format of the date. */ export declare function getReadableDate(date: DateObjectStrict, lang: PnLanguages, format: string): string; export declare function getDateJs({ year, month, date, day }: DateObjectStrict): dayjs.Dayjs; export declare function getDateObject(data: dayjs.Dayjs | string, format?: string): DateObjectStrict; export declare function getDiff(from: string | DateObjectStrict, to: string | DateObjectStrict, format: string): number; export declare function isBefore(data: string | DateObjectStrict, max: string | DateObjectStrict, format: string, type: DateType): boolean; export declare function isAfter(data: string | DateObjectStrict, min: string | DateObjectStrict, format: string, type: DateType): boolean; export declare function selectedDate(dateOne: string | DateObjectStrict, dateTwo: string | DateObjectStrict, format: string, type: DateType): boolean; export declare function modifyDate({ data, amount, unit, minus, plus, }: { data: dayjs.Dayjs; amount?: number; unit: dayjs.ManipulateType; minus?: boolean; plus?: boolean; }): dayjs.Dayjs; /** Set another year for the value. */ export declare function setYear({ year, minus, plus, }: { year: number; minus?: boolean; plus?: boolean; }): number; /** * You select a month you wish to decrease or increase by 1. */ export declare function setMonth({ month, minus, plus, }: { month: number; minus?: boolean; plus?: boolean; }): number; export declare function setDay(date: DateObjectStrict, { minus, plus, }: { minus?: boolean; plus?: boolean; }): number; export declare function navigateGrid(code: string, data: DateObjectStrict, disableWeekends: boolean, type: DateType): dayjs.Dayjs; export declare function navDate(code: string, data: DateObjectStrict, disableWeekend: boolean): dayjs.Dayjs; export declare function navList(key: string, data: DateObjectStrict, type: DateType): dayjs.Dayjs; export declare function getGrid(year: number, month: number): GridDate; export declare function getCode(code: string): { enter: boolean; space: boolean; next: boolean; previous: boolean; down: boolean; upwards: boolean; pageDown: boolean; pageUp: boolean; end: boolean; home: boolean; };