-
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(popover): add config service to provide default values
- Loading branch information
1 parent
5a0226d
commit a58588c
Showing
10 changed files
with
129 additions
and
11 deletions.
There are no files selected for viewing
4 changes: 4 additions & 0 deletions
4
demo/src/app/components/popover/demos/config/popover-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,4 @@ | ||
<button type="button" class="btn btn-secondary" | ||
ngbPopover="This popover gets its inputs from the customized configuration" title="Customized popover"> | ||
Customized popover | ||
</button> |
15 changes: 15 additions & 0 deletions
15
demo/src/app/components/popover/demos/config/popover-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,15 @@ | ||
import {Component} from '@angular/core'; | ||
import {NgbPopoverConfig} from '@ng-bootstrap/ng-bootstrap'; | ||
|
||
@Component({ | ||
selector: 'ngbd-popover-config', | ||
templateUrl: './popover-config.html', | ||
providers: [NgbPopoverConfig] // add NgbPopoverConfig to the component providers | ||
}) | ||
export class NgbdPopoverConfig { | ||
constructor(config: NgbPopoverConfig) { | ||
// customize default values of popovers used by this component tree | ||
config.placement = 'right'; | ||
config.triggers = 'hover'; | ||
} | ||
} |
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 {NgbdPopoverBasic} from './basic/popover-basic'; | ||
import {NgbdPopoverTplcontent} from './tplcontent/popover-tplcontent'; | ||
import {NgbdPopoverTriggers} from './triggers/popover-triggers'; | ||
import {NgbdPopoverConfig} from './config/popover-config'; | ||
|
||
export const DEMO_DIRECTIVES = [NgbdPopoverBasic, NgbdPopoverTplcontent, NgbdPopoverTriggers]; | ||
export const DEMO_DIRECTIVES = [NgbdPopoverBasic, NgbdPopoverTplcontent, NgbdPopoverTriggers, NgbdPopoverConfig]; | ||
|
||
export const DEMO_SNIPPETS = { | ||
basic: { | ||
code: require('!!prismjs?lang=typescript!./basic/popover-basic'), | ||
markup: require('!!prismjs?lang=markup!./basic/popover-basic.html')}, | ||
markup: require('!!prismjs?lang=markup!./basic/popover-basic.html') | ||
}, | ||
tplcontent: { | ||
code: require('!!prismjs?lang=typescript!./tplcontent/popover-tplcontent'), | ||
markup: require('!!prismjs?lang=markup!./tplcontent/popover-tplcontent.html')}, | ||
markup: require('!!prismjs?lang=markup!./tplcontent/popover-tplcontent.html') | ||
}, | ||
triggers: { | ||
code: require('!!prismjs?lang=typescript!./triggers/popover-triggers'), | ||
markup: require('!!prismjs?lang=markup!./triggers/popover-triggers.html')} | ||
markup: require('!!prismjs?lang=markup!./triggers/popover-triggers.html') | ||
}, | ||
config: { | ||
code: require('!!prismjs?lang=typescript!./config/popover-config'), | ||
markup: require('!!prismjs?lang=markup!./config/popover-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,10 @@ | ||
import {NgbPopoverConfig} from './popover-config'; | ||
|
||
describe('ngb-popover-config', () => { | ||
it('should have sensible default values', () => { | ||
const config = new NgbPopoverConfig(); | ||
|
||
expect(config.placement).toBe('top'); | ||
expect(config.triggers).toBe('click'); | ||
}); | ||
}); |
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 NgbPopover directive. | ||
* 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 popovers used in the application. | ||
*/ | ||
@Injectable() | ||
export class NgbPopoverConfig { | ||
placement: 'top' | 'bottom' | 'left' | 'right' = 'top'; | ||
triggers = 'click'; | ||
} |
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,7 +1,15 @@ | ||
import {NgModule} from '@angular/core'; | ||
|
||
import {NGB_POPOVER_DIRECTIVES, NgbPopoverWindow} from './popover'; | ||
import {NgbPopoverConfig} from './popover-config'; | ||
|
||
@NgModule({declarations: NGB_POPOVER_DIRECTIVES, exports: NGB_POPOVER_DIRECTIVES, entryComponents: [NgbPopoverWindow]}) | ||
export {NgbPopoverConfig} from './popover-config'; | ||
|
||
@NgModule({ | ||
declarations: NGB_POPOVER_DIRECTIVES, | ||
exports: NGB_POPOVER_DIRECTIVES, | ||
entryComponents: [NgbPopoverWindow], | ||
providers: [NgbPopoverConfig] | ||
}) | ||
export class NgbPopoverModule { | ||
} |
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