-
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(datepicker): add config service to provide default values
- Loading branch information
Showing
11 changed files
with
169 additions
and
11 deletions.
There are no files selected for viewing
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
3 changes: 3 additions & 0 deletions
3
demo/src/app/components/datepicker/demos/config/datepicker-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,3 @@ | ||
<p>This datepicker uses customized default values.</p> | ||
|
||
<ngb-datepicker [(ngModel)]="model"></ngb-datepicker> |
24 changes: 24 additions & 0 deletions
24
demo/src/app/components/datepicker/demos/config/datepicker-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,24 @@ | ||
import {Component} from '@angular/core'; | ||
import {NgbDatepickerConfig} from '@ng-bootstrap/ng-bootstrap'; | ||
|
||
@Component({ | ||
selector: 'ngbd-datepicker-config', | ||
templateUrl: './datepicker-config.html', | ||
providers: [NgbDatepickerConfig] // add NgbDatepickerConfig to the component providers | ||
}) | ||
export class NgbdDatepickerConfig { | ||
|
||
model; | ||
|
||
constructor(config: NgbDatepickerConfig) { | ||
// customize default values of datepickers used by this component tree | ||
config.minDate = {year: 1900, month: 0, day: 1}; | ||
config.maxDate = {year: 2099, month: 11, day: 31}; | ||
|
||
// weekends are disabled | ||
config.markDisabled = (date: {year: number, month: number, day: number}) => { | ||
const d = new Date(date.year, date.month, date.day); | ||
return d.getDay() === 0 || d.getDay() === 6; | ||
}; | ||
} | ||
} |
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,9 +1,15 @@ | ||
import {NgbdDatepickerBasic} from './basic/datepicker-basic'; | ||
import {NgbdDatepickerConfig} from './config/datepicker-config'; | ||
|
||
export const DEMO_DIRECTIVES = [NgbdDatepickerBasic]; | ||
export const DEMO_DIRECTIVES = [NgbdDatepickerBasic, NgbdDatepickerConfig]; | ||
|
||
export const DEMO_SNIPPETS = { | ||
basic: { | ||
code: require('!!prismjs?lang=typescript!./basic/datepicker-basic'), | ||
markup: require('!!prismjs?lang=markup!./basic/datepicker-basic.html')} | ||
markup: require('!!prismjs?lang=markup!./basic/datepicker-basic.html') | ||
}, | ||
config: { | ||
code: require('!!prismjs?lang=typescript!./config/datepicker-config'), | ||
markup: require('!!prismjs?lang=markup!./config/datepicker-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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import {NgbDatepickerConfig} from './datepicker-config'; | ||
|
||
describe('ngb-datepicker-config', () => { | ||
it('should have sensible default values', () => { | ||
const config = new NgbDatepickerConfig(); | ||
|
||
expect(config.dayTemplate).toBeUndefined(); | ||
expect(config.firstDayOfWeek).toBe(1); | ||
expect(config.markDisabled).toBeUndefined(); | ||
expect(config.minDate).toBeUndefined(); | ||
expect(config.maxDate).toBeUndefined(); | ||
expect(config.showNavigation).toBe(true); | ||
expect(config.showWeekdays).toBe(true); | ||
expect(config.showWeekNumbers).toBe(false); | ||
expect(config.startDate).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,20 @@ | ||
import {Injectable, TemplateRef} from '@angular/core'; | ||
import {DayTemplateContext} from './datepicker-day-template-context'; | ||
|
||
/** | ||
* Configuration service for the NgbDatepicker 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 datepickers used in the application. | ||
*/ | ||
@Injectable() | ||
export class NgbDatepickerConfig { | ||
dayTemplate: TemplateRef<DayTemplateContext>; | ||
firstDayOfWeek = 1; | ||
markDisabled: (date: {year: number, month: number, day: number}) => boolean; | ||
minDate: {year: number, month: number, day: number}; | ||
maxDate: {year: number, month: number, day: number}; | ||
showNavigation = true; | ||
showWeekdays = true; | ||
showWeekNumbers = false; | ||
startDate: {year: number, month: number}; | ||
} |
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
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