Skip to content

Commit

Permalink
Add "identity" CSS class for handling cases with missing images
Browse files Browse the repository at this point in the history
- Implement `%identity-background` to set the background color and apply a bold border.
- Introduce `image-credited__no-image` class that extends `%identity-background`.
  • Loading branch information
kasperbirch1 committed Dec 12, 2023
1 parent 9fc11ff commit 13d65ca
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 7 deletions.
4 changes: 4 additions & 0 deletions src/stories/Blocks/event-page/EventPage.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -109,3 +109,7 @@ export default {
const Template: ComponentStory<typeof Event> = (args) => <Event {...args} />;

export const Default = Template.bind({});
export const withOutImage = Template.bind({});
withOutImage.args = {
image: "",
};
4 changes: 4 additions & 0 deletions src/stories/Library/image-credited/ImageCredited.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,7 @@ const Template: ComponentStory<typeof ImageCredited> = (args) => (
);

export const Default = Template.bind({});
export const withOutImage = Template.bind({});
withOutImage.args = {
src: "",
};
19 changes: 12 additions & 7 deletions src/stories/Library/image-credited/ImageCredited.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import clsx from "clsx";
import { FC } from "react";

type ImageCreditedProps = {
src: string;
Expand All @@ -9,7 +8,7 @@ type ImageCreditedProps = {
className?: string;
};

const ImageCredited: FC<ImageCreditedProps> = ({
const ImageCredited: React.FC<ImageCreditedProps> = ({
src,
alt = "",
description,
Expand All @@ -18,11 +17,17 @@ const ImageCredited: FC<ImageCreditedProps> = ({
}) => {
return (
<figure className={clsx("image-credited", className)}>
<img src={src} className="image-credited__img" alt={alt} />
<div className="image-credited__info">
<span>{description}</span>
<span>{year}</span>
</div>
{src ? (
<>
<img src={src} className="image-credited__img" alt={alt} />
<figcaption className="image-credited__info">
<span>{description}</span>
<span>{year}</span>
</figcaption>
</>
) : (
<div className="image-credited__no-image" />
)}
</figure>
);
};
Expand Down
5 changes: 5 additions & 0 deletions src/stories/Library/image-credited/image-credited.scss
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,8 @@
display: flex;
justify-content: space-between;
}

.image-credited__no-image {
aspect-ratio: 16 / 9;
@extend %identity-background;
}
5 changes: 5 additions & 0 deletions src/styles/scss/shared.scss
Original file line number Diff line number Diff line change
Expand Up @@ -85,3 +85,8 @@
display: inline;
margin: 0 0 -5px 5px;
}

%identity-background {
background-color: var(--tint-color-120);
border: $s-2xl solid $color__identity-primary;
}

0 comments on commit 13d65ca

Please sign in to comment.