HeadersRenderer.vue 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <template>
  2. <div>
  3. <div
  4. class="bg-primary border-dividerLight top-lowerSecondaryStickyFold sticky z-10 flex items-center justify-between flex-1 pl-4 border-b"
  5. >
  6. <label class="text-secondaryLight font-semibold">
  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. <div
  21. v-for="(header, index) in headers"
  22. :key="`header-${index}`"
  23. class="divide-dividerLight border-dividerLight group flex border-b divide-x"
  24. >
  25. <span
  26. class="group-hover:text-secondaryDark flex flex-1 min-w-0 px-4 py-2 transition"
  27. >
  28. <span class="truncate rounded-sm select-all">
  29. {{ header.key }}
  30. </span>
  31. </span>
  32. <span
  33. class="group-hover:text-secondaryDark flex flex-1 min-w-0 px-4 py-2 transition"
  34. >
  35. <span class="truncate rounded-sm select-all">
  36. {{ header.value }}
  37. </span>
  38. </span>
  39. </div>
  40. </div>
  41. </template>
  42. <script setup lang="ts">
  43. import { ref } from "@nuxtjs/composition-api"
  44. import { HoppRESTHeader } from "~/helpers/types/HoppRESTRequest"
  45. import { copyToClipboard } from "~/helpers/utils/clipboard"
  46. import { useI18n, useToast } from "~/helpers/utils/composables"
  47. const t = useI18n()
  48. const toast = useToast()
  49. const props = defineProps<{
  50. headers: Array<HoppRESTHeader>
  51. }>()
  52. const copyIcon = ref("copy")
  53. const copyHeaders = () => {
  54. copyToClipboard(JSON.stringify(props.headers))
  55. copyIcon.value = "check"
  56. toast.success(`${t("state.copied_to_clipboard")}`)
  57. setTimeout(() => (copyIcon.value = "copy"), 1000)
  58. }
  59. </script>