Skip to content

Commit 198ae71

Browse files
docs(buttons): add demo
Closes ng-bootstrap#324
1 parent 07fc542 commit 198ae71

10 files changed

+79
-3
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
11
<ngbd-content-wrapper component="Buttons">
22
<ngbd-api-docs directive="NgbRadioGroup"></ngbd-api-docs>
33
<ngbd-api-docs directive="NgbRadio"></ngbd-api-docs>
4+
<ngbd-example-box demoTitle="Radio buttons" [htmlSnippet]="radioHtmlContent" [tsSnippet]="radioTsContent">
5+
<ngbd-buttons-radio></ngbd-buttons-radio>
6+
</ngbd-example-box>
7+
<ngbd-example-box demoTitle="Checkbox buttons" [htmlSnippet]="checkboxHtmlContent" [tsSnippet]="checkboxTsContent">
8+
<ngbd-buttons-checkbox></ngbd-buttons-checkbox>
9+
</ngbd-example-box>
410
</ngbd-content-wrapper>
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,17 @@
11
import {Component} from '@angular/core';
22
import {ContentWrapper} from '../../shared';
3-
import {NgbdApiDocs} from '../shared/api-docs';
3+
import {ExampleBoxComponent, NgbdApiDocs} from '../shared';
4+
import {NgbdButtonsCheckbox, checkboxHtmlContent, checkboxTsContent} from './demos';
5+
import {NgbdButtonsRadio, radioHtmlContent, radioTsContent} from './demos';
46

57
@Component({
68
selector: 'ngbd-buttons',
79
template: require('./buttons.component.html'),
8-
directives: [ContentWrapper, NgbdApiDocs]
10+
directives: [ContentWrapper, ExampleBoxComponent, NgbdApiDocs, NgbdButtonsCheckbox, NgbdButtonsRadio]
911
})
10-
export class NgbdButtons {}
12+
export class NgbdButtons {
13+
checkboxHtmlContent = checkboxHtmlContent;
14+
checkboxTsContent = checkboxTsContent;
15+
radioHtmlContent = radioHtmlContent;
16+
radioTsContent = radioTsContent;
17+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import {Component} from '@angular/core';
2+
3+
@Component({
4+
selector: 'ngbd-buttons-checkbox',
5+
template: require('./checkbox.html')
6+
})
7+
export class NgbdButtonsCheckbox {
8+
model = {
9+
left: true,
10+
middle: false,
11+
right: false
12+
}
13+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<p>
2+
Check-box-like button group can be easily done with pure Angular 2, no custom directives necessary.
3+
But we include demo here for completeness.
4+
</p>
5+
<div class="btn-group" data-toggle="buttons">
6+
<label class="btn btn-primary" [class.active]="model.left">
7+
<input type="checkbox" [(ngModel)]="model.left"> Left (pre-checked)
8+
</label>
9+
<label class="btn btn-primary" [class.active]="model.middle">
10+
<input type="checkbox" [(ngModel)]="model.middle"> Middle
11+
</label>
12+
<label class="btn btn-primary" [class.active]="model.right">
13+
<input type="checkbox" [(ngModel)]="model.right"> Right
14+
</label>
15+
</div>
16+
<hr>
17+
<pre>{{model | json}}</pre>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export * from './checkbox.component';
2+
export const checkboxTsContent = require('!!prismjs?lang=typescript!./checkbox.component');
3+
export const checkboxHtmlContent = require('!!prismjs?lang=markup!./checkbox.html');
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export * from './checkbox';
2+
export * from './radio';
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export * from './radio.component';
2+
export const radioTsContent = require('!!prismjs?lang=typescript!./radio.component');
3+
export const radioHtmlContent = require('!!prismjs?lang=markup!./radio.html');
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import {Component} from '@angular/core';
2+
import {NGB_RADIO_DIRECTIVES} from '@ng-bootstrap/buttons';
3+
4+
@Component({
5+
selector: 'ngbd-buttons-radio',
6+
template: require('./radio.html'),
7+
directives: [NGB_RADIO_DIRECTIVES]
8+
})
9+
export class NgbdButtonsRadio {
10+
model = 1;
11+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<div class="btn-group" data-toggle="buttons" [(ngModel)]="model" ngbRadioGroup>
2+
<label class="btn btn-primary">
3+
<input type="radio" [value]="1"> Left (pre-checked)
4+
</label>
5+
<label class="btn btn-primary">
6+
<input type="radio" value="middle"> Middle
7+
</label>
8+
<label class="btn btn-primary">
9+
<input type="radio" [value]="false"> Right
10+
</label>
11+
</div>
12+
<hr>
13+
<pre>{{model}}</pre>

webpack.demo.js

+1
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ module.exports = function makeWebpackConfig() {
7070
alias: {
7171
'@ng-bootstrap/accordion': root('src/accordion/accordion.ts'),
7272
'@ng-bootstrap/alert': root('src/alert/alert.ts'),
73+
'@ng-bootstrap/buttons': root('src/buttons/radio.ts'),
7374
'@ng-bootstrap/collapse': root('src/collapse/collapse.ts'),
7475
'@ng-bootstrap/dropdown': root('src/dropdown/dropdown.ts')
7576
}

0 commit comments

Comments
 (0)