it-tools/src/components/FormatTransformer.vue

57 lines
1.4 KiB
Vue
Raw Normal View History

2023-04-10 16:34:10 +02:00
<template>
<c-input-text
ref="inputElement"
v-model:value="input"
:placeholder="inputPlaceholder"
:label="inputLabel"
multiline
autosize
rows="20"
raw-text
test-id="input"
:validation-rules="inputValidationRules"
/>
<div>
<div mb-5px>{{ outputLabel }}</div>
<textarea-copyable :value="output" :language="outputLanguage" :follow-height-of="inputElement?.inputWrapperRef" />
</div>
2023-04-10 16:34:10 +02:00
</template>
<script setup lang="ts">
import type { UseValidationRule } from '@/composable/validation';
2023-04-10 16:34:10 +02:00
import _ from 'lodash';
import CInputText from '@/ui/c-input-text/c-input-text.vue';
2023-04-10 16:34:10 +02:00
const props = withDefaults(
defineProps<{
transformer?: (v: string) => string;
inputValidationRules?: UseValidationRule<string>[];
inputLabel?: string;
inputPlaceholder?: string;
inputDefault?: string;
outputLabel?: string;
outputLanguage?: string;
}>(),
{
transformer: _.identity,
inputValidationRules: () => [],
inputLabel: 'Input',
inputDefault: '',
inputPlaceholder: 'Input...',
outputLabel: 'Output',
outputLanguage: '',
},
);
const { transformer, inputValidationRules, inputLabel, outputLabel, outputLanguage, inputPlaceholder, inputDefault } =
toRefs(props);
const inputElement = ref<typeof CInputText>();
2023-04-10 16:34:10 +02:00
const input = ref(inputDefault.value);
const output = computed(() => transformer.value(input.value));
</script>
<style scoped></style>