Skip to content

Commit b439148

Browse files
authored
isom-1639 infocards on homepage have a short image height when in 2 (#801)
* refactor Infocards stories * add more stories (different columns) * enhance Infocards - varying height based no layout * add more stories * fix - remain to be h-52 for below md * fix - styling
1 parent 5f5165a commit b439148

File tree

3 files changed

+122
-127
lines changed

3 files changed

+122
-127
lines changed

packages/components/src/interfaces/complex/InfoCards.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ export type SingleCardWithImageProps = Static<
138138
typeof SingleCardWithImageSchema
139139
> & {
140140
site: IsomerSiteProps
141+
layout: IsomerPageLayoutType
141142
LinkComponent?: LinkComponentType
142143
}
143144
export type InfoCardsProps = Static<typeof InfoCardsSchema> & {
Lines changed: 109 additions & 124 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import type { Meta, StoryObj } from "@storybook/react"
22

33
import type { InfoCardsProps } from "~/interfaces"
4+
import type { IsomerPageLayoutType } from "~/types"
45
import InfoCards from "./InfoCards"
56

67
const meta: Meta<InfoCardsProps> = {
@@ -45,137 +46,121 @@ const meta: Meta<InfoCardsProps> = {
4546
export default meta
4647
type Story = StoryObj<typeof InfoCards>
4748

48-
export const WithImage: Story = {
49-
args: {
49+
const generateArgs = ({
50+
layout = "content",
51+
maxColumns,
52+
withoutImage = false,
53+
isImageFitContain = false,
54+
}: {
55+
layout?: IsomerPageLayoutType
56+
maxColumns: "1" | "2" | "3"
57+
withoutImage?: boolean
58+
isImageFitContain?: boolean
59+
}): InfoCardsProps => {
60+
const cards = [
61+
{
62+
title:
63+
"Testing for a card with a long line length that spans across two lines or more",
64+
description:
65+
"Explore Duxton with us and leave with a full belly, tipsy mind, and a happy smile.",
66+
imageUrl: "https://placehold.co/200x300",
67+
imageAlt: "alt text",
68+
imageFit: "contain",
69+
url: "https://www.google.com",
70+
},
71+
{
72+
title: "Card with short title",
73+
description:
74+
"Card description, 200 chars. In the kingdom of Veridonia, the government operates as a benevolent monarchy, guided by ancient traditions and the wisdom of its sovereign.",
75+
imageUrl:
76+
"https://craftypixels.com/placeholder-image/800x400/ffffff/000000&text=Image+with+white+background",
77+
imageAlt: "alt text",
78+
imageFit: "contain",
79+
},
80+
{
81+
title: "Hover on me to see me change colors",
82+
description:
83+
"Card description, 200 chars. In the kingdom of Veridonia, the government operates as a benevolent monarchy, guided by ancient traditions and the wisdom of its sovereign.",
84+
imageUrl: "https://placehold.co/800x200",
85+
imageAlt: "alt text",
86+
imageFit: "contain",
87+
url: "https://www.google.com",
88+
},
89+
{
90+
title: "Testing a card with a larger image and no description",
91+
imageUrl: "https://placehold.co/500x500",
92+
imageAlt: "alt text",
93+
imageFit: "contain",
94+
},
95+
{
96+
title: "A non-placeholder image version",
97+
description: "This is an image that is added using a URL.",
98+
imageUrl:
99+
"https://images.unsplash.com/photo-1722260613137-f8f5ac432d69?q=80&w=3570&auto=format&fit=crop&ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D",
100+
imageAlt: "alt text",
101+
imageFit: "contain",
102+
url: "https://www.google.com",
103+
},
104+
]
105+
106+
if (withoutImage) {
107+
cards.forEach((card) => {
108+
delete (card as any).imageAlt
109+
delete (card as any).imageUrl
110+
})
111+
}
112+
113+
if (!isImageFitContain) {
114+
cards.forEach((card) => {
115+
delete (card as any).imageFit
116+
})
117+
}
118+
119+
return {
120+
layout: layout,
50121
title: "Section title ministry highlights",
51122
subtitle:
52123
"Section subtitle, maximum 150 chars. These are some of the things we are working on. As a ministry, we focus on delivering value to the members of public.",
53-
variant: "cardsWithImages",
54-
cards: [
55-
{
56-
title:
57-
"Testing for a card with a long line length that spans across two lines or more",
58-
description:
59-
"Explore Duxton with us and leave with a full belly, tipsy mind, and a happy smile.",
60-
imageUrl: "https://placehold.co/200x300",
61-
imageAlt: "alt text",
62-
url: "https://www.google.com",
63-
},
64-
{
65-
title: "Card with short title",
66-
description:
67-
"Card description, 200 chars. In the kingdom of Veridonia, the government operates as a benevolent monarchy, guided by ancient traditions and the wisdom of its sovereign.",
68-
imageUrl:
69-
"https://craftypixels.com/placeholder-image/800x400/ffffff/000000&text=Image+with+white+background",
70-
imageAlt: "alt text",
71-
},
72-
{
73-
title: "Hover on me to see me change colors",
74-
description:
75-
"Card description, 200 chars. In the kingdom of Veridonia, the government operates as a benevolent monarchy, guided by ancient traditions and the wisdom of its sovereign.",
76-
imageUrl: "https://placehold.co/800x200",
77-
imageAlt: "alt text",
78-
url: "https://www.google.com",
79-
},
80-
{
81-
title: "Testing a card with a larger image and no description",
82-
imageUrl: "https://placehold.co/500x500",
83-
imageAlt: "alt text",
84-
},
85-
{
86-
title: "A non-placeholder image version",
87-
description: "This is an image that is added using a URL.",
88-
imageUrl:
89-
"https://images.unsplash.com/photo-1722260613137-f8f5ac432d69?q=80&w=3570&auto=format&fit=crop&ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D",
90-
imageAlt: "alt text",
91-
url: "https://www.google.com",
92-
},
93-
],
94-
},
124+
maxColumns: maxColumns,
125+
variant: withoutImage ? "cardsWithoutImages" : "cardsWithImages",
126+
cards: cards,
127+
} as InfoCardsProps
128+
}
129+
130+
export const WithImage3Columns: Story = {
131+
name: "With Image (3 Cols)",
132+
args: generateArgs({ maxColumns: "3" }),
133+
}
134+
135+
export const WithImage3ColumnsHomepage: Story = {
136+
name: "With Image (3 Cols) Homepage",
137+
args: generateArgs({ maxColumns: "3", layout: "homepage" }),
138+
}
139+
140+
export const WithImage2Columns: Story = {
141+
name: "With Image (2 Cols)",
142+
args: generateArgs({ maxColumns: "2" }),
143+
}
144+
145+
export const WithImage2ColumnsHomepage: Story = {
146+
name: "With Image (2 Cols) Homepage",
147+
args: generateArgs({ maxColumns: "2", layout: "homepage" }),
148+
}
149+
150+
export const WithImage1Columns: Story = {
151+
name: "With Image (1 Col)",
152+
args: generateArgs({ maxColumns: "1" }),
153+
}
154+
155+
export const WithImage1ColumnsHomepage: Story = {
156+
name: "With Image (1 Col) Homepage",
157+
args: generateArgs({ maxColumns: "1", layout: "homepage" }),
95158
}
96159

97160
export const NoImage: Story = {
98-
args: {
99-
title: "Section title ministry highlights",
100-
subtitle:
101-
"Section subtitle, maximum 150 chars. These are some of the things we are working on. As a ministry, we focus on delivering value to the members of public.",
102-
variant: "cardsWithoutImages",
103-
cards: [
104-
{
105-
title:
106-
"Testing for a card with a long line length that spans across two lines or more",
107-
description:
108-
"Explore Duxton with us and leave with a full belly, tipsy mind, and a happy smile.",
109-
url: "https://www.google.com",
110-
},
111-
{
112-
title: "Card with short title",
113-
description:
114-
"Card description, 200 chars. In the kingdom of Veridonia, the government operates as a benevolent monarchy, guided by ancient traditions and the wisdom of its sovereign.",
115-
},
116-
{
117-
title: "Hover on me to see me change colors",
118-
description:
119-
"Card description, 200 chars. In the kingdom of Veridonia, the government operates as a benevolent monarchy, guided by ancient traditions and the wisdom of its sovereign.",
120-
url: "https://www.google.com",
121-
},
122-
{
123-
title: "A yummy, tipsy evening at Duxton",
124-
},
125-
],
126-
},
161+
args: generateArgs({ maxColumns: "3", withoutImage: true }),
127162
}
128163

129164
export const WithContainImageFit: Story = {
130-
args: {
131-
title: "Section title ministry highlights",
132-
subtitle:
133-
"Section subtitle, maximum 150 chars. These are some of the things we are working on. As a ministry, we focus on delivering value to the members of public.",
134-
variant: "cardsWithImages",
135-
cards: [
136-
{
137-
title:
138-
"Testing for a card with a long line length that spans across two lines or more",
139-
description:
140-
"Explore Duxton with us and leave with a full belly, tipsy mind, and a happy smile.",
141-
imageUrl: "https://placehold.co/200x300",
142-
imageAlt: "alt text",
143-
imageFit: "contain",
144-
url: "https://www.google.com",
145-
},
146-
{
147-
title: "Card with short title",
148-
description:
149-
"Card description, 200 chars. In the kingdom of Veridonia, the government operates as a benevolent monarchy, guided by ancient traditions and the wisdom of its sovereign.",
150-
imageUrl:
151-
"https://craftypixels.com/placeholder-image/800x400/ffffff/000000&text=Image+with+white+background",
152-
imageAlt: "alt text",
153-
imageFit: "contain",
154-
},
155-
{
156-
title: "Hover on me to see me change colors",
157-
description:
158-
"Card description, 200 chars. In the kingdom of Veridonia, the government operates as a benevolent monarchy, guided by ancient traditions and the wisdom of its sovereign.",
159-
imageUrl: "https://placehold.co/800x200",
160-
imageAlt: "alt text",
161-
url: "https://www.google.com",
162-
imageFit: "contain",
163-
},
164-
{
165-
title: "Testing a card with a larger image and no description",
166-
imageUrl: "https://placehold.co/500x500",
167-
imageAlt: "alt text",
168-
imageFit: "contain",
169-
},
170-
{
171-
title: "A non-placeholder image version",
172-
description: "This is an image that is added using a URL.",
173-
imageUrl:
174-
"https://images.unsplash.com/photo-1722260613137-f8f5ac432d69?q=80&w=3570&auto=format&fit=crop&ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D",
175-
imageAlt: "alt text",
176-
url: "https://www.google.com",
177-
imageFit: "contain",
178-
},
179-
],
180-
},
165+
args: generateArgs({ maxColumns: "3", isImageFitContain: true }),
181166
}

packages/components/src/templates/next/components/complex/InfoCards/InfoCards.tsx

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ const createInfoCardsStyles = tv({
3636
grid: "grid grid-cols-1 gap-10 md:gap-7 lg:gap-x-16 lg:gap-y-12",
3737
cardContainer: "group flex flex-col gap-5 outline-0",
3838
cardImageContainer:
39-
"h-[11.875rem] w-full overflow-hidden rounded-lg border border-base-divider-subtle drop-shadow-none transition ease-in md:h-52",
39+
"w-full overflow-hidden rounded-lg border border-base-divider-subtle drop-shadow-none transition ease-in",
4040
cardImage: "h-full w-full object-center",
4141
cardTextContainer: "flex flex-col gap-2.5 sm:gap-3",
4242
cardTitleArrow:
@@ -49,11 +49,13 @@ const createInfoCardsStyles = tv({
4949
container: "py-12 first:pt-0 md:py-16",
5050
headingContainer: "gap-2.5 lg:max-w-3xl",
5151
headingSubtitle: "prose-headline-lg-regular",
52+
cardImageContainer: "h-[11.875rem] md:h-60",
5253
},
5354
default: {
5455
container: "mt-14 first:mt-0",
5556
headingContainer: "gap-6",
5657
headingSubtitle: "prose-body-base",
58+
cardImageContainer: "h-[11.875rem] md:h-52",
5759
},
5860
},
5961
isClickableCard: {
@@ -116,10 +118,11 @@ const InfoCardImage = ({
116118
imageAlt,
117119
imageFit,
118120
url,
121+
layout,
119122
site,
120123
}: Pick<
121124
SingleCardWithImageProps,
122-
"imageUrl" | "imageAlt" | "url" | "imageFit" | "site"
125+
"imageUrl" | "imageAlt" | "url" | "imageFit" | "layout" | "site"
123126
>): JSX.Element => {
124127
const imgSrc =
125128
isExternalUrl(imageUrl) || site.assetsBaseUrl === undefined
@@ -128,7 +131,10 @@ const InfoCardImage = ({
128131

129132
return (
130133
<div
131-
className={compoundStyles.cardImageContainer({ isClickableCard: !!url })}
134+
className={compoundStyles.cardImageContainer({
135+
layout: getTailwindVariantLayout(layout),
136+
isClickableCard: !!url,
137+
})}
132138
>
133139
<ImageClient
134140
src={imgSrc}
@@ -187,6 +193,7 @@ const InfoCardWithImage = ({
187193
imageAlt,
188194
imageFit,
189195
url,
196+
layout,
190197
site,
191198
LinkComponent,
192199
}: SingleCardWithImageProps): JSX.Element => {
@@ -198,6 +205,7 @@ const InfoCardWithImage = ({
198205
imageAlt={imageAlt}
199206
url={url}
200207
site={site}
208+
layout={layout}
201209
/>
202210
<InfoCardText title={title} description={description} url={url} />
203211
</InfoCardContainer>
@@ -225,6 +233,7 @@ const InfoCards = ({
225233
<InfoCardWithImage
226234
key={idx}
227235
{...card}
236+
layout={layout}
228237
site={site}
229238
LinkComponent={LinkComponent}
230239
/>

0 commit comments

Comments
 (0)