First version running with npm run dev
This commit is contained in:
commit
f90ec06a4f
28 files changed
+12042
No files matched your search
@@ -0,0 +1,160 @@
|
||||
<script setup lang="ts">
|
||||
import { useToast } from "~/composables/useToast";
|
||||
|
||||
interface Props {
|
||||
label?: string;
|
||||
text: string;
|
||||
loading?: boolean;
|
||||
error?: string;
|
||||
}
|
||||
|
||||
const props = defineProps<Props>();
|
||||
const emit = defineEmits<{
|
||||
(e: "copy"): void;
|
||||
}>();
|
||||
|
||||
const { show: showToast } = useToast();
|
||||
const isCopied = ref(false);
|
||||
|
||||
async function copyToClipboard() {
|
||||
if (!props.text) return;
|
||||
|
||||
try {
|
||||
await navigator.clipboard.writeText(props.text);
|
||||
isCopied.value = true;
|
||||
emit("copy");
|
||||
showToast("Copied to clipboard", "success");
|
||||
setTimeout(() => {
|
||||
isCopied.value = false;
|
||||
}, 2000);
|
||||
} catch {
|
||||
isCopied.value = false;
|
||||
showToast("Failed to copy text", "error");
|
||||
}
|
||||
}
|
||||
|
||||
const outputRef = computed(() => props.text);
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="translation-output">
|
||||
<div class="translation-output-header">
|
||||
<label v-if="label" class="translation-output-label">
|
||||
{{ label }}
|
||||
</label>
|
||||
<button
|
||||
v-if="outputRef"
|
||||
class="copy-btn btn"
|
||||
@click="copyToClipboard"
|
||||
:disabled="loading"
|
||||
type="button"
|
||||
:aria-label="isCopied ? 'Copied!' : 'Copy to clipboard'"
|
||||
:title="isCopied ? 'Copied!' : 'Copy to clipboard'"
|
||||
>
|
||||
{{ isCopied ? "✓ Copied" : "Copy" }}
|
||||
</button>
|
||||
</div>
|
||||
<div
|
||||
class="translation-output-area textarea"
|
||||
:class="{ loading: loading, error: !!error }"
|
||||
>
|
||||
<div v-if="loading" class="translation-loading">
|
||||
<div class="loading-spinner"></div>
|
||||
<span>Translating...</span>
|
||||
</div>
|
||||
<div v-else-if="error" class="translation-error">
|
||||
<span class="error-icon">⚠</span>
|
||||
{{ error }}
|
||||
</div>
|
||||
<div v-else-if="text" class="translation-result">
|
||||
{{ text }}
|
||||
</div>
|
||||
<span v-else class="translation-placeholder">
|
||||
Translation will appear here...
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.translation-output {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
.translation-output-header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
margin-bottom: 0.25rem;
|
||||
}
|
||||
|
||||
.translation-output-label {
|
||||
font-size: 0.875rem;
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
.copy-btn {
|
||||
padding: 0.25rem 0.5rem;
|
||||
font-size: 0.75rem;
|
||||
background-color: var(--secondary-color);
|
||||
}
|
||||
|
||||
.copy-btn:hover {
|
||||
opacity: 0.9;
|
||||
}
|
||||
|
||||
.copy-btn:disabled {
|
||||
opacity: 0.5;
|
||||
cursor: not-allowed;
|
||||
}
|
||||
|
||||
.translation-output-area {
|
||||
position: relative;
|
||||
min-height: 120px;
|
||||
background-color: var(--surface-alt-color);
|
||||
}
|
||||
|
||||
.translation-output-area.loading {
|
||||
opacity: 0.7;
|
||||
}
|
||||
|
||||
.translation-loading {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.5rem;
|
||||
color: var(--muted-color);
|
||||
}
|
||||
|
||||
.loading-spinner {
|
||||
width: 16px;
|
||||
height: 16px;
|
||||
border: 2px solid var(--border-color);
|
||||
border-top-color: var(--primary-color);
|
||||
border-radius: 50%;
|
||||
animation: spin 1s linear infinite;
|
||||
}
|
||||
|
||||
@keyframes spin {
|
||||
to {
|
||||
transform: rotate(360deg);
|
||||
}
|
||||
}
|
||||
|
||||
.translation-error {
|
||||
color: var(--error-color);
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.5rem;
|
||||
}
|
||||
|
||||
.error-icon {
|
||||
font-size: 1rem;
|
||||
}
|
||||
|
||||
.translation-placeholder {
|
||||
color: var(--placeholder-color);
|
||||
font-style: italic;
|
||||
}
|
||||
</style>
|
||||
Reference in new issue
Block a user