Skip to content

Commit dd9299a

Browse files
authored
add position input to background image directive (#309)
1 parent d982e2b commit dd9299a

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

projects/angular-cld/src/lib/cloudinary-background-image.directive.spec.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import { CloudinaryTransformationDirective } from './cloudinary-transformation.d
1212
<cl-transformation effect="sepia"></cl-transformation>
1313
click me
1414
</button>
15-
<img [clBackgroundImage]="image.public_id" width="100" crop="scale"/>
15+
<img [clBackgroundImage]="image.public_id" position="left" width="100" crop="scale"/>
1616
`
1717
})
1818
class TestComponent { }
@@ -56,4 +56,14 @@ describe('CloudinaryBackgroundImageDirective', () => {
5656
const div = des[1].nativeElement as HTMLDivElement;
5757
expect(div.style.backgroundImage).toEqual(jasmine.stringMatching(/c_scale,w_100\/some_image_id/));
5858
});
59+
60+
it('background image position should default to center', () => {
61+
const div = des[0].nativeElement as HTMLDivElement;
62+
expect(div.style.backgroundPosition).toEqual('center center');
63+
});
64+
65+
it('should be able to pass background image position', () => {
66+
const div = des[1].nativeElement as HTMLDivElement;
67+
expect(div.style.backgroundPosition).toEqual('left center');
68+
});
5969
});

projects/angular-cld/src/lib/cloudinary-background-image.directive.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {CloudinaryTransformationDirective} from './cloudinary-transformation.dir
88
export class CloudinaryBackgroundImageDirective implements AfterViewInit {
99

1010
@Input() clBackgroundImage: string;
11+
@Input() position: string = 'center';
1112

1213
@ContentChildren(CloudinaryTransformationDirective)
1314
transformations: QueryList<CloudinaryTransformationDirective>;
@@ -26,7 +27,7 @@ export class CloudinaryBackgroundImageDirective implements AfterViewInit {
2627
const imageUrl = this.cloudinary.url(this.clBackgroundImage, options);
2728
this.renderer.setStyle(nativeElement, 'background-image', `url('${imageUrl}')`);
2829
this.renderer.setStyle(nativeElement, 'background-repeat', 'no-repeat');
29-
this.renderer.setStyle(nativeElement, 'background-position', 'center');
30+
this.renderer.setStyle(nativeElement, 'background-position', this.position);
3031
}
3132
}
3233
}

0 commit comments

Comments
 (0)