-
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(rating): add config service to provide default values
- Loading branch information
1 parent
925a3cf
commit 8b7047d
Showing
11 changed files
with
123 additions
and
8 deletions.
There are no files selected for viewing
3 changes: 3 additions & 0 deletions
3
demo/src/app/components/rating/demos/config/config.component.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,3 @@ | ||
<p>This rating uses customized default values.</p> | ||
|
||
<ngb-rating [rate]="3"></ngb-rating> |
15 changes: 15 additions & 0 deletions
15
demo/src/app/components/rating/demos/config/config.component.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,15 @@ | ||
import {Component} from '@angular/core'; | ||
import {NgbRatingConfig} from '@ng-bootstrap/ng-bootstrap'; | ||
|
||
@Component({ | ||
selector: 'ngbd-rating-config', | ||
templateUrl: './config.component.html', | ||
providers: [NgbRatingConfig] // add NgbRatingConfig to the component providers | ||
}) | ||
export class RatingConfigComponent { | ||
constructor(config: NgbRatingConfig) { | ||
// customize default values of ratings used by this component tree | ||
config.max = 5; | ||
config.readonly = 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,10 +1,15 @@ | ||
import {RatingBasicComponent} from './basic/basic.component'; | ||
import {RatingConfigComponent} from './config/config.component'; | ||
|
||
export const DEMO_DIRECTIVES = [RatingBasicComponent]; | ||
export const DEMO_DIRECTIVES = [RatingBasicComponent, RatingConfigComponent]; | ||
|
||
export const DEMO_SNIPPETS = { | ||
basic: { | ||
code: require('!!prismjs?lang=typescript!./basic/basic.component'), | ||
markup: require('!!prismjs?lang=markup!./basic/basic.component.html') | ||
}, | ||
config: { | ||
code: require('!!prismjs?lang=typescript!./config/config.component'), | ||
markup: require('!!prismjs?lang=markup!./config/config.component.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 |
---|---|---|
@@ -1,6 +1,12 @@ | ||
<ngbd-content-wrapper component="Rating"> | ||
<ngbd-api-docs directive="NgbRating"></ngbd-api-docs> | ||
<ngbd-api-docs-config type="NgbRatingConfig"></ngbd-api-docs-config> | ||
<ngbd-example-box demoTitle="Basic demo" [htmlSnippet]="snippets.basic.markup" [tsSnippet]="snippets.basic.code"> | ||
<ngbd-rating-basic></ngbd-rating-basic> | ||
</ngbd-example-box> | ||
<ngbd-example-box demoTitle="Global configuration of ratings" | ||
[htmlSnippet]="snippets.config.markup" | ||
[tsSnippet]="snippets.config.code"> | ||
<ngbd-rating-config></ngbd-rating-config> | ||
</ngbd-example-box> | ||
</ngbd-content-wrapper> |
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,10 @@ | ||
import {NgbRatingConfig} from './rating-config'; | ||
|
||
describe('ngb-rating-config', () => { | ||
it('should have sensible default values', () => { | ||
const config = new NgbRatingConfig(); | ||
|
||
expect(config.max).toBe(10); | ||
expect(config.readonly).toBe(false); | ||
}); | ||
}); |
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,12 @@ | ||
import {Injectable} from '@angular/core'; | ||
|
||
/** | ||
* Configuration service for the NgbRating 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 ratings used in the application. | ||
*/ | ||
@Injectable() | ||
export class NgbRatingConfig { | ||
max = 10; | ||
readonly = false; | ||
} |
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,8 +1,16 @@ | ||
import {NgModule} from '@angular/core'; | ||
import {CommonModule} from '@angular/common'; | ||
import {NgbRatingConfig} from './rating-config'; | ||
|
||
import {NGB_RATING_DIRECTIVES} from './rating'; | ||
|
||
@NgModule({declarations: NGB_RATING_DIRECTIVES, exports: NGB_RATING_DIRECTIVES, imports: [CommonModule]}) | ||
export {NgbRatingConfig} from './rating-config'; | ||
|
||
@NgModule({ | ||
declarations: NGB_RATING_DIRECTIVES, | ||
exports: NGB_RATING_DIRECTIVES, | ||
imports: [CommonModule], | ||
providers: [NgbRatingConfig] | ||
}) | ||
export class NgbRatingModule { | ||
} |
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