FitTrackee/fittrackee_client/src/components/Common/CustomTextArea.vue

58 lines
1.1 KiB
Vue
Raw Normal View History

2021-09-28 12:39:12 +02:00
<template>
<div class="custom-textarea">
<textarea
:id="name"
:name="name"
2023-02-16 10:06:54 +01:00
:maxLength="charLimit"
2021-09-29 11:32:05 +02:00
:disabled="disabled"
2021-09-28 12:39:12 +02:00
v-model="text"
@input="updateText"
/>
<div class="remaining-chars">
2021-10-20 17:38:25 +02:00
{{ $t('workouts.REMAINING_CHARS') }}: {{ text.length }}/{{ charLimit }}
2021-09-28 12:39:12 +02:00
</div>
</div>
</template>
<script setup lang="ts">
import { ref, watch, withDefaults } from 'vue'
2021-09-28 12:39:12 +02:00
interface Props {
name: string
charLimit?: number
disabled?: boolean
input?: string | null
}
const props = withDefaults(defineProps<Props>(), {
charLimit: 500,
disabled: false,
input: '',
})
2021-09-28 12:39:12 +02:00
const emit = defineEmits(['updateValue'])
2021-09-28 12:39:12 +02:00
2022-06-22 17:53:59 +02:00
const text = ref('')
2021-09-28 12:39:12 +02:00
function updateText(event: Event & { target: HTMLInputElement }) {
emit('updateValue', event.target.value)
}
watch(
() => props.input,
(value) => {
text.value = value === null ? '' : value
}
)
2021-09-28 12:39:12 +02:00
</script>
<style lang="scss" scoped>
.custom-textarea {
display: flex;
flex-direction: column;
.remaining-chars {
font-size: 0.8em;
font-style: italic;
}
}
</style>