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

atinc / ngx-tethys / 5ba5b9d7-3ca9-4ff2-bbba-bde58c0f849f

22 Feb 2024 09:41AM UTC coverage: 90.604%. Remained the same
5ba5b9d7-3ca9-4ff2-bbba-bde58c0f849f

Pull #3027

circleci

minlovehua
feat(schematics): provide schematics for removing the suffix of standalone components #INFR-11662
Pull Request #3027: refactor: remove the component suffix for standalone components and provide schematics #INFR-10654

5425 of 6642 branches covered (81.68%)

Branch coverage included in aggregate %.

323 of 333 new or added lines in 193 files covered. (97.0%)

36 existing lines in 8 files now uncovered.

13504 of 14250 relevant lines covered (94.76%)

981.28 hits per line

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

90.0
/src/radio/group/radio-group.component.ts
1
import {
2
    AfterContentInit,
3
    ChangeDetectionStrategy,
4
    ChangeDetectorRef,
5
    Component,
6
    forwardRef,
7
    HostBinding,
8
    Input,
1✔
9
    OnChanges,
10
    OnInit,
11
    SimpleChanges
12
} from '@angular/core';
1✔
13
import { ControlValueAccessor, NG_VALUE_ACCESSOR } from '@angular/forms';
14
import { useHostRenderer } from '@tethys/cdk/dom';
15
import { InputBoolean } from 'ngx-tethys/core';
16

17
import { ThyRadioButton } from '../button/radio-button.component';
18
import { ThyRadio } from '../radio.component';
19
import { coerceBooleanProperty } from 'ngx-tethys/util';
1✔
20

21
const buttonGroupSizeMap = {
10✔
22
    sm: ['btn-group-sm'],
23
    lg: ['btn-group-lg']
24
};
×
25

26
const radioGroupLayoutMap = {
27
    flex: ['radio-group-layout-flex']
9✔
28
};
29

30
/**
7✔
31
 * @name thy-radio-group
7✔
32
 * @order 20
7✔
33
 */
7✔
34
@Component({
7✔
35
    selector: 'thy-radio-group',
7✔
36
    templateUrl: './radio-group.component.html',
7✔
37
    providers: [
7✔
38
        {
7✔
39
            provide: NG_VALUE_ACCESSOR,
40
            useExisting: forwardRef(() => ThyRadioGroup),
41
            multi: true
21✔
42
        }
21✔
43
    ],
44
    host: {
45
        '[attr.tabindex]': `-1`
16✔
46
    },
16✔
47
    changeDetection: ChangeDetectionStrategy.OnPush,
27✔
48
    standalone: true
49
})
16!
NEW
50
export class ThyRadioGroup implements ControlValueAccessor, OnInit, OnChanges, AfterContentInit {
×
51
    @HostBinding('class.thy-radio-group') thyRadioGroup = true;
52

16✔
53
    @HostBinding('class.btn-group') isButtonGroup = false;
16✔
54

55
    @HostBinding('class.btn-group-outline-default')
56
    isButtonGroupOutline = false;
16✔
57

58
    private _size: string;
59

7✔
60
    private _layout: string;
61

62
    private _disabled = false;
7✔
63

64
    /**
65
     * 大小
23✔
66
     * @type sm | md | lg
27✔
67
     * @default md
68
     */
69
    @Input()
70
    set thySize(size: string) {
7!
71
        this._size = size;
7✔
72
    }
7✔
73

74
    @Input()
75
    set thyLayout(layout: string) {
76
        this._layout = layout;
10✔
77
    }
78

79
    _innerValue: string | number;
12✔
80

12✔
81
    radios: Array<ThyRadio | ThyRadioButton> = [];
9✔
82

83
    private hostRenderer = useHostRenderer();
84

85
    /**
7✔
86
     * 是否禁用单选组合框
87
     * @default false
88
     */
10✔
89
    @Input()
10✔
90
    @InputBoolean()
2✔
91
    set thyDisabled(value: boolean) {
92
        this._disabled = coerceBooleanProperty(value);
10!
93
    }
×
94

95
    onChange: (_: string) => void = () => null;
10✔
96
    onTouched: () => void = () => null;
97

1✔
98
    constructor(private changeDetectorRef: ChangeDetectorRef) {}
99

100
    addRadio(radio: ThyRadio | ThyRadioButton): void {
1✔
101
        this.radios.push(radio);
102
        radio.thyChecked = radio.thyValue === this._innerValue;
103
    }
104

105
    updateValue(value: string, emit: boolean): void {
106
        this._innerValue = value;
107
        this.radios.forEach(radio => {
108
            radio.thyChecked = radio.thyValue === this._innerValue;
109
        });
1✔
110
        if (emit) {
111
            this.onChange(value);
112
        }
113
        this.onTouched();
114
        this.changeDetectorRef.detectChanges();
1✔
115
    }
116

117
    writeValue(value: any): void {
118
        this.updateValue(value, false);
119
    }
120

121
    registerOnChange(fn: any): void {
7✔
122
        this.onChange = fn;
123
    }
124

125
    registerOnTouched(fn: any): void {
126
        this.onTouched = fn;
127
    }
128

129
    setDisabledState?(isDisabled: boolean): void {
130
        this.radios.forEach(radio => {
131
            radio.setDisabledState(isDisabled);
132
        });
133
    }
134

135
    setGroup() {
136
        if (!this.isButtonGroup && !this.isButtonGroupOutline) {
137
            this.isButtonGroup = true;
138
            this.isButtonGroupOutline = true;
139
        }
140
    }
141

142
    ngOnInit() {
143
        this._setClasses();
144
    }
145

146
    ngOnChanges(changes: SimpleChanges): void {
147
        const { thyDisabled } = changes;
148
        if (thyDisabled) {
149
            this.setDisabledState(this.thyDisabled);
150
        }
151
    }
152

153
    ngAfterContentInit(): void {
154
        this.setDisabledState(this._disabled);
155
    }
156

157
    private _setClasses() {
158
        const classNames: string[] = [];
159
        if (buttonGroupSizeMap[this._size]) {
160
            classNames.push(buttonGroupSizeMap[this._size]);
161
        }
162
        if (radioGroupLayoutMap[this._layout]) {
163
            classNames.push(radioGroupLayoutMap[this._layout]);
164
        }
165
        this.hostRenderer.updateClass(classNames);
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