| 
									
										
										
										
											2021-08-02 22:15:11 -08:00
										 |  |  | <template> | 
					
						
							|  |  |  |   <v-tooltip | 
					
						
							|  |  |  |     ref="copyToolTip" | 
					
						
							|  |  |  |     v-model="show" | 
					
						
							| 
									
										
										
										
											2023-12-29 16:48:28 +01:00
										 |  |  |     :color="copied? 'success lighten-1' : 'red lighten-1'" | 
					
						
							| 
									
										
										
										
											2021-08-02 22:15:11 -08:00
										 |  |  |     top | 
					
						
							|  |  |  |     :open-on-hover="false" | 
					
						
							|  |  |  |     :open-on-click="true" | 
					
						
							|  |  |  |     close-delay="500" | 
					
						
							|  |  |  |     transition="slide-y-transition" | 
					
						
							|  |  |  |   > | 
					
						
							|  |  |  |     <template #activator="{ on }"> | 
					
						
							|  |  |  |       <v-btn | 
					
						
							| 
									
										
										
										
											2021-10-04 20:16:37 -08:00
										 |  |  |         :icon="icon" | 
					
						
							| 
									
										
										
										
											2021-08-02 22:15:11 -08:00
										 |  |  |         :color="color" | 
					
						
							|  |  |  |         retain-focus-on-click | 
					
						
							| 
									
										
										
										
											2021-11-04 18:15:23 -08:00
										 |  |  |         :class="btnClass" | 
					
						
							| 
									
										
										
										
											2021-08-02 22:15:11 -08:00
										 |  |  |         @click=" | 
					
						
							|  |  |  |           on.click; | 
					
						
							|  |  |  |           textToClipboard(); | 
					
						
							|  |  |  |         " | 
					
						
							|  |  |  |         @blur="on.blur" | 
					
						
							|  |  |  |       > | 
					
						
							|  |  |  |         <v-icon>{{ $globals.icons.contentCopy }}</v-icon> | 
					
						
							| 
									
										
										
										
											2022-08-15 23:55:51 +02:00
										 |  |  |         {{ icon ? "" : $t("general.copy") }} | 
					
						
							| 
									
										
										
										
											2021-08-02 22:15:11 -08:00
										 |  |  |       </v-btn> | 
					
						
							|  |  |  |     </template> | 
					
						
							|  |  |  |     <span> | 
					
						
							|  |  |  |       <v-icon left dark> | 
					
						
							|  |  |  |         {{ $globals.icons.clipboardCheck }} | 
					
						
							|  |  |  |       </v-icon> | 
					
						
							| 
									
										
										
										
											2023-12-29 16:48:28 +01:00
										 |  |  |       <slot v-if="!isSupported"> {{ $t("general.your-browser-does-not-support-clipboard") }} </slot> | 
					
						
							|  |  |  |       <slot v-else> {{ copied ? $t("general.copied_message") : $t("general.clipboard-copy-failure") }} </slot> | 
					
						
							| 
									
										
										
										
											2021-08-02 22:15:11 -08:00
										 |  |  |     </span> | 
					
						
							|  |  |  |   </v-tooltip> | 
					
						
							|  |  |  | </template> | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-01-09 07:15:23 +01:00
										 |  |  | <script lang="ts"> | 
					
						
							| 
									
										
										
										
											2023-12-29 16:48:28 +01:00
										 |  |  | import { useClipboard } from "@vueuse/core" | 
					
						
							| 
									
										
										
										
											2022-01-09 07:15:23 +01:00
										 |  |  | import { defineComponent, ref } from "@nuxtjs/composition-api"; | 
					
						
							|  |  |  | import { VTooltip } from "~/types/vuetify"; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | export default defineComponent({ | 
					
						
							| 
									
										
										
										
											2021-08-02 22:15:11 -08:00
										 |  |  |   props: { | 
					
						
							|  |  |  |     copyText: { | 
					
						
							| 
									
										
										
										
											2021-08-07 16:49:55 -08:00
										 |  |  |       type: String, | 
					
						
							| 
									
										
										
										
											2022-08-15 23:55:51 +02:00
										 |  |  |       required: true, | 
					
						
							| 
									
										
										
										
											2021-08-02 22:15:11 -08:00
										 |  |  |     }, | 
					
						
							|  |  |  |     color: { | 
					
						
							| 
									
										
										
										
											2021-08-07 16:49:55 -08:00
										 |  |  |       type: String, | 
					
						
							| 
									
										
										
										
											2021-11-22 20:10:48 -09:00
										 |  |  |       default: "", | 
					
						
							| 
									
										
										
										
											2021-08-02 22:15:11 -08:00
										 |  |  |     }, | 
					
						
							| 
									
										
										
										
											2021-10-04 20:16:37 -08:00
										 |  |  |     icon: { | 
					
						
							|  |  |  |       type: Boolean, | 
					
						
							|  |  |  |       default: true, | 
					
						
							|  |  |  |     }, | 
					
						
							| 
									
										
										
										
											2021-11-04 18:15:23 -08:00
										 |  |  |     btnClass: { | 
					
						
							|  |  |  |       type: String, | 
					
						
							|  |  |  |       default: "", | 
					
						
							|  |  |  |     }, | 
					
						
							| 
									
										
										
										
											2021-08-02 22:15:11 -08:00
										 |  |  |   }, | 
					
						
							| 
									
										
										
										
											2022-01-09 07:15:23 +01:00
										 |  |  |   setup(props) { | 
					
						
							| 
									
										
										
										
											2023-12-29 16:48:28 +01:00
										 |  |  |     const { copy, copied, isSupported } = useClipboard() | 
					
						
							| 
									
										
										
										
											2022-01-09 07:15:23 +01:00
										 |  |  |     const show = ref(false); | 
					
						
							|  |  |  |     const copyToolTip = ref<VTooltip | null>(null); | 
					
						
							| 
									
										
										
										
											2021-08-02 22:15:11 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-01-09 07:15:23 +01:00
										 |  |  |     function toggleBlur() { | 
					
						
							|  |  |  |       copyToolTip.value?.deactivate(); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-12-29 16:48:28 +01:00
										 |  |  |     async function textToClipboard() { | 
					
						
							|  |  |  |       if (isSupported.value) { | 
					
						
							|  |  |  |         await copy(props.copyText); | 
					
						
							|  |  |  |         if (copied.value) { | 
					
						
							|  |  |  |           console.log(`Copied\n${props.copyText}`) | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         else { | 
					
						
							|  |  |  |           console.warn("Copy failed: ", copied.value); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |       else { | 
					
						
							|  |  |  |         console.warn("Clipboard is currently not supported by your browser. Ensure you're on a secure (https) site."); | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-01-09 07:15:23 +01:00
										 |  |  |       show.value = true; | 
					
						
							| 
									
										
										
										
											2021-08-02 22:15:11 -08:00
										 |  |  |       setTimeout(() => { | 
					
						
							| 
									
										
										
										
											2022-01-09 07:15:23 +01:00
										 |  |  |         toggleBlur(); | 
					
						
							| 
									
										
										
										
											2021-08-02 22:15:11 -08:00
										 |  |  |       }, 500); | 
					
						
							| 
									
										
										
										
											2022-01-09 07:15:23 +01:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return { | 
					
						
							|  |  |  |       show, | 
					
						
							|  |  |  |       copyToolTip, | 
					
						
							|  |  |  |       textToClipboard, | 
					
						
							| 
									
										
										
										
											2023-12-29 16:48:28 +01:00
										 |  |  |       copied, | 
					
						
							|  |  |  |       isSupported, | 
					
						
							| 
									
										
										
										
											2022-08-15 23:55:51 +02:00
										 |  |  |     }; | 
					
						
							| 
									
										
										
										
											2021-08-02 22:15:11 -08:00
										 |  |  |   }, | 
					
						
							| 
									
										
										
										
											2022-01-09 07:15:23 +01:00
										 |  |  | }); | 
					
						
							| 
									
										
										
										
											2021-08-02 22:15:11 -08:00
										 |  |  | </script> | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-08-15 23:55:51 +02:00
										 |  |  | <style lang="scss" scoped></style> |