-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathResponsePanel.vue
More file actions
155 lines (134 loc) · 3.02 KB
/
Copy pathResponsePanel.vue
File metadata and controls
155 lines (134 loc) · 3.02 KB
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
<script setup>
import { ref } from "vue";
const props = defineProps({
status: {
type: [String, Number],
default: "200",
},
});
const copied = ref(false);
const copyCode = async (event) => {
const panel = event.target.closest(".response-panel");
const codeBlock = panel?.querySelector("pre code");
if (codeBlock) {
await navigator.clipboard.writeText(codeBlock.textContent);
copied.value = true;
setTimeout(() => (copied.value = false), 2000);
}
};
const statusClass = () => {
const code = parseInt(props.status);
if (code >= 200 && code < 300) return "status-success";
if (code >= 400 && code < 500) return "status-warning";
if (code >= 500) return "status-error";
return "";
};
</script>
<template>
<div class="response-panel">
<div class="response-header">
<div class="header-left">
<span class="response-label">Response</span>
<span class="status-code" :class="statusClass()">{{ status }}</span>
</div>
<button class="copy-btn" @click="copyCode" title="Copy response">
<svg
v-if="!copied"
width="16"
height="16"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="2"
>
<rect x="9" y="9" width="13" height="13" rx="2" ry="2" />
<path d="M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1" />
</svg>
<svg v-else width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="#22c55e" stroke-width="2">
<polyline points="20 6 9 17 4 12" />
</svg>
</button>
</div>
<div class="response-body">
<slot />
</div>
</div>
</template>
<style scoped>
.response-panel {
border-radius: 8px;
overflow: hidden;
border: 1px solid #e5e7eb;
background: #fff;
margin-bottom: 16px;
}
.dark .response-panel {
background: #0f0f0f;
border-color: #2a2a2a;
}
.response-header {
display: flex;
align-items: center;
justify-content: space-between;
padding: 8px 12px;
background: #f9fafb;
border-bottom: 1px solid #e5e7eb;
}
.dark .response-header {
background: #1a1a1a;
border-bottom-color: #2a2a2a;
}
.header-left {
display: flex;
align-items: center;
gap: 12px;
}
.response-label {
font-size: 14px;
font-weight: 500;
color: #374151;
}
.dark .response-label {
color: #d1d5db;
}
.status-code {
font-family: var(--vp-font-family-mono);
font-size: 14px;
font-weight: 600;
}
.status-success {
color: #22c55e;
}
.status-warning {
color: #f59e0b;
}
.status-error {
color: #ef4444;
}
.copy-btn {
padding: 6px;
background: transparent;
border: none;
color: #9ca3af;
cursor: pointer;
border-radius: 4px;
display: flex;
align-items: center;
}
.copy-btn:hover {
color: #374151;
background: #e5e7eb;
}
.dark .copy-btn:hover {
color: #f3f4f6;
background: #374151;
}
.response-body :deep(div[class*="language-"]) {
margin: 0 !important;
border-radius: 0 !important;
border: none !important;
}
.response-body :deep(pre) {
margin: 0 !important;
}
</style>