• 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

14.63
/src/alert/alert.component.ts
1
import { Component, TemplateRef, ChangeDetectionStrategy, input, contentChild, effect, computed } 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 { NgTemplateOutlet } from '@angular/common';
6

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

9
type ThyAlertType =
1✔
10
    | 'success'
1✔
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',
26
    info: 'minus-circle-fill',
1✔
27
    primary: 'info-circle-fill',
UNCOV
28
    'primary-weak': 'info-circle-fill',
×
UNCOV
29
    'success-weak': 'check-circle-fill',
×
UNCOV
30
    'warning-weak': 'waring-fill',
×
UNCOV
31
    'danger-weak': 'close-circle-fill'
×
UNCOV
32
};
×
33

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

52
    private hostRenderer = useHostRenderer();
53

UNCOV
54
    messageIsTemplate = computed(() => {
×
55
        const value = this.thyMessage();
56
        return value instanceof TemplateRef;
57
    });
UNCOV
58

×
UNCOV
59
    /**
×
UNCOV
60
     * 指定警告提示的类型
×
UNCOV
61
     * @type success | warning | danger | info | primary | primary-weak | success-weak | warning-weak | danger-weak
×
UNCOV
62
     * @default info
×
63
     */
UNCOV
64
    thyType = input<ThyAlertType>('info');
×
65

66
    /**
1✔
67
     * 指定警告提示的主题
1✔
68
     * @type fill | bordered | naked
69
     * @default fill
70
     */
71
    thyTheme = input<ThyAlertTheme>('fill');
72

73
    /**
74
     * 显示警告提示的内容
75
     */
76
    thyMessage = input<string | TemplateRef<HTMLElement>>();
1✔
77

78
    /**
79
     * 显示自定义图标,可传 true/false 控制是否显示图标,或者传字符串去指定图标名称
80
     */
81
    thyIcon = input<boolean | string>();
82

83
    icon = computed(() => {
84
        const icon = this.thyIcon();
85
        if (icon) {
86
            return isString(icon) ? icon : typeIconsMap[this.thyType()];
87
        } else {
88
            return icon === 'false' || icon === false ? '' : typeIconsMap[this.thyType()];
89
        }
90
    });
91

92
    /**
93
     * 是否显示关闭警告框按钮,默认不显示
94
     * @default false
95
     */
96
    thyCloseable = input(false, { transform: coerceBooleanProperty });
97

98
    /**
99
     * 警告框自定义操作
100
     * @type TemplateRef
101
     */
102
    alertOperation = contentChild<TemplateRef<any>>('operation');
103

104
    constructor() {
105
        effect(() => {
106
            this.updateClass();
107
        });
108
    }
109

110
    closeAlert() {
111
        this.hidden = true;
112
    }
113

114
    private updateClass() {
115
        // 兼容 'primary-weak', 'success-weak', 'warning-weak', 'danger-weak' types
116
        let theme = this.thyTheme();
117
        let type = this.thyType();
118
        if (weakTypes.includes(type)) {
119
            theme = 'bordered';
120
            type = type.split('-')[0] as ThyAlertType;
121
        }
122
        this.hostRenderer.updateClass([`thy-alert-${theme}`, `thy-alert-${theme}-${type}`]);
123
    }
124
}
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