Skip to content

Commit

Permalink
Merge pull request #11442 from wellcomecollection/featured-card-refactor
Browse files Browse the repository at this point in the history
Featured card refactor
  • Loading branch information
rcantin-w authored Dec 16, 2024
2 parents 8dd6381 + 1ae810b commit 12386dd
Show file tree
Hide file tree
Showing 13 changed files with 539 additions and 360 deletions.
Original file line number Diff line number Diff line change
@@ -1,49 +1,84 @@
import { Meta, StoryObj } from '@storybook/react';

import { ReadmeDecorator } from '@weco/cardigan/config/decorators';
import {
contentAPIArticle,
exhibitionBasic,
} from '@weco/cardigan/stories/data/content';
import { image } from '@weco/cardigan/stories/data/images';
import { font } from '@weco/common/utils/classnames';
import FeaturedCard from '@weco/content/components/FeaturedCard/FeaturedCard';
import FeaturedCard from '@weco/content/components/FeaturedCard';
import Readme from '@weco/content/components/FeaturedCard/README.mdx';

const meta: Meta<typeof FeaturedCard> = {
title: 'Components/Cards/FeaturedCard',
component: FeaturedCard,
args: {
type: 'card',
image: image(),
labels: [{ text: 'Article' }],
labels: [{ text: 'Page' }],
link: { url: '#', text: 'Remote diagnosis from wee to the web' },
background: 'neutral.700',
textColor: 'white',
isReversed: false,
},
argTypes: {
type: {
options: ['card', 'exhibition', 'article'],
control: { type: 'radio' },
},
background: {
options: ['neutral.700', 'warmNeutral.300'],
control: { type: 'select' },
},
textColor: {
options: ['white', 'black'],
control: { type: 'select' },
},
labels: {
table: {
disable: true,
},
},
link: {
table: {
disable: true,
},
},
image: {
table: {
disable: true,
},
},
},
};

export default meta;

type Story = StoryObj<typeof FeaturedCard>;
export const Basic: Story = {
name: 'FeaturedCard',
render: args => (
<ReadmeDecorator
WrappedComponent={FeaturedCard}
args={{
id: 'id',
image: image(),
labels: [{ text: 'Article' }],
link: { url: '#', text: 'Remote diagnosis from wee to the web' },
background: args.background,
textColor: args.textColor,
isReversed: args.isReversed,
}}
Readme={Readme}
>
<h2 className={font('wb', 2)}>Remote diagnosis from wee to the Web</h2>
<p className={font('intr', 5)}>
Medical practice might have moved on from when patients posted flasks of
their urine for doctors to taste, but telehealth today keeps up the
tradition of remote diagnosis – to our possible detriment.
</p>
</ReadmeDecorator>
),
render: args => {
return (
<ReadmeDecorator
WrappedComponent={FeaturedCard}
args={{
...args,
type: args.type || 'card',
image: image(),
link: { url: '#', text: 'Remote diagnosis from wee to the web' },
...(args.type === 'article' && { article: contentAPIArticle }),
...(args.type === 'exhibition' && { exhibition: exhibitionBasic }),
}}
Readme={Readme}
>
<h2 className={font('wb', 2)}>Remote diagnosis from wee to the Web</h2>
<p className={font('intr', 5)}>
Medical practice might have moved on from when patients posted flasks
of their urine for doctors to taste, but telehealth today keeps up the
tradition of remote diagnosis – to our possible detriment.
</p>
</ReadmeDecorator>
);
},
};
55 changes: 52 additions & 3 deletions cardigan/stories/data/content.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@ import { faker } from '@faker-js/faker';

import untransformedBody from '@weco/cardigan/stories/data/untransformed-body';
import { Props as QuoteProps } from '@weco/content/components/Quote/Quote';
import { Article, ArticleBasic } from '@weco/content/types/articles';
import { Article } from '@weco/content/services/wellcome/content/types/api';
import {
ArticleBasic,
Article as TransformedPrismicArticle,
} from '@weco/content/types/articles';
import {
Organisation as OrganisationType,
Person as PersonType,
Expand All @@ -12,6 +16,7 @@ import { ExhibitionBasic } from '@weco/content/types/exhibitions';
import { Season } from '@weco/content/types/seasons';

import {
contentAPIImage,
darkCloudImageUrl,
florenceWinterfloodImageUrl,
image,
Expand Down Expand Up @@ -257,7 +262,7 @@ export const organisation: OrganisationType = {
sameAs: [],
};

export const article: Article = {
export const article: TransformedPrismicArticle = {
type: 'articles',
id: 'YLoCLhAAACEAfyuO',
uid: 'a-dark-cloud',
Expand Down Expand Up @@ -466,5 +471,49 @@ export const exhibitionBasic: ExhibitionBasic = {
end: new Date('2021-09-29T23:00:00+0000'),
isPermanent: false,
contributors: [],
labels: [],
labels: [{ text: 'Exhibition' }],
};

export const contentAPIArticle: Article = {
type: 'Article',
id: 'Zz2g4BAAAB8AAs0L',
uid: 'the-personal-cost-of-mental-illness',
title: 'The personal cost of mental illness',
caption:
'Laura Grace Simpkins is tired of hearing how much her mental ill health costs the country. What about how much it costs her?',
format: {
type: 'ArticleFormat',
id: 'W7TfJRAAAJ1D0eLK',
label: 'Article',
},
publicationDate: '2024-12-11T10:00:07+0000',
contributors: [
{
type: 'Contributor',
contributor: {
type: 'Person',
id: 'YRpIOREAANdN3wpG',
label: 'Laura Grace Simpkins',
},
role: {
type: 'EditorialContributorRole',
id: 'WcUWeCgAAFws-nGh',
label: 'Author',
},
},
{
type: 'Contributor',
contributor: {
type: 'Person',
id: 'Yw8WwhAAADhyTh92',
label: 'Tanya Cooper',
},
role: {
type: 'EditorialContributorRole',
id: 'YEu7zhAAACMAX7IG',
label: 'Artist',
},
},
],
image: contentAPIImage,
};
71 changes: 71 additions & 0 deletions cardigan/stories/data/images.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { LicenseType } from '@weco/common/model/license';
import { Picture } from '@weco/common/model/picture';
import { CaptionedImageProps } from '@weco/content/components/CaptionedImage/CaptionedImage';
import { Props as ImageGalleryProps } from '@weco/content/components/ImageGallery';
import { ContentApiImage } from '@weco/content/services/wellcome/content/types/api';

import { singleLineOfText } from './text';

Expand Down Expand Up @@ -112,3 +113,73 @@ export const imageWithCrops = {
},
},
};

export const contentAPIImage: ContentApiImage = {
type: 'PrismicImage',
dimensions: {
width: 3543,
height: 1993,
},
alt: 'A collage combining photos and illustration featuring a woman in a blue hairnet.',
copyright:
'The personal cost of mental illness | Tanya Cooper for Wellcome Collection | | | CC-BY-NC-ND | |',
url: 'https://images.prismic.io/wellcomecollection/Z1BdtpbqstJ98BwR_WellcomeCollection_Main.jpg?auto=format,compress',
id: 'Z1BdtpbqstJ98BwR',
edit: {
x: 0,
y: 0,
zoom: 1,
background: 'transparent',
},
'32:15': {
dimensions: {
width: 3200,
height: 1500,
},
alt: 'A collage combining photos and illustration featuring a woman in a blue hairnet.',
copyright:
'The personal cost of mental illness | Tanya Cooper for Wellcome Collection | | | CC-BY-NC-ND | |',
url: florenceWinterfloodImageUrl('3200x1500'),
id: 'Z1BdtpbqstJ98BwR',
edit: {
x: 0,
y: 166,
zoom: 1,
background: 'transparent',
},
},
'16:9': {
dimensions: {
width: 3200,
height: 1800,
},
alt: 'A collage combining photos and illustration featuring a woman in a blue hairnet.',
copyright:
'The personal cost of mental illness | Tanya Cooper for Wellcome Collection | | | CC-BY-NC-ND | |',
url: florenceWinterfloodImageUrl('3200x1800'),
id: 'Z1BdtpbqstJ98BwR',
edit: {
x: 0,
y: 0,
zoom: 1,
background: 'transparent',
},
},
square: {
dimensions: {
width: 3200,
height: 3200,
},
alt: 'A collage combining photos and illustration featuring a woman in a blue hairnet.',
copyright:
'The personal cost of mental illness | Tanya Cooper for Wellcome Collection | | | CC-BY-NC-ND | |',
url: florenceWinterfloodImageUrl('3200x3200'),
id: 'Z1BdtpbqstJ98BwR',
edit: {
x: 775,
y: 0,
zoom: 1,
background: 'transparent',
},
},
};
2 changes: 1 addition & 1 deletion content/webapp/components/Body/Body.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import { Props as ComicPreviousNextProps } from '@weco/content/components/ComicP
import FeaturedCard, {
convertCardToFeaturedCardProps,
convertItemToFeaturedCardProps,
} from '@weco/content/components/FeaturedCard/FeaturedCard';
} from '@weco/content/components/FeaturedCard';
import FeaturedText from '@weco/content/components/FeaturedText/FeaturedText';
import { defaultSerializer } from '@weco/content/components/HTMLSerializers/HTMLSerializers';
import OnThisPageAnchors from '@weco/content/components/OnThisPageAnchors/OnThisPageAnchors';
Expand Down
68 changes: 68 additions & 0 deletions content/webapp/components/FeaturedCard/FeaturedCard.helpers.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import { ImageType } from '@weco/common/model/image';
import { Label } from '@weco/common/model/labels';
import linkResolver from '@weco/common/services/prismic/link-resolver';
import { ArticleBasic } from '@weco/content/types/articles';
import { BookBasic } from '@weco/content/types/books';
import { Card } from '@weco/content/types/card';
import { EventSeries } from '@weco/content/types/event-series';
import { EventBasic } from '@weco/content/types/events';
import { ExhibitionBasic } from '@weco/content/types/exhibitions';
import { Guide } from '@weco/content/types/guides';
import { Link } from '@weco/content/types/link';
import { Page } from '@weco/content/types/pages';
import { Season } from '@weco/content/types/seasons';
import { SeriesBasic } from '@weco/content/types/series';

export type PartialFeaturedCard = {
image?: ImageType;
labels: Label[];
link: Link;
};

export function convertCardToFeaturedCardProps(
item: Card
): PartialFeaturedCard {
return {
// We intentionally omit the alt text on promos, so screen reader
// users don't have to listen to the alt text before hearing the
// title of the item in the list.
//
// See https://github.com/wellcomecollection/wellcomecollection.org/issues/6007
image: item.image && {
...item.image,
alt: '',
},
labels: item.format ? [{ text: item.format.title }] : [],
link: { url: item.link || '', text: item.title || '' },
};
}

export function convertItemToFeaturedCardProps(
item:
| ArticleBasic
| ExhibitionBasic
| Season
| Page
| EventSeries
| BookBasic
| SeriesBasic
| EventBasic
| Guide
): PartialFeaturedCard {
return {
image: item.promo?.image && {
...item.promo.image,
// We intentionally omit the alt text on promos, so screen reader
// users don't have to listen to the alt text before hearing the
// title of the item in the list.
//
// See https://github.com/wellcomecollection/wellcomecollection.org/issues/6007
alt: '',
},
labels: item.labels,
link: {
url: linkResolver(item),
text: item.title,
},
};
}
Loading

0 comments on commit 12386dd

Please sign in to comment.