Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#464411 - Add external components config excel sheet #23

Merged
merged 4 commits into from
May 28, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 metaFragment === 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
46 changes: 25 additions & 21 deletions blocks/section-metadata/section-metadata.js
Original file line number Diff line number Diff line change
@@ -1,27 +1,31 @@
import { collectAttributes } from '../../scripts/libs.js';
// 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
Loading
Loading