Skip to content

Commit

Permalink
KAW-7941-NBA-component
Browse files Browse the repository at this point in the history
  • Loading branch information
Lakshmishri committed Sep 12, 2024
1 parent c319c73 commit 803bf74
Show file tree
Hide file tree
Showing 5 changed files with 98 additions and 12 deletions.
54 changes: 54 additions & 0 deletions blocks/nba/nba.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
.nba {
--row-gap: 40px;

justify-content: center;
align-items: center;
padding: 60px 20px;
}

.nba-text-wrapper {
--row-gap: 16px;

justify-content: center;
align-items: center;
text-align: center;
}

.nba-button-wrapper {
--row-gap: 24px;

width: 100%;
}

.nba .nba-button-wrapper:not(:first-child) {
padding-top: 0;
}

.nba-button-wrapper .icon-arrow-right {
height: 24px;
width: 24px;
}

.nba ,
.nba-button-wrapper,
.nba-text-wrapper {
display: flex;
flex-flow: column;
gap: var(--row-gap)
}

.heading {
margin-bottom: 0;
}

@media (width >= 768px) {
.nba {
padding-top: 80px;
padding-bottom: 80px;
}

.nba .nba-button-wrapper {
width: auto;
flex-flow: row;
}
}
33 changes: 33 additions & 0 deletions blocks/nba/nba.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { unwrapDivs } from '../../scripts/helpers.js';

export default async function decorate(block) {
const textWrapper = document.createElement('div');
textWrapper.classList.add('nba-text-wrapper');

const headings = block.querySelectorAll('h1, h2, h3, h4, h5, h6');
[...headings].forEach((heading) => {
heading.classList.add('heading');
textWrapper.append(heading);
});

block.querySelectorAll('p').forEach((textEle) => {
if (!textEle.children.length) {
textWrapper.append(textEle);
}
});
block.prepend(textWrapper);

const buttonWrapper = document.createElement('div');
buttonWrapper.classList.add('nba-button-wrapper');
block.querySelectorAll('a').forEach((button, index) => {
const buttonClass = index < 1 ? 'primary' : 'secondary';
button.classList.add('button', buttonClass);
if (button.parentElement.classList.contains('button-container')) {
button.parentElement.remove();
}
buttonWrapper.append(button);
});
block.append(buttonWrapper);

unwrapDivs(block);
}
5 changes: 5 additions & 0 deletions icons/arrow-right.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
13 changes: 3 additions & 10 deletions scripts/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,25 +93,18 @@ export const adjustPretitle = (element) => {
});
};

export const unwrapDivs = (element, options = {}) => {
export const unwrapDivs = (element) => {
const stack = [element];
const { ignoreDataAlign = false } = options;

while (stack.length > 0) {
const currentElement = stack.pop();

let i = 0;
while (i < currentElement.children.length) {
const node = currentElement.children[i];
const attributesLength = [...node.attributes].filter((el) => {
if (ignoreDataAlign) {
return !(el.name.startsWith('data-align') || el.name.startsWith('data-valign'));
}

return el;
}).length;
const attributesLength = [...node.attributes].filter((el) => el).length;

if (node.tagName === 'DIV' && attributesLength === 0) {
if (node && attributesLength === 0) {
while (node.firstChild) {
currentElement.insertBefore(node.firstChild, node);
}
Expand Down
5 changes: 3 additions & 2 deletions styles/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@

.dark {
background-color: var(--black);
color: var(--white);
}

:root .dark {
Expand Down Expand Up @@ -436,8 +437,8 @@ button.secondary.small {

.dark a.button.primary:hover,
.dark button.primary:hover {
color: #ed1c24;
border-color: #ed1c24;
color: #ae2d27;
border-color: #ae2d27;
}

.dark a.button.primary:focus,
Expand Down

0 comments on commit 803bf74

Please sign in to comment.