Skip to content

Commit

Permalink
Quiz Atom Dark Mode (#13169)
Browse files Browse the repository at this point in the history
Makes some Design-suggested changes to colours in the quiz atom to improve support for dark mode, particularly in the box that shows the results. Also makes a small tweak to the padding in that results box.
  • Loading branch information
JamieB-gu authored Jan 17, 2025
1 parent 68ae045 commit ee88ba1
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 13 deletions.
20 changes: 15 additions & 5 deletions dotcom-rendering/src/components/KnowledgeQuizAtom.importable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { css } from '@emotion/react';
import { isUndefined } from '@guardian/libs';
import {
article17,
palette,
space,
textSans17,
textSansBold17,
Expand All @@ -12,6 +11,7 @@ import { Button, Radio, RadioGroup } from '@guardian/source/react-components';
import { Fragment, useEffect, useState } from 'react';
import { ArticleSpecial } from '../lib/articleFormat';
import type { ArticleFormat, ArticleTheme } from '../lib/articleFormat';
import { palette } from '../palette';
import type {
AnswerType,
KnowledgeQuizAtomType,
Expand Down Expand Up @@ -182,6 +182,15 @@ export const Question = ({
onClick={() => {
setHasSubmitted(true);
}}
theme={{
backgroundPrimary: palette(
'--quiz-atom-button-background',
),
textPrimary: palette('--quiz-atom-button-text'),
backgroundPrimaryHover: palette(
'--quiz-atom-button-background-hover',
),
}}
onKeyDown={(
e: React.KeyboardEvent<HTMLButtonElement>,
) => {
Expand Down Expand Up @@ -299,10 +308,12 @@ const Answers = ({
};

const resultWrapperStyles = css`
background-color: ${palette.neutral[93]};
background-color: ${palette('--quiz-atom-results-background')};
color: ${palette('--quiz-atom-results-text')};
margin-top: ${space[3]}px;
margin-bottom: ${space[3]}px;
padding: ${space[2]}px;
border: 1px solid ${palette('--quiz-atom-results-border')};
`;

const resultDescriptionStyles = css`
Expand All @@ -313,13 +324,12 @@ const resultDescriptionStyles = css`

const resultsNumberStyles = css`
${textSansBold34}
color: ${palette.brand[400]};
color: ${palette('--quiz-atom-results-number')};
`;

const resultHeaderStyles = css`
${textSansBold17}
color: ${palette.neutral[20]};
padding-bottom: ${space[1]}px;
padding-bottom: ${space[2]}px;
`;

export const Result = ({
Expand Down
26 changes: 18 additions & 8 deletions dotcom-rendering/src/components/PersonalityQuizAtom.importable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { css } from '@emotion/react';
import { isUndefined } from '@guardian/libs';
import {
article17,
palette,
palette as sourcePalette,
space,
textSans17,
textSansBold17,
Expand All @@ -12,6 +12,7 @@ import type { KeyboardEvent, MouseEvent } from 'react';
import { memo, useEffect, useState } from 'react';
import { ArticleSpecial } from '../lib/articleFormat';
import type { ArticleFormat, ArticleTheme } from '../lib/articleFormat';
import { palette } from '../palette';
import type {
AnswerType,
PersonalityQuizAtomType,
Expand Down Expand Up @@ -205,6 +206,15 @@ export const PersonalityQuizAtom = ({
<Button
type="submit"
onClick={onSubmit}
theme={{
backgroundPrimary: palette(
'--quiz-atom-button-background',
),
textPrimary: palette('--quiz-atom-button-text'),
backgroundPrimaryHover: palette(
'--quiz-atom-button-background-hover',
),
}}
onKeyDown={(e: React.KeyboardEvent<HTMLButtonElement>) => {
const spaceKey = 32;
const enterKey = 13;
Expand Down Expand Up @@ -344,8 +354,8 @@ const AnswersGroup = memo(
label {
:hover {
background-color: ${hasSubmittedAnswers
? palette.neutral[97]
: palette.neutral[86]};
? palette('--quiz-atom-answers-background')
: palette('--quiz-atom-answers-hover')};
}
/* TODO: apply same styles on focus (requires source update) */
}
Expand Down Expand Up @@ -378,7 +388,7 @@ AnswersGroup.displayName = 'AnswersGroup';
const missingAnswersStyles = css`
${textSansBold17}
padding-bottom: ${space[3]}px;
color: ${palette.error[500]};
color: ${sourcePalette.error[500]};
`;

export const MissingAnswers = () => (
Expand All @@ -388,21 +398,21 @@ export const MissingAnswers = () => (
);

const resultWrapperStyles = css`
background-color: ${palette.neutral[93]};
background-color: ${palette('--quiz-atom-results-background')};
color: ${palette('--quiz-atom-results-text')};
margin-top: ${space[3]}px;
margin-bottom: ${space[3]}px;
padding: ${space[2]}px;
border: 1px solid ${palette('--quiz-atom-results-border')};
`;

const resultHeaderStyles = css`
${textSansBold17}
color: ${palette.neutral[20]};
padding-bottom: ${space[1]}px;
padding-bottom: ${space[2]}px;
`;

const resultDescriptionStyles = css`
${textSans17}
color: ${palette.neutral[46]};
`;

export const Result = ({
Expand Down
28 changes: 28 additions & 0 deletions dotcom-rendering/src/paletteDeclarations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6847,6 +6847,18 @@ const paletteColours = {
light: () => sourcePalette.neutral[86],
dark: () => sourcePalette.neutral[38],
},
'--quiz-atom-button-background': {
light: () => sourcePalette.brand[400],
dark: () => sourcePalette.neutral[86],
},
'--quiz-atom-button-background-hover': {
light: () => '#234B8A',
dark: () => sourcePalette.neutral[93],
},
'--quiz-atom-button-text': {
light: () => sourcePalette.neutral[100],
dark: () => sourcePalette.brand[400],
},
'--quiz-atom-check-mark': {
light: () => sourcePalette.neutral[0],
dark: () => sourcePalette.neutral[97],
Expand All @@ -6855,6 +6867,22 @@ const paletteColours = {
light: () => sourcePalette.news[400],
dark: () => sourcePalette.news[300],
},
'--quiz-atom-results-background': {
light: () => sourcePalette.neutral[93],
dark: () => sourcePalette.neutral[10],
},
'--quiz-atom-results-border': {
light: () => sourcePalette.neutral[93],
dark: () => sourcePalette.neutral[46],
},
'--quiz-atom-results-number': {
light: () => sourcePalette.brand[400],
dark: () => sourcePalette.neutral[86],
},
'--quiz-atom-results-text': {
light: () => sourcePalette.neutral[7],
dark: () => sourcePalette.neutral[86],
},
'--quote-icon-fill': {
light: richLinkQuoteFillLight,
dark: richLinkFillDark,
Expand Down

0 comments on commit ee88ba1

Please sign in to comment.