2023-08-21 01:51:35 -04:00
|
|
|
<script setup lang="ts">
|
|
|
|
|
import { computed } from "vue";
|
|
|
|
|
import TooltippedLabel from "@/components/common/cv-tooltipped-label.vue";
|
|
|
|
|
|
|
|
|
|
const props = withDefaults(defineProps<{
|
|
|
|
|
label?: string,
|
|
|
|
|
tooltip?: string,
|
|
|
|
|
// TODO fully update v-model usage in custom components on Vue3 update
|
|
|
|
|
value: string,
|
|
|
|
|
disabled?: boolean,
|
|
|
|
|
errorMessage?: string,
|
|
|
|
|
placeholder?: string,
|
|
|
|
|
labelCols?: number,
|
|
|
|
|
inputCols?: number,
|
|
|
|
|
rules?: ((v: string) => boolean | string)[]
|
|
|
|
|
}>(), {
|
|
|
|
|
disabled: false,
|
|
|
|
|
inputCols: 8
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const emit = defineEmits<{
|
|
|
|
|
(e: "input", value: string): void
|
|
|
|
|
(e: "onEnter", value: string): void
|
|
|
|
|
(e: "onEscape"): void
|
|
|
|
|
}>();
|
|
|
|
|
|
|
|
|
|
const localValue = computed({
|
|
|
|
|
get: () => props.value,
|
|
|
|
|
set: v => emit("input", v)
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const handleKeydown = ({ key }) => {
|
|
|
|
|
switch (key) {
|
|
|
|
|
case "Enter":
|
|
|
|
|
if(!(props.rules || []).some(v => v(localValue.value) === false || typeof v(localValue.value) === "string")) {
|
|
|
|
|
emit("onEnter", localValue.value);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case "Escape":
|
|
|
|
|
emit("onEscape");
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
</script>
|
|
|
|
|
|
2019-09-28 21:42:04 +03:00
|
|
|
<template>
|
2020-06-26 04:39:14 -07:00
|
|
|
<div>
|
|
|
|
|
<v-row
|
|
|
|
|
dense
|
|
|
|
|
align="center"
|
|
|
|
|
>
|
2023-08-21 01:51:35 -04:00
|
|
|
<v-col :cols="labelCols || (12 - inputCols)">
|
2020-07-31 13:50:50 -07:00
|
|
|
<tooltipped-label
|
|
|
|
|
:tooltip="tooltip"
|
2023-08-21 01:51:35 -04:00
|
|
|
:label="label"
|
2020-07-31 13:50:50 -07:00
|
|
|
/>
|
2020-06-26 04:39:14 -07:00
|
|
|
</v-col>
|
2023-08-21 01:51:35 -04:00
|
|
|
|
|
|
|
|
<v-col :cols="inputCols">
|
2020-06-26 04:39:14 -07:00
|
|
|
<v-text-field
|
|
|
|
|
v-model="localValue"
|
|
|
|
|
dark
|
|
|
|
|
dense
|
2020-07-31 13:50:50 -07:00
|
|
|
color="accent"
|
2023-08-21 01:51:35 -04:00
|
|
|
:placeholder="placeholder"
|
2020-06-26 04:39:14 -07:00
|
|
|
:disabled="disabled"
|
|
|
|
|
:error-messages="errorMessage"
|
2020-07-31 13:50:50 -07:00
|
|
|
:rules="rules"
|
|
|
|
|
class="mt-1 pt-2"
|
2023-08-21 01:51:35 -04:00
|
|
|
@keydown="handleKeydown"
|
2020-06-26 04:39:14 -07:00
|
|
|
/>
|
|
|
|
|
</v-col>
|
|
|
|
|
</v-row>
|
|
|
|
|
</div>
|
2019-09-28 21:42:04 +03:00
|
|
|
</template>
|