Skip to content

Commit 137370a

Browse files
committed
Refactor code
1 parent c9c1af8 commit 137370a

File tree

3 files changed

+44
-21
lines changed

3 files changed

+44
-21
lines changed

components/Cart/CartCheckoutButton.vue

Lines changed: 0 additions & 17 deletions
This file was deleted.

components/Cart/CartContents.vue

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,11 @@
4545
>
4646
Cart is currently empty
4747
</h2>
48-
<CartCheckoutButton
48+
<CommonButton
49+
link-to="/checkout"
4950
v-if="showCheckoutButton && data.cart?.contents?.nodes?.length"
50-
/>
51+
>CHECKOUT</CommonButton
52+
>
5153
</div>
5254
</template>
5355

components/common/CommonButton.vue

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,32 @@
11
<template>
2-
<div>
2+
<div v-if="linkTo" class="flex justify-center">
3+
<NuxtLink :to="linkTo" class="button-link">
4+
<button
5+
:class="{ disabled: isLoading }"
6+
@click="$emit('CommonButtonClick')"
7+
>
8+
<slot />
9+
<svg
10+
v-if="isLoading"
11+
class="absolute -mt-6 -ml-2 animate-spin"
12+
width="25"
13+
height="25"
14+
viewBox="0 0 24 24"
15+
fill="none"
16+
xmlns="http://www.w3.org/2000/svg"
17+
>
18+
<path
19+
fill-rule="evenodd"
20+
clip-rule="evenodd"
21+
d="M12 0C5.37258 0 0 5.37258 0 12C0 18.6274 5.37258 24 12 24C18.6274 24 24 18.6274 24 12C24 5.37258 18.6274 0 12 0ZM4.14355 13.5165C4.85219 17.2096 8.10023 20 12 20C16.4183 20 20 16.4183 20 12C20 7.58172 16.4183 4 12 4C8.0886 4 4.83283 6.80704 4.13728 10.5165L6.72824 10.5071C7.37819 8.20738 9.49236 6.52222 12.0001 6.52222C15.0254 6.52222 17.4779 8.9747 17.4779 12C17.4779 15.0253 15.0254 17.4778 12.0001 17.4778C9.49752 17.4778 7.3869 15.7995 6.73228 13.5071L4.14355 13.5165ZM9.52234 12C9.52234 13.3684 10.6317 14.4778 12.0001 14.4778C13.3685 14.4778 14.4779 13.3684 14.4779 12C14.4779 10.6316 13.3685 9.52222 12.0001 9.52222C10.6317 9.52222 9.52234 10.6316 9.52234 12Z"
22+
fill="white"
23+
/>
24+
</svg>
25+
</button>
26+
</NuxtLink>
27+
</div>
28+
<div v-else class="flex justify-center">
329
<button
4-
class="relative w-48 h-12 px-4 py-2 mt-4 transition ease-in-out delay-75 duration-300 font-bold text-white bg-blue-500 rounded hover:bg-blue-800"
530
:class="{ disabled: isLoading }"
631
@click="$emit('CommonButtonClick')"
732
>
@@ -40,11 +65,24 @@ defineProps({
4065
required: false,
4166
default: false,
4267
},
68+
linkTo: {
69+
type: String,
70+
required: false,
71+
default: "",
72+
},
4373
});
4474
</script>
4575

4676
<style scoped>
4777
.disabled {
4878
@apply bg-blue-500 text-white font-bold py-2 px-4 rounded opacity-50 cursor-not-allowed;
4979
}
80+
81+
button {
82+
@apply relative w-48 h-12 px-4 py-2 mt-4 transition ease-in-out delay-75 duration-300 font-bold text-white bg-blue-500 rounded hover:bg-blue-800;
83+
}
84+
85+
.button-link {
86+
border-bottom: none;
87+
}
5088
</style>

0 commit comments

Comments
 (0)