Skip to content

Commit

Permalink
Add customer avatar (#3376)
Browse files Browse the repository at this point in the history
  • Loading branch information
mtbottens committed Apr 2, 2024
1 parent 3c99075 commit 8b1099b
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 2 deletions.
4 changes: 4 additions & 0 deletions assets/base.css
Expand Up @@ -2533,6 +2533,10 @@ product-info .loading__spinner:not(.hidden) ~ *,
background: rgba(var(--color-foreground), 0.5);
}

.header__icon--account shop-user-avatar {
--shop-avatar-size: 2.8rem;
}

/* Search */
menu-drawer + .header__search {
display: none;
Expand Down
6 changes: 6 additions & 0 deletions assets/component-menu-drawer.css
Expand Up @@ -209,6 +209,12 @@ details[open].menu-opening > .menu-drawer__submenu {
margin-right: 1rem;
}

.menu-drawer__account shop-user-avatar {
--shop-avatar-size: 2.4rem;
margin-right: 0.55rem;
margin-left: -0.45rem;
}

.menu-drawer__account:hover .icon-account {
transform: scale(1.07);
}
Expand Down
20 changes: 20 additions & 0 deletions assets/global.js
Expand Up @@ -1339,3 +1339,23 @@ class ProductRecommendations extends HTMLElement {
}

customElements.define('product-recommendations', ProductRecommendations);

class AccountIcon extends HTMLElement {
constructor() {
super();

this.icon = this.querySelector('.icon');
}

connectedCallback() {
document.addEventListener('storefront:signincompleted', this.handleStorefrontSignInCompleted.bind(this));
}

handleStorefrontSignInCompleted(event) {
if (event?.detail?.avatar) {
this.icon?.replaceWith(event.detail.avatar.cloneNode());
}
}
}

customElements.define('account-icon', AccountIcon);
8 changes: 7 additions & 1 deletion sections/header.liquid
Expand Up @@ -256,7 +256,13 @@

{%- if shop.customer_accounts_enabled -%}
<a href="{%- if customer -%}{{ routes.account_url }}{%- else -%}{{ routes.account_login_url }}{%- endif -%}" class="header__icon header__icon--account link focus-inset{% if section.settings.menu != blank %} small-hide{% endif %}">
{% render 'icon-account' %}
<account-icon>
{%- if customer and customer.has_avatar? -%}
{{ customer | avatar }}

Check failure on line 261 in sections/header.liquid

View workflow job for this annotation

GitHub Actions / Theme Check Report

sections/header.liquid#L261

[UnknownFilter] Undefined filter `avatar`
{%- else -%}
{% render 'icon-account' %}
{%- endif -%}
</account-icon>
<span class="visually-hidden">
{%- liquid
if customer
Expand Down
8 changes: 7 additions & 1 deletion snippets/header-drawer.liquid
Expand Up @@ -129,7 +129,13 @@
href="{%- if customer -%}{{ routes.account_url }}{%- else -%}{{ routes.account_login_url }}{%- endif -%}"
class="menu-drawer__account link focus-inset h5 medium-hide large-up-hide"
>
{% render 'icon-account' %}
<account-icon>
{%- if customer and customer.has_avatar? -%}
{{ customer | avatar }}

Check failure on line 134 in snippets/header-drawer.liquid

View workflow job for this annotation

GitHub Actions / Theme Check Report

snippets/header-drawer.liquid#L134

[UnknownFilter] Undefined filter `avatar`
{%- else -%}
{% render 'icon-account' %}
{%- endif -%}
</account-icon>
{%- liquid
if customer
echo 'customer.account_fallback' | t
Expand Down

0 comments on commit 8b1099b

Please sign in to comment.