Skip to content

Commit

Permalink
MWPW-119392 - Text block updates (adobecom#325)
Browse files Browse the repository at this point in the history
* added Text util()

* refact text init an css

* default heading

* update decorateButtons to include fill and loop in action area.

* gap instead of link margin

* text.body-

* update Text.js bump bus

* style updates

* fixed text analytics ref and moved .md file into martec

* shared utils

* refactored data-con-block styles

* style conflict w/ how-to, updated text block to handle inset variant

* target spacing top / bottom

* section grids

* uneeded func

* Feedback on design review

* XS action area on small grid

* grid 12 with offsets

* Default con-btn: 15, text grid selector

* some edge cases

* fill row mobile

* dialed semantic

* branch to test grid

* auto columns

* grid span instead of offsets

* auto offsets

* auto offset with custom items

* cleanup

* cleanup

* update to text block to support grid

* handling auto cols

* Cleaned up styles and removed comments

* git ignore

* simple up solution

* add grid section metadata test

* simplified selectors

* cleanup

* tests

* random let that is never reassigned

* semantic

* dialed and final cleanup

* icon block test

* updated class names

* some final updates

* testing errors

* add section gap tokens

* ryans review items

* new line in css

* optimize grid widths css calc

* remove calcs for speed and up selector on gaps

* put calcs back because container width breakpoints

* Update text grid and refined text block

* updated decorateText block util to pass param, fixed issue w/ .content in section-meta, updated text styles, js

* grid items start

* text-block test coverage, cleaned up decorateButton, linted text.js

* PR feedback. Fixed scope of actionArea on decorateButton

Co-authored-by: thi64146 <[email protected]>
Co-authored-by: Sartxi <[email protected]>
  • Loading branch information
3 people authored Nov 18, 2022
1 parent 8c729a6 commit f5c5213
Show file tree
Hide file tree
Showing 9 changed files with 179 additions and 160 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ logs/*
node_modules/*
.DS_Store
.idea
.iml
6 changes: 4 additions & 2 deletions libs/blocks/how-to/how-to.css
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
margin: 0 auto;
}
}
ol, h1 {

.how-to ol,
.how-to h1 {
max-width: 700px;
margin: 0 auto;
}
Expand All @@ -26,7 +28,7 @@ ol, h1 {
.how-to ol li {
counter-increment: step-counter;
display: flex;
align-items: center;
align-items: center;
padding: 24px 0;
font-size: 18px;
line-height: 27px;
Expand Down
10 changes: 8 additions & 2 deletions libs/blocks/section-metadata/section-metadata.css
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,17 @@
text-align: center;
}

.section.divider {
border-bottom: 1px solid #d8d8d8;
}

.section.center[class*='-up'] {
justify-items: center;
}

.section.divider {
border-bottom: 1px solid #d8d8d8;
main > .section[class*='-up'] > .content {
max-width: initial;
margin: 0;
}

.section[class*='-up'].no-gap {
Expand Down Expand Up @@ -115,6 +120,7 @@
display: grid;
grid-template-columns: repeat(auto-fit, minmax(276px, 1fr));
gap: var(--spacing-m);
align-items: start;
padding-left: var(--grid-margins-width);
padding-right: var(--grid-margins-width);
}
Expand Down
85 changes: 46 additions & 39 deletions libs/blocks/text/text.css
Original file line number Diff line number Diff line change
@@ -1,25 +1,19 @@
.text-block {
padding: var(--spacing-xxl) 0;
position: relative;
}
.text-block p {
margin: 0 0 var(--spacing-s);
}

.text-block p.action-area {
display: flex;
flex-wrap: wrap;
align-items: center;
gap: var(--spacing-xs);
}
.text-block p,
.text-block [class^="body-"] { margin: var(--spacing-xs) 0; }

.text-block p.action-area a {
margin-right: var(--spacing-s);
}
.text-block [class^="heading"] { margin: 0 0 var(--spacing-xs) 0; }

.text-block p.action-area a.con-button {
flex: 0 0 auto;
}
.text-block [class^="detail"] { margin: 0 0 var(--spacing-xxs) 0; }

.text-block p.action-area { margin-top: var(--spacing-s); }

.text-block div > *:last-child { margin-bottom: 0; }

.grid .text-block div > *:last-child { margin-bottom: var(--spacing-s); }

.text-block .background {
bottom: 0;
Expand All @@ -30,47 +24,60 @@
z-index: -1;
}

.text-block .full-width {
align-items: center;
display: flex;
flex-direction: column;
text-align: center;
width: 100%;
.text-block .foreground {
max-width: var(--grid-container-width);
margin: 0 auto;
}

.text-block .full-width .heading-XL,
.text-block .full-width .heading-L {
margin: 0 0 var(--spacing-xs);
[class*=-up] .text-block .foreground {
max-width: none;
margin: 0;
}

.text-block .full-width p {
margin: 0;
.text-block .action-area {
margin-top: var(--spacing-s);
display: flex;
gap: var(--spacing-s);
flex-wrap: wrap;
align-items: center;
}

.text-block .full-width p:not(:last-child) {
margin: 0 0 var(--spacing-s);
/* Alignment */
.text-block.center {
text-align: center;
align-items: center;
}

.text.vertical p {
margin-bottom: var(--spacing-s);
.text-block.center .action-area { justify-content: center; }

.text-block.right {
text-align: right;
align-items: end;
}

.text.vertical .container > div {
padding: 0 var(--spacing-xs) var(--spacing-m);
.text-block.right .action-area { justify-content: end; }

/* Vertical */
.vertical.text-block .foreground {
padding-bottom: var(--spacing-m);
}

.text.vertical a:not(.con-button) {
font-size: var(--type-body-xs-size);
/* Inset */
.inset.text-block .text {
padding-left: var(--spacing-l);
border-left: 2px solid #ccc;
text-align: left;
}

.text-block .heading-M {
margin: 0 0 var(--spacing-xs);
.inset.text-block .text ul,
.inset.text-block .text ol {
list-style: inside;
padding-left: 0;
}

/* Desktop */

@media screen and (min-width: 1200px) {
.text-block .full-width > * {
.text-block.full-width .foreground {
max-width: calc(var(--grid-column-width) * 8);
}
}
58 changes: 21 additions & 37 deletions libs/blocks/text/text.js
Original file line number Diff line number Diff line change
@@ -1,41 +1,25 @@
/*
* Copyright 2022 Adobe. All rights reserved.
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. You may obtain a copy
* of the License at http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
* OF ANY KIND, either express or implied. See the License for the specific language
* governing permissions and limitations under the License.
*/

import { decorateBlockBg, decorateBlockText } from '../../utils/decorate.js';

/*
* Text Block - v1.0
*/
import { decorateBlockBg, decorateBlockText, getBlockSize } from '../../utils/decorate.js';
import { createTag } from '../../utils/utils.js';

export default function init(el) {
el.classList.add('text-block');
const children = el.querySelectorAll(':scope > div');
const [background, ...cols] = children;
decorateBlockBg(el, background);

const container = document.createElement('div');
container.classList.add('foreground', 'container', 'grid');
el.appendChild(container);

cols.forEach((col, idx) => {
let headingClass = 'medium';
if (idx === 0 && (el.classList.contains('full-width'))) {
col.children[0].classList.add('full-width');
headingClass = el.classList.contains('large') ? 'large' : 'medium';
}
col.children[0].classList.add('text');
decorateBlockText(el, headingClass);
col.querySelector('a + a')?.closest('p').classList.add('action-area');
container.insertAdjacentElement('beforeend', col.children[0]);
col.remove();
});
el.classList.add('text-block', 'con-block');
let rows = el.querySelectorAll(':scope > div');
if (rows.length > 1) {
el.classList.add('has-bg');
const [head, ...tail] = rows;
decorateBlockBg(el, head);
rows = tail;
}
const size = getBlockSize(el);
decorateBlockText(el, size);
rows.forEach((row) => { row.classList.add('foreground'); });
let helperClasses = [];
if (el.classList.contains('full-width')) helperClasses.push('center', 'xxl-spacing');
if (el.classList.contains('intro')) helperClasses.push('xxl-spacing-top', 'xl-spacing-bottom');
if (el.classList.contains('vertical')) {
const elAction = el.querySelector('.action-area');
if (elAction) elAction.classList.add('body-S');
}
el.classList.add(...helperClasses);
}
35 changes: 34 additions & 1 deletion libs/styles/typography.css
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
display: inline-block;
padding: 5px 14px;
text-decoration: none;
font-size: 14px;
font-size: 15px;
line-height: 16px;
font-style: normal;
font-weight: 700;
Expand Down Expand Up @@ -185,3 +185,36 @@ span.icon.margin-left { margin-left: 8px; }
text-align: center;
}
}

/* Con Block Utils */
.con-block.xs-spacing { padding: var(--spacing-xs) 0; }
.con-block.s-spacing { padding: var(--spacing-s) 0; }
.con-block.m-spacing { padding: var(--spacing-m) 0; }
.con-block.l-spacing { padding: var(--spacing-l) 0; }
.con-block.xl-spacing { padding: var(--spacing-xl) 0; }
.con-block.xxl-spacing { padding: var(--spacing-xxl) 0; }
.con-block.no-spacing { padding: 0; }

.con-block.xs-spacing-top { padding-top: var(--spacing-xs); }
.con-block.s-spacing-top { padding-top: var(--spacing-s); }
.con-block.m-spacing-top { padding-top: var(--spacing-m); }
.con-block.l-spacing-top { padding-top: var(--spacing-l); }
.con-block.xl-spacing-top { padding-top: var(--spacing-xl); }
.con-block.xxl-spacing-top { padding-top: var(--spacing-xxl); }
.con-block.no-spacing-top { padding-top: 0; }

.con-block.xs-spacing-bottom { padding-bottom: var(--spacing-xs); }
.con-block.s-spacing-bottom { padding-bottom: var(--spacing-s); }
.con-block.m-spacing-bottom { padding-bottom: var(--spacing-m); }
.con-block.l-spacing-bottom { padding-bottom: var(--spacing-l); }
.con-block.xl-spacing-bottom { padding-bottom: var(--spacing-xl); }
.con-block.xxl-spacing-bottom { padding-bottom: var(--spacing-xxl); }
.con-block.no-spacing-bottom { padding-bottom: 0; }

div[class*='-up'] .con-block.has-bg { padding: var(--spacing-m); }
div[class*='-up'] .con-block.has-bg.xs-spacing { padding: var(--spacing-xs); }
div[class*='-up'] .con-block.has-bg.s-spacing { padding: var(--spacing-s); }
div[class*='-up'] .con-block.has-bg.m-spacing { padding: var(--spacing-m); }
div[class*='-up'] .con-block.has-bg.l-spacing { padding: var(--spacing-l); }
div[class*='-up'] .con-block.has-bg.xl-spacing { padding: var(--spacing-xl); }
div[class*='-up'] .con-block.has-bg.xxl-spacing { padding: var(--spacing-xxl); }
49 changes: 31 additions & 18 deletions libs/utils/decorate.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@ export function decorateButtons(el, size) {
parent.insertAdjacentElement('afterend', button);
parent.remove();
});
const actionArea = buttons[0].closest('p');
actionArea.classList.add('action-area');
actionArea.nextElementSibling?.classList.add('supplemental-text', 'body-XL');
const actionArea = buttons[0].closest('p, div');
if (actionArea) {
actionArea.classList.add('action-area');
actionArea.nextElementSibling?.classList.add('supplemental-text', 'body-XL');
}
}

export function decorateButtonsGroup(el) {
export function decorateIconArea(el) {
const icons = el.querySelectorAll('.icon');
icons.forEach((icon) => {
icon.parentElement.classList.add('icon-area');
Expand All @@ -25,21 +27,32 @@ export function decorateButtonsGroup(el) {
}

export function decorateBlockText(el, size = 'small') {
const blockTypeSizes = {
media: {
// name: [heading, detail, body]
small: ['XS', 'M', 'S'],
medium: ['M', 'M', 'S'],
large: ['XL', 'L', 'M'],
xlarge: ['XXL', 'L', 'M'],
},
text: {
small: ['M', 'S', 'S'],
medium: ['L', 'M', 'M'],
large: ['XL', 'L', 'M'],
xlarge: ['XXL', 'XL', 'L'],
}
};
const sizeType = el.classList.contains('text-block') ? blockTypeSizes.text[size] : blockTypeSizes.media[size];
const decorateHeading = (headingEl, sizes) => {
headingEl.classList.add(`heading-${sizes[0]}`);
headingEl.previousElementSibling?.classList.add(`detail-${sizes[1]}`);
const emptyPs = headingEl.parentElement.querySelectorAll(':scope > p:not([class])');
if (emptyPs) emptyPs.forEach((p) => { p.classList.add(`body-${sizeType[2]}`); });
};
const headings = el.querySelectorAll('h1, h2, h3, h4, h5, h6');
const heading = headings[headings.length - 1];
const decorate = (headingEl, headingSize, bodySize, detailSize) => {
headingEl.classList.add(`heading-${headingSize}`);
headingEl.nextElementSibling?.classList.add(`body-${bodySize}`);
headingEl.previousElementSibling?.classList.add(`detail-${detailSize}`);
};
if (size === 'small') {
decorate(heading, 'XS', 'S', 'M');
} else if (size === 'large') {
decorate(heading, 'XL', 'M', 'L');
} else {
decorate(heading, 'M', 'S', 'M');
}
decorateButtonsGroup(el);
if (heading) decorateHeading(heading, sizeType);
decorateIconArea(el);
decorateButtons(el);
decorateLinkAnalytics(el, headings);
}
Expand All @@ -65,6 +78,6 @@ export function decorateBlockBg(block, node) {
}

export function getBlockSize(el) {
const sizes = ['small', 'medium', 'large'];
const sizes = ['small', 'medium', 'large', 'xlarge'];
return sizes.find((size) => el.classList.contains(size)) || sizes[1]; /* medium default */
}
Loading

0 comments on commit f5c5213

Please sign in to comment.