-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(dropdown): add config service to provide default values
- Loading branch information
1 parent
a58588c
commit e97d260
Showing
10 changed files
with
126 additions
and
6 deletions.
There are no files selected for viewing
10 changes: 10 additions & 0 deletions
10
demo/src/app/components/dropdown/demos/config/dropdown-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,10 @@ | ||
<p>This dropdown uses customized default values.</p> | ||
|
||
<div ngbDropdown> | ||
<button class="btn btn-outline-primary" id="dropdownMenu3" ngbDropdownToggle>Toggle</button> | ||
<div class="dropdown-menu" aria-labelledby="dropdownMenu3"> | ||
<button class="dropdown-item">Action - 1</button> | ||
<button class="dropdown-item">Another Action</button> | ||
<button class="dropdown-item">Something else is here</button> | ||
</div> | ||
</div> |
15 changes: 15 additions & 0 deletions
15
demo/src/app/components/dropdown/demos/config/dropdown-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 {NgbDropdownConfig} from '@ng-bootstrap/ng-bootstrap'; | ||
|
||
@Component({ | ||
selector: 'ngbd-dropdown-config', | ||
templateUrl: './dropdown-config.html', | ||
providers: [NgbDropdownConfig] // add NgbDropdownConfig to the component providers | ||
}) | ||
export class NgbdDropdownConfig { | ||
constructor(config: NgbDropdownConfig) { | ||
// customize default values of dropdowns used by this component tree | ||
config.up = true; | ||
config.autoClose = 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,9 +1,15 @@ | ||
import {NgbdDropdownBasic} from './basic/dropdown-basic'; | ||
import {NgbdDropdownConfig} from './config/dropdown-config'; | ||
|
||
export const DEMO_DIRECTIVES = [NgbdDropdownBasic]; | ||
export const DEMO_DIRECTIVES = [NgbdDropdownBasic, NgbdDropdownConfig]; | ||
|
||
export const DEMO_SNIPPETS = { | ||
basic: { | ||
code: require('!!prismjs?lang=typescript!./basic/dropdown-basic'), | ||
markup: require('!!prismjs?lang=markup!./basic/dropdown-basic.html')} | ||
markup: require('!!prismjs?lang=markup!./basic/dropdown-basic.html') | ||
}, | ||
config: { | ||
code: require('!!prismjs?lang=typescript!./config/dropdown-config'), | ||
markup: require('!!prismjs?lang=markup!./config/dropdown-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,10 @@ | ||
import {NgbDropdownConfig} from './dropdown-config'; | ||
|
||
describe('ngb-dropdown-config', () => { | ||
it('should have sensible default values', () => { | ||
const config = new NgbDropdownConfig(); | ||
|
||
expect(config.up).toBe(false); | ||
expect(config.autoClose).toBe(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 |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import {Injectable, TemplateRef} from '@angular/core'; | ||
|
||
/** | ||
* Configuration service for the NgbDropdown 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 dropdowns used in the application. | ||
*/ | ||
@Injectable() | ||
export class NgbDropdownConfig { | ||
up = false; | ||
autoClose = 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,6 +1,9 @@ | ||
import {NgModule} from '@angular/core'; | ||
import {NGB_DROPDOWN_DIRECTIVES} from './dropdown'; | ||
import {NgbDropdownConfig} from './dropdown-config'; | ||
|
||
@NgModule({declarations: NGB_DROPDOWN_DIRECTIVES, exports: NGB_DROPDOWN_DIRECTIVES}) | ||
export {NgbDropdownConfig} from './dropdown-config'; | ||
|
||
@NgModule({declarations: NGB_DROPDOWN_DIRECTIVES, exports: NGB_DROPDOWN_DIRECTIVES, providers: [NgbDropdownConfig]}) | ||
export class NgbDropdownModule { | ||
} |
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