-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(pagination): add config service to provide default values (#665)
- Loading branch information
Showing
10 changed files
with
162 additions
and
13 deletions.
There are no files selected for viewing
2 changes: 2 additions & 0 deletions
2
demo/src/app/components/pagination/demos/config/pagination-config.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
<p>This pagination uses custom default values</p> | ||
<ngb-pagination [collectionSize]="70" [(page)]="page"></ngb-pagination> |
17 changes: 17 additions & 0 deletions
17
demo/src/app/components/pagination/demos/config/pagination-config.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import {Component} from '@angular/core'; | ||
import {NgbPaginationConfig} from '@ng-bootstrap/ng-bootstrap'; | ||
|
||
@Component({ | ||
selector: 'ngbd-pagination-config', | ||
templateUrl: './pagination-config.html', | ||
providers: [NgbPaginationConfig] // add NgbPaginationConfig to the component providers | ||
}) | ||
export class NgbdPaginationConfig { | ||
page = 4; | ||
|
||
constructor(config: NgbPaginationConfig) { | ||
// customize default values of paginations used by this component tree | ||
config.size = 'sm'; | ||
config.boundaryLinks = true; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,25 @@ | ||
import {NgbdPaginationAdvanced} from './advanced/pagination-advanced'; | ||
import {NgbdPaginationBasic} from './basic/pagination-basic'; | ||
import {NgbdPaginationSize} from './size/pagination-size'; | ||
import {NgbdPaginationConfig} from './config/pagination-config'; | ||
|
||
export const DEMO_DIRECTIVES = [NgbdPaginationAdvanced, NgbdPaginationBasic, NgbdPaginationSize]; | ||
export const DEMO_DIRECTIVES = [NgbdPaginationAdvanced, NgbdPaginationBasic, NgbdPaginationSize, NgbdPaginationConfig]; | ||
|
||
export const DEMO_SNIPPETS = { | ||
advanced: { | ||
code: require('!!prismjs?lang=typescript!./advanced/pagination-advanced'), | ||
markup: require('!!prismjs?lang=markup!./advanced/pagination-advanced.html')}, | ||
markup: require('!!prismjs?lang=markup!./advanced/pagination-advanced.html') | ||
}, | ||
basic: { | ||
code: require('!!prismjs?lang=typescript!./basic/pagination-basic'), | ||
markup: require('!!prismjs?lang=markup!./basic/pagination-basic.html')}, | ||
markup: require('!!prismjs?lang=markup!./basic/pagination-basic.html') | ||
}, | ||
size: { | ||
code: require('!!prismjs?lang=typescript!./size/pagination-size'), | ||
markup: require('!!prismjs?lang=markup!./size/pagination-size.html')} | ||
markup: require('!!prismjs?lang=markup!./size/pagination-size.html') | ||
}, | ||
config: { | ||
code: require('!!prismjs?lang=typescript!./config/pagination-config'), | ||
markup: require('!!prismjs?lang=markup!./config/pagination-config.html') | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import {NgbPaginationConfig} from './pagination-config'; | ||
|
||
describe('ngb-pagination-config', () => { | ||
it('should have sensible default values', () => { | ||
const config = new NgbPaginationConfig(); | ||
|
||
expect(config.boundaryLinks).toBe(false); | ||
expect(config.directionLinks).toBe(true); | ||
expect(config.ellipses).toBe(true); | ||
expect(config.maxSize).toBe(0); | ||
expect(config.pageSize).toBe(10); | ||
expect(config.rotate).toBe(false); | ||
expect(config.size).toBeUndefined(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import {Injectable} from '@angular/core'; | ||
|
||
/** | ||
* Configuration service for the NgbPagination component. | ||
* You can inject this service, typically in your root component, and customize the values of its properties in | ||
* order to provide default values for all the paginations used in the application. | ||
*/ | ||
@Injectable() | ||
export class NgbPaginationConfig { | ||
boundaryLinks = false; | ||
directionLinks = true; | ||
ellipses = true; | ||
maxSize = 0; | ||
pageSize = 10; | ||
rotate = false; | ||
size: 'sm' | 'lg'; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters