datepicker.d.ts 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  1. import { AfterViewInit, ChangeDetectorRef, ElementRef, EventEmitter, NgZone, OnChanges, OnDestroy, OnInit, SimpleChanges, TemplateRef } from '@angular/core';
  2. import { ControlValueAccessor } from '@angular/forms';
  3. import { NgbCalendar } from './ngb-calendar';
  4. import { NgbDate } from './ngb-date';
  5. import { NgbDatepickerService } from './datepicker-service';
  6. import { NgbDatepickerKeyboardService } from './datepicker-keyboard-service';
  7. import { DatepickerViewModel, NavigationEvent } from './datepicker-view-model';
  8. import { DayTemplateContext } from './datepicker-day-template-context';
  9. import { NgbDatepickerConfig } from './datepicker-config';
  10. import { NgbDateAdapter } from './adapters/ngb-date-adapter';
  11. import { NgbDateStruct } from './ngb-date-struct';
  12. import { NgbDatepickerI18n } from './datepicker-i18n';
  13. /**
  14. * An event emitted right before the navigation happens and the month displayed by the datepicker changes.
  15. */
  16. export interface NgbDatepickerNavigateEvent {
  17. /**
  18. * The currently displayed month.
  19. */
  20. current: {
  21. year: number;
  22. month: number;
  23. };
  24. /**
  25. * The month we're navigating to.
  26. */
  27. next: {
  28. year: number;
  29. month: number;
  30. };
  31. /**
  32. * Calling this function will prevent navigation from happening.
  33. *
  34. * @since 4.1.0
  35. */
  36. preventDefault: () => void;
  37. }
  38. /**
  39. * An interface that represents the readonly public state of the datepicker.
  40. *
  41. * Accessible via the `datepicker.state` getter
  42. *
  43. * @since 5.2.0
  44. */
  45. export interface NgbDatepickerState {
  46. /**
  47. * The earliest date that can be displayed or selected
  48. */
  49. readonly minDate: NgbDate;
  50. /**
  51. * The latest date that can be displayed or selected
  52. */
  53. readonly maxDate: NgbDate;
  54. /**
  55. * The first visible date of currently displayed months
  56. */
  57. readonly firstDate: NgbDate;
  58. /**
  59. * The last visible date of currently displayed months
  60. */
  61. readonly lastDate: NgbDate;
  62. /**
  63. * The date currently focused by the datepicker
  64. */
  65. readonly focusedDate: NgbDate;
  66. }
  67. /**
  68. * A highly configurable component that helps you with selecting calendar dates.
  69. *
  70. * `NgbDatepicker` is meant to be displayed inline on a page or put inside a popup.
  71. */
  72. export declare class NgbDatepicker implements OnDestroy, OnChanges, OnInit, AfterViewInit, ControlValueAccessor {
  73. private _service;
  74. private _calendar;
  75. i18n: NgbDatepickerI18n;
  76. private _keyboardService;
  77. private _elementRef;
  78. private _ngbDateAdapter;
  79. private _ngZone;
  80. model: DatepickerViewModel;
  81. private _monthsEl;
  82. private _controlValue;
  83. private _destroyed$;
  84. private _publicState;
  85. /**
  86. * The reference to a custom template for the day.
  87. *
  88. * Allows to completely override the way a day 'cell' in the calendar is displayed.
  89. *
  90. * See [`DayTemplateContext`](#/components/datepicker/api#DayTemplateContext) for the data you get inside.
  91. */
  92. dayTemplate: TemplateRef<DayTemplateContext>;
  93. /**
  94. * The callback to pass any arbitrary data to the template cell via the
  95. * [`DayTemplateContext`](#/components/datepicker/api#DayTemplateContext)'s `data` parameter.
  96. *
  97. * `current` is the month that is currently displayed by the datepicker.
  98. *
  99. * @since 3.3.0
  100. */
  101. dayTemplateData: (date: NgbDate, current: {
  102. year: number;
  103. month: number;
  104. }) => any;
  105. /**
  106. * The number of months to display.
  107. */
  108. displayMonths: number;
  109. /**
  110. * The first day of the week.
  111. *
  112. * With default calendar we use ISO 8601: 'weekday' is 1=Mon ... 7=Sun.
  113. */
  114. firstDayOfWeek: number;
  115. /**
  116. * The reference to the custom template for the datepicker footer.
  117. *
  118. * @since 3.3.0
  119. */
  120. footerTemplate: TemplateRef<any>;
  121. /**
  122. * The callback to mark some dates as disabled.
  123. *
  124. * It is called for each new date when navigating to a different month.
  125. *
  126. * `current` is the month that is currently displayed by the datepicker.
  127. */
  128. markDisabled: (date: NgbDate, current: {
  129. year: number;
  130. month: number;
  131. }) => boolean;
  132. /**
  133. * The latest date that can be displayed or selected.
  134. *
  135. * If not provided, 'year' select box will display 10 years after the current month.
  136. */
  137. maxDate: NgbDateStruct;
  138. /**
  139. * The earliest date that can be displayed or selected.
  140. *
  141. * If not provided, 'year' select box will display 10 years before the current month.
  142. */
  143. minDate: NgbDateStruct;
  144. /**
  145. * Navigation type.
  146. *
  147. * * `"select"` - select boxes for month and navigation arrows
  148. * * `"arrows"` - only navigation arrows
  149. * * `"none"` - no navigation visible at all
  150. */
  151. navigation: 'select' | 'arrows' | 'none';
  152. /**
  153. * The way of displaying days that don't belong to the current month.
  154. *
  155. * * `"visible"` - days are visible
  156. * * `"hidden"` - days are hidden, white space preserved
  157. * * `"collapsed"` - days are collapsed, so the datepicker height might change between months
  158. *
  159. * For the 2+ months view, days in between months are never shown.
  160. */
  161. outsideDays: 'visible' | 'collapsed' | 'hidden';
  162. /**
  163. * If `true`, weekdays will be displayed.
  164. */
  165. showWeekdays: boolean;
  166. /**
  167. * If `true`, week numbers will be displayed.
  168. */
  169. showWeekNumbers: boolean;
  170. /**
  171. * The date to open calendar with.
  172. *
  173. * With the default calendar we use ISO 8601: 'month' is 1=Jan ... 12=Dec.
  174. * If nothing or invalid date is provided, calendar will open with current month.
  175. *
  176. * You could use `navigateTo(date)` method as an alternative.
  177. */
  178. startDate: {
  179. year: number;
  180. month: number;
  181. day?: number;
  182. };
  183. /**
  184. * An event emitted right before the navigation happens and displayed month changes.
  185. *
  186. * See [`NgbDatepickerNavigateEvent`](#/components/datepicker/api#NgbDatepickerNavigateEvent) for the payload info.
  187. */
  188. navigate: EventEmitter<NgbDatepickerNavigateEvent>;
  189. /**
  190. * An event emitted when user selects a date using keyboard or mouse.
  191. *
  192. * The payload of the event is currently selected `NgbDate`.
  193. *
  194. * @since 5.2.0
  195. */
  196. dateSelect: EventEmitter<NgbDate>;
  197. /**
  198. * An event emitted when user selects a date using keyboard or mouse.
  199. *
  200. * The payload of the event is currently selected `NgbDate`.
  201. *
  202. * Please use 'dateSelect' output instead, this will be deprecated in version 6.0 due to collision with native
  203. * 'select' event.
  204. */
  205. select: EventEmitter<NgbDate>;
  206. onChange: (_: any) => void;
  207. onTouched: () => void;
  208. constructor(_service: NgbDatepickerService, _calendar: NgbCalendar, i18n: NgbDatepickerI18n, config: NgbDatepickerConfig, _keyboardService: NgbDatepickerKeyboardService, cd: ChangeDetectorRef, _elementRef: ElementRef<HTMLElement>, _ngbDateAdapter: NgbDateAdapter<any>, _ngZone: NgZone);
  209. /**
  210. * Returns the readonly public state of the datepicker
  211. *
  212. * @since 5.2.0
  213. */
  214. readonly state: NgbDatepickerState;
  215. /**
  216. * Focuses on given date.
  217. */
  218. focusDate(date: NgbDateStruct): void;
  219. /**
  220. * Selects focused date.
  221. */
  222. focusSelect(): void;
  223. focus(): void;
  224. /**
  225. * Navigates to the provided date.
  226. *
  227. * With the default calendar we use ISO 8601: 'month' is 1=Jan ... 12=Dec.
  228. * If nothing or invalid date provided calendar will open current month.
  229. *
  230. * Use the `[startDate]` input as an alternative.
  231. */
  232. navigateTo(date?: {
  233. year: number;
  234. month: number;
  235. day?: number;
  236. }): void;
  237. ngAfterViewInit(): void;
  238. ngOnDestroy(): void;
  239. ngOnInit(): void;
  240. ngOnChanges(changes: SimpleChanges): void;
  241. onDateSelect(date: NgbDate): void;
  242. onKeyDown(event: KeyboardEvent): void;
  243. onNavigateDateSelect(date: NgbDate): void;
  244. onNavigateEvent(event: NavigationEvent): void;
  245. registerOnChange(fn: (value: any) => any): void;
  246. registerOnTouched(fn: () => any): void;
  247. setDisabledState(disabled: boolean): void;
  248. writeValue(value: any): void;
  249. }