Skip to content

Commit

Permalink
JS updates all card versions
Browse files Browse the repository at this point in the history
  • Loading branch information
anu13297 committed Jan 15, 2025
1 parent 77f82ab commit d69229b
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 101 deletions.
4 changes: 4 additions & 0 deletions eds/blocks/cards/cards.css
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@
h3, p:last-child {
padding-inline-end: var(--space-5);
}

calcite-link {
display: block;
}
}

.cards-card-image {
Expand Down
32 changes: 21 additions & 11 deletions eds/blocks/cards/cards.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,18 +36,19 @@ function processStandardCard(element) {
el.classList.add('overlay-text');
}
});
const pictureEl = element.querySelector('picture')
.closest('p');
const pictureEl = element.querySelector('picture').closest('p');
const overlayTextEl = element.querySelector('.overlay-text');
if (overlayTextEl) pictureEl.append(overlayTextEl);
pictureEl.nextElementSibling.classList.add('card-body-title');
const cardBodyTitle = element.querySelector('.card-body-title');
if(pictureEl) {

Check failure on line 42 in eds/blocks/cards/cards.js

View workflow job for this annotation

GitHub Actions / build

Expected space(s) after "if"
pictureEl.nextElementSibling.classList.add('card-body-title');
const cardBodyTitle = element.querySelector('.card-body-title');
if (cardBodyContent.lastChild.classList === '') cardBodyContent.lastChild.classList.add('card-body-description');

if (cardBodyContent.lastChild.classList === '') cardBodyContent.lastChild.classList.add('card-body-description');

if (cardBodyTitle.nextElementSibling && !cardBodyTitle.nextElementSibling.classList.contains('card-body-description')) {
cardBodyTitle.nextElementSibling.classList.add('card-body-subtitle');
if (cardBodyTitle.nextElementSibling && !cardBodyTitle.nextElementSibling.classList.contains('card-body-description')) {
cardBodyTitle.nextElementSibling.classList.add('card-body-subtitle');
}
}

Check failure on line 50 in eds/blocks/cards/cards.js

View workflow job for this annotation

GitHub Actions / build

Block must not be padded by blank lines

Check failure on line 51 in eds/blocks/cards/cards.js

View workflow job for this annotation

GitHub Actions / build

Trailing spaces not allowed
}

export default function decorate(block) {
Expand Down Expand Up @@ -76,9 +77,18 @@ export default function decorate(block) {
p.replaceWith(button);
}
});
if (!block.classList.contains('simple')) {
const isLastChildLink = element.lastElementChild?.tagName.toLowerCase() === 'calcite-link';
const titleSelector = isLastChildLink ? 'p:nth-last-child(3)' : 'p:nth-last-child(2)';

const linksCount = element.querySelectorAll('calcite-link').length;
let titleSelector;
if (block.classList.contains('block-group')) {
const pTags = element.querySelectorAll('p');
console.log('number of p '+pTags.length);

Check warning on line 85 in eds/blocks/cards/cards.js

View workflow job for this annotation

GitHub Actions / build

Unexpected console statement

Check failure on line 85 in eds/blocks/cards/cards.js

View workflow job for this annotation

GitHub Actions / build

Unexpected string concatenation

Check failure on line 85 in eds/blocks/cards/cards.js

View workflow job for this annotation

GitHub Actions / build

Operator '+' must be spaced
titleSelector = (pTags.length >= 3) ? 'p:nth-last-child(2)' : 'p:nth-last-child(1)';
} else if (!block.classList.contains('simple') && !block.classList.contains('standard')) {
titleSelector = (linksCount === 1) ? 'p:nth-last-child(3)' :

Check failure on line 88 in eds/blocks/cards/cards.js

View workflow job for this annotation

GitHub Actions / build

Do not nest ternary expressions

Check failure on line 88 in eds/blocks/cards/cards.js

View workflow job for this annotation

GitHub Actions / build

':' should be placed at the beginning of the line
(linksCount === 2) ? 'p:nth-last-child(4)' : 'p:nth-last-child(3)';

Check failure on line 89 in eds/blocks/cards/cards.js

View workflow job for this annotation

GitHub Actions / build

Expected indentation of 10 spaces but found 12
}
if (titleSelector) {
element.querySelectorAll(titleSelector).forEach((p) => {
const h3 = document.createElement('h3');
h3.innerHTML = p.innerHTML;
Expand Down
71 changes: 0 additions & 71 deletions eds/blocks/tabs/tabs.css
Original file line number Diff line number Diff line change
Expand Up @@ -23,26 +23,6 @@
margin-block-start: var(--space-5);
}

.cards ul {
align-items: stretch;
}

.cards li {
block-size: 100%;
flex: 0 0 100%;
}

.cards a {
block-size: 100%;
color: var(--calcite-ui-text-1);
display: block;
text-decoration: none;
}

.cards-card-body :is(picture, img) {
aspect-ratio: 342 / 192;
}

p:last-child {
align-items: center;
display: flex;
Expand Down Expand Up @@ -81,38 +61,6 @@
}
}

.cards-card-body {
border: solid 1px var(--calcite-ui-border-1);
margin: var(--space-2);

& > p:first-child {
margin-block-end: 0;
}

& > p:nth-child(2) {
color: var(--calcite-ui-text-1);
font-size: var(--font-2);
margin-block-end: var(--space-2);
margin-inline: var(--space-5);
}

& > p:last-child {
color: var(--calcite-ui-text-1);
display: block;
font-size: var(--font-minus-1);
margin-block-end: var(--space-6);
margin-inline: var(--space-5);
padding: 0;
}

& > p:nth-child(3):not(:last-child) {
color: var(--calcite-ui-text-2);
font-size: var(--font-minus-1);
margin-block-end: var(--space-2);
margin-inline: var(--space-5);
}
}

.tab-component {
display: flex;
flex-direction: column;
Expand Down Expand Up @@ -231,17 +179,6 @@
}
}
}

/* .tab-content .text-wrapper, .tab-content .buttons-wrapper {
animation-delay: 50ms;
animation-duration: 550ms;
animation-fill-mode: both;
animation-timing-function: ease-in-out;
}
.tab-content[aria-hidden='false'] .text-wrapper, .tab-content[aria-hidden='false'] .buttons-wrapper {
animation-name: in-up;
} */
}

@media (width >= 900px) {
Expand All @@ -257,10 +194,6 @@

@media (width >= 1024px) {
.tabs {
.cards li {
flex: 0 0 33.33%;
}

.tab-component {
position: relative;
}
Expand Down Expand Up @@ -357,10 +290,6 @@
}

@media (width >= 1440px) {
.tabs .cards li {
flex: 0 0 25%;
}

.tabs .columns {
margin: auto;
}
Expand Down
19 changes: 0 additions & 19 deletions eds/blocks/tabs/tabs.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,25 +47,6 @@ export default async function decorate(block) {
}, content));
}

const isCardsVariant = contents?.every((content) => content.querySelectorAll('.cards').length > 0);
if (isCardsVariant) {
contents.forEach((content) => {
const cards = content.querySelectorAll('.cards-card-body');
cards.forEach((card) => {
const anchor = card.querySelector('a');
anchor.classList.remove('button');
anchor.textContent = '';

const cardParent = card.parentElement;
cardParent.removeChild(card);

anchor.parentElement.parentElement.removeChild(anchor.parentElement);
anchor.appendChild(card);
cardParent.appendChild(anchor);
});
});
}

if (!tabsContainFragments) {
tabContents.forEach((content) => {
const text = [content[1], content[2], content[3]];
Expand Down

0 comments on commit d69229b

Please sign in to comment.