Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(sbb-image): introduce css property to configure object-fit #3134

Merged
merged 1 commit into from
Oct 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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')!);
}),
);
});
});
1 change: 1 addition & 0 deletions src/elements/image/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,5 @@ The size can be set with `pictureSizesConfig`.
| ----------------------------- | ----------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `--sbb-image-aspect-ratio` | `auto` | Can be used to override `aspectRatio` property. This way we can have, for example, an image component with an aspect ratio of 4/3 in smaller viewports and 16/9 in larger viewports. |
| `--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. |
| `--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. |
| `--sbb-image-object-position` | | Can be used to set the object-position css property of the image itself if the image itself is cropped. |
Loading