Skip to content

Commit

Permalink
MWPW-151936 - Aside Tiger Team Enhancements (a new hope) (#2782)
Browse files Browse the repository at this point in the history
* MWPW-151936 Aside Tiger Team Enhancements

* fix standard tests

* update tests

* simplify icon area

* set approved desktop column spans

* css updates based on feedback

* account for notifications

* additional fixes for notification asides

* additional tweaks to account for promobar and notification edge cases

* remove unnecessary async/await declarations

* remove additional unnecessary async/awaits

* adjustments to styles based on QA review

* add base min-height for mobile, use variables

---------

Co-authored-by: Megan Thomas <[email protected]>
  • Loading branch information
elan-tbx and meganthecoder committed Aug 29, 2024
1 parent d90dcc0 commit adb35eb
Show file tree
Hide file tree
Showing 8 changed files with 766 additions and 837 deletions.
330 changes: 213 additions & 117 deletions libs/blocks/aside/aside.css

Large diffs are not rendered by default.

29 changes: 20 additions & 9 deletions libs/blocks/aside/aside.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
* Aside - v5.1
*/

import { decorateBlockText, decorateIconStack, applyHoverPlay, decorateBlockBg } from '../../utils/decorate.js';
import { createTag } from '../../utils/utils.js';
import { decorateBlockText, decorateIconStack, applyHoverPlay, decorateBlockBg, decorateTextOverrides } from '../../utils/decorate.js';
import { createTag, getConfig, loadStyle } from '../../utils/utils.js';

// standard/default aside uses same text sizes as the split
const variants = ['split', 'inline', 'notification'];
Expand Down Expand Up @@ -163,6 +163,12 @@ function decoratePromobar(el) {
return foreground;
}

function loadIconography() {
const { miloLibs, codeRoot } = getConfig();
const base = miloLibs || codeRoot;
return new Promise((resolve) => { loadStyle(`${base}/styles/iconography.css`, resolve); });
}

function decorateLayout(el) {
const elems = el.querySelectorAll(':scope > div');
if (elems.length > 1) {
Expand All @@ -182,11 +188,16 @@ function decorateLayout(el) {
}
const picture = text?.querySelector('p picture');
const iconArea = picture ? (picture.closest('p') || createTag('p', null, picture)) : null;
iconArea?.classList.add('icon-area');
if (iconArea) {
const iconVariant = el.className.match(/-(avatar|lockup)/);
const iconClass = iconVariant ? `${iconVariant[1]}-area` : 'icon-area';
if (iconVariant) loadIconography();
iconArea.classList.add(iconClass);
}
const foregroundImage = foreground.querySelector(':scope > div:not(.text) img')?.closest('div');
const bgImage = el.querySelector(':scope > div:not(.text):not(.foreground) img')?.closest('div');
const foregroundMedia = foreground.querySelector(':scope > div:not(.text) video, :scope > div:not(.text) a[href*=".mp4"]')?.closest('div');
const bgMedia = el.querySelector(':scope > div:not(.text):not(.foreground) video, :scope > div:not(.text):not(.foreground) a[href*=".mp4"]')?.closest('div');
const foregroundMedia = foreground.querySelector(':scope > div:not(.text) video, :scope > div:not(.text) a:is([href*=".mp4"], [href*="tv.adobe.com"])')?.closest('div');
const bgMedia = el.querySelector(':scope > div:not(.text):not(.foreground) video, :scope > div:not(.text):not(.foreground) a:is([href*=".mp4"], [href*="tv.adobe.com"])')?.closest('div');
const image = foregroundImage ?? bgImage;
const asideMedia = foregroundMedia ?? bgMedia ?? image;
const isSplit = el.classList.contains('split');
Expand All @@ -202,10 +213,7 @@ function decorateLayout(el) {
} else if (!iconArea) {
foreground?.classList.add('no-image');
}
if (el.classList.contains('split')
&& (el.classList.contains('medium') || el.classList.contains('large'))) {
decorateIconStack(el);
}
if (el.classList.contains('split')) decorateIconStack(el);
return foreground;
}

Expand All @@ -216,4 +224,7 @@ export default function init(el) {
decorateBlockText(blockText, blockData);
decorateStaticLinks(el);
formatPromoButton(el);
decorateTextOverrides(el);
// Override Detail with Title L style if class exists - Temporary solution until Spectrum 2
if (el.classList.contains('l-title')) el.querySelector('[class*="detail-"]')?.classList.add('title-l');
}
71 changes: 53 additions & 18 deletions libs/styles/iconography.css
Original file line number Diff line number Diff line change
@@ -1,28 +1,40 @@
/* iconograph.css
/* iconography.css
This is consonant shared design patterns
dealing w/ groups of media and associated text
- lockup
(coming soon...)
- avatar
*/

:root {
/* lockup sizes */
--type-lockup-all-weight: 700;
--type-lockup-xxl-size: 55px;
--type-lockup-xxl-ls: -0.01em;
--type-lockup-xl-size: 44px;
--type-lockup-xl-ls: -0.01em;
--type-lockup-l-size: 38px;
--type-lockup-l-ls: -0.01em;
--type-lockup-m-size: 27px;
--type-lockup-m-ls: -0.02em;
--type-lockup-s-size: 22px;
--type-lockup-s-ls: -0.02em;
--type-lockup-xs-size: 16px;
--type-lockup-xs-ls: 0;
--type-lockup-xxs-size: 11px;
--type-lockup-xxs-ls: -0.01em;
/* lockup sizes */
--type-lockup-all-weight: 700;
--type-lockup-xxl-size: 55px;
--type-lockup-xxl-ls: -0.01em;
--type-lockup-xl-size: 44px;
--type-lockup-xl-ls: -0.01em;
--type-lockup-l-size: 38px;
--type-lockup-l-ls: -0.01em;
--type-lockup-m-size: 27px;
--type-lockup-m-ls: -0.02em;
--type-lockup-s-size: 22px;
--type-lockup-s-ls: -0.02em;
--type-lockup-xs-size: 16px;
--type-lockup-xs-ls: 0;
--type-lockup-xxs-size: 11px;
--type-lockup-xxs-ls: -0.01em;

/* avatar sizes */
--avatar-size-xxl: 64px;
--avatar-size-xl: 56px;
--avatar-size-l: 40px;
}

@media (min-width: 1200px) {
:root {
--avatar-size-xxl: 80px;
--avatar-size-xl: 64px;
--avatar-size-l: 56px;
}
}

/* Lockup */
Expand Down Expand Up @@ -90,3 +102,26 @@ dealing w/ groups of media and associated text
.l-lockup .lockup-area img { height: var(--icon-size-l); }
.xl-lockup .lockup-area img { height: var(--icon-size-xl); }
.xxl-lockup .lockup-area img { height: var(--icon-size-xxl); }

.avatar-area {
line-height: 0;
margin-bottom: var(--spacing-s);
}

.l-avatar .avatar-area img {
border-radius: 50%;
height: var(--avatar-size-l);
width: var(--avatar-size-l);
}

.xl-avatar .avatar-area img {
border-radius: 50%;
height: var(--avatar-size-xl);
width: var(--avatar-size-xl);
}

.xxl-avatar .avatar-area img {
border-radius: 50%;
height: var(--avatar-size-xxl);
width: var(--avatar-size-xxl);
}
116 changes: 116 additions & 0 deletions test/blocks/aside/aside-legacy.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
import { readFile } from '@web/test-runner-commands';
import { expect } from '@esm-bundle/chai';

document.body.innerHTML = await readFile({ path: './mocks/body.html' });
const { default: init } = await import('../../../libs/blocks/aside/aside.js');

const types = ['simple', 'split', 'inline', 'notification', 'promobar'];

describe('aside', () => {
const asides = document.querySelectorAll('.aside');
asides.forEach((aside) => {
init(aside);

const typeIndex = types.findIndex((v) => aside.classList.contains(v));
const type = typeIndex >= 0 ? types[typeIndex] : 'default';

describe(`aside ${type}`, () => {
const isInline = type === 'inline';

if (type !== 'notification') {
it('has a heading', () => {
const heading = aside.querySelector('[class^=heading-]');
expect(heading).to.exist;
});

it('icon has a wrapper', () => {
const icon = aside.querySelector('.text picture, .promo-text picture');
if (icon) {
expect(icon.closest('.icon-area')).to.exist;
}
});

it('has a body', () => {
const body = aside.querySelector('[class^=body-]');
expect(body).to.exist;
});

it('button has a wrapper', () => {
const button = aside.querySelector('.text .con-button, .promo-text .con-button');
if (button) {
expect(button.closest('p')).to.exist;
}
});

if (aside.classList.contains('icon-stack')) {
it('Has icon stack area', () => {
const iconStack = aside.querySelector('ul.icon-stack-area');
expect(iconStack).to.exist;
});
}

if (aside.classList.contains('aspect-ratio')) {
it('Has aspect ratio set', () => {
let aspectRatios = '';
if (aside.classList.contains('aspect-ratio-three')) {
aspectRatios = aside.querySelector('.mobile-square.tablet-standard.desktop-wide');
expect(aspectRatios).to.exist;
} else if (aside.classList.contains('aspect-ratio-two')) {
aspectRatios = aside.querySelector('.mobile-standard.tablet-wide');
expect(aspectRatios).to.exist;
} else if (aside.classList.contains('aspect-ratio-one')) {
aspectRatios = aside.querySelector('.mobile-standard');
expect(aspectRatios).to.exist;
}
});
}
}

if (type === 'default' || type === isInline) {
it('has an image', () => {
const image = aside.querySelector('.image');
expect(image).to.exist;
});
}

if (type === types[1]) {
it('has a background image or video', () => {
const body = aside.querySelector('.split-image');
expect(body).to.exist;
});
}

if (type === 'promobar') {
it('has viewport content', () => {
const viewportContent = aside.querySelectorAll('.promo-text');
expect(viewportContent.length).to.equal(3);
});

if (aside.classList.contains('popup')) {
it('has promo close button', () => {
const closeBtn = aside.querySelector('.promo-close');
expect(closeBtn).to.exist;
});

if (aside.classList.contains('mobile-promo-only')) {
it('has empty tablet block hidden', () => {
const tabletBlock = aside.querySelector('.tablet-up.hide-block');
expect(tabletBlock).to.exist;
});

it('has empty desktop block hidden', () => {
const desktopBlock = aside.querySelector('.tablet-up.hide-block');
expect(desktopBlock).to.exist;
});
}

it('close button click closes the popup', () => {
const closeBtn = aside.querySelector('.promo-close');
closeBtn.click();
expect(aside.closest('.section').classList.contains('close-sticky-section')).to.be.true;
});
}
}
});
});
});
Loading

0 comments on commit adb35eb

Please sign in to comment.