• 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

4.44
/src/badge/badge.component.ts
1
import { isTextColor } from 'ngx-tethys/core';
2

3
import { ChangeDetectionStrategy, Component, ElementRef, OnInit, Signal, computed, inject, input, numberAttribute } from '@angular/core';
4

5
import { coerceBooleanProperty, isUndefined } from 'ngx-tethys/util';
6

7
export type ThyBadgeSize = 'md' | 'sm' | 'lg';
8

9
/**
10
 * 徽标组件,支持组件`thy-badge`和`thyBadge`指令两种使用方式
11
 * @name thy-badge,[thyBadge]
1✔
12
 */
UNCOV
13
@Component({
×
UNCOV
14
    selector: 'thy-badge,[thyBadge]',
×
UNCOV
15
    templateUrl: './badge.component.html',
×
UNCOV
16
    changeDetection: ChangeDetectionStrategy.OnPush,
×
UNCOV
17
    host: {
×
18
        class: 'thy-badge-container',
UNCOV
19
        '[class.thy-badge-wrapper]': 'isWrapper'
×
20
    },
UNCOV
21
    imports: []
×
UNCOV
22
})
×
UNCOV
23
export class ThyBadge implements OnInit {
×
UNCOV
24
    private elementRef = inject(ElementRef);
×
UNCOV
25

×
26
    private nativeElement: any;
UNCOV
27

×
UNCOV
28
    readonly displayContent: Signal<string> = computed(() => {
×
29
        let content = this.value() as string;
UNCOV
30
        if (this.value() && !isUndefined(this.thyMaxCount()) && (this.value() as number) > this.thyMaxCount()) {
×
UNCOV
31
            content = `${this.thyMaxCount()}+`;
×
32
        }
33
        return content;
UNCOV
34
    });
×
35

UNCOV
36
    readonly badgeClassName: Signal<string> = computed(() => {
×
UNCOV
37
        const classes: string[] = [];
×
UNCOV
38
        classes.push(`thy-badge-${this.thyType()}`);
×
39
        if (this.thySize()) {
UNCOV
40
            classes.push(`thy-badge-${this.thySize()}`);
×
UNCOV
41
        }
×
UNCOV
42
        if (this.thyIsDot()) {
×
43
            classes.push(`thy-badge-dot`);
UNCOV
44
        } else if (this.thyIsHollow()) {
×
45
            classes.push(`thy-badge-hollow`);
46
        } else {
UNCOV
47
            classes.push(`thy-badge-count`);
×
UNCOV
48
        }
×
UNCOV
49
        const builtInTextColorClass = isTextColor(this.thyTextColor()) ? `text-${this.thyTextColor()}` : null;
×
50
        if (builtInTextColorClass) {
UNCOV
51
            classes.push(builtInTextColorClass);
×
UNCOV
52
        }
×
53
        const builtInBackgroundColorClass = isTextColor(this.thyBackgroundColor()) ? `bg-${this.thyBackgroundColor()}` : null;
UNCOV
54
        if (builtInBackgroundColorClass) {
×
UNCOV
55
            classes.push(builtInBackgroundColorClass);
×
56
        }
UNCOV
57
        return classes.join(' ');
×
UNCOV
58
    });
×
59

UNCOV
60
    // 是否包裹在元素上
×
UNCOV
61
    protected isWrapper = false;
×
62

UNCOV
63
    public readonly isShowBadge: Signal<boolean> = computed(() => {
×
UNCOV
64
        return !(!this.value() && !this.thyKeepShow() && !this.thyIsDot() && !this.thyIsHollow());
×
UNCOV
65
    });
×
UNCOV
66

×
UNCOV
67
    private readonly value: Signal<number | string> = computed(() => {
×
UNCOV
68
        return this.thyContent() || this.thyContext() || this.thyCount();
×
UNCOV
69
    });
×
UNCOV
70

×
UNCOV
71
    protected readonly textColor: Signal<string> = computed(() => {
×
UNCOV
72
        return !isTextColor(this.thyTextColor()) ? this.thyTextColor() : null;
×
UNCOV
73
    });
×
74

75
    protected readonly backgroundColor: Signal<string> = computed(() => {
UNCOV
76
        return !isTextColor(this.thyBackgroundColor()) ? this.thyBackgroundColor() : null;
×
UNCOV
77
    });
×
UNCOV
78

×
UNCOV
79
    constructor() {
×
80
        this.nativeElement = this.elementRef.nativeElement;
81
    }
UNCOV
82

×
83
    /**
84
     * 徽标类型
1✔
85
     * @type default | primary | danger | warning | success
1✔
86
     */
87
    readonly thyType = input<string, string>('danger', {
88
        transform: (value: string) => value || 'danger'
89
    });
90

91
    /**
92
     * 徽标内容数字
93
     * @type number
94
     */
95
    readonly thyCount = input<number, unknown>(undefined, { transform: numberAttribute });
96

97
    /**
98
     * 徽标内容文本
99
     * @type string
1✔
100
     */
101
    readonly thyContent = input<string>();
102

103
    /**
104
     * 已废弃,徽标内容文本,命名错误,请使用 thyContent
105
     */
106
    readonly thyContext = input<string>();
107

108
    /**
109
     * 徽标显示的最大值, 与 thyCount 一起使用,thyCount 超过了 thyMaxCount 设置的值时,徽标内容为 thyMaxCount+
110
     * @type number
111
     */
112
    readonly thyMaxCount = input<number, unknown>(undefined, { transform: numberAttribute });
113

114
    /**
115
     * 徽标显示的大小
116
     * @type md | sm | lg
117
     */
118
    readonly thySize = input<ThyBadgeSize, ThyBadgeSize>('md', { transform: (value: ThyBadgeSize) => value || 'md' });
119

120
    /**
121
     * 已废弃,徽标是一个实心点,已经被废弃
122
     * @deprecated
123
     */
124
    readonly thyIsDot = input(false, { transform: coerceBooleanProperty });
125

126
    /**
127
     * 已废弃,徽标是一个空心点
128
     * @deprecated
129
     */
130
    readonly thyIsHollow = input(false, { transform: coerceBooleanProperty });
131

132
    /**
133
     * thyCount 为 0 时,强制显示数字 0,默认不显示
134
     */
135
    readonly thyKeepShow = input(false, { transform: coerceBooleanProperty });
136

137
    /**
138
     * 设置徽标字体的颜色,支持内置颜色和自定义颜色 'primary' | '#87d068' | ...
139
     * @type string
140
     */
141
    readonly thyTextColor = input<string>('');
142

143
    /**
144
     * 设置徽标的背景颜色,支持内置颜色和自定义颜色 'primary' | '#87d068' | ...
145
     * @type string
146
     */
147
    readonly thyBackgroundColor = input<string>('');
148

149
    ngOnInit() {
150
        let childNodeCount = 0;
151
        this.nativeElement.childNodes.forEach((n: HTMLElement) => {
152
            if (['#comment'].indexOf(n.nodeName) < 0) {
153
                childNodeCount++;
154
            }
155
        });
156
        this.isWrapper = childNodeCount > 0;
157
    }
158
}
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