Skip to content

Commit

Permalink
feat: support backgroundBox field that changes the background
Browse files Browse the repository at this point in the history
  • Loading branch information
umbobabo committed Mar 7, 2023
1 parent 842429b commit 253979b
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/lib/get-topper-settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,13 @@ const useEditoriallySelectedTopper = (content) => {
if (content.topper.layout === 'full-bleed-offset') {
backgroundColour = 'wheat';
} else if (content.topper.layout === 'deep-landscape') {
if (!hasDarkBackground(content.topper.backgroundColour)) {
// If the backgroundBox is present, use its color to determine a background colour
// The background color won't be visible due to the overlapping image, however, it's needed to
// determine the text color
if (content.topper.backgroundBox) {
backgroundColour =
content.topper.backgroundBox === 'light' ? 'white' : 'black';
} else if (!hasDarkBackground(content.topper.backgroundColour)) {
backgroundColour = 'white';
}
} else if (
Expand Down
23 changes: 23 additions & 0 deletions test/lib/get-topper-settings.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,29 @@ describe('Get topper settings', () => {

expect(topper.backgroundColour).to.equal('white');
});

describe('When a background Box is present', () => {
it('sets the `backgroundColour` to `white` if layout is deep landscape and background Box is light', () => {
const topper = getTopperSettings({
topper: {
layout: 'deep-landscape',
backgroundBox: 'light'
}
});

expect(topper.backgroundColour).to.equal('white');
});
it('sets the `backgroundColour` to `black` if layout is deep landscape and background Box is dark', () => {
const topper = getTopperSettings({
topper: {
layout: 'deep-landscape',
backgroundBox: 'dark'
}
});

expect(topper.backgroundColour).to.equal('black');
});
});
});

describe('Podcast', () => {
Expand Down

0 comments on commit 253979b

Please sign in to comment.