Skip to content

Commit

Permalink
Fix scrollable containers by adjusting islands logic (#12673)
Browse files Browse the repository at this point in the history
* Make scrollable containers islands, moving the scrollable island wrapper to decide container

* Move comments explaining why the scrollable containers need to be islands
  • Loading branch information
Georges-GNM authored Oct 24, 2024
1 parent 5b5dee5 commit b41b474
Show file tree
Hide file tree
Showing 6 changed files with 91 additions and 95 deletions.
40 changes: 22 additions & 18 deletions dotcom-rendering/src/components/DecideContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ 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';
import { ScrollableMedium } from './ScrollableMedium.importable';
import { ScrollableSmall } from './ScrollableSmall.importable';

type Props = {
trails: DCRFrontCard[];
Expand Down Expand Up @@ -253,25 +253,29 @@ export const DecideContainer = ({
);
case 'scrollable/small':
return (
<ScrollableSmall
trails={trails}
imageLoading={imageLoading}
containerType={'scrollable/small'}
containerPalette={containerPalette}
showAge={showAge}
absoluteServerTimes={absoluteServerTimes}
/>
<Island priority="feature" defer={{ until: 'visible' }}>
<ScrollableSmall
trails={trails}
imageLoading={imageLoading}
containerType={'scrollable/small'}
containerPalette={containerPalette}
showAge={showAge}
absoluteServerTimes={absoluteServerTimes}
/>
</Island>
);
case 'scrollable/medium':
return (
<ScrollableMedium
trails={trails}
imageLoading={imageLoading}
containerType={'scrollable/small'}
containerPalette={containerPalette}
showAge={showAge}
absoluteServerTimes={absoluteServerTimes}
/>
<Island priority="feature" defer={{ until: 'visible' }}>
<ScrollableMedium
trails={trails}
imageLoading={imageLoading}
containerType={'scrollable/small'}
containerPalette={containerPalette}
showAge={showAge}
absoluteServerTimes={absoluteServerTimes}
/>
</Island>
);
case 'scrollable/feature':
case 'static/feature/2':
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,10 +153,6 @@ const generateCarouselColumnStyles = (totalCards: number) => {

/**
* A component used in the carousel fronts containers (e.g. small/medium/feature)
*
* ## Why does this need to be an Island?
*
* The carouselling arrow buttons need to run javascript.
*/
export const ScrollableCarousel = ({ children, carouselLength }: Props) => {
const carouselRef = useRef<HTMLOListElement | null>(null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ import type {
DCRFrontCard,
} from '../types/front';
import { FrontCard } from './FrontCard';
import { Island } from './Island';
import { ScrollableCarousel } from './ScrollableCarousel.Importable';
import { ScrollableCarousel } from './ScrollableCarousel';

type Props = {
trails: DCRFrontCard[];
Expand Down Expand Up @@ -52,6 +51,10 @@ const verticalLineStyles = css`

/**
* 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 ScrollableMedium = ({
trails,
Expand All @@ -62,40 +65,35 @@ export const ScrollableMedium = ({
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}
headlineSizes={{
desktop: 'xsmall',
tablet: 'xxsmall',
}}
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>
<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}
headlineSizes={{
desktop: 'xsmall',
tablet: 'xxsmall',
}}
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>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ 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';
import { ScrollableMedium } from './ScrollableMedium.importable';

export default {
title: 'Components/ScrollableMedium',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ import type {
DCRFrontCard,
} from '../types/front';
import { FrontCard } from './FrontCard';
import { Island } from './Island';
import { ScrollableCarousel } from './ScrollableCarousel.Importable';
import { ScrollableCarousel } from './ScrollableCarousel';

type Props = {
trails: DCRFrontCard[];
Expand Down Expand Up @@ -52,6 +51,10 @@ const verticalLineStyles = css`

/**
* 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 ScrollableSmall = ({
trails,
Expand All @@ -62,37 +65,32 @@ export const ScrollableSmall = ({
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}
headlineSizes={{ desktop: 'xxsmall' }}
imagePositionOnDesktop="left"
imagePositionOnMobile="left"
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>
<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}
headlineSizes={{ desktop: 'xxsmall' }}
imagePositionOnDesktop="left"
imagePositionOnMobile="left"
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>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { discussionApiUrl } from '../../fixtures/manual/discussionApiUrl';
import { trails } from '../../fixtures/manual/highlights-trails';
import type { DCRContainerPalette } from '../types/front';
import { FrontSection } from './FrontSection';
import { ScrollableSmall } from './ScrollableSmall';
import { ScrollableSmall } from './ScrollableSmall.importable';

export default {
title: 'Components/ScrollableSmall',
Expand Down

0 comments on commit b41b474

Please sign in to comment.