Skip to content

Commit

Permalink
refactor(all): use the transform attribute of @input() instead of @In…
Browse files Browse the repository at this point in the history
…putBoolean() and @InputNumber()
  • Loading branch information
minlovehua committed Apr 2, 2024
1 parent f744f67 commit df715d6
Show file tree
Hide file tree
Showing 39 changed files with 134 additions and 177 deletions.
11 changes: 1 addition & 10 deletions src/autocomplete/autocomplete.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -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 值
Expand Down
6 changes: 3 additions & 3 deletions src/avatar/avatar.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -120,7 +120,7 @@ export class ThyAvatar implements OnInit {
*/
@Input({ transform: booleanAttribute })
set thyShowRemove(value: boolean) {
this._showRemove = coerceBooleanProperty(value);
this._showRemove = value;
}

/**
Expand All @@ -129,7 +129,7 @@ export class ThyAvatar implements OnInit {
*/
@Input({ transform: booleanAttribute })
set thyRemovable(value: boolean) {
this._showRemove = coerceBooleanProperty(value);
this._showRemove = value;
}

/**
Expand Down
3 changes: 1 addition & 2 deletions src/badge/badge.component.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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();
}
Expand Down
5 changes: 2 additions & 3 deletions src/button/button-icon.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -81,7 +80,7 @@ export class ThyButtonIcon implements OnInit {
*/
@Input({ transform: booleanAttribute })
set thyLight(value: boolean) {
this._isLighted = coerceBooleanProperty(value);
this._isLighted = value;
}

/**
Expand All @@ -90,7 +89,7 @@ export class ThyButtonIcon implements OnInit {
*/
@Input({ transform: booleanAttribute })
set thyActive(value: boolean) {
this._isActive = coerceBooleanProperty(value);
this._isActive = value;
}

/**
Expand Down
10 changes: 4 additions & 6 deletions src/card/content.component.ts
Original file line number Diff line number Diff line change
@@ -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';

/**
* 卡片内容组件
Expand All @@ -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;
Expand Down
12 changes: 5 additions & 7 deletions src/cascader/cascader.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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;

/**
Expand Down
3 changes: 1 addition & 2 deletions src/checkbox/checkbox.component.ts
Original file line number Diff line number Diff line change
@@ -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';

Expand Down Expand Up @@ -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) {
Expand Down
10 changes: 4 additions & 6 deletions src/color-picker/color-picker.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<HTMLElement>, platform: Platform, focusMonitor: FocusMonitor) {
Expand Down Expand Up @@ -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 = () => {};
Expand Down
8 changes: 4 additions & 4 deletions src/date-picker/abstract-picker.component.ts
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down Expand Up @@ -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;

Expand Down
8 changes: 5 additions & 3 deletions src/date-picker/lib/popups/inner-popup.component.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {
booleanAttribute,
ChangeDetectionStrategy,
Component,
EventEmitter,
Expand All @@ -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';
Expand Down Expand Up @@ -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() {
Expand Down
9 changes: 4 additions & 5 deletions src/dialog/body/dialog-body.component.ts
Original file line number Diff line number Diff line change
@@ -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';

/**
Expand All @@ -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) {}
Expand Down
3 changes: 1 addition & 2 deletions src/dialog/footer/dialog-footer.component.ts
Original file line number Diff line number Diff line change
@@ -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';

Expand Down Expand Up @@ -32,7 +31,7 @@ export class ThyDialogFooter implements OnInit {
*/
@Input({ transform: booleanAttribute })
set thyDivided(value: boolean) {
this.divided = coerceBooleanProperty(value);
this.divided = value;
}

/**
Expand Down
3 changes: 1 addition & 2 deletions src/drag-drop/drag-handle.directive.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { Directive, ElementRef, Input, Optional, booleanAttribute } from '@angular/core';
import { coerceBooleanProperty } from '@angular/cdk/coercion';
import { ThyDragDirective } from './drag.directive';

/**
Expand All @@ -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;
Expand Down
3 changes: 1 addition & 2 deletions src/dropdown/dropdown-menu-item.directive.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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'])
Expand Down
4 changes: 1 addition & 3 deletions src/empty/empty.component.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { ThyTranslate } from 'ngx-tethys/core';
import { coerceBooleanProperty } from 'ngx-tethys/util';
import { useHostRenderer } from '@tethys/cdk/dom';
import {
AfterViewInit,
Expand Down Expand Up @@ -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;
Expand Down
9 changes: 4 additions & 5 deletions src/form/form-group-label.directive.ts
Original file line number Diff line number Diff line change
@@ -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';

/**
Expand Down Expand Up @@ -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) {}
Expand Down
15 changes: 7 additions & 8 deletions src/form/form-group.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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;
}

/**
Expand Down Expand Up @@ -135,7 +134,7 @@ export class ThyFormGroup implements OnInit {
*/
@Input({ transform: booleanAttribute })
set thyRowFill(value: boolean) {
this._rowFill = coerceBooleanProperty(value);
this._rowFill = value;
}

/**
Expand Down
Loading

0 comments on commit df715d6

Please sign in to comment.