Skip to content

Commit

Permalink
Add custom Thumbnail slot content example
Browse files Browse the repository at this point in the history
  • Loading branch information
jcalcaben committed Sep 23, 2024
1 parent e66e6ee commit 4a61807
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions blocks/commerce-cart-summary/commerce-cart-summary.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,51 @@ export default async function decorate(block) {
attributesToHide: hideAttributes.split(',').map((attr) => attr.trim().toLowerCase()),
enableUpdateItemQuantity: enableUpdateItemQuantity === 'true',
enableRemoveItem: enableRemoveItem === 'true',
slots: {
Thumbnail: (ctx) => {
const { item } = ctx;

// Create a link to save the item for later
const saveForLaterLink = document.createElement('a');

Check failure on line 30 in blocks/commerce-cart-summary/commerce-cart-summary.js

View workflow job for this annotation

GitHub Actions / build

Multiple spaces found before '='
saveForLaterLink.href = '#';
saveForLaterLink.addEventListener('click', (e) => {
e.preventDefault();
console.log(`Saving ${item.name}(${item.sku}) for later`);

Check failure on line 34 in blocks/commerce-cart-summary/commerce-cart-summary.js

View workflow job for this annotation

GitHub Actions / build

Unexpected console statement
// TODO: Implement save for later functionality
});
saveForLaterLink.innerText = 'Save for later';

// Create a separator
const separator = document.createElement('span');
separator.innerText = ' | ';

// Create a link to remove the item from the cart
const removeLink = document.createElement('a');
removeLink.href = '#';
removeLink.addEventListener('click', (e) => {
e.preventDefault();
console.log(`Removing ${item.name}(${item.sku}) from cart`);

Check failure on line 48 in blocks/commerce-cart-summary/commerce-cart-summary.js

View workflow job for this annotation

GitHub Actions / build

Unexpected console statement
// TODO: Implement remove item functionality
});
removeLink.innerText = 'Remove';

// Create a container to hold the links
const container = document.createElement('div');
container.innerHTML = '<div class="cart-summary__thumbnail"/>';

// Style the container
container.style.font = 'var(--type-details-caption-2-font)'

Check failure on line 58 in blocks/commerce-cart-summary/commerce-cart-summary.js

View workflow job for this annotation

GitHub Actions / build

Missing semicolon
container.style.display = 'flex';
container.style.justifyContent = 'space-between';

// Append the links to the container
container.appendChild(saveForLaterLink);
container.appendChild(separator);
container.appendChild(removeLink);

// Append the container as a child to the existing thumbnail content
ctx.appendChild(container)

Check failure on line 68 in blocks/commerce-cart-summary/commerce-cart-summary.js

View workflow job for this annotation

GitHub Actions / build

Missing semicolon
}

Check failure on line 69 in blocks/commerce-cart-summary/commerce-cart-summary.js

View workflow job for this annotation

GitHub Actions / build

Missing trailing comma
}

Check failure on line 70 in blocks/commerce-cart-summary/commerce-cart-summary.js

View workflow job for this annotation

GitHub Actions / build

Missing trailing comma
})(block);
}

0 comments on commit 4a61807

Please sign in to comment.