Skip to content

Commit b86762b

Browse files
committed
add comments, remove md-tab-body prefix
1 parent 54c2c92 commit b86762b

File tree

3 files changed

+32
-22
lines changed

3 files changed

+32
-22
lines changed

src/lib/tabs/tab-body.spec.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -174,10 +174,7 @@ describe('MdTabBody', () => {
174174
@Component({
175175
template: `
176176
<template>Tab Body Content</template>
177-
<md-tab-body [md-tab-body-content]="content"
178-
[md-tab-body-position]="position"
179-
[md-tab-body-origin]="origin">
180-
</md-tab-body>
177+
<md-tab-body [content]="content" [position]="position" [origin]="origin"></md-tab-body>
181178
`
182179
})
183180
class SimpleTabBodyApp {

src/lib/tabs/tab-body.ts

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,25 @@ import {
1717
import {TemplatePortal, PortalHostDirective, Dir, LayoutDirection} from '../core';
1818
import 'rxjs/add/operator/map';
1919

20+
/**
21+
* These position states are used internally as animation states for the tab body. Setting the
22+
* position state to left, right, or center will transition the tab body from its current
23+
* position to its respective state. If there is not current position (void, in the case of a new
24+
* tab body), then there will be no transition animation to its state.
25+
*
26+
* In the case of a new tab body that should immediately be centered with an animating transition,
27+
* then left-origin-center or right-origin-center can be used, which will use left or right as its
28+
* psuedo-prior state.
29+
*/
2030
export type MdTabBodyPositionState =
2131
'left' | 'center' | 'right' | 'left-origin-center' | 'right-origin-center';
2232

33+
/**
34+
* The origin state is an internally used state that is set on a new tab body indicating if it
35+
* began to the left or right of the prior selected index. For example, if the selected index was
36+
* set to 1, and a new tab is created and selected at index 2, then the tab body would have an
37+
* origin of right because its index was greater than the prior selected index.
38+
*/
2339
export type MdTabBodyOriginState = 'left' | 'right';
2440

2541
@Component({
@@ -44,29 +60,26 @@ export type MdTabBodyOriginState = 'left' | 'right';
4460
animate('500ms cubic-bezier(0.35, 0, 0.25, 1)')
4561
])
4662
])
47-
],
48-
host: {
49-
'md-tab-body-active': "'this._position == 'center'"
50-
}
63+
]
5164
})
5265
export class MdTabBody implements OnInit {
5366
/** The portal host inside of this container into which the tab body content will be loaded. */
5467
@ViewChild(PortalHostDirective) _portalHost: PortalHostDirective;
5568

5669
/** Event emitted when the tab begins to animate towards the center as the active tab. */
5770
@Output()
58-
onTabBodyCentering: EventEmitter<number> = new EventEmitter<number>();
71+
onCentering: EventEmitter<number> = new EventEmitter<number>();
5972

6073
/** Event emitted when the tab completes its animation towards the center. */
6174
@Output()
62-
onTabBodyCentered: EventEmitter<void> = new EventEmitter<void>(true);
75+
onCentered: EventEmitter<void> = new EventEmitter<void>(true);
6376

6477
/** The tab body content to display. */
65-
@Input('md-tab-body-content') _content: TemplatePortal;
78+
@Input('content') _content: TemplatePortal;
6679

6780
/** The shifted index position of the tab body, where zero represents the active center tab. */
6881
_position: MdTabBodyPositionState;
69-
@Input('md-tab-body-position') set position(position: number) {
82+
@Input('position') set position(position: number) {
7083
if (position < 0) {
7184
this._position = this._getLayoutDirection() == 'ltr' ? 'left' : 'right';
7285
} else if (position > 0) {
@@ -78,11 +91,11 @@ export class MdTabBody implements OnInit {
7891

7992
/** The origin position from which this tab should appear when it is centered into view. */
8093
_origin: MdTabBodyOriginState;
81-
@Input('md-tab-body-origin') set origin(origin: number) {
94+
@Input('origin') set origin(origin: number) {
8295
if (origin == null) { return; }
8396

84-
if ((this._getLayoutDirection() == 'ltr' && origin <= 0) ||
85-
(this._getLayoutDirection() == 'rtl' && origin > 0)) {
97+
const dir = this._getLayoutDirection();
98+
if ((dir == 'ltr' && origin <= 0) || (dir == 'rtl' && origin > 0)) {
8699
this._origin = 'left';
87100
} else {
88101
this._origin = 'right';
@@ -113,7 +126,7 @@ export class MdTabBody implements OnInit {
113126

114127
_onTranslateTabStarted(e: AnimationTransitionEvent) {
115128
if (this._isCenterPosition(e.toState)) {
116-
this.onTabBodyCentering.emit(this._elementRef.nativeElement.clientHeight);
129+
this.onCentering.emit(this._elementRef.nativeElement.clientHeight);
117130
}
118131
}
119132

@@ -125,7 +138,7 @@ export class MdTabBody implements OnInit {
125138

126139
// If the transition to the center is complete, emit an event.
127140
if (this._isCenterPosition(e.toState) && this._isCenterPosition(this._position)) {
128-
this.onTabBodyCentered.emit();
141+
this.onCentered.emit();
129142
}
130143
}
131144

src/lib/tabs/tab-group.html

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@
2626
[id]="_getTabContentId(i)"
2727
[attr.aria-labelledby]="_getTabLabelId(i)"
2828
[class.md-tab-body-active]="selectedIndex == i"
29-
[md-tab-body-content]="tab.content"
30-
[md-tab-body-position]="tab.position"
31-
[md-tab-body-origin]="tab.origin"
32-
(onTabBodyCentered)="_removeTabBodyWrapperHeight()"
33-
(onTabBodyCentering)="_setTabBodyWrapperHeight($event)">
29+
[content]="tab.content"
30+
[position]="tab.position"
31+
[origin]="tab.origin"
32+
(onCentered)="_removeTabBodyWrapperHeight()"
33+
(onCentering)="_setTabBodyWrapperHeight($event)">
3434
</md-tab-body>
3535
</div>

0 commit comments

Comments
 (0)