Skip to content

Commit 1066636

Browse files
authored
Merge branch 'master' into skeleton-select
2 parents 44430e9 + 0719bf2 commit 1066636

File tree

2 files changed

+85
-6
lines changed

2 files changed

+85
-6
lines changed

src/table/table.component.ts

Lines changed: 44 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import {
88
import { Subscription, fromEvent } from "rxjs";
99

1010
import { TableModel } from "./table.module";
11+
import { TableHeaderItem } from "./table-header-item.class";
12+
import { TableItem } from "./table-item.class";
1113
import { getScrollbarWidth } from "../common/utils";
1214
import { I18n } from "./../i18n/i18n.module";
1315

@@ -165,12 +167,13 @@ import { I18n } from "./../i18n/i18n.module";
165167
[ngClass]="{
166168
'bx--data-table-v2--compact': size === 'sm',
167169
'bx--data-table-v2--tall': size === 'lg',
168-
'bx--data-table-v2--zebra': striped
170+
'bx--data-table-v2--zebra': striped,
171+
'bx--skeleton': skeleton
169172
}">
170173
<thead>
171174
<tr>
172175
<th *ngIf="model.hasExpandableRows()"></th>
173-
<th *ngIf="showSelectionColumn" style="width: 10px;">
176+
<th *ngIf="!skeleton && showSelectionColumn" style="width: 10px;">
174177
<ibm-checkbox
175178
[size]="size !== ('lg' ? 'sm' : 'md')"
176179
[(ngModel)]="selectAllCheckbox"
@@ -187,6 +190,7 @@ import { I18n } from "./../i18n/i18n.module";
187190
[draggable]="columnsDraggable"
188191
(dragstart)="columnDragStart($event, i)"
189192
(dragend)="columnDragEnd($event, i)">
193+
<span *ngIf="skeleton"></span>
190194
<div
191195
*ngIf="columnsResizable"
192196
class="column-resize-handle"
@@ -215,7 +219,7 @@ import { I18n } from "./../i18n/i18n.module";
215219
</button>
216220
<span
217221
class="bx--table-header-label"
218-
*ngIf="this.sort.observers.length === 0 || (this.sort.observers.length > 0 && !column.sortable)">
222+
*ngIf="!skeleton && this.sort.observers.length === 0 || (this.sort.observers.length > 0 && !column.sortable)">
219223
<span *ngIf="!column.template" [title]="column.data">{{column.data}}</span>
220224
<ng-template
221225
[ngTemplateOutlet]="column.template" [ngTemplateOutletContext]="{data: column.data}">
@@ -271,7 +275,7 @@ import { I18n } from "./../i18n/i18n.module";
271275
</div>
272276
</th>
273277
</ng-container>
274-
<th [ngStyle]="{'width': scrollbarWidth + 'px', 'padding': 0, 'border': 0}">
278+
<th *ngIf="!skeleton" [ngStyle]="{'width': scrollbarWidth + 'px', 'padding': 0, 'border': 0}">
275279
<!--
276280
Scrollbar pushes body to the left so this header column is added to push
277281
the title bar the same amount and keep the header and body columns aligned.
@@ -311,7 +315,7 @@ import { I18n } from "./../i18n/i18n.module";
311315
</svg>
312316
</button>
313317
</td>
314-
<td *ngIf="showSelectionColumn">
318+
<td *ngIf="!skeleton && showSelectionColumn">
315319
<ibm-checkbox
316320
aria-label="Select row"
317321
[size]="size !== ('lg' ? 'sm' : 'md')"
@@ -364,13 +368,48 @@ import { I18n } from "./../i18n/i18n.module";
364368
`
365369
})
366370
export class Table {
371+
/**
372+
* Creates a skeleton model with a row and column count specified by the user
373+
*
374+
* Example:
375+
*
376+
* ```typescript
377+
* this.model = Table.skeletonModel(5, 5);
378+
* ```
379+
*
380+
* @param {number} rowCount
381+
* @param {number} columnCount
382+
*/
383+
static skeletonModel(rowCount: number, columnCount: number) {
384+
const model = new TableModel();
385+
let header = new Array<TableHeaderItem>();
386+
let data = new Array<Array<TableItem>>();
387+
let row = new Array<TableItem>();
388+
389+
for (let i = 0; i < columnCount; i++) {
390+
header.push(new TableHeaderItem());
391+
row.push(new TableItem());
392+
}
393+
for (let i = 0; i < rowCount - 1; i++) {
394+
data.push(row);
395+
}
396+
397+
model.header = header;
398+
model.data = data;
399+
return model;
400+
}
401+
367402
/**
368403
* Size of the table rows.
369404
*
370405
* @type {("sm" | "md" | "lg")}
371406
* @memberof Table
372407
*/
373408
@Input() size: "sm" | "md" | "lg" = "md";
409+
/**
410+
* Set to `true` for a loading table.
411+
*/
412+
@Input() skeleton = false;
374413
/**
375414
* Object of all the strings table needs.
376415
* Defaults to the `TABLE` value from the i18n service.

src/table/table.stories.ts

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import {
1717
} from "@storybook/addon-knobs/angular";
1818

1919
import {
20+
Table,
2021
TableModule,
2122
TableModel,
2223
TableItem,
@@ -414,6 +415,29 @@ function sort(model, index: number) {
414415
model.sort(index);
415416
}
416417

418+
@Component({
419+
selector: "app-skeleton-table",
420+
template: `
421+
<ibm-table
422+
[model]="skeletonModel"
423+
[skeleton]="skeleton"
424+
[size]="size"
425+
[striped]="striped">
426+
<ng-content></ng-content>
427+
</ibm-table>
428+
`
429+
})
430+
class SkeletonTableStory implements OnInit, OnChanges {
431+
@Input() size = "md";
432+
@Input() striped = false;
433+
@Input() skeleton = true;
434+
@Input() skeletonModel = new TableModel();
435+
436+
ngOnInit() {
437+
// Creates an empty table with 5 rows and 5 columns
438+
this.skeletonModel = Table.skeletonModel(5, 5);
439+
}
440+
}
417441

418442
storiesOf("Table", module).addDecorator(
419443
moduleMetadata({
@@ -428,7 +452,8 @@ storiesOf("Table", module).addDecorator(
428452
DynamicTableStory,
429453
ExpansionTableStory,
430454
OverflowTableStory,
431-
PaginationTableStory
455+
PaginationTableStory,
456+
SkeletonTableStory
432457
]
433458
})
434459
)
@@ -525,5 +550,20 @@ storiesOf("Table", module).addDecorator(
525550
model: simpleModel,
526551
totalDataLength: number("totalDataLength", 105)
527552
}
553+
}))
554+
.add("Skeleton", () => ({
555+
template: `
556+
<div style="width: 800px">
557+
<app-skeleton-table
558+
[skeletonModel]="skeletonModel"
559+
[size]="size"
560+
[striped]="striped">
561+
</app-skeleton-table>
562+
</div>
563+
`,
564+
props: {
565+
size: selectV2("size", {Small: "sm", Normal: "md", Large: "lg"}, "md"),
566+
striped: boolean("striped", false)
567+
}
528568
}));
529569

0 commit comments

Comments
 (0)