• 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

10.0
/src/form/form-group.component.ts
1
import { NgClass, NgTemplateOutlet } from '@angular/common';
2
import {
3
    ChangeDetectionStrategy,
4
    Component,
5
    ContentChild,
6
    HostBinding,
7
    Input,
8
    OnInit,
9
    TemplateRef,
10
    ViewEncapsulation,
11
    inject,
1✔
12
    input,
13
    computed,
14
    signal,
15
    effect
16
} from '@angular/core';
17

18
import { ThyTranslate } from 'ngx-tethys/core';
19
import { ThyIcon } from 'ngx-tethys/icon';
1✔
20
import { ThyTooltipDirective } from 'ngx-tethys/tooltip';
21

×
22
import { ThyFormDirective } from './form.directive';
×
23
import { coerceBooleanProperty } from 'ngx-tethys/util';
×
24

×
25
const internalIconMap: Record<string, string> = {
×
26
    date: 'calendar'
×
27
};
×
28

×
29
type TipsMode = 'default' | 'label';
×
30

×
31
/**
32
 * 表单分组组件
×
33
 * @name thy-form-group
×
34
 * @order 40
35
 */
×
36
@Component({
37
    selector: 'thy-form-group',
×
38
    templateUrl: './form-group.component.html',
39
    encapsulation: ViewEncapsulation.None,
40
    changeDetection: ChangeDetectionStrategy.OnPush,
×
41
    imports: [NgTemplateOutlet, ThyIcon, NgClass, ThyTooltipDirective],
42
    host: {
43
        class: 'form-group',
×
44
        '[class.row-fill]': 'thyRowFill()',
45
        '[class.row]': 'isHorizontalSignal()',
×
46
        '[class.has-feedback]': 'thyFeedbackIcon()'
×
47
    }
48
})
×
49
export class ThyFormGroup implements OnInit {
50
    private thyParentForm = inject(ThyFormDirective, { optional: true })!;
51
    private thyTranslate = inject(ThyTranslate);
×
52

×
53
    protected isHorizontalSignal = signal(true);
×
54

×
55
    /**
×
56
     * Label 文本
×
57
     */
×
58
    readonly thyLabelText = input<string>();
×
59

60
    /**
×
61
     * Label 文本多语言 Key
×
62
     */
63
    readonly thyLabelTextTranslateKey = input<string>();
×
64

65
    protected labelTextSignal = computed(() => {
×
66
        const labelTextTranslateKey = this.thyLabelTextTranslateKey();
67
        const labelText = this.thyLabelText();
68
        if (labelText) {
69
            return labelText;
70
        } else if (labelTextTranslateKey) {
71
            return this.thyTranslate.instant(labelTextTranslateKey);
72
        }
×
73
        return '';
×
74
    });
75

1✔
76
    /**
1✔
77
     * Label 是否显示必填项样式
78
     */
79
    readonly thyLabelRequired = input(false, {
80
        transform: coerceBooleanProperty
81
    });
82

83
    /**
84
     * 清楚 Label padding 间距
85
     */
86
    readonly thyLabelPaddingTopClear = input(false, {
87
        transform: coerceBooleanProperty
88
    });
89

90
    /**
1✔
91
     * 反馈图标,比如日期输入框显示日期的图标,常用输入 date 表示时间 wtf wtf-schedule-o
92
     */
93
    thyFeedbackIcon = input('', {
94
        transform: (value: string) => {
95
            if (internalIconMap[value]) {
96
                return internalIconMap[value];
97
            }
98
            return value;
99
        }
100
    });
101

102
    /**
103
     * 提示文字的显示模式,`label`模式表示在 label 后通过图标+Tooltip 提示, `default`模式在 Form Control 下方直接显示
104
     * @type default | label
105
     * @default default
106
     */
107
    thyTipsMode = input<TipsMode>('default');
108

109
    /**
110
     * 提示文案
111
     */
112
    readonly thyTips = input<string>('');
113

114
    /**
115
     * 提示文案的多语言 Key
116
     */
117
    readonly thyTipsTranslateKey = input<string>('');
118

119
    protected readonly tipsSignal = computed(() => {
120
        const key = this.thyTipsTranslateKey();
121
        const tips = this.thyTips();
122

123
        if (key) {
124
            return this.thyTranslate.instant(key);
125
        }
126
        if (tips) {
127
            return tips;
128
        }
129
        return '';
130
    });
131

132
    /**
133
     * 是否填充整行, 没有 Label 文本,只有输入框
134
     * @default false
135
     */
136
    readonly thyRowFill = input(false, { transform: coerceBooleanProperty });
137

138
    /**
139
     * 已废弃
140
     * @deprecated please use content because formGroup is same name with angular formGroup directive
141
     */
142
    @ContentChild('formGroup')
143
    public contentTemplateRef: TemplateRef<any>;
144

145
    /**
146
     * 内容自定义模板,`<ng-template #content></ng-template>`
147
     */
148
    @ContentChild('content')
149
    public contentTemplate: TemplateRef<any>;
150

151
    constructor() {
152
        // effect(() => {
153
        //     const isHorizontal = this.thyParentForm ? this.thyParentForm.isHorizontal : true;
154
        //     this.isHorizontal.set(isHorizontal);
155
        // });
156
    }
157

158
    ngOnInit() {
159
        const isHorizontal = this.thyParentForm ? this.thyParentForm.isHorizontal : true;
160
        this.isHorizontalSignal.set(isHorizontal);
161
    }
162
}
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

© 2026 Coveralls, Inc