forked from ionic-team/ionic-framework
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtoolbar.ts
More file actions
295 lines (274 loc) · 8 KB
/
toolbar.ts
File metadata and controls
295 lines (274 loc) · 8 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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
import { ChangeDetectionStrategy, Component, Directive, ElementRef, Input, Optional, Renderer } from '@angular/core';
import { Config } from '../../config/config';
import { Ion } from '../ion';
import { ToolbarTitle } from './toolbar-title';
import { ViewController } from '../../navigation/view-controller';
/**
* @name Header
* @description
* Header is a parent component that holds the navbar and toolbar component.
* It's important to note that `ion-header` needs to be the one of the three root elements of a page
*
* @usage
*
* ```ts
* @Component({
* template: `
* <ion-header>
* <ion-navbar>
* <ion-title>Page1</ion-title>
* </ion-navbar>
*
* <ion-toolbar>
* <ion-title>Subheader</ion-title>
* </ion-toolbar>
* </ion-header>
*
* <ion-content></ion-content>
* `
* })
* ```
*
*/
@Directive({
selector: 'ion-header'
})
export class Header extends Ion {
constructor(config: Config, elementRef: ElementRef, renderer: Renderer, @Optional() viewCtrl: ViewController) {
super(config, elementRef, renderer);
this._setMode('header', config.get('mode'));
viewCtrl && viewCtrl._setHeader(this);
}
}
/**
* @name Footer
* @description
* Footer is a root component of a page that sits at the bottom of the page.
* Footer can be a wrapper for `ion-toolbar` to make sure the content area is sized correctly.
*
* @usage
*
* ```ts
* @Component({
* template: `
* <ion-content></ion-content>
* <ion-footer>
* <ion-toolbar>
* <ion-title>Footer</ion-title>
* </ion-toolbar>
* </ion-footer>
* `
* })
* ```
*
*/
@Directive({
selector: 'ion-footer'
})
export class Footer extends Ion {
constructor(config: Config, elementRef: ElementRef, renderer: Renderer, @Optional() viewCtrl: ViewController) {
super(config, elementRef, renderer);
this._setMode('footer', config.get('mode'));
viewCtrl && viewCtrl._setFooter(this);
}
}
/**
* @private
*/
export class ToolbarBase extends Ion {
private _title: ToolbarTitle;
constructor(config: Config, elementRef: ElementRef, renderer: Renderer) {
super(config, elementRef, renderer);
}
/**
* @private
*/
_setTitle(titleCmp: ToolbarTitle) {
this._title = titleCmp;
}
/**
* @private
* Returns the toolbar title text if it exists or an empty string
*/
getTitleText() {
return (this._title && this._title.getTitleText()) || '';
}
}
/**
* @name Toolbar
* @description
* A Toolbar is a generic bar that is positioned above or below content.
* Unlike a [Navbar](../../navbar/Navbar), a toolbar can be used as a subheader.
* When toolbars are placed within an `<ion-header>` or `<ion-footer>`,
* the toolbars stay fixed in their respective location. When placed within
* `<ion-content>`, toolbars will scroll with the content.
*
*
* ### Buttons in a Toolbar
* Buttons placed in a toolbar should be placed inside of the `<ion-buttons>`
* element. An exception to this is a [menuToggle](../../menu/MenuToggle) button.
* It should not be placed inside of the `<ion-buttons>` element. Both the
* `<ion-buttons>` element and the `menuToggle` can be positioned inside of the
* toolbar using different properties. The below chart has a description of each
* property.
*
* | Property | Description |
* |-------------|-----------------------------------------------------------------------------------------------------------------------|
* | `start` | Positions element to the left of the content in `ios` mode, and directly to the right in `md` and `wp` mode. |
* | `end` | Positions element to the right of the content in `ios` mode, and to the far right in `md` and `wp` mode. |
* | `left` | Positions element to the left of all other elements. |
* | `right` | Positions element to the right of all other elements. |
*
*
* ### Header / Footer Box Shadow
* In `md` mode, the `ion-header` will receive a box-shadow on the bottom, and the
* `ion-footer` will receive a box-shadow on the top. This can be removed by adding
* the `no-shadow` attribute to the element.
*
* ```html
* <ion-header no-shadow>
* <ion-toolbar>
* <ion-title>Header</ion-title>
* </ion-toolbar>
* </ion-header>
*
* <ion-content>
* </ion-content>
*
* <ion-footer no-shadow>
* <ion-toolbar>
* <ion-title>Footer</ion-title>
* </ion-toolbar>
* </ion-footer>
* ```
*
* ### Toolbar Borders
* Toolbars can be stacked up vertically in `<ion-header>`, `<ion-content>`, and
* `<ion-footer>` elements. In `ios` mode, toolbars have borders on the top and
* bottom. To hide both borders, the `no-border` attribute should be used on the
* `ion-toolbar`. To hide the top or bottom border, the `no-border-top` and
* `no-border-bottom` attribute should be used.
*
* ```html
* <ion-header no-shadow>
* <ion-toolbar no-border-bottom>
* <ion-title>Header</ion-title>
* </ion-toolbar>
* <ion-toolbar no-border>
* <ion-title>Subheader</ion-title>
* </ion-toolbar>
* <ion-toolbar no-border-top>
* <ion-title>Another Header</ion-title>
* </ion-toolbar>
* </ion-header>
*
* <ion-content>
* </ion-content>
* ```
*
*
* @usage
* ```html
* <ion-header no-shadow>
*
* <ion-toolbar no-border-bottom>
* <ion-buttons start>
* <button ion-button>
* <ion-icon name="contact"></ion-icon>
* </button>
* <button ion-button>
* <ion-icon name="search"></ion-icon>
* </button>
* </ion-buttons>
* <ion-title>My Toolbar Title</ion-title>
* </ion-toolbar>
*
* <ion-toolbar no-border-top>
* <ion-title>I'm a subheader</ion-title>
* </ion-toolbar>
*
* <ion-header>
*
*
* <ion-content>
*
* <ion-toolbar>
* <ion-title>Scrolls with the content</ion-title>
* </ion-toolbar>
*
* </ion-content>
*
*
* <ion-footer>
*
* <ion-toolbar no-border>
* <ion-title>I'm a subfooter</ion-title>
* <ion-buttons right>
* <button ion-button>
* <ion-icon name="menu"></ion-icon>
* </button>
* </ion-buttons>
* </ion-toolbar>
*
* <ion-toolbar no-border-top>
* <ion-title>I'm a footer</ion-title>
* <ion-buttons end>
* <button ion-button>
* <ion-icon name="more"></ion-icon>
* </button>
* <button ion-button>
* <ion-icon name="options"></ion-icon>
* </button>
* </ion-buttons>
* </ion-toolbar>
*
* </ion-footer>
* ```
*
* @demo /docs/v2/demos/toolbar/
* @see {@link ../../navbar/Navbar/ Navbar API Docs}
*/
@Component({
selector: 'ion-toolbar',
template:
'<div class="toolbar-background" [ngClass]="\'toolbar-background-\' + _mode"></div>' +
'<ng-content select="[menuToggle],ion-buttons[left]"></ng-content>' +
'<ng-content select="ion-buttons[start]"></ng-content>' +
'<ng-content select="ion-buttons[end],ion-buttons[right]"></ng-content>' +
'<div class="toolbar-content" [ngClass]="\'toolbar-content-\' + _mode">' +
'<ng-content></ng-content>' +
'</div>',
host: {
'class': 'toolbar',
'[class.statusbar-padding]': '_sbPadding'
},
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class Toolbar extends ToolbarBase {
/** @private */
_sbPadding: boolean;
/**
* @input {string} The predefined color to use. For example: `"primary"`, `"secondary"`, `"danger"`.
*/
@Input()
set color(val: string) {
this._setColor('toolbar', val);
}
/**
* @input {string} The mode to apply to this component.
*/
@Input()
set mode(val: string) {
this._setMode('toolbar', val);
}
constructor(
@Optional() viewCtrl: ViewController,
config: Config,
elementRef: ElementRef,
renderer: Renderer
) {
super(config, elementRef, renderer);
this.mode = config.get('mode');
this._sbPadding = config.getBoolean('statusbarPadding');
}
}