-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Fairground 🎡] Scrollable Feature Container (#12733)
Co-authored-by: Charlotte <[email protected]>
- Loading branch information
Showing
5 changed files
with
123 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
dotcom-rendering/src/components/ScrollableFeature.importable.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
41
dotcom-rendering/src/components/ScrollableFeature.stories.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters