diff --git a/content/webapp/components/FeaturedCard/index.tsx b/content/webapp/components/FeaturedCard/index.tsx index ee2210881c..953fd8de09 100644 --- a/content/webapp/components/FeaturedCard/index.tsx +++ b/content/webapp/components/FeaturedCard/index.tsx @@ -27,21 +27,35 @@ import { FeaturedCardWrap, } from './FeaturedCard.styles'; -type Props = PartialFeaturedCard & { +type FeaturedCardProps = PartialFeaturedCard & { background: PaletteColor; textColor: PaletteColor; isReversed?: boolean; }; -const FeaturedCard: FunctionComponent> = ({ - image, - labels, - children, - link, - textColor, - background, - isReversed = false, -}) => { +type FeaturedCardArticleProps = { + article: Article; + background: PaletteColor; + textColor: PaletteColor; +}; + +type FeaturedCardExhibitionProps = { + exhibition: ExhibitionBasic; + background: PaletteColor; + textColor: PaletteColor; +}; + +const FeaturedCardBasic = props => { + const { + image, + labels, + children, + link, + textColor, + background, + isReversed = false, + } = props; + return ( @@ -81,12 +95,6 @@ const FeaturedCard: FunctionComponent> = ({ ); }; -type FeaturedCardArticleProps = { - article: Article; - background: PaletteColor; - textColor: PaletteColor; -}; - export const FeaturedCardArticle: FunctionComponent< FeaturedCardArticleProps > = ({ article, background, textColor }) => { @@ -102,7 +110,7 @@ export const FeaturedCardArticle: FunctionComponent< const labels = [{ text: article.format.label }]; return ( - )} - + ); }; -type FeaturedCardExhibitionProps = { - exhibition: ExhibitionBasic; - background: PaletteColor; - textColor: PaletteColor; -}; - export const FeaturedCardExhibition: FunctionComponent< FeaturedCardExhibitionProps > = ({ exhibition, background, textColor }) => { const props = convertItemToFeaturedCardProps(exhibition); return ( - +

{exhibition.title}

{!exhibition.statusOverride && exhibition.start && exhibition.end && ( @@ -149,9 +151,37 @@ export const FeaturedCardExhibition: FunctionComponent< statusOverride={exhibition.statusOverride} />
-
+ ); }; +const FeaturedCard: FunctionComponent< + | PropsWithChildren + | (FeaturedCardArticleProps & { type: 'article' }) + | (FeaturedCardExhibitionProps & { type: 'exhibition' }) +> = props => { + if (props.type === 'article') { + return ( + + ); + } + + if (props.type === 'exhibition') { + return ( + + ); + } + + return ; +}; + export default FeaturedCard; export { convertCardToFeaturedCardProps, convertItemToFeaturedCardProps }; diff --git a/content/webapp/pages/stories/index.tsx b/content/webapp/pages/stories/index.tsx index ea97faf58b..369117cbdf 100644 --- a/content/webapp/pages/stories/index.tsx +++ b/content/webapp/pages/stories/index.tsx @@ -24,7 +24,7 @@ import Space from '@weco/common/views/components/styled/Space'; import SpacingComponent from '@weco/common/views/components/styled/SpacingComponent'; import SpacingSection from '@weco/common/views/components/styled/SpacingSection'; import CardGrid from '@weco/content/components/CardGrid/CardGrid'; -import { FeaturedCardArticle } from '@weco/content/components/FeaturedCard'; +import FeaturedCard from '@weco/content/components/FeaturedCard'; import FeaturedText from '@weco/content/components/FeaturedText/FeaturedText'; import { defaultSerializer } from '@weco/content/components/HTMLSerializers/HTMLSerializers'; import SectionHeader from '@weco/content/components/SectionHeader/SectionHeader'; @@ -203,7 +203,8 @@ const StoriesPage: FunctionComponent = ({ - = props => { {firstExhibition ? ( -