Skip to content

Commit 86dd242

Browse files
authored
Merge pull request #346 from youda97/skeleton-radio
feat(radio): Add skeleton state
2 parents 7980050 + 69218d3 commit 86dd242

File tree

4 files changed

+44
-2
lines changed

4 files changed

+44
-2
lines changed

src/radio/radio-group.component.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,22 @@ export class RadioGroup implements OnInit, AfterContentInit, ControlValueAccesso
163163
this.markRadiosForCheck();
164164
}
165165

166+
/**
167+
* Returns the skeleton value in the `RadioGroup` if there is one.
168+
*/
169+
@Input()
170+
get skeleton(): any {
171+
return this._skeleton;
172+
}
173+
174+
/**
175+
* Sets the skeleton value for all `Radio` to the skeleton value of `RadioGroup`.
176+
*/
177+
set skeleton(value: any) {
178+
this._skeleton = value;
179+
this.updateChildren();
180+
}
181+
166182
/**
167183
* Binds 'radiogroup' value to the role attribute for `RadioGroup`.
168184
*/
@@ -181,6 +197,10 @@ export class RadioGroup implements OnInit, AfterContentInit, ControlValueAccesso
181197
* Reflects whether or not the input is disabled and cannot be selected.
182198
*/
183199
protected _disabled = false;
200+
/**
201+
* Reflects wheather or not the dropdown is loading.
202+
*/
203+
protected _skeleton = false;
184204
/**
185205
* The value of the selected option within the `RadioGroup`.
186206
*/
@@ -301,6 +321,8 @@ export class RadioGroup implements OnInit, AfterContentInit, ControlValueAccesso
301321
this.radios = updatedRadios;
302322
this.updateFocusableRadio();
303323
});
324+
325+
this.updateChildren();
304326
}
305327

306328
updateFocusableRadio() {
@@ -338,4 +360,10 @@ export class RadioGroup implements OnInit, AfterContentInit, ControlValueAccesso
338360
* Method set in registerOnChange to propagate changes back to the form.
339361
*/
340362
propagateChange = (_: any) => {};
363+
364+
protected updateChildren() {
365+
if (this.radios) {
366+
this.radios.toArray().forEach(child => child.skeleton = this.skeleton);
367+
}
368+
}
341369
}

src/radio/radio.component.spec.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@ describe("RadioComponent", () => {
6565
let fixture: ComponentFixture<Radio>;
6666
let de: DebugElement;
6767
let el: HTMLElement;
68-
let inputElement: HTMLElement;
6968

7069
beforeEach(() => {
7170
TestBed.configureTestingModule({
@@ -78,7 +77,6 @@ describe("RadioComponent", () => {
7877
component = fixture.componentInstance;
7978
de = fixture.debugElement.query(By.css("label"));
8079
el = de.nativeElement;
81-
inputElement = fixture.debugElement.query(By.css("input")).nativeElement;
8280
});
8381

8482
it("should work", () => {

src/radio/radio.component.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ import { RadioGroup } from "./radio-group.component";
3434
selector: "ibm-radio",
3535
template: `
3636
<input
37+
*ngIf="!skeleton"
3738
class="bx--radio-button"
3839
type="radio"
3940
#inputCheckbox
@@ -48,8 +49,12 @@ import { RadioGroup } from "./radio-group.component";
4849
(change)="onChange($event)"
4950
(click)="onClick($event)"
5051
[tabindex]="(checked || needsToBeFocusable ? 0 : -1)">
52+
<div *ngIf="skeleton" class="bx--radio-button bx--skeleton"></div>
5153
<label
5254
class="bx--radio-button__label"
55+
[ngClass]="{
56+
'bx--skeleton': skeleton
57+
}"
5358
[for]="id">
5459
<span class="bx--radio-button__appearance"></span>
5560
<ng-content></ng-content>
@@ -71,6 +76,10 @@ export class Radio extends Checkbox implements OnInit {
7176
*/
7277
static radioCount = 0;
7378

79+
/**
80+
* Set to `true` for a loading table.
81+
*/
82+
@Input() skeleton = false;
7483
/**
7584
* Returns the value/state of the `Radio`.
7685
* @readonly

src/radio/radio.stories.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,11 @@ storiesOf("Radio", module).addDecorator(
2828
{ num: "four" }
2929
]
3030
}
31+
}))
32+
.add("Skeleton", () => ({
33+
template: `
34+
<ibm-radio-group skeleton="true">
35+
<ibm-radio></ibm-radio>
36+
</ibm-radio-group>
37+
`
3138
}));

0 commit comments

Comments
 (0)