Skip to content

Commit

Permalink
Limit the number of stylesheets on the page (Shopify#3509)
Browse files Browse the repository at this point in the history
* Limit the number of stylesheets on the page

* Apply suggestions from code review

Co-authored-by: Ludo <ludo.segura@shopify.com>

* Improve the logic and wording a bit

---------

Co-authored-by: Ludo <ludo.segura@shopify.com>
  • Loading branch information
krzksz and ludoboludo committed Jun 7, 2024
1 parent 4b7a19b commit 6495238
Show file tree
Hide file tree
Showing 11 changed files with 127 additions and 75 deletions.
98 changes: 98 additions & 0 deletions assets/base.css
Original file line number Diff line number Diff line change
Expand Up @@ -3468,3 +3468,101 @@ details-disclosure > details {
--border-offset: 0px; /* Prevent the border from growing on buttons when this effect is on. */
}
}

/* Loading spinner */
.loading__spinner {
position: absolute;
z-index: 1;
width: 1.8rem;
}

.loading__spinner {
width: 1.8rem;
display: inline-block;
}

.spinner {
animation: rotator 1.4s linear infinite;
}

@keyframes rotator {
0% {
transform: rotate(0deg);
}
100% {
transform: rotate(270deg);
}
}

.path {
stroke-dasharray: 280;
stroke-dashoffset: 0;
transform-origin: center;
stroke: rgb(var(--color-foreground));
animation: dash 1.4s ease-in-out infinite;
}

@media screen and (forced-colors: active) {
.path {
stroke: CanvasText;
}
}

@keyframes dash {
0% {
stroke-dashoffset: 280;
}
50% {
stroke-dashoffset: 75;
transform: rotate(135deg);
}
100% {
stroke-dashoffset: 280;
transform: rotate(450deg);
}
}

.loading__spinner:not(.hidden) + .cart-item__price-wrapper,
.loading__spinner:not(.hidden) ~ cart-remove-button {
opacity: 50%;
}

.loading__spinner:not(.hidden) ~ cart-remove-button {
pointer-events: none;
cursor: default;
}

/* Progress bar */
.progress-bar-container {
width: 100%;
margin: auto;
}

.progress-bar {
height: 0.13rem;
width: 100%;
}

.progress-bar-value {
width: 100%;
height: 100%;
background-color: rgb(var(--color-foreground));
animation: indeterminateAnimation var(--duration-extra-longer) infinite ease-in-out;
transform-origin: 0;
}

.progress-bar .progress-bar-value {
display: block;
}

@keyframes indeterminateAnimation {
0% {
transform: translateX(-20%) scaleX(0);
}
40% {
transform: translateX(30%) scaleX(0.7);
}
100% {
transform: translateX(100%) scaleX(0);
}
}
61 changes: 0 additions & 61 deletions assets/component-loading-spinner.css

This file was deleted.

5 changes: 4 additions & 1 deletion sections/collage.liquid
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
</h2>
{%- endif -%}
<div class="collage{% if section.settings.mobile_layout == 'collage' %} collage--mobile{% endif %}">
{% assign skip_card_product_styles = false %}
{%- for block in section.blocks -%}
<div
class="collage__item collage__item--{{ block.type }} collage__item--{{ section.settings.desktop_layout }}{% if settings.animations_reveal_on_scroll %} scroll-trigger animate--slide-in{% endif %}"
Expand Down Expand Up @@ -97,8 +98,10 @@
media_aspect_ratio: 'adapt',
show_secondary_image: block.settings.second_image,
extend_height: true,
placeholder_image: placeholder_image
placeholder_image: placeholder_image,
skip_styles: skip_card_product_styles
%}
{% assign skip_card_product_styles = true %}
{%- when 'collection' -%}
{%- assign placeholder_image = 'collection-apparel-' | append: placeholder_image_index -%}
{% render 'card-collection',
Expand Down
3 changes: 3 additions & 0 deletions sections/featured-collection.liquid
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@
role="list"
aria-label="{{ 'general.slider.name' | t }}"
>
{% assign skip_card_product_styles = false %}
{%- for product in section.settings.collection.products limit: section.settings.products_to_show -%}
<li
id="Slide-{{ section.id }}-{{ forloop.index }}"
Expand All @@ -110,10 +111,12 @@
show_secondary_image: section.settings.show_secondary_image,
show_vendor: section.settings.show_vendor,
show_rating: section.settings.show_rating,
skip_styles: skip_card_product_styles,
section_id: section.id,
quick_add: section.settings.quick_add
%}
</li>
{%- assign skip_card_product_styles = true -%}
{%- else -%}
{%- for i in (1..section.settings.columns_desktop) -%}
<li
Expand Down
3 changes: 3 additions & 0 deletions sections/main-collection-product-grid.liquid
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@
{% if section.settings.quick_add == 'bulk' %} collection-quick-add-bulk{% endif %}
"
>
{% assign skip_card_product_styles = false %}
{%- for product in collection.products -%}
{% assign lazy_load = false %}
{%- if forloop.index > 2 -%}
Expand All @@ -170,10 +171,12 @@
show_vendor: section.settings.show_vendor,
show_rating: section.settings.show_rating,
lazy_load: lazy_load,
skip_styles: skip_card_product_styles,
quick_add: section.settings.quick_add,
section_id: section.id
%}
</li>
{%- assign skip_card_product_styles = true -%}
{%- endfor -%}
</ul>

Expand Down
3 changes: 3 additions & 0 deletions sections/main-product.liquid
Original file line number Diff line number Diff line change
Expand Up @@ -552,6 +552,7 @@
aria-label="{{ 'general.slider.name' | t }}"
{% endif %}
>
{% assign skip_card_product_styles = false %}
{%- for i in (1..number_of_slides) -%}
<div
id="Slide-{{ block.id }}-{{ forloop.index }}"
Expand Down Expand Up @@ -579,12 +580,14 @@
media_aspect_ratio: block.settings.image_ratio,
show_secondary_image: false,
lazy_load: false,
skip_styles: skip_card_product_styles,
quick_add: quick_add,
section_id: section.id,
horizontal_class: true,
horizontal_quick_add: true
%}
</li>
{%- assign skip_card_product_styles = true -%}
{%- endfor -%}
</ul>
</div>
Expand Down
5 changes: 4 additions & 1 deletion sections/main-search.liquid
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,7 @@
class="grid product-grid grid--{{ section.settings.columns_mobile }}-col-tablet-down grid--{{ section.settings.columns_desktop }}-col-desktop"
role="list"
>
{%- assign skip_card_product_styles = false -%}
{%- for item in search.results -%}
{% assign lazy_load = false %}
{%- if forloop.index > 2 -%}
Expand All @@ -276,8 +277,10 @@
show_secondary_image: section.settings.show_secondary_image,
show_vendor: section.settings.show_vendor,
show_rating: section.settings.show_rating,
lazy_load: lazy_load
lazy_load: lazy_load,
skip_styles: skip_card_product_styles
%}
{%- assign skip_card_product_styles = true -%}
{%- when 'article' -%}
{% render 'article-card',
article: item,
Expand Down
5 changes: 4 additions & 1 deletion sections/related-products.liquid
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
class="grid product-grid grid--{{ section.settings.columns_desktop }}-col-desktop grid--{{ section.settings.columns_mobile }}-col-tablet-down"
role="list"
>
{% assign skip_card_product_styles = false %}
{% for recommendation in recommendations.products %}
<li class="grid__item">
{% render 'card-product',
Expand All @@ -43,9 +44,11 @@
image_shape: section.settings.image_shape,
show_secondary_image: section.settings.show_secondary_image,
show_vendor: section.settings.show_vendor,
show_rating: section.settings.show_rating
show_rating: section.settings.show_rating,
skip_styles: skip_card_product_styles
%}
</li>
{%- assign skip_card_product_styles = true -%}
{% endfor %}
</ul>
{% endif %}
Expand Down
15 changes: 8 additions & 7 deletions snippets/card-product.liquid
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
- show_rating: {Boolean} Show the product rating. Default: false
- extend_height: {Boolean} Card height extends to available container space. Default: true (optional)
- lazy_load: {Boolean} Image should be lazy loaded. Default: true (optional)
- skip_styles: {Boolean} Don't include component styles. Useful when rendering multiple product cards in a loop. Default: false (optional)
- quick_add: {Boolean} Show the quick add button.
- section_id: {String} The ID of the section that contains this card.
- horizontal_class: {Boolean} Add a card--horizontal class if set to true. Default: false (optional)
Expand All @@ -19,14 +20,14 @@
Usage:
{% render 'card-product', show_vendor: section.settings.show_vendor %}
{% endcomment %}
{%- unless skip_styles -%}
{{ 'component-rating.css' | asset_url | stylesheet_tag }}
{{ 'component-volume-pricing.css' | asset_url | stylesheet_tag }}

{{ 'component-rating.css' | asset_url | stylesheet_tag }}
{{ 'component-volume-pricing.css' | asset_url | stylesheet_tag }}

{{ 'component-price.css' | asset_url | stylesheet_tag }}
{{ 'quick-order-list.css' | asset_url | stylesheet_tag }}
{{ 'quantity-popover.css' | asset_url | stylesheet_tag }}

{{ 'component-price.css' | asset_url | stylesheet_tag }}
{{ 'quick-order-list.css' | asset_url | stylesheet_tag }}
{{ 'quantity-popover.css' | asset_url | stylesheet_tag }}
{%- endunless -%}
{%- if card_product and card_product != empty -%}
{%- liquid
assign ratio = 1
Expand Down
2 changes: 0 additions & 2 deletions snippets/loading-spinner.liquid
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
{% render 'loading-spinner' %}
{% endcomment %}

{{ 'component-loading-spinner.css' | asset_url | stylesheet_tag }}

<div class="{% if class %}{{ class }}{% else %}loading__spinner hidden{% endif %}">
<svg
aria-hidden="true"
Expand Down
2 changes: 0 additions & 2 deletions snippets/progress-bar.liquid
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
{{ 'component-progress-bar.css' | asset_url | stylesheet_tag }}

<div class="progress-bar-container hidden">
<div class="progress-bar">
<div class="progress-bar-value"></div>
Expand Down

0 comments on commit 6495238

Please sign in to comment.