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

atinc / ngx-tethys / e62d3b10-1466-49c3-aabd-707148681fc8

14 Jun 2024 08:24AM UTC coverage: 90.422%. Remained the same
e62d3b10-1466-49c3-aabd-707148681fc8

push

circleci

minlovehua
feat: use the ngx-tethys/util's coerceBooleanProperty instead of booleanAttribute #INFR-12648

5467 of 6692 branches covered (81.69%)

Branch coverage included in aggregate %.

117 of 120 new or added lines in 66 files covered. (97.5%)

183 existing lines in 46 files now uncovered.

13216 of 13970 relevant lines covered (94.6%)

985.91 hits per line

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

96.08
/src/alert/alert.component.ts
1
import { Component, Input, OnInit, ContentChild, TemplateRef, OnChanges, ChangeDetectionStrategy, SimpleChanges } from '@angular/core';
2
import { coerceBooleanProperty, isString } from 'ngx-tethys/util';
3
import { useHostRenderer } from '@tethys/cdk/dom';
4
import { ThyIcon } from 'ngx-tethys/icon';
5
import { NgIf, NgTemplateOutlet } from '@angular/common';
6

7
const weakTypes = ['primary-weak', 'success-weak', 'warning-weak', 'danger-weak'];
8

1✔
9
type ThyAlertType =
1✔
10
    | 'success'
11
    | 'warning'
12
    | 'danger'
13
    | 'info'
14
    | 'primary'
15
    | 'primary-weak'
16
    | 'success-weak'
17
    | 'warning-weak'
18
    | 'danger-weak';
19

20
export type ThyAlertTheme = 'fill' | 'bordered' | 'naked';
21

22
const typeIconsMap: Record<string, string> = {
23
    success: 'check-circle-fill',
24
    warning: 'waring-fill',
25
    danger: 'close-circle-fill',
1✔
26
    info: 'minus-circle-fill',
27
    primary: 'info-circle-fill',
22✔
28
    'primary-weak': 'info-circle-fill',
29
    'success-weak': 'check-circle-fill',
30
    'warning-weak': 'waring-fill',
17✔
31
    'danger-weak': 'close-circle-fill'
32
};
33

22✔
34
/**
1✔
35
 * 警告提示,展现需要关注的信息
36
 * @name thy-alert
37
 * @order 10
21✔
38
 */
39
@Component({
40
    selector: 'thy-alert',
41
    templateUrl: './alert.component.html',
17✔
42
    changeDetection: ChangeDetectionStrategy.OnPush,
15✔
43
    host: {
15✔
44
        class: 'thy-alert',
45
        '[class.thy-alert-hidden]': 'hidden'
46
    },
2✔
47
    standalone: true,
48
    imports: [NgIf, ThyIcon, NgTemplateOutlet]
49
})
50
export class ThyAlert implements OnInit, OnChanges {
44✔
51
    private hidden = false;
42✔
52

53
    private showIcon = true;
54

2✔
55
    private icon: string;
56

57
    private type: ThyAlertType = 'info';
58

23✔
59
    private hostRenderer = useHostRenderer();
23✔
60

23✔
61
    public theme: ThyAlertTheme = 'fill';
23✔
62

23✔
63
    messageTemplate: TemplateRef<HTMLElement>;
64

65
    messageText: string;
22✔
66

67
    /**
68
     * 指定警告提示的类型
22!
UNCOV
69
     * @type success | warning | danger | info | primary | primary-weak | success-weak | warning-weak | danger-weak
×
70
     * @default info
71
     */
72
    @Input() set thyType(value: ThyAlertType) {
73
        this.type = value;
1✔
74
    }
75

76
    /**
77
     * 指定警告提示的主题
22✔
78
     * @type fill | bordered | naked
22✔
79
     * @default fill
22✔
80
     */
1✔
81
    @Input() set thyTheme(value: ThyAlertTheme) {
1✔
82
        this.theme = value;
83
    }
22✔
84

85
    /**
1✔
86
     * 显示警告提示的内容
1✔
87
     */
88
    @Input() set thyMessage(value: string | TemplateRef<HTMLElement>) {
89
        if (value instanceof TemplateRef) {
90
            this.messageTemplate = value;
91
        } else {
92
            this.messageText = value;
93
        }
94
    }
95

1✔
96
    /**
97
     * 显示自定义图标,可传 true/false 控制是否显示图标,或者传字符串去指定图标名称
98
     */
99
    @Input()
100
    set thyIcon(value: boolean | string) {
101
        if (value) {
102
            this.showIcon = true;
103
            this.icon = isString(value) ? value.toString() : null;
104
        } else {
105
            this.showIcon = false;
106
        }
107
    }
108

109
    get thyIcon() {
110
        if (this.showIcon) {
111
            return this.icon || typeIconsMap[this.type];
112
        } else {
113
            return null;
114
        }
115
    }
116

117
    /**
118
     * 是否显示关闭警告框按钮,默认不显示
119
     * @default false
120
     */
121
    @Input({ transform: coerceBooleanProperty }) thyCloseable: boolean;
122

123
    /**
124
     * 警告框自定义操作
125
     * @type TemplateRef
126
     */
127
    @ContentChild('operation') alertOperation: TemplateRef<any>;
128

129
    constructor() {}
130

131
    ngOnInit() {
132
        this.updateClass();
133
    }
134

135
    ngOnChanges(changes: SimpleChanges): void {
136
        if ((changes.thyTheme && !changes.thyTheme.firstChange) || (changes.thyType && !changes.thyType.firstChange)) {
137
            this.updateClass();
138
        }
139
    }
140

141
    closeAlert() {
142
        this.hidden = true;
143
    }
144

145
    private updateClass() {
146
        // 兼容 'primary-weak', 'success-weak', 'warning-weak', 'danger-weak' types
147
        let theme = this.theme;
148
        let type = this.type;
149
        if (weakTypes.includes(this.type)) {
150
            theme = 'bordered';
151
            type = this.type.split('-')[0] as ThyAlertType;
152
        }
153
        this.hostRenderer.updateClass([`thy-alert-${theme}`, `thy-alert-${theme}-${type}`]);
154
    }
155
}
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