Add Cart button and opening/closing transition

This commit is contained in:
2021-11-05 12:45:30 +01:00
parent 77b072359c
commit b8d1d6334c
6 changed files with 69 additions and 26 deletions

View File

@@ -0,0 +1,19 @@
<script lang="ts">
import { cartOpen, cartAmount } from '$utils/store'
import ButtonCircle from './ButtonCircle.svelte'
const handleCartOpening = () => {
$cartOpen = true
}
</script>
<div class="shop-location__cart">
<ButtonCircle color="purple" on:click={handleCartOpening}>
<img src="/images/icons/pin.svg" alt="">
</ButtonCircle>
{#if $cartAmount > 0}
<span class="quantity">{$cartAmount}</span>
{/if}
</div>

View File

@@ -1,18 +1,24 @@
<script lang="ts"> <script lang="ts">
import { getContext } from 'svelte' import { fade, fly } from 'svelte/transition'
import { cartOpen } from '$utils/store'
import { quartOut } from 'svelte/easing'
// Components // Components
import Button from '$components/atoms/Button.svelte' import Button from '$components/atoms/Button.svelte'
import Image from '$components/atoms/Image.svelte'
import PosterCart from '$components/molecules/PosterCart.svelte' import PosterCart from '$components/molecules/PosterCart.svelte'
const { locations, shop } = getContext('global')
// Closing the cart
const handleCloseCart = () => {
$cartOpen = false
}
</script> </script>
<aside class="cart"> <aside class="cart"
transition:fly={{ x: 48, duration: 600, easing: quartOut }}
>
<header class="cart__heading"> <header class="cart__heading">
<h2>Cart</h2> <h2>Cart</h2>
<a class="text-label" href="#">Close</a> <button class="text-label" on:click={handleCloseCart}>Close</button>
</header> </header>
<div class="cart__content"> <div class="cart__content">
@@ -36,3 +42,8 @@
</div> </div>
</footer> </footer>
</aside> </aside>
<div class="cart-overlay"
transition:fade={{ duration: 600, easing: quartOut }}
on:click={handleCloseCart}
/>

View File

@@ -1,9 +1,10 @@
<script lang="ts"> <script lang="ts">
import { cartOpen } from '$utils/store'
// Components // Components
import Metas from '$components/Metas.svelte' import Metas from '$components/Metas.svelte'
import SiteTitle from '$components/atoms/SiteTitle.svelte' import SiteTitle from '$components/atoms/SiteTitle.svelte'
import Image from '$components/atoms/Image.svelte' import Image from '$components/atoms/Image.svelte'
import ButtonCircle from '$components/atoms/ButtonCircle.svelte' import CartButton from '$components/atoms/CartButton.svelte'
import PosterLayout from '$components/layouts/PosterLayout.svelte' import PosterLayout from '$components/layouts/PosterLayout.svelte'
import Poster from '$components/molecules/Poster.svelte' import Poster from '$components/molecules/Poster.svelte'
import EmailForm from '$components/molecules/EmailForm.svelte' import EmailForm from '$components/molecules/EmailForm.svelte'
@@ -22,7 +23,9 @@
/> />
<main class="shop-page"> <main class="shop-page">
{#if $cartOpen}
<Cart /> <Cart />
{/if}
<section class="shop-page__intro"> <section class="shop-page__intro">
<a href="/" class="back"> <a href="/" class="back">
Back to Houses Of Back to Houses Of
@@ -47,9 +50,8 @@
{/each} {/each}
</ul> </ul>
</nav> </nav>
<button class="button-cart">
<span>2</span> <CartButton />
</button>
</div> </div>
</header> </header>
@@ -75,14 +77,8 @@
</select> </select>
</dd> </dd>
</dl> </dl>
<div class="shop-location__cart">
<ButtonCircle <CartButton />
color= 'purple'
>
<img src="/images/icons/pin.svg" alt="">
</ButtonCircle>
<p class="quantity">3</p>
</div>
</nav> </nav>
<section class="shop-page__about grid"> <section class="shop-page__about grid">

View File

@@ -167,4 +167,15 @@
} }
} }
} }
// Overlay
&-overlay {
position: fixed;
z-index: 99;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: rgba($color-primary, 0.9);
}
} }

View File

@@ -1,5 +1,6 @@
.shop-page { .shop-page {
position: relative; position: relative;
// Cart // Cart
.cart { .cart {
display: flex; display: flex;
@@ -27,18 +28,16 @@
top: 18px; top: 18px;
left: 20px; left: 20px;
right: 20px; right: 20px;
width: calc(100% - 80px);
justify-content: space-between; justify-content: space-between;
@include bp (sm) { @include bp (sm) {
top: 32px; top: 32px;
left: 40px; left: 32px;
right: 40px; right: 32px;
} }
// Left // Left
&__left { &__left {
dt { dt {
color: $color-primary; color: $color-primary;
font-weight: 400; font-weight: 400;
@@ -78,6 +77,7 @@
} }
} }
} }
// Cart // Cart
&__cart { &__cart {
display: none; display: none;
@@ -85,6 +85,7 @@
@include bp (sm) { @include bp (sm) {
display: flex; display: flex;
margin-left: auto;
} }
.quantity { .quantity {
@@ -101,7 +102,7 @@
font-weight: 600; font-weight: 600;
color: #fff; color: #fff;
background-color: $color-secondary; background-color: $color-secondary;
border-radius: 100vh; border-radius: 100%;
} }
} }
} }
@@ -149,13 +150,13 @@
// Site Title // Site Title
h1 { h1 {
font-size: clamp(#{rem(88px)}, 10vw, #{rem(140px)});
position: absolute; position: absolute;
z-index: 2; z-index: 2;
top: 50%; top: 50%;
left: 50%; left: 50%;
transform: translate(-50%, -50%);
width: 100%; width: 100%;
transform: translate3d(-50%, -50%, 0);
font-size: clamp(#{rem(88px)}, 10vw, #{rem(140px)});
text-align: center; text-align: center;
span, strong { span, strong {

5
src/utils/store.ts Normal file
View File

@@ -0,0 +1,5 @@
import { writable } from 'svelte/store'
// Shop
export const cartOpen = writable(false)
export const cartAmount = writable(3)