Files
hoppscotch/packages/hoppscotch-app/components/lenses/HeadersRenderer.vue
2022-06-01 16:54:37 +05:30

50 lines
1.3 KiB
Vue

<template>
<div>
<div
class="sticky z-10 flex items-center justify-between pl-4 border-b bg-primary border-dividerLight top-lowerSecondaryStickyFold"
>
<label class="font-semibold text-secondaryLight">
{{ t("request.header_list") }}
</label>
<div class="flex">
<ButtonSecondary
v-if="headers"
ref="copyHeaders"
v-tippy="{ theme: 'tooltip' }"
:title="t('action.copy')"
:svg="copyIcon"
@click.native="copyHeaders"
/>
</div>
</div>
<LensesHeadersRendererEntry
v-for="(header, index) in headers"
:key="index"
:header="header"
/>
</div>
</template>
<script setup lang="ts">
import { HoppRESTHeader } from "@hoppscotch/data"
import { refAutoReset } from "@vueuse/core"
import { copyToClipboard } from "~/helpers/utils/clipboard"
import { useI18n, useToast } from "~/helpers/utils/composables"
const t = useI18n()
const toast = useToast()
const props = defineProps<{
headers: Array<HoppRESTHeader>
}>()
const copyIcon = refAutoReset<"copy" | "check">("copy", 1000)
const copyHeaders = () => {
copyToClipboard(JSON.stringify(props.headers))
copyIcon.value = "check"
toast.success(`${t("state.copied_to_clipboard")}`)
}
</script>