From b458bcb4ca1ca16fd2e58bf22e4ca7fe4f4988db Mon Sep 17 00:00:00 2001 From: Adam Kwiatek Date: Fri, 25 Oct 2019 22:11:49 +0200 Subject: [PATCH] [lightpick] Lightpick 1.4.1 (#39411) * New options `onMonthsChange` and `onYearsChange`. * New option `weekdayStyle`. * Remove enum definitions which are not provided by the actual library. --- types/lightpick/index.d.ts | 65 ++++++++++++++++++++---------- types/lightpick/lightpick-tests.ts | 7 +++- 2 files changed, 49 insertions(+), 23 deletions(-) diff --git a/types/lightpick/index.d.ts b/types/lightpick/index.d.ts index 8bce2b0d5e..407d02d209 100644 --- a/types/lightpick/index.d.ts +++ b/types/lightpick/index.d.ts @@ -1,4 +1,4 @@ -// Type definitions for Lightpick 1.3 +// Type definitions for Lightpick 1.4 // Project: https://wakirin.github.io/Lightpick // Definitions by: Adam Kwiatek // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped @@ -239,6 +239,12 @@ declare namespace Lightpick { */ inline?: boolean; + /** + * Determines the weekday display style. + * Two weekdays may have the same narrow style for some locales (e.g. Tuesday's narrow style is also T). + */ + weekdayStyle?: Options.WeekdayStyle; + /** * Dropdown selections for years, months. Can be false for disable both dropdowns. */ @@ -262,32 +268,35 @@ declare namespace Lightpick { onClose?: Options.OnCloseFn; onError?: Options.OnErrorFn; + + /** + * Triggered when the months select is changed. + */ + onMonthsChange?: Options.OnMonthsChangeFn; + + /** + * Triggered when the years select is changed. + */ + onYearsChange?: Options.OnYearsChangeFn; } namespace Options { type Field = Element & { value: string }; - enum DayOfWeek { - Monday = 1, - Tuesday, - Wednesday, - Thursday, - Friday, - Saturday, - Sunday, - } + type DayOfWeek = 1 | 2 | 3 | 4 | 5 | 6 | 7; - enum Orientation { - Auto = 'auto', - Left = 'left', - Right = 'right', - Top = 'top', - Bottom = 'bottom', - TopLeft = 'top left', - TopRight = 'top right', - BottomLeft = 'bottom left', - BottomRight = 'bottom right', - } + type Orientation = + | 'auto' + | 'left' + | 'right' + | 'top' + | 'bottom' + | 'top left' + | 'top right' + | 'bottom left' + | 'bottom right'; + + type WeekdayStyle = 'long' | 'short' | 'narrow'; interface Dropdowns { /** @@ -381,5 +390,19 @@ declare namespace Lightpick { interface OnErrorFn { (this: Lightpick, message: string): void; } + + /** + * Callback function for when the months select is changed. + */ + interface OnMonthsChangeFn { + (this: Lightpick, month: number): void; + } + + /** + * Callback function for when the years select is changed. + */ + interface OnYearsChangeFn { + (this: Lightpick, year: number): void; + } } } diff --git a/types/lightpick/lightpick-tests.ts b/types/lightpick/lightpick-tests.ts index 1723dcf544..0dbd807fd5 100644 --- a/types/lightpick/lightpick-tests.ts +++ b/types/lightpick/lightpick-tests.ts @@ -28,7 +28,7 @@ const inputDate = moment(); options.startDate = inputDate; options.field = inputField; options.secondField = inputField; - options.firstDay = Lightpick.Options.DayOfWeek.Monday; + options.firstDay = 1; options.footer = true; options.footer = '
FOOTER
'; options.format = 'DD/MM/YYYY'; @@ -54,7 +54,7 @@ const inputDate = moment(); options.minDays = 1; options.numberOfMonths = 1; options.numberOfColumns = 1; - options.orientation = Lightpick.Options.Orientation.TopRight; + options.orientation = 'top right'; options.parentEl = 'body'; options.repick = true; options.selectForward = true; @@ -62,6 +62,7 @@ const inputDate = moment(); options.separator = ' - '; options.singleDate = true; options.tooltipNights = true; + options.weekdayStyle = 'short'; options.onOpen = () => console.log('open event'); options.onClose = () => console.log('close event'); options.onError = (errorMsg: string) => console.log(`error event: ${errorMsg}`); @@ -71,6 +72,8 @@ const inputDate = moment(); str += to ? to.format('Do MMMM YYYY') : '...'; console.log(`str: ${str}`); }; + options.onMonthsChange = (month: number) => console.log(`changing to month ${month} event`); + options.onYearsChange = (year: number) => console.log(`changing to year ${year} event`); new Lightpick(options); }