Skip to content

Commit

Permalink
fix(sbb-image): introduce css property to configure object-fit
Browse files Browse the repository at this point in the history
  • Loading branch information
jeripeierSBB committed Oct 2, 2024
1 parent 44c2810 commit d7f931a
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/elements/image/image.scss
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
--sbb-disable-animation-zero-time,
var(--sbb-animation-duration-4x)
);
--sbb-image-object-fit: cover;

display: block;
}
Expand Down Expand Up @@ -105,7 +106,7 @@
:is(.sbb-image__img, .sbb-image__blurred) {
width: 100%;
height: 100%;
object-fit: cover;
object-fit: var(--sbb-image-object-fit);
object-position: var(--sbb-image-object-position);
transition: opacity var(--sbb-image-animation-duration) var(--sbb-animation-easing);
}
Expand Down
1 change: 1 addition & 0 deletions src/elements/image/image.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ const breakpointMap: Record<string, number> = {
* @cssprop [--sbb-image-border-radius=var(--sbb-border-radius-4x)] - Can be used to override the
* `borderRadius` property in case of different values for different viewports.
* @cssprop [--sbb-image-object-position] - Can be used to set the object-position css property of the image itself if the image itself is cropped.
* @cssprop [--sbb-image-object-fit=cover] - Can be used to set the object-fit css property of the image itself if the image itself is cropped.
*/
@customElement('sbb-image')
export class SbbImageElement extends LitElement {
Expand Down
14 changes: 14 additions & 0 deletions src/elements/image/image.visual.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,5 +132,19 @@ describe(`sbb-image`, () => {
await waitForImageReady(setup.snapshotElement.querySelector('sbb-image')!);
}),
);

it(
'cropped with object-fit',
visualDiffDefault.with(async (setup) => {
await setup.withFixture(
html`<sbb-image
image-src=${imageUrl}
style="width: 200px; height: 300px; --sbb-image-object-fit: contain"
></sbb-image>`,
);

await waitForImageReady(setup.snapshotElement.querySelector('sbb-image')!);
}),
);
});
});

0 comments on commit d7f931a

Please sign in to comment.