Skip to content

Commit ca132ea

Browse files
authored
Merge pull request #338 from youda97/skeleton-breadcrumb
feat(breadcrumb): Add skeleton state
2 parents 688ab7e + e6f7584 commit ca132ea

File tree

3 files changed

+46
-4
lines changed

3 files changed

+46
-4
lines changed

src/breadcrumb/breadcrumb-item.component.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ import {
88
selector: "ibm-breadcrumb-item",
99
template: `
1010
<a class="bx--link"
11-
href="{{href}}"
12-
*ngIf="href; else content">
11+
href="{{skeleton ? href : '/#'}}"
12+
*ngIf="skeleton || href; else content">
1313
<ng-container *ngTemplateOutlet="content"></ng-container>
1414
</a>
1515
<ng-template #content>
@@ -19,5 +19,7 @@ import {
1919
export class BreadcrumbItemComponent {
2020
@Input() href: string;
2121

22+
@Input() skeleton = false;
23+
2224
@HostBinding("class.bx--breadcrumb-item") itemClass = true;
2325
}

src/breadcrumb/breadcrumb.component.ts

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
import {
22
Component,
3-
Input
3+
Input,
4+
ContentChildren,
5+
QueryList,
6+
AfterContentInit
47
} from "@angular/core";
58

69
import { BreadcrumbItem } from "./breadcrumb-item.interface";
10+
import { BreadcrumbItemComponent } from "./breadcrumb-item.component";
711

812
const MINIMUM_OVERFLOW_THRESHOLD = 4;
913

@@ -12,6 +16,7 @@ const MINIMUM_OVERFLOW_THRESHOLD = 4;
1216
template: `
1317
<nav #nav class="bx--breadcrumb"
1418
[ngClass]="{
19+
'bx--skeleton' : skeleton,
1520
'bx--breadcrumb--no-trailing-slash' : noTrailingSlash
1621
}"
1722
[attr.aria-label]="ariaLabel">
@@ -50,14 +55,27 @@ const MINIMUM_OVERFLOW_THRESHOLD = 4;
5055
</ng-template>
5156
</nav>`
5257
})
53-
export class Breadcrumb {
58+
export class Breadcrumb implements AfterContentInit {
59+
@ContentChildren(BreadcrumbItemComponent) children: QueryList<BreadcrumbItemComponent>;
60+
5461
@Input() items: Array<BreadcrumbItem>;
5562

5663
@Input() noTrailingSlash = false;
5764

5865
@Input() ariaLabel: string;
5966

6067
protected _threshold: number;
68+
protected _skeleton = false;
69+
70+
@Input()
71+
set skeleton(value: any) {
72+
this._skeleton = value;
73+
this.updateChildren();
74+
}
75+
76+
get skeleton(): any {
77+
return this._skeleton;
78+
}
6179

6280
@Input()
6381
set threshold(threshold: number) {
@@ -71,6 +89,10 @@ export class Breadcrumb {
7189
return this._threshold;
7290
}
7391

92+
ngAfterContentInit() {
93+
this.updateChildren();
94+
}
95+
7496
get shouldShowContent(): boolean {
7597
return !this.items;
7698
}
@@ -97,4 +119,10 @@ export class Breadcrumb {
97119
get last(): BreadcrumbItem {
98120
return this.shouldShowOverflow ? this.items[this.items.length - 1] : null;
99121
}
122+
123+
protected updateChildren() {
124+
if (this.children) {
125+
this.children.toArray().forEach(child => child.skeleton = this.skeleton);
126+
}
127+
}
100128
}

src/breadcrumb/breadcrumb.stories.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,4 +57,16 @@ storiesOf("Breadcrumb", module)
5757
threshold: number("threshold", 4),
5858
items: createBreadcrumbItems
5959
}
60+
}))
61+
.add("Skeleton", () => ({
62+
template: `
63+
<ibm-breadcrumb skeleton="true" [noTrailingSlash]="noTrailingSlash">
64+
<ibm-breadcrumb-item></ibm-breadcrumb-item>
65+
<ibm-breadcrumb-item></ibm-breadcrumb-item>
66+
<ibm-breadcrumb-item></ibm-breadcrumb-item>
67+
<ibm-breadcrumb-item></ibm-breadcrumb-item>
68+
</ibm-breadcrumb>`,
69+
props: {
70+
noTrailingSlash: boolean("noTrailingSlash", true)
71+
}
6072
}));

0 commit comments

Comments
 (0)