diff --git a/src/autocomplete/autocomplete.component.ts b/src/autocomplete/autocomplete.component.ts index ca737fa18..f5a8389b1 100644 --- a/src/autocomplete/autocomplete.component.ts +++ b/src/autocomplete/autocomplete.component.ts @@ -29,7 +29,6 @@ import { ThyStopPropagationDirective } from 'ngx-tethys/shared'; import { ActiveDescendantKeyManager } from '@angular/cdk/a11y'; -import { coerceBooleanProperty } from '@angular/cdk/coercion'; import { ThyEmpty } from 'ngx-tethys/empty'; import { NgClass, NgIf } from '@angular/common'; @@ -111,15 +110,7 @@ export class ThyAutocomplete extends _MixinBase implements IThyOptionParentCompo * @type boolean * @default false */ - @Input({ transform: booleanAttribute }) - set thyAutoActiveFirstOption(value: boolean) { - this._autoActiveFirstOption = coerceBooleanProperty(value); - } - - get thyAutoActiveFirstOption(): boolean { - return this._autoActiveFirstOption; - } - private _autoActiveFirstOption: boolean; + @Input({ transform: booleanAttribute }) thyAutoActiveFirstOption: boolean; /** * 被选中时调用,参数包含选中项的 value 值 diff --git a/src/avatar/avatar.component.ts b/src/avatar/avatar.component.ts index bd695427f..b81160a0e 100644 --- a/src/avatar/avatar.component.ts +++ b/src/avatar/avatar.component.ts @@ -10,7 +10,7 @@ import { booleanAttribute } from '@angular/core'; import { SafeHtml } from '@angular/platform-browser'; -import { coerceBooleanProperty, isString } from 'ngx-tethys/util'; +import { isString } from 'ngx-tethys/util'; import { useHostRenderer } from '@tethys/cdk/dom'; import { ThyAvatarService } from './avatar.service'; import { AvatarShortNamePipe, AvatarBgColorPipe, AvatarSrcPipe } from './avatar.pipe'; @@ -120,7 +120,7 @@ export class ThyAvatar implements OnInit { */ @Input({ transform: booleanAttribute }) set thyShowRemove(value: boolean) { - this._showRemove = coerceBooleanProperty(value); + this._showRemove = value; } /** @@ -129,7 +129,7 @@ export class ThyAvatar implements OnInit { */ @Input({ transform: booleanAttribute }) set thyRemovable(value: boolean) { - this._showRemove = coerceBooleanProperty(value); + this._showRemove = value; } /** diff --git a/src/badge/badge.component.ts b/src/badge/badge.component.ts index 5a3bbfd73..74fb49082 100644 --- a/src/badge/badge.component.ts +++ b/src/badge/badge.component.ts @@ -1,5 +1,4 @@ import { isTextColor } from 'ngx-tethys/core'; -import { coerceBooleanProperty } from 'ngx-tethys/util'; import { ChangeDetectionStrategy, Component, ElementRef, Input, OnInit, booleanAttribute, numberAttribute } from '@angular/core'; import { NgIf } from '@angular/common'; @@ -172,7 +171,7 @@ export class ThyBadge implements OnInit { */ @Input({ transform: booleanAttribute }) set thyKeepShow(value: boolean) { - this.keepShowValue = coerceBooleanProperty(value); + this.keepShowValue = value; if (this.initialized) { this.combineBadgeDisplayContent(); } diff --git a/src/button/button-icon.component.ts b/src/button/button-icon.component.ts index e7e5342b7..2ca2d2994 100644 --- a/src/button/button-icon.component.ts +++ b/src/button/button-icon.component.ts @@ -2,7 +2,6 @@ import { NgClass, NgIf } from '@angular/common'; import { ChangeDetectionStrategy, Component, HostBinding, Input, OnInit, ViewEncapsulation, booleanAttribute } from '@angular/core'; import { useHostRenderer } from '@tethys/cdk/dom'; import { ThyIcon } from 'ngx-tethys/icon'; -import { coerceBooleanProperty } from 'ngx-tethys/util'; export type ThyButtonIconShape = '' | 'circle-dashed' | 'circle-solid' | 'circle-thick-dashed' | 'circle-thick-solid' | 'self-icon'; @@ -81,7 +80,7 @@ export class ThyButtonIcon implements OnInit { */ @Input({ transform: booleanAttribute }) set thyLight(value: boolean) { - this._isLighted = coerceBooleanProperty(value); + this._isLighted = value; } /** @@ -90,7 +89,7 @@ export class ThyButtonIcon implements OnInit { */ @Input({ transform: booleanAttribute }) set thyActive(value: boolean) { - this._isActive = coerceBooleanProperty(value); + this._isActive = value; } /** diff --git a/src/card/content.component.ts b/src/card/content.component.ts index 013d1c557..43986b2fc 100644 --- a/src/card/content.component.ts +++ b/src/card/content.component.ts @@ -1,6 +1,4 @@ -import { coerceBooleanProperty } from 'ngx-tethys/util'; - -import { ChangeDetectionStrategy, Component, HostBinding, Input, OnInit } from '@angular/core'; +import { ChangeDetectionStrategy, Component, HostBinding, Input, OnInit, booleanAttribute } from '@angular/core'; /** * 卡片内容组件 @@ -24,9 +22,9 @@ export class ThyCardContent implements OnInit { * 内容区,滚动 * @default false */ - @Input('thyScroll') - set thyScroll(value: any) { - this.scrollClassName = coerceBooleanProperty(value); + @Input({ transform: booleanAttribute }) + set thyScroll(value: boolean) { + this.scrollClassName = value; } @HostBinding('class.thy-card-content--sm') _thySizeSm = false; diff --git a/src/cascader/cascader.component.ts b/src/cascader/cascader.component.ts index e399d0aed..aae197dc0 100644 --- a/src/cascader/cascader.component.ts +++ b/src/cascader/cascader.component.ts @@ -7,7 +7,7 @@ import { import { ThyEmpty } from 'ngx-tethys/empty'; import { ThyIcon } from 'ngx-tethys/icon'; import { SelectControlSize, SelectOptionBase, ThySelectControl } from 'ngx-tethys/shared'; -import { coerceBooleanProperty, elementMatchClosest, isEmpty } from 'ngx-tethys/util'; +import { elementMatchClosest, isEmpty } from 'ngx-tethys/util'; import { BehaviorSubject, Observable, Subject, Subscription, timer } from 'rxjs'; import { debounceTime, distinctUntilChanged, filter, take, takeUntil } from 'rxjs/operators'; import { CdkConnectedOverlay, CdkOverlayOrigin, ConnectedOverlayPositionChange, ConnectionPositionPair } from '@angular/cdk/overlay'; @@ -213,16 +213,14 @@ export class ThyCascader * 是否只读 * @default false */ - @Input() - // eslint-disable-next-line prettier/prettier + @Input({ transform: booleanAttribute }) + override set thyDisabled(value: boolean) { + this.disabled = value; + } override get thyDisabled(): boolean { return this.disabled; } - override set thyDisabled(value: boolean) { - this.disabled = coerceBooleanProperty(value); - } - disabled = false; /** diff --git a/src/checkbox/checkbox.component.ts b/src/checkbox/checkbox.component.ts index 4630edce0..c4ff69f41 100644 --- a/src/checkbox/checkbox.component.ts +++ b/src/checkbox/checkbox.component.ts @@ -1,7 +1,6 @@ import { booleanAttribute, Component, forwardRef, Input } from '@angular/core'; import { NG_VALUE_ACCESSOR } from '@angular/forms'; import { ThyTranslate } from 'ngx-tethys/core'; -import { coerceBooleanProperty } from 'ngx-tethys/util'; import { ThyFormCheckBaseComponent } from 'ngx-tethys/shared'; import { NgClass, NgIf } from '@angular/common'; @@ -38,7 +37,7 @@ export class ThyCheckbox extends ThyFormCheckBaseComponent { */ @Input({ transform: booleanAttribute }) set thyIndeterminate(value: boolean) { - this.isIndeterminate = coerceBooleanProperty(value); + this.isIndeterminate = value; } constructor(thyTranslate: ThyTranslate) { diff --git a/src/color-picker/color-picker.component.ts b/src/color-picker/color-picker.component.ts index b9dc9b43d..090ef28e4 100644 --- a/src/color-picker/color-picker.component.ts +++ b/src/color-picker/color-picker.component.ts @@ -21,7 +21,6 @@ import { ThyColorPickerPanel } from './color-picker-panel.component'; import { DEFAULT_COLORS } from './constant'; import { ThyColor } from './helpers/color.class'; import { takeUntil } from 'rxjs/operators'; -import { coerceBooleanProperty } from 'ngx-tethys/util'; export class OverlayBase extends ThyOverlayDirectiveBase { constructor(protected zone: NgZone, protected elementRef: ElementRef, platform: Platform, focusMonitor: FocusMonitor) { @@ -127,15 +126,14 @@ export class ThyColorPickerDirective extends _BaseMixin implements OnInit, OnDes /** * 是否属于禁用状态 */ - @Input() + @Input({ transform: booleanAttribute }) + override set thyDisabled(value: boolean) { + this.disabled = value; + } override get thyDisabled(): boolean { return this.disabled; } - override set thyDisabled(value: boolean) { - this.disabled = coerceBooleanProperty(value); - } - protected onChangeFn: (value: number | string) => void = () => {}; private onTouchFn: () => void = () => {}; diff --git a/src/date-picker/abstract-picker.component.ts b/src/date-picker/abstract-picker.component.ts index 9b885abdf..f4c5c3247 100644 --- a/src/date-picker/abstract-picker.component.ts +++ b/src/date-picker/abstract-picker.component.ts @@ -1,5 +1,5 @@ import { TabIndexDisabledControlValueAccessorMixin } from 'ngx-tethys/core'; -import { coerceBooleanProperty, TinyDate, warnDeprecation } from 'ngx-tethys/util'; +import { TinyDate, warnDeprecation } from 'ngx-tethys/util'; import { Subject } from 'rxjs'; import { @@ -173,12 +173,12 @@ export abstract class AbstractPickerComponent * @default false */ @Input({ transform: booleanAttribute }) + set thyDisabled(value: boolean) { + this.disabled = value; + } get thyDisabled(): boolean { return this.disabled; } - set thyDisabled(value: boolean) { - this.disabled = coerceBooleanProperty(value); - } disabled = false; diff --git a/src/date-picker/lib/popups/inner-popup.component.ts b/src/date-picker/lib/popups/inner-popup.component.ts index dfaeaabce..50a475924 100644 --- a/src/date-picker/lib/popups/inner-popup.component.ts +++ b/src/date-picker/lib/popups/inner-popup.component.ts @@ -1,4 +1,5 @@ import { + booleanAttribute, ChangeDetectionStrategy, Component, EventEmitter, @@ -10,7 +11,7 @@ import { TemplateRef } from '@angular/core'; -import { coerceBooleanProperty, FunctionProp, TinyDate } from 'ngx-tethys/util'; +import { FunctionProp, TinyDate } from 'ngx-tethys/util'; import { DateHelperService } from '../../date-helper.service'; import { RangePartType } from '../../inner-types'; import { isAfterMoreThanLessOneYear, isAfterMoreThanOneDecade, isAfterMoreThanOneMonth, isAfterMoreThanOneYear } from '../../picker.util'; @@ -72,8 +73,9 @@ export class InnerPopup implements OnChanges { @Input() panelMode: ThyPanelMode; - @Input() set showDateRangeInput(value: boolean) { - this._showDateRangeInput = coerceBooleanProperty(value); + @Input({ transform: booleanAttribute }) + set showDateRangeInput(value: boolean) { + this._showDateRangeInput = value; } get showDateRangeInput() { diff --git a/src/dialog/body/dialog-body.component.ts b/src/dialog/body/dialog-body.component.ts index cf926b5aa..dbbdaaf4b 100644 --- a/src/dialog/body/dialog-body.component.ts +++ b/src/dialog/body/dialog-body.component.ts @@ -1,6 +1,5 @@ -import { Component, Input, OnInit, HostBinding } from '@angular/core'; +import { Component, Input, OnInit, HostBinding, booleanAttribute } from '@angular/core'; import { ThyDialog } from '../dialog.service'; -import { coerceBooleanProperty } from 'ngx-tethys/util'; import { CdkScrollable } from '@angular/cdk/scrolling'; /** @@ -26,9 +25,9 @@ export class ThyDialogBody implements OnInit { * 清除间距 * @default false */ - @Input() - set thyClearPadding(value: string) { - this.thyClearPaddingClassName = coerceBooleanProperty(value); + @Input({ transform: booleanAttribute }) + set thyClearPadding(value: boolean) { + this.thyClearPaddingClassName = value; } constructor(private dialog: ThyDialog) {} diff --git a/src/dialog/footer/dialog-footer.component.ts b/src/dialog/footer/dialog-footer.component.ts index 920beeb31..a60035590 100644 --- a/src/dialog/footer/dialog-footer.component.ts +++ b/src/dialog/footer/dialog-footer.component.ts @@ -1,4 +1,3 @@ -import { coerceBooleanProperty } from 'ngx-tethys/util'; import { useHostRenderer } from '@tethys/cdk/dom'; import { Component, ContentChild, Inject, Input, OnInit, TemplateRef, booleanAttribute } from '@angular/core'; @@ -32,7 +31,7 @@ export class ThyDialogFooter implements OnInit { */ @Input({ transform: booleanAttribute }) set thyDivided(value: boolean) { - this.divided = coerceBooleanProperty(value); + this.divided = value; } /** diff --git a/src/drag-drop/drag-handle.directive.ts b/src/drag-drop/drag-handle.directive.ts index 6370decb5..c6ddc606d 100644 --- a/src/drag-drop/drag-handle.directive.ts +++ b/src/drag-drop/drag-handle.directive.ts @@ -1,5 +1,4 @@ import { Directive, ElementRef, Input, Optional, booleanAttribute } from '@angular/core'; -import { coerceBooleanProperty } from '@angular/cdk/coercion'; import { ThyDragDirective } from './drag.directive'; /** @@ -20,7 +19,7 @@ export class ThyDragHandleDirective { */ @Input({ alias: 'thyDisabled', transform: booleanAttribute }) set disabled(value: boolean) { - this._disabled = coerceBooleanProperty(value); + this._disabled = value; } get disabled(): boolean { return this._disabled; diff --git a/src/dropdown/dropdown-menu-item.directive.ts b/src/dropdown/dropdown-menu-item.directive.ts index 2b7f6d631..408128898 100644 --- a/src/dropdown/dropdown-menu-item.directive.ts +++ b/src/dropdown/dropdown-menu-item.directive.ts @@ -1,5 +1,4 @@ import { Directive, HostBinding, Input, HostListener, ElementRef, OnInit, booleanAttribute } from '@angular/core'; -import { coerceBooleanProperty } from 'ngx-tethys/util'; import { fromEvent } from 'rxjs'; import { debounceTime, shareReplay } from 'rxjs/operators'; import { useHostRenderer } from '@tethys/cdk/dom'; @@ -40,7 +39,7 @@ export class ThyDropdownMenuItemDirective implements OnInit { */ @Input({ transform: booleanAttribute }) set thyDisabled(value: boolean) { - this.disabled = coerceBooleanProperty(value); + this.disabled = value; } @HostListener('click', ['$event']) diff --git a/src/empty/empty.component.ts b/src/empty/empty.component.ts index 432a9e715..d3c87a8ae 100644 --- a/src/empty/empty.component.ts +++ b/src/empty/empty.component.ts @@ -1,5 +1,4 @@ import { ThyTranslate } from 'ngx-tethys/core'; -import { coerceBooleanProperty } from 'ngx-tethys/util'; import { useHostRenderer } from '@tethys/cdk/dom'; import { AfterViewInit, @@ -171,9 +170,8 @@ export class ThyEmpty implements OnInit, AfterViewInit, OnChanges { private _calculatePosition() { const sizeOptions = sizeMap[this.thySize || 'md']; - const topAuto = coerceBooleanProperty(this.thyTopAuto); let marginTop = null; - if (topAuto) { + if (this.thyTopAuto) { // 选择参考父容器居中 const containerElement = this.thyContainer ? this.thyContainer.nativeElement : this.elementRef.nativeElement.parentElement; // containerElement.height; diff --git a/src/form/form-group-label.directive.ts b/src/form/form-group-label.directive.ts index a5eea7bf0..a4c30c3ac 100644 --- a/src/form/form-group-label.directive.ts +++ b/src/form/form-group-label.directive.ts @@ -1,5 +1,4 @@ -import { Directive, HostBinding, Input } from '@angular/core'; -import { coerceBooleanProperty } from 'ngx-tethys/util'; +import { Directive, HostBinding, Input, booleanAttribute } from '@angular/core'; import { ThyTranslate } from 'ngx-tethys/core'; /** @@ -29,9 +28,9 @@ export class ThyFormGroupLabelDirective { } } - @Input() - set thyLabelRequired(value: string) { - this.labelRequired = coerceBooleanProperty(value); + @Input({ transform: booleanAttribute }) + set thyLabelRequired(value: boolean) { + this.labelRequired = value; } constructor(private thyTranslate: ThyTranslate) {} diff --git a/src/form/form-group.component.ts b/src/form/form-group.component.ts index 62377f91c..90d3762d9 100644 --- a/src/form/form-group.component.ts +++ b/src/form/form-group.component.ts @@ -2,7 +2,6 @@ import { NgClass, NgIf, NgTemplateOutlet } from '@angular/common'; import { ThyTranslate } from 'ngx-tethys/core'; import { ThyIcon } from 'ngx-tethys/icon'; import { ThyTooltipDirective } from 'ngx-tethys/tooltip'; -import { coerceBooleanProperty } from 'ngx-tethys/util'; import { ChangeDetectionStrategy, @@ -78,14 +77,14 @@ export class ThyFormGroup implements OnInit { /** * Label 是否显示必填项样式 */ - @Input() - set thyLabelRequired(value: string) { - this.labelRequired = coerceBooleanProperty(value); + @Input({ transform: booleanAttribute }) + set thyLabelRequired(value: boolean) { + this.labelRequired = value; } - @Input() - set thyLabelPaddingTopClear(value: string) { - this.labelPaddingTopClear = coerceBooleanProperty(value); + @Input({ transform: booleanAttribute }) + set thyLabelPaddingTopClear(value: boolean) { + this.labelPaddingTopClear = value; } /** @@ -135,7 +134,7 @@ export class ThyFormGroup implements OnInit { */ @Input({ transform: booleanAttribute }) set thyRowFill(value: boolean) { - this._rowFill = coerceBooleanProperty(value); + this._rowFill = value; } /** diff --git a/src/layout/header.component.ts b/src/layout/header.component.ts index 8c0f18f54..e86c10327 100644 --- a/src/layout/header.component.ts +++ b/src/layout/header.component.ts @@ -1,7 +1,6 @@ import { NgClass, NgIf, NgTemplateOutlet } from '@angular/common'; import { ChangeDetectionStrategy, Component, ContentChild, Directive, Input, TemplateRef, booleanAttribute } from '@angular/core'; import { ThyIcon } from 'ngx-tethys/icon'; -import { coerceBooleanProperty } from 'ngx-tethys/util'; /** * 头部布局指令 @@ -39,17 +38,17 @@ export class ThyHeaderDirective { * 底部是否有分割线 */ @Input({ transform: booleanAttribute }) - set thyDivided(value: string | boolean) { - this.divided = value as boolean; + set thyDivided(value: boolean) { + this.divided = value; } /** * 底部是否有分割线,已废弃,请使用 thyDivided * @deprecated please use thyDivided */ - @Input('thyHasBorder') - set thyHasBorder(value: string) { - this.divided = coerceBooleanProperty(value); + @Input({ transform: booleanAttribute }) + set thyHasBorder(value: boolean) { + this.divided = value; } } diff --git a/src/layout/sidebar.component.ts b/src/layout/sidebar.component.ts index 1aaecb86e..2ae50ec98 100644 --- a/src/layout/sidebar.component.ts +++ b/src/layout/sidebar.component.ts @@ -22,7 +22,6 @@ import { isMacPlatform } from '@tethys/cdk/is'; import { ThyIcon } from 'ngx-tethys/icon'; import { ThyResizableDirective, ThyResizeEvent, ThyResizeHandle } from 'ngx-tethys/resizable'; import { ThyTooltipDirective } from 'ngx-tethys/tooltip'; -import { coerceBooleanProperty } from 'ngx-tethys/util'; import { Subscription } from 'rxjs'; import { ThyLayoutDirective } from './layout.component'; @@ -87,18 +86,18 @@ export class ThySidebarDirective implements OnInit { * 是否和右侧 /左侧隔离,当为 true 时距右侧 /左侧会有 margin,同时边框会去掉 * @default false */ - @Input('thyIsolated') - set thyIsolated(value: string) { - this.sidebarIsolated = coerceBooleanProperty(value); + @Input({ transform: booleanAttribute }) + set thyIsolated(value: boolean) { + this.sidebarIsolated = value; } /** * sidebar 是否有分割线。当`thyDirection`值为`left`时,控制右侧是否有分割线;当`thyDirection`值为`right`时,控制左侧是否有分割线。 * @default true */ - @Input('thyDivided') - set thyDivided(value: string) { - this.isDivided = coerceBooleanProperty(value); + @Input({ transform: booleanAttribute }) + set thyDivided(value: boolean) { + this.isDivided = value; } /** @@ -106,8 +105,8 @@ export class ThySidebarDirective implements OnInit { * @deprecated please use thyDivided * @default true */ - @Input('thyHasBorderRight') - set thyHasBorderRight(value: string) { + @Input({ transform: booleanAttribute }) + set thyHasBorderRight(value: boolean) { this.thyDivided = value; } @@ -116,8 +115,8 @@ export class ThySidebarDirective implements OnInit { * @deprecated please use thyDivided * @default true */ - @Input('thyHasBorderLeft') - set thyHasBorderLeft(value: string) { + @Input({ transform: booleanAttribute }) + set thyHasBorderLeft(value: boolean) { this.thyDivided = value; } diff --git a/src/list/selection/selection-list.ts b/src/list/selection/selection-list.ts index 5eea144a4..cb5894a86 100644 --- a/src/list/selection/selection-list.ts +++ b/src/list/selection/selection-list.ts @@ -1,6 +1,6 @@ import { ScrollToService } from 'ngx-tethys/core'; import { IThyListOptionParentComponent, THY_LIST_OPTION_PARENT_COMPONENT, ThyListLayout, ThyListOption } from 'ngx-tethys/shared'; -import { coerceBooleanProperty, dom, helpers, keycodes } from 'ngx-tethys/util'; +import { dom, helpers, keycodes } from 'ngx-tethys/util'; import { Subscription } from 'rxjs'; import { startWith } from 'rxjs/operators'; import { useHostRenderer } from '@tethys/cdk/dom'; @@ -8,6 +8,7 @@ import { ActiveDescendantKeyManager } from '@angular/cdk/a11y'; import { SelectionModel } from '@angular/cdk/collections'; import { AfterContentInit, + booleanAttribute, ChangeDetectionStrategy, ChangeDetectorRef, Component, @@ -90,10 +91,10 @@ export class ThySelectionList implements OnInit, OnDestroy, AfterContentInit, IT * 改变 grid item 的选择模式,使其支持多选 * @default true */ - @Input() - set thyMultiple(value: any) { + @Input({ transform: booleanAttribute }) + set thyMultiple(value: boolean) { const previousValue = this.multiple; - this.multiple = coerceBooleanProperty(value); + this.multiple = value; if (previousValue !== this.multiple) { this._instanceSelectionModel(); } @@ -141,8 +142,8 @@ export class ThySelectionList implements OnInit, OnDestroy, AfterContentInit, IT /** * 是否自动激活第一项 */ - @Input() set thyAutoActiveFirstItem(value: boolean) { - this.autoActiveFirstItem = coerceBooleanProperty(value); + @Input({ transform: booleanAttribute }) set thyAutoActiveFirstItem(value: boolean) { + this.autoActiveFirstItem = value; } /** @@ -158,8 +159,8 @@ export class ThySelectionList implements OnInit, OnDestroy, AfterContentInit, IT /** * 是否按下空格切换聚焦选项 */ - @Input() set thySpaceKeyEnabled(value: boolean) { - this.spaceEnabled = coerceBooleanProperty(value); + @Input({ transform: booleanAttribute }) set thySpaceKeyEnabled(value: boolean) { + this.spaceEnabled = value; } /** diff --git a/src/loading/loading.component.ts b/src/loading/loading.component.ts index aa33965d8..32c791b0c 100644 --- a/src/loading/loading.component.ts +++ b/src/loading/loading.component.ts @@ -1,5 +1,4 @@ import { Component, Input, HostBinding, ChangeDetectionStrategy, ChangeDetectorRef, booleanAttribute } from '@angular/core'; -import { coerceBooleanProperty } from 'ngx-tethys/util'; import { NgIf } from '@angular/common'; /** @@ -26,8 +25,8 @@ export class ThyLoading { * @default false */ @Input({ transform: booleanAttribute }) - set thyDone(value: boolean | string) { - this.isDone = coerceBooleanProperty(value); + set thyDone(value: boolean) { + this.isDone = value; this.changeDetectorRef.markForCheck(); } @@ -44,8 +43,8 @@ export class ThyLoading { * 加载时是否启用嵌套遮罩模式,不传或传 false,没有遮罩层,加载完成出现内容 */ @Input({ transform: booleanAttribute }) - set thyIsMask(value: boolean | string) { - this.isMask = coerceBooleanProperty(value); + set thyIsMask(value: boolean) { + this.isMask = value; this.changeDetectorRef.markForCheck(); } diff --git a/src/nav/icon-nav/icon-nav-link.directive.ts b/src/nav/icon-nav/icon-nav-link.directive.ts index 6b46eaddc..8fd61a9cd 100644 --- a/src/nav/icon-nav/icon-nav-link.directive.ts +++ b/src/nav/icon-nav/icon-nav-link.directive.ts @@ -1,7 +1,6 @@ import { NgIf } from '@angular/common'; -import { Component, HostBinding, Input } from '@angular/core'; +import { Component, HostBinding, Input, booleanAttribute } from '@angular/core'; import { ThyIcon } from 'ngx-tethys/icon'; -import { coerceBooleanProperty } from 'ngx-tethys/util'; /** * @private @@ -25,8 +24,8 @@ export class ThyIconNavLink { this.icon = icon; } - @Input() - set thyIconNavLinkActive(active: string) { - this.navLinkActive = coerceBooleanProperty(active); + @Input({ transform: booleanAttribute }) + set thyIconNavLinkActive(active: boolean) { + this.navLinkActive = active; } } diff --git a/src/progress/progress.component.ts b/src/progress/progress.component.ts index eefddd8f8..d40923aa5 100644 --- a/src/progress/progress.component.ts +++ b/src/progress/progress.component.ts @@ -1,4 +1,4 @@ -import { helpers, isNumber } from 'ngx-tethys/util'; +import { isNumber } from 'ngx-tethys/util'; import { ChangeDetectionStrategy, @@ -103,7 +103,7 @@ export class ThyProgress implements ThyParentProgress, OnInit, OnChanges { */ @Input({ transform: numberAttribute }) set thyMax(max: number) { - this.settedMax = helpers.coerceNumberValue(max); + this.settedMax = max; this.calculateMax(); } diff --git a/src/property-operation/property-operation.component.ts b/src/property-operation/property-operation.component.ts index 4c45243c6..89de61b68 100644 --- a/src/property-operation/property-operation.component.ts +++ b/src/property-operation/property-operation.component.ts @@ -16,7 +16,7 @@ import { } from '@angular/core'; import { useHostRenderer } from '@tethys/cdk/dom'; import { ThyTranslate } from 'ngx-tethys/core'; -import { htmlElementIsEmpty, coerceBooleanProperty } from 'ngx-tethys/util'; +import { htmlElementIsEmpty } from 'ngx-tethys/util'; import { fromEvent, Subject } from 'rxjs'; import { takeUntil } from 'rxjs/operators'; import { ThyIcon } from 'ngx-tethys/icon'; @@ -111,13 +111,13 @@ export class ThyPropertyOperation implements OnInit, AfterContentInit, OnDestroy */ @Input({ transform: booleanAttribute }) set thyShowClose(value: boolean) { - this.showClose = coerceBooleanProperty(value); + this.showClose = value; } // 支持有值时,label不显示 @Input({ transform: booleanAttribute }) set thyLabelHasValue(value: boolean) { - this.labelHideWhenHasValue = !coerceBooleanProperty(value); + this.labelHideWhenHasValue = !value; } /** @@ -126,7 +126,7 @@ export class ThyPropertyOperation implements OnInit, AfterContentInit, OnDestroy */ @Input({ transform: booleanAttribute }) set thyLabelHideWhenHasValue(value: boolean) { - this.labelHideWhenHasValue = coerceBooleanProperty(value); + this.labelHideWhenHasValue = value; } /** diff --git a/src/rate/rate.component.ts b/src/rate/rate.component.ts index 8bc7c5c24..03bc3e138 100644 --- a/src/rate/rate.component.ts +++ b/src/rate/rate.component.ts @@ -1,5 +1,5 @@ import { TabIndexDisabledControlValueAccessorMixin } from 'ngx-tethys/core'; -import { coerceBooleanProperty, helpers } from 'ngx-tethys/util'; +import { helpers } from 'ngx-tethys/util'; import { NgClass, NgFor } from '@angular/common'; import { @@ -78,16 +78,16 @@ export class ThyRate extends TabIndexDisabledControlValueAccessorMixin implement * 是否只读 * @default false */ - @Input() + @Input({ transform: booleanAttribute }) + override set thyDisabled(value: boolean) { + this.disabled = value; + } override get thyDisabled(): boolean { return this.disabled; } - override set thyDisabled(value: boolean) { - this.disabled = coerceBooleanProperty(value); - } - disabled = false; + /** * 是否允许半选 * @default false diff --git a/src/select/custom-select/custom-select.component.ts b/src/select/custom-select/custom-select.component.ts index db045b385..a77e6e39a 100644 --- a/src/select/custom-select/custom-select.component.ts +++ b/src/select/custom-select/custom-select.component.ts @@ -43,7 +43,7 @@ import { defer, merge, Observable, Subject, Subscription, timer } from 'rxjs'; import { distinctUntilChanged, filter, map, startWith, switchMap, take, takeUntil } from 'rxjs/operators'; import { ActiveDescendantKeyManager } from '@angular/cdk/a11y'; -import { coerceBooleanProperty, coerceElement } from '@angular/cdk/coercion'; +import { coerceElement } from '@angular/cdk/coercion'; import { SelectionModel } from '@angular/cdk/collections'; import { CdkConnectedOverlay, CdkOverlayOrigin, ConnectionPositionPair, Overlay, ScrollStrategy } from '@angular/cdk/overlay'; import { isPlatformBrowser, NgClass, NgFor, NgIf, NgTemplateOutlet } from '@angular/common'; @@ -341,12 +341,12 @@ export class ThySelect * @default false */ @Input({ transform: booleanAttribute }) + set thyDisabled(value: boolean) { + this.disabled = value; + } get thyDisabled(): boolean { return this.disabled; } - set thyDisabled(value: boolean) { - this.disabled = coerceBooleanProperty(value); - } /** * 排序比较函数 diff --git a/src/shared/base-form-check.component.ts b/src/shared/base-form-check.component.ts index 3fbd95b76..7a09ed263 100644 --- a/src/shared/base-form-check.component.ts +++ b/src/shared/base-form-check.component.ts @@ -1,6 +1,5 @@ import { ControlValueAccessor } from '@angular/forms'; import { HostBinding, Input, ChangeDetectorRef, Directive, booleanAttribute } from '@angular/core'; -import { coerceBooleanProperty } from 'ngx-tethys/util'; import { ThyTranslate, TabIndexDisabledControlValueAccessorMixin } from 'ngx-tethys/core'; const noop = () => {}; @@ -37,7 +36,7 @@ export class ThyFormCheckBaseComponent extends TabIndexDisabledControlValueAcces */ @Input({ transform: booleanAttribute }) set thyInline(value: boolean) { - this._isFormCheckInline = coerceBooleanProperty(value); + this._isFormCheckInline = value; } /** @@ -68,7 +67,7 @@ export class ThyFormCheckBaseComponent extends TabIndexDisabledControlValueAcces */ @Input({ transform: booleanAttribute }) override set thyDisabled(value: boolean) { - this.disabled = coerceBooleanProperty(value); + this.disabled = value; this.setDisabledState(this.disabled); } diff --git a/src/shared/directives/thy-autofocus.directive.ts b/src/shared/directives/thy-autofocus.directive.ts index 0920d8ef8..326f1eaff 100644 --- a/src/shared/directives/thy-autofocus.directive.ts +++ b/src/shared/directives/thy-autofocus.directive.ts @@ -1,7 +1,5 @@ import { Directive, Input, ElementRef, NgZone, booleanAttribute } from '@angular/core'; import { reqAnimFrame } from 'ngx-tethys/core'; -import { coerceBooleanProperty } from 'ngx-tethys/util'; - /** * 自动聚焦指令 * @name input[thyAutofocus],textarea[thyAutofocus] @@ -18,9 +16,9 @@ export class ThyAutofocusDirective { * 是否自动聚焦 * @default false */ - @Input() - set thyAutofocus(value: boolean | string) { - if (coerceBooleanProperty(value) !== false) { + @Input({ transform: booleanAttribute }) + set thyAutofocus(value: boolean) { + if (value) { // Note: this is being run outside of the Angular zone because `element.focus()` doesn't require // running change detection. this.ngZone.runOutsideAngular(() => @@ -44,7 +42,7 @@ export class ThyAutofocusDirective { */ @Input({ transform: booleanAttribute }) set thyAutoSelect(value: boolean) { - this._autoSelect = coerceBooleanProperty(value); + this._autoSelect = value; } constructor(private elementRef: ElementRef, private ngZone: NgZone) {} diff --git a/src/shared/directives/thy-scroll.directive.ts b/src/shared/directives/thy-scroll.directive.ts index cbbeeb494..cca1e23b5 100644 --- a/src/shared/directives/thy-scroll.directive.ts +++ b/src/shared/directives/thy-scroll.directive.ts @@ -1,7 +1,6 @@ import { Directive, ElementRef, OnInit, NgZone, OnDestroy, Output, EventEmitter, Input, booleanAttribute } from '@angular/core'; import { Subject, Observable, Observer, fromEvent, Subscription } from 'rxjs'; import { takeUntil } from 'rxjs/operators'; -import { coerceBooleanProperty } from 'ngx-tethys/util'; import { normalizePassiveListenerOptions } from '@angular/cdk/platform'; const passiveEventListenerOptions = normalizePassiveListenerOptions({ passive: true }); @@ -29,7 +28,7 @@ export class ThyScrollDirective implements OnInit, OnDestroy { @Input({ transform: booleanAttribute }) set thyEnable(value: boolean) { - this._enable = coerceBooleanProperty(value); + this._enable = value; if (this._initialled) { if (this._enable && this._subscription === null) { this._subscription = this._elementScrolled.subscribe(() => this.thyOnScrolled.emit(this.elementRef)); diff --git a/src/shared/option/list-option/list-option.component.ts b/src/shared/option/list-option/list-option.component.ts index 836c7200f..570d1c041 100644 --- a/src/shared/option/list-option/list-option.component.ts +++ b/src/shared/option/list-option/list-option.component.ts @@ -10,7 +10,6 @@ import { booleanAttribute } from '@angular/core'; import { Highlightable } from '@angular/cdk/a11y'; -import { coerceBooleanProperty } from 'ngx-tethys/util'; import { IThyListOptionParentComponent, THY_LIST_OPTION_PARENT_COMPONENT } from '../option.token'; import { ThyIcon } from 'ngx-tethys/icon'; import { NgIf } from '@angular/common'; @@ -50,7 +49,7 @@ export class ThyListOption implements Highlightable { @Input({ transform: booleanAttribute }) set thyDisabled(value: boolean) { - this.disabled = coerceBooleanProperty(value); + this.disabled = value; } @HostBinding(`class.disabled`) disabled?: boolean; diff --git a/src/slide/slide-body/slide-body-section.component.ts b/src/slide/slide-body/slide-body-section.component.ts index b5073b7aa..559f968b0 100644 --- a/src/slide/slide-body/slide-body-section.component.ts +++ b/src/slide/slide-body/slide-body-section.component.ts @@ -1,5 +1,4 @@ -import { Component, Input, OnInit, HostBinding } from '@angular/core'; -import { coerceBooleanProperty } from 'ngx-tethys/util'; +import { Component, Input, OnInit, HostBinding, booleanAttribute } from '@angular/core'; /** * @name thy-slide-body-section @@ -19,9 +18,9 @@ export class ThySlideBodySection implements OnInit { * 是否有分割线 * @default false */ - @Input() - set thyDividerBorder(value: string | boolean) { - this.hasDivider = coerceBooleanProperty(value); + @Input({ transform: booleanAttribute }) + set thyDividerBorder(value: boolean) { + this.hasDivider = value; } ngOnInit() {} diff --git a/src/slider/slider.component.ts b/src/slider/slider.component.ts index 03534773c..29251c268 100644 --- a/src/slider/slider.component.ts +++ b/src/slider/slider.component.ts @@ -19,7 +19,7 @@ import { } from '@angular/core'; import { ControlValueAccessor, NG_VALUE_ACCESSOR } from '@angular/forms'; import { Observable, Subscription, fromEvent } from 'rxjs'; -import { clamp, coerceBooleanProperty } from 'ngx-tethys/util'; +import { clamp } from 'ngx-tethys/util'; import { tap, pluck, map, distinctUntilChanged, takeUntil } from 'rxjs/operators'; import { TabIndexDisabledControlValueAccessorMixin } from 'ngx-tethys/core'; import { useHostRenderer } from '@tethys/cdk/dom'; @@ -66,14 +66,13 @@ export class ThySlider */ @HostBinding('class.slider-disabled') @Input({ transform: booleanAttribute }) + override set thyDisabled(value: boolean) { + this.disabled = value; + } override get thyDisabled(): boolean { return this.disabled; } - override set thyDisabled(value: boolean) { - this.disabled = coerceBooleanProperty(value); - } - disabled = false; @HostBinding('class.thy-slider') _thySlider = true; diff --git a/src/switch/switch.component.ts b/src/switch/switch.component.ts index 9e6b42bf2..64abcc933 100644 --- a/src/switch/switch.component.ts +++ b/src/switch/switch.component.ts @@ -1,5 +1,3 @@ -import { coerceBooleanProperty } from 'ngx-tethys/util'; - import { NgClass, NgIf } from '@angular/common'; import { booleanAttribute, @@ -111,15 +109,14 @@ export class ThySwitch extends TabIndexDisabledControlValueAccessorMixin impleme /** * 是否属于禁用状态 */ - @Input() - override get thyDisabled(): boolean { - return this.disabled; - } - + @Input({ transform: booleanAttribute }) override set thyDisabled(value: boolean) { - this.disabled = coerceBooleanProperty(value); + this.disabled = value; this.setClassNames(); } + override get thyDisabled(): boolean { + return this.disabled; + } /** * 是否加载中 diff --git a/src/table/table.component.ts b/src/table/table.component.ts index 4197d5151..c2ff9c415 100644 --- a/src/table/table.component.ts +++ b/src/table/table.component.ts @@ -1,6 +1,6 @@ import { Constructor, InputCssPixel, MixinBase, mixinUnsubscribe, ThyUnsubscribe, UpdateHostClassService } from 'ngx-tethys/core'; import { Dictionary, SafeAny } from 'ngx-tethys/types'; -import { coerceBooleanProperty, get, helpers, isString, keyBy, set } from 'ngx-tethys/util'; +import { get, helpers, isString, keyBy, set } from 'ngx-tethys/util'; import { EMPTY, fromEvent, merge, Observable, of } from 'rxjs'; import { delay, startWith, switchMap, takeUntil } from 'rxjs/operators'; @@ -379,7 +379,7 @@ export class ThyTable extends _MixinBase implements OnInit, OnChanges, AfterView */ @Input({ transform: booleanAttribute }) set thyDraggable(value: boolean) { - this.draggable = coerceBooleanProperty(value); + this.draggable = value; if ((typeof ngDevMode === 'undefined' || ngDevMode) && this.draggable && this.mode === 'tree') { throw new Error('Tree mode sorting is not supported'); } diff --git a/src/time-picker/time-picker.component.ts b/src/time-picker/time-picker.component.ts index 7a145fe62..cdf830a05 100644 --- a/src/time-picker/time-picker.component.ts +++ b/src/time-picker/time-picker.component.ts @@ -16,7 +16,7 @@ import { import { ControlValueAccessor, NG_VALUE_ACCESSOR, FormsModule } from '@angular/forms'; import { isValid } from 'date-fns'; import { getFlexiblePositions, ThyPlacement } from 'ngx-tethys/core'; -import { TinyDate, coerceBooleanProperty } from 'ngx-tethys/util'; +import { TinyDate } from 'ngx-tethys/util'; import { ThyTimePanel } from './time-picker-panel.component'; import { ThyIcon } from 'ngx-tethys/icon'; import { NgTemplateOutlet, NgIf, NgClass } from '@angular/common'; @@ -135,7 +135,7 @@ export class ThyTimePicker implements OnInit, AfterViewInit, ControlValueAccesso * @default false */ @Input({ transform: booleanAttribute }) set thyDisabled(value: boolean) { - this.disabled = coerceBooleanProperty(value); + this.disabled = value; } get thyDisabled(): boolean { diff --git a/src/tooltip/tooltip.directive.ts b/src/tooltip/tooltip.directive.ts index 9dafa30bb..f825968b1 100644 --- a/src/tooltip/tooltip.directive.ts +++ b/src/tooltip/tooltip.directive.ts @@ -13,7 +13,7 @@ import { } from '@angular/core'; import { ThyOverlayDirectiveBase, ThyOverlayTrigger, ThyPlacement } from 'ngx-tethys/core'; import { SafeAny } from 'ngx-tethys/types'; -import { coerceBooleanProperty, isString } from 'ngx-tethys/util'; +import { isString } from 'ngx-tethys/util'; import { ThyTooltipContent } from './interface'; import { ThyTooltipRef } from './tooltip-ref'; import { ThyTooltipService } from './tooltip.service'; @@ -100,7 +100,7 @@ export class ThyTooltipDirective extends ThyOverlayDirectiveBase implements OnIn */ @Input({ alias: 'thyTooltipDisabled', transform: booleanAttribute }) set thyTooltipDisabled(value: boolean) { - this.disabled = coerceBooleanProperty(value); + this.disabled = value; // If tooltip is disabled, hide immediately. if (this.disabled) { this.hide(0); diff --git a/src/upload/file-select-base.ts b/src/upload/file-select-base.ts index 6b62fb3b8..ab4c9870b 100644 --- a/src/upload/file-select-base.ts +++ b/src/upload/file-select-base.ts @@ -1,5 +1,5 @@ -import { coerceNumberValue, isNumber } from 'ngx-tethys/util'; -import { Directive, ElementRef, EventEmitter, Inject, Input, NgZone } from '@angular/core'; +import { isNumber } from 'ngx-tethys/util'; +import { Directive, ElementRef, EventEmitter, Inject, Input, NgZone, numberAttribute } from '@angular/core'; import { ThyFileSelectEvent, ThySizeExceedsHandler } from './types'; import { THY_UPLOAD_DEFAULT_OPTIONS, ThyUploadConfig } from './upload.config'; import { mimeTypeConvert } from './util'; @@ -13,8 +13,9 @@ export class FileSelectBaseDirective { sizeThreshold: number; sizeExceedsHandler: ThySizeExceedsHandler; - @Input() set thySizeThreshold(value: number) { - const sizeThreshold = coerceNumberValue(value); + @Input({ transform: numberAttribute }) + set thySizeThreshold(value: number) { + const sizeThreshold = value; if (isNumber(sizeThreshold)) { this.sizeThreshold = sizeThreshold; } diff --git a/src/upload/file-select.component.ts b/src/upload/file-select.component.ts index 780448355..f5a75ac99 100644 --- a/src/upload/file-select.component.ts +++ b/src/upload/file-select.component.ts @@ -1,4 +1,3 @@ -import { coerceBooleanProperty } from 'ngx-tethys/util'; import { fromEvent, Subject } from 'rxjs'; import { takeUntil } from 'rxjs/operators'; @@ -48,7 +47,7 @@ export class ThyFileSelect extends FileSelectBaseDirective implements OnDestroy */ @Input({ transform: booleanAttribute }) set thyMultiple(value: boolean) { - this.multiple = coerceBooleanProperty(value); + this.multiple = value; if (this.multiple) { this.fileInput.nativeElement.setAttribute('multiple', ''); } else { @@ -58,7 +57,7 @@ export class ThyFileSelect extends FileSelectBaseDirective implements OnDestroy @Input({ transform: booleanAttribute }) set thyAcceptFolder(value: boolean) { - this.acceptFolder = coerceBooleanProperty(value); + this.acceptFolder = value; if (this.acceptFolder) { this.fileInput.nativeElement.setAttribute('webkitdirectory', ''); } else { diff --git a/src/vote/vote.component.ts b/src/vote/vote.component.ts index a646b032c..342accf05 100644 --- a/src/vote/vote.component.ts +++ b/src/vote/vote.component.ts @@ -1,4 +1,3 @@ -import { coerceBooleanProperty } from 'ngx-tethys/util'; import { useHostRenderer } from '@tethys/cdk/dom'; import { Component, ContentChild, HostBinding, Input, OnInit, TemplateRef, booleanAttribute } from '@angular/core'; @@ -34,8 +33,6 @@ export class ThyVote implements OnInit { _initialized = false; - _isRound = false; - private hostRenderer = useHostRenderer(); @HostBinding(`class.thy-vote`) class = true; @@ -70,10 +67,7 @@ export class ThyVote implements OnInit { * 是否是偏圆型 * @default false */ - @Input({ transform: booleanAttribute }) - set thyRound(value: boolean) { - this._isRound = coerceBooleanProperty(value); - } + @Input({ transform: booleanAttribute }) thyRound: boolean; /** * 布局: horizontal | vertical @@ -105,7 +99,7 @@ export class ThyVote implements OnInit { */ @Input({ transform: booleanAttribute }) set thyHasVoted(value: boolean) { - this._hasVoted = coerceBooleanProperty(value); + this._hasVoted = value; if (this._initialized) { this._setClassesByType(); } @@ -141,7 +135,7 @@ export class ThyVote implements OnInit { if (!this._size) { this._size = 'default'; } - if (this._isRound) { + if (this.thyRound) { classNames.push('thy-vote-round'); } classNames.push(`thy-vote-${this._type}`);