Skip to content

Commit 19fffb7

Browse files
committed
Merge branch 'master' of https://github.com/IBM/carbon-components-angular into storybook-styles
2 parents 0264e62 + 0719bf2 commit 19fffb7

File tree

4 files changed

+124
-26
lines changed

4 files changed

+124
-26
lines changed

src/file-uploader/file-uploader.component.ts

Lines changed: 32 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -16,27 +16,35 @@ const noop = () => {};
1616
@Component({
1717
selector: "ibm-file-uploader",
1818
template: `
19-
<strong class="bx--label">{{title}}</strong>
20-
<p class="bx--label-description">{{description}}</p>
21-
<div class="bx--file">
22-
<button
23-
ibmButton="secondary"
24-
(click)="fileInput.click()"
25-
[attr.for]="fileUploaderId">
26-
{{buttonText}}
27-
</button>
28-
<input
29-
#fileInput
30-
type="file"
31-
class="bx--file-input"
32-
[accept]="accept"
33-
[id]="fileUploaderId"
34-
[multiple]="multiple"
35-
(change)="onFilesAdded()"/>
36-
<div class="bx--file-container">
37-
<ibm-file *ngFor="let fileItem of files" [fileItem]="fileItem" (remove)="removeFile(fileItem)"></ibm-file>
19+
<ng-container *ngIf="!skeleton; else skeletonTemplate">
20+
<strong class="bx--label">{{title}}</strong>
21+
<p class="bx--label-description">{{description}}</p>
22+
<div class="bx--file">
23+
<button
24+
ibmButton="secondary"
25+
(click)="fileInput.click()"
26+
[attr.for]="fileUploaderId">
27+
{{buttonText}}
28+
</button>
29+
<input
30+
#fileInput
31+
type="file"
32+
class="bx--file-input"
33+
[accept]="accept"
34+
[id]="fileUploaderId"
35+
[multiple]="multiple"
36+
(change)="onFilesAdded()"/>
37+
<div class="bx--file-container">
38+
<ibm-file *ngFor="let fileItem of files" [fileItem]="fileItem" (remove)="removeFile(fileItem)"></ibm-file>
39+
</div>
3840
</div>
39-
</div>
41+
</ng-container>
42+
43+
<ng-template #skeletonTemplate>
44+
<div class="bx--skeleton__text" style="width: 100px"></div>
45+
<div class="bx--skeleton__text" style="width: 225px"></div>
46+
<button ibmButton skeleton="true"></button>
47+
</ng-template>
4048
`,
4149
providers: [
4250
{
@@ -75,6 +83,10 @@ export class FileUploader implements OnInit {
7583
* Defaults to `true`. Accepts multiple files.
7684
*/
7785
@Input() multiple = true;
86+
/**
87+
* Set to `true` for a loading file uploader.
88+
*/
89+
@Input() skeleton = false;
7890
/**
7991
* Provides a unique id for the underlying <input> node
8092
*/

src/file-uploader/file-uploader.stories.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import { NotificationService } from "../notification/notification.service";
2121
[buttonText]="buttonText"
2222
[accept]="accept"
2323
[multiple]="multiple"
24+
[skeleton]="skeleton"
2425
[(files)]="files">
2526
</ibm-file-uploader>
2627
@@ -40,6 +41,7 @@ class FileUploaderStory {
4041
@Input() buttonText;
4142
@Input() accept;
4243
@Input() multiple;
44+
@Input() skeleton = false;
4345

4446
protected maxSize = 500000;
4547

@@ -181,4 +183,9 @@ storiesOf("File Uploader", module)
181183
accept: array("Accepted file extensions", [".png", ".jpg"], ","),
182184
multiple: boolean("Supports multiple files", true)
183185
}
186+
}))
187+
.add("Skeleton", () => ({
188+
template: `
189+
<app-file-uploader skeleton="true"></app-file-uploader>
190+
`
184191
}));

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
)
@@ -537,5 +562,20 @@ storiesOf("Table", module).addDecorator(
537562
model: simpleModel,
538563
totalDataLength: number("totalDataLength", 105)
539564
}
565+
}))
566+
.add("Skeleton", () => ({
567+
template: `
568+
<div style="width: 800px">
569+
<app-skeleton-table
570+
[skeletonModel]="skeletonModel"
571+
[size]="size"
572+
[striped]="striped">
573+
</app-skeleton-table>
574+
</div>
575+
`,
576+
props: {
577+
size: selectV2("size", {Small: "sm", Normal: "md", Large: "lg"}, "md"),
578+
striped: boolean("striped", false)
579+
}
540580
}));
541581

0 commit comments

Comments
 (0)