Skip to content

Commit

Permalink
feat: update layout of translate dialog
Browse files Browse the repository at this point in the history
Signed-off-by: Luka Trovic <[email protected]>
  • Loading branch information
luka-nextcloud committed Jun 29, 2023
1 parent 6f12481 commit a7bbf77
Show file tree
Hide file tree
Showing 2 changed files with 93 additions and 18 deletions.
8 changes: 7 additions & 1 deletion src/components/Menu/MenuBar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,13 @@ export default {
},
showTranslate() {
const { from, to } = this.$editor.view.state.selection
const selectedText = this.$editor.view.state.doc.textBetween(from, to, ' ')
let selectedText = this.$editor.view.state.doc.textBetween(from, to, ' ')

if (!selectedText.trim().length) {
this.$editor.commands.selectAll()
selectedText = this.$editor.view.state.doc.textContent
}

console.debug('translation click', this.$editor.view.state.selection, selectedText)
this.displayTranslate = selectedText ?? ''
},
Expand Down
103 changes: 86 additions & 17 deletions src/components/Modal/Translate.vue
Original file line number Diff line number Diff line change
Expand Up @@ -20,26 +20,43 @@
-->

<template>
<NcModal @close="$emit('close')">
<NcModal size="large" @close="$emit('close')">
<div class="translate-dialog">
<h2>{{ t('text', 'Translate') }}</h2>
<textarea v-model="input" />
<div class="language-selector">
<label for="fromLanguage">{{ t('text', 'Source language') }}</label>
<NcSelect v-model="fromLanguage"
input-id="fromLanguage"
:options="fromLanguages"
:append-to-body="false" />
<em>{{ t('text', 'To translate individual parts of the text, select it before using the translate function.') }}</em>
<div class="wrapper">
<div class="col">
<div class="language-selector">
<label for="fromLanguage">{{ t('text', 'Translate from') }}</label>
<NcSelect v-model="fromLanguage"
input-id="fromLanguage"
:placeholder="t('text', 'Select language')"
:options="fromLanguages"
:disabled="disableFromLanguageSelect"
:append-to-body="false" />
</div>
<textarea ref="input"
v-model="input"
autofocus
@input="autosize"
@focus="onInputFocus" />
</div>
<div class="col">
<div class="language-selector">
<label for="toLanguage">{{ t('text', 'to') }}</label>
<NcSelect v-model="toLanguage"
input-id="toLanguage"
:placeholder="t('text', 'Select language')"
:options="toLanguages"
:disabled="!fromLanguage"
:append-to-body="false" />
</div>
<textarea ref="result"
v-model="result"
readonly
:class="{'icon-loading': loading }" />
</div>
</div>
<div class="language-selector">
<label for="toLanguage">{{ t('text', 'Target language') }}</label>
<NcSelect v-model="toLanguage"
input-id="toLanguage"
:options="toLanguages"
:disabled="!fromLanguage"
:append-to-body="false" />
</div>
<textarea v-model="result" readonly :class="{'icon-loading': loading }" />
<div class="translate-actions">
<NcLoadingIcon v-if="loading" />
<NcButton v-if="!result"
Expand Down Expand Up @@ -94,6 +111,7 @@ export default {
canDetect: loadState('text', 'translation_can_detect'),
loading: false,
error: null,
disableFromLanguageSelect: true,
}
},
computed: {
Expand Down Expand Up @@ -172,20 +190,71 @@ export default {
async contentReplace() {
this.$emit('replace-content', this.result)
},
autosize() {
this.$refs.input.style.overflowY = 'hidden'
this.$refs.input.style.height = 'auto'
const height = this.$refs.input.scrollHeight + 10
this.$refs.input.style.height = height + 'px'
this.$refs.result.style.height = height + 'px'
this.$refs.input.style.overflowY = 'auto'
},
onInputFocus() {
this.disableFromLanguageSelect = false
this.autosize()
},
},
}
</script>

<style lang="scss" scoped>
.translate-dialog {
margin: 24px;

.wrapper {
display: grid;
grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
grid-column-gap: 16px;
margin-top: calc(var(--default-grid-baseline) * 6);

.language-selector {
font-weight: bold;
flex-wrap: wrap;
gap: var(--default-grid-baseline);
}

.col {
grid-row: 1/2;
}
}
}

textarea {
display: block;
width: 100%;
margin-bottom: 12px;
height: auto;
resize: none;
box-sizing: border-box;
overflow-y: auto;
max-height: 60vh;
}

@media (max-width: 670px) {
.translate-dialog {
.wrapper {
display: block;
}

.language-selector {
.select {
width: 100%;
}
}
}

textarea {
max-height: 20vh;
}
}

.language-selector {
Expand Down

0 comments on commit a7bbf77

Please sign in to comment.