Skip to content

Commit

Permalink
#520964 - Add template and grid by section
Browse files Browse the repository at this point in the history
  • Loading branch information
infloent committed Oct 2, 2024
1 parent 360e0a7 commit e438a79
Show file tree
Hide file tree
Showing 27 changed files with 679 additions and 295 deletions.
10 changes: 10 additions & 0 deletions blocks/accordion/accordion.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,16 @@ import ComponentBase from '../../scripts/component-base.js';
export default class Accordion extends ComponentBase {
dependencies = ['icon'];

extendConfig() {
return [
...super.extendConfig(),
{
innerComponents: null,
nestedComponentsPrefix: ':scope > ',
},
];
}

extendNestedConfig() {
return [
...super.extendNestedConfig(),
Expand Down
10 changes: 7 additions & 3 deletions blocks/breadcrumbs/breadcrumbs.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ export default class Breadcrumbs extends ComponentBase {
targetsSelectorsLimit: 1,
};

attributesValues = {
all: {
class: 'full-width',
},
};

nestedComponentsConfig = {};

extendConfig() {
Expand All @@ -24,9 +30,7 @@ export default class Breadcrumbs extends ComponentBase {
];
}

connected() {
this.classList.add('full-width');
this.classList.add('breadcrumbs');
addHtml() {
const { origin, pathname } = window.location;
let breadcrumbRoot = getMeta(metaTags.breadcrumbRoot.metaName);
breadcrumbRoot = breadcrumbRoot?.startsWith('/') ? breadcrumbRoot : `/${breadcrumbRoot}`;
Expand Down
2 changes: 1 addition & 1 deletion blocks/button/button.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export default class Button extends ComponentBase {
];
}

connected() {
addEDSHtml() {
this.initAsBlock();
this.queryElements();
this.wrapText();
Expand Down
16 changes: 6 additions & 10 deletions blocks/footer/footer.css
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
footer {
background: var(--background-color);
width: var(--max-width);
margin: 0 auto;
}

raqn-footer {
background: var(--background-color);
border-top: 1px solid var(--text);
padding: 20px 0;

}

raqn-footer ul {
Expand All @@ -22,8 +18,8 @@ raqn-footer ul li a {

@media screen and (min-width: 1024px) {
raqn-footer {
display: grid;
grid-template-columns: auto 20vw;
/* display: grid;
grid-template-columns: auto 20vw; */
}

raqn-footer ul li a {
Expand All @@ -40,10 +36,10 @@ raqn-footer ul li a {
margin: 2em 0;
}

raqn-footer > *:last-child {
/* raqn-footer > *:last-child {
justify-self: end;
align-self: center;
}
} */
}

raqn-footer ul li:last-child a {
Expand Down
12 changes: 7 additions & 5 deletions blocks/footer/footer.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ const metaFooter = getMeta(metaTags.footer.metaName);
export default class Footer extends ComponentBase {
static loaderConfig = {
...ComponentBase.loaderConfig,
targetsSelectors: ':scope > footer',
targetsSelectorsLimit: 1,
loaderStopInit() {
return metaFooter === false;
},
Expand All @@ -17,18 +19,18 @@ export default class Footer extends ComponentBase {
return [
...super.extendConfig(),
{
contentFromTargets: false,
addToTargetMethod: 'append',
targetsAsContainers: {
addToTargetMethod: 'append',
contentFromTargets: false,
},
},
];
}

ready() {
const child = this.children[0];
if (!child) return;
child.replaceWith(...child.children);
this.nav = this.querySelector('ul');
this.nav?.setAttribute('role', 'navigation');
this.classList.add('full-width');
this.classList.add('horizontal');
}
}
39 changes: 37 additions & 2 deletions blocks/grid-item/grid-item.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import ComponentBase from '../../scripts/component-base.js';
import { globalConfig } from '../../scripts/libs.js';

export default class Grid extends ComponentBase {
static observedAttributes = [
Expand All @@ -12,7 +13,7 @@ export default class Grid extends ComponentBase {
'data-align',
];

nestedComponentsConfig = {};
// nestedComponentsConfig = {};

attributesValues = {
all: {
Expand All @@ -22,8 +23,18 @@ export default class Grid extends ComponentBase {
},
};

extendConfig() {
return [
...super.extendConfig(),
{
innerComponents: globalConfig.blockSelector,
},
];
}

setDefaults() {
super.setDefaults();

this.gridParent = null;
}

Expand All @@ -48,7 +59,7 @@ export default class Grid extends ComponentBase {
}
}

connected() {
ready() {
this.gridParent ??= this.parentElement;
}

Expand Down Expand Up @@ -87,4 +98,28 @@ export default class Grid extends ComponentBase {
this.style.removeProperty(prop);
}
}

addEDSHtml() {
if (!this.isInitAsBlock) return;

this.recursiveItems(this.previousElementSibling);
}

recursiveItems(elem) {
if (!elem) return;
if (this.isGridItem(elem)) return;
if (this.isRaqnGrid(elem)) return;

this.prepend(elem);

this.recursiveItems(this.previousElementSibling);
}

isGridItem(elem) {
return elem.tagName === 'DIV' && elem.classList.contains('grid-item');
}

isRaqnGrid(elem) {
return elem.tagName === 'RAQN-GRID-ITEM';
}
}
2 changes: 1 addition & 1 deletion blocks/grid/grid.css
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
raqn-grid {
/* Set to initial to prevent inheritance for nested grids */
--grid-height: initial;
--grid-width: 100%;
--grid-width: initial;
--grid-justify-items: initial;
--grid-align-items: initial;
--grid-justify-content: initial;
Expand Down
95 changes: 16 additions & 79 deletions blocks/grid/grid.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import ComponentBase from '../../scripts/component-base.js';
import { stringToJsVal } from '../../scripts/libs.js';
import component from '../../scripts/init.js';

export default class Grid extends ComponentBase {
static observedAttributes = [
Expand Down Expand Up @@ -29,12 +28,17 @@ export default class Grid extends ComponentBase {
},
};

setDefaults() {
super.setDefaults();
extendConfig() {
return [
...super.extendConfig(),
{
innerComponents: ':scope > .grid-item',
},
];
}

get gridItems() {
return [...this.children];
return [...this.children].filter((el) => el.tagName.toLowerCase() === 'raqn-grid-item');
}

onAttributeHeightChanged({ oldValue, newValue }) {
Expand Down Expand Up @@ -190,87 +194,20 @@ export default class Grid extends ComponentBase {
}
}

async connected() {
await this.collectGridItemsFromBlocks();
}

ready() {
this.cleanGridItems();
}

cleanGridItems() {
// Get all the grid items and remove any non grid item element.
return [...this.children].filter((child) => child.matches('raqn-grid-item') || child.remove());
}

async collectGridItemsFromBlocks() {
async addEDSHtml() {
if (!this.isInitAsBlock) return;

await this.recursiveItems(this.nextElementSibling);
}
const elems = [...this.parentElement.children];

async recursiveItems(elem, children = []) {
if (!elem) return;
if (this.isForbiddenGridItem(elem)) return;
if (this.isForbiddenBlockGrid(elem)) return;
if (this.isForbiddenRaqnGrid(elem)) return;
const gridIndex = elems.indexOf(this);

if (this.isThisGridItem(elem)) {
await this.createGridItem([...children], [...elem.classList]);
await this.recursiveItems(elem.nextElementSibling, []);
elem.remove();
return;
}
let children = elems.slice(gridIndex + 1);

children.push(elem);

await this.recursiveItems(elem.nextElementSibling, children);
}
const lastItem = [...children].reverse().find((el) => el.matches('.grid-item'));
const lastItemIndex = children.indexOf(lastItem);

getLevel(elem = this) {
return Number(elem.dataset.level);
}

getLevelFromClass(elem) {
const levelClass = [...elem.classList].find((cls) => cls.startsWith('data-level-')) || 'data-level-1';
return Number(levelClass.slice('data-level-'.length));
}

isGridItem(elem) {
return elem.tagName === 'DIV' && elem.classList.contains('grid-item');
}

isThisGridItem(elem) {
return this.isGridItem(elem) && this.getLevelFromClass(elem) === this.getLevel();
}

isForbiddenGridItem(elem) {
return this.isGridItem(elem) && this.getLevelFromClass(elem) > this.getLevel();
}

isBlockGrid(elem) {
return elem.tagName === 'DIV' && elem.classList.contains('grid');
}

isRaqnGrid(elem) {
return elem.tagName === 'RAQN-GRID';
}

isForbiddenRaqnGrid(elem) {
return this.isRaqnGrid(elem) && this.getLevel() >= this.getLevel(elem);
}

isForbiddenBlockGrid(elem) {
return this.isBlockGrid(elem) && this.getLevelFromClass(elem) <= this.getLevel();
}
children = children.slice(0, lastItemIndex + 1);

async createGridItem(children, configByClasses) {
await component.loadAndDefine('grid-item');
const tempGridItem = document.createElement('raqn-grid-item');
tempGridItem.init({ configByClasses });
tempGridItem.gridParent = this;
tempGridItem.append(...children);
this.gridItems.push(tempGridItem);
this.append(tempGridItem);
this.append(...children);
}
}
13 changes: 9 additions & 4 deletions blocks/header/header.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@ const metaHeader = getMeta(metaTags.header.metaName);
export default class Header extends ComponentBase {
static loaderConfig = {
...ComponentBase.loaderConfig,
targetsSelectors: ':scope > header',
targetsSelectorsLimit: 1,
loaderStopInit() {
return metaHeader === false;
},
};

attributesValues = {
all: {
class: {
color: 'primary',
},
class: 'color-primary',
},
};

Expand All @@ -27,12 +27,17 @@ export default class Header extends ComponentBase {
return [
...super.extendConfig(),
{
contentFromTargets: false,
addToTargetMethod: 'append',
targetsAsContainers: {
addToTargetMethod: 'append',
contentFromTargets: false,
},
},
];
}

connected() {
ready() {
eagerImage(this, 1);
}
}
12 changes: 8 additions & 4 deletions blocks/icon/icon.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@ const metaIcons = getMeta(metaTags.icons.metaName);
export default class Icon extends ComponentBase {
static observedAttributes = ['data-active', 'data-icon'];

attributesValues = {
all: {
attribute: {
'aria-hidden': 'true',
},
},
};

#initialIcon = null;

#activeIcon = null;
Expand Down Expand Up @@ -52,10 +60,6 @@ export default class Icon extends ComponentBase {
return `${path}/${iconName}.svg`;
}

async connected() {
this.setAttribute('aria-hidden', 'true');
}

// ${viewport}-icon-${value} or icon-${value}
applyIcon(icon) {
this.dataset.icon = isObject(icon) ? flatAsValue(icon) : icon;
Expand Down
Loading

0 comments on commit e438a79

Please sign in to comment.