Skip to content

Commit

Permalink
feat(module:radio): add solid button style (#1892)
Browse files Browse the repository at this point in the history
close #1891
  • Loading branch information
Wendell authored and vthinkxie committed Aug 3, 2018
1 parent cea0e51 commit 945a924
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 0 deletions.
1 change: 1 addition & 0 deletions components/radio/doc/index.en-US.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ radio group,wrap a group of `nz-radio`。
| `[nzDisabled]` | Disable all radio buttons | boolean | false |
| `[nzSize]` | Size, only on radio style | `large` `default` `small` | `default` |
| `(ngModelChange)` | the callback function when current selected `nz-radio` value change | `EventEmitter<string>` | - |
| `[nzButtonStyle]` | style type of radio button | `outline``solid` | `outline` |

## Methods

Expand Down
1 change: 1 addition & 0 deletions components/radio/doc/index.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ title: Radio
| `[nzDisabled]` | 设定所有 `nz-radio` disable 状态 | boolean | false |
| `[nzSize]` | 大小,只对按钮样式生效 | `large``default``small` | `default` |
| `(ngModelChange)` | 选中变化时回调 | `EventEmitter<boolean>` | - |
| `[nzButtonStyle]` | RadioButton 的风格样式,目前有描边和填色两种风格 | `outline``solid` | `outline` |

## 方法

Expand Down
8 changes: 8 additions & 0 deletions components/radio/nz-radio-group.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { isNotNil } from '../core/util/check';
import { toBoolean } from '../core/util/convert';

export type NzRadioGroupSizeType = 'large' | 'default' | 'small';
export type NzRadioButtonStyle = 'outline' | 'solid';

import { NzRadioButtonComponent } from './nz-radio-button.component';
import { NzRadioComponent } from './nz-radio.component';
Expand Down Expand Up @@ -72,6 +73,8 @@ export class NzRadioGroupComponent implements AfterContentInit, ControlValueAcce
return this._name;
}

@Input() nzButtonStyle: NzRadioButtonStyle = 'outline';

updateDisabledState(): void {
if (isNotNil(this.nzDisabled)) {
this.radios.forEach((radio) => {
Expand Down Expand Up @@ -104,6 +107,11 @@ export class NzRadioGroupComponent implements AfterContentInit, ControlValueAcce
return this.nzSize === 'small';
}

@HostBinding('class.ant-radio-group-solid')
get isSolid(): boolean {
return this.nzButtonStyle === 'solid';
}

addRadio(radio: NzRadioComponent | NzRadioButtonComponent): void {
this.radios.push(radio);
radio.nzChecked = radio.nzValue === this.value;
Expand Down
28 changes: 28 additions & 0 deletions components/radio/nz-radio.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,19 @@ describe('radio', () => {
expect(testComponent.value).toBe('A');
}));
});
describe('radio group solid', () => {
let fixture;
let radioGroup;
beforeEach(() => {
fixture = TestBed.createComponent(NzTestRadioGroupSolidComponent);
fixture.detectChanges();
radioGroup = fixture.debugElement.query(By.directive(NzRadioGroupComponent));
it('should support solid css', () => {
fixture.detectChanges();
expect(radioGroup.nativeElement.classList).toContain('ant-radio-group-solid');
});
});
});
describe('radio form', () => {
let fixture;
let testComponent;
Expand Down Expand Up @@ -410,3 +423,18 @@ export class NzTestRadioGroupDisabledFormComponent implements OnInit {
});
}
}

@Component({
selector: 'nz-test-radui-group-solid',
template: `
<nz-radio-group [(ngModel)]="value" [nzButtonStyle]="'solid'">
<label nz-radio-button nzValue="A">A</label>
<label nz-radio-button nzValue="B">B</label>
<label nz-radio-button nzValue="C" [nzDisabled]="singleDisabled">C</label>
<label nz-radio-button nzValue="D">D</label>
</nz-radio-group>`
})
export class NzTestRadioGroupSolidComponent {
value = 'A';
singleDisabled = false;
}
16 changes: 16 additions & 0 deletions components/radio/style/index.less
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,22 @@ span.@{radio-prefix-cls} + * {
padding: 0 @control-padding-horizontal-sm - 1px;
}

.@{radio-group-prefix-cls}-solid &-checked:not(&-disabled) {
background: @radio-dot-color;
border-color: @radio-dot-color;
color: #fff;
&:hover {
border-color: @radio-button-hover-color;
background: @radio-button-hover-color;
color: #fff;
}
&:active {
border-color: @radio-button-active-color;
background: @radio-button-active-color;
color: #fff;
}
}

&:not(:first-child) {
&::before {
content: "";
Expand Down

0 comments on commit 945a924

Please sign in to comment.