HeadersRenderer.vue 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. <template>
  2. <div>
  3. <div
  4. class="
  5. bg-primary
  6. border-b border-dividerLight
  7. flex flex-1
  8. top-lowerSecondaryStickyFold
  9. pl-4
  10. z-10
  11. sticky
  12. items-center
  13. justify-between
  14. "
  15. >
  16. <label class="font-semibold text-secondaryLight">
  17. {{ $t("request.header_list") }}
  18. </label>
  19. <div class="flex">
  20. <ButtonSecondary
  21. v-if="headers"
  22. ref="copyHeaders"
  23. v-tippy="{ theme: 'tooltip' }"
  24. :title="$t('action.copy')"
  25. :svg="copyIcon"
  26. @click.native="copyHeaders"
  27. />
  28. </div>
  29. </div>
  30. <div
  31. v-for="(header, index) in headers"
  32. :key="`header-${index}`"
  33. class="
  34. divide-x divide-dividerLight
  35. border-b border-dividerLight
  36. flex
  37. group
  38. "
  39. >
  40. <span
  41. class="
  42. flex flex-1
  43. min-w-0
  44. py-2
  45. px-4
  46. transition
  47. group-hover:text-secondaryDark
  48. "
  49. >
  50. <span class="rounded-sm select-all truncate">
  51. {{ header.key }}
  52. </span>
  53. </span>
  54. <span
  55. class="
  56. flex flex-1
  57. min-w-0
  58. py-2
  59. px-4
  60. transition
  61. group-hover:text-secondaryDark
  62. "
  63. >
  64. <span class="rounded-sm select-all truncate">
  65. {{ header.value }}
  66. </span>
  67. </span>
  68. </div>
  69. </div>
  70. </template>
  71. <script setup lang="ts">
  72. import { ref, useContext } from "@nuxtjs/composition-api"
  73. import { HoppRESTHeader } from "~/helpers/types/HoppRESTRequest"
  74. import { copyToClipboard } from "~/helpers/utils/clipboard"
  75. const {
  76. $toast,
  77. app: { i18n },
  78. } = useContext()
  79. const t = i18n.t.bind(i18n)
  80. const props = defineProps<{
  81. headers: Array<HoppRESTHeader>
  82. }>()
  83. const copyIcon = ref("copy")
  84. const copyHeaders = () => {
  85. copyToClipboard(JSON.stringify(props.headers))
  86. copyIcon.value = "check"
  87. $toast.success(`${t("state.copied_to_clipboard")}`)
  88. setTimeout(() => (copyIcon.value = "copy"), 1000)
  89. }
  90. </script>