UNPKG

@taiga-ui/kit

Version:
824 lines (784 loc) 46.4 kB
(function (global, factory) { typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@angular/core'), require('@angular/router'), require('@taiga-ui/cdk'), require('@taiga-ui/core'), require('@taiga-ui/kit/tokens'), require('rxjs'), require('@angular/common'), require('rxjs/operators'), require('@tinkoff/ng-polymorpheus'), require('@ng-web-apis/mutation-observer'), require('@ng-web-apis/common'), require('@tinkoff/ng-event-plugins')) : typeof define === 'function' && define.amd ? define('@taiga-ui/kit/components/tabs', ['exports', '@angular/core', '@angular/router', '@taiga-ui/cdk', '@taiga-ui/core', '@taiga-ui/kit/tokens', 'rxjs', '@angular/common', 'rxjs/operators', '@tinkoff/ng-polymorpheus', '@ng-web-apis/mutation-observer', '@ng-web-apis/common', '@tinkoff/ng-event-plugins'], factory) : (global = global || self, factory((global['taiga-ui'] = global['taiga-ui'] || {}, global['taiga-ui'].kit = global['taiga-ui'].kit || {}, global['taiga-ui'].kit.components = global['taiga-ui'].kit.components || {}, global['taiga-ui'].kit.components.tabs = {}), global.ng.core, global.ng.router, global.cdk, global.core$1, global['taiga-ui'].kit.tokens, global.rxjs, global.ng.common, global.rxjs.operators, global.ngPolymorpheus, global.mutationObserver, global.common$1, global.ngEventPlugins)); }(this, (function (exports, core, router, cdk, core$1, tokens, rxjs, common, operators, ngPolymorpheus, mutationObserver, common$1, ngEventPlugins) { '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; } var TuiTabDirective = /** @class */ (function () { function TuiTabDirective(template) { this.template = template; } TuiTabDirective.ctorParameters = function () { return [ { type: core.TemplateRef, decorators: [{ type: core.Inject, args: [core.TemplateRef,] }] } ]; }; TuiTabDirective = __decorate([ core.Directive({ selector: "ng-template[tuiTab]", }), __param(0, core.Inject(core.TemplateRef)) ], TuiTabDirective); return TuiTabDirective; }()); var TUI_TAB_ACTIVATE = 'tui-tab-activate'; var TUI_TAB_EVENT = new core.InjectionToken('Stream of tab activation events'); var TUI_TAB_PROVIDERS = [ cdk.TuiDestroyService, cdk.TuiFocusVisibleService, core$1.TuiRouterLinkActiveService, { provide: TUI_TAB_EVENT, deps: [core.ElementRef, common.DOCUMENT, core$1.TuiRouterLinkActiveService], useFactory: tabActiveFactory, }, core$1.MODE_PROVIDER, ]; function tabActiveFactory(_a, documentRef, routerLinkActiveService) { var nativeElement = _a.nativeElement; return rxjs.merge(routerLinkActiveService.pipe(operators.filter(cdk.identity)), nativeElement.matches('button') ? cdk.typedFromEvent(nativeElement, 'click') : rxjs.EMPTY).pipe(operators.map(function () { return nativeElement.dispatchEvent(cdk.tuiCustomEvent(TUI_TAB_ACTIVATE, { bubbles: true }, documentRef)); })); } var TuiTabComponent = /** @class */ (function () { function TuiTabComponent(routerLinkActive, mode$, event$, mobileAware, isIos, isAndroid, focusVisible$) { var _this = this; this.routerLinkActive = routerLinkActive; this.mode$ = mode$; this.event$ = event$; this.focusVisible = false; this.isIos = mobileAware && isIos; this.isAndroid = mobileAware && isAndroid; focusVisible$.subscribe(function (visible) { _this.focusVisible = visible; }); } Object.defineProperty(TuiTabComponent.prototype, "isActive", { get: function () { return !!this.routerLinkActive && this.routerLinkActive.isActive; }, enumerable: true, configurable: true }); TuiTabComponent.ctorParameters = function () { return [ { type: router.RouterLinkActive, decorators: [{ type: core.Optional }, { type: core.Inject, args: [router.RouterLinkActive,] }] }, { type: rxjs.Observable, decorators: [{ type: core.Inject, args: [core$1.TUI_MODE,] }] }, { type: rxjs.Observable, decorators: [{ type: core.Inject, args: [TUI_TAB_EVENT,] }] }, { type: Boolean, decorators: [{ type: core.Inject, args: [tokens.TUI_MOBILE_AWARE,] }] }, { type: Boolean, decorators: [{ type: core.Inject, args: [cdk.TUI_IS_IOS,] }] }, { type: Boolean, decorators: [{ type: core.Inject, args: [cdk.TUI_IS_ANDROID,] }] }, { type: cdk.TuiFocusVisibleService, decorators: [{ type: core.Inject, args: [cdk.TuiFocusVisibleService,] }] } ]; }; __decorate([ core.HostBinding('class._ios') ], TuiTabComponent.prototype, "isIos", void 0); __decorate([ core.HostBinding('class._android') ], TuiTabComponent.prototype, "isAndroid", void 0); __decorate([ core.HostBinding('class._focus-visible') ], TuiTabComponent.prototype, "focusVisible", void 0); __decorate([ core.HostBinding('class._active') ], TuiTabComponent.prototype, "isActive", null); TuiTabComponent = __decorate([ core.Component({ selector: "a[tuiTab]:not([routerLink]), a[tuiTab][routerLink][routerLinkActive], button[tuiTab]", template: "<ng-container *ngIf=\"event$ | async\"></ng-container>\n<span class=\"highlight\"><ng-content></ng-content></span>\n", changeDetection: core.ChangeDetectionStrategy.OnPush, providers: TUI_TAB_PROVIDERS, host: { '($.data-mode.attr)': 'mode$', }, styles: [":host-context(._underline):hover{box-shadow:inset 0 -2px var(--tui-base-03)}:host{transition-duration:.3s;transition-timing-function:ease-in-out;-webkit-appearance:none;-moz-appearance:none;appearance:none;padding:0;border:0;background:0 0;font-size:inherit;line-height:inherit;position:relative;display:flex;flex-shrink:0;height:100%;justify-content:space-between;align-items:center;white-space:nowrap;cursor:pointer;outline:0;text-decoration:none;color:inherit;transition-property:color,box-shadow,opacity}:host:not(:last-child){margin-right:24px}:host:hover{color:var(--tui-text-01)}:host:disabled{opacity:var(--tui-disabled-opacity);pointer-events:none}:host:not([data-mode])._active{opacity:1;color:var(--tui-text-01);box-shadow:none}:host[data-mode=onDark]{color:rgba(255,255,255,.72)}:host[data-mode=onDark]._active,:host[data-mode=onDark]:hover{color:#fff}:host[data-mode=onDark]._focus-visible .highlight{background:var(--tui-clear-inverse);color:var(--tui-text-01)}:host[data-mode=onLight]{color:rgba(0,0,0,.56)}:host[data-mode=onLight]._focus-visible .highlight{background:var(--tui-text-01);color:#fff}:host._focus-visible .highlight{background:var(--tui-selection)}:host._android{transition-property:opacity;transition-duration:.3s;transition-timing-function:ease-in-out;height:48px;flex:1;flex-shrink:0;justify-content:center;margin:0;text-transform:uppercase;color:var(--tui-base-09);opacity:.5;font-size:14px;font-weight:500;letter-spacing:-.13px;font-family:-apple-system,BlinkMacSystemFont,Roboto,'Helvetica Neue',sans-serif}:host._android:hover{box-shadow:none}:host._android._active{opacity:1;color:var(--tui-base-09)}:host._android .highlight{width:auto}:host._ios{height:28px;flex:1;flex-shrink:0;justify-content:center;margin:0;color:var(--tui-base-01);opacity:1;font-size:13px;font-weight:500;letter-spacing:-.08px;font-family:-apple-system,BlinkMacSystemFont,Roboto,'Helvetica Neue',sans-serif}:host._ios:hover{box-shadow:none}:host._ios._active{font-size:14px;font-weight:600;color:var(--tui-link)}:host._ios .highlight{width:auto}.highlight{display:inline-flex;width:100%;align-items:center;justify-content:inherit}.highlight ::ng-deep>*{flex-shrink:0}"] }), __param(0, core.Optional()), __param(0, core.Inject(router.RouterLinkActive)), __param(1, core.Inject(core$1.TUI_MODE)), __param(2, core.Inject(TUI_TAB_EVENT)), __param(3, core.Inject(tokens.TUI_MOBILE_AWARE)), __param(4, core.Inject(cdk.TUI_IS_IOS)), __param(5, core.Inject(cdk.TUI_IS_ANDROID)), __param(6, core.Inject(cdk.TuiFocusVisibleService)) ], TuiTabComponent); return TuiTabComponent; }()); var TAB_ACTIVE_CLASS = '_active'; var TAB_MARGIN = 24; // @dynamic var TuiTabsComponent = /** @class */ (function () { function TuiTabsComponent(elementRef, renderer, changeDetectorRef, resize$, isIos, isAndroid, mobileAware) { var _this = this; this.elementRef = elementRef; this.renderer = renderer; this.underline = true; this.activeItemIndexChange = new core.EventEmitter(); this.children = cdk.EMPTY_QUERY; this.activeItemIndex = 0; this.isIos = mobileAware && isIos; this.isAndroid = mobileAware && isAndroid; resize$.pipe(operators.filter(function () { return _this.underline; })).subscribe(function () { changeDetectorRef.detectChanges(); }); } Object.defineProperty(TuiTabsComponent.prototype, "activeItemIndexSetter", { set: function (index) { this.activeItemIndex = index; this.scrollTo(this.tabs[index]); }, enumerable: true, configurable: true }); Object.defineProperty(TuiTabsComponent.prototype, "refresh$", { get: function () { return cdk.itemsQueryListObservable(this.children).pipe(operators.mapTo(true)); }, enumerable: true, configurable: true }); Object.defineProperty(TuiTabsComponent.prototype, "tabs", { get: function () { var tabs = Array.from(this.elementRef.nativeElement.querySelectorAll('[tuiTab]')); return tabs; }, enumerable: true, configurable: true }); Object.defineProperty(TuiTabsComponent.prototype, "activeElement", { get: function () { return this.tabs[this.activeItemIndex] || null; }, enumerable: true, configurable: true }); TuiTabsComponent.prototype.ngAfterViewChecked = function () { var _this = this; var _a = this, tabs = _a.tabs, activeElement = _a.activeElement; tabs.forEach(function (nativeElement) { _this.renderer.removeClass(nativeElement, TAB_ACTIVE_CLASS); _this.renderer.setAttribute(nativeElement, 'tabIndex', '-1'); }); if (activeElement) { this.renderer.addClass(activeElement, TAB_ACTIVE_CLASS); this.renderer.setAttribute(activeElement, 'tabIndex', '0'); } }; TuiTabsComponent.prototype.onActivate = function (element) { var index = this.tabs.findIndex(function (tab) { return tab === element; }); if (index === this.activeItemIndex) { return; } this.activeItemIndexSetter = index; this.activeItemIndexChange.emit(index); }; TuiTabsComponent.prototype.onKeyDownArrow = function (current, step) { var tabs = this.tabs; cdk.moveFocus(tabs.indexOf(current), tabs, step); }; TuiTabsComponent.prototype.scrollTo = function (element) { if (!element) { return; } var offsetLeft = element.offsetLeft, offsetWidth = element.offsetWidth; var nativeElement = this.elementRef.nativeElement; if (offsetLeft < nativeElement.scrollLeft) { nativeElement.scrollLeft = offsetLeft; } if (offsetLeft + offsetWidth > nativeElement.scrollLeft + nativeElement.offsetWidth) { nativeElement.scrollLeft = offsetLeft + offsetWidth - nativeElement.offsetWidth; } }; TuiTabsComponent.ctorParameters = function () { return [ { type: core.ElementRef, decorators: [{ type: core.Inject, args: [core.ElementRef,] }] }, { type: core.Renderer2, decorators: [{ type: core.Inject, args: [core.Renderer2,] }] }, { type: core.ChangeDetectorRef, decorators: [{ type: core.Inject, args: [core.ChangeDetectorRef,] }] }, { type: rxjs.Observable, decorators: [{ type: core.Inject, args: [cdk.TuiResizeService,] }] }, { type: Boolean, decorators: [{ type: core.Inject, args: [cdk.TUI_IS_IOS,] }] }, { type: Boolean, decorators: [{ type: core.Inject, args: [cdk.TUI_IS_ANDROID,] }] }, { type: Boolean, decorators: [{ type: core.Inject, args: [tokens.TUI_MOBILE_AWARE,] }] } ]; }; __decorate([ core.Input(), core.HostBinding('class._underline'), cdk.tuiDefaultProp() ], TuiTabsComponent.prototype, "underline", void 0); __decorate([ core.Input('activeItemIndex') ], TuiTabsComponent.prototype, "activeItemIndexSetter", null); __decorate([ core.Output() ], TuiTabsComponent.prototype, "activeItemIndexChange", void 0); __decorate([ core.HostBinding('class._ios') ], TuiTabsComponent.prototype, "isIos", void 0); __decorate([ core.HostBinding('class._android') ], TuiTabsComponent.prototype, "isAndroid", void 0); __decorate([ core.ContentChildren(core.forwardRef(function () { return TuiTabComponent; })) ], TuiTabsComponent.prototype, "children", void 0); __decorate([ cdk.tuiPure ], TuiTabsComponent.prototype, "refresh$", null); __decorate([ core.HostListener(TUI_TAB_ACTIVATE + ".stop", ['$event.target']) ], TuiTabsComponent.prototype, "onActivate", null); __decorate([ core.HostListener('keydown.arrowRight.prevent', ['$event.target', '1']), core.HostListener('keydown.arrowLeft.prevent', ['$event.target', '-1']) ], TuiTabsComponent.prototype, "onKeyDownArrow", null); TuiTabsComponent = __decorate([ core.Component({ selector: 'tui-tabs, nav[tuiTabs]', template: "<tui-underline\n *ngIf=\"underline && (refresh$ | async)\"\n [element]=\"activeElement\"\n></tui-underline>\n<ng-content></ng-content>\n", changeDetection: core.ChangeDetectionStrategy.OnPush, host: { class: 'tui-zero-scrollbar', }, providers: [cdk.TuiDestroyService, cdk.TuiResizeService], styles: [":host{font:var(--tui-font-text-m);position:relative;display:flex;height:var(--tui-height-l);color:var(--tui-text-02);box-shadow:inset 0 -1px var(--tui-base-03);overflow:auto}:host._android{height:auto}:host._ios{height:auto;border:2px solid transparent;border-radius:9px;background:var(--tui-link);box-shadow:none}"] }), __param(0, core.Inject(core.ElementRef)), __param(1, core.Inject(core.Renderer2)), __param(2, core.Inject(core.ChangeDetectorRef)), __param(3, core.Inject(cdk.TuiResizeService)), __param(4, core.Inject(cdk.TUI_IS_IOS)), __param(5, core.Inject(cdk.TUI_IS_ANDROID)), __param(6, core.Inject(tokens.TUI_MOBILE_AWARE)) ], TuiTabsComponent); return TuiTabsComponent; }()); function tabsRefreshFactory(resize$, mutations$, destroy$, _a, _b, changeDetectorRef) { var body = _a.body; var nativeElement = _b.nativeElement; return rxjs.merge(resize$, mutations$.pipe(operators.tap(function () { return changeDetectorRef.detectChanges(); }))).pipe( // Ignoring cases when host is detached from DOM operators.filter(function () { return body.contains(nativeElement); }), operators.debounceTime(0), operators.startWith(null), operators.takeUntil(destroy$)); } var TABS_REFRESH = new core.InjectionToken('Refresh stream'); var ɵ0 = { childList: true, subtree: true, }; var TABS_PROVIDERS = [ cdk.TuiResizeService, cdk.TuiDestroyService, mutationObserver.MutationObserverService, { provide: mutationObserver.MUTATION_OBSERVER_INIT, useValue: ɵ0, }, { provide: TABS_REFRESH, deps: [ cdk.TuiResizeService, mutationObserver.MutationObserverService, cdk.TuiDestroyService, common.DOCUMENT, core.ElementRef, core.ChangeDetectorRef, ], useFactory: tabsRefreshFactory, }, ]; // @dynamic var TuiTabsWithMoreComponent = /** @class */ (function () { function TuiTabsWithMoreComponent(refresh$, elementRef, changeDetectorRef, moreWord$) { this.refresh$ = refresh$; this.elementRef = elementRef; this.changeDetectorRef = changeDetectorRef; this.moreWord$ = moreWord$; this.moreContent = ''; this.underline = true; this.activeItemIndex = 0; this.itemsLimit = Infinity; this.activeItemIndexChange = new core.EventEmitter(); this.items = cdk.EMPTY_QUERY; this.open = false; this.maxIndex = Infinity; } Object.defineProperty(TuiTabsWithMoreComponent.prototype, "tabs", { get: function () { return Array.from(this.elementRef.nativeElement.querySelectorAll('[tuiTab]')); }, enumerable: true, configurable: true }); Object.defineProperty(TuiTabsWithMoreComponent.prototype, "activeElement", { get: function () { return this.tabs[this.activeItemIndex] || null; }, enumerable: true, configurable: true }); Object.defineProperty(TuiTabsWithMoreComponent.prototype, "isMoreVisible", { get: function () { return this.lastVisibleIndex < this.items.length - 1; }, enumerable: true, configurable: true }); Object.defineProperty(TuiTabsWithMoreComponent.prototype, "isMoreFocusable", { get: function () { return !!this.moreButton && cdk.isNativeFocused(this.moreButton.nativeElement); }, enumerable: true, configurable: true }); Object.defineProperty(TuiTabsWithMoreComponent.prototype, "lastVisibleIndex", { get: function () { if (this.itemsLimit + 1 >= this.items.length) { return this.maxIndex; } var offset = this.itemsLimit - 1 > this.activeItemIndex ? 1 : 2; return Math.min(this.itemsLimit - offset, this.maxIndex); }, enumerable: true, configurable: true }); TuiTabsWithMoreComponent.prototype.ngAfterViewInit = function () { var _this = this; this.refresh$ .pipe(operators.map(function () { return _this.getMaxIndex(); }), operators.filter(function (maxIndex) { return _this.maxIndex !== maxIndex; })) .subscribe(function (maxIndex) { _this.maxIndex = maxIndex; _this.changeDetectorRef.detectChanges(); }); }; TuiTabsWithMoreComponent.prototype.onActiveItemIndexChange = function (activeItemIndex) { this.updateActiveItemIndex(activeItemIndex); }; TuiTabsWithMoreComponent.prototype.onClick = function (index) { this.open = false; this.focusMore(); this.updateActiveItemIndex(index); }; TuiTabsWithMoreComponent.prototype.onArrowRight = function (element) { if (cdk.isNativeFocused(element)) { this.focusMore(); } }; TuiTabsWithMoreComponent.prototype.onArrowLeft = function () { var tabs = this.tabs; var index = tabs.length - 2; while (index >= 0) { cdk.setNativeFocused(tabs[index]); if (cdk.isNativeFocused(tabs[index])) { return; } index--; } }; TuiTabsWithMoreComponent.prototype.onWrapperArrow = function (button, wrapper, prev) { var target = cdk.getClosestFocusable(button, prev, wrapper); if (target) { cdk.setNativeFocused(target); } }; TuiTabsWithMoreComponent.prototype.focusMore = function () { if (this.moreButton) { cdk.setNativeFocused(this.moreButton.nativeElement); } }; TuiTabsWithMoreComponent.prototype.getMaxIndex = function () { var _a = this, tabs = _a.tabs, activeItemIndex = _a.activeItemIndex; if (tabs.length < 2) { return 0; } var clientWidth = this.elementRef.nativeElement.clientWidth; var activeWidth = tabs[activeItemIndex] ? tabs[activeItemIndex].scrollWidth : 0; var moreWidth = tabs[tabs.length - 1].scrollWidth; var maxIndex = tabs.length - 2; var total = tabs.reduce(function (acc, tab) { return acc + tab.scrollWidth; }, 0) + maxIndex * TAB_MARGIN - moreWidth; if (total <= clientWidth) { return Infinity; } while (maxIndex) { total -= tabs[maxIndex].scrollWidth + TAB_MARGIN; maxIndex--; var activeOffset = activeItemIndex > maxIndex ? activeWidth + TAB_MARGIN : 0; if (total + activeOffset + moreWidth + TAB_MARGIN < clientWidth) { return maxIndex; } } return 0; }; TuiTabsWithMoreComponent.prototype.updateActiveItemIndex = function (activeItemIndex) { if (this.activeItemIndex === activeItemIndex) { return; } this.activeItemIndex = activeItemIndex; this.activeItemIndexChange.emit(activeItemIndex); this.maxIndex = this.getMaxIndex(); }; TuiTabsWithMoreComponent.ctorParameters = function () { return [ { type: rxjs.Observable, decorators: [{ type: core.Inject, args: [TABS_REFRESH,] }] }, { type: core.ElementRef, decorators: [{ type: core.Inject, args: [core.ElementRef,] }] }, { type: core.ChangeDetectorRef, decorators: [{ type: core.Inject, args: [core.ChangeDetectorRef,] }] }, { type: rxjs.Observable, decorators: [{ type: core.Inject, args: [tokens.TUI_MORE_WORD,] }] } ]; }; __decorate([ core.Input(), cdk.tuiDefaultProp() ], TuiTabsWithMoreComponent.prototype, "moreContent", void 0); __decorate([ core.Input(), core.HostBinding('class._underline'), cdk.tuiDefaultProp() ], TuiTabsWithMoreComponent.prototype, "underline", void 0); __decorate([ core.Input(), cdk.tuiDefaultProp() ], TuiTabsWithMoreComponent.prototype, "activeItemIndex", void 0); __decorate([ core.Input(), cdk.tuiDefaultProp() ], TuiTabsWithMoreComponent.prototype, "itemsLimit", void 0); __decorate([ core.Output() ], TuiTabsWithMoreComponent.prototype, "activeItemIndexChange", void 0); __decorate([ core.ContentChildren(TuiTabDirective, { read: core.TemplateRef }) ], TuiTabsWithMoreComponent.prototype, "items", void 0); __decorate([ core.ViewChild(TuiTabComponent, { read: core.ElementRef }) ], TuiTabsWithMoreComponent.prototype, "moreButton", void 0); TuiTabsWithMoreComponent = __decorate([ core.Component({ selector: 'tui-tabs-with-more, nav[tuiTabsWithMore]', template: "<ng-container *ngIf=\"items.changes | async\"></ng-container>\n<div class=\"wrapper\">\n <tui-tabs\n class=\"tabs\"\n [underline]=\"false\"\n [activeItemIndex]=\"activeItemIndex\"\n (activeItemIndexChange)=\"onActiveItemIndexChange($event)\"\n (keydown.arrowRight)=\"onArrowRight($event.target)\"\n >\n <ng-container *ngFor=\"let item of items; let index = index\">\n <ng-container\n *ngIf=\"index <= lastVisibleIndex; else hidden\"\n [ngTemplateOutlet]=\"item\"\n ></ng-container>\n <ng-template #hidden>\n <div\n class=\"overflown\"\n [class.overflown_hidden]=\"index !== activeItemIndex\"\n >\n <ng-container *ngTemplateOutlet=\"item\"></ng-container>\n </div>\n </ng-template>\n </ng-container>\n </tui-tabs>\n <tui-hosted-dropdown\n class=\"more_wrapper\"\n [class.overflown_hidden]=\"!isMoreVisible\"\n [content]=\"dropdown\"\n [(open)]=\"open\"\n >\n <button\n tuiTab\n type=\"button\"\n class=\"more\"\n [class._active]=\"open\"\n [tuiFocusable]=\"isMoreFocusable\"\n (keydown.arrowLeft.prevent)=\"onArrowLeft()\"\n >\n <span polymorpheus-outlet [content]=\"moreContent || more\"></span>\n </button>\n <ng-template #more>\n {{moreWord$ | async}}\n <tui-svg\n src=\"tuiIconChevronDown\"\n class=\"icon\"\n [class.icon_rotated]=\"open\"\n ></tui-svg>\n </ng-template>\n </tui-hosted-dropdown>\n <ng-template #dropdown>\n <div\n #element\n class=\"dropdown\"\n (keydown.arrowUp.prevent)=\"onWrapperArrow($event.target, element, true)\"\n (keydown.arrowDown.prevent)=\"onWrapperArrow($event.target, element, false)\"\n >\n <div\n *ngFor=\"let item of items; let index = index\"\n (tui-tab-activate)=\"onClick(index)\"\n >\n <ng-container\n *ngIf=\"index > lastVisibleIndex && index !== activeItemIndex\"\n [ngTemplateOutlet]=\"item\"\n ></ng-container>\n </div>\n </div>\n </ng-template>\n <tui-underline *ngIf=\"underline\" [element]=\"activeElement\"></tui-underline>\n</div>\n", changeDetection: core.ChangeDetectionStrategy.OnPush, providers: TABS_PROVIDERS, styles: [":host{font:var(--tui-font-text-m);position:relative;display:flex;height:var(--tui-height-l);box-sizing:border-box;color:var(--tui-text-02);box-shadow:inset 0 -1px var(--tui-base-03);overflow:hidden}.wrapper{position:relative;display:flex}.tabs{height:inherit;font-size:inherit;font-weight:inherit;overflow:visible;box-shadow:none;color:inherit}.overflown{margin-right:24px}.overflown_hidden{margin:0;width:0;max-width:0;overflow:hidden;visibility:hidden}.more_wrapper{height:100%}.icon{transition-property:transform;transition-duration:.3s;transition-timing-function:ease-in-out;margin-right:-4px;vertical-align:bottom}.icon_rotated{transform:rotate(180deg)}.dropdown{padding:8px 0}.dropdown ::ng-deep [tuiTab]{width:100%;height:44px;justify-content:flex-start;margin:0;padding:0 16px;color:var(--tui-text-02)}.dropdown ::ng-deep [tuiTab]:before{display:none}.dropdown ::ng-deep [tuiTab]._active,.dropdown ::ng-deep [tuiTab]:focus,.dropdown ::ng-deep [tuiTab]:hover{box-shadow:none;color:var(--tui-base-08);background:var(--tui-base-02)}"] }), __param(0, core.Inject(TABS_REFRESH)), __param(1, core.Inject(core.ElementRef)), __param(2, core.Inject(core.ChangeDetectorRef)), __param(3, core.Inject(tokens.TUI_MORE_WORD)) ], TuiTabsWithMoreComponent); return TuiTabsWithMoreComponent; }()); var TuiUnderlineComponent = /** @class */ (function () { function TuiUnderlineComponent(_a, ngZone, animationFrame$, mobileAware, ios, android, mode$) { var _this = this; var nativeElement = _a.nativeElement; this.ngZone = ngZone; this.animationFrame$ = animationFrame$; this.mobileAware = mobileAware; this.ios = ios; this.android = android; this.mode$ = mode$; this.isIos = this.mobileAware && this.ios; this.isAndroid = this.mobileAware && this.android; this.element$ = new rxjs.ReplaySubject(1); this.refresh$ = this.element$.pipe(operators.switchMap(function (element) { return element ? _this.animationFrame$.pipe(operators.mapTo(element), cdk.tuiZonefree(_this.ngZone)) : rxjs.of(null); }), operators.share()); this.transition$ = ngEventPlugins.asCallable(this.element$.pipe(operators.map(function (element) { return element && 'all'; }), operators.debounceTime(50))); this.transform$ = ngEventPlugins.asCallable(this.refresh$.pipe(operators.map(function (element) { return element ? "translate3d(" + cdk.px(element.offsetLeft) + ", 0, 0)" : null; }))); this.width$ = ngEventPlugins.asCallable(this.refresh$.pipe(operators.map(function (element) { return (element ? element.clientWidth : 0); }))); nativeElement['$.style.transitionProperty'] = this.transition$; nativeElement['$.style.transform'] = this.transform$; nativeElement['$.style.width.px'] = this.width$; } Object.defineProperty(TuiUnderlineComponent.prototype, "element", { set: function (element) { this.element$.next(element); }, enumerable: true, configurable: true }); TuiUnderlineComponent.ctorParameters = function () { return [ { type: core.ElementRef, decorators: [{ type: core.Inject, args: [core.ElementRef,] }] }, { type: core.NgZone, decorators: [{ type: core.Inject, args: [core.NgZone,] }] }, { type: rxjs.Observable, decorators: [{ type: core.Inject, args: [common$1.ANIMATION_FRAME,] }] }, { type: Boolean, decorators: [{ type: core.Inject, args: [tokens.TUI_MOBILE_AWARE,] }] }, { type: Boolean, decorators: [{ type: core.Inject, args: [cdk.TUI_IS_IOS,] }] }, { type: Boolean, decorators: [{ type: core.Inject, args: [cdk.TUI_IS_ANDROID,] }] }, { type: rxjs.Observable, decorators: [{ type: core.Inject, args: [core$1.TUI_MODE,] }] } ]; }; __decorate([ core.Input(), cdk.tuiDefaultProp() ], TuiUnderlineComponent.prototype, "element", null); __decorate([ core.HostBinding('class._ios') ], TuiUnderlineComponent.prototype, "isIos", void 0); __decorate([ core.HostBinding('class._android') ], TuiUnderlineComponent.prototype, "isAndroid", void 0); __decorate([ core.HostListener('$.style.transitionProperty') ], TuiUnderlineComponent.prototype, "transition$", void 0); __decorate([ core.HostListener('$.style.transform') ], TuiUnderlineComponent.prototype, "transform$", void 0); __decorate([ core.HostListener('$.style.width.px') ], TuiUnderlineComponent.prototype, "width$", void 0); TuiUnderlineComponent = __decorate([ core.Component({ selector: 'tui-underline', template: '', changeDetection: core.ChangeDetectionStrategy.OnPush, providers: [core$1.MODE_PROVIDER], host: { '($.data-mode.attr)': 'mode$', }, styles: [":host{transition-duration:.3s;transition-timing-function:ease-in-out;position:absolute;left:0;height:100%;color:var(--tui-primary);transform:scale(0);box-shadow:inset 0 -3px 0 -1px;transition-property:none;pointer-events:none}:host._ios{border-radius:7px;background:var(--tui-base-01);box-shadow:0 3px 1px rgba(0,0,0,.04),0 3px 8px rgba(0,0,0,.12)}:host._android{box-shadow:inset 0 -3px var(--tui-link)}:host[data-mode=onDark]{color:var(--tui-text-01-night)}:host[data-mode=onLight]{color:#666}"] }), __param(0, core.Inject(core.ElementRef)), __param(1, core.Inject(core.NgZone)), __param(2, core.Inject(common$1.ANIMATION_FRAME)), __param(3, core.Inject(tokens.TUI_MOBILE_AWARE)), __param(4, core.Inject(cdk.TUI_IS_IOS)), __param(5, core.Inject(cdk.TUI_IS_ANDROID)), __param(6, core.Inject(core$1.TUI_MODE)) ], TuiUnderlineComponent); return TuiUnderlineComponent; }()); var TuiTabsModule = /** @class */ (function () { function TuiTabsModule() { } TuiTabsModule = __decorate([ core.NgModule({ imports: [ common.CommonModule, core$1.TuiHostedDropdownModule, core$1.TuiSvgModule, cdk.TuiFocusableModule, ngPolymorpheus.PolymorpheusModule, ], declarations: [ TuiTabsWithMoreComponent, TuiTabsComponent, TuiTabComponent, TuiUnderlineComponent, TuiTabDirective, ], exports: [ TuiTabsWithMoreComponent, TuiTabsComponent, TuiTabComponent, TuiTabDirective, ], }) ], TuiTabsModule); return TuiTabsModule; }()); exports.TABS_PROVIDERS = TABS_PROVIDERS; exports.TABS_REFRESH = TABS_REFRESH; exports.TAB_ACTIVE_CLASS = TAB_ACTIVE_CLASS; exports.TAB_MARGIN = TAB_MARGIN; exports.TUI_TAB_ACTIVATE = TUI_TAB_ACTIVATE; exports.TUI_TAB_EVENT = TUI_TAB_EVENT; exports.TUI_TAB_PROVIDERS = TUI_TAB_PROVIDERS; exports.TuiTabComponent = TuiTabComponent; exports.TuiTabDirective = TuiTabDirective; exports.TuiTabsComponent = TuiTabsComponent; exports.TuiTabsModule = TuiTabsModule; exports.TuiTabsWithMoreComponent = TuiTabsWithMoreComponent; exports.TuiUnderlineComponent = TuiUnderlineComponent; exports.tabActiveFactory = tabActiveFactory; exports.tabsRefreshFactory = tabsRefreshFactory; exports.ɵ0 = ɵ0; Object.defineProperty(exports, '__esModule', { value: true }); }))); //# sourceMappingURL=taiga-ui-kit-components-tabs.umd.js.map