diff --git a/express/blocks/browse-by-category/browse-by-category.css b/express/blocks/browse-by-category/browse-by-category.css index ec8073ac9..01f6f5efb 100644 --- a/express/blocks/browse-by-category/browse-by-category.css +++ b/express/blocks/browse-by-category/browse-by-category.css @@ -1,26 +1,27 @@ -main .browse-by-category-container { - padding-bottom: 24px; -} - -main .browse-by-category-container .browse-by-category { +main .browse-by-category-wrapper.fullwidth { + margin: 0; + max-width: fit-content; + } + + main .browse-by-category { max-width: max-content; -} - -main .browse-by-category-container .browse-by-category-wrapper { - padding: 0; - max-width: none; -} - -main .browse-by-category-container .browse-by-category .carousel-container .carousel-platform { - align-items: flex-start; -} - -main .browse-by-category-container .browse-by-category .carousel-container .button.carousel-arrow { + } + + main .browse-by-category .carousel-container .carousel-platform { + align-items: start; + } + + main .browse-by-category.card .carousel-container .carousel-platform { + gap: 14px; + margin: 6px 0 0 0; + } + + main .browse-by-category .carousel-container .button.carousel-arrow { position: absolute; top: 46px; -} - -main .browse-by-category-container .browse-by-category-heading-section { + } + + main .browse-by-category .browse-by-category-heading-section { display: flex; justify-content: space-between; flex-direction: column; @@ -29,28 +30,28 @@ main .browse-by-category-container .browse-by-category-heading-section { margin-left: auto; margin-right: auto; margin-bottom: 10px; -} - -main .browse-by-category-container .browse-by-category-heading-section .browse-by-category-heading { + } + + main .browse-by-category .browse-by-category-heading-section .browse-by-category-heading { text-align: left; font-size: 28px; line-height: 30px; -} - -main .browse-by-category-container .browse-by-category-heading-section .browse-by-category-link-wrapper { + } + + main .browse-by-category .browse-by-category-heading-section .browse-by-category-link-wrapper { margin: 8px 0 0; -} - -main .browse-by-category-container .browse-by-category-link { + } + + main .browse-by-category .browse-by-category-link { font-size: 16px; line-height: 22px; display: flex; padding: 0; white-space: nowrap; width: max-content; -} - -main .browse-by-category-container .browse-by-category-link::after { + } + + main .browse-by-category .browse-by-category-link::after { display: flex; width: 6px; height: 6px; @@ -61,14 +62,14 @@ main .browse-by-category-container .browse-by-category-link::after { border-style: solid; border-color: var(--color-info-accent); transform-origin: 75% 75%; - transform: rotate( -45deg ); + transform: rotate(-45deg); content: ""; margin-top: 5px; margin-left: 5px; margin-right: 2.25px; -} - -main .browse-by-category-container .browse-by-category-category { + } + + main .browse-by-category:not(.card) .browse-by-category-card { position: relative; display: flex; gap: 8px; @@ -77,19 +78,29 @@ main .browse-by-category-container .browse-by-category-category { min-width: 123px; margin: 0; padding: 10px 8px 0 8px; -} - -main .browse-by-category-container .browse-by-category-category-anchor { + } + + main .browse-by-category.card .browse-by-category-card { + position: relative; + display: flex; + flex-direction: column; + } + + main .browse-by-category .browse-by-category-card-link { position: absolute; height: 100%; width: 100%; -} - -main .browse-by-category-container .browse-by-category-category-anchor:hover ~ .browse-by-category-category-image-wrapper img { - transform: scale(1.1) matrix(1, -0.07, 0.07, 1, 0, 0); -} - -main .browse-by-category-container .browse-by-category-category-image-wrapper { + } + + main .browse-by-category:not(.card) .browse-by-category-card-link:hover ~ .browse-by-category-image-wrapper img { + transform: scale(1.1) matrix(1, -0.07, 0.05, 1, 0, 0); + } + + main .browse-by-category.card .browse-by-category-card-link:hover ~ .browse-by-category-image-wrapper img { + transform: scale(1.1) matrix(1, -0.01, 0.01, 1, 0, 0); + } + + main .browse-by-category .browse-by-category-image-wrapper { background-color: var(--color-gray-200); min-height: 90px; width: 148px; @@ -98,21 +109,21 @@ main .browse-by-category-container .browse-by-category-category-image-wrapper { justify-content: center; align-items: center; pointer-events: none; -} - -main .browse-by-category-container .browse-by-category-category-image-wrapper img { + } + + main .browse-by-category:not(.card) .browse-by-category-image-wrapper img { display: block; object-fit: cover; width: 80px; height: 80px; transform: matrix(1, -0.07, 0.07, 1, 0, 0); - box-shadow: 0 0 6px #0000001F; + box-shadow: 0 0 6px #0000001f; border-radius: 8px; opacity: 1; transition: transform 0.2s ease-in-out; -} - -main .browse-by-category-container .browse-by-category-category-image-wrapper .browse-by-category-category-image-shadow { + } + + main .browse-by-category .browse-by-category-image-wrapper .browse-by-category-image-shadow { position: absolute; width: 76px; height: 76px; @@ -120,31 +131,75 @@ main .browse-by-category-container .browse-by-category-category-image-wrapper .b background: var(--color-gray-300) 0 0 no-repeat padding-box; border-radius: 10px; opacity: 1; -} - -main .browse-by-category-container .browse-by-category-category-title { + } + + main .browse-by-category.card .browse-by-category-image-shadow-wrapper { + display: block; + object-fit: cover; + transform: matrix(1, -0.07, 0.07, 1, 0, 0); + box-shadow: 0 0 6px #0000001f; + border-radius: 8px; + opacity: 1; + transition: transform 0.2s ease-in-out; + } + + main .browse-by-category.card .browse-by-category-image-wrapper { + background-color: #f8f8f8; + min-height: 90px; + height: 116px; + width: 182px; + border-radius: 10px; + display: flex; + justify-content: center; + align-items: center; + pointer-events: none; + } + + main .browse-by-category.card .browse-by-category-image-wrapper img { + display: block; + object-fit: contain; + max-width: 110px; + max-height: 97px; + height: 100%; + transform: matrix(1, -0.01, 0.01, 1, 0, 0); + box-shadow: 0 0 6px #0000001f; + border-radius: 8px; + opacity: 1; + transition: transform 0.2s ease-in-out; + } + + main .browse-by-category.card .browse-by-category-image-wrapper .browse-by-category-image-shadow { + position: absolute; + width: 100%; + height: 100%; + transform: matrix(0.90, -0.18, 0.20, 0.90, -14, 0); + background: #d6d6d6e5; + } + + main .browse-by-category:not(.card) .browse-by-category-card-title { margin: 0; font-size: 18px; line-height: 24px; font-weight: 700; max-width: 148px; -} - -@media (min-width: 900px) { - main .browse-by-category-container .browse-by-category-heading-section { - flex-direction: row; - padding: 0; - } - - main .browse-by-category-container .browse-by-category-wrapper { - padding: 0 28px; - max-width: none; + } + + main .browse-by-category.card .browse-by-category-card-title { + margin: 6px 0; + font-size: 16px; + line-height: 24px; + font-weight: 700; + align-self: start; + } + + @media (min-width: 900px) { + main .browse-by-category-wrapper .browse-by-category { + padding: 0 28px; + max-width: none; } -} - -@media (min-width: 1200px) { - main .browse-by-category-container .browse-by-category-wrapper { - padding: 0 28px; - max-width: none; + + main .browse-by-category .browse-by-category-heading-section { + flex-direction: row; + padding: 0; } -} + } diff --git a/express/blocks/browse-by-category/browse-by-category.js b/express/blocks/browse-by-category/browse-by-category.js index 7ceec92c5..328b268ec 100644 --- a/express/blocks/browse-by-category/browse-by-category.js +++ b/express/blocks/browse-by-category/browse-by-category.js @@ -11,75 +11,94 @@ */ /* eslint-disable import/named, import/extensions */ -import { - createTag, -} from '../../scripts/scripts.js'; +import { createTag } from '../../scripts/scripts.js'; -import { - buildCarousel, -} from '../shared/carousel.js'; +import { buildCarousel } from '../shared/carousel.js'; -export function decorateHeading($block, payload) { - const $headingSection = createTag('div', { class: 'browse-by-category-heading-section' }); - const $heading = createTag('h3', { class: 'browse-by-category-heading' }); - const $viewAllButtonWrapper = createTag('p', { class: 'browse-by-category-link-wrapper' }); +export function decorateHeading(block, payload) { + const headingSection = createTag('div', { class: 'browse-by-category-heading-section' }); + const heading = createTag('h3', { class: 'browse-by-category-heading' }); + const viewAllButtonWrapper = createTag('p', { class: 'browse-by-category-link-wrapper' }); if (payload.viewAllLink.href !== '') { - const $viewAllButton = createTag('a', { class: 'browse-by-category-link', href: payload.viewAllLink.href }); - $viewAllButton.textContent = payload.viewAllLink.text; - $viewAllButtonWrapper.append($viewAllButton); + const viewAllButton = createTag('a', { + class: 'browse-by-category-link', + href: payload.viewAllLink.href, + }); + viewAllButton.textContent = payload.viewAllLink.text; + viewAllButtonWrapper.append(viewAllButton); } - $heading.textContent = payload.heading; - $headingSection.append($heading, $viewAllButtonWrapper); - $block.append($headingSection); + heading.textContent = payload.heading; + headingSection.append(heading, viewAllButtonWrapper); + block.append(headingSection); } -export function decorateCategories($block, payload) { - const $categoriesWrapper = createTag('div', { class: 'browse-by-category-categories-wrapper' }); - - payload.categories.forEach((category) => { - const $category = createTag('div', { class: 'browse-by-category-category' }); - const $categoryImageWrapper = createTag('div', { class: 'browse-by-category-category-image-wrapper' }); - const $categoryImageShadow = createTag('div', { class: 'browse-by-category-category-image-shadow' }); - const $categoryImage = category.$image; - const $categoryTitle = createTag('h4', { class: 'browse-by-category-category-title' }); - const $categoryAnchor = createTag('a', { class: 'browse-by-category-category-anchor' }); - - $categoryTitle.textContent = category.text; - $categoryAnchor.href = category.link; - $categoryImageWrapper.append($categoryImageShadow, $categoryImage); - $category.append($categoryAnchor, $categoryImageWrapper, $categoryTitle); - $categoriesWrapper.append($category); +export function decorateCategories(block, payload) { + const categoriesWrapper = createTag('div', { class: 'browse-by-category-categories-wrapper' }); + + payload.categories.forEach((categoryCard) => { + const category = createTag('div', { class: 'browse-by-category-card' }); + const categoryImageWrapper = createTag('div', { class: 'browse-by-category-image-wrapper' }); + const categoryImageShadowWrapper = createTag('div', { + class: 'browse-by-category-image-shadow-wrapper', + }); + const categoryImageShadow = createTag('div', { class: 'browse-by-category-image-shadow' }); + const categoryImage = categoryCard.image; + const categoryTitle = createTag('h4', { class: 'browse-by-category-card-title' }); + const categoryAnchor = createTag('a', { class: 'browse-by-category-card-link' }); + + categoryTitle.textContent = categoryCard.text; + categoryAnchor.href = categoryCard.link; + categoryImageShadowWrapper.append(categoryImageShadow, categoryImage); + categoryImageWrapper.append(categoryImageShadowWrapper); + category.append(categoryAnchor, categoryImageWrapper, categoryTitle); + categoriesWrapper.append(category); }); - $block.append($categoriesWrapper); + block.append(categoriesWrapper); } -export default async function decorate($block) { - const $rows = Array.from($block.children); - const $headingDiv = $rows.shift(); +export default async function decorate(block) { + const rows = Array.from(block.children); + const headingDiv = rows.shift(); const payload = { - heading: $headingDiv.querySelector('h4') ? $headingDiv.querySelector('h4').textContent.trim() : '', + heading: headingDiv.querySelector('h4') + ? headingDiv.querySelector('h4').textContent.trim() + : '', viewAllLink: { - text: $headingDiv.querySelector('a.button') ? $headingDiv.querySelector('a.button').textContent.trim() : '', - href: $headingDiv.querySelector('a.button') ? $headingDiv.querySelector('a.button').href : '', + text: headingDiv.querySelector('a.button') + ? headingDiv.querySelector('a.button').textContent.trim() + : '', + href: headingDiv.querySelector('a.button') ? headingDiv.querySelector('a.button').href : '', }, categories: [], }; - $rows.forEach(($row) => { + rows.forEach((row) => { payload.categories.push({ - $image: $row.querySelector('picture'), - text: $row.querySelector('a.button') ? $row.querySelector('a.button').textContent.trim() : 'missing category text', - link: $row.querySelector('a.button') ? $row.querySelector('a.button').href : 'missing category link', + image: row.querySelector('picture'), + text: row.querySelector('a.button') + ? row.querySelector('a.button').textContent.trim() + : 'missing category text', + link: row.querySelector('a.button') + ? row.querySelector('a.button').href + : 'missing category link', }); }); - $block.innerHTML = ''; + block.innerHTML = ''; - decorateHeading($block, payload); - decorateCategories($block, payload); - buildCarousel('.browse-by-category-category', $block, false); + decorateHeading(block, payload); + decorateCategories(block, payload); + buildCarousel('.browse-by-category-card', block, false); + + if (block.classList.contains('fullwidth')) { + const blockWrapper = block.parentNode; + + if (blockWrapper && blockWrapper.classList.contains('browse-by-category-wrapper')) { + blockWrapper.classList.add('fullwidth'); + } + } }