Skip to content

Commit e2f3931

Browse files
authored
Merge pull request #1125 from isaacphysics/improvement/ada-accordion-colour-coding
Improve Ada accordion colour styling
2 parents ef3eaf4 + e2ddc6f commit e2f3931

File tree

2 files changed

+31
-35
lines changed

2 files changed

+31
-35
lines changed

src/app/services/userViewingContext.ts

Lines changed: 30 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -422,24 +422,36 @@ export function notRelevantMessage(userContext: UseUserContextReturnType): strin
422422
}
423423

424424
export function audienceStyle(audienceString: string): string {
425-
switch (audienceString) {
426-
case stageLabelMap.a_level:
427-
return "stage-label-alevel";
428-
case stageLabelMap.gcse:
429-
return "stage-label-gcse";
430-
case stageLabelMap.scotland_national_5:
431-
return "stage-label-national-5";
432-
case stageLabelMap.scotland_higher:
433-
return "stage-label-higher";
434-
case stageLabelMap.scotland_advanced_higher:
435-
return "stage-label-advanced-higher";
436-
case stageLabelMap.core:
437-
return "stage-label-core";
438-
case stageLabelMap.advanced:
439-
return "stage-label-advanced";
440-
default:
441-
return "stage-label-all";
442-
}
425+
const audienceStages = audienceString.split('\n').flatMap(line => line.split(', '));
426+
427+
// Convert to css labels
428+
const stageLabels = audienceStages.map(
429+
stage => {switch (stage) {
430+
case stageLabelMap.core:
431+
case stageLabelMap.gcse:
432+
case stageLabelMap.scotland_national_5:
433+
return "stage-label-core";
434+
435+
case stageLabelMap.advanced:
436+
case stageLabelMap.a_level:
437+
case stageLabelMap.scotland_advanced_higher:
438+
return "stage-label-advanced";
439+
440+
case stageLabelMap.scotland_higher:
441+
// Scotland higher has a unique styling
442+
return "stage-label-higher";
443+
444+
default:
445+
return "stage-label-all";
446+
}}
447+
);
448+
const uniqueLabels = audienceStages.length === 1
449+
? new Set(stageLabels)
450+
// If multiple stages are present group into "advanced" and "core"
451+
: new Set(stageLabels.map(v => v === "stage-label-higher" ? "stage-label-advanced" : v));
452+
453+
// If only one group exists use that colour, otherwise, use the mixed colour
454+
return uniqueLabels.size === 1 ? uniqueLabels.values().next().value : "stage-label-all";
443455
}
444456

445457
export function stringifyAudience(audience: ContentDTO["audience"], userContext: UseUserContextReturnType, intendedAudience: boolean): string {

src/scss/cs/accordions.scss

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,17 @@
11
@import "../common/accordions";
22

3-
.stage-label-gcse, .stage-label-alevel, .stage-label-national-5, .stage-label-higher, .stage-label-advanced-higher, .stage-label-core, .stage-label-advanced, .stage-label-all {
3+
.stage-label-higher, .stage-label-core, .stage-label-advanced, .stage-label-all {
44
color: black;
55
font-weight: 600;
66
text-wrap: none;
77
font-size: 1rem !important;
88
line-height: 1.15rem;
99
}
1010

11-
.stage-label-gcse {
12-
background-color: $gcse-colour;
13-
}
14-
15-
.stage-label-alevel {
16-
background-color: $a-level-colour;
17-
}
18-
19-
.stage-label-national-5 {
20-
background-color: $national-5-colour;
21-
}
22-
2311
.stage-label-higher {
2412
background-color: $higher-colour;
2513
}
2614

27-
.stage-label-advanced-higher {
28-
background-color: $adv-higher-colour;
29-
}
30-
3115
.stage-label-core {
3216
background-color: $core-colour;
3317
}

0 commit comments

Comments
 (0)