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

atinc / ngx-tethys / #55

30 Jul 2025 07:08AM UTC coverage: 9.866% (-80.4%) from 90.297%
#55

push

why520crazy
feat(empty): add setMessage for update display text #TINFR-2616

92 of 6794 branches covered (1.35%)

Branch coverage included in aggregate %.

2014 of 14552 relevant lines covered (13.84%)

6.15 hits per line

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

7.41
/src/progress/progress.component.ts
1
import { isNumber } from 'ngx-tethys/util';
2
import {
3
    ChangeDetectionStrategy,
4
    Component,
5
    computed,
6
    TemplateRef,
7
    ViewEncapsulation,
8
    numberAttribute,
9
    input,
10
    viewChildren,
11
    effect
12
} from '@angular/core';
13
import { useHostRenderer } from '@tethys/cdk/dom';
14
import { ThyProgressGapPositionType, ThyProgressShapeType, ThyProgressStackedValue, ThyProgressType } from './interfaces';
15
import { THY_PROGRESS_COMPONENT, ThyParentProgress, ThyProgressStrip } from './progress-strip.component';
1✔
16
import { ThyProgressCircle } from './progress-circle.component';
17
import { ThyTooltipDirective } from 'ngx-tethys/tooltip';
×
18
import { NgClass, NgTemplateOutlet } from '@angular/common';
×
19

×
20
/**
×
21
 * 进度条组件
×
22
 * @name thy-progress
×
23
 */
24
@Component({
25
    selector: 'thy-progress',
×
26
    templateUrl: './progress.component.html',
27
    changeDetection: ChangeDetectionStrategy.OnPush,
×
28
    encapsulation: ViewEncapsulation.None,
×
29
    providers: [
×
30
        {
×
31
            provide: THY_PROGRESS_COMPONENT,
×
32
            useExisting: ThyProgress
×
33
        }
34
    ],
×
35
    host: {
×
36
        class: `thy-progress progress`,
37
        '[class.thy-progress-strip]': `thyShape() === 'strip'`,
×
38
        '[class.thy-progress-circle]': `thyShape() === 'circle'`,
×
39
        '[class.progress-stacked]': 'isStacked()',
40
        '[attr.max]': 'max()'
×
41
    },
42
    imports: [ThyProgressStrip, NgClass, ThyTooltipDirective, NgTemplateOutlet, ThyProgressCircle]
×
43
})
×
44
export class ThyProgress implements ThyParentProgress {
45
    private hostRenderer = useHostRenderer();
×
46

×
47
    readonly barsTotalValue = computed(() => {
×
48
        const value = this.thyValue();
×
49
        if (Array.isArray(value)) {
50
            return value.reduce((total, item) => {
×
51
                return total + item.value;
×
52
            }, 0);
53
        }
54
        return undefined;
×
55
    });
56

57
    readonly max = computed(() => {
58
        const setMax = this.thyMax();
×
59
        const barsTotalValue = this.barsTotalValue();
×
60
        let result: number = 100;
×
61
        if (isNumber(setMax) && setMax > 0) {
×
62
            result = setMax;
×
63
        } else if (isNumber(barsTotalValue)) {
×
64
            result = barsTotalValue;
×
65
        }
×
66
        if (result < barsTotalValue) {
×
67
            result = barsTotalValue;
68
        }
69
        return result;
1✔
70
    });
1✔
71

72
    readonly isStacked = computed(() => {
73
        return Array.isArray(this.thyValue());
74
    });
75

76
    readonly bars = viewChildren(ThyProgressStrip);
77

78
    /**
79
     * 进度条类型: `primary` | `success` | `info` | `warning` | `danger`
80
     */
81
    readonly thyType = input<ThyProgressType>('primary');
82

83
    /**
1✔
84
     * 进度条大小
85
     * @type xs | sm | md
86
     * @default md
87
     */
88
    readonly thySize = input<string | number>('md');
89

90
    /**
91
     * 进度值,传入数字时显示百分比 = value / max * 100,当传入数组时显示多个 bar,stacked 模式的进度条
92
     * @type number | ThyProgressStackedValue[]
93
     */
94
    readonly thyValue = input<number | ThyProgressStackedValue[], number | ThyProgressStackedValue[]>(undefined, {
95
        transform: (value: number | ThyProgressStackedValue[]) => {
96
            if (Array.isArray(value)) {
97
                return [...value].filter(item => item.value !== 0);
98
            } else {
99
                return value;
100
            }
101
        }
102
    });
103

104
    /**
105
     * 最大值,主要计算百分比进度的分母使用,当 thyValue 传入数组时,自动累加数组中的 value 之和为 max
106
     */
107
    readonly thyMax = input<number, unknown>(undefined, { transform: numberAttribute });
108

109
    /**
110
     * 鼠标移入进度条时显示的提示文案或者模板
111
     */
112
    readonly thyTips = input<string | TemplateRef<unknown>>(undefined);
113

114
    /**
115
     * 进度形状
116
     * @type strip | circle
117
     */
118
    readonly thyShape = input<ThyProgressShapeType>('strip');
119

120
    /**
121
     * 圆形进度条缺口角度,可取值 0 ~ 360
122
     */
123
    readonly thyGapDegree = input<number, unknown>(undefined, { transform: numberAttribute });
124

125
    /**
126
     * 圆形进度条缺口位置
127
     * @type top | bottom | left | right
128
     */
129
    readonly thyGapPosition = input<ThyProgressGapPositionType>('top');
130

131
    /**
132
     *         圆形进度条线的宽度
133
     */
134
    readonly thyStrokeWidth = input<number, unknown>(undefined, { transform: numberAttribute });
135

136
    constructor() {
137
        effect(() => {
138
            const size = this.thySize();
139
            this.hostRenderer.updateClass(size ? [`progress-${size}`] : []);
140
        });
141
    }
142
}
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