Skip to content

Commit 8e14ea8

Browse files
committed
rename hasDarkBackground helper function and add docstring
1 parent fff5a3f commit 8e14ea8

File tree

3 files changed

+13
-9
lines changed

3 files changed

+13
-9
lines changed

dotcom-rendering/src/lib/cardHelpers.test.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type { DCRContainerPalette } from '../types/front';
2-
import { containerPaletteHasDarkBackground } from './cardHelpers';
2+
import { hasDarkBackground } from './cardHelpers';
33

4-
describe('cardHasDarkBackground', () => {
4+
describe('hasDarkBackground', () => {
55
const testCases = [
66
{
77
containerPalette: undefined,
@@ -35,9 +35,7 @@ describe('cardHasDarkBackground', () => {
3535
it.each(testCases)(
3636
'returns $expectedResult for $format format, $containerPalette containerPalette',
3737
({ containerPalette, expectedResult }) => {
38-
expect(containerPaletteHasDarkBackground(containerPalette)).toBe(
39-
expectedResult,
40-
);
38+
expect(hasDarkBackground(containerPalette)).toBe(expectedResult);
4139
},
4240
);
4341
});

dotcom-rendering/src/lib/cardHelpers.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,14 @@ export const isMediaCard = (format: ArticleFormat): boolean => {
1414
}
1515
};
1616

17-
export const containerPaletteHasDarkBackground = (
17+
/**
18+
* Determines whether the application of a container palette override
19+
* results in a dark background for the container and cards inside it
20+
*
21+
* This is primarily used to decide whether to force usage of the logo
22+
* for dark mode when it would otherwise be configured as light mode
23+
*/
24+
export const hasDarkBackground = (
1825
containerPalette?: DCRContainerPalette,
1926
): boolean => {
2027
switch (containerPalette) {
Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
import type { Branding } from '../types/branding';
22
import type { DCRContainerPalette } from '../types/front';
3-
import { containerPaletteHasDarkBackground } from './cardHelpers';
3+
import { hasDarkBackground } from './cardHelpers';
44

55
export const decideBrandingLogo = (
66
branding: Branding,
77
containerPalette?: DCRContainerPalette,
88
): Branding['logo'] => {
9-
return containerPaletteHasDarkBackground(containerPalette) &&
10-
branding.logoForDarkBackground
9+
return hasDarkBackground(containerPalette) && branding.logoForDarkBackground
1110
? branding.logoForDarkBackground
1211
: branding.logo;
1312
};

0 commit comments

Comments
 (0)