Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add customer avatar #3376

Merged
merged 1 commit into from
Apr 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions assets/base.css
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Loading