|
| 1 | +import { ElementRef, EventEmitter, Inject, LOCALE_ID, Optional, Input, Directive, Output } from '@angular/core'; |
| 2 | +import { DisplayDensityBase, DisplayDensityToken, IDisplayDensityOptions } from '../core/density'; |
| 3 | +import { InteractionMode } from '../core/enums'; |
| 4 | +import { IToggleView } from '../core/navigation'; |
| 5 | +import { IBaseCancelableBrowserEventArgs, IBaseEventArgs } from '../core/utils'; |
| 6 | +import { DateRange } from '../date-range-picker/public_api'; |
| 7 | +import { IgxOverlayOutletDirective } from '../directives/toggle/toggle.directive'; |
| 8 | +import { IgxInputGroupType, IGX_INPUT_GROUP_TYPE } from '../input-group/public_api'; |
| 9 | +import { OverlaySettings } from '../services/overlay/utilities'; |
| 10 | + |
| 11 | +@Directive() |
| 12 | +export abstract class PickersBaseDirective extends DisplayDensityBase implements IToggleView { |
| 13 | + /** |
| 14 | + * The expected user input format and placeholder. |
| 15 | + * |
| 16 | + * @remarks |
| 17 | + * Default is `"'MM/dd/yyyy'"` |
| 18 | + * |
| 19 | + * @example |
| 20 | + * ```html |
| 21 | + * <igx-date-picker inputFormat="dd/MM/yy"></igx-date-picker> |
| 22 | + * ``` |
| 23 | + */ |
| 24 | + @Input() |
| 25 | + public inputFormat: string; |
| 26 | + |
| 27 | + /** |
| 28 | + * The format used when the editable input(s) are not focused. |
| 29 | + * |
| 30 | + * @remarks |
| 31 | + * Uses Angular's DatePipe. |
| 32 | + * |
| 33 | + * @example |
| 34 | + * ```html |
| 35 | + * <igx-date-picker displayFormat="EE/M/yy"></igx-date-picker> |
| 36 | + * ``` |
| 37 | + * |
| 38 | + */ |
| 39 | + @Input() |
| 40 | + public displayFormat: string; |
| 41 | + |
| 42 | + /** |
| 43 | + * Sets the `placeholder` of the picker's input. |
| 44 | + * |
| 45 | + * @example |
| 46 | + * ```html |
| 47 | + * <igx-date-picker [placeholder]="'Choose your date'"></igx-date-picker> |
| 48 | + * ``` |
| 49 | + */ |
| 50 | + @Input() |
| 51 | + public placeholder = ''; |
| 52 | + |
| 53 | + /** |
| 54 | + * Display calendar in either `dialog` or `dropdown` mode. |
| 55 | + * |
| 56 | + * @remarks |
| 57 | + * Default mode is `dialog` |
| 58 | + * |
| 59 | + * @example |
| 60 | + * ```html |
| 61 | + * <igx-date-picker mode="dropdown"></igx-date-picker> |
| 62 | + * ``` |
| 63 | + */ |
| 64 | + @Input() |
| 65 | + public mode = InteractionMode.Dialog; |
| 66 | + |
| 67 | + /** |
| 68 | + * Custom overlay settings that will be used to display the calendar. |
| 69 | + * |
| 70 | + * @example |
| 71 | + * ```html |
| 72 | + * <igx-date-picker [overlaySettings]="customOverlaySettings"></igx-date-picker> |
| 73 | + * ``` |
| 74 | + */ |
| 75 | + @Input() |
| 76 | + public overlaySettings: OverlaySettings; |
| 77 | + |
| 78 | + /** |
| 79 | + * Enables/Disables the picker. |
| 80 | + * @example |
| 81 | + * ```html |
| 82 | + * <igx-date-picker [disabled]="'true'"></igx-date-picker> |
| 83 | + * ``` |
| 84 | + */ |
| 85 | + @Input() |
| 86 | + public disabled = false; |
| 87 | + |
| 88 | + /** |
| 89 | + * Locale settings used for value formatting and calendar. |
| 90 | + * |
| 91 | + * @remarks |
| 92 | + * Uses Angular's `LOCALE_ID` by default. Affects both input mask and display format if those are not set. |
| 93 | + * If a `locale` is set, it must be registered via `registerLocaleData`. |
| 94 | + * Please refer to https://angular.io/guide/i18n#i18n-pipes. |
| 95 | + * If it is not registered, `Intl` will be used for formatting. |
| 96 | + * |
| 97 | + * @example |
| 98 | + * ```html |
| 99 | + * <igx-date-picker locale="jp"></igx-date-picker> |
| 100 | + * ``` |
| 101 | + */ |
| 102 | + @Input() |
| 103 | + public locale: string; |
| 104 | + |
| 105 | + /** |
| 106 | + * The container used for the popup element. |
| 107 | + * |
| 108 | + * @example |
| 109 | + * ```html |
| 110 | + * <div igxOverlayOutlet #outlet="overlay-outlet"></div> |
| 111 | + * <!-- ... --> |
| 112 | + * <igx-date-picker [outlet]="outlet"></igx-date-picker> |
| 113 | + * <!-- ... --> |
| 114 | + * ``` |
| 115 | + */ |
| 116 | + @Input() |
| 117 | + public outlet: IgxOverlayOutletDirective | ElementRef; |
| 118 | + |
| 119 | + /** |
| 120 | + * Determines how the picker will be styled. |
| 121 | + * |
| 122 | + * @remarks |
| 123 | + * Default is `box`. |
| 124 | + * |
| 125 | + * @example |
| 126 | + * ```html |
| 127 | + * <igx-date-picker [type]="'line'"></igx-date-picker> |
| 128 | + * ``` |
| 129 | + */ |
| 130 | + @Input() |
| 131 | + public set type(val: IgxInputGroupType) { |
| 132 | + this._type = val; |
| 133 | + } |
| 134 | + public get type(): IgxInputGroupType { |
| 135 | + return this._type || this._inputGroupType || 'box'; |
| 136 | + } |
| 137 | + |
| 138 | + /** |
| 139 | + * Emitted right before a selection is done, cancelable. |
| 140 | + * |
| 141 | + * @example |
| 142 | + * ```html |
| 143 | + * <igx-date-picker (selecting)="onSelecting($event)"></igx-date-picker> |
| 144 | + * ``` |
| 145 | + */ |
| 146 | + @Output() |
| 147 | + public selecting: EventEmitter<IBaseCancelableBrowserEventArgs>; |
| 148 | + |
| 149 | + /** |
| 150 | + * Emitted after a selection has been done. |
| 151 | + * |
| 152 | + * @example |
| 153 | + * ```html |
| 154 | + * <igx-date-picker (selected)="onSelection($event)"></igx-date-picker> |
| 155 | + * ``` |
| 156 | + */ |
| 157 | + @Input() |
| 158 | + public abstract selected: Date | DateRange; |
| 159 | + |
| 160 | + /** |
| 161 | + * Emitted when the calendar starts opening, cancelable. |
| 162 | + * |
| 163 | + * @example |
| 164 | + * ```html |
| 165 | + * <igx-date-picker (opening)="handleOpening($event)"></igx-date-picker> |
| 166 | + * ``` |
| 167 | + */ |
| 168 | + @Output() |
| 169 | + public opening: EventEmitter<IBaseCancelableBrowserEventArgs>; |
| 170 | + |
| 171 | + /** |
| 172 | + * Emitted when the picker has opened. |
| 173 | + * |
| 174 | + * @example |
| 175 | + * ```html |
| 176 | + * <igx-date-picker (opened)="handleOpened($event)"></igx-date-picker> |
| 177 | + * ``` |
| 178 | + */ |
| 179 | + @Output() |
| 180 | + public opened: EventEmitter<IBaseEventArgs>; |
| 181 | + |
| 182 | + /** |
| 183 | + * Emitted when the calendar starts closing, cancelable. |
| 184 | + * |
| 185 | + * @example |
| 186 | + * ```html |
| 187 | + * <igx-date-picker (closing)="handleClosing($event)"></igx-date-picker> |
| 188 | + * ``` |
| 189 | + */ |
| 190 | + @Output() |
| 191 | + public closing: EventEmitter<IBaseCancelableBrowserEventArgs>; |
| 192 | + |
| 193 | + /** |
| 194 | + * Emitted when the picker has closed. |
| 195 | + * |
| 196 | + * @example |
| 197 | + * ```html |
| 198 | + * <igx-date-picker (closed)="handleClosed($event)"></igx-date-picker> |
| 199 | + * ``` |
| 200 | + */ |
| 201 | + @Output() |
| 202 | + public closed: EventEmitter<IBaseEventArgs>; |
| 203 | + |
| 204 | + protected _collapsed = true; |
| 205 | + protected _type: IgxInputGroupType; |
| 206 | + protected _minValue: Date | string; |
| 207 | + protected _maxValue: Date | string; |
| 208 | + |
| 209 | + /** |
| 210 | + * Gets the picker's calendar state. |
| 211 | + * |
| 212 | + * @example |
| 213 | + * ```typescript |
| 214 | + * const state = this.picker.collapsed; |
| 215 | + * ``` |
| 216 | + */ |
| 217 | + public get collapsed(): boolean { |
| 218 | + return this._collapsed; |
| 219 | + } |
| 220 | + |
| 221 | + constructor(public element: ElementRef, |
| 222 | + @Inject(LOCALE_ID) protected _localeId: string, |
| 223 | + @Optional() @Inject(DisplayDensityToken) protected _displayDensityOptions?: IDisplayDensityOptions, |
| 224 | + @Optional() @Inject(IGX_INPUT_GROUP_TYPE) protected _inputGroupType?: IgxInputGroupType) { |
| 225 | + super(_displayDensityOptions || { displayDensity: 'comfortable' }); |
| 226 | + this.locale = this.locale || this._localeId; |
| 227 | + } |
| 228 | + |
| 229 | + public abstract select(value: Date | DateRange): void; |
| 230 | + public abstract open(settings?: OverlaySettings): void; |
| 231 | + public abstract toggle(settings?: OverlaySettings): void; |
| 232 | + public abstract close(): void; |
| 233 | +} |
0 commit comments