Skip to content

Commit

Permalink
tabs section
Browse files Browse the repository at this point in the history
  • Loading branch information
msagolj committed Oct 9, 2024
1 parent b5cd3f9 commit bfb5677
Show file tree
Hide file tree
Showing 7 changed files with 158 additions and 12 deletions.
17 changes: 17 additions & 0 deletions component-definition.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,23 @@
}
}
}
},
{
"title": "Tab Section",
"id": "tab-section",
"plugins": {
"xwalk": {
"page": {
"resourceType": "core/franklin/components/section/v1/section",
"template": {
"name": "Tab Section",
"model": "tab-section",
"filter": "tab-section",
"style": "tab-section"
}
}
}
}
}
]
},
Expand Down
18 changes: 18 additions & 0 deletions component-filters.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,24 @@
"title"
]
},
{
"id": "tab-section",
"components": [
"text",
"image",
"button",
"title",
"columns",
"icon-block",
"teaser",
"detailed-teaser",
"video-embed",
"media",
"block-quote",
"callout",
"note"
]
},
{
"id": "cards",
"components": [
Expand Down
22 changes: 22 additions & 0 deletions component-models.json
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,28 @@
}
]
},
{
"id": "tab-section",
"fields": [
{
"component": "select",
"name": "style",
"value": "",
"label": "Style",
"description": "The section style",
"valueType": "string",
"hidden": true,
"options": []
},
{
"component": "text",
"valueType": "string",
"name": "title",
"value": "",
"label": "Tab heading"
}
]
},
{
"id": "page-metadata",
"fields": [
Expand Down
57 changes: 57 additions & 0 deletions models/_section.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,23 @@
}
}
}
},
{
"title": "Tab Section",
"id": "tab-section",
"plugins": {
"xwalk": {
"page": {
"resourceType": "core/franklin/components/section/v1/section",
"template": {
"name": "Tab Section",
"model": "tab-section",
"filter": "tab-section",
"style": "tab-section"
}
}
}
}
}
],
"models": [
Expand All @@ -33,6 +50,28 @@
]
}
]
},
{
"id": "tab-section",
"fields": [
{
"component": "select",
"name": "style",
"value": "",
"label": "Style",
"description": "The section style",
"valueType": "string",
"hidden": true,
"options": []
},
{
"component": "text",
"valueType": "string",
"name": "title",
"value": "",
"label": "Tab heading"
}
]
}
],
"filters": [
Expand All @@ -56,6 +95,24 @@
"image",
"title"
]
},
{
"id": "tab-section",
"components": [
"text",
"image",
"button",
"title",
"columns",
"icon-block",
"teaser",
"detailed-teaser",
"video-embed",
"media",
"block-quote",
"callout",
"note"
]
}
]
}
2 changes: 1 addition & 1 deletion scripts/aem.js
Original file line number Diff line number Diff line change
Expand Up @@ -539,7 +539,7 @@ async function fetchPlaceholders(prefix = 'default') {
* @param {string} blockName name of the block
* @param {*} content two dimensional array or string or object of content
*/
function buildBlock(blockName, content) {
export function buildBlock(blockName, content) {
const table = Array.isArray(content) ? content : [[content]];
const blockEl = document.createElement('div');
// build image block nested div structure
Expand Down
11 changes: 0 additions & 11 deletions scripts/editor-support.js
Original file line number Diff line number Diff line change
Expand Up @@ -174,17 +174,6 @@ function handleEditorSelect(event) {
// click it
button.click();
}

// if a teaser in a carousel was selected
if (event.target.closest('.panel-container')) {
// switch to the selected carousel slide
const carouselItem = event.target;
carouselItem.parentElement.scrollTo({
top: 0,
left: carouselItem.offsetLeft - carouselItem.parentNode.offsetLeft,
behavior: 'instant',
});
}
}

function attachEventListeners(main) {
Expand Down
43 changes: 43 additions & 0 deletions scripts/scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
loadSection,
loadSections,
loadCSS,
buildBlock

Check failure on line 14 in scripts/scripts.js

View workflow job for this annotation

GitHub Actions / build

Missing trailing comma
} from './aem.js';

/**
Expand Down Expand Up @@ -59,13 +60,55 @@ async function loadFonts() {
}
}

/**
* Tabbed layout for Tab section
* @param {HTMLElement} main
*/
async function buildTabSection(main) {
let tabIndex = 0;
let tabContainer;
let tabFound = false;
const sections = main.querySelectorAll('main > div');
sections.forEach((section, i) => {
const sectionMeta = section.querySelector('.section-metadata > div > div:nth-child(2)');
if (sectionMeta?.textContent.includes('tab-section')) {
if (!tabFound) {
tabIndex += 1;
tabFound = true;
const tabs = buildBlock('tabs', []);
tabs.dataset.tabIndex = tabIndex;
tabContainer = document.createElement('div');
tabContainer.classList.add('section');
if (
i > 0 && sections[i - 1]
.querySelector('.section-metadata > div > div:nth-child(2)')
?.textContent.includes('article-content-section')
) {
tabContainer.classList.add('article-content-section');
}
tabContainer.append(tabs);
main.insertBefore(tabContainer, section);
}
if (
tabFound && !sections[i + 1]
?.querySelector('.section-metadata > div > div:nth-child(2)')
?.textContent.includes('tab-section')
) {
tabFound = false;
}
section.classList.add(`tab-index-${tabIndex}`);
}
});
}

/**
* Builds all synthetic blocks in a container element.
* @param {Element} main The container element
*/
function buildAutoBlocks() {
try {
// TODO: add auto block, if needed
buildTabSection(main);

Check failure on line 111 in scripts/scripts.js

View workflow job for this annotation

GitHub Actions / build

'main' is not defined
} catch (error) {
// eslint-disable-next-line no-console
console.error('Auto Blocking failed', error);
Expand Down

0 comments on commit bfb5677

Please sign in to comment.