1 | import { ChangeDetectorRef, ElementRef, InjectionToken, OnDestroy, Type } from '@angular/core';
|
2 | import { ControlValueAccessor, ValidationErrors, Validator, ValidatorFn } from '@angular/forms';
|
3 | import { Observable, Subject, Subscription } from 'rxjs';
|
4 | import { NbDateService } from '../calendar-kit/services/date.service';
|
5 | import * as i0 from "@angular/core";
|
6 | /**
|
7 | * The `NbDatepickerAdapter` instances provide way how to parse, format and validate
|
8 | * different date types.
|
9 | * */
|
10 | export declare abstract class NbDatepickerAdapter<D> {
|
11 | /**
|
12 | * Picker component class.
|
13 | * */
|
14 | abstract picker: Type<any>;
|
15 | /**
|
16 | * Parse date string according to the format.
|
17 | * */
|
18 | abstract parse(value: string, format: string): D;
|
19 | /**
|
20 | * Format date according to the format.
|
21 | * */
|
22 | abstract format(value: D, format: string): string;
|
23 | /**
|
24 | * Validates date string according to the passed format.
|
25 | * */
|
26 | abstract isValid(value: string, format: string): boolean;
|
27 | }
|
28 | /**
|
29 | * Validators config that will be used by form control to perform proper validation.
|
30 | * */
|
31 | export interface NbPickerValidatorConfig<D> {
|
32 | /**
|
33 | * Minimum date available in picker.
|
34 | * */
|
35 | min: D;
|
36 | /**
|
37 | * Maximum date available in picker.
|
38 | * */
|
39 | max: D;
|
40 | /**
|
41 | * Predicate that determines is value available for picking.
|
42 | * */
|
43 | filter: (D: any) => boolean;
|
44 | }
|
45 | /**
|
46 | * Datepicker is an control that can pick any values anyway.
|
47 | * It has to be bound to the datepicker directive through nbDatepicker input.
|
48 | * */
|
49 | export declare abstract class NbDatepicker<T, D = T> {
|
50 | /**
|
51 | * HTML input element date format.
|
52 | * */
|
53 | abstract format: string;
|
54 | abstract get value(): T;
|
55 | abstract set value(value: T);
|
56 | abstract get valueChange(): Observable<T>;
|
57 | abstract get init(): Observable<void>;
|
58 | /**
|
59 | * Attaches datepicker to the native input element.
|
60 | * */
|
61 | abstract attach(hostRef: ElementRef): any;
|
62 | /**
|
63 | * Returns validator configuration based on the input properties.
|
64 | * */
|
65 | abstract getValidatorConfig(): NbPickerValidatorConfig<D>;
|
66 | abstract show(): any;
|
67 | abstract hide(): any;
|
68 | abstract shouldHide(): boolean;
|
69 | abstract get isShown(): boolean;
|
70 | abstract get blur(): Observable<void>;
|
71 | abstract get formatChanged$(): Observable<void>;
|
72 | }
|
73 | export declare const NB_DATE_ADAPTER: InjectionToken<NbDatepickerAdapter<any>>;
|
74 | export declare const NB_DATE_SERVICE_OPTIONS: InjectionToken<unknown>;
|
75 | /**
|
76 | * The `NbDatepickerDirective` is form control that gives you ability to select dates and ranges. The datepicker
|
77 | * is shown when input receives a `focus` event.
|
78 | *
|
79 | * ```html
|
80 | * <input [nbDatepicker]="datepicker">
|
81 | * <nb-datepicker #datepicker></nb-datepicker>
|
82 | * ```
|
83 | *
|
84 | * @stacked-example(Showcase, datepicker/datepicker-showcase.component)
|
85 | *
|
86 | * ### Installation
|
87 | *
|
88 | * Import `NbDatepickerModule.forRoot()` to your root module.
|
89 | * ```ts
|
90 | * @NgModule({
|
91 | * imports: [
|
92 | * // ...
|
93 | * NbDatepickerModule.forRoot(),
|
94 | * ],
|
95 | * })
|
96 | * export class AppModule { }
|
97 | * ```
|
98 | * And `NbDatepickerModule` to your feature module.
|
99 | * ```ts
|
100 | * @NgModule({
|
101 | * imports: [
|
102 | * // ...
|
103 | * NbDatepickerModule,
|
104 | * ],
|
105 | * })
|
106 | *
|
107 | * export class PageModule { }
|
108 | * ```
|
109 | * ### Usage
|
110 | *
|
111 | * If you want to use range selection, you have to use `NbRangepickerComponent` instead:
|
112 | *
|
113 | * ```html
|
114 | * <input [nbDatepicker]="rangepicker">
|
115 | * <nb-rangepicker #rangepicker></nb-rangepicker>
|
116 | * ```
|
117 | *
|
118 | * Both range and date pickers support all parameters as calendar, so, check `NbCalendarComponent` for additional
|
119 | * info.
|
120 | *
|
121 | * @stacked-example(Range showcase, datepicker/rangepicker-showcase.component)
|
122 | *
|
123 | * Datepicker is the form control so it can be bound with angular forms through ngModel and form controls.
|
124 | *
|
125 | * @stacked-example(Forms, datepicker/datepicker-forms.component)
|
126 | *
|
127 | * `NbDatepickerDirective` may be validated using `min` and `max` dates passed to the datepicker.
|
128 | *
|
129 | * @stacked-example(Validation, datepicker/datepicker-validation.component)
|
130 | *
|
131 | * Also `NbDatepickerDirective` may be filtered using `filter` predicate
|
132 | * that receives date object and has to return a boolean value.
|
133 | *
|
134 | * @stacked-example(Filter, datepicker/datepicker-filter.component)
|
135 | *
|
136 | * If you need to pick a time along with the date, you can use nb-date-timepicker
|
137 | *
|
138 | * ```html
|
139 | * <input nbInput placeholder="Pick Date" [nbDatepicker]="dateTimePicker">
|
140 | * <nb-date-timepicker withSeconds #dateTimePicker></nb-date-timepicker>
|
141 | * ```
|
142 | * @stacked-example(Date timepicker, datepicker/date-timepicker-showcase.component)
|
143 | *
|
144 | * A single column picker with options value as time and minute, so users won’t be able to pick
|
145 | * hours and minutes individually.
|
146 | *
|
147 | * @stacked-example(Date timepicker single column, datepicker/date-timepicker-single-column.component)
|
148 |
|
149 | * The `NbDatepickerComponent` supports date formatting:
|
150 | *
|
151 | * ```html
|
152 | * <input [nbDatepicker]="datepicker">
|
153 | * <nb-datepicker #datepicker format="MM\dd\yyyy"></nb-datepicker>
|
154 | * ```
|
155 | * <span id="formatting-issue"></span>
|
156 | * ## Formatting Issue
|
157 | *
|
158 | * By default, datepicker uses angulars `LOCALE_ID` token for localization and `DatePipe` for dates formatting.
|
159 | * And native `Date.parse(...)` for dates parsing. But native `Date.parse` function doesn't support formats.
|
160 | * To provide custom formatting you have to use one of the following packages:
|
161 | *
|
162 | * - `@nebular/moment` - provides moment date adapter that uses moment for date objects. This means datepicker than
|
163 | * will operate only moment date objects. If you want to use it you have to install it: `npm i @nebular/moment`, and
|
164 | * import `NbMomentDateModule` from this package.
|
165 | *
|
166 | * - `@nebular/date-fns` - adapter for popular date-fns library. This way is preferred if you need only date formatting.
|
167 | * Because date-fns is treeshakable, tiny and operates native date objects. If you want to use it you have to
|
168 | * install it: `npm i @nebular/date-fns`, and import `NbDateFnsDateModule` from this package.
|
169 | *
|
170 | * ### NbDateFnsDateModule
|
171 | *
|
172 | * Format is required when using `NbDateFnsDateModule`. You can set it via `format` input on datepicker component:
|
173 | * ```html
|
174 | * <nb-datepicker format="dd.MM.yyyy"></nb-datepicker>
|
175 | * ```
|
176 | * Also format can be set globally with `NbDateFnsDateModule.forRoot({ format: 'dd.MM.yyyy' })` and
|
177 | * `NbDateFnsDateModule.forChild({ format: 'dd.MM.yyyy' })` methods.
|
178 | *
|
179 | * Please note to use some of the formatting tokens you also need to pass
|
180 | * `{ useAdditionalWeekYearTokens: true, useAdditionalDayOfYearTokens: true }` to date-fns parse and format functions.
|
181 | * You can configure options passed this functions by setting `formatOptions` and
|
182 | * `parseOptions` of options object passed to `NbDateFnsDateModule.forRoot` and `NbDateFnsDateModule.forChild` methods.
|
183 | * ```ts
|
184 | * NbDateFnsDateModule.forRoot({
|
185 | * parseOptions: { useAdditionalWeekYearTokens: true, useAdditionalDayOfYearTokens: true },
|
186 | * formatOptions: { useAdditionalWeekYearTokens: true, useAdditionalDayOfYearTokens: true },
|
187 | * })
|
188 | * ```
|
189 | * Further info on `date-fns` formatting tokens could be found at
|
190 | * [date-fns docs](https://date-fns.org/v2.0.0-alpha.27/docs/Unicode-Tokens).
|
191 | *
|
192 | * You can also use `parseOptions` and `formatOptions` to provide locale.
|
193 | * ```ts
|
194 | * import { eo } from 'date-fns/locale';
|
195 | *
|
196 | * @NgModule({
|
197 | * imports: [
|
198 | * NbDateFnsDateModule.forRoot({
|
199 | * parseOptions: { locale: eo },
|
200 | * formatOptions: { locale: eo },
|
201 | * }),
|
202 | * ],
|
203 | * })
|
204 | * ```
|
205 | *
|
206 | * @styles
|
207 | *
|
208 | * datepicker-background-color:
|
209 | * datepicker-border-color:
|
210 | * datepicker-border-style:
|
211 | * datepicker-border-width:
|
212 | * datepicker-border-radius:
|
213 | * datepicker-shadow:
|
214 | * */
|
215 | export declare class NbDatepickerDirective<D> implements OnDestroy, ControlValueAccessor, Validator {
|
216 | protected document: any;
|
217 | protected datepickerAdapters: NbDatepickerAdapter<D>[];
|
218 | protected hostRef: ElementRef;
|
219 | protected dateService: NbDateService<D>;
|
220 | protected changeDetector: ChangeDetectorRef;
|
221 | /**
|
222 | * Provides datepicker component.
|
223 | * */
|
224 | set setPicker(picker: NbDatepicker<D>);
|
225 | protected pickerInputsChangedSubscription: Subscription | undefined;
|
226 | /**
|
227 | * Datepicker adapter.
|
228 | * */
|
229 | protected datepickerAdapter: NbDatepickerAdapter<D>;
|
230 | /**
|
231 | * Datepicker instance.
|
232 | * */
|
233 | protected picker: NbDatepicker<D>;
|
234 | protected destroy$: Subject<void>;
|
235 | protected isDatepickerReady: boolean;
|
236 | protected queue: D | undefined;
|
237 | protected onChange: (D: any) => void;
|
238 | protected onTouched: () => void;
|
239 | /**
|
240 | * Form control validators will be called in validators context, so, we need to bind them.
|
241 | * */
|
242 | protected validator: ValidatorFn;
|
243 | constructor(document: any, datepickerAdapters: NbDatepickerAdapter<D>[], hostRef: ElementRef, dateService: NbDateService<D>, changeDetector: ChangeDetectorRef);
|
244 | /**
|
245 | * Returns html input element.
|
246 | * */
|
247 | get input(): HTMLInputElement;
|
248 | /**
|
249 | * Returns host input value.
|
250 | * */
|
251 | get inputValue(): string;
|
252 | ngOnDestroy(): void;
|
253 | /**
|
254 | * Writes value in picker and html input element.
|
255 | * */
|
256 | writeValue(value: D): void;
|
257 | registerOnChange(fn: any): void;
|
258 | registerOnTouched(fn: any): void;
|
259 | setDisabledState(isDisabled: boolean): void;
|
260 | /**
|
261 | * Form control validation based on picker validator config.
|
262 | * */
|
263 | validate(): ValidationErrors | null;
|
264 | /**
|
265 | * Hides picker, focuses the input
|
266 | */
|
267 | protected hidePicker(): void;
|
268 | /**
|
269 | * Validates that we can parse value correctly.
|
270 | * */
|
271 | protected parseValidator(): ValidationErrors | null;
|
272 | /**
|
273 | * Validates passed value is greater than min.
|
274 | * */
|
275 | protected minValidator(): ValidationErrors | null;
|
276 | /**
|
277 | * Validates passed value is smaller than max.
|
278 | * */
|
279 | protected maxValidator(): ValidationErrors | null;
|
280 | /**
|
281 | * Validates passed value satisfy the filter.
|
282 | * */
|
283 | protected filterValidator(): ValidationErrors | null;
|
284 | /**
|
285 | * Chooses datepicker adapter based on passed picker component.
|
286 | * */
|
287 | protected chooseDatepickerAdapter(): void;
|
288 | /**
|
289 | * Attaches picker to the host input element and subscribes on value changes.
|
290 | * */
|
291 | protected setupPicker(): void;
|
292 | protected writePicker(value: D): void;
|
293 | protected writeInput(value: D): void;
|
294 | /**
|
295 | * Validates if no datepicker adapter provided.
|
296 | * */
|
297 | protected noDatepickerAdapterProvided(): boolean;
|
298 | protected subscribeOnInputChange(): void;
|
299 | /**
|
300 | * Parses input value and write if it isn't null.
|
301 | * */
|
302 | protected handleInputChange(value: string): void;
|
303 | protected parseInputValue(value: any): D | null;
|
304 | static ɵfac: i0.ɵɵFactoryDeclaration<NbDatepickerDirective<any>, never>;
|
305 | static ɵdir: i0.ɵɵDirectiveDeclaration<NbDatepickerDirective<any>, "input[nbDatepicker]", never, { "setPicker": { "alias": "nbDatepicker"; "required": false; }; }, {}, never, never, false, never>;
|
306 | }
|