Skip to content

Commit

Permalink
🐛 [Amp story page outlink] Default outlink color and warning (#35866)
Browse files Browse the repository at this point in the history
* Default outlink color.

* Remove unnecessary if block.
  • Loading branch information
processprocess committed Sep 2, 2021
1 parent 64cb73b commit 0fd840c
Showing 1 changed file with 20 additions and 13 deletions.
33 changes: 20 additions & 13 deletions extensions/amp-story/1.0/amp-story-open-page-attachment.js
Expand Up @@ -4,6 +4,7 @@
import {AttachmentTheme} from './amp-story-page-attachment';
import {LocalizedStringId} from '#service/localization/strings';
import {computedStyle, setImportantStyles} from '#core/dom/style';
import {dev} from '../../../src/log';
import {getLocalizationService} from './amp-story-localization-service';
import {
getRGBFromCssColorValue,
Expand Down Expand Up @@ -221,23 +222,29 @@ const renderInlineUi = (pageEl, attachmentEl) => {
* @param {!Element} openAttachmentEl
*/
export const setCustomThemeStyles = (attachmentEl, openAttachmentEl) => {
const accentColor = attachmentEl.getAttribute('cta-accent-color');
if (!attachmentEl.hasAttribute('cta-accent-color')) {
dev().warn(
'AMP-STORY-PAGE-OUTLINK',
'No cta-accent-color attribute found.'
);
}

const accentColor =
attachmentEl.getAttribute('cta-accent-color') || '#000000';

// Calculating contrast color (black or white) needed for outlink CTA UI.
let contrastColor = null;
if (accentColor) {
setImportantStyles(attachmentEl, {
'background-color': attachmentEl.getAttribute('cta-accent-color'),
});
setImportantStyles(attachmentEl, {
'background-color': accentColor,
});

const win = toWin(attachmentEl.ownerDocument.defaultView);
const styles = computedStyle(win, attachmentEl);
const rgb = getRGBFromCssColorValue(styles['background-color']);
contrastColor = getTextColorForRGB(rgb);
setImportantStyles(attachmentEl, {
'background-color': '',
});
}
const win = toWin(attachmentEl.ownerDocument.defaultView);
const styles = computedStyle(win, attachmentEl);
const rgb = getRGBFromCssColorValue(styles['background-color']);
contrastColor = getTextColorForRGB(rgb);
setImportantStyles(attachmentEl, {
'background-color': '',
});
if (
attachmentEl.getAttribute('cta-accent-element') ===
CtaAccentElement.BACKGROUND
Expand Down

0 comments on commit 0fd840c

Please sign in to comment.