From b641341e03085a88d4082826e58af3605811c590 Mon Sep 17 00:00:00 2001 From: jamyoucn00 <114928221+jamyoucn00@users.noreply.github.com> Date: Wed, 21 Dec 2022 11:27:00 +0100 Subject: [PATCH 01/11] update the script --- assets/cart.js | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/assets/cart.js b/assets/cart.js index 4b0ed5ad..6ef649c2 100644 --- a/assets/cart.js +++ b/assets/cart.js @@ -92,23 +92,44 @@ async function removeItem(cartItemId, productVariantId) { } function moveQuantityWrapper() { + const cartItemsTable = document.querySelector('.cart-items-table'); + const cartItemsTableWidth = cartItemsTable ? cartItemsTable.offsetWidth : 0; + + const mobileBreakpoint = 768; + const quantityWrapper = document.querySelector('.quantity-wrapper'); const quantityOnDesktop = document.querySelector('.quantity-on-desktop'); const quantityOnMobile = document.querySelector('.quantity-on-mobile'); - if (window.innerWidth > 768) { + if (window.innerWidth > mobileBreakpoint || cartItemsTableWidth > 500) { quantityOnDesktop.appendChild(quantityWrapper); if (quantityOnMobile.contains(quantityWrapper)) { quantityOnMobile.removeChild(quantityWrapper); } + + if (cartItemsTable.classList.contains('mobile')) { + cartItemsTable.classList.remove('mobile'); + } + + if (!cartItemsTable.classList.contains('desktop')) { + cartItemsTable.classList.add('desktop'); + } } - if (window.innerWidth < 768) { + if (window.innerWidth < mobileBreakpoint || cartItemsTableWidth < 500) { quantityOnMobile.appendChild(quantityWrapper); if (quantityOnDesktop.contains(quantityWrapper)) { quantityOnDesktop.removeChild(quantityWrapper); } + + if (!cartItemsTable.classList.contains('mobile')) { + cartItemsTable.classList.add('mobile'); + } + + if (cartItemsTable.classList.contains('desktop')) { + cartItemsTable.classList.remove('desktop'); + } } } From 1367f45a1f7d3e9a7cd3b237f3d740776b8fa1b7 Mon Sep 17 00:00:00 2001 From: jamyoucn00 <114928221+jamyoucn00@users.noreply.github.com> Date: Wed, 21 Dec 2022 11:27:10 +0100 Subject: [PATCH 02/11] update styles --- assets/cart.css | 21 ++++++++++++++++++ assets/utils.css | 55 +++++++++++++++++++++++------------------------- styles/cart.scss | 35 ++++++++++++++++++++++++++++++ 3 files changed, 82 insertions(+), 29 deletions(-) diff --git a/assets/cart.css b/assets/cart.css index 3a68dbbf..42d2f891 100644 --- a/assets/cart.css +++ b/assets/cart.css @@ -9,6 +9,27 @@ max-width: 100%; min-width: 22rem; } +.yc-cart .cart-items-table .quantity-head, +.yc-cart .cart-items-table .quantity-on-desktop { + display: none; +} +.yc-cart .cart-items-table .quantity-on-mobile { + display: table-cell; +} +@media (min-width: 768px) { + .yc-cart .cart-items-table .quantity-on-desktop { + display: table-cell; + } + .yc-cart .cart-items-table .quantity-head { + display: block; + } +} +.yc-cart .cart-items-table.mobile .quantity-head { + display: none; +} +.yc-cart .cart-items-table.desktop .quantity-head { + display: block; +} .yc-cart .cart-table th { text-align: start; } diff --git a/assets/utils.css b/assets/utils.css index 0825d165..a1b5ba8f 100644 --- a/assets/utils.css +++ b/assets/utils.css @@ -264,18 +264,14 @@ video { margin-top: 0.25rem; } -.mt-7 { - margin-top: 1.75rem; +.mb-7 { + margin-bottom: 1.75rem; } .mt-5 { margin-top: 1.25rem; } -.mb-7 { - margin-bottom: 1.75rem; -} - .mt-24 { margin-top: 6rem; } @@ -284,6 +280,10 @@ video { margin-top: -0.25rem; } +.mt-7 { + margin-top: 1.75rem; +} + .mt-8 { margin-top: 2rem; } @@ -312,19 +312,24 @@ video { height: 100%; } -.h-9 { - height: 2.25rem; -} - .h-fit { height: -moz-fit-content; height: fit-content; } +.h-9 { + height: 2.25rem; +} + .w-full { width: 100%; } +.w-fit { + width: -moz-fit-content; + width: fit-content; +} + .w-9 { width: 2.25rem; } @@ -333,11 +338,6 @@ video { width: 6rem; } -.w-fit { - width: -moz-fit-content; - width: fit-content; -} - .table-auto { table-layout: auto; } @@ -370,18 +370,14 @@ video { gap: 3.5rem; } -.gap-6 { - gap: 1.5rem; +.gap-1 { + gap: 0.25rem; } .gap-3 { gap: 0.75rem; } -.gap-1 { - gap: 0.25rem; -} - .gap-2 { gap: 0.5rem; } @@ -390,6 +386,10 @@ video { gap: 2.5rem; } +.gap-6 { + gap: 1.5rem; +} + .self-baseline { align-self: baseline; } @@ -450,11 +450,6 @@ video { line-height: 2.5rem; } -.text-base { - font-size: 1rem; - line-height: 1.5rem; -} - .text-2xl { font-size: 1.5rem; line-height: 2rem; @@ -480,6 +475,11 @@ video { line-height: 1.75rem; } +.text-base { + font-size: 1rem; + line-height: 1.5rem; +} + .capitalize { text-transform: capitalize; } @@ -496,9 +496,6 @@ video { .md\:block { display: block; } - .md\:table-cell { - display: table-cell; - } .md\:hidden { display: none; } diff --git a/styles/cart.scss b/styles/cart.scss index d3dd7eb9..d023635f 100644 --- a/styles/cart.scss +++ b/styles/cart.scss @@ -1,3 +1,5 @@ +@import 'helpers/mixins'; + .yc-cart { margin: 4rem 0 2rem; @@ -13,6 +15,39 @@ min-width: 22rem; } + .cart-items-table { + .quantity-head, + .quantity-on-desktop { + display: none; + } + + .quantity-on-mobile { + display: table-cell; + } + + @include breakpoint('md') { + .quantity-on-desktop { + display: table-cell; + } + + .quantity-head { + display: block; + } + } + + &.mobile { + .quantity-head { + display: none; + } + } + + &.desktop { + .quantity-head { + display: block; + } + } + } + .cart-table { th { text-align: start; From 1cada31fcff3f7ad9a6c51c109d84a7c412f7202 Mon Sep 17 00:00:00 2001 From: jamyoucn00 <114928221+jamyoucn00@users.noreply.github.com> Date: Wed, 21 Dec 2022 11:27:21 +0100 Subject: [PATCH 03/11] update liquid --- sections/main-cart.liquid | 69 +---------------------------------- snippets/cart-table.liquid | 73 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 74 insertions(+), 68 deletions(-) create mode 100644 snippets/cart-table.liquid diff --git a/sections/main-cart.liquid b/sections/main-cart.liquid index 17d85172..e9cfc24e 100644 --- a/sections/main-cart.liquid +++ b/sections/main-cart.liquid @@ -9,74 +9,7 @@ {{ 'cart.items_count' | t }}
- | - {{ 'cart.items.quantity' | t }} - | -{{ 'cart.items.total' | t }} | -
---|---|---|
-
-
-
- {{ item.name }}
-
- {{ item.price | money }}
-
-
- |
-
-
-
- - {%- render 'quantity-input', item: item -%} - | -{{ item.price | times: item.quantity | money }} | -
+ | + {{ 'cart.items.quantity' | t }} + | +{{ 'cart.items.total' | t }} | +
---|---|---|
+
+
+
+ {{ item.name }}
+
+ {{ item.price | money }}
+
+
+ |
+
+
+
+ + {%- render 'quantity-input', item: item -%} + | +{{ item.price | times: item.quantity | money }} | +
- | - {{ 'cart.items.quantity' | t }} - | -{{ 'cart.items.total' | t }} | -
---|---|---|
- |
+
+ + {%- render 'quantity-input', item: item -%} + | +{{ item.price | times: item.quantity | money }} | +