UNPKG

ngx-bootstrap

Version:
147 lines 5.45 kB
import { Component, EventEmitter, Input, Output, ElementRef, Renderer, ViewContainerRef } from '@angular/core'; import { BsDaterangepickerContainerComponent } from './themes/bs/bs-daterangepicker-container.component'; import { ComponentLoaderFactory } from '../component-loader/component-loader.factory'; var BsDaterangepickerComponent = (function () { function BsDaterangepickerComponent(_elementRef, _renderer, _viewContainerRef, cis) { /** * Placement of a popover. Accepts: "top", "bottom", "left", "right" */ this.placement = 'bottom'; /** * Specifies events that should trigger. Supports a space separated list of * event names. */ this.triggers = 'click'; this.outsideClick = true; /** * A selector specifying the element the popover should be appended to. * Currently only supports "body". */ this.container = 'body'; this.bsValueChange = new EventEmitter(); this.subscriptions = []; this._datepicker = cis .createLoader(_elementRef, _viewContainerRef, _renderer); // .provide({provide: PopoverConfig, useValue: _config}); // Object.assign(this, _config); this.onShown = this._datepicker.onShown; this.onHidden = this._datepicker.onHidden; } Object.defineProperty(BsDaterangepickerComponent.prototype, "isOpen", { /** * Returns whether or not the popover is currently being shown */ get: function () { return this._datepicker.isShown; }, set: function (value) { if (value) { this.show(); } else { this.hide(); } }, enumerable: true, configurable: true }); Object.defineProperty(BsDaterangepickerComponent.prototype, "bsValue", { set: function (value) { this._bsValue = value; this.bsValueChange.emit(value); }, enumerable: true, configurable: true }); /** * Opens an element’s datepicker. This is considered a “manual” triggering of * the datepicker. */ BsDaterangepickerComponent.prototype.show = function () { var _this = this; if (this._datepicker.isShown) { return; } this._datepickerRef = this._datepicker .attach(BsDaterangepickerContainerComponent) .to(this.container) .position({ attachment: this.placement }) .show({ placement: this.placement }); // link with datepicker // set initial value of picker this._datepickerRef.instance.value = this._bsValue; // if date changes from external source (model -> view) this.subscriptions.push(this.bsValueChange.subscribe(function (value) { _this._datepickerRef.instance.value = value; })); // if date changes from picker (view -> model) this.subscriptions.push(this._datepickerRef.instance .valueChange .filter(function (range) { return range && range[0] && !!range[1]; }) .subscribe(function (value) { if (value === _this._bsValue) { return; } _this.bsValueChange.emit(value); _this.hide(); })); }; /** * Closes an element’s datepicker. This is considered a “manual” triggering of * the datepicker. */ BsDaterangepickerComponent.prototype.hide = function () { if (this.isOpen) { this._datepicker.hide(); } }; /** * Toggles an element’s datepicker. This is considered a “manual” triggering of * the datepicker. */ BsDaterangepickerComponent.prototype.toggle = function () { if (this.isOpen) { return this.hide(); } this.show(); }; BsDaterangepickerComponent.prototype.ngOnInit = function () { var _this = this; this._datepicker.listen({ outsideClick: this.outsideClick, triggers: this.triggers, show: function () { return _this.show(); } }); }; BsDaterangepickerComponent.prototype.ngOnDestroy = function () { this._datepicker.dispose(); }; BsDaterangepickerComponent.decorators = [ { type: Component, args: [{ selector: 'bs-daterangepicker,[bsDaterangepicker]', exportAs: 'bsDaterangepicker', template: ' ' },] }, ]; /** @nocollapse */ BsDaterangepickerComponent.ctorParameters = function () { return [ { type: ElementRef, }, { type: Renderer, }, { type: ViewContainerRef, }, { type: ComponentLoaderFactory, }, ]; }; BsDaterangepickerComponent.propDecorators = { 'placement': [{ type: Input },], 'triggers': [{ type: Input },], 'outsideClick': [{ type: Input },], 'container': [{ type: Input },], 'isOpen': [{ type: Input },], 'onShown': [{ type: Output },], 'onHidden': [{ type: Output },], 'bsValue': [{ type: Input },], 'bsValueChange': [{ type: Output },], }; return BsDaterangepickerComponent; }()); export { BsDaterangepickerComponent }; //# sourceMappingURL=bs-daterangepicker.component.js.map