Skip to content

Commit 19ca741

Browse files
xelaintdamienwebdev
authored andcommitted
feat(design): convert image to standalone (#3054)
1 parent 8fd50a6 commit 19ca741

File tree

13 files changed

+87
-25
lines changed

13 files changed

+87
-25
lines changed

libs/design/image/README.md

+43-7
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,54 @@
11
# Image
22
Image utilizes the native HTML `<img>` element to display responsive images on a page and prevent content jumping while images are loading. `<daff-image>` is an opinionated version that encourages friendly end-user usage.
33

4+
<design-land-example-viewer-container example="load-image"></design-land-example-viewer-container>
5+
46
## Attributes
57
The `src`, `width`, `height`, and `alt` attributes must be defined. An error will be thrown any of these attributes are missing.
68

79
`width` and `height` are required to calculate the aspect ratio of an image, used for the [aspect ratio padding trick](https://css-tricks.com/aspect-ratio-boxes/) that helps to prevent content jumping while images are loading. The `width` and `height` values are rendered as pixels.
810

11+
## Usage
12+
13+
### Within a standalone component
14+
To use image in a standalone component, import it directly into your custom component:
15+
16+
```ts
17+
@Component({
18+
selector: 'custom-component',
19+
templateUrl: './custom-component.component.html',
20+
standalone: true,
21+
imports: [
22+
DAFF_IMAGE_COMPONENTS,
23+
],
24+
})
25+
export class CustomComponent {}
26+
```
27+
28+
### Within a module (deprecated)
29+
To use image in a module, import `DaffImageModule` into your custom module:
30+
31+
```ts
32+
import { NgModule } from '@angular/core';
33+
34+
import { DaffImageModule } from '@daffodil/design/image';
35+
36+
@NgModule({
37+
declarations: [
38+
CustomComponent,
39+
],
40+
exports: [
41+
CustomComponent,
42+
],
43+
imports: [
44+
DaffImageModule,
45+
],
46+
})
47+
export class CustomComponentModule { }
48+
```
49+
50+
> This method is deprecated. It's recommended to update all custom components to standalone.
51+
952
## Errors
1053

1154
**DaffImageComponent must have a defined src attribute.**
@@ -22,10 +65,3 @@ This error appears when `<daff-image>` is missing a `height` attribute. The heig
2265

2366
## Accessbility
2467
Images should be given a meaningful description using the native `alt` attribute to ensure an accessible experience by default. An error will be thrown if the `alt` attribute is missing.
25-
26-
## Usage
27-
### Basic Image
28-
<design-land-example-viewer-container example="load-image"></design-land-example-viewer-container>
29-
30-
### Image Load Output
31-
<design-land-example-viewer-container example="load-image"></design-land-example-viewer-container>

libs/design/image/examples/src/basic-image/basic-image.component.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,17 @@ import {
33
Component,
44
} from '@angular/core';
55

6-
import { DaffImageModule } from '@daffodil/design/image';
6+
import { DAFF_IMAGE_COMPONENTS } from '@daffodil/design/image';
77

88
@Component({
99
// eslint-disable-next-line @angular-eslint/component-selector
1010
selector: 'basic-image',
1111
templateUrl: './basic-image.component.html',
1212
changeDetection: ChangeDetectionStrategy.OnPush,
1313
standalone: true,
14-
imports: [DaffImageModule],
14+
imports: [
15+
DAFF_IMAGE_COMPONENTS,
16+
],
1517
})
1618
export class BasicImageComponent {
1719

libs/design/image/examples/src/load-image/load-image.component.ts

+5-2
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,18 @@ import {
44
Component,
55
} from '@angular/core';
66

7-
import { DaffImageModule } from '@daffodil/design/image';
7+
import { DAFF_IMAGE_COMPONENTS } from '@daffodil/design/image';
88

99
@Component({
1010
// eslint-disable-next-line @angular-eslint/component-selector
1111
selector: 'load-image',
1212
templateUrl: './load-image.component.html',
1313
changeDetection: ChangeDetectionStrategy.OnPush,
1414
standalone: true,
15-
imports: [DaffImageModule, NgIf],
15+
imports: [
16+
DAFF_IMAGE_COMPONENTS,
17+
NgIf,
18+
],
1619
})
1720
export class LoadImageComponent {
1821
loaded = false;

libs/design/image/examples/src/skeleton-image/skeleton-image.component.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,17 @@ import {
33
Component,
44
} from '@angular/core';
55

6-
import { DaffImageModule } from '@daffodil/design/image';
6+
import { DAFF_IMAGE_COMPONENTS } from '@daffodil/design/image';
77

88
@Component({
99
// eslint-disable-next-line @angular-eslint/component-selector
1010
selector: 'skeleton-image',
1111
templateUrl: './skeleton-image.component.html',
1212
changeDetection: ChangeDetectionStrategy.OnPush,
1313
standalone: true,
14-
imports: [DaffImageModule],
14+
imports: [
15+
DAFF_IMAGE_COMPONENTS,
16+
],
1517
})
1618
export class SkeletonImageComponent {
1719

libs/design/image/src/image.module.ts

+4-3
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,13 @@ import { NgModule } from '@angular/core';
33

44
import { DaffImageComponent } from './image/image.component';
55

6+
/**
7+
* @deprecated in favor of {@link DAFF_IMAGE_COMPONENTS}
8+
* */
69
@NgModule({
7-
declarations: [
8-
DaffImageComponent,
9-
],
1010
imports: [
1111
CommonModule,
12+
DaffImageComponent,
1213
],
1314
exports: [
1415
DaffImageComponent,

libs/design/image/src/image.ts

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { DaffImageComponent } from './image/image.component';
2+
3+
export const DAFF_IMAGE_COMPONENTS = <const>[
4+
DaffImageComponent,
5+
];

libs/design/image/src/image/image.component.spec.ts

+5-2
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ import { DaffImageComponent } from './image.component';
1313

1414
@Component({
1515
template: `<daff-image [src]="src" [alt]="alt" [width]="width" [height]="height" [skeleton]="skeleton"></daff-image>`,
16+
standalone: true,
17+
imports: [
18+
DaffImageComponent,
19+
],
1620
})
1721

1822
class WrapperComponent {
@@ -32,8 +36,7 @@ describe('@daffodil/design/image | DaffImageComponent', () => {
3236

3337
beforeEach(waitForAsync(() => {
3438
TestBed.configureTestingModule({
35-
declarations: [
36-
DaffImageComponent,
39+
imports: [
3740
WrapperComponent,
3841
],
3942
})

libs/design/image/src/image/image.component.ts

+1
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ const validateProperties = (object: Record<string, any>, props: string[]) => {
4848
directive: DaffSkeletonableDirective,
4949
inputs: ['skeleton'],
5050
}],
51+
standalone: true,
5152
})
5253
export class DaffImageComponent implements OnInit {
5354

libs/design/image/src/image/specs/image-props.spec.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,10 @@ describe('DaffImageComponent | Props Validation', () => {
2323

2424
beforeEach(waitForAsync(() => {
2525
TestBed.configureTestingModule({
26-
declarations: [
26+
imports: [
2727
DaffImageComponent,
28+
],
29+
declarations: [
2830
WrapperComponent,
2931
],
3032
})

libs/design/image/src/public_api.ts

+1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
export { DaffImageModule } from './image.module';
22
export { DaffImageComponent } from './image/image.component';
3+
export { DAFF_IMAGE_COMPONENTS } from './image';

libs/design/media-gallery/examples/src/basic-media-gallery/basic-media-gallery.component.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import {
33
Component,
44
} from '@angular/core';
55

6-
import { DaffImageModule } from '@daffodil/design/image';
6+
import { DAFF_IMAGE_COMPONENTS } from '@daffodil/design/image';
77
import { DaffMediaGalleryModule } from '@daffodil/design/media-gallery';
88

99
@Component({
@@ -12,7 +12,7 @@ import { DaffMediaGalleryModule } from '@daffodil/design/media-gallery';
1212
templateUrl: './basic-media-gallery.component.html',
1313
changeDetection: ChangeDetectionStrategy.OnPush,
1414
standalone: true,
15-
imports: [DaffMediaGalleryModule, DaffImageModule],
15+
imports: [DaffMediaGalleryModule, DAFF_IMAGE_COMPONENTS],
1616
})
1717
export class BasicMediaGalleryComponent {
1818

libs/design/media-gallery/examples/src/mismatched-sizes-media-gallery/mismatched-sizes-media-gallery.component.ts

+5-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import {
33
Component,
44
} from '@angular/core';
55

6-
import { DaffImageModule } from '@daffodil/design/image';
6+
import { DAFF_IMAGE_COMPONENTS } from '@daffodil/design/image';
77
import { DaffMediaGalleryModule } from '@daffodil/design/media-gallery';
88

99
@Component({
@@ -12,6 +12,9 @@ import { DaffMediaGalleryModule } from '@daffodil/design/media-gallery';
1212
templateUrl: './mismatched-sizes-media-gallery.component.html',
1313
changeDetection: ChangeDetectionStrategy.OnPush,
1414
standalone: true,
15-
imports: [DaffMediaGalleryModule, DaffImageModule],
15+
imports: [
16+
DaffMediaGalleryModule,
17+
DAFF_IMAGE_COMPONENTS,
18+
],
1619
})
1720
export class MismatchedSizesMediaGalleryComponent {}

libs/design/media-gallery/examples/src/skeleton-media-gallery/skeleton-media-gallery.component.ts

+5-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import {
33
Component,
44
} from '@angular/core';
55

6-
import { DaffImageModule } from '@daffodil/design/image';
6+
import { DAFF_IMAGE_COMPONENTS } from '@daffodil/design/image';
77
import { DaffMediaGalleryModule } from '@daffodil/design/media-gallery';
88

99
@Component({
@@ -12,7 +12,10 @@ import { DaffMediaGalleryModule } from '@daffodil/design/media-gallery';
1212
templateUrl: './skeleton-media-gallery.component.html',
1313
changeDetection: ChangeDetectionStrategy.OnPush,
1414
standalone: true,
15-
imports: [DaffMediaGalleryModule, DaffImageModule],
15+
imports: [
16+
DaffMediaGalleryModule,
17+
DAFF_IMAGE_COMPONENTS,
18+
],
1619
})
1720
export class SkeletonMediaGalleryComponent {
1821

0 commit comments

Comments
 (0)