Skip to content

Commit da3fcab

Browse files
authored
Merge pull request #374 from youda97/checkbox
Update checkbox with inline input
2 parents c9e05c8 + 6d1c2fe commit da3fcab

File tree

3 files changed

+33
-29
lines changed

3 files changed

+33
-29
lines changed

src/checkbox/checkbox.component.ts

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -94,20 +94,18 @@ export class Checkbox implements ControlValueAccessor, AfterViewInit {
9494
*/
9595
static checkboxCount = 0;
9696

97-
@HostBinding("attr.class") class = "bx--checkbox-wrapper";
98-
9997
/**
10098
* Size of the checkbox.
10199
*/
102100
@Input() size: "sm" | "md" = "md";
103-
/**
104-
* Set to `true` for checkbox to be rendered with inline styles.
105-
*/
106-
@Input() inline: boolean;
107101
/**
108102
* Set to `true` for checkbox to be rendered with nested styles.
109103
*/
110104
@Input() nested: boolean;
105+
/**
106+
* Set to `true` for checkbox to be rendered without any classes on the host element.
107+
*/
108+
@Input() inline = false;
111109
/**
112110
* Set to `true` for a disabled checkbox.
113111
*/
@@ -190,6 +188,13 @@ export class Checkbox implements ControlValueAccessor, AfterViewInit {
190188
}
191189
}
192190

191+
@HostBinding("class.bx--checkbox-wrapper") get checkboxWrapperClass() {
192+
return !this.inline;
193+
}
194+
@HostBinding("class.bx--form-item") get formItemClass() {
195+
return !this.inline;
196+
}
197+
193198
/**
194199
* Emits event notifying other classes when a change in state occurs on a checkbox after a
195200
* click.
@@ -226,18 +231,6 @@ export class Checkbox implements ControlValueAccessor, AfterViewInit {
226231
Checkbox.checkboxCount++;
227232
}
228233

229-
/**
230-
* Creates a class name based on `@Input() size`, `@Input() inline`, and `@Input() nested`.
231-
* @return {string}
232-
*/
233-
public getVariantClass() {
234-
if (this.inline || this.nested) {
235-
return `checkbox${this.inline ? "--inline" : ""}${this.nested ? "--nested" : ""}${this.size !== "md" ? `-${this.size}` : ""}`;
236-
} else {
237-
return `checkbox${this.size !== "md" ? `--${this.size}` : ""}`;
238-
}
239-
}
240-
241234
/**
242235
* Toggle the selected state of the checkbox.
243236
* @memberof Checkbox

src/checkbox/checkbox.stories.ts

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,28 @@ storiesOf("Checkbox", module).addDecorator(
1212
.addDecorator(withKnobs)
1313
.add("Basic", () => ({
1414
template: `
15-
<ibm-checkbox
16-
[checked]="checked"
17-
[disabled]="disabled"
18-
[indeterminate]="indeterminate"
19-
(change)="onChange($event)"
20-
(indeterminateChange)="onIndeterminateChange($event)">
21-
Checkbox
22-
</ibm-checkbox>
15+
<fieldset class="bx--fieldset">
16+
<legend class="bx--label">Checkbox</legend>
17+
<ibm-checkbox
18+
checked="true"
19+
(change)="onChange($event)">
20+
Checkbox
21+
</ibm-checkbox>
22+
<ibm-checkbox
23+
indeterminate="true"
24+
(change)="onChange($event)"
25+
(indeterminateChange)="onIndeterminateChange($event)">
26+
Indeterminate checkbox
27+
</ibm-checkbox>
28+
<ibm-checkbox
29+
disabled="true"
30+
(change)="onChange($event)"
31+
(indeterminateChange)="onIndeterminateChange($event)">
32+
Disabled checkbox
33+
</ibm-checkbox>
34+
</fieldset>
2335
`,
2436
props: {
25-
checked: boolean("checked", false),
26-
disabled: boolean("disabled", false),
27-
indeterminate: boolean("indeterminate", false),
2837
onChange: action("Change fired!"),
2938
onIndeterminateChange: action("Indeterminate change fired!")
3039
}

src/table/table.component.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,7 @@ import { I18n } from "./../i18n/i18n.module";
175175
<th *ngIf="model.hasExpandableRows()"></th>
176176
<th *ngIf="!skeleton && showSelectionColumn" style="width: 10px;">
177177
<ibm-checkbox
178+
inline="true"
178179
[size]="size !== ('lg' ? 'sm' : 'md')"
179180
[(ngModel)]="selectAllCheckbox"
180181
[indeterminate]="selectAllCheckboxSomeSelected"
@@ -316,6 +317,7 @@ import { I18n } from "./../i18n/i18n.module";
316317
</td>
317318
<td *ngIf="!skeleton && showSelectionColumn">
318319
<ibm-checkbox
320+
inline="true"
319321
[attr.aria-label]="checkboxRowLabel | async"
320322
[size]="size !== ('lg' ? 'sm' : 'md')"
321323
[(ngModel)]="model.rowsSelected[i]"

0 commit comments

Comments
 (0)