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

atinc / ngx-tethys / d9ae709b-3c27-4b69-b125-b8b80b54f90b

pending completion
d9ae709b-3c27-4b69-b125-b8b80b54f90b

Pull #2757

circleci

mengshuicmq
fix: fix code review
Pull Request #2757: feat(color-picker): color-picker support disabled (#INFR-8645)

98 of 6315 branches covered (1.55%)

Branch coverage included in aggregate %.

1 of 1 new or added line in 1 file covered. (100.0%)

2392 of 13661 relevant lines covered (17.51%)

83.12 hits per line

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

8.89
/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
    ContentChild,
9
    EventEmitter,
10
    forwardRef,
11
    HostBinding,
12
    Input,
13
    OnChanges,
14
    OnInit,
15
    Output,
16
    SimpleChanges,
1✔
17
    TemplateRef,
18
    ViewEncapsulation
×
19
} from '@angular/core';
20
import { NG_VALUE_ACCESSOR } from '@angular/forms';
21

×
22
import { ThyCalendarHeaderOperationDirective as HeaderOperation, ThyDateCellDirective as DateCell } from './calendar-cells';
23
import { DateTableComponent, MonthTableComponent } from 'ngx-tethys/date-picker';
24
import { NgIf } from '@angular/common';
×
25
import { ThyCalendarHeaderComponent } from './calendar-header.component';
×
26

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

×
30
/**
×
31
 * 日历组件
×
32
 * @name thy-calendar
×
33
 * @order 10
×
34
 */
×
35
@Component({
36
    selector: 'thy-calendar',
37
    templateUrl: './calendar.component.html',
38
    encapsulation: ViewEncapsulation.None,
×
39
    changeDetection: ChangeDetectionStrategy.OnPush,
×
40
    providers: [{ provide: NG_VALUE_ACCESSOR, useExisting: forwardRef(() => ThyCalendarComponent), multi: true }],
41
    standalone: true,
42
    imports: [ThyCalendarHeaderComponent, NgIf, DateTableComponent, MonthTableComponent]
×
43
})
×
44
export class ThyCalendarComponent implements OnInit, OnChanges {
45
    @HostBinding('class.thy-calendar-container') className = true;
46

47
    @HostBinding('class.thy-calendar-full') className1 = true;
48

×
49
    /**
50
     * 展示模式
51
     * @type month | year
×
52
     */
53
    @Input() thyMode: CalendarMode = 'month';
54

×
55
    /**
×
56
     * (可双向绑定)展示日期,默认为当前日期
57
     */
58
    @Input() thyValue?: Date;
×
59

60
    /**
61
     * 不可选择的日期
×
62
     */
63
    @Input() thyDisabledDate?: (date: Date) => boolean;
×
64

×
65
    /**
×
66
     * 日期选择变化的回调
×
67
     */
×
68
    @Output() thySelectChange: EventEmitter<Date> = new EventEmitter();
×
69

×
70
    /**
71
     * 日期选择变化的回调
72
     */
73
    @Output() thyValueChange: EventEmitter<Date> = new EventEmitter();
×
74

×
75
    /**
76
     * 日期选择范围变化的回调
77
     */
1✔
78
    @Output() thyDateRangeChange: EventEmitter<DateRangeItemInfo> = new EventEmitter();
79

80
    /**
1✔
81
     * (可作为内容)自定义渲染日期单元格,模板内容会被追加到单元格
82
     */
83
    @Input() thyDateCell?: CalendarDateTemplate;
84

85
    /**
86
     *  追加到单元格的自定义模板
87
     */
88
    @ContentChild(DateCell, { read: TemplateRef }) thyDateCellChild?: CalendarDateTemplate;
89
    get dateCell(): CalendarDateTemplate {
90
        return (this.thyDateCell || this.thyDateCellChild)!;
91
    }
92

93
    /**
94
     * (可作为内容)自定义渲染右上角操作项
95
     */
1✔
96
    @Input() thyCalendarHeaderOperation?: CalendarDateTemplate;
97

98
    /**
99
     * 右上角操作项的自定义模板
100
     */
101
    @ContentChild(HeaderOperation, { read: TemplateRef }) thyCalendarHeaderOperationChild?: CalendarDateTemplate;
×
102
    get headerOperation(): CalendarDateTemplate {
103
        return (this.thyCalendarHeaderOperation || this.thyCalendarHeaderOperationChild)!;
104
    }
105

106
    public currentDate = new TinyDate();
107

108
    public prefixCls = 'thy-calendar-full';
109

110
    private onChangeFn: (date: Date) => void = () => {};
111

112
    private onTouchFn: () => void = () => {};
113

114
    constructor(private cdr: ChangeDetectorRef) {}
115

116
    ngOnInit(): void {}
117

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

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

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

134
    onDateRangeSelect(date: DateRangeItemInfo) {
135
        this.thyDateRangeChange.emit(date);
136
    }
137

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

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

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

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

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

162
    ngOnChanges(changes: SimpleChanges): void {
163
        if (changes.thyValue) {
164
            this.updateDate(new TinyDate(this.thyValue), false);
165
        }
166
    }
167
}
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