Skip to content

Commit 62c6743

Browse files
committed
refactor(cards): card navigation update to the latest tabs api
1 parent e9cf88f commit 62c6743

File tree

4 files changed

+90
-83
lines changed

4 files changed

+90
-83
lines changed

Diff for: src/app/views/base/cards/cards.component.html

+73-73
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,8 @@ <h6 cCardSubtitle class="mb-2 text-body-secondary">
8484
Some quick example text to build on the card title and make up the
8585
bulk of the card content.
8686
</p>
87-
<a cCardLink [routerLink]="[]">Card link</a>
88-
<a cCardLink [routerLink]="[]">Another link</a>
87+
<a [routerLink]="[]" cCardLink>Card link</a>
88+
<a [routerLink]="[]" cCardLink>Another link</a>
8989
</c-card-body>
9090
</c-card>
9191
</app-docs-example>
@@ -190,8 +190,8 @@ <h5 cCardTitle>Card title</h5>
190190
<li cListGroupItem>Vestibulum at eros</li>
191191
</ul>
192192
<c-card-body>
193-
<a cCardLink [routerLink]="[]">Card link</a>
194-
<a cCardLink [routerLink]="[]">Another link</a>
193+
<a [routerLink]="[]" cCardLink>Card link</a>
194+
<a [routerLink]="[]" cCardLink>Another link</a>
195195
</c-card-body>
196196
</c-card>
197197
</app-docs-example>
@@ -209,7 +209,7 @@ <h5 cCardTitle>Card title</h5>
209209
<p class="text-body-secondary small">
210210
Add an optional header and/or footer within a card.
211211
</p>
212-
<app-docs-example href="components/card/#header-and-footer" class="mb-1">
212+
<app-docs-example class="mb-1" href="components/card/#header-and-footer">
213213
<c-card>
214214
<c-card-header>Featured</c-card-header>
215215
<c-card-body>
@@ -223,7 +223,7 @@ <h5 cCardTitle>Card title</h5>
223223
Card headers can be styled by adding ex.
224224
<code>&#34;h5&#34;</code>.
225225
</p>
226-
<app-docs-example href="components/card/#header-and-footer" class="mb-1">
226+
<app-docs-example class="mb-1" href="components/card/#header-and-footer">
227227
<c-card>
228228
<c-card-header>
229229
<h5>Header</h5>
@@ -287,7 +287,7 @@ <h3>Using grid markup</h3>
287287
<p class="text-body-secondary small">
288288
Using the grid, wrap cards in columns and rows as needed.
289289
</p>
290-
<app-docs-example href="components/card/#sizing" class="mb-2">
290+
<app-docs-example class="mb-2" href="components/card/#sizing">
291291
<c-row class="g-4">
292292
<c-col sm="6">
293293
<c-card>
@@ -310,7 +310,7 @@ <h3>Using utilities</h3>
310310
Use some of <a href="https://coreui.io/docs/utilities/sizing/">available sizing utilities</a> to rapidly set a
311311
card width.
312312
</p>
313-
<app-docs-example href="components/card/#sizing" class="mb-2">
313+
<app-docs-example class="mb-2" href="components/card/#sizing">
314314
<c-card class="w-75 mb-2">
315315
<c-card-body>
316316
<ng-container *ngTemplateOutlet="cardBodyTemplate" />
@@ -390,55 +390,55 @@ <h3>Using utilities</h3>
390390
</p>
391391
<c-row>
392392
<c-col>
393-
<app-docs-example href="components/card/##navigation">
394-
<c-card class="text-center">
395-
<c-card-header>
396-
<c-nav class="card-header-tabs" variant="tabs">
397-
<c-nav-item>
398-
<a [active]="true" cNavLink [routerLink]="[]">
399-
Active
400-
</a>
401-
</c-nav-item>
402-
<c-nav-item>
403-
<a cNavLink [routerLink]="[]">Link</a>
404-
</c-nav-item>
405-
<c-nav-item>
406-
<a cNavLink disabled [routerLink]="[]">
407-
Disabled
408-
</a>
409-
</c-nav-item>
410-
</c-nav>
411-
</c-card-header>
412-
<c-card-body>
413-
<ng-container *ngTemplateOutlet="cardBodyTemplate" />
414-
</c-card-body>
415-
</c-card>
393+
<app-docs-example href="components/card/#navigation">
394+
<c-tabs activeItemKey="Active">
395+
<c-card class="text-center">
396+
<c-card-header>
397+
<c-tabs-list class="card-header-tabs" variant="tabs">
398+
@for (tab of tabs; track tab) {
399+
<button [itemKey]="tab" cTab [disabled]="tab==='Disabled'">
400+
{{ tab }}
401+
</button>
402+
}
403+
</c-tabs-list>
404+
</c-card-header>
405+
<c-card-body>
406+
<c-tabs-content>
407+
@for (panel of tabs; track panel) {
408+
<c-tab-panel [itemKey]="panel">
409+
<ng-container *ngTemplateOutlet="cardBodyTemplate; context: {$implicit: panel}" />
410+
</c-tab-panel>
411+
}
412+
</c-tabs-content>
413+
</c-card-body>
414+
</c-card>
415+
</c-tabs>
416416
</app-docs-example>
417417
</c-col>
418418
<c-col>
419-
<app-docs-example href="components/card/##navigation">
420-
<c-card class="text-center">
421-
<c-card-header>
422-
<c-nav class="card-header-pills" variant="pills">
423-
<c-nav-item>
424-
<a [active]="true" cNavLink [routerLink]="[]">
425-
Active
426-
</a>
427-
</c-nav-item>
428-
<c-nav-item>
429-
<a cNavLink [routerLink]="[]">Link</a>
430-
</c-nav-item>
431-
<c-nav-item>
432-
<a cNavLink disabled [routerLink]="[]">
433-
Disabled
434-
</a>
435-
</c-nav-item>
436-
</c-nav>
437-
</c-card-header>
438-
<c-card-body>
439-
<ng-container *ngTemplateOutlet="cardBodyTemplate" />
440-
</c-card-body>
441-
</c-card>
419+
<app-docs-example href="components/card/#navigation">
420+
<c-tabs activeItemKey="Active">
421+
<c-card class="text-center">
422+
<c-card-header>
423+
<c-tabs-list class="card-header-pills" variant="pills">
424+
@for (tab of tabs; track tab) {
425+
<button [itemKey]="tab" cTab [disabled]="tab==='Disabled'">
426+
{{ tab }}
427+
</button>
428+
}
429+
</c-tabs-list>
430+
</c-card-header>
431+
<c-card-body>
432+
<c-tabs-content>
433+
@for (panel of tabs; track panel) {
434+
<c-tab-panel [itemKey]="panel">
435+
<ng-container *ngTemplateOutlet="cardBodyTemplate; context: {$implicit: panel}" />
436+
</c-tab-panel>
437+
}
438+
</c-tabs-content>
439+
</c-card-body>
440+
</c-card>
441+
</c-tabs>
442442
</app-docs-example>
443443
</c-col>
444444
</c-row>
@@ -505,7 +505,7 @@ <h3>Background and color</h3>
505505
<p class="text-body-secondary small">
506506
Use <code>color</code> property to change the appearance of a card.
507507
</p>
508-
<app-docs-example href="components/card/#background-and-color" class="mb-1">
508+
<app-docs-example class="mb-1" href="components/card/#background-and-color">
509509
<c-row>
510510
@for (item of colors; track item; let i = $index) {
511511
<c-col lg="4">
@@ -533,7 +533,7 @@ <h3>Border</h3>
533533
<code>textColor</code> property on the <code>&lt;c-card&gt;</code> or a subset of the
534534
card&#39;s contents as shown below.
535535
</p>
536-
<app-docs-example href="components/card/#border" class="mb-1">
536+
<app-docs-example class="mb-1" href="components/card/#border">
537537
<c-row class="g-4">
538538
@for (item of colors; track item; let i = $index) {
539539
<c-col lg="4">
@@ -562,19 +562,19 @@ <h3>Top border</h3>
562562
<app-docs-example href="components/card/#top-border">
563563
<c-row>
564564
@for (item of colors; track item; let i = $index) {
565-
<c-col lg="4">
566-
<c-card [cBorder]="{top: {color: item.color, width: 3}}" [textColor]="item?.textColor ?? ''" class="mb-3">
567-
<c-card-header>Header</c-card-header>
568-
<c-card-body>
569-
<h5 cCardTitle>{{ item.color }} card title</h5>
570-
<p cCardText>
571-
Some quick example text to build on the card title and make up the bulk of
572-
the card&#39;s content.
573-
</p>
574-
<button [color]="item.color" cButton>Go somewhere</button>
575-
</c-card-body>
576-
</c-card>
577-
</c-col>
565+
<c-col lg="4">
566+
<c-card [cBorder]="{top: {color: item.color, width: 3}}" [textColor]="item?.textColor ?? ''" class="mb-3">
567+
<c-card-header>Header</c-card-header>
568+
<c-card-body>
569+
<h5 cCardTitle>{{ item.color }} card title</h5>
570+
<p cCardText>
571+
Some quick example text to build on the card title and make up the bulk of
572+
the card&#39;s content.
573+
</p>
574+
<button [color]="item.color" cButton>Go somewhere</button>
575+
</c-card-body>
576+
</c-card>
577+
</c-col>
578578
}
579579
</c-row>
580580
</app-docs-example>
@@ -699,7 +699,7 @@ <h5 cCardTitle>Card title</h5>
699699
four cards to equal width across multiple rows, from the medium breakpoint up.
700700
</p>
701701
<app-docs-example href="components/card/#grid-cards">
702-
<c-row [gutter]="{g: 4}" class="mb-3" [md]="2" [xs]="1">
702+
<c-row [gutter]="{g: 4}" [md]="2" [xs]="1" class="mb-3">
703703
<c-col>
704704
<c-card>
705705
<ng-container *ngTemplateOutlet="imgAngularTemplate" />
@@ -835,7 +835,7 @@ <h5 cCardTitle>Card title</h5>
835835
</c-row>
836836

837837
<ng-template #imgAngularTemplate let-orientation>
838-
<img [cCardImg]="orientation ?? 'top'" src="assets/images/angular.jpg">
838+
<img [cCardImg]="orientation ?? 'top'" src="assets/images/angular.jpg" alt="CoreUI for Angular">
839839
</ng-template>
840840

841841
<ng-template #imgPlaceholderTemplate let-orientation>
@@ -856,8 +856,8 @@ <h5 cCardTitle>Card title</h5>
856856
</svg>
857857
</ng-template>
858858

859-
<ng-template #cardBodyTemplate>
860-
<h5 cCardTitle>Card title</h5>
859+
<ng-template #cardBodyTemplate let-title>
860+
<h5 cCardTitle>Card {{ title ?? 'title' }}</h5>
861861
<p cCardText>
862862
Some quick example text to build on the card title and make up the bulk of the card's content.
863863
</p>

Diff for: src/app/views/base/cards/cards.component.spec.ts

+6-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { ComponentFixture, TestBed } from '@angular/core/testing';
2-
import { RouterTestingModule } from '@angular/router/testing';
2+
import { NoopAnimationsModule } from '@angular/platform-browser/animations';
3+
import { provideRouter } from '@angular/router';
34

45
import { ButtonModule, CardModule, GridModule, ListGroupModule, NavModule, UtilitiesModule } from '@coreui/angular';
56
import { IconSetService } from '@coreui/icons-angular';
@@ -13,9 +14,10 @@ describe('CardsComponent', () => {
1314

1415
beforeEach(async () => {
1516
await TestBed.configureTestingModule({
16-
imports: [CardModule, NavModule, GridModule, ListGroupModule, UtilitiesModule, ButtonModule, RouterTestingModule, CardsComponent],
17-
providers: [IconSetService]
18-
})
17+
imports: [CardModule, NavModule, GridModule, ListGroupModule, UtilitiesModule, ButtonModule, CardsComponent, NoopAnimationsModule, ],
18+
providers: [IconSetService, provideRouter([])],
19+
teardown: { destroyAfterEach: false } // <- add this line for Error: NG0205: Injector has already been destroyed.
20+
})
1921
.compileComponents();
2022
});
2123

Diff for: src/app/views/base/cards/cards.component.ts

+8-5
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,15 @@ import {
1919
GutterDirective,
2020
ListGroupDirective,
2121
ListGroupItemDirective,
22-
NavComponent,
23-
NavItemComponent,
24-
NavLinkDirective,
2522
RowComponent,
23+
TabDirective,
24+
TabPanelComponent,
25+
TabsComponent,
26+
TabsContentComponent,
27+
TabsListComponent,
2628
TextColorDirective
2729
} from '@coreui/angular';
30+
import { IconDirective } from '@coreui/icons-angular';
2831

2932
type CardColor = {
3033
color: string
@@ -36,7 +39,7 @@ type CardColor = {
3639
templateUrl: './cards.component.html',
3740
styleUrls: ['./cards.component.scss'],
3841
standalone: true,
39-
imports: [RowComponent, ColComponent, TextColorDirective, CardComponent, CardHeaderComponent, CardBodyComponent, DocsExampleComponent, NgTemplateOutlet, CardTitleDirective, CardTextDirective, ButtonDirective, CardSubtitleDirective, CardLinkDirective, RouterLink, ListGroupDirective, ListGroupItemDirective, CardFooterComponent, NavComponent, NavItemComponent, NavLinkDirective, BorderDirective, CardGroupComponent, GutterDirective, CardImgDirective]
42+
imports: [RowComponent, ColComponent, TextColorDirective, CardComponent, CardHeaderComponent, CardBodyComponent, DocsExampleComponent, NgTemplateOutlet, CardTitleDirective, CardTextDirective, ButtonDirective, CardSubtitleDirective, CardLinkDirective, RouterLink, ListGroupDirective, ListGroupItemDirective, CardFooterComponent, BorderDirective, CardGroupComponent, GutterDirective, CardImgDirective, TabsComponent, TabsListComponent, IconDirective, TabDirective, TabsContentComponent, TabPanelComponent]
4043
})
4144
export class CardsComponent {
4245

@@ -53,6 +56,6 @@ export class CardsComponent {
5356

5457
imgContext = { $implicit: 'top', bottom: 'bottom' };
5558

56-
constructor() { }
59+
tabs = ['Active', 'List', 'Disabled']
5760

5861
}

Diff for: src/app/views/base/tabs/tabs.component.spec.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@ describe('TabsComponent', () => {
1212

1313
beforeEach(async () => {
1414
await TestBed.configureTestingModule({
15-
imports: [AppTabsComponent, NoopAnimationsModule], providers: [IconSetService], teardown: { destroyAfterEach: false } // <- add this line
15+
imports: [AppTabsComponent, NoopAnimationsModule],
16+
providers: [IconSetService],
17+
teardown: { destroyAfterEach: false } // <- add this line for Error: NG0205: Injector has already been destroyed.
1618
}).compileComponents();
1719
});
1820

0 commit comments

Comments
 (0)