Skip to content

Commit

Permalink
feat(Radio): Adding ability to have icon only button radio groups (#493)
Browse files Browse the repository at this point in the history
  • Loading branch information
MagicAardvark authored and jgodi committed Jun 28, 2017
1 parent d711a1d commit 9c058ee
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 1 deletion.
11 changes: 11 additions & 0 deletions demo/pages/elements/radio/RadioDemo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { Component } from '@angular/core';
let BasicRadioTpl = require('./templates/BasicRadio.html');
let VerticalRadioTpl = require('./templates/VerticalRadio.html');
let ButtonRadioTpl = require('./templates/ButtonRadio.html');
let IconRadioTpl = require('./templates/IconRadio.html');

const template = `
<div class="container">
Expand All @@ -21,6 +22,11 @@ const template = `
<h5>Button Radio</h5>
<div class="example radio-demo">${ButtonRadioTpl}</div>
<code-snippet [code]="ButtonRadioTpl"></code-snippet>
<h5>Icon Radio</h5>
<div class="example radio-demo">${IconRadioTpl}</div>
<code-snippet [code]="IconRadioTpl"></code-snippet>
</div>
`;

Expand All @@ -32,6 +38,7 @@ export class RadioDemoComponent {
BasicRadioTpl: string = BasicRadioTpl;
VerticalRadioTpl: string = VerticalRadioTpl;
ButtonRadioTpl: string = ButtonRadioTpl;
IconRadioTpl: string = IconRadioTpl;

onChangeVertical(change) {
console.log('Vertical Radio Change:', change); // tslint:disable-line
Expand All @@ -44,4 +51,8 @@ export class RadioDemoComponent {
onChangeButton(change) {
console.log('Button Radio Change:', change); // tslint:disable-line
}

onChangeIcon(change) {
console.log('Button Icon Radio Change:', change); // tslint:disable-line
}
}
5 changes: 5 additions & 0 deletions demo/pages/elements/radio/templates/IconRadio.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<novo-radio-group>
<novo-radio button="true" theme="icon" icon="checkbox-filled" name="icon" value="one" (change)="onChangeIcon($event)"></novo-radio>
<novo-radio button="true" theme="icon" icon="checkbox-indeterminate" name="icon" value="two" (change)="onChangeIcon($event)"></novo-radio>
<novo-radio button="true" theme="icon" icon="checkbox-add" name="icon" value="three" (change)="onChangeIcon($event)"></novo-radio>
</novo-radio-group>
6 changes: 6 additions & 0 deletions src/elements/radio/Radio.scss
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ novo-radio-group {
&.unchecked {
opacity: .5;
}
&[theme="icon"] i {
margin-right: 0;
}
}
&:first-child {
button {
Expand All @@ -20,6 +23,9 @@ novo-radio-group {
border-bottom-right-radius: 3px;
border-right-width: 1px !important;
border-right-style: solid !important;
&[theme="icon"] {
border-right-width: 0px !important;
}
}
}
}
Expand Down
4 changes: 4 additions & 0 deletions src/elements/radio/Radio.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import { TestBed, async } from '@angular/core/testing';
// App
import { NovoRadioElement } from './Radio';
import { NovoButtonModule } from '../button/Button.module';

describe('Elements: NovoRadioElement', () => {
let fixture;
Expand All @@ -11,6 +12,9 @@ describe('Elements: NovoRadioElement', () => {
TestBed.configureTestingModule({
declarations: [
NovoRadioElement
],
imports: [
NovoButtonModule
]
}).compileComponents();
fixture = TestBed.createComponent(NovoRadioElement);
Expand Down
4 changes: 3 additions & 1 deletion src/elements/radio/Radio.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export class NovoRadioGroup { }
template: `
<input [name]="name" type="radio" [checked]="checked" [attr.id]="name" #radio>
<label [attr.for]="name" (click)="select($event, radio)">
<button *ngIf="button" [ngClass]="{'unchecked': !radio.checked, 'checked': radio.checked}" theme="secondary">{{ label }}</button>
<button *ngIf="button" [ngClass]="{'unchecked': !radio.checked, 'checked': radio.checked}" [theme]="theme" [icon]="icon">{{ label }}</button>
<div *ngIf="!button">
<i [ngClass]="{'bhi-radio-empty': !radio.checked, 'bhi-radio-filled': radio.checked}"></i>
{{ label }}
Expand All @@ -42,6 +42,8 @@ export class NovoRadioElement implements ControlValueAccessor {
@Input() vertical: boolean;
@Input() label: string;
@Input() button: boolean = false;
@Input() theme: string = 'secondary';
@Input() icon: string;

@Output() change: EventEmitter<any> = new EventEmitter();

Expand Down

0 comments on commit 9c058ee

Please sign in to comment.