HeadersRenderer.vue 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. <template>
  2. <div>
  3. <div
  4. class="sticky z-10 flex items-center justify-between pl-4 border-b bg-primary border-dividerLight top-lowerSecondaryStickyFold"
  5. >
  6. <label class="font-semibold text-secondaryLight">
  7. {{ t("request.header_list") }}
  8. </label>
  9. <div class="flex">
  10. <ButtonSecondary
  11. v-if="headers"
  12. ref="copyHeaders"
  13. v-tippy="{ theme: 'tooltip' }"
  14. :title="t('action.copy')"
  15. :svg="copyIcon"
  16. @click.native="copyHeaders"
  17. />
  18. </div>
  19. </div>
  20. <LensesHeadersRendererEntry
  21. v-for="(header, index) in headers"
  22. :key="index"
  23. :header="header"
  24. />
  25. </div>
  26. </template>
  27. <script setup lang="ts">
  28. import { HoppRESTHeader } from "@hoppscotch/data"
  29. import { refAutoReset } from "@vueuse/core"
  30. import { copyToClipboard } from "~/helpers/utils/clipboard"
  31. import { useI18n, useToast } from "~/helpers/utils/composables"
  32. const t = useI18n()
  33. const toast = useToast()
  34. const props = defineProps<{
  35. headers: Array<HoppRESTHeader>
  36. }>()
  37. const copyIcon = refAutoReset<"copy" | "check">("copy", 1000)
  38. const copyHeaders = () => {
  39. copyToClipboard(JSON.stringify(props.headers))
  40. copyIcon.value = "check"
  41. toast.success(`${t("state.copied_to_clipboard")}`)
  42. }
  43. </script>