[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.
This commit is contained in:
Adam Kwiatek 2019-10-25 22:11:49 +02:00 committed by Wesley Wigham
parent 6a0c849210
commit b458bcb4ca
2 changed files with 49 additions and 23 deletions

View File

@ -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 <https://github.com/akwiatek>
// 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;
}
}
}

View File

@ -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 = '<div style="background:red">FOOTER</div>';
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);
}