Skip to content

Commit 2713daf

Browse files
committed
feat: bruk card for thumbnails i komponentoversikten
closes #4781
1 parent 58c663e commit 2713daf

File tree

3 files changed

+53
-15
lines changed

3 files changed

+53
-15
lines changed

ny-portal/src/app/(frontend)/komponenter/ComponentCard.tsx

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1+
import { client } from "@/sanity/client";
2+
import { componentCardQuery } from "@/sanity/queries/component";
13
import imageUrlBuilder from "@sanity/image-url";
24
import NextLink from "next/link";
5+
import { ComponentThumbnail } from "./ComponentThumbnail";
36
import styles from "./komponenter.module.scss";
4-
import { client } from "@/sanity/client";
5-
import { componentCardQuery } from "@/sanity/queries/component";
67

78
type Props = {
89
componentSlug: string;
@@ -91,13 +92,12 @@ export const ComponentCard = async ({ componentSlug }: Props) => {
9192
aria-label={component.name || "Gå til komponent"}
9293
aria-describedby={`${component.name}-description`}
9394
>
94-
<picture className={styles.image}>
95-
<source
96-
media="(prefers-color-scheme: dark)"
97-
srcSet={imageDarkUrl}
95+
{imageDarkUrl && imageLightUrl ? (
96+
<ComponentThumbnail
97+
darkImage={imageDarkUrl}
98+
lightImage={imageLightUrl}
9899
/>
99-
<img className={styles.image} src={imageLightUrl} alt="" />
100-
</picture>
100+
) : null}
101101
<p className={styles.name}>{component.name}</p>
102102
<p
103103
className={styles.description}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
"use client";
2+
3+
import { Card, CardImage } from "@fremtind/jokul";
4+
import styles from "./komponenter.module.scss";
5+
6+
type Props = {
7+
lightImage: string;
8+
darkImage: string;
9+
};
10+
11+
export function ComponentThumbnail({ darkImage, lightImage }: Props) {
12+
return (
13+
<Card variant="high" className={styles.image}>
14+
<picture>
15+
<source
16+
media="(prefers-color-scheme: dark)"
17+
srcSet={darkImage}
18+
/>
19+
<CardImage as="img" placement="top" src={lightImage} alt="" />
20+
</picture>
21+
</Card>
22+
);
23+
}

ny-portal/src/app/(frontend)/komponenter/komponenter.module.scss

+22-7
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* stylelint-disable declaration-block-no-redundant-longhand-properties */
12
@use "@fremtind/jokul/styles/core/jkl";
23

34
.pageTitle {
@@ -25,7 +26,17 @@
2526
margin: 0;
2627
display: grid;
2728
grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
28-
gap: jkl.$spacing-24;
29+
column-gap: clamp(
30+
var(--jkl-unit-10),
31+
0.4038rem + 0.3846vw,
32+
var(--jkl-unit-15)
33+
);
34+
35+
row-gap: clamp(
36+
var(--jkl-unit-30),
37+
1.1154rem + 1.5385vw,
38+
var(--jkl-unit-50)
39+
);
2940
container-type: inline-size;
3041

3142
&.listView {
@@ -40,9 +51,12 @@
4051
}
4152

4253
.componentCard {
54+
--aspect-ratio: 1.5;
55+
4356
display: grid;
4457
grid-template-columns: 1fr;
45-
gap: var(--jkl-unit-30);
58+
gap: clamp(var(--jkl-unit-10), 0.3077rem + 0.7692vw, var(--jkl-unit-20));
59+
box-sizing: border-box;
4660
width: 100%;
4761
text-decoration: none;
4862
color: var(--color-text);
@@ -120,10 +134,11 @@
120134
}
121135

122136
.image {
123-
width: 100%;
124-
height: auto;
125-
object-fit: cover;
126-
border-radius: var(--jkl-spacing-16);
127-
aspect-ratio: 1.6;
137+
aspect-ratio: var(--aspect-ratio);
138+
139+
img {
140+
object-fit: cover;
141+
aspect-ratio: var(--aspect-ratio);
142+
}
128143
}
129144
}

0 commit comments

Comments
 (0)