Skip to content

Commit

Permalink
コンポーネントのリファクタリングと新規コンポーネントの追加
Browse files Browse the repository at this point in the history
- App.vue内のヘッダー、入力、出力、文字数制限の部分をそれぞれのコンポーネントに分割
- 新しいコンポーネントを以下の通り追加:
  - Header.vue
  - TextInput.vue
  - TextOutput.vue
  - CharLimitInput.vue
  • Loading branch information
takanotume24 committed Dec 6, 2024
1 parent c82d708 commit 7001e41
Show file tree
Hide file tree
Showing 5 changed files with 146 additions and 56 deletions.
70 changes: 14 additions & 56 deletions src/App.vue
Original file line number Diff line number Diff line change
@@ -1,70 +1,29 @@
<template>
<div id="app">
<header>
<nav class="navbar navbar-expand-lg navbar-dark bg-dark">
<div class="container">
<a href="#" class="navbar-brand">📄📚 Paper Translation Helper 📚📄</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarNav"
aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarNav">
<ul class="navbar-nav mr-auto"></ul>
<ul class="navbar-nav">
<li class="nav-item">
<a class="nav-link"
href="https://github.com/takanotume24/paper-translation-helper/wiki/%E4%BD%BF%E3%81%84%E6%96%B9">使い方</a>
</li>
<li class="nav-item">
<a class="nav-link"
href="https://github.com/takanotume24/paper-translation-helper/issues">ご意見・ご要望</a>
</li>
<li class="nav-item">
<a class="nav-link"
href="https://github.com/takanotume24/paper-translation-helper/">Repository</a>
</li>
<li class="nav-item">
<a class="nav-link" href="https://github.com/takanotume24/">@takanotume24</a>
</li>
</ul>
</div>
</div>
</nav>
</header>

<Header />
<main class="container mt-4">
<div class="form-group">
<label for="original">Input / 入力</label>
<textarea id="original" class="form-control" v-model="originalText"
placeholder="Paste Here. / ここに貼り付けてください." rows="5"></textarea>
</div>
<div class="list-group mt-3">
<label class="list-group-item">Output / 出力</label>
<ul class="list-group">
<li v-for="(column, index) in outputColumns" :key="index" class="list-group-item">
<label :for="'text_area_' + index">
No.{{ index }}, Number of characters: {{ column.join("").length }}
</label>
<textarea class="form-control" :id="'text_area_' + index" readonly>{{ column.join("\n") }}</textarea>
</li>
</ul>
</div>
<div class="input-group mb-3 mt-3">
<div class="input-group-prepend">
<span class="input-group-text">Character limit / 文字数制限</span>
</div>
<input type="number" min="1000" class="form-control" v-model.number="charLimit"
placeholder="More than 1000 / 1000以上を入力してください">
</div>
<TextInput v-model="originalText" />
<TextOutput :outputColumns="outputColumns" />
<CharLimitInput v-model.number="charLimit" />
</main>
</div>
</template>

<script lang="ts">
import { defineComponent } from 'vue';
import Header from './components/Header.vue';
import TextInput from './components/TextInput.vue';
import TextOutput from './components/TextOutput.vue';
import CharLimitInput from './components/CharLimitInput.vue';
import { formatAndSplitTextIntoColumns } from './lib/format_and_split_text_into_columns';
export default defineComponent({
components: {
Header,
TextInput,
TextOutput,
CharLimitInput,
},
data() {
return {
originalText: '',
Expand All @@ -74,7 +33,6 @@ export default defineComponent({
computed: {
outputColumns(): string[][] {
if (!this.originalText) return [];
return formatAndSplitTextIntoColumns(this.originalText, this.charLimit);
}
}
Expand Down
34 changes: 34 additions & 0 deletions src/components/CharLimitInput.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<template>
<div class="input-group mb-3 mt-3">
<div class="input-group-prepend">
<span class="input-group-text">Character limit / 文字数制限</span>
</div>
<input type="number" min="1000" class="form-control" v-model="localLimit"
placeholder="More than 1000 / 1000以上を入力してください" />
</div>
</template>

<script lang="ts">
import { defineComponent, ref, watch } from 'vue';
export default defineComponent({
name: 'CharLimitInput',
props: {
modelValue: {
type: Number,
default: 4500
}
},
setup(props, { emit }) {
const localLimit = ref(props.modelValue);
watch(localLimit, (newValue) => {
emit('update:modelValue', newValue);
});
return {
localLimit
};
}
});
</script>
39 changes: 39 additions & 0 deletions src/components/Header.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<template>
<header>
<nav class="navbar navbar-expand-lg navbar-dark bg-dark">
<div class="container">
<a href="#" class="navbar-brand">📄📚 Paper Translation Helper 📚📄</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarNav"
aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarNav">
<ul class="navbar-nav mr-auto"></ul>
<ul class="navbar-nav">
<li class="nav-item">
<a class="nav-link"
href="https://github.com/takanotume24/paper-translation-helper/wiki/%E4%BD%BF%E3%81%84%E6%96%B9">使い方</a>
</li>
<li class="nav-item">
<a class="nav-link"
href="https://github.com/takanotume24/paper-translation-helper/issues">ご意見・ご要望</a>
</li>
<li class="nav-item">
<a class="nav-link"
href="https://github.com/takanotume24/paper-translation-helper/">Repository</a>
</li>
<li class="nav-item">
<a class="nav-link" href="https://github.com/takanotume24/">@takanotume24</a>
</li>
</ul>
</div>
</div>
</nav>
</header>
</template>

<script lang="ts">
export default {
name: 'Header'
};
</script>
32 changes: 32 additions & 0 deletions src/components/TextInput.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<template>
<div class="form-group">
<label for="original">Input / 入力</label>
<textarea id="original" class="form-control" v-model="localValue" placeholder="Paste Here. / ここに貼り付けてください."
rows="5"></textarea>
</div>
</template>

<script lang="ts">
import { defineComponent, ref, watch } from 'vue';
export default defineComponent({
name: 'TextInput',
props: {
modelValue: {
type: String,
default: ''
}
},
setup(props, { emit }) {
const localValue = ref(props.modelValue);
watch(localValue, (newValue) => {
emit('update:modelValue', newValue);
});
return {
localValue
};
}
});
</script>
27 changes: 27 additions & 0 deletions src/components/TextOutput.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<template>
<div class="list-group mt-3">
<label class="list-group-item">Output / 出力</label>
<ul class="list-group">
<li v-for="(column, index) in outputColumns" :key="index" class="list-group-item">
<label :for="'text_area_' + index">
No.{{ index }}, Number of characters: {{ column.join("").length }}
</label>
<textarea class="form-control" :id="'text_area_' + index" readonly>{{ column.join("\n") }}</textarea>
</li>
</ul>
</div>
</template>

<script lang="ts">
import { defineComponent } from 'vue';
export default defineComponent({
name: 'TextOutput',
props: {
outputColumns: {
type: Array as () => string[][],
default: () => []
}
}
});
</script>

0 comments on commit 7001e41

Please sign in to comment.