UNPKG

9.9 kBTypeScriptView Raw
1import { ChangeDetectorRef, ComponentFactoryResolver, ElementRef, EventEmitter, NgZone, OnChanges, OnDestroy, Renderer2, SimpleChanges, TemplateRef, ViewContainerRef } from '@angular/core';
2import { TranslationWidth } from '@angular/common';
3import { AbstractControl, ControlValueAccessor, ValidationErrors, Validator } from '@angular/forms';
4import { PlacementArray } from '../util/positioning';
5import { NgbDateAdapter } from './adapters/ngb-date-adapter';
6import { NgbDatepickerNavigateEvent } from './datepicker';
7import { DayTemplateContext } from './datepicker-day-template-context';
8import { NgbCalendar } from './ngb-calendar';
9import { NgbDate } from './ngb-date';
10import { NgbDateParserFormatter } from './ngb-date-parser-formatter';
11import { NgbDateStruct } from './ngb-date-struct';
12import { NgbInputDatepickerConfig } from './datepicker-input-config';
13/**
14 * A directive that allows to stick a datepicker popup to an input field.
15 *
16 * Manages interaction with the input field itself, does value formatting and provides forms integration.
17 */
18export declare class NgbInputDatepicker implements OnChanges, OnDestroy, ControlValueAccessor, Validator {
19 private _parserFormatter;
20 private _elRef;
21 private _vcRef;
22 private _renderer;
23 private _cfr;
24 private _ngZone;
25 private _calendar;
26 private _dateAdapter;
27 private _document;
28 private _changeDetector;
29 static ngAcceptInputType_autoClose: boolean | string;
30 static ngAcceptInputType_disabled: boolean | '';
31 static ngAcceptInputType_navigation: string;
32 static ngAcceptInputType_outsideDays: string;
33 static ngAcceptInputType_weekdays: boolean | number;
34 private _cRef;
35 private _disabled;
36 private _elWithFocus;
37 private _model;
38 private _inputValue;
39 private _zoneSubscription;
40 /**
41 * Indicates whether the datepicker popup should be closed automatically after date selection / outside click or not.
42 *
43 * * `true` - the popup will close on both date selection and outside click.
44 * * `false` - the popup can only be closed manually via `close()` or `toggle()` methods.
45 * * `"inside"` - the popup will close on date selection, but not outside clicks.
46 * * `"outside"` - the popup will close only on the outside click and not on date selection/inside clicks.
47 *
48 * @since 3.0.0
49 */
50 autoClose: boolean | 'inside' | 'outside';
51 /**
52 * An optional class applied to the datepicker popup element.
53 *
54 * @since 9.1.0
55 */
56 datepickerClass: string;
57 /**
58 * The reference to a custom template for the day.
59 *
60 * Allows to completely override the way a day 'cell' in the calendar is displayed.
61 *
62 * See [`DayTemplateContext`](#/components/datepicker/api#DayTemplateContext) for the data you get inside.
63 */
64 dayTemplate: TemplateRef<DayTemplateContext>;
65 /**
66 * The callback to pass any arbitrary data to the template cell via the
67 * [`DayTemplateContext`](#/components/datepicker/api#DayTemplateContext)'s `data` parameter.
68 *
69 * `current` is the month that is currently displayed by the datepicker.
70 *
71 * @since 3.3.0
72 */
73 dayTemplateData: (date: NgbDate, current?: {
74 year: number;
75 month: number;
76 }) => any;
77 /**
78 * The number of months to display.
79 */
80 displayMonths: number;
81 /**
82 * The first day of the week.
83 *
84 * With default calendar we use ISO 8601: 'weekday' is 1=Mon ... 7=Sun.
85 */
86 firstDayOfWeek: number;
87 /**
88 * The reference to the custom template for the datepicker footer.
89 *
90 * @since 3.3.0
91 */
92 footerTemplate: TemplateRef<any>;
93 /**
94 * The callback to mark some dates as disabled.
95 *
96 * It is called for each new date when navigating to a different month.
97 *
98 * `current` is the month that is currently displayed by the datepicker.
99 */
100 markDisabled: (date: NgbDate, current?: {
101 year: number;
102 month: number;
103 }) => boolean;
104 /**
105 * The earliest date that can be displayed or selected. Also used for form validation.
106 *
107 * If not provided, 'year' select box will display 10 years before the current month.
108 */
109 minDate: NgbDateStruct;
110 /**
111 * The latest date that can be displayed or selected. Also used for form validation.
112 *
113 * If not provided, 'year' select box will display 10 years after the current month.
114 */
115 maxDate: NgbDateStruct;
116 /**
117 * Navigation type.
118 *
119 * * `"select"` - select boxes for month and navigation arrows
120 * * `"arrows"` - only navigation arrows
121 * * `"none"` - no navigation visible at all
122 */
123 navigation: 'select' | 'arrows' | 'none';
124 /**
125 * The way of displaying days that don't belong to the current month.
126 *
127 * * `"visible"` - days are visible
128 * * `"hidden"` - days are hidden, white space preserved
129 * * `"collapsed"` - days are collapsed, so the datepicker height might change between months
130 *
131 * For the 2+ months view, days in between months are never shown.
132 */
133 outsideDays: 'visible' | 'collapsed' | 'hidden';
134 /**
135 * The preferred placement of the datepicker popup.
136 *
137 * Possible values are `"top"`, `"top-left"`, `"top-right"`, `"bottom"`, `"bottom-left"`,
138 * `"bottom-right"`, `"left"`, `"left-top"`, `"left-bottom"`, `"right"`, `"right-top"`,
139 * `"right-bottom"`
140 *
141 * Accepts an array of strings or a string with space separated possible values.
142 *
143 * The default order of preference is `"bottom-left bottom-right top-left top-right"`
144 *
145 * Please see the [positioning overview](#/positioning) for more details.
146 */
147 placement: PlacementArray;
148 /**
149 * If `true`, when closing datepicker will focus element that was focused before datepicker was opened.
150 *
151 * Alternatively you could provide a selector or an `HTMLElement` to focus. If the element doesn't exist or invalid,
152 * we'll fallback to focus document body.
153 *
154 * @since 5.2.0
155 */
156 restoreFocus: true | string | HTMLElement;
157 /**
158 * If `true`, week numbers will be displayed.
159 */
160 showWeekNumbers: boolean;
161 /**
162 * The date to open calendar with.
163 *
164 * With the default calendar we use ISO 8601: 'month' is 1=Jan ... 12=Dec.
165 * If nothing or invalid date is provided, calendar will open with current month.
166 *
167 * You could use `navigateTo(date)` method as an alternative.
168 */
169 startDate: {
170 year: number;
171 month: number;
172 day?: number;
173 };
174 /**
175 * A selector specifying the element the datepicker popup should be appended to.
176 *
177 * Currently only supports `"body"`.
178 */
179 container: string;
180 /**
181 * A css selector or html element specifying the element the datepicker popup should be positioned against.
182 *
183 * By default the input is used as a target.
184 *
185 * @since 4.2.0
186 */
187 positionTarget: string | HTMLElement;
188 /**
189 * The way weekdays should be displayed.
190 *
191 * * `true` - weekdays are displayed using default width
192 * * `false` - weekdays are not displayed
193 * * `TranslationWidth` - weekdays are displayed using specified width
194 *
195 * @since 9.1.0
196 */
197 weekdays: TranslationWidth | boolean;
198 /**
199 * An event emitted when user selects a date using keyboard or mouse.
200 *
201 * The payload of the event is currently selected `NgbDate`.
202 *
203 * @since 1.1.1
204 */
205 dateSelect: EventEmitter<NgbDate>;
206 /**
207 * Event emitted right after the navigation happens and displayed month changes.
208 *
209 * See [`NgbDatepickerNavigateEvent`](#/components/datepicker/api#NgbDatepickerNavigateEvent) for the payload info.
210 */
211 navigate: EventEmitter<NgbDatepickerNavigateEvent>;
212 /**
213 * An event fired after closing datepicker window.
214 *
215 * @since 4.2.0
216 */
217 closed: EventEmitter<void>;
218 get disabled(): any;
219 set disabled(value: any);
220 private _onChange;
221 private _onTouched;
222 private _validatorChange;
223 constructor(_parserFormatter: NgbDateParserFormatter, _elRef: ElementRef<HTMLInputElement>, _vcRef: ViewContainerRef, _renderer: Renderer2, _cfr: ComponentFactoryResolver, _ngZone: NgZone, _calendar: NgbCalendar, _dateAdapter: NgbDateAdapter<any>, _document: any, _changeDetector: ChangeDetectorRef, config: NgbInputDatepickerConfig);
224 registerOnChange(fn: (value: any) => any): void;
225 registerOnTouched(fn: () => any): void;
226 registerOnValidatorChange(fn: () => void): void;
227 setDisabledState(isDisabled: boolean): void;
228 validate(c: AbstractControl): ValidationErrors | null;
229 writeValue(value: any): void;
230 manualDateChange(value: string, updateView?: boolean): void;
231 isOpen(): boolean;
232 /**
233 * Opens the datepicker popup.
234 *
235 * If the related form control contains a valid date, the corresponding month will be opened.
236 */
237 open(): void;
238 /**
239 * Closes the datepicker popup.
240 */
241 close(): void;
242 /**
243 * Toggles the datepicker popup.
244 */
245 toggle(): void;
246 /**
247 * Navigates to the provided date.
248 *
249 * With the default calendar we use ISO 8601: 'month' is 1=Jan ... 12=Dec.
250 * If nothing or invalid date provided calendar will open current month.
251 *
252 * Use the `[startDate]` input as an alternative.
253 */
254 navigateTo(date?: {
255 year: number;
256 month: number;
257 day?: number;
258 }): void;
259 onBlur(): void;
260 onFocus(): void;
261 ngOnChanges(changes: SimpleChanges): void;
262 ngOnDestroy(): void;
263 private _applyDatepickerInputs;
264 private _applyPopupClass;
265 private _applyPopupStyling;
266 private _subscribeForDatepickerOutputs;
267 private _writeModelValue;
268 private _fromDateStruct;
269 private _updatePopupPosition;
270}