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

Add dark mode colours for NumberedList titles #9788

Merged
merged 4 commits into from
Dec 7, 2023
Merged
Show file tree
Hide file tree
Changes from 3 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
Original file line number Diff line number Diff line change
@@ -1,66 +1,78 @@
import {
ArticleDesign,
ArticleDisplay,
ArticleSpecial,
Pillar,
} from '@guardian/libs';
import { splitTheme } from '../../.storybook/decorators/splitThemeDecorator';
import { NumberedTitleBlockComponent } from './NumberedTitleBlockComponent';

export default {
component: NumberedTitleBlockComponent,
title: 'Components/NumberedTitleBlockComponent',
};

export const JustH2 = () => (
const allThemes = [
Pillar.News,
Pillar.Sport,
Pillar.Culture,
Pillar.Lifestyle,
Pillar.Opinion,
ArticleSpecial.SpecialReportAlt,
ArticleSpecial.SpecialReport,
ArticleSpecial.Labs,
] as const satisfies ReadonlyArray<ArticleTheme>;

const allThemeStandardVariations = allThemes.map((theme) => ({
design: ArticleDesign.Standard,
display: ArticleDisplay.Standard,
theme,
}));

export const JustH2 = ({ format }: { format: ArticleFormat }) => (
<div>
<NumberedTitleBlockComponent
position={1}
html="<h2>Simple text</h2>"
format={{
theme: 'NewsPillar',
design: 'ArticleDesign',
display: 'StandardDisplay',
}}
format={format}
/>
</div>
);
JustH2.storyName = 'with just h2 text';
JustH2.decorators = [splitTheme(allThemeStandardVariations)];

export const Strong = () => (
export const Strong = ({ format }: { format: ArticleFormat }) => (
<div>
<NumberedTitleBlockComponent
position={1}
html="<h2><strong>Strong text</strong></h2>"
format={{
theme: 'NewsPillar',
design: 'ArticleDesign',
display: 'StandardDisplay',
}}
format={format}
/>
</div>
);
Strong.storyName = 'with only strong text';
Strong.decorators = [splitTheme(allThemeStandardVariations)];

export const Leading = () => (
export const Leading = ({ format }: { format: ArticleFormat }) => (
<div>
<NumberedTitleBlockComponent
position={1}
html="<h2><strong>Strong text</strong> One Plus 7T Pro</h2>"
format={{
theme: 'CulturePillar',
design: 'ArticleDesign',
display: 'StandardDisplay',
}}
format={format}
/>
</div>
);
Leading.storyName = 'with leading strong text';
Leading.decorators = [splitTheme(allThemeStandardVariations)];

export const Trailing = () => (
export const Trailing = ({ format }: { format: ArticleFormat }) => (
<div>
<NumberedTitleBlockComponent
position={1}
html="<h2>Plain H2<strong>Strong text</strong></h2>"
format={{
theme: 'LifestylePillar',
design: 'ArticleDesign',
display: 'StandardDisplay',
}}
format={format}
/>
</div>
);
Trailing.storyName = 'with trailing strong text';
Trailing.decorators = [splitTheme(allThemeStandardVariations)];
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
import { css } from '@emotion/react';
import { headline } from '@guardian/source-foundations';
import { decideFormat } from '../lib/decideFormat';
import { decidePalette } from '../lib/decidePalette';
import { palette as themePalette } from '../palette';
import type { Palette } from '../types/palette';

type Props = {
position: number;
html: string;
format: FEFormat;
format: ArticleFormat;
};

const titleStyles = (palette: Palette) => css`
const titleStyles = () => css`
ioannakok marked this conversation as resolved.
Show resolved Hide resolved
h2 {
${headline.medium({ fontWeight: 'light' })}
}

strong {
${headline.medium({ fontWeight: 'bold' })}
display: block;
color: ${palette.text.numberedTitle};
color: ${themePalette('--numbered-list-title')};
}
`;

Expand All @@ -33,7 +33,8 @@ export const NumberedTitleBlockComponent = ({
html,
format,
}: Props) => {
const palette = decidePalette(decideFormat(format));
const palette = decidePalette(format);

return (
<div
css={css`
Expand All @@ -42,7 +43,7 @@ export const NumberedTitleBlockComponent = ({
>
<div css={numberStyles(palette)}>{position}</div>
<div
css={titleStyles(palette)}
css={titleStyles()}
dangerouslySetInnerHTML={{ __html: html }}
/>
</div>
Expand Down
5 changes: 0 additions & 5 deletions dotcom-rendering/src/lib/decidePalette.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1106,10 +1106,6 @@ const textDateLine = (format: ArticleFormat): string => {
return neutral[46];
};

const textNumberedTitle = (format: ArticleFormat): string => {
return pillarPalette[format.theme].main;
};

const textNumberedPosition = (): string => {
return text.supporting;
};
Expand Down Expand Up @@ -1388,7 +1384,6 @@ export const decidePalette = (
witnessAuthor: textWitnessAuthor(format),
witnessTitle: textWitnessTitle(format),
carouselTitle: textCarouselTitle(format),
numberedTitle: textNumberedTitle(format),
numberedPosition: textNumberedPosition(),
cricketScoreboardLink: textCricketScoreboardLink(),
filterButton: textFilterButton(),
Expand Down
2 changes: 1 addition & 1 deletion dotcom-rendering/src/lib/renderElement.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,7 @@ export const renderElement = ({
<NumberedTitleBlockComponent
position={element.position}
html={element.html}
format={element.format}
format={format}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changing the type from FEFormat to ArticleFormat so that we can see the palette changes in the stories. Previously format was ignored.

/>
);
case 'model.dotcomrendering.pageElements.ProfileAtomBlockElement':
Expand Down
38 changes: 38 additions & 0 deletions dotcom-rendering/src/palette.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2457,6 +2457,40 @@ const keyEventButtonFillLight: PaletteFunction = () =>
sourcePalette.neutral[100];
const keyEventButtonFillDark: PaletteFunction = () => sourcePalette.neutral[7];

const numberedListTitleLight: PaletteFunction = ({ theme }) => {
switch (theme) {
case Pillar.News:
case Pillar.Sport:
case Pillar.Lifestyle:
case Pillar.Culture:
case Pillar.Opinion:
return pillarPalette(theme, 400);
case ArticleSpecial.Labs:
return sourcePalette.labs[400];
case ArticleSpecial.SpecialReport:
return sourcePalette.specialReport[400];
case ArticleSpecial.SpecialReportAlt:
return sourcePalette.specialReportAlt[200];
}
};

const numberedListTitleDark: PaletteFunction = ({ theme }) => {
switch (theme) {
case Pillar.News:
case Pillar.Sport:
case Pillar.Lifestyle:
case Pillar.Culture:
case Pillar.Opinion:
return pillarPalette(theme, 500);
case ArticleSpecial.Labs:
return sourcePalette.labs[400];
case ArticleSpecial.SpecialReport:
return sourcePalette.specialReport[500];
case ArticleSpecial.SpecialReportAlt:
return sourcePalette.specialReportAlt[300];
}
};

const summaryEventBulletLight: PaletteFunction = ({ theme }) => {
switch (theme) {
case Pillar.News:
Expand Down Expand Up @@ -3887,6 +3921,10 @@ const paletteColours = {
light: keyEventButtonFillLight,
dark: keyEventButtonFillDark,
},
'--numbered-list-title': {
light: numberedListTitleLight,
dark: numberedListTitleDark,
},
'--summary-event-bullet': {
light: summaryEventBulletLight,
dark: summaryEventBulletDark,
Expand Down
1 change: 0 additions & 1 deletion dotcom-rendering/src/types/palette.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ export type Palette = {
witnessTitle: Colour;
carouselTitle: Colour;
pagination: Colour;
numberedTitle: Colour;
numberedPosition: Colour;
cricketScoreboardLink: Colour;
filterButton: Colour;
Expand Down
Loading