Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scrollable medium setup #12628

Merged
merged 6 commits into from
Oct 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions dotcom-rendering/src/components/DecideContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import { FlexibleSpecial } from './FlexibleSpecial';
import { Island } from './Island';
import { NavList } from './NavList';
import { ScrollableHighlights } from './ScrollableHighlights.importable';
import { ScrollableMedium } from './ScrollableMedium';
import { ScrollableSmall } from './ScrollableSmall';

type Props = {
Expand Down Expand Up @@ -262,6 +263,16 @@ export const DecideContainer = ({
/>
);
case 'scrollable/medium':
return (
<ScrollableMedium
trails={trails}
imageLoading={imageLoading}
containerType={'scrollable/small'}
containerPalette={containerPalette}
showAge={showAge}
absoluteServerTimes={absoluteServerTimes}
/>
);
case 'scrollable/feature':
case 'static/feature/2':
case 'static/medium/4':
Expand Down
35 changes: 35 additions & 0 deletions dotcom-rendering/src/components/ScrollableMedium.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
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 { ScrollableMedium } from './ScrollableMedium';

export default {
title: 'Components/ScrollableMedium',
component: ScrollableMedium,
args: {
trails,
containerPalette: undefined,
showAge: true,
absoluteServerTimes: true,
imageLoading: 'eager',
containerType: 'scrollable/medium',
},
} as Meta;

type Story = StoryObj<typeof ScrollableMedium>;

export const Default = {};

export const WithFrontSection = {
render: (args) => (
<FrontSection
title="Scrollable medium"
discussionApiUrl={discussionApiUrl}
editionId={'UK'}
showTopBorder={false}
>
<ScrollableMedium {...args} />
</FrontSection>
),
} satisfies Story;
100 changes: 100 additions & 0 deletions dotcom-rendering/src/components/ScrollableMedium.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
import { css } from '@emotion/react';
import { from } from '@guardian/source/foundations';
import { palette } from '../palette';
import type {
DCRContainerPalette,
DCRContainerType,
DCRFrontCard,
} from '../types/front';
import { FrontCard } from './FrontCard';
import { Island } from './Island';
import { ScrollableCarousel } from './ScrollableCarousel.Importable';

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

const itemStyles = css`
scroll-snap-align: start;
grid-area: span 1;
position: relative;
`;

const verticalLineStyles = css`
:not(:last-child)::after {
content: '';
position: absolute;
top: 0;
bottom: 0;
right: -10px;
width: 1px;
background-color: ${palette('--card-border-top')};
transform: translateX(-50%);
}
${from.leftCol} {
:first-child::before {
content: '';
position: absolute;
top: 0;
bottom: 0;
left: -10px;
width: 1px;
background-color: ${palette('--card-border-top')};
transform: translateX(-50%);
}
}
`;

/**
* A container used on fronts to display a carousel of small cards
*/
export const ScrollableMedium = ({
trails,
containerPalette,
containerType,
absoluteServerTimes,
imageLoading,
showAge,
}: Props) => {
return (
<Island priority="feature" defer={{ until: 'visible' }}>
<ScrollableCarousel carouselLength={trails.length}>
{trails.map((trail) => {
return (
<li
key={trail.url}
css={[itemStyles, verticalLineStyles]}
>
<FrontCard
trail={trail}
imageLoading={imageLoading}
absoluteServerTimes={!!absoluteServerTimes}
containerPalette={containerPalette}
containerType={containerType}
showAge={!!showAge}
headlineSize="medium"
headlineSizeOnMobile="medium"
headlineSizeOnTablet="medium"
imagePositionOnDesktop="bottom"
imagePositionOnMobile="bottom"
imageSize="small" // TODO - needs fixed width images
trailText={undefined} // unsupported
supportingContent={undefined} // unsupported
aspectRatio="5:4"
kickerText={trail.kickerText}
showLivePlayable={trail.showLivePlayable}
showTopBarDesktop={false}
showTopBarMobile={false}
/>
</li>
);
})}
</ScrollableCarousel>
</Island>
);
};
1 change: 0 additions & 1 deletion dotcom-rendering/src/model/enhanceCollections.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ const FORBIDDEN_CONTAINERS = [
];

const UNSUPPORTED_CONTAINERS = [
'scrollable/medium',
'scrollable/feature',
'static/feature/2',
'static/medium/4',
Expand Down
Loading