UNPKG

@taiga-ui/kit

Version:
172 lines (167 loc) • 8.21 kB
import { __extends, __decorate, __param } from 'tslib'; import { DOCUMENT, CommonModule } from '@angular/common'; import { Optional, Self, Inject, ChangeDetectorRef, Input, ViewChild, HostBinding, Component, ChangeDetectionStrategy, forwardRef, NgModule } from '@angular/core'; import { NgControl } from '@angular/forms'; import { tuiDefaultProp, tuiPure, TUI_FOCUSABLE_ITEM_ACCESSOR, AbstractTuiControl } from '@taiga-ui/cdk'; import { TuiTextfieldSizeDirective, TUI_TEXTFIELD_SIZE, TuiPrimitiveTextfieldComponent, TUI_VALUE_ACCESSOR_PROVIDER, TuiSvgModule, TuiHintModule, TuiPrimitiveTextfieldModule, TuiNotificationsModule } from '@taiga-ui/core'; import { TUI_COPY_TEXTS } from '@taiga-ui/kit/tokens'; import { Subject, merge, of, timer, Observable } from 'rxjs'; import { switchMap, mapTo, startWith } from 'rxjs/operators'; import { PolymorpheusModule } from '@tinkoff/ng-polymorpheus'; // @dynamic var TuiInputCopyComponent = /** @class */ (function (_super) { __extends(TuiInputCopyComponent, _super); function TuiInputCopyComponent(control, changeDetectorRef, documentRef, textfieldSize, copyTexts$) { var _this = _super.call(this, control, changeDetectorRef) || this; _this.documentRef = documentRef; _this.textfieldSize = textfieldSize; _this.copyTexts$ = copyTexts$; _this.successMessage = ''; _this.messageDirection = 'bottom-left'; _this.messageMode = null; _this.copy$ = new Subject(); return _this; } TuiInputCopyComponent_1 = TuiInputCopyComponent; Object.defineProperty(TuiInputCopyComponent.prototype, "hasValue", { get: function () { return !!this.value; }, enumerable: true, configurable: true }); Object.defineProperty(TuiInputCopyComponent.prototype, "hintText$", { get: function () { var _this = this; return this.copyTexts$.pipe(switchMap(function (texts) { return _this.copy$.pipe(switchMap(function () { return merge(of(_this.successMessage || texts[1]), timer(3000).pipe(mapTo(texts[0]))); }), startWith(texts[0])); })); }, enumerable: true, configurable: true }); Object.defineProperty(TuiInputCopyComponent.prototype, "nativeFocusableElement", { get: function () { return this.computedDisabled || !this.textfield ? null : this.textfield.nativeFocusableElement; }, enumerable: true, configurable: true }); Object.defineProperty(TuiInputCopyComponent.prototype, "focused", { get: function () { return !!this.textfield && this.textfield.focused; }, enumerable: true, configurable: true }); Object.defineProperty(TuiInputCopyComponent.prototype, "icon", { get: function () { return this.textfieldSize.size === 's' ? 'tuiIconCopy' : 'tuiIconCopyLarge'; }, enumerable: true, configurable: true }); TuiInputCopyComponent.prototype.onValueChange = function (value) { this.updateValue(value); }; TuiInputCopyComponent.prototype.onFocused = function (focused) { this.updateFocused(focused); }; TuiInputCopyComponent.prototype.onHovered = function (hovered) { this.updateHovered(hovered); }; TuiInputCopyComponent.prototype.onPressed = function (pressed) { this.updatePressed(pressed); }; TuiInputCopyComponent.prototype.copy = function () { if (!this.textfield || !this.textfield.nativeFocusableElement) { return; } this.textfield.nativeFocusableElement.select(); this.documentRef.execCommand('copy'); this.copy$.next(); }; TuiInputCopyComponent.prototype.getFallbackValue = function () { return ''; }; var TuiInputCopyComponent_1; TuiInputCopyComponent.ctorParameters = function () { return [ { type: NgControl, decorators: [{ type: Optional }, { type: Self }, { type: Inject, args: [NgControl,] }] }, { type: ChangeDetectorRef, decorators: [{ type: Inject, args: [ChangeDetectorRef,] }] }, { type: Document, decorators: [{ type: Inject, args: [DOCUMENT,] }] }, { type: TuiTextfieldSizeDirective, decorators: [{ type: Inject, args: [TUI_TEXTFIELD_SIZE,] }] }, { type: Observable, decorators: [{ type: Inject, args: [TUI_COPY_TEXTS,] }] } ]; }; __decorate([ Input(), tuiDefaultProp() ], TuiInputCopyComponent.prototype, "successMessage", void 0); __decorate([ Input(), tuiDefaultProp() ], TuiInputCopyComponent.prototype, "messageDirection", void 0); __decorate([ Input(), tuiDefaultProp() ], TuiInputCopyComponent.prototype, "messageMode", void 0); __decorate([ ViewChild(TuiPrimitiveTextfieldComponent) ], TuiInputCopyComponent.prototype, "textfield", void 0); __decorate([ HostBinding('class._has-value') ], TuiInputCopyComponent.prototype, "hasValue", null); __decorate([ tuiPure ], TuiInputCopyComponent.prototype, "hintText$", null); TuiInputCopyComponent = TuiInputCopyComponent_1 = __decorate([ Component({ selector: 'tui-input-copy', template: "<tui-primitive-textfield\n class=\"textfield\"\n [pseudoFocused]=\"pseudoFocused\"\n [pseudoHovered]=\"pseudoHovered\"\n [pseudoPressed]=\"pseudoPressed\"\n [invalid]=\"computedInvalid\"\n [focusable]=\"focusable\"\n [nativeId]=\"nativeId\"\n [disabled]=\"disabled\"\n [readOnly]=\"readOnly\"\n [iconContent]=\"!disabled ? iconContent : null\"\n [value]=\"value\"\n (valueChange)=\"onValueChange($event)\"\n (focusedChange)=\"onFocused($event)\"\n (hoveredChange)=\"onHovered($event)\"\n (pressedChange)=\"onPressed($event)\"\n>\n <ng-content></ng-content>\n</tui-primitive-textfield>\n\n<ng-template #iconContent>\n <tui-svg\n automation-id=\"tui-copy__icon\"\n class=\"icon\"\n tuiHintId=\"not_required\"\n [tuiHint]=\"hint\"\n [tuiHintDirection]=\"messageDirection\"\n [tuiHintMode]=\"messageMode\"\n [src]=\"icon\"\n (click)=\"copy()\"\n ></tui-svg>\n</ng-template>\n\n<ng-template #hint>\n <div polymorpheus-outlet [content]=\"hintText$ | async\"></div>\n</ng-template>\n", changeDetection: ChangeDetectionStrategy.OnPush, providers: [ TUI_VALUE_ACCESSOR_PROVIDER, { provide: TUI_FOCUSABLE_ITEM_ACCESSOR, useExisting: forwardRef(function () { return TuiInputCopyComponent_1; }), }, ], styles: [":host{display:block;border-radius:var(--tui-radius-m)}.icon{position:relative;cursor:pointer;pointer-events:auto;color:var(--tui-base-06)}:host:not(._has-value) .icon{pointer-events:none;opacity:var(--tui-disabled-opacity)}.textfield{border-radius:inherit}"] }), __param(0, Optional()), __param(0, Self()), __param(0, Inject(NgControl)), __param(1, Inject(ChangeDetectorRef)), __param(2, Inject(DOCUMENT)), __param(3, Inject(TUI_TEXTFIELD_SIZE)), __param(4, Inject(TUI_COPY_TEXTS)) ], TuiInputCopyComponent); return TuiInputCopyComponent; }(AbstractTuiControl)); var TuiInputCopyModule = /** @class */ (function () { function TuiInputCopyModule() { } TuiInputCopyModule = __decorate([ NgModule({ imports: [ CommonModule, PolymorpheusModule, TuiSvgModule, TuiHintModule, TuiPrimitiveTextfieldModule, TuiNotificationsModule, ], declarations: [TuiInputCopyComponent], exports: [TuiInputCopyComponent], }) ], TuiInputCopyModule); return TuiInputCopyModule; }()); /** * Generated bundle index. Do not edit. */ export { TuiInputCopyComponent, TuiInputCopyModule }; //# sourceMappingURL=taiga-ui-kit-components-input-copy.js.map