forked from ionic-team/ionic-framework
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlabel.ts
More file actions
121 lines (107 loc) · 2.67 KB
/
label.ts
File metadata and controls
121 lines (107 loc) · 2.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
import { Attribute, Directive, ElementRef, Renderer, Input } from '@angular/core';
import { Config } from '../../config/config';
import { Ion } from '../ion';
/**
* @name Label
* @description
* Labels are placed inside of an `ion-item` element and can be used
* to describe an `ion-input`, `ion-toggle`, `ion-checkbox`, and more.
*
* @property [fixed] - A persistent label that sits next the input.
* @property [floating] - A label that will float above the input if the input is empty or loses focus.
* @property [stacked] - A stacked label will always appear on top of the input.
*
* @usage
* ```html
* <ion-item>
* <ion-label>Username</ion-label>
* <ion-input></ion-input>
* </ion-item>
*
* <ion-item>
* <ion-label fixed>Website</ion-label>
* <ion-input type="url"></ion-input>
* </ion-item>
*
* <ion-item>
* <ion-label floating>Email</ion-label>
* <ion-input type="email"></ion-input>
* </ion-item>
*
* <ion-item>
* <ion-label stacked>Phone</ion-label>
* <ion-input type="tel"></ion-input>
* </ion-item>
*
* <ion-item>
* <ion-label>Toggle</ion-label>
* <ion-toggle></ion-toggle>
* </ion-item>
*
* <ion-item>
* <ion-label>Checkbox</ion-label>
* <ion-checkbox></ion-checkbox>
* </ion-item>
* ```
*
* @demo /docs/v2/demos/label/
* @see {@link ../../../../components#inputs Input Component Docs}
* @see {@link ../../input/Input Input API Docs}
*
*/
@Directive({
selector: 'ion-label'
})
export class Label extends Ion {
private _id: string;
/**
* @input {string} The predefined color to use. For example: `"primary"`, `"secondary"`, `"danger"`.
*/
@Input()
set color(val: string) {
this._setColor('label', val);
}
/**
* @input {string} The mode to apply to this component.
*/
@Input()
set mode(val: string) {
this._setMode('label', val);
}
/**
* @private
*/
type: string;
constructor(
config: Config,
elementRef: ElementRef,
renderer: Renderer,
@Attribute('floating') isFloating: string,
@Attribute('stacked') isStacked: string,
@Attribute('fixed') isFixed: string,
@Attribute('inset') isInset: string
) {
super(config, elementRef, renderer);
this.mode = config.get('mode');
this.type = (isFloating === '' ? 'floating' : (isStacked === '' ? 'stacked' : (isFixed === '' ? 'fixed' : (isInset === '' ? 'inset' : null))));
}
/**
* @private
*/
@Input()
get id(): string {
return this._id;
}
set id(val: string) {
this._id = val;
if (val) {
this.setElementAttribute('id', val);
}
}
/**
* @private
*/
get text(): string {
return this.getNativeElement().textContent || '';
}
}