Skip to content

Commit

Permalink
Merge pull request #23 from hlxsites/config-sheet
Browse files Browse the repository at this point in the history
#464411 - Add external components config excel sheet
  • Loading branch information
infloent authored May 28, 2024
2 parents 66aded4 + b9bd59e commit 50a1001
Show file tree
Hide file tree
Showing 15 changed files with 627 additions and 455 deletions.
2 changes: 1 addition & 1 deletion blocks/breadcrumbs/breadcrumbs.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { getBaseUrl } from '../../scripts/libs.js';
export default class Breadcrumbs extends ComponentBase {
static loaderConfig = {
...ComponentBase.loaderConfig,
targetsSelectors: 'main > div',
targetsSelectors: 'main > div:first-child',
targetsSelectorsLimit: 1,
};

Expand Down
3 changes: 0 additions & 3 deletions blocks/columns/columns.css

This file was deleted.

76 changes: 0 additions & 76 deletions blocks/columns/columns.js

This file was deleted.

13 changes: 8 additions & 5 deletions blocks/footer/footer.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,14 @@ import { getMeta } from '../../scripts/libs.js';
const metaFooter = getMeta('footer');
const metaFragment = !!metaFooter && `${metaFooter}.plain.html`;
export default class Footer extends ComponentBase {
fragment = metaFragment || 'footer.plain.html';
static loaderConfig = {
...ComponentBase.loaderConfig,
loaderStopInit() {
return metaFooter === false;
},
};

fragmentPath = metaFragment || 'footer.plain.html';

extendConfig() {
return [
Expand All @@ -15,10 +22,6 @@ export default class Footer extends ComponentBase {
];
}

static earlyStopRender() {
return metaFooter === false;
}

ready() {
const child = this.children[0];
child.replaceWith(...child.children);
Expand Down
13 changes: 8 additions & 5 deletions blocks/header/header.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,14 @@ import { eagerImage, getMeta } from '../../scripts/libs.js';
const metaHeader = getMeta('header');
const metaFragment = !!metaHeader && `${metaHeader}.plain.html`;
export default class Header extends ComponentBase {
fragment = metaFragment || 'header.plain.html';
static loaderConfig = {
...ComponentBase.loaderConfig,
loaderStopInit() {
return metaHeader === false;
},
};

fragmentPath = metaFragment || 'header.plain.html';

dependencies = ['navigation', 'image'];

Expand All @@ -17,10 +24,6 @@ export default class Header extends ComponentBase {
];
}

static earlyStopRender() {
return metaHeader === false;
}

connected() {
eagerImage(this, 1);
}
Expand Down
9 changes: 8 additions & 1 deletion blocks/icon/icon.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,15 @@ export default class Icon extends ComponentBase {

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

onAttributeIconChanged({ oldValue, newValue }) {
if (oldValue === newValue) return;
this.loadIcon(newValue);
}

this.iconName = this.dataset.icon;
async loadIcon(icon) {
this.iconName = icon;
if (!this.cache[this.iconName]) {
this.cache[this.iconName] = {
loading: new Promise((resolve) => {
Expand Down
2 changes: 1 addition & 1 deletion blocks/image/image.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export default class Image extends ComponentBase {
static loaderConfig = {
...ComponentBase.loaderConfig,
targetsSelectors: 'p:has(>picture:only-child) + p:has(> em:only-child > a:only-child)',
selectorTest: (el) => [el.childNodes.length, el.childNodes[0].childNodes.length].every(len => len === 1),
selectorTest: (el) => [el.childNodes.length, el.childNodes[0].childNodes.length].every((len) => len === 1),
targetsAsContainers: true,
};

Expand Down
54 changes: 23 additions & 31 deletions blocks/navigation/navigation.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,30 +9,6 @@ export default class Navigation extends ComponentBase {
targetsSelectors: ':scope > :is(:first-child)',
};

attributesValues = {
compact: {
xs: 'true',
s: 'true',
m: 'true',
all: 'false',
},
};

createButton() {
this.navButton = document.createElement('button');
this.navButton.setAttribute('aria-label', 'Menu');
this.navButton.setAttribute('aria-expanded', 'false');
this.navButton.setAttribute('aria-controls', 'navigation');
this.navButton.setAttribute('aria-haspopup', 'true');
this.navButton.setAttribute('type', 'button');
this.navButton.innerHTML = '<raqn-icon data-icon=menu></raqn-icon>';
this.navButton.addEventListener('click', () => {
this.classList.toggle('active');
this.navButton.setAttribute('aria-expanded', this.classList.contains('active'));
});
return this.navButton;
}

async ready() {
this.active = {};
this.navContent = this.querySelector('ul');
Expand Down Expand Up @@ -90,18 +66,34 @@ export default class Navigation extends ComponentBase {
}
}

createIcon(name = this.icon) {
const icon = document.createElement('raqn-icon');
icon.setAttribute('icon', name);
return icon;
onAttributeIconChanged({ newValue }) {
if (!this.initialized) return;
if (!this.isCompact) return;
this.navIcon.dataset.icon = newValue;
}

createButton() {
this.navButton = document.createElement('button');
this.navButton.setAttribute('aria-label', 'Menu');
this.navButton.setAttribute('aria-expanded', 'false');
this.navButton.setAttribute('aria-controls', 'navigation');
this.navButton.setAttribute('aria-haspopup', 'true');
this.navButton.setAttribute('type', 'button');
this.navButton.innerHTML = `<raqn-icon data-icon=${this.dataset.icon}></raqn-icon>`;
this.navIcon = this.navButton.querySelector('raqn-icon');
this.navButton.addEventListener('click', () => {
this.classList.toggle('active');
this.navButton.setAttribute('aria-expanded', this.classList.contains('active'));
});
return this.navButton;
}

addIcon(elem) {
component.init({
componentName: 'icon',
targets: [elem],
rawClasses: 'icon-chevron-right',
config: {
configByClasses: 'icon-chevron-right',
componentConfig: {
addToTargetMethod: 'append',
},
});
Expand All @@ -111,7 +103,7 @@ export default class Navigation extends ComponentBase {
component.init({
componentName: 'accordion',
targets: [elem],
config: {
componentConfig: {
addToTargetMethod: 'append',
},
nestedComponentsConfig: {
Expand Down
45 changes: 24 additions & 21 deletions blocks/section-metadata/section-metadata.js
Original file line number Diff line number Diff line change
@@ -1,27 +1,30 @@
import { collectAttributes } from '../../scripts/libs.js';
import ComponentBase from '../../scripts/component-base.js';
import { stringToArray } from '../../scripts/libs.js';

// TODO the block for this component should not have content, the values should come only form class attribute as for any other component
// as for any other block. should replace the this.parentElement
export default class SectionMetadata extends ComponentBase {
async ready() {
const classes = [...this.querySelectorAll(':scope > div > div:first-child')].map(
(keyCell) => `${keyCell.textContent.trim()}-${keyCell.nextElementSibling.textContent.trim()}`,
);
static observedAttributes = ['class'];

const { currentAttributes } = collectAttributes(
'section-metadata',
classes,
SectionMetadata.observedAttributes,
this,
);
const section = this.parentElement;
Object.keys(currentAttributes).forEach((key) => {
if (key === 'class') {
section.setAttribute(key, currentAttributes[key]);
} else {
section.setAttribute(`data-${key}`, currentAttributes[key]);
}
});
extendConfig() {
return [
...super.extendConfig(),
{
classes: {
section: 'section',
},
},
];
}

ready() {
this.parentElement.classList.add(this.config.classes.section, ...this.classList.values());
}

onAttributeClassChanged({ oldValue, newValue }) {
if (!this.initialized) return;
if (oldValue === newValue) return;

const opts = { divider: ' ' };
this.parentElement.classList.remove(...stringToArray(oldValue, opts));
this.parentElement.classList.add(...stringToArray(newValue, opts));
}
}
6 changes: 3 additions & 3 deletions blocks/theming/theming.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ export default class Theming extends ComponentBase {

nestedComponentsConfig = {};

constructor() {
super();
setDefaults() {
super.setDefaults();
this.scapeDiv = document.createElement('div');
// keep as it is
this.fragment = metaFragment || 'theming.json';
this.fragmentPath = metaFragment || 'theming.json';
this.skip = ['tags'];
this.toTags = [
'font-size',
Expand Down
15 changes: 8 additions & 7 deletions head.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,18 @@
});

const headerMeta = document.querySelector('meta[name="header"]');
const link = document.createElement('link');
link.setAttribute('rel', 'preload');
link.setAttribute('as', 'fetch');
link.setAttribute('crossorigin', 'anonymous');
const url = headerMeta?.content.trim();
link.href = url ? `${url}.plain.html` : 'header.plain.html';
document.head.appendChild(link);
if (url?.toLowerCase() !== 'false') {
const link = document.createElement('link');
link.setAttribute('rel', 'preload');
link.setAttribute('as', 'fetch');
link.setAttribute('crossorigin', 'anonymous');
link.href = url ? `${url}.plain.html` : 'header.plain.html';
document.head.appendChild(link);
}
</script>
<style>body { display: none; }</style>
<link rel="stylesheet" href="/styles/styles.css" />
<script src="/scripts/pubsub.js" type="module"></script>
<script src="/scripts/component-base.js" type="module"></script>
<script src="/scripts/component-loader.js" type="module"></script>
<script src="/scripts/libs.js" type="module"></script>
Expand Down
Loading

0 comments on commit 50a1001

Please sign in to comment.