Skip to content

Commit

Permalink
Merge pull request #12508 from guardian/revert-12499-revert-12153-cc/…
Browse files Browse the repository at this point in the history
…ticker-update

Revert "Revert "Ticker Update""
  • Loading branch information
charleycampbell authored Oct 8, 2024
2 parents e71e207 + d131a24 commit 623abd4
Show file tree
Hide file tree
Showing 12 changed files with 89 additions and 467 deletions.
2 changes: 1 addition & 1 deletion dotcom-rendering/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
"@guardian/ophan-tracker-js": "2.2.5",
"@guardian/shimport": "1.0.2",
"@guardian/source": "8.0.0",
"@guardian/source-development-kitchen": "8.0.0",
"@guardian/source-development-kitchen": "9.0.0",
"@guardian/support-dotcom-components": "2.9.1",
"@guardian/tsconfig": "0.2.0",
"@playwright/test": "1.45.3",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
until,
} from '@guardian/source/foundations';
import { Button, SvgGuardianLogo } from '@guardian/source/react-components';
import { Ticker } from '@guardian/source-development-kitchen/react-components';
import {
hexColourToString,
SecondaryCtaType,
Expand Down Expand Up @@ -47,7 +48,6 @@ import { DesignableBannerCloseButton } from './components/DesignableBannerCloseB
import { DesignableBannerCtas } from './components/DesignableBannerCtas';
import { DesignableBannerHeader } from './components/DesignableBannerHeader';
import { DesignableBannerReminder } from './components/DesignableBannerReminder';
import { DesignableBannerTicker } from './components/DesignableBannerTicker';
import { DesignableBannerVisual } from './components/DesignableBannerVisual';
import type { BannerTemplateSettings, CtaSettings } from './settings';
import { buttonStyles } from './styles/buttonStyles';
Expand Down Expand Up @@ -265,12 +265,13 @@ const DesignableBanner: ReactComponent<BannerRenderProps> = ({
imageSettings,
bannerId: 'designable-banner',
tickerStylingSettings: {
textColour: hexColourToString(ticker.text),
filledProgressColour: hexColourToString(ticker.filledProgress),
progressBarBackgroundColour: hexColourToString(
ticker.progressBarBackground,
),
goalMarkerColour: hexColourToString(ticker.goalMarker),
headlineColour: hexColourToString(ticker.headlineColour),
totalColour: hexColourToString(ticker.totalColour),
goalColour: hexColourToString(ticker.goalColour),
},
};

Expand Down Expand Up @@ -342,9 +343,11 @@ const DesignableBanner: ReactComponent<BannerRenderProps> = ({

{tickerSettings?.tickerData &&
templateSettings.tickerStylingSettings && (
<DesignableBannerTicker
tickerSettings={tickerSettings}
stylingSettings={
<Ticker
currencySymbol={tickerSettings.currencySymbol}
copy={tickerSettings.copy}
tickerData={tickerSettings.tickerData}
tickerStylingSettings={
templateSettings.tickerStylingSettings
}
/>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,198 +0,0 @@
/**
* @file
* This file was migrated from:
* https://github.com/guardian/support-dotcom-components/blob/0a2439b701586a7a2cc60dce10b4d96cf7a828db/packages/modules/src/modules/banners/designableBanner/components/DesignableBannerTicker.tsx
*/
import type { SerializedStyles } from '@emotion/react';
import { css } from '@emotion/react';
import { from, space, textSansBold15 } from '@guardian/source/foundations';
import { TickerCountType } from '@guardian/support-dotcom-components';
import type { TickerSettings } from '@guardian/support-dotcom-components/dist/shared/src/types';
import { useEffect, useState } from 'react';
import { useIsInView } from '../../../../../lib/useIsInView';
import { useTicker } from '../../../hooks/useTicker';
import type { ReactComponent } from '../../../lib/ReactComponent';
import type { TickerStylingSettings } from '../settings';
import { templateSpacing } from '../styles/templateStyles';

const progressBarHeight = 12;
const tickerFillOffset = 15;
const overFilledTickerOffset = 10;

const styles = {
containerStyles: css`
position: relative;
${templateSpacing.bannerTicker}
`,
tickerLabelsContainer: css`
display: flex;
justify-content: space-between;
align-items: end;
margin-bottom: ${space[1]}px;
`,
countLabelStyles: (colour: string) => css`
${textSansBold15};
font-size: 13px;
color: ${colour};
line-height: 1.3;
${from.desktop} {
font-size: 17px;
}
`,
progressBarContainerStyles: css`
position: relative;
`,
progressBarStyles: (backgroundColour: string) => css`
position: relative;
overflow: hidden;
width: 100%;
height: ${progressBarHeight}px;
background: ${backgroundColour};
`,
progressBarTransform: (
end: number,
runningTotal: number,
total: number,
): string => {
const haveStartedAnimating = runningTotal > 0;

if (!haveStartedAnimating) {
return 'translateX(-100%)';
}

const percentage = (total / end) * 100 - 100;

return `translate3d(${percentage >= 0 ? 0 : percentage}%, 0, 0)`;
},
filledProgressStyles: (
end: number,
runningTotal: number,
total: number,
colour: string,
isGoalReached: boolean,
): SerializedStyles => css`
height: ${progressBarHeight}px;
width: calc(
100% - ${isGoalReached ? overFilledTickerOffset : tickerFillOffset}%
);
transform: ${styles.progressBarTransform(end, runningTotal, total)};
transition: transform 3s cubic-bezier(0.25, 0.55, 0.2, 0.85);
background-color: ${colour};
`,
soFarContainerStyles: css`
padding-right: ${space[5]}px;
`,
goalContainerStyles: css`
text-align: end;
margin-right: ${tickerFillOffset}%;
transform: translateX(50%);
`,
goalMarkerStyles: (colour: string): SerializedStyles => css`
border-right: 2px solid ${colour};
height: calc(100% + 6px);
position: absolute;
top: -3px;
right: ${tickerFillOffset}%;
`,
};

type DesignableBannerTickerProps = {
tickerSettings: TickerSettings;
stylingSettings: TickerStylingSettings;
};

const DesignableBannerTicker: ReactComponent<DesignableBannerTickerProps> = ({
tickerSettings,
stylingSettings,
}: DesignableBannerTickerProps) => {
const [readyToAnimate, setReadyToAnimate] = useState(false);

const [hasBeenSeen, setNode] = useIsInView({
debounce: true,
threshold: 0,
});

useEffect(() => {
if (hasBeenSeen) {
setTimeout(() => setReadyToAnimate(true), 500);
}
}, [hasBeenSeen]);

const total = tickerSettings.tickerData?.total ?? 1;
const goal = tickerSettings.tickerData?.goal ?? 1;
const isGoalReached = total >= goal;
const runningTotal = useTicker(total, readyToAnimate);

const currencySymbol =
tickerSettings.countType === TickerCountType.money
? tickerSettings.currencySymbol
: '';

return (
<div ref={setNode} css={styles.containerStyles}>
<div css={styles.tickerLabelsContainer}>
<div css={styles.soFarContainerStyles}>
<div
css={styles.countLabelStyles(
stylingSettings.textColour,
)}
>
{!isGoalReached && currencySymbol}
{isGoalReached
? tickerSettings.copy.goalReachedPrimary
: runningTotal.toLocaleString()}{' '}
<span>
{isGoalReached
? tickerSettings.copy.goalReachedSecondary
: tickerSettings.copy.countLabel}
</span>
</div>
</div>

<div css={styles.goalContainerStyles}>
<div
css={styles.countLabelStyles(
stylingSettings.textColour,
)}
>
{currencySymbol}
{isGoalReached
? runningTotal.toLocaleString()
: goal.toLocaleString()}{' '}
<span>
{isGoalReached
? tickerSettings.copy.countLabel
: 'goal'}
</span>
</div>
</div>
</div>

<div css={styles.progressBarContainerStyles}>
<div
css={styles.progressBarStyles(
stylingSettings.progressBarBackgroundColour,
)}
>
<div
css={styles.filledProgressStyles(
goal,
runningTotal,
total,
stylingSettings.filledProgressColour,
isGoalReached,
)}
/>
</div>
<div
css={styles.goalMarkerStyles(
stylingSettings.goalMarkerColour,
)}
/>
</div>
</div>
);
};

export { DesignableBannerTicker };
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* This file was migrated from:
* https://github.com/guardian/support-dotcom-components/blob/0a2439b701586a7a2cc60dce10b4d96cf7a828db/packages/modules/src/modules/banners/designableBanner/settings.ts
*/
import type { TickerSettings } from '@guardian/source-development-kitchen/react-components';
import type { Image } from '@guardian/support-dotcom-components/dist/shared/src/types';
import type { ReactNode } from 'react';
import type { BannerId } from '../common/types';
Expand Down Expand Up @@ -32,13 +33,6 @@ export interface HighlightedTextSettings {
highlightColour?: string;
}

export interface TickerStylingSettings {
textColour: string;
filledProgressColour: string;
progressBarBackgroundColour: string;
goalMarkerColour: string;
}

export interface HeaderSettings {
textColour?: string;
headerImage?: Image;
Expand All @@ -56,6 +50,6 @@ export interface BannerTemplateSettings {
alternativeVisual?: ReactNode;
choiceCardSettings?: ChoiceCardSettings;
bannerId?: BannerId;
tickerStylingSettings?: TickerStylingSettings;
tickerStylingSettings?: TickerSettings['tickerStylingSettings'];
headerSettings?: HeaderSettings;
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import {
import type {
BannerDesignImage,
SelectedAmountsVariant,
TickerSettings,
} from '@guardian/support-dotcom-components/dist/shared/src/types';
import type { TickerSettings } from '@guardian/support-dotcom-components/dist/shared/src/types';
import type { Meta, StoryObj } from '@storybook/react';
import lzstring from 'lz-string';
import { DesignableBannerUnvalidated as DesignableBanner } from '../../../banners/designableBanner/DesignableBanner';
Expand Down Expand Up @@ -55,19 +55,19 @@ export const Default: Story = {
};

const tickerSettings: TickerSettings = {
endType: TickerEndType.unlimited,
countType: TickerCountType.money,
endType: TickerEndType.hardstop,
currencySymbol: '',
currencySymbol: '£',
copy: {
countLabel: 'contributions in May',
goalReachedPrimary: "We've met our goal - thank you!",
countLabel: 'Help us reach our end-of-year goal',
goalReachedPrimary: '',
goalReachedSecondary: '',
},
tickerData: {
total: 4_000,
goal: 50_000,
total: 500000,
goal: 1000000,
},
name: 'AU',
name: 'US',
};

const regularChoiceCardAmounts: SelectedAmountsVariant = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,9 @@ export const design: ConfigurableDesign = {
filledProgress: stringToHexColour('052962'),
progressBarBackground: stringToHexColour('cccccc'),
goalMarker: stringToHexColour('000000'),
goalColour: stringToHexColour('000000'),
headlineColour: stringToHexColour('000000'),
totalColour: stringToHexColour('000000'),
headlineColour: stringToHexColour('052962'),
totalColour: stringToHexColour('052962'),
goalColour: stringToHexColour('052962'),
},
},
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,14 +198,41 @@ export const WithTicker: Story = {
variant: {
...props.variant,
tickerSettings: {
endType: TickerEndType.unlimited,
countType: TickerCountType.money,
currencySymbol: '£',
copy: {
countLabel: 'Help us reach our end-of-year goal',
goalReachedPrimary: '',
goalReachedSecondary: '',
},
tickerData: {
total: 10000,
goal: 100000,
},
name: 'US',
},
},
},
};

export const WithTickerAndWithAboveTopReaderArticleCount: Story = {
name: 'ContributionsEpic with ticker and top reader article count',
args: {
...meta.args,
variant: {
...props.variant,
separateArticleCount: {
type: 'above',
},
tickerSettings: {
endType: TickerEndType.unlimited,
countType: TickerCountType.money,
currencySymbol: '£',
copy: {
countLabel: 'contributed',
goalReachedPrimary: "We've met our goal - thank you",
goalReachedSecondary:
'Contributions are still being accepted',
countLabel: 'Help us reach our end-of-year goal',
goalReachedPrimary: '',
goalReachedSecondary: '',
},
tickerData: {
total: 10000,
Expand All @@ -214,6 +241,11 @@ export const WithTicker: Story = {
name: 'US',
},
},
articleCounts: {
for52Weeks: 99,
forTargetedWeeks: 99,
},
hasConsentForArticleCount: true,
},
};

Expand Down
Loading

0 comments on commit 623abd4

Please sign in to comment.