Skip to content

Commit 5f62d14

Browse files
committed
add examples and readme
1 parent c331450 commit 5f62d14

20 files changed

+629
-104
lines changed

src/demo-app/data-table/data-table-demo.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,9 @@
4343
</cdk-table>
4444

4545
<md-paginator #paginator
46+
[listLength]="_peopleDatabase.data.length"
4647
[currentPageIndex]="0"
4748
[pageLength]="10"
48-
[listLength]="_peopleDatabase.data.length"
4949
[pageLengthOptions]="[5, 10, 25, 100]">
5050
</md-paginator>
5151
</div>

src/lib/core/testing/jasmine-matchers.ts

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,35 @@
1010
* Collection of useful custom jasmine matchers for tests.
1111
*/
1212
export const customMatchers: jasmine.CustomMatcherFactories = {
13+
/** Matcher verifying that the element has the expected role attribute. */
1314
toBeRole: () => {
1415
return {
1516
compare: function (element: Element, expectedRole: string) {
16-
const result: jasmine.CustomMatcherResult = {pass: false};
17-
const actualRole = element.getAttribute('role');
18-
19-
result.pass = actualRole === expectedRole;
20-
result.message = `Expected role for ${element.tagName} to be ${expectedRole}`;
21-
22-
if (!result.pass) {
23-
result.message += ` but was ${actualRole}`;
24-
}
17+
return checkElementAttribute(element, 'role', expectedRole);
18+
}
19+
};
20+
},
2521

26-
return result;
22+
/** Matcher verifying that the element has the expected aria label. */
23+
toHaveAriaLabel: () => {
24+
return {
25+
compare: function (element: Element, expectedAriaLabel: string) {
26+
return checkElementAttribute(element, 'aria-label', expectedAriaLabel);
2727
}
2828
};
29-
}
29+
},
3030
};
31+
32+
function checkElementAttribute(element, attr, expectation): jasmine.CustomMatcherResult {
33+
const result: jasmine.CustomMatcherResult = {pass: false};
34+
const actual = element.getAttribute(attr);
35+
36+
result.pass = actual === expectation;
37+
result.message = `Expected aria-label for ${element.tagName} to be ${expectation}`;
38+
39+
if (!result.pass) {
40+
result.message += ` but was ${actual}`;
41+
}
42+
43+
return result;
44+
}

src/lib/core/theming/_all-theme.scss

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
@import '../../input/input-theme';
1515
@import '../../list/list-theme';
1616
@import '../../menu/menu-theme';
17+
@import '../../paginator/paginator-theme';
1718
@import '../../progress-bar/progress-bar-theme';
1819
@import '../../progress-spinner/progress-spinner-theme';
1920
@import '../../radio/radio-theme';
@@ -44,6 +45,7 @@
4445
@include mat-input-theme($theme);
4546
@include mat-list-theme($theme);
4647
@include mat-menu-theme($theme);
48+
@include mat-paginator-theme($theme);
4749
@include mat-progress-bar-theme($theme);
4850
@include mat-progress-spinner-theme($theme);
4951
@include mat-radio-theme($theme);

src/lib/core/typography/_all-typography.scss

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
@import '../../input/input-theme';
1313
@import '../../list/list-theme';
1414
@import '../../menu/menu-theme';
15+
@import '../../paginator/paginator-theme';
1516
@import '../../progress-bar/progress-bar-theme';
1617
@import '../../progress-spinner/progress-spinner-theme';
1718
@import '../../radio/radio-theme';
@@ -41,6 +42,7 @@
4142
@include mat-icon-typography($config);
4243
@include mat-input-typography($config);
4344
@include mat-menu-typography($config);
45+
@include mat-paginator-typography($config);
4446
@include mat-progress-bar-typography($config);
4547
@include mat-progress-spinner-typography($config);
4648
@include mat-radio-typography($config);
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
@import '../core/theming/palette';
2+
@import '../core/theming/theming';
3+
@import '../core/typography/typography-utils';
4+
5+
6+
@mixin mat-paginator-theme($theme) {
7+
$foreground: map-get($theme, foreground);
8+
9+
.mat-paginator,
10+
.mat-paginator-page-length-select .mat-select-trigger {
11+
color: mat-color($foreground, secondary-text);
12+
}
13+
14+
.mat-paginator-increment,
15+
.mat-paginator-decrement {
16+
border-top: 2px solid mat-color($foreground, 'icon');
17+
border-right: 2px solid mat-color($foreground, 'icon');
18+
19+
.mat-icon-button[disabled] & {
20+
border-color: mat-color($foreground, 'disabled');
21+
}
22+
}
23+
}
24+
25+
@mixin mat-paginator-typography($config) {
26+
.mat-paginator {
27+
font: {
28+
family: mat-font-family($config);
29+
size: mat-font-size($config, caption);
30+
}
31+
}
32+
33+
.mat-paginator-page-length-select .mat-select-trigger {
34+
font: {
35+
family: mat-font-family($config);
36+
size: mat-font-size($config, caption);
37+
}
38+
}
39+
}

src/lib/paginator/index.ts

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,33 @@
1+
/**
2+
* @license
3+
* Copyright Google Inc. All Rights Reserved.
4+
*
5+
* Use of this source code is governed by an MIT-style license that can be
6+
* found in the LICENSE file at https://angular.io/license
7+
*/
8+
19
import {NgModule} from '@angular/core';
210
import {CommonModule} from '@angular/common';
311
import {FormsModule} from '@angular/forms';
412
import {MdCommonModule, OverlayModule} from '../core';
5-
import {MdButtonModule} from '../button';
6-
import {MdSelectModule} from '../select';
13+
import {MdButtonModule} from '../button/index';
14+
import {MdSelectModule} from '../select/index';
715
import {MdPaginator} from './paginator';
816
import {MdPaginatorIntl} from './paginator-intl';
9-
import {MdTooltipModule} from '../tooltip';
17+
import {MdTooltipModule} from '../tooltip/index';
1018

1119

1220
@NgModule({
1321
imports: [
1422
CommonModule,
1523
FormsModule,
1624
MdButtonModule,
17-
MdCommonModule,
1825
MdSelectModule,
1926
MdTooltipModule,
20-
OverlayModule,
2127
],
2228
exports: [MdPaginator],
2329
declarations: [MdPaginator],
24-
providers: [
25-
MdPaginatorIntl,
26-
],
30+
providers: [MdPaginatorIntl],
2731
})
2832
export class MdPaginatorModule {}
2933

src/lib/paginator/paginator-intl.ts

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,40 @@
1-
import {Injectable} from '@angular/core';
1+
/**
2+
* @license
3+
* Copyright Google Inc. All Rights Reserved.
4+
*
5+
* Use of this source code is governed by an MIT-style license that can be
6+
* found in the LICENSE file at https://angular.io/license
7+
*/
28

9+
import {Injectable} from '@angular/core';
310

4-
/** Paginator labels that require internationalization. */
11+
/**
12+
* Paginator labels that require internationalization. To modify the labels and text displayed,
13+
* extend this class with custom values and inject it as a custom provider.
14+
*/
515
@Injectable()
616
export class MdPaginatorIntl {
717
/** A label for the page size selector. */
818
itemsPerPageLabel = 'Items per page:';
919

1020
/** A label for the button that increments the current page. */
11-
incrementLabel = 'Next page';
21+
nextPageLabel = 'Next page';
1222

1323
/** A label for the button that decrements the current page. */
14-
decrementLabel = 'Previous page';
24+
previousPageLabel = 'Previous page';
1525

1626
getRangeLabel(currentPage: number, pageSize: number, listLength: number) {
27+
if (listLength == 0 || pageSize == 0) { return `0 of ${listLength}`}
28+
29+
listLength = Math.max(listLength, 0);
30+
1731
const startIndex = currentPage * pageSize;
18-
const endIndex = Math.min(startIndex + pageSize, listLength);
1932

20-
return `${currentPage * pageSize + 1} - ${endIndex} of ${listLength}`;
33+
// If the start index exceeds the list length, do not try and fix the end index to the end.
34+
const endIndex = startIndex < listLength ?
35+
Math.min(startIndex + pageSize, listLength) :
36+
startIndex + pageSize;
37+
38+
return `${startIndex + 1} - ${endIndex} of ${listLength}`;
2139
}
2240
}

src/lib/paginator/paginator.html

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,39 @@
11
<div class="mat-paginator-page-length-select">
2-
{{_intl.itemsPerPageLabel}}
3-
<md-select [ngModel]="pageLength"
4-
[attr.aria-label]="_intl.itemsPerPageLabel"
2+
<div class="mat-paginator-items-per-page-label">
3+
{{_intl.itemsPerPageLabel}}
4+
</div>
5+
6+
<md-select *ngIf="_displayedPageLengthOptions.length > 1"
7+
[ngModel]="pageLength"
8+
[aria-label]="_intl.itemsPerPageLabel"
59
(change)="_changePageLength($event.value)">
6-
<md-option *ngFor="let pageLengthOption of pageLengthOptions" [value]="pageLengthOption">
10+
<md-option *ngFor="let pageLengthOption of _displayedPageLengthOptions" [value]="pageLengthOption">
711
{{pageLengthOption}}
812
</md-option>
913
</md-select>
14+
15+
<div *ngIf="_displayedPageLengthOptions.length <= 1">{{pageLength}}</div>
1016
</div>
1117

1218
<div class="mat-paginator-range-label">
1319
{{_intl.getRangeLabel(currentPageIndex, pageLength, listLength)}}
1420
</div>
1521

1622
<button md-icon-button
17-
class="mat-paginator-increment-button"
18-
(click)="incrementPage(-1)"
19-
[attr.aria-label]="_intl.decrementLabel"
20-
[mdTooltip]="_intl.decrementLabel"
23+
class="mat-paginator-navigation-button mat-paginator-navigation-previous"
24+
(click)="navigateToPreviousPage()"
25+
[attr.aria-label]="_intl.previousPageLabel"
26+
[mdTooltip]="_intl.previousPageLabel"
2127
[mdTooltipPosition]="'above'"
22-
[disabled]="!_canIncrementPage(-1)">
28+
[disabled]="!canNavigateToPreviousPage(-1)">
2329
<div class="mat-paginator-increment"></div>
2430
</button>
2531
<button md-icon-button
26-
class="mat-paginator-increment-button"
27-
(click)="incrementPage(1)"
28-
[attr.aria-label]="_intl.incrementLabel"
29-
[mdTooltip]="_intl.incrementLabel"
32+
class="mat-paginator-navigation-button mat-paginator-navigation-next"
33+
(click)="navigateToNextPage()"
34+
[attr.aria-label]="_intl.nextPageLabel"
35+
[mdTooltip]="_intl.nextPageLabel"
3036
[mdTooltipPosition]="'above'"
31-
[disabled]="!_canIncrementPage(1)">
37+
[disabled]="!canNavigateToNextPage(1)">
3238
<div class="mat-paginator-decrement"></div>
3339
</button>

src/lib/paginator/paginator.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
`<md-paginator>` is a component that provides navigation between paged information. It supports
2+
the changing of page length as well as giving the user buttons to navigate to the previous or next
3+
page.
4+
5+
<!-- example(pagination-overview) -->
6+
7+
To use the paginator, you must provide the total length of the pagination information list and
8+
the length of each page. To allow the end-user to change the page length list, you may optionally
9+
input an array of numbers that the user may select from.
10+
11+
Additionally you may provide an input of what the current page index should be. Note that
12+
a non-zero index will be interpretted to display the first page, whereas if the page index is beyond
13+
the max number of pages, then this will be reflected to the user (e.g. `140 - 149 of 100 items`).
14+
15+
When the user changes the page length, or navigates between pages, the paginator will output a
16+
`PageChangeEvent` that contains the paginator's context, including the list length,
17+
18+
### Internationalization
19+
In order to support internationalization or customization of the displayed text, the paginator
20+
supports an injection of a custom class that extends `MdPaginatorIntl`. This will allow you to
21+
change the following:
22+
1. The label for the length of each page.
23+
2. The range text displayed to the user.
24+
3. The tooltip messages on the navigation buttons.

src/lib/paginator/paginator.scss

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,23 @@
22
display: flex;
33
align-items: center;
44
justify-content: flex-end;
5-
font-size: 12px;
65
min-height: 56px;
76
padding: 0 8px;
8-
color: rgba(0, 0, 0, 0.54);
7+
}
8+
9+
.mat-paginator-items-per-page-label {
10+
margin: 0 4px;
911
}
1012

1113
.mat-paginator-page-length-select {
1214
display: flex;
1315
align-items: center;
1416

1517
.mat-select {
16-
margin: 0 8px;
18+
margin: 0 4px;
1719
}
1820

1921
.mat-select-trigger {
20-
font-size: 12px;
2122
min-width: 56px;
2223
}
2324
}
@@ -38,12 +39,6 @@
3839
.mat-paginator-decrement {
3940
width: 8px;
4041
height: 8px;
41-
border-top: 2px solid #666;
42-
border-right: 2px solid #666;
43-
44-
.mat-icon-button[disabled] & {
45-
border-color: rgba(0, 0, 0, 0.25);
46-
}
4742
}
4843

4944
.mat-paginator-decrement,

0 commit comments

Comments
 (0)