Skip to content

Commit

Permalink
[Fairground 🎡] Scrollable Feature Container (#12733)
Browse files Browse the repository at this point in the history
Co-authored-by: Charlotte <[email protected]>
  • Loading branch information
abeddow91 and cemms1 authored Nov 1, 2024
1 parent 6716cb4 commit 8ca0c33
Show file tree
Hide file tree
Showing 5 changed files with 123 additions and 1 deletion.
11 changes: 11 additions & 0 deletions dotcom-rendering/src/components/DecideContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import { FlexibleGeneral } from './FlexibleGeneral';
import { FlexibleSpecial } from './FlexibleSpecial';
import { Island } from './Island';
import { NavList } from './NavList';
import { ScrollableFeature } from './ScrollableFeature.importable';
import { ScrollableHighlights } from './ScrollableHighlights.importable';
import { ScrollableMedium } from './ScrollableMedium.importable';
import { ScrollableSmall } from './ScrollableSmall.importable';
Expand Down Expand Up @@ -289,6 +290,16 @@ export const DecideContainer = ({
/>
);
case 'scrollable/feature':
return (
<Island priority="feature" defer={{ until: 'visible' }}>
<ScrollableFeature
trails={trails}
imageLoading={imageLoading}
containerPalette={containerPalette}
absoluteServerTimes={absoluteServerTimes}
/>
</Island>
);
case 'static/feature/2':
default:
return <p>{containerType} is not yet supported</p>;
Expand Down
2 changes: 2 additions & 0 deletions dotcom-rendering/src/components/ScrollableCarousel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ const carouselContainerStyles = css`
${from.tablet} {
gap: ${space[2]}px;
}
${from.wide} {
flex-direction: row;
gap: ${space[1]}px;
Expand Down Expand Up @@ -91,6 +92,7 @@ const carouselContainerStyles = css`

const carouselStyles = css`
display: grid;
width: 100%;
grid-auto-columns: 1fr;
grid-auto-flow: column;
gap: 20px;
Expand Down
68 changes: 68 additions & 0 deletions dotcom-rendering/src/components/ScrollableFeature.importable.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import type { DCRContainerPalette, DCRFrontCard } from '../types/front';
import { FeatureCard } from './FeatureCard';
import { ScrollableCarousel } from './ScrollableCarousel';

type Props = {
trails: DCRFrontCard[];
containerPalette?: DCRContainerPalette;
absoluteServerTimes: boolean;
imageLoading: 'lazy' | 'eager';
};

/**
* A container used on fronts to display a carousel of small cards
*
* ## Why does this need to be an Island?
*
* The carouselling arrow buttons need to run javascript.
*/
export const ScrollableFeature = ({
trails,
containerPalette,
absoluteServerTimes,
imageLoading,
}: Props) => {
return (
<ScrollableCarousel
carouselLength={trails.length}
visibleCardsOnMobile={1}
visibleCardsOnTablet={3}
>
{trails.map((card) => {
return (
<ScrollableCarousel.Item key={card.url}>
<FeatureCard
linkTo={card.url}
format={card.format}
headlineText={card.headline}
byline={card.byline}
showByline={card.showByline}
webPublicationDate={card.webPublicationDate}
kickerText={card.kickerText}
showClock={false}
image={card.image}
isPlayableMediaCard={true}
starRating={card.starRating}
dataLinkName={card.dataLinkName}
discussionApiUrl={card.discussionApiUrl}
discussionId={card.discussionId}
mainMedia={card.mainMedia}
isExternalLink={card.isExternalLink}
// branding={card.branding}
containerPalette={containerPalette}
absoluteServerTimes={absoluteServerTimes}
imageLoading={imageLoading}
aspectRatio="4:5"
imageSize={'feature'}
headlineSizes={{
desktop: 'xsmall',
tablet: 'xxsmall',
mobile: 'xsmall',
}}
/>
</ScrollableCarousel.Item>
);
})}
</ScrollableCarousel>
);
};
41 changes: 41 additions & 0 deletions dotcom-rendering/src/components/ScrollableFeature.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { breakpoints } from '@guardian/source/foundations';
import type { Meta, StoryObj } from '@storybook/react';
import { discussionApiUrl } from '../../fixtures/manual/discussionApiUrl';
import { trails } from '../../fixtures/manual/highlights-trails';
import { FrontSection } from './FrontSection';
import { ScrollableFeature } from './ScrollableFeature.importable';

export default {
title: 'Components/ScrollableFeature',
component: ScrollableFeature,
parameters: {
chromatic: {
viewports: [
breakpoints.mobile,
breakpoints.tablet,
breakpoints.wide,
],
},
},
args: {
trails,
containerPalette: undefined,
absoluteServerTimes: true,
imageLoading: 'eager',
},
} as Meta;

type Story = StoryObj<typeof ScrollableFeature>;

export const WithFrontSection = {
render: (args) => (
<FrontSection
title="Scrollable feature"
discussionApiUrl={discussionApiUrl}
editionId={'UK'}
showTopBorder={false}
>
<ScrollableFeature {...args} />
</FrontSection>
),
} satisfies Story;
2 changes: 1 addition & 1 deletion dotcom-rendering/src/model/enhanceCollections.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const FORBIDDEN_CONTAINERS = [
'qatar treat',
];

const UNSUPPORTED_CONTAINERS = ['scrollable/feature', 'static/feature/2'];
const UNSUPPORTED_CONTAINERS = ['static/feature/2'];

const PALETTE_STYLES_URI =
'https://content.guardianapis.com/atom/interactive/interactives/2022/03/29/fronts-container-colours/default';
Expand Down

0 comments on commit 8ca0c33

Please sign in to comment.