• 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

7.41
/src/calendar/calendar.component.ts
1
import { DateRangeItemInfo } from 'ngx-tethys/date-range';
2
import { TinyDate } from 'ngx-tethys/util';
3

4
import {
5
    ChangeDetectionStrategy,
6
    ChangeDetectorRef,
7
    Component,
8
    computed,
9
    contentChild,
10
    effect,
11
    forwardRef,
12
    HostBinding,
13
    inject,
14
    input,
15
    OnInit,
1✔
16
    output,
17
    Signal,
UNCOV
18
    TemplateRef,
×
UNCOV
19
    ViewEncapsulation
×
20
} from '@angular/core';
21
import { NG_VALUE_ACCESSOR } from '@angular/forms';
UNCOV
22

×
UNCOV
23
import { DateTable, MonthTable } from 'ngx-tethys/date-picker';
×
24
import { ThyDateCellDirective as DateCell, ThyCalendarHeaderOperationDirective as HeaderOperation } from './calendar-cells';
25

26
import { ThyCalendarHeader } from './calendar-header.component';
27

UNCOV
28
export type CalendarMode = 'month' | 'year';
×
29
type CalendarDateTemplate = TemplateRef<{ $implicit: Date }>;
30

UNCOV
31
/**
×
32
 * 日历组件
33
 * @name thy-calendar
UNCOV
34
 * @order 10
×
UNCOV
35
 */
×
36
@Component({
37
    selector: 'thy-calendar',
UNCOV
38
    templateUrl: './calendar.component.html',
×
39
    encapsulation: ViewEncapsulation.None,
40
    changeDetection: ChangeDetectionStrategy.OnPush,
UNCOV
41
    providers: [{ provide: NG_VALUE_ACCESSOR, useExisting: forwardRef(() => ThyCalendar), multi: true }],
×
42
    imports: [ThyCalendarHeader, DateTable, MonthTable]
43
})
×
UNCOV
44
export class ThyCalendar implements OnInit {
×
UNCOV
45
    private cdr = inject(ChangeDetectorRef);
×
UNCOV
46

×
UNCOV
47
    @HostBinding('class.thy-calendar-container') className = true;
×
UNCOV
48

×
UNCOV
49
    @HostBinding('class.thy-calendar-full') className1 = true;
×
50

51
    /**
52
     * 展示模式
UNCOV
53
     * @type month | year
×
UNCOV
54
     */
×
UNCOV
55
    readonly thyMode = input<CalendarMode>('month');
×
UNCOV
56

×
UNCOV
57
    /**
×
UNCOV
58
     * (可双向绑定)展示日期,默认为当前日期
×
UNCOV
59
     */
×
UNCOV
60
    readonly thyValue = input<Date>();
×
UNCOV
61

×
UNCOV
62
    /**
×
UNCOV
63
     * 不可选择的日期
×
UNCOV
64
     */
×
UNCOV
65
    readonly thyDisabledDate = input<(date: Date) => boolean>();
×
66

UNCOV
67
    /**
×
UNCOV
68
     * 日期选择变化的回调
×
UNCOV
69
     */
×
UNCOV
70
    readonly thySelectChange = output<Date>();
×
71

UNCOV
72
    /**
×
UNCOV
73
     * 日期选择变化的回调
×
UNCOV
74
     */
×
UNCOV
75
    readonly thyValueChange = output<Date>();
×
UNCOV
76

×
UNCOV
77
    /**
×
UNCOV
78
     * 日期选择范围变化的回调
×
79
     */
80
    readonly thyDateRangeChange = output<DateRangeItemInfo>();
81

82
    /**
1✔
83
     * (可作为内容)自定义渲染日期单元格,模板内容会被追加到单元格
1✔
84
     */
85
    readonly thyDateCell = input<CalendarDateTemplate>();
86

87
    /**
88
     *  追加到单元格的自定义模板
89
     */
90
    readonly thyDateCellChild = contentChild(DateCell, { read: TemplateRef });
91

92
    readonly dateCell: Signal<CalendarDateTemplate> = computed(() => {
93
        return (this.thyDateCell() || this.thyDateCellChild())!;
94
    });
95

96
    /**
97
     * (可作为内容)自定义渲染右上角操作项
98
     */
1✔
99
    readonly thyCalendarHeaderOperation = input<CalendarDateTemplate>();
100

101
    /**
102
     * 右上角操作项的自定义模板
103
     */
UNCOV
104
    readonly thyCalendarHeaderOperationChild = contentChild(HeaderOperation, { read: TemplateRef });
×
105

106
    readonly headerOperation: Signal<CalendarDateTemplate> = computed(() => {
107
        return (this.thyCalendarHeaderOperation() || this.thyCalendarHeaderOperationChild())!;
108
    });
109

110
    public currentDate = new TinyDate();
111

112
    public prefixCls = 'thy-calendar-full';
113

114
    private onChangeFn: (date: Date) => void = () => {};
115

116
    private onTouchFn: () => void = () => {};
117

118
    ngOnInit(): void {}
119

120
    onYearSelect(year: number): void {
121
        const date = this.currentDate.setYear(year);
122
        this.updateDate(date);
123
    }
124

125
    onMonthSelect(month: number): void {
126
        const date = this.currentDate.setMonth(month);
127
        this.updateDate(date);
128
    }
129

130
    onDateSelect(date: TinyDate): void {
131
        // Only currentDate is enough in calendar
132
        // this.value = date;
133
        this.updateDate(date);
134
    }
135

136
    onDateRangeSelect(date: DateRangeItemInfo) {
137
        this.thyDateRangeChange.emit(date);
138
    }
139

140
    writeValue(value: Date | null): void {
141
        this.updateDate(new TinyDate(value as Date), false);
142
        this.cdr.markForCheck();
143
    }
144

145
    registerOnChange(fn: (date: Date) => void): void {
146
        this.onChangeFn = fn;
147
    }
148

149
    registerOnTouched(fn: () => void): void {
150
        this.onTouchFn = fn;
151
    }
152

153
    private updateDate(date: TinyDate, touched: boolean = true): void {
154
        this.currentDate = date;
155

156
        if (touched) {
157
            this.onChangeFn(date.nativeDate);
158
            this.onTouchFn();
159
            this.thySelectChange.emit(date.nativeDate);
160
            this.thyValueChange.emit(date.nativeDate);
161
        }
162
    }
163

164
    constructor() {
165
        effect(() => {
166
            if (this.thyValue()) {
167
                this.updateDate(new TinyDate(this.thyValue()), false);
168
            }
169
        });
170
    }
171
}
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