Skip to content

Commit

Permalink
Merge pull request #40 from Financial-Times/feat/CI-1517-deep-landscape
Browse files Browse the repository at this point in the history
CI-1517: Add styling changes for topic and myft for deep landscape
  • Loading branch information
phil-hunt-ft authored Feb 28, 2023
2 parents 4efb8ca + b00ac03 commit 842429b
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 9 deletions.
5 changes: 5 additions & 0 deletions src/lib/get-topper-settings.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
const { hasDarkBackground } = require('./utils');
const themeImageRatio = {
'split-text-center': 'split',
'split-text-left': 'split',
Expand Down Expand Up @@ -104,6 +105,10 @@ const useEditoriallySelectedTopper = (content) => {
// Convert old palette colours to new palette colours from Methode
if (content.topper.layout === 'full-bleed-offset') {
backgroundColour = 'wheat';
} else if (content.topper.layout === 'deep-landscape') {
if (!hasDarkBackground(content.topper.backgroundColour)) {
backgroundColour = 'white';
}
} else if (
content.topper.backgroundColour === 'pink' ||
content.topper.backgroundColour === 'auto'
Expand Down
14 changes: 14 additions & 0 deletions src/lib/utils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
const hasDarkBackground = (backgroundColour) => {
const darkBackgrounds = ['black', 'slate', 'oxford', 'claret', 'crimson'];
return darkBackgrounds.includes(backgroundColour);
};

const hasLightBackground = (backgroundColour) => {
const lightBackgrounds = ['paper', 'wheat', 'white'];
return lightBackgrounds.includes(backgroundColour);
};

module.exports = {
hasDarkBackground,
hasLightBackground
};
18 changes: 9 additions & 9 deletions src/map-content-to-topper.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ const {
getTopperSettings
} = require('./lib/get-topper-settings');

const myFtButtonVariant = (backgroundColour) => {
const lightBackgrounds = ['paper', 'wheat', 'white'];
const hasLightBackground = lightBackgrounds.indexOf(backgroundColour) > -1;
return !backgroundColour || hasLightBackground ? 'standard' : 'monochrome';
};
const { hasDarkBackground, hasLightBackground } = require('./lib/utils');

const hasDarkBackground = (backgroundColour) => {
const darkBackgrounds = ['black', 'slate', 'oxford', 'claret', 'crimson'];
return darkBackgrounds.indexOf(backgroundColour) > -1;
const myFtButtonVariant = (backgroundColour, layout) => {
if (layout === 'deep-landscape' && hasLightBackground(backgroundColour)) {
return 'inverse-monochrome';
}
return !backgroundColour || hasLightBackground(backgroundColour)
? 'standard'
: 'monochrome';
};

module.exports = (content, flags = {}) => {
Expand All @@ -27,7 +27,7 @@ module.exports = (content, flags = {}) => {
standfirst:
content.descriptionHTML || topper.standfirst || content.standfirst,
myFtButton: {
variant: myFtButtonVariant(settings.backgroundColour),
variant: myFtButtonVariant(settings.backgroundColour, settings.layout),
followPlusDigestEmail: followPlusDigestEmail(flags)
},
themeImageRatio: themeImageRatio[settings.layout]
Expand Down
8 changes: 8 additions & 0 deletions test/lib/get-topper-settings.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,14 @@ describe('Get topper settings', () => {

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

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

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

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

0 comments on commit 842429b

Please sign in to comment.