forked from adobe/aem-boilerplate
-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
265 changed files
with
4,639 additions
and
393 deletions.
There are no files selected for viewing
53 changes: 53 additions & 0 deletions
53
blocks/commerce-account-sidebar/commerce-account-sidebar.css
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
.commerce-account-sidebar-wrapper .commerce-account-sidebar .commerce-account-sidebar-item { | ||
display: flex; | ||
align-items: center; | ||
padding: var(--spacing-medium); | ||
margin-bottom: var(--spacing-small); | ||
border: var(--shape-border-width-1) solid var(--color-neutral-400); | ||
border-radius: var(--shape-border-radius-1); | ||
text-decoration: none; | ||
} | ||
|
||
.commerce-account-sidebar-wrapper .commerce-account-sidebar .commerce-account-sidebar-item-active { | ||
border-color: var(--color-neutral-800); | ||
background-color: var(--color-neutral-200); | ||
} | ||
|
||
.commerce-account-sidebar-item-icon { | ||
flex: 0 0 auto; | ||
margin-right: var(--spacing-small); | ||
} | ||
|
||
.commerce-account-sidebar-item-icon > div { | ||
display: flex; | ||
align-items: center; | ||
justify-content: center; | ||
} | ||
|
||
.commerce-account-sidebar-item-content { | ||
flex: 1 1 auto; | ||
} | ||
|
||
.commerce-account-sidebar-item-title { | ||
font: var(--type-button-1-font); | ||
margin: 0 0 var(--spacing-xxsmall); | ||
border: none; | ||
text-decoration: none; | ||
} | ||
|
||
.commerce-account-sidebar-item-subtitle { | ||
font: var(--type-button-2-font); | ||
margin: 0; | ||
text-decoration: none; | ||
} | ||
|
||
.commerce-account-sidebar-item-arrow { | ||
flex: 0 0 auto; | ||
margin-left: var(--spacing-small); | ||
} | ||
|
||
.commerce-account-sidebar-item-arrow > div { | ||
display: flex; | ||
align-items: center; | ||
justify-content: center; | ||
} |
79 changes: 79 additions & 0 deletions
79
blocks/commerce-account-sidebar/commerce-account-sidebar.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
import { Icon, provider as uiProvider } from '@dropins/tools/components.js'; | ||
import { render as accountRenderer } from '@dropins/storefront-account/render.js'; | ||
import { loadFragment } from '../fragment/fragment.js'; | ||
|
||
export default async function decorate(block) { | ||
const fragment = await loadFragment('/customer/sidebar-fragment'); | ||
const sidebarItemsConfig = fragment.querySelectorAll('.default-content-wrapper > ol > li'); | ||
const sidebarItems = Array.from(sidebarItemsConfig).map((item) => { | ||
const itemParams = Array.from(item.querySelectorAll('ol > li')); | ||
const itemConfig = { | ||
itemTitle: item.childNodes[0]?.textContent.trim() || 'Default Title', | ||
itemSubtitle: itemParams[0]?.innerText || '', | ||
itemLink: itemParams[1]?.innerText || '#', | ||
itemIcon: itemParams[2]?.innerText || 'Placeholder', | ||
}; | ||
|
||
const menuItemEl = document.createElement('a'); | ||
menuItemEl.classList.add('commerce-account-sidebar-item'); | ||
menuItemEl.href = itemConfig.itemLink; | ||
|
||
const isItemActive = ( | ||
itemConfig.itemLink === '/customer/orders' | ||
? window.location.href.includes('/customer/order') | ||
: window.location.href.includes(itemConfig.itemLink) | ||
); | ||
if (isItemActive) { | ||
menuItemEl.classList.add('commerce-account-sidebar-item-active'); | ||
} | ||
|
||
const iconEl = createMenuItemIcon(itemConfig.itemIcon); | ||
const contentEl = createMenuItemContent(itemConfig.itemTitle, itemConfig.itemSubtitle); | ||
const arrowEl = createMenuItemArrow(); | ||
|
||
menuItemEl.appendChild(iconEl); | ||
menuItemEl.appendChild(contentEl); | ||
menuItemEl.appendChild(arrowEl); | ||
|
||
return menuItemEl; | ||
}); | ||
|
||
block.innerHTML = ''; | ||
sidebarItems.forEach((el) => { | ||
block.appendChild(el); | ||
}); | ||
} | ||
|
||
function createMenuItemIcon(iconSource) { | ||
const iconEl = document.createElement('div'); | ||
iconEl.classList.add('commerce-account-sidebar-item-icon'); | ||
accountRenderer.render(Icon, { source: iconSource, size: 32 })(iconEl); | ||
return iconEl; | ||
} | ||
|
||
function createMenuItemContent(title, subtitle) { | ||
const contentEl = document.createElement('div'); | ||
contentEl.classList.add('commerce-account-sidebar-item-content'); | ||
|
||
const titleEl = document.createElement('p'); | ||
titleEl.classList.add('commerce-account-sidebar-item-title'); | ||
titleEl.innerText = title; | ||
|
||
const subtitleEl = document.createElement('p'); | ||
subtitleEl.classList.add('commerce-account-sidebar-item-subtitle'); | ||
subtitleEl.innerText = subtitle; | ||
|
||
contentEl.appendChild(titleEl); | ||
contentEl.appendChild(subtitleEl); | ||
return contentEl; | ||
} | ||
|
||
function createMenuItemArrow() { | ||
const arrowEl = document.createElement('div'); | ||
arrowEl.classList.add('commerce-account-sidebar-item-arrow'); | ||
uiProvider.render(Icon, { | ||
source: 'ChevronRight', | ||
size: 32, | ||
})(arrowEl); | ||
return arrowEl; | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.