- Added new tertiary button style with focus ring. - Updated button classes in navbar and basket components for consistency.
75 lines
1.9 KiB
Vue
75 lines
1.9 KiB
Vue
<template>
|
|
<button
|
|
ref="navBasketButton"
|
|
class="btn btn-tertiary border-dark focus-ring focus-ring-dark btn-lg text-decoration-none d-flex align-items-center gap-2"
|
|
:title="__('Show basket')"
|
|
data-bs-toggle="tooltip"
|
|
aria-label="Ouvrir le panier"
|
|
@click="onBasketButtonClick"
|
|
>
|
|
<div class="position-relative">
|
|
<i class="fa-solid fa-basket-shopping" />
|
|
|
|
<span
|
|
v-show="count > 0"
|
|
class="position-absolute top-0 start-100 translate-middle ms-2 badge rounded-pill text-bg-info"
|
|
>
|
|
{{ count }}
|
|
<span class="visually-hidden">{{ __('articles dans le panier') }}</span>
|
|
</span>
|
|
</div>
|
|
|
|
<span
|
|
v-if="amount"
|
|
class="d-none d-lg-block fw-bold"
|
|
>
|
|
{{ amount }}
|
|
</span>
|
|
</button>
|
|
</template>
|
|
|
|
<script setup lang="ts">
|
|
import { computed, onBeforeUnmount, onMounted, ref } from "vue";
|
|
|
|
import { useBasketStore } from "@fo/stores/basket.store";
|
|
import { Tooltips } from "@modules/bs-tooltips";
|
|
import { __ } from "@modules/trans";
|
|
|
|
defineOptions({ name: "NavBasketButton" });
|
|
|
|
const cartStore = useBasketStore();
|
|
|
|
const count = computed(() => cartStore.basket.items.reduce((acc, item) => acc + item.qty, 0));
|
|
const amount = computed(() => cartStore.basket.total.taxIncluded?.formatted);
|
|
|
|
const navBasketButton = ref<HTMLButtonElement | null>(null);
|
|
let tooltipsInstance: Tooltips | null = null;
|
|
|
|
onMounted(() => {
|
|
initTooltips();
|
|
});
|
|
|
|
onBeforeUnmount(() => {
|
|
if (tooltipsInstance) {
|
|
tooltipsInstance.destroy();
|
|
}
|
|
});
|
|
|
|
function onBasketButtonClick() {
|
|
cartStore.toggleBaketPanel();
|
|
}
|
|
|
|
/** Initialise le tooltip directement sur la ref Vue */
|
|
function initTooltips(): void {
|
|
setTimeout(() => {
|
|
if (!navBasketButton.value) {
|
|
return;
|
|
}
|
|
tooltipsInstance = Tooltips.make({
|
|
type: "dom",
|
|
elements: navBasketButton.value,
|
|
options: {container: navBasketButton.value}
|
|
});
|
|
}, 500);
|
|
}
|
|
</script>
|