Skip to content

Commit

Permalink
Merge pull request #19 from Netcentric/nested-components
Browse files Browse the repository at this point in the history
Add handling nested components
  • Loading branch information
lakshmishriaswathnarayana authored Aug 20, 2024
2 parents c26b4d5 + 8ad3265 commit 167b20c
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 2 deletions.
4 changes: 2 additions & 2 deletions blocks/columns/columns.css
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
order: 1;
}

.columns > div > div:not(.columns-img-col, .columns.locations > div > div) {
.columns:not(.locations) > div > div:not(.columns-img-col) {
max-width: 750px;
margin-left: auto;
margin-right: auto;
Expand Down Expand Up @@ -137,7 +137,7 @@
}

/* ratio variants */
.columns.ratio > div > div {
.columns.ratio.block > div > div {
margin: unset;
}

Expand Down
1 change: 1 addition & 0 deletions blocks/form/form-fields.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ const createSubmit = (fd) => {

const fieldWrapper = createFieldWrapper(fd);
fieldWrapper.append(button);
button.disabled = true;
return { field: button, fieldWrapper };
};

Expand Down
10 changes: 10 additions & 0 deletions blocks/form/form.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,18 @@ export default async function decorate(block) {
if (!formLink) return;

const form = await createForm(formLink.href);
const submitButton = form.querySelector('button[type="submit"]');
block.replaceChildren(form);

/* enabling the submit button only when all of the checkboxes are checked */
const checkboxList = [...form.querySelectorAll('input[type="checkbox"]')];
checkboxList.forEach((checkbox) => {
checkbox.addEventListener('input', () => {
const disabled = checkboxList.length !== checkboxList.filter((ch) => ch.checked).length;
submitButton.disabled = disabled;
});
});

form.addEventListener('submit', (e) => {
e.preventDefault();
const valid = form.checkValidity();
Expand Down
1 change: 1 addition & 0 deletions blocks/table/table.css
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
.table {
overflow: auto;
width: 100%;
text-align: left;
}

.table .table-element {
Expand Down
19 changes: 19 additions & 0 deletions scripts/scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,24 @@ function customDecorateBlocks(main) {
});
}

function swappingPlacesBlock(main) {
const idLinks = [...main.querySelectorAll('a[href*="#id-"]')];
const elWithId = [...main.querySelectorAll('.block, .section')]
.filter((el) => [...el.classList].find((className) => className.startsWith('id-')));

idLinks.forEach((link) => {
const id = link.href.split('#')[1];
const selectedEl = elWithId.find((el) => el.classList.contains(id));
let targetEl = link;

if (link.closest('.button-container')) {
targetEl = link.closest('.button-container');
}

targetEl.replaceWith(selectedEl);
});
}

/**
* Decorates the main element.
* @param {Element} main The main element
Expand All @@ -90,6 +108,7 @@ export function decorateMain(main) {
customDecorateSections(main);
decorateBlocks(main);
customDecorateBlocks(main);
swappingPlacesBlock(main);
}

/**
Expand Down

0 comments on commit 167b20c

Please sign in to comment.