Skip to content

Commit

Permalink
feat(design): convert card component to standalone (#3054)
Browse files Browse the repository at this point in the history
  • Loading branch information
xelaint authored and damienwebdev committed Sep 27, 2024
1 parent 1de68ab commit 7f830b6
Show file tree
Hide file tree
Showing 24 changed files with 126 additions and 38 deletions.
41 changes: 41 additions & 0 deletions libs/design/card/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,47 @@ The example below is a default, filled card that includes all of a card's pre-st

<design-land-example-viewer-container example="basic-card"></design-land-example-viewer-container>

## Usage

### Within a standalone component
To use card in a standalone component, import it directly into your custom component:

```ts
@Component({
selector: 'custom-component',
templateUrl: './custom-component.component.html',
standalone: true,
imports: [
DAFF_CARD_COMPONENTS,
],
})
export class CustomComponent {}
```

### Within a module (deprecated)
To use card in a module, import `DaffCardModule` into your custom module:

```ts
import { NgModule } from '@angular/core';

import { DaffCardModule } from '@daffodil/design/card';

@NgModule({
declarations: [
CustomComponent,
],
exports: [
CustomComponent,
],
imports: [
DaffCardModule,
],
})
export class CustomComponentModule { }
```

> This method is deprecated. It's recommended to update all custom components to standalone.
## Supported Content Types
A card supports a wide variety of content and includes minimally pre-styled `image`, `icon`, `tagline`, `title`, `content`, and `actions` content containers.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import { FaIconComponent } from '@fortawesome/angular-fontawesome';
import { faMapMarked } from '@fortawesome/free-solid-svg-icons';

import { DAFF_BUTTON_COMPONENTS } from '@daffodil/design/button';
import { DaffCardModule } from '@daffodil/design/card';
import { DaffImageModule } from '@daffodil/design/image';
import { DAFF_CARD_COMPONENTS } from '@daffodil/design/card';
import { DAFF_IMAGE_COMPONENTS } from '@daffodil/design/image';

@Component({
// eslint-disable-next-line @angular-eslint/component-selector
Expand All @@ -17,8 +17,8 @@ import { DaffImageModule } from '@daffodil/design/image';
changeDetection: ChangeDetectionStrategy.OnPush,
standalone: true,
imports: [
DaffCardModule,
DaffImageModule,
DAFF_CARD_COMPONENTS,
DAFF_IMAGE_COMPONENTS,
FaIconComponent,
DAFF_BUTTON_COMPONENTS,
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import { FaIconComponent } from '@fortawesome/angular-fontawesome';
import { faMapMarked } from '@fortawesome/free-solid-svg-icons';

import { DAFF_BUTTON_COMPONENTS } from '@daffodil/design/button';
import { DaffCardModule } from '@daffodil/design/card';
import { DaffImageModule } from '@daffodil/design/image';
import { DAFF_CARD_COMPONENTS } from '@daffodil/design/card';
import { DAFF_IMAGE_COMPONENTS } from '@daffodil/design/image';

@Component({
// eslint-disable-next-line @angular-eslint/component-selector
Expand All @@ -22,8 +22,8 @@ import { DaffImageModule } from '@daffodil/design/image';
changeDetection: ChangeDetectionStrategy.OnPush,
standalone: true,
imports: [
DaffCardModule,
DaffImageModule,
DAFF_CARD_COMPONENTS,
DAFF_IMAGE_COMPONENTS,
FaIconComponent,
DAFF_BUTTON_COMPONENTS,
ReactiveFormsModule,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
ReactiveFormsModule,
} from '@angular/forms';

import { DaffCardModule } from '@daffodil/design/card';
import { DAFF_CARD_COMPONENTS } from '@daffodil/design/card';

@Component({
// eslint-disable-next-line @angular-eslint/component-selector
Expand All @@ -22,7 +22,7 @@ import { DaffCardModule } from '@daffodil/design/card';
changeDetection: ChangeDetectionStrategy.OnPush,
standalone: true,
imports: [
DaffCardModule,
DAFF_CARD_COMPONENTS,
ReactiveFormsModule,
NgFor,
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import {
ReactiveFormsModule,
} from '@angular/forms';

import { DaffCardModule } from '@daffodil/design/card';
import { DaffImageModule } from '@daffodil/design/image';
import { DAFF_CARD_COMPONENTS } from '@daffodil/design/card';
import { DAFF_IMAGE_COMPONENTS } from '@daffodil/design/image';

@Component({
// eslint-disable-next-line @angular-eslint/component-selector
Expand All @@ -19,8 +19,8 @@ import { DaffImageModule } from '@daffodil/design/image';
changeDetection: ChangeDetectionStrategy.OnPush,
standalone: true,
imports: [
DaffCardModule,
DaffImageModule,
DAFF_CARD_COMPONENTS,
DAFF_IMAGE_COMPONENTS,
ReactiveFormsModule,
NgFor,
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import {
ReactiveFormsModule,
} from '@angular/forms';

import { DaffCardModule } from '@daffodil/design/card';
import { DaffImageModule } from '@daffodil/design/image';
import { DAFF_CARD_COMPONENTS } from '@daffodil/design/card';
import { DAFF_IMAGE_COMPONENTS } from '@daffodil/design/image';

@Component({
// eslint-disable-next-line @angular-eslint/component-selector
Expand All @@ -19,8 +19,8 @@ import { DaffImageModule } from '@daffodil/design/image';
changeDetection: ChangeDetectionStrategy.OnPush,
standalone: true,
imports: [
DaffCardModule,
DaffImageModule,
DAFF_CARD_COMPONENTS,
DAFF_IMAGE_COMPONENTS,
ReactiveFormsModule,
NgFor,
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import {
ReactiveFormsModule,
} from '@angular/forms';

import { DaffCardModule } from '@daffodil/design/card';
import { DaffImageModule } from '@daffodil/design/image';
import { DAFF_CARD_COMPONENTS } from '@daffodil/design/card';
import { DAFF_IMAGE_COMPONENTS } from '@daffodil/design/image';

@Component({
// eslint-disable-next-line @angular-eslint/component-selector
Expand All @@ -19,8 +19,8 @@ import { DaffImageModule } from '@daffodil/design/image';
changeDetection: ChangeDetectionStrategy.OnPush,
standalone: true,
imports: [
DaffCardModule,
DaffImageModule,
DAFF_CARD_COMPONENTS,
DAFF_IMAGE_COMPONENTS,
ReactiveFormsModule,
NgFor,
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ import { DaffCardActionsDirective } from './card-actions.directive';

@Component({
template: `<div daffCardActions></div>`,
standalone: true,
imports: [
DaffCardActionsDirective,
],
})

class WrapperComponent {}
Expand All @@ -24,8 +28,7 @@ describe('@daffodil/design/card | DaffCardActionsDirective', () => {

beforeEach(waitForAsync(() => {
TestBed.configureTestingModule({
declarations: [
DaffCardActionsDirective,
imports: [
WrapperComponent,
],
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {

@Directive({
selector: '[daffCardActions]',
standalone: true,
})
export class DaffCardActionsDirective {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ import { DaffCardContentDirective } from './card-content.directive';

@Component({
template: `<div daffCardContent></div>`,
standalone: true,
imports: [
DaffCardContentDirective,
],
})

class WrapperComponent {}
Expand All @@ -24,8 +28,7 @@ describe('@daffodil/design/card | DaffCardContentDirective', () => {

beforeEach(waitForAsync(() => {
TestBed.configureTestingModule({
declarations: [
DaffCardContentDirective,
imports: [
WrapperComponent,
],
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {

@Directive({
selector: '[daffCardContent]',
standalone: true,
})
export class DaffCardContentDirective {

Expand Down
7 changes: 5 additions & 2 deletions libs/design/card/src/card-icon/card-icon.directive.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ import { DaffCardIconDirective } from './card-icon.directive';

@Component({
template: `<div daffCardIcon></div>`,
standalone: true,
imports: [
DaffCardIconDirective,
],
})

class WrapperComponent {}
Expand All @@ -24,8 +28,7 @@ describe('@daffodil/design/card | DaffCardIconDirective', () => {

beforeEach(waitForAsync(() => {
TestBed.configureTestingModule({
declarations: [
DaffCardIconDirective,
imports: [
WrapperComponent,
],
})
Expand Down
1 change: 1 addition & 0 deletions libs/design/card/src/card-icon/card-icon.directive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {

@Directive({
selector: '[daffCardIcon]',
standalone: true,
})
export class DaffCardIconDirective {

Expand Down
7 changes: 5 additions & 2 deletions libs/design/card/src/card-image/card-image.directive.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ import { DaffCardImageDirective } from './card-image.directive';

@Component({
template: `<img src="/" daffCardImage />`,
standalone: true,
imports: [
DaffCardImageDirective,
],
})

class WrapperComponent {}
Expand All @@ -24,8 +28,7 @@ describe('@daffodil/design/card | DaffCardImageDirective', () => {

beforeEach(waitForAsync(() => {
TestBed.configureTestingModule({
declarations: [
DaffCardImageDirective,
imports: [
WrapperComponent,
],
})
Expand Down
1 change: 1 addition & 0 deletions libs/design/card/src/card-image/card-image.directive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {

@Directive({
selector: '[daffCardImage]',
standalone: true,
})
export class DaffCardImageDirective {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ import { DaffCardTaglineDirective } from './card-tagline.directive';

@Component({
template: `<div daffCardTagline></div>`,
standalone: true,
imports: [
DaffCardTaglineDirective,
],
})

class WrapperComponent {}
Expand All @@ -24,8 +28,7 @@ describe('@daffodil/design/card | DaffCardTaglineDirective', () => {

beforeEach(waitForAsync(() => {
TestBed.configureTestingModule({
declarations: [
DaffCardTaglineDirective,
imports: [
WrapperComponent,
],
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {

@Directive({
selector: '[daffCardTagline]',
standalone: true,
})
export class DaffCardTaglineDirective {

Expand Down
7 changes: 5 additions & 2 deletions libs/design/card/src/card-title/card-title.directive.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ import { DaffCardTitleDirective } from './card-title.directive';

@Component({
template: `<div daffCardTitle></div>`,
standalone: true,
imports: [
DaffCardTitleDirective,
],
})

class WrapperComponent {}
Expand All @@ -24,8 +28,7 @@ describe('@daffodil/design/card | DaffCardTitleDirective', () => {

beforeEach(waitForAsync(() => {
TestBed.configureTestingModule({
declarations: [
DaffCardTitleDirective,
imports: [
WrapperComponent,
],
})
Expand Down
1 change: 1 addition & 0 deletions libs/design/card/src/card-title/card-title.directive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {

@Directive({
selector: '[daffCardTitle]',
standalone: true,
})
export class DaffCardTitleDirective {

Expand Down
5 changes: 3 additions & 2 deletions libs/design/card/src/card.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@ import { DaffCardImageDirective } from './card-image/card-image.directive';
import { DaffCardTaglineDirective } from './card-tagline/card-tagline.directive';
import { DaffCardTitleDirective } from './card-title/card-title.directive';

/**
* @deprecated in favor of {@link DAFF_CARD_COMPONENTS}
*/
@NgModule({
imports: [
CommonModule,
],
declarations: [
DaffCardComponent,
DaffCardIconDirective,
DaffCardImageDirective,
Expand Down
17 changes: 17 additions & 0 deletions libs/design/card/src/card.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { DaffCardComponent } from './card/card.component';
import { DaffCardActionsDirective } from './card-actions/card-actions.directive';
import { DaffCardContentDirective } from './card-content/card-content.directive';
import { DaffCardIconDirective } from './card-icon/card-icon.directive';
import { DaffCardImageDirective } from './card-image/card-image.directive';
import { DaffCardTaglineDirective } from './card-tagline/card-tagline.directive';
import { DaffCardTitleDirective } from './card-title/card-title.directive';

export const DAFF_CARD_COMPONENTS = <const>[
DaffCardComponent,
DaffCardIconDirective,
DaffCardImageDirective,
DaffCardTaglineDirective,
DaffCardTitleDirective,
DaffCardContentDirective,
DaffCardActionsDirective,
];
Loading

0 comments on commit 7f830b6

Please sign in to comment.