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

Fix scrollable containers by adjusting islands logic #12673

Merged
merged 2 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
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
Loading