All files / apps/huella-legal/layers/reading/app/components/article CiteBox.vue

100% Statements 22/22
100% Branches 10/10
100% Functions 8/8
100% Lines 21/21

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70    19x                 2x           10x 5x                               2x 12x                       17x   17x 17x 17x 17x 17x 17x   17x 12x   17x 19x     17x 2x 2x 2x      
<template>
    <section
        v-if="citation"
        :aria-labelledby="headingId"
        class="rounded-sm border border-default bg-muted p-5 md:p-6"
    >
        <h2 :id="headingId" class="font-serif text-xl text-highlighted">
            {{ $t("citeBox.title") }}
        </h2>
        <UTabs
            v-if="citations.length > 1"
            v-model="tab"
            :items="tabs"
            variant="link"
            :ui="{ list: 'print:hidden', trigger: 'text-sm' }"
            class="mt-3"
        >
            <template #content="{ item }">
                <p class="mt-4 font-serif text-citation wrap-break-word text-toned">
                    {{ item.text }}
                </p>
            </template>
        </UTabs>
        <p v-else class="mt-4 font-serif text-citation wrap-break-word text-toned">
            {{ citation.text }}
        </p>
        <ClientOnly>
            <UButton
                v-if="canCopy"
                variant="outline"
                color="neutral"
                icon="i-lucide-copy"
                :label="$t('citeBox.copy')"
                class="mt-4 print:hidden"
                @click="copy(citation)"
            />
        </ClientOnly>
    </section>
</template>
 
<script setup lang="ts">
import { useClipboard } from "@vueuse/core";
 
interface Props {
    citations: Citation[];
}
 
const props = defineProps<Props>();
 
const { t } = useI18n();
const toast = useToast();
const headingId = useId();
const { copy: copyText, isSupported: canCopy } = useClipboard();
const track = useTrack();
const tab = ref<string>("0");
 
const tabs = computed(() =>
    props.citations.map(({ style, text }, index) => ({ label: style, value: String(index), text })),
);
const citation = computed<Citation | undefined>(
    () => props.citations[Number(tab.value)] ?? props.citations[0],
);
 
const copy = async ({ style, text }: Citation): Promise<void> => {
    await copyText(text);
    track("citation_copy", { style });
    toast.add({ title: t("citeBox.copied"), icon: "i-lucide-check" });
};
</script>