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 20, 2023
1 parent 5c9f626 commit 8e0afc2
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 19 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
84 changes: 66 additions & 18 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', 'You can translate parts of the document by selecting the text before using the translate function.') }}</em>
<div class="wrapper">
<div class="col">
<div class="language-selector">
<label for="fromLanguage">{{ t('text', 'Source language') }}</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="true"
@input="autosize"
@focus="onInputFocus" />
</div>
<div class="col">
<div class="language-selector">
<label for="toLanguage">{{ t('text', 'Target language') }}</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,50 @@ export default {
async contentReplace() {
this.$emit('replace-content', this.result)
},
autosize() {
this.$refs.input.style.height = 'auto'
const height = this.$refs.input.scrollHeight
this.$refs.input.style.height = height + 'px'
this.$refs.result.style.height = height + 'px'
},
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: hidden;
}

.language-selector {
Expand Down

0 comments on commit 8e0afc2

Please sign in to comment.