UNPKG

@dhutaryan/ngx-mat-timepicker

Version:

Angular timepicker to add time which is based on material design and Angular material.

197 lines (196 loc) 9.81 kB
import { ViewContainerRef, NgZone, EventEmitter, OnChanges, SimpleChanges, ElementRef, InjectionToken } from '@angular/core'; import { ThemePalette } from '@angular/material/core'; import { BooleanInput } from '@angular/cdk/coercion'; import { Overlay } from '@angular/cdk/overlay'; import { ComponentType, TemplatePortal } from '@angular/cdk/portal'; import { Observable, Subject } from 'rxjs'; import { MatTimepickerContent } from './timepicker-content'; import { ExtractTimeTypeFromSelection, MatTimeSelectionModel } from './time-selection-model'; import { TimepickerOrientation } from './orientation'; import * as i0 from "@angular/core"; /** Possible options for the timepicker to open. */ export type TimepickerOpenAs = 'dialog' | 'popup'; /** Possible positions for the timepicker dropdown along the X axis. */ export type TimepickerDropdownPositionX = 'start' | 'end'; /** Possible positions for the timepicker dropdown along the Y axis. */ export type TimepickerDropdownPositionY = 'above' | 'below'; /** Possible options for the timepicker to display. */ export type TimepickerMode = 'input' | 'dial'; /** Possible options for the timepicker period format. */ export type TimepickerFormat = '12h' | '24h'; /** Form control that can be associated with a timepicker. */ export interface MatTimepickerControl<T> { disabled: boolean; min: T | null; max: T | null; stateChanges: Observable<void>; getThemePalette(): ThemePalette; getConnectedOverlayOrigin(): ElementRef; getOverlayLabelId(): string | null; } /** A timepicker that can be attached to a {@link MatTimepickerControl}. */ export interface MatTimepickerPanel<C extends MatTimepickerControl<T>, S, T = ExtractTimeTypeFromSelection<S>> { /** Stream that emits whenever the timepicker is opened. */ openedStream: EventEmitter<void>; /** Stream that emits whenever the timepicker is closed. */ closedStream: EventEmitter<void>; /** Emits when the timepicker's state changes. */ stateChanges: Subject<void>; /** Register an input with the timeepicker. */ registerInput(input: C): MatTimeSelectionModel<S, T>; } /** * Represents the default options for the form field that can be configured * using the `MAT_TIMEPICKER_DEFAULT_OPTIONS` injection token. */ export interface MatTimepickerDefaultOptions { /** Default color of the timepicker. */ color?: ThemePalette; /** Default timepicker mode. */ mode: TimepickerMode; /** Defines how timepicker will be appeared. */ openAs: TimepickerOpenAs; /** Default timepicker format. */ format: TimepickerFormat; /** Should toggle face button be visible. */ showToggleModeButton: boolean; /** Step for minutes. */ minuteInterval: number; /** Orientation for dial mode. */ orientation: TimepickerOrientation; } /** * Injection token that can be used to configure the * default options for all timepickers within an app. */ export declare const MAT_TIMEPICKER_DEFAULT_OPTIONS: InjectionToken<MatTimepickerDefaultOptions>; export declare abstract class MatTimepickerBase<C extends MatTimepickerControl<T>, S, T = ExtractTimeTypeFromSelection<S>> implements OnChanges { private _viewContainerRef; private _overlay; private _ngZone; private _defaultActionsComponent; private _model; private _defaults?; /** Whether the timepicker pop-up should be disabled. */ get disabled(): boolean; set disabled(value: BooleanInput); private _disabled; /** Whether the timepicker is open. */ get opened(): boolean; set opened(value: BooleanInput); private _opened; /** Whether the timepicker mode which determines what the timepicker will be opened as. */ get openAs(): TimepickerOpenAs; set openAs(value: TimepickerOpenAs); private _openAs; /** Color palette to use on the timepicker's content. */ get color(): ThemePalette; set color(value: ThemePalette); private _color; /** Timepicker display mode. */ get mode(): TimepickerMode; set mode(value: TimepickerMode); private _mode; /** Timepicker period format. */ get format(): TimepickerFormat; set format(value: TimepickerFormat); private _format; /** Show or hide toggle button between dial and input. */ get showToggleModeButton(): boolean; set showToggleModeButton(value: boolean); private _showToggleModeButton; /** Step for minutes. */ get minuteInterval(): number; set minuteInterval(value: number); private _minuteInterval; /** Orientation for dial mode. */ get orientation(): TimepickerOrientation; set orientation(value: TimepickerOrientation); private _orientation; /** * Whether the timepicker UI is in touch mode. In touch mode elements are larger for bigger touch targets. */ get touchUi(): boolean; set touchUi(value: boolean); private _touchUi; /** Preferred position of the timepicker in the X axis. */ xPosition: TimepickerDropdownPositionX; /** Preferred position of the timepicker in the Y axis. */ yPosition: TimepickerDropdownPositionY; /** * Whether to restore focus to the previously-focused element when the timepicker is closed. * Note that automatic focus restoration is an accessibility feature and it is recommended that * you provide your own equivalent, if you decide to turn it off. */ restoreFocus: boolean; /** Emits when the timepicker has been opened. */ readonly openedStream: EventEmitter<void>; /** Emits when the timepicker has been closed. */ readonly closedStream: EventEmitter<void>; /** The id for the timepicker. */ id: string; /** The input element this timepicker is associated with. */ timepickerInput: C; /** Portal with projected action buttons. */ _actionsPortal: TemplatePortal | null; /** Emits when the timepicker's state changes. */ readonly stateChanges: Subject<void>; /** A reference to the overlay into which we've rendered the timepicker. */ private _overlayRef; /** Reference to the component instance rendered in the overlay. */ private _componentRef; /** Unique class that will be added to the backdrop so that the test harnesses can look it up. */ private _backdropHarnessClass; /** The element that was focused before the timepicker was opened. */ private _focusedElementBeforeOpen; private _document; /** Scroll strategy. */ private _scrollStrategy; /** The minimum selectable time. */ _getMinTime(): T | null; /** The maximum selectable time. */ _getMaxTime(): T | null; constructor(_viewContainerRef: ViewContainerRef, _overlay: Overlay, _ngZone: NgZone, scrollStrategy: any, _defaultActionsComponent: ComponentType<any>, _model: MatTimeSelectionModel<S, T>, _defaults?: MatTimepickerDefaultOptions | undefined); ngOnChanges(changes: SimpleChanges): void; ngOnDestroy(): void; /** Opens the timepicker. */ open(): void; /** Closes the timepicker. */ close(): void; /** * Register an input with this timepicker. * @param input The timepicker input to register with this timepicker. * @returns Selection model that the input should hook itself up to. */ registerInput(input: C): MatTimeSelectionModel<S, T>; /** * Registers a portal containing action buttons with the timepicker. * @param portal Portal to be registered. */ registerActions(portal: TemplatePortal): void; /** * Removes a portal containing action buttons from the timepicker. * @param portal Portal to be removed. */ removeActions(portal: TemplatePortal): void; /** Applies the current pending selection on the overlay to the model. */ _applyPendingSelection(): void; /** Forwards relevant values from the timepicker to the timepicker content inside the overlay. */ protected _forwardContentValues(instance: MatTimepickerContent<S, T>): void; /** Opens the overlay with the timepicker. */ private _openOverlay; /** Destroys the current overlay. */ private _destroyOverlay; /** Gets a position strategy that will open the timepicker as a dropdown. */ private _getDialogStrategy; /** Gets a position strategy that will open the timepicker as a dropdown. */ private _getDropdownStrategy; /** Sets the positions of the timepicker in dropdown mode based on the current configuration. */ private _setConnectedPositions; /** Gets an observable that will emit when the overlay is supposed to be closed. */ private _getCloseStream; static ɵfac: i0.ɵɵFactoryDeclaration<MatTimepickerBase<any, any, any>, [null, null, null, null, null, null, { optional: true; }]>; static ɵdir: i0.ɵɵDirectiveDeclaration<MatTimepickerBase<any, any, any>, never, never, { "disabled": { "alias": "disabled"; "required": false; }; "opened": { "alias": "opened"; "required": false; }; "openAs": { "alias": "openAs"; "required": false; }; "color": { "alias": "color"; "required": false; }; "mode": { "alias": "mode"; "required": false; }; "format": { "alias": "format"; "required": false; }; "showToggleModeButton": { "alias": "showToggleModeButton"; "required": false; }; "minuteInterval": { "alias": "minuteInterval"; "required": false; }; "orientation": { "alias": "orientation"; "required": false; }; "touchUi": { "alias": "touchUi"; "required": false; }; "xPosition": { "alias": "xPosition"; "required": false; }; "yPosition": { "alias": "yPosition"; "required": false; }; "restoreFocus": { "alias": "restoreFocus"; "required": false; }; }, { "openedStream": "opened"; "closedStream": "closed"; }, never, never, true, never>; static ngAcceptInputType_touchUi: unknown; static ngAcceptInputType_restoreFocus: unknown; }