ngnz-time-input
Version:
Material design time input for Angular 8
907 lines (871 loc) • 48.5 kB
JavaScript
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@angular/core'), require('rxjs/operators'), require('@angular/cdk/a11y'), require('@angular/cdk/coercion'), require('@angular/forms'), require('@angular/material'), require('moment'), require('rxjs/internal/Subject'), require('@angular/common'), require('@angular/material/button'), require('@angular/material/form-field'), require('@angular/material/input')) :
typeof define === 'function' && define.amd ? define('ngnz-time-input', ['exports', '@angular/core', 'rxjs/operators', '@angular/cdk/a11y', '@angular/cdk/coercion', '@angular/forms', '@angular/material', 'moment', 'rxjs/internal/Subject', '@angular/common', '@angular/material/button', '@angular/material/form-field', '@angular/material/input'], factory) :
(global = global || self, factory(global['ngnz-time-input'] = {}, global.ng.core, global.rxjs.operators, global.ng.cdk.a11y, global.ng.cdk.coercion, global.ng.forms, global.ng.material, global.moment, global.rxjs['internal/Subject'], global.ng.common, global.ng.material.button, global.ng.material.formField, global.ng.material.input));
}(this, (function (exports, core, operators, a11y, coercion, forms, material, moment, Subject, common, button, formField, input) { 'use strict';
/*! *****************************************************************************
Copyright (c) Microsoft Corporation.
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
***************************************************************************** */
/* global Reflect, Promise */
var extendStatics = function(d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return extendStatics(d, b);
};
function __extends(d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
}
var __assign = function() {
__assign = Object.assign || function __assign(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
function __rest(s, e) {
var t = {};
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
t[p] = s[p];
if (s != null && typeof Object.getOwnPropertySymbols === "function")
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
t[p[i]] = s[p[i]];
}
return t;
}
function __decorate(decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
}
function __param(paramIndex, decorator) {
return function (target, key) { decorator(target, key, paramIndex); }
}
function __metadata(metadataKey, metadataValue) {
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(metadataKey, metadataValue);
}
function __awaiter(thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
}
function __generator(thisArg, body) {
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
function verb(n) { return function (v) { return step([n, v]); }; }
function step(op) {
if (f) throw new TypeError("Generator is already executing.");
while (_) try {
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
if (y = 0, t) op = [op[0] & 2, t.value];
switch (op[0]) {
case 0: case 1: t = op; break;
case 4: _.label++; return { value: op[1], done: false };
case 5: _.label++; y = op[1]; op = [0]; continue;
case 7: op = _.ops.pop(); _.trys.pop(); continue;
default:
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
if (t[2]) _.ops.pop();
_.trys.pop(); continue;
}
op = body.call(thisArg, _);
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
}
}
function __createBinding(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}
function __exportStar(m, exports) {
for (var p in m) if (p !== "default" && !exports.hasOwnProperty(p)) exports[p] = m[p];
}
function __values(o) {
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
if (m) return m.call(o);
if (o && typeof o.length === "number") return {
next: function () {
if (o && i >= o.length) o = void 0;
return { value: o && o[i++], done: !o };
}
};
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
}
function __read(o, n) {
var m = typeof Symbol === "function" && o[Symbol.iterator];
if (!m) return o;
var i = m.call(o), r, ar = [], e;
try {
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
}
catch (error) { e = { error: error }; }
finally {
try {
if (r && !r.done && (m = i["return"])) m.call(i);
}
finally { if (e) throw e.error; }
}
return ar;
}
function __spread() {
for (var ar = [], i = 0; i < arguments.length; i++)
ar = ar.concat(__read(arguments[i]));
return ar;
}
function __spreadArrays() {
for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;
for (var r = Array(s), k = 0, i = 0; i < il; i++)
for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
r[k] = a[j];
return r;
};
function __await(v) {
return this instanceof __await ? (this.v = v, this) : new __await(v);
}
function __asyncGenerator(thisArg, _arguments, generator) {
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
var g = generator.apply(thisArg, _arguments || []), i, q = [];
return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i;
function verb(n) { if (g[n]) i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; }
function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }
function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }
function fulfill(value) { resume("next", value); }
function reject(value) { resume("throw", value); }
function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); }
}
function __asyncDelegator(o) {
var i, p;
return i = {}, verb("next"), verb("throw", function (e) { throw e; }), verb("return"), i[Symbol.iterator] = function () { return this; }, i;
function verb(n, f) { i[n] = o[n] ? function (v) { return (p = !p) ? { value: __await(o[n](v)), done: n === "return" } : f ? f(v) : v; } : f; }
}
function __asyncValues(o) {
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
var m = o[Symbol.asyncIterator], i;
return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
}
function __makeTemplateObject(cooked, raw) {
if (Object.defineProperty) { Object.defineProperty(cooked, "raw", { value: raw }); } else { cooked.raw = raw; }
return cooked;
};
function __importStar(mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
result.default = mod;
return result;
}
function __importDefault(mod) {
return (mod && mod.__esModule) ? mod : { default: mod };
}
function __classPrivateFieldGet(receiver, privateMap) {
if (!privateMap.has(receiver)) {
throw new TypeError("attempted to get private field on non-instance");
}
return privateMap.get(receiver);
}
function __classPrivateFieldSet(receiver, privateMap, value) {
if (!privateMap.has(receiver)) {
throw new TypeError("attempted to set private field on non-instance");
}
privateMap.set(receiver, value);
return value;
}
(function (TimeInputMode) {
TimeInputMode[TimeInputMode["Circular"] = 0] = "Circular";
TimeInputMode[TimeInputMode["CircularForwarding"] = 1] = "CircularForwarding";
TimeInputMode[TimeInputMode["Limit"] = 2] = "Limit";
})(exports.TimeInputMode || (exports.TimeInputMode = {}));
var TimeValue = /** @class */ (function () {
function TimeValue(inputMode) {
var _this = this;
if (inputMode === void 0) { inputMode = exports.TimeInputMode.CircularForwarding; }
this.inputMode = inputMode;
this.TIME_LIMITS = {
zero: 0,
hours: 23,
minutes: 59,
seconds: 59,
};
this.exeedHours = new core.EventEmitter();
this.exeedMinutes = new core.EventEmitter();
this.exeedSeconds = new core.EventEmitter();
this.hoursChanged = new core.EventEmitter();
this.minutesChanged = new core.EventEmitter();
this.secondsChanged = new core.EventEmitter();
this.exeedSeconds
.pipe(operators.filter(function (val) { return val !== 0; }))
.subscribe(function (data) { return _this.setMinutes(_this.minutes + data); });
this.exeedMinutes
.pipe(operators.filter(function (val) { return val !== 0; }))
.subscribe(function (data) { return _this.setHours(_this.hours + data); });
}
Object.defineProperty(TimeValue.prototype, "hours", {
get: function () {
return this._hours;
},
enumerable: true,
configurable: true
});
TimeValue.prototype.setHours = function (value, emitChange) {
if (emitChange === void 0) { emitChange = true; }
if (this._hours !== value) {
var partVal = this._setPart(value, this.TIME_LIMITS.hours);
this._hours = partVal.value;
if (this.inputMode === exports.TimeInputMode.CircularForwarding) {
this.exeedHours.emit(partVal.exeedValue);
}
if (emitChange) {
this.hoursChanged.emit(this._hours);
}
}
return this;
};
Object.defineProperty(TimeValue.prototype, "minutes", {
get: function () {
return this._minutes;
},
enumerable: true,
configurable: true
});
TimeValue.prototype.setMinutes = function (value, emitChange) {
if (emitChange === void 0) { emitChange = true; }
if (this._minutes !== value) {
var partVal = this._setPart(value, this.TIME_LIMITS.minutes);
this._minutes = partVal.value;
if (this.inputMode === exports.TimeInputMode.CircularForwarding) {
this.exeedMinutes.emit(partVal.exeedValue);
}
if (emitChange) {
this.minutesChanged.emit(this._minutes);
}
}
return this;
};
Object.defineProperty(TimeValue.prototype, "seconds", {
get: function () {
return this._seconds;
},
enumerable: true,
configurable: true
});
TimeValue.prototype.setSeconds = function (value, emitChange) {
if (emitChange === void 0) { emitChange = true; }
if (this._seconds !== value) {
var partVal = this._setPart(value, this.TIME_LIMITS.seconds);
this._seconds = partVal.value;
if (this.inputMode === exports.TimeInputMode.CircularForwarding) {
this.exeedSeconds.emit(partVal.exeedValue);
}
if (emitChange) {
this.secondsChanged.emit(this._seconds);
}
}
return this;
};
Object.defineProperty(TimeValue.prototype, "value", {
get: function () {
return {
hours: this.hours,
minutes: this.minutes,
seconds: this.seconds,
};
},
enumerable: true,
configurable: true
});
TimeValue.prototype.setValue = function (hours, minutes, seconds) {
this.setHours(hours).setMinutes(minutes).setSeconds(seconds);
};
TimeValue.prototype._setPart = function (value, maxLimit) {
var partVal = 0;
var exeedVal = 0;
var minLimit = this.TIME_LIMITS.zero;
var divider = maxLimit + 1;
switch (this.inputMode) {
case exports.TimeInputMode.Limit:
if (value > maxLimit) {
partVal = maxLimit;
}
else if (value < minLimit) {
partVal = minLimit;
}
else {
partVal = value;
}
exeedVal = 0;
break;
case exports.TimeInputMode.Circular:
if (value > maxLimit) {
partVal = minLimit;
}
else if (value < minLimit) {
partVal = maxLimit;
}
else {
partVal = value;
}
exeedVal = 0;
break;
case exports.TimeInputMode.CircularForwarding:
if (value > maxLimit) {
partVal = value % divider;
exeedVal = Math.round(value / divider);
}
else if (value < minLimit) {
partVal = divider + (value % divider);
exeedVal = Math.round(value / divider) - 1;
}
else {
partVal = value;
exeedVal = 0;
}
break;
}
return {
value: partVal,
exeedValue: exeedVal,
};
};
return TimeValue;
}());
var CssClassCreator = /** @class */ (function () {
function CssClassCreator(initVal) {
this._classes = {};
if (!!initVal) {
this.appendCssClasses(initVal);
}
}
CssClassCreator.prototype.appendCssClasses = function (classes, trigger) {
if (trigger === void 0) { trigger = true; }
if (!!classes) {
if (typeof classes === 'string') {
this._createFromString(classes, trigger);
}
else if (Array.isArray(classes)) {
this._createFromArray(classes, trigger);
}
else if (typeof classes === 'object') {
Object.assign(this._classes, classes);
}
}
return this;
};
CssClassCreator.prototype.generate = function () {
var out = {};
for (var item in this._classes) {
if (this._classes.hasOwnProperty(item)) {
out[item] =
typeof this._classes[item] === 'function'
? this._classes[item].call(this)
: !!this._classes[item];
}
}
return out;
};
CssClassCreator.prototype._createFromArray = function (classes, trigger) {
var e_1, _a;
try {
for (var classes_1 = __values(classes), classes_1_1 = classes_1.next(); !classes_1_1.done; classes_1_1 = classes_1.next()) {
var cls = classes_1_1.value;
this._classes['' + cls] = true;
}
}
catch (e_1_1) { e_1 = { error: e_1_1 }; }
finally {
try {
if (classes_1_1 && !classes_1_1.done && (_a = classes_1.return)) _a.call(classes_1);
}
finally { if (e_1) throw e_1.error; }
}
};
CssClassCreator.prototype._createFromString = function (classes, trigger) {
var splitted = classes.split(/[\s,;]+/).filter(function (item) { return !!item; });
this._createFromArray(splitted, trigger);
};
return CssClassCreator;
}());
/**
* Time Input Component.
* The component as a part of UI allows to change time part of Moment data type.
* It looks and uses like a input field.
* It is possible to use mouse wheel and/or control buttons to change time.
* Can be used with [value] attribute or FormControl inside angular reactive form
* @author Aleksey Nazarenko
* @version 0.0.1
*/
var NgnzTimeInputInlineComponent = /** @class */ (function () {
function NgnzTimeInputInlineComponent(_fm, _elRef, _chDetector, ngControl) {
var _this = this;
this._fm = _fm;
this._elRef = _elRef;
this._chDetector = _chDetector;
this.ngControl = ngControl;
this.BUTTON_HOST_ATTRIBUTES = [
'mat-button',
'mat-flat-button',
'mat-icon-button',
'mat-raised-button',
'mat-stroked-button',
'mat-mini-fab',
'mat-fab',
];
this.stateChanges = new Subject.Subject();
this._hoursControl = new forms.FormControl(null);
this._minutesControl = new forms.FormControl(null);
this._secondsControl = new forms.FormControl(null);
this.parts = new forms.FormGroup({
hours: this._hoursControl,
minutes: this._minutesControl,
seconds: this._secondsControl,
});
this._required = false;
this._disabled = false;
this._unsubscribe = new Subject.Subject();
this._debounceTime = 300;
this._focused = false;
this.controlType = 'ngnz-time-input-inline';
this.id = [
this.controlType,
++NgnzTimeInputInlineComponent_1.nextId,
].join('-');
this.describedBy = '';
this.inputClassesConf = {};
this.buttonDecreaseClassesConf = {};
this.buttonIncreaseClassesConf = {};
// enum defining of time change mode: Limit, Circular, CircularForwarding
this.inputMode = exports.TimeInputMode.CircularForwarding;
// do not show control buttons; normally buttons are shown on focus
this.noButtons = false;
// always show control buttons; normally buttons are shown on focus
this.showButtons = false;
// do not show seconds block if it is not necessary
this.noSeconds = false;
// mat icon name for descrease controll button
this.decreaseBtnIconName = 'remove';
// mat icon name for increase control button
this.increaseBtnIconName = 'add';
this.timeChange = new core.EventEmitter();
this._timeChange = new core.EventEmitter();
this._onChange = function (_) { };
this._onTouched = function (_) { };
this._timeValue = new TimeValue();
if (this.ngControl !== null) {
this.ngControl.valueAccessor = this;
}
this._fm
.monitor(this._elRef.nativeElement, true)
.subscribe(function (origin) {
if (origin == null) {
_this._onTouched(_this);
}
_this.focused = !!origin;
_this.detectChangies();
});
this._hoursControl.valueChanges
.pipe(operators.filter(function (data) { return +data !== _this._timeValue.hours; }), operators.takeUntil(this._unsubscribe.asObservable()))
.subscribe(function (data) {
_this._timeValue.setHours(+data);
});
this._timeValue.hoursChanged
.pipe(operators.takeUntil(this._unsubscribe.asObservable()))
.subscribe(function (data) {
_this._hoursControl.setValue(_this.padNumber(data));
_this._timeChange.emit(_this.value);
});
this._minutesControl.valueChanges
.pipe(operators.filter(function (data) { return +data !== _this._timeValue.minutes; }), operators.takeUntil(this._unsubscribe.asObservable()))
.subscribe(function (data) {
_this._timeValue.setMinutes(+data);
});
this._timeValue.minutesChanged
.pipe(operators.takeUntil(this._unsubscribe.asObservable()))
.subscribe(function (data) {
_this._minutesControl.setValue(_this.padNumber(data));
_this._timeChange.emit(_this.value);
});
this._secondsControl.valueChanges
.pipe(operators.filter(function (data) { return +data !== _this._timeValue.seconds; }), operators.takeUntil(this._unsubscribe.asObservable()))
.subscribe(function (data) {
_this._timeValue.setSeconds(+data);
});
this._timeValue.secondsChanged
.pipe(operators.takeUntil(this._unsubscribe.asObservable()))
.subscribe(function (data) {
_this._secondsControl.setValue(_this.padNumber(data));
_this._timeChange.emit(_this.value);
});
this._timeChange
.pipe(operators.debounceTime(this._debounceTime), operators.takeUntil(this._unsubscribe.asObservable()))
.subscribe(function (data) {
_this.timeChange.emit(data);
});
}
NgnzTimeInputInlineComponent_1 = NgnzTimeInputInlineComponent;
Object.defineProperty(NgnzTimeInputInlineComponent.prototype, "focused", {
get: function () {
return this._focused;
},
set: function (val) {
this._focused = val;
},
enumerable: true,
configurable: true
});
Object.defineProperty(NgnzTimeInputInlineComponent.prototype, "shouldLabelFloat", {
get: function () {
return this.focused || !this.empty;
},
enumerable: true,
configurable: true
});
Object.defineProperty(NgnzTimeInputInlineComponent.prototype, "placeholder", {
// placeholder // FIXME: is to show when value is not set
get: function () {
return this._placeholder;
},
set: function (placeholder) {
this._placeholder = placeholder;
},
enumerable: true,
configurable: true
});
Object.defineProperty(NgnzTimeInputInlineComponent.prototype, "value", {
get: function () {
var out = moment({
years: this._inputValue.year(),
months: this._inputValue.month(),
days: this._inputValue.date(),
hours: this._timeValue.hours,
minutes: this._timeValue.minutes,
seconds: this._timeValue.seconds,
});
return out;
},
set: function (value) {
this._inputValue = (!!value && moment.isMoment(value) && value) || moment();
var hours = +this._inputValue.hours();
var minutes = +this._inputValue.minutes();
var seconds = +this._inputValue.seconds();
this._timeValue.setHours(hours).setMinutes(minutes).setSeconds(seconds);
this.detectChangies();
},
enumerable: true,
configurable: true
});
Object.defineProperty(NgnzTimeInputInlineComponent.prototype, "required", {
get: function () {
return this._required;
},
set: function (req) {
this._required = coercion.coerceBooleanProperty(req);
this.detectChangies();
},
enumerable: true,
configurable: true
});
Object.defineProperty(NgnzTimeInputInlineComponent.prototype, "disabled", {
get: function () {
return this._disabled;
},
set: function (value) {
this._disabled = coercion.coerceBooleanProperty(value);
this._disabled ? this.parts.disable() : this.parts.enable();
this.detectChangies();
},
enumerable: true,
configurable: true
});
Object.defineProperty(NgnzTimeInputInlineComponent.prototype, "splitter", {
// one character to separate hours from minutes and minutes from seconds; default is ':'
get: function () {
return this._splitter || ':';
},
set: function (value) {
this._splitter = ('' + value).slice(0);
},
enumerable: true,
configurable: true
});
NgnzTimeInputInlineComponent.prototype.ngOnInit = function () {
this._timeValue.inputMode = this.inputMode;
this._cssClassChange();
};
NgnzTimeInputInlineComponent.prototype.ngDoCheck = function () {
this._cssClassChange();
};
NgnzTimeInputInlineComponent.prototype.ngOnDestroy = function () {
this._unsubscribe.next();
this._unsubscribe.complete();
this._fm.stopMonitoring(this._elRef.nativeElement);
};
NgnzTimeInputInlineComponent.prototype.detectChangies = function () {
this.stateChanges.next();
this._cssClassChange();
this._chDetector.detectChanges();
};
Object.defineProperty(NgnzTimeInputInlineComponent.prototype, "errorState", {
get: function () {
return !!(!!this.ngControl &&
this.ngControl.touched &&
this.ngControl.invalid);
},
enumerable: true,
configurable: true
});
Object.defineProperty(NgnzTimeInputInlineComponent.prototype, "empty", {
get: function () {
var value = this.parts.value;
return (!(value.hours && value.hours >= 0) &&
!(value.minutes && value.minutes >= 0) &&
!(value.seconds && value.minutes >= 0));
},
enumerable: true,
configurable: true
});
NgnzTimeInputInlineComponent.prototype.setDescribedByIds = function (ids) {
this.describedBy = ids.join(' ');
};
NgnzTimeInputInlineComponent.prototype.onContainerClick = function (event) {
};
NgnzTimeInputInlineComponent.prototype.writeValue = function (value) {
this.value = value;
};
NgnzTimeInputInlineComponent.prototype.registerOnChange = function (fn) {
this._onChange = function (_) {
fn(_);
};
};
NgnzTimeInputInlineComponent.prototype.registerOnTouched = function (fn) {
this._onTouched = function (_) {
fn(_);
};
};
NgnzTimeInputInlineComponent.prototype.setDisabledState = function (isDisabled) {
this.disabled = isDisabled;
};
NgnzTimeInputInlineComponent.prototype.btnsAction = function (partName, step) {
switch (partName) {
case 'hours':
this._timeValue.setHours(this._timeValue.hours + step);
break;
case 'minutes':
this._timeValue.setMinutes(this._timeValue.minutes + step);
break;
case 'seconds':
this._timeValue.setSeconds(this._timeValue.seconds + step);
break;
}
this.detectChangies();
};
NgnzTimeInputInlineComponent.prototype.btnIncrease = function ($event, partName) {
$event.preventDefault();
$event.stopPropagation();
this.btnsAction(partName, 1);
};
NgnzTimeInputInlineComponent.prototype.btnDecrease = function ($event, partName) {
$event.preventDefault();
$event.stopPropagation();
this.btnsAction(partName, -1);
};
NgnzTimeInputInlineComponent.prototype.padNumber = function (value, places) {
if (places === void 0) { places = 2; }
return String(value).padStart(places, '0');
};
NgnzTimeInputInlineComponent.prototype.wheel = function ($event, partName) {
if (this.focused) {
$event.preventDefault();
$event.stopPropagation();
var step = $event.deltaY > 0 ? -1 : $event.deltaY < 0 ? 1 : 0;
this.btnsAction(partName, step);
}
};
// rearrange additional and conditional classes
NgnzTimeInputInlineComponent.prototype._cssClassChange = function () {
this._defineCssButtons();
this._defineCssInputs();
};
// detect type of control buttons in material design
NgnzTimeInputInlineComponent.prototype._defineMatButtonType = function () {
var _this = this;
var out = this.buttonMatTypeClassName = (!!this.buttonMatType && ('' + this.buttonMatType))
|| this.BUTTON_HOST_ATTRIBUTES.filter(function (attribute) {
return _this._elRef.nativeElement.hasAttribute(attribute);
}).join(' ');
return out;
};
// detect color of control buttons in material design
NgnzTimeInputInlineComponent.prototype._defineMatButtonColor = function () {
return this.colorClassName = !!this.color ? 'mat-' + this.color : '';
};
// combine additional and conditional classes for control buttons
NgnzTimeInputInlineComponent.prototype._defineCssButtons = function () {
var cssClasses = new CssClassCreator()
.appendCssClasses(this.colorClassName || this._defineMatButtonColor())
.appendCssClasses(this.buttonMatTypeClassName || this._defineMatButtonType())
.appendCssClasses(this.buttonsClasses)
.generate();
var cssCreatorLeft = new CssClassCreator()
.appendCssClasses(this.buttonDecreaseClasses)
.appendCssClasses(cssClasses);
var cssCreatorRight = new CssClassCreator()
.appendCssClasses(this.buttonIncreaseClasses)
.appendCssClasses(cssClasses);
Object.assign(this.buttonDecreaseClassesConf, cssCreatorLeft.generate());
Object.assign(this.buttonIncreaseClassesConf, cssCreatorRight.generate());
};
// combine additional and conditional classes for inputs
NgnzTimeInputInlineComponent.prototype._defineCssInputs = function () {
var _this = this;
var cssCreator = new CssClassCreator()
.appendCssClasses({
'ngnz-lr-margin-1em': function () { return (!_this.showButtons && !_this.noButtons && !_this.focused); },
})
.appendCssClasses(this.inputClasses);
Object.assign(this.inputClassesConf, cssCreator.generate());
};
var NgnzTimeInputInlineComponent_1;
NgnzTimeInputInlineComponent.nextId = 0;
NgnzTimeInputInlineComponent.ctorParameters = function () { return [
{ type: a11y.FocusMonitor },
{ type: core.ElementRef },
{ type: core.ChangeDetectorRef },
{ type: forms.NgControl, decorators: [{ type: core.Optional }, { type: core.Self }] }
]; };
__decorate([
core.HostBinding()
], NgnzTimeInputInlineComponent.prototype, "id", void 0);
__decorate([
core.HostBinding('attr.aria-describedby')
], NgnzTimeInputInlineComponent.prototype, "describedBy", void 0);
__decorate([
core.HostBinding('class.floating')
], NgnzTimeInputInlineComponent.prototype, "shouldLabelFloat", null);
__decorate([
core.Input()
], NgnzTimeInputInlineComponent.prototype, "color", void 0);
__decorate([
core.Input()
], NgnzTimeInputInlineComponent.prototype, "buttonMatType", void 0);
__decorate([
core.Input()
], NgnzTimeInputInlineComponent.prototype, "inputClasses", void 0);
__decorate([
core.Input()
], NgnzTimeInputInlineComponent.prototype, "buttonsClasses", void 0);
__decorate([
core.Input()
], NgnzTimeInputInlineComponent.prototype, "buttonDecreaseClasses", void 0);
__decorate([
core.Input()
], NgnzTimeInputInlineComponent.prototype, "buttonIncreaseClasses", void 0);
__decorate([
core.Input()
], NgnzTimeInputInlineComponent.prototype, "placeholder", null);
__decorate([
core.Input()
], NgnzTimeInputInlineComponent.prototype, "inputMode", void 0);
__decorate([
core.Input()
], NgnzTimeInputInlineComponent.prototype, "value", null);
__decorate([
core.Input()
], NgnzTimeInputInlineComponent.prototype, "required", null);
__decorate([
core.Input()
], NgnzTimeInputInlineComponent.prototype, "disabled", null);
__decorate([
core.Input()
], NgnzTimeInputInlineComponent.prototype, "splitter", null);
__decorate([
core.Input()
], NgnzTimeInputInlineComponent.prototype, "noButtons", void 0);
__decorate([
core.Input()
], NgnzTimeInputInlineComponent.prototype, "showButtons", void 0);
__decorate([
core.Input()
], NgnzTimeInputInlineComponent.prototype, "noSeconds", void 0);
__decorate([
core.Input()
], NgnzTimeInputInlineComponent.prototype, "decreaseBtnIconName", void 0);
__decorate([
core.Input()
], NgnzTimeInputInlineComponent.prototype, "increaseBtnIconName", void 0);
__decorate([
core.Output()
], NgnzTimeInputInlineComponent.prototype, "timeChange", void 0);
__decorate([
core.HostListener('timeChange', ['$event']),
core.HostListener('change', ['$event'])
], NgnzTimeInputInlineComponent.prototype, "_onChange", void 0);
NgnzTimeInputInlineComponent = NgnzTimeInputInlineComponent_1 = __decorate([
core.Component({
selector: 'ngnz-time-input-inline',
template: "<div class=\"ngnz-time-group\" [formGroup]=\"parts\">\n \n <div class=\"ngnz-hours-block\">\n <button\n *ngIf=\"showButtons || (!noButtons && focused)\"\n class=\"ngnz-button\"\n [ngClass]=\"buttonDecreaseClassesConf\"\n (click)=\"btnDecrease($event, 'hours')\"\n >\n <mat-icon class=\"ngnz-square-1em\">{{\n decreaseBtnIconName\n }}</mat-icon>\n </button>\n <input\n #hours\n class=\"ngnz-hours ngnz-width-2em\"\n formControlName=\"hours\"\n readonly\n [matTooltip]=\"focused ? '\u0438\u0441\u043F\u043E\u043B\u044C\u0437\u0443\u0439\u0442\u0435 \u043A\u043E\u043B\u0435\u0441\u043E \u043F\u0440\u043E\u043A\u0440\u0443\u0442\u043A\u0438' : ''\"\n [ngClass]=\"inputClassesConf\"\n (wheel)=\"wheel($event, 'hours')\"\n />\n <button\n *ngIf=\"showButtons || (!noButtons && focused)\"\n class=\"ngnz-button\"\n [ngClass]=\"buttonIncreaseClassesConf\"\n (click)=\"btnIncrease($event, 'hours')\"\n >\n <mat-icon class=\"ngnz-square-1em\">{{\n increaseBtnIconName\n }}</mat-icon>\n </button>\n </div>\n\n <div class=\"ngnz-splitter\">{{ splitter }}</div>\n\n <div class=\"ngnz-minutes-block\">\n <button\n *ngIf=\"showButtons || (!noButtons && focused)\"\n class=\"ngnz-button\"\n [ngClass]=\"buttonDecreaseClassesConf\"\n (click)=\"btnDecrease($event, 'minutes')\"\n >\n <mat-icon class=\"ngnz-square-1em\">{{\n decreaseBtnIconName\n }}</mat-icon>\n </button>\n <input\n #minutes\n class=\"ngnz-minutes ngnz-width-2em\"\n formControlName=\"minutes\"\n readonly\n [matTooltip]=\"focused ? '\u0438\u0441\u043F\u043E\u043B\u044C\u0437\u0443\u0439\u0442\u0435 \u043A\u043E\u043B\u0435\u0441\u043E \u043F\u0440\u043E\u043A\u0440\u0443\u0442\u043A\u0438' : ''\"\n [ngClass]=\"inputClassesConf\"\n (wheel)=\"wheel($event, 'minutes')\"\n />\n <button\n *ngIf=\"showButtons || (!noButtons && focused)\"\n class=\"ngnz-button\"\n [ngClass]=\"buttonIncreaseClassesConf\"\n (click)=\"btnIncrease($event, 'minutes')\"\n >\n <mat-icon class=\"ngnz-square-1em\">{{\n increaseBtnIconName\n }}</mat-icon>\n </button>\n </div>\n\n <div class=\"ngnz-splitter\" *ngIf=\"!noSeconds\">{{ splitter }}</div>\n\n <div class=\"ngnz-seconds-block\" *ngIf=\"!noSeconds\">\n <button\n *ngIf=\"showButtons || (!noButtons && focused)\"\n class=\"ngnz-button\"\n [ngClass]=\"buttonDecreaseClassesConf\"\n (click)=\"btnDecrease($event, 'seconds')\"\n >\n <mat-icon class=\"ngnz-square-1em\">{{\n decreaseBtnIconName\n }}</mat-icon>\n </button>\n <input\n #seconds\n class=\"ngnz-seconds ngnz-width-2em\"\n formControlName=\"seconds\"\n readonly\n [matTooltip]=\"focused ? '\u0438\u0441\u043F\u043E\u043B\u044C\u0437\u0443\u0439\u0442\u0435 \u043A\u043E\u043B\u0435\u0441\u043E \u043F\u0440\u043E\u043A\u0440\u0443\u0442\u043A\u0438' : ''\"\n [ngClass]=\"inputClassesConf\"\n (wheel)=\"wheel($event, 'seconds')\"\n />\n <button\n *ngIf=\"showButtons || (!noButtons && focused)\"\n class=\"ngnz-button\"\n [ngClass]=\"buttonIncreaseClassesConf\"\n (click)=\"btnIncrease($event, 'seconds')\"\n >\n <mat-icon class=\"ngnz-square-1em\">{{\n increaseBtnIconName\n }}</mat-icon>\n </button>\n </div>\n \n</div>\n",
changeDetection: core.ChangeDetectionStrategy.OnPush,
providers: [
{
provide: material.MatFormFieldControl,
useExisting: NgnzTimeInputInlineComponent_1,
},
],
styles: [".ngnz-time-group{display:flex!important;justify-content:center!important;align-items:center!important;padding:0!important}.ngnz-time-group .ngnz-hours-block,.ngnz-time-group .ngnz-minutes-block,.ngnz-time-group .ngnz-seconds-block,.ngnz-time-group .ngnz-splitter{display:flex!important;align-items:center!important;justify-content:center!important;flex-direction:row!important}.ngnz-time-group .ngnz-hours-block .ngnz-hours,.ngnz-time-group .ngnz-hours-block .ngnz-minutes,.ngnz-time-group .ngnz-hours-block .ngnz-seconds,.ngnz-time-group .ngnz-minutes-block .ngnz-hours,.ngnz-time-group .ngnz-minutes-block .ngnz-minutes,.ngnz-time-group .ngnz-minutes-block .ngnz-seconds,.ngnz-time-group .ngnz-seconds-block .ngnz-hours,.ngnz-time-group .ngnz-seconds-block .ngnz-minutes,.ngnz-time-group .ngnz-seconds-block .ngnz-seconds,.ngnz-time-group .ngnz-splitter .ngnz-hours,.ngnz-time-group .ngnz-splitter .ngnz-minutes,.ngnz-time-group .ngnz-splitter .ngnz-seconds{color:inherit;border:none;outline:0;font:inherit;text-align:center!important;vertical-align:middle!important;padding:0!important}.ngnz-time-group .ngnz-hours-block .ngnz-button,.ngnz-time-group .ngnz-minutes-block .ngnz-button,.ngnz-time-group .ngnz-seconds-block .ngnz-button,.ngnz-time-group .ngnz-splitter .ngnz-button{cursor:pointer;padding:0!important;font-weight:700;display:flex!important;justify-content:center!important;align-items:center!important;line-height:inherit!important;font-size:inherit!important;box-sizing:border-box;position:relative;top:0}.ngnz-time-group .ngnz-hours-block .ngnz-button ::ng-deep .mat-button-wrapper,.ngnz-time-group .ngnz-minutes-block .ngnz-button ::ng-deep .mat-button-wrapper,.ngnz-time-group .ngnz-seconds-block .ngnz-button ::ng-deep .mat-button-wrapper,.ngnz-time-group .ngnz-splitter .ngnz-button ::ng-deep .mat-button-wrapper{line-height:inherit!important;padding:0!important}.ngnz-time-group .ngnz-hours-block .ngnz-button ::ng-deep .mat-button-base,.ngnz-time-group .ngnz-minutes-block .ngnz-button ::ng-deep .mat-button-base,.ngnz-time-group .ngnz-seconds-block .ngnz-button ::ng-deep .mat-button-base,.ngnz-time-group .ngnz-splitter .ngnz-button ::ng-deep .mat-button-base{min-width:inherit!important}.ngnz-time-group .ngnz-splitter{opacity:0;min-width:1em!important;transition:opacity .2s!important}:host.floating .ngnz-splitter{opacity:1}.ngnz-lr-margin-1em{margin-left:1em;margin-right:1em}.ngnz-square-1em,.ngnz-time-group .ngnz-hours-block .ngnz-button,.ngnz-time-group .ngnz-minutes-block .ngnz-button,.ngnz-time-group .ngnz-seconds-block .ngnz-button,.ngnz-time-group .ngnz-splitter .ngnz-button,.ngnz-width-1em{width:1em!important;min-width:1em!important}.ngnz-height-1em,.ngnz-square-1em,.ngnz-time-group .ngnz-hours-block .ngnz-button,.ngnz-time-group .ngnz-minutes-block .ngnz-button,.ngnz-time-group .ngnz-seconds-block .ngnz-button,.ngnz-time-group .ngnz-splitter .ngnz-button{height:1em!important;min-height:1em!important}.ngnz-width-2em{width:2em!important;min-width:2em!important}.ngnz-height-2em{height:2em!important;min-height:2em!important}.material-icons{font-size:inherit!important}"]
}),
__param(3, core.Optional()), __param(3, core.Self())
], NgnzTimeInputInlineComponent);
return NgnzTimeInputInlineComponent;
}());
var NgnzTimeInputInlineModule = /** @class */ (function () {
function NgnzTimeInputInlineModule() {
}
NgnzTimeInputInlineModule = __decorate([
core.NgModule({
declarations: [NgnzTimeInputInlineComponent],
imports: [
common.CommonModule,
forms.ReactiveFormsModule,
button.MatButtonModule,
formField.MatFormFieldModule,
input.MatInputModule,
material.MatCommonModule,
material.MatIconModule,
material.MatTooltipModule
],
exports: [
NgnzTimeInputInlineComponent
],
})
], NgnzTimeInputInlineModule);
return NgnzTimeInputInlineModule;
}());
exports.NgnzTimeInputInlineComponent = NgnzTimeInputInlineComponent;
exports.NgnzTimeInputInlineModule = NgnzTimeInputInlineModule;
exports.TimeValue = TimeValue;
Object.defineProperty(exports, '__esModule', { value: true });
})));
//# sourceMappingURL=ngnz-time-input.umd.js.map