• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

atinc / ngx-tethys / 68ef226c-f83e-44c1-b8ed-e420a83c5d84

28 May 2025 10:31AM UTC coverage: 10.352% (-80.0%) from 90.316%
68ef226c-f83e-44c1-b8ed-e420a83c5d84

Pull #3460

circleci

pubuzhixing8
chore: xxx
Pull Request #3460: refactor(icon): migrate signal input #TINFR-1476

132 of 6823 branches covered (1.93%)

Branch coverage included in aggregate %.

10 of 14 new or added lines in 1 file covered. (71.43%)

11648 existing lines in 344 files now uncovered.

2078 of 14525 relevant lines covered (14.31%)

6.69 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

8.82
/src/switch/switch.component.ts
1
import { NgClass } from '@angular/common';
2
import {
3
    ChangeDetectionStrategy,
4
    ChangeDetectorRef,
5
    Component,
6
    ElementRef,
7
    forwardRef,
8
    inject,
9
    viewChild,
1✔
10
    input,
1✔
11
    computed,
12
    signal,
13
    output,
14
    effect
15
} from '@angular/core';
16
import { ControlValueAccessor, NG_VALUE_ACCESSOR } from '@angular/forms';
1✔
17
import { TabIndexDisabledControlValueAccessorMixin } from 'ngx-tethys/core';
UNCOV
18
import { coerceBooleanProperty } from 'ngx-tethys/util';
×
19

20
const supportedTypes: string[] = ['primary', 'info', 'warning', 'danger'];
UNCOV
21

×
UNCOV
22
const supportedSizes: string[] = ['', 'sm', 'xs'];
×
UNCOV
23

×
UNCOV
24
/**
×
UNCOV
25
 * 开关组件
×
UNCOV
26
 * @name thy-switch
×
UNCOV
27
 * @order 10
×
UNCOV
28
 */
×
UNCOV
29
@Component({
×
UNCOV
30
    selector: 'thy-switch',
×
UNCOV
31
    templateUrl: './switch.component.html',
×
32
    changeDetection: ChangeDetectionStrategy.OnPush,
33
    providers: [{ provide: NG_VALUE_ACCESSOR, useExisting: forwardRef(() => ThySwitch), multi: true }],
UNCOV
34
    imports: [NgClass],
×
35
    host: { class: 'thy-switch', '[class.thy-switch-xs]': 'size() === "xs"', '[class.thy-switch-sm]': 'size() === "sm"' }
36
})
UNCOV
37
export class ThySwitch extends TabIndexDisabledControlValueAccessorMixin implements ControlValueAccessor {
×
UNCOV
38
    /**
×
39
     * 类型,目前分为: 'primary' |'info' | 'warning' | 'danger'
×
40
     */
41
    readonly thyType = input<string>('primary');
UNCOV
42

×
43
    /**
44
     * 大小
UNCOV
45
     * @type xs | sm | md
×
UNCOV
46
     * @default md
×
UNCOV
47
     */
×
UNCOV
48
    readonly thySize = input<string>('');
×
49

UNCOV
50
    /**
×
UNCOV
51
     * 是否属于禁用状态
×
UNCOV
52
     */
×
53
    readonly inputDisabled = input(false, { transform: coerceBooleanProperty, alias: `thyDisabled` });
×
54

55
    /**
UNCOV
56
     * 是否加载中
×
57
     */
UNCOV
58
    readonly thyLoading = input(false, { transform: coerceBooleanProperty });
×
UNCOV
59

×
UNCOV
60
    /**
×
UNCOV
61
     * 数据变化的回调事件,即将被弃用,请使用 ngModelChange
×
UNCOV
62
     * @deprecated
×
UNCOV
63
     */
×
64
    thyChange = output<Event>();
65

66
    model = signal<boolean>(false);
67

68
    disabled = signal(false);
69

70
    get thyDisabled() {
UNCOV
71
        return this.disabled() as boolean;
×
UNCOV
72
    }
×
UNCOV
73

×
UNCOV
74
    readonly type = computed(() => {
×
UNCOV
75
        if (!supportedTypes.includes(this.thyType())) {
×
UNCOV
76
            return 'primary';
×
77
        } else {
78
            return this.thyType();
79
        }
UNCOV
80
    });
×
UNCOV
81

×
82
    readonly size = computed(() => {
83
        if (!supportedSizes.includes(this.thySize())) {
UNCOV
84
            return '';
×
85
        } else {
86
            return this.thySize();
UNCOV
87
        }
×
88
    });
89

UNCOV
90
    readonly classNames = computed(() => {
×
91
        const classList = [`thy-switch-${this.type()}`];
92
        if (this.size()) {
UNCOV
93
            classList.push(`thy-switch-${this.size()}`);
×
UNCOV
94
        }
×
UNCOV
95
        if (this.disabled() || this.thyLoading()) {
×
UNCOV
96
            classList.push(`thy-switch-disabled`);
×
97
            if (this.model()) {
98
                classList.push(`thy-switch-disabled-true`);
1✔
99
            }
1✔
100
        }
101
        return classList;
102
    });
103

104
    readonly loadingCircle = computed(() => {
105
        const svgSize: Record<string, number> = { xs: 12, sm: 16 };
106
        const circleSize = svgSize[this.size()] ?? 20;
107
        const centerPoint = circleSize / 2;
108
        const r = circleSize / 4;
1✔
109
        return {
110
            viewBox: `0 0 ${circleSize} ${circleSize}`,
111
            cx: centerPoint,
112
            cy: centerPoint,
UNCOV
113
            r: r,
×
114
            dasharray: `${2 * Math.PI * r * 0.75} ${2 * Math.PI * r * 0.25}`
115
        };
116
    });
117

118
    onModelChange: Function = () => {};
119

120
    onModelTouched: Function = () => {};
121

122
    readonly switchElementRef = viewChild<string, ElementRef<HTMLElement>>('switch', { read: ElementRef<HTMLElement> });
123

124
    private cdr = inject(ChangeDetectorRef);
125

126
    constructor() {
127
        super();
128

129
        effect(() => {
130
            this.disabled.set(this.inputDisabled());
131
        });
132
    }
133

134
    writeValue(value: boolean) {
135
        this.model.set(value);
136
        this.cdr.markForCheck();
137
    }
138

139
    registerOnChange(fn: Function): void {
140
        this.onModelChange = fn;
141
    }
142

143
    registerOnTouched(fn: Function): void {
144
        this.onModelTouched = fn;
145
    }
146

147
    setDisabledState(isDisabled: boolean): void {
148
        this.disabled.set(isDisabled);
149
    }
150

151
    toggle(event: Event) {
152
        this.model.set(!this.model());
153
        this.onModelChange(this.model());
154
        this.onModelTouched();
155
        this.thyChange?.emit(event);
156
    }
157
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc