2020-11-25 13:31:34 +01:00
|
|
|
<template>
|
2021-02-13 04:28:26 +01:00
|
|
|
<FormGroup class="_formItem">
|
|
|
|
<template #label><slot></slot></template>
|
|
|
|
<div class="rivhosbp _formItem" :class="{ tall, pre }">
|
|
|
|
<div class="input _formPanel">
|
|
|
|
<textarea ref="input" :class="{ code, _monospace: code }"
|
|
|
|
v-model="v"
|
|
|
|
:required="required"
|
|
|
|
:readonly="readonly"
|
|
|
|
:pattern="pattern"
|
|
|
|
:autocomplete="autocomplete"
|
|
|
|
:spellcheck="!code"
|
|
|
|
@input="onInput"
|
|
|
|
@focus="focused = true"
|
|
|
|
@blur="focused = false"
|
|
|
|
></textarea>
|
|
|
|
</div>
|
2020-11-25 13:31:34 +01:00
|
|
|
</div>
|
2021-02-13 04:28:26 +01:00
|
|
|
<template #caption><slot name="desc"></slot></template>
|
|
|
|
|
2021-04-20 16:22:59 +02:00
|
|
|
<FormButton v-if="manualSave && changed" @click="updated" primary><i class="fas fa-save"></i> {{ $ts.save }}</FormButton>
|
2021-02-13 04:28:26 +01:00
|
|
|
</FormGroup>
|
2020-11-25 13:31:34 +01:00
|
|
|
</template>
|
|
|
|
|
|
|
|
<script lang="ts">
|
2021-02-13 04:28:26 +01:00
|
|
|
import { defineComponent, ref, toRefs, watch } from 'vue';
|
2020-11-25 13:31:34 +01:00
|
|
|
import './form.scss';
|
2021-02-13 04:28:26 +01:00
|
|
|
import FormButton from './button.vue';
|
|
|
|
import FormGroup from './group.vue';
|
2020-11-25 13:31:34 +01:00
|
|
|
|
|
|
|
export default defineComponent({
|
2021-02-13 04:28:26 +01:00
|
|
|
components: {
|
|
|
|
FormGroup,
|
|
|
|
FormButton,
|
|
|
|
},
|
2020-11-25 13:31:34 +01:00
|
|
|
props: {
|
|
|
|
value: {
|
|
|
|
required: false
|
|
|
|
},
|
|
|
|
required: {
|
|
|
|
type: Boolean,
|
|
|
|
required: false
|
|
|
|
},
|
|
|
|
readonly: {
|
|
|
|
type: Boolean,
|
|
|
|
required: false
|
|
|
|
},
|
|
|
|
pattern: {
|
|
|
|
type: String,
|
|
|
|
required: false
|
|
|
|
},
|
|
|
|
autocomplete: {
|
|
|
|
type: String,
|
|
|
|
required: false
|
|
|
|
},
|
|
|
|
code: {
|
|
|
|
type: Boolean,
|
|
|
|
required: false
|
|
|
|
},
|
|
|
|
tall: {
|
|
|
|
type: Boolean,
|
|
|
|
required: false,
|
|
|
|
default: false
|
|
|
|
},
|
|
|
|
pre: {
|
|
|
|
type: Boolean,
|
|
|
|
required: false,
|
|
|
|
default: false
|
|
|
|
},
|
2021-02-13 04:28:26 +01:00
|
|
|
manualSave: {
|
|
|
|
type: Boolean,
|
2020-11-25 13:31:34 +01:00
|
|
|
required: false,
|
2021-02-13 04:28:26 +01:00
|
|
|
default: false
|
2020-11-25 13:31:34 +01:00
|
|
|
},
|
|
|
|
},
|
2021-02-13 04:28:26 +01:00
|
|
|
setup(props, context) {
|
|
|
|
const { value } = toRefs(props);
|
|
|
|
const v = ref(value.value);
|
|
|
|
const changed = ref(false);
|
|
|
|
const inputEl = ref(null);
|
|
|
|
const focus = () => inputEl.value.focus();
|
|
|
|
const onInput = (ev) => {
|
|
|
|
changed.value = true;
|
|
|
|
context.emit('change', ev);
|
|
|
|
};
|
|
|
|
|
|
|
|
const updated = () => {
|
|
|
|
changed.value = false;
|
|
|
|
context.emit('update:value', v.value);
|
|
|
|
};
|
|
|
|
|
|
|
|
watch(value, newValue => {
|
|
|
|
v.value = newValue;
|
|
|
|
});
|
|
|
|
|
|
|
|
watch(v, newValue => {
|
|
|
|
if (!props.manualSave) {
|
|
|
|
updated();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2020-11-25 13:31:34 +01:00
|
|
|
return {
|
2021-02-13 04:28:26 +01:00
|
|
|
v,
|
|
|
|
updated,
|
|
|
|
changed,
|
|
|
|
focus,
|
|
|
|
onInput,
|
|
|
|
};
|
2020-11-25 13:31:34 +01:00
|
|
|
}
|
|
|
|
});
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style lang="scss" scoped>
|
|
|
|
.rivhosbp {
|
|
|
|
position: relative;
|
|
|
|
|
|
|
|
> .input {
|
|
|
|
position: relative;
|
|
|
|
|
|
|
|
> textarea {
|
|
|
|
display: block;
|
|
|
|
width: 100%;
|
|
|
|
min-width: 100%;
|
|
|
|
max-width: 100%;
|
|
|
|
min-height: 130px;
|
|
|
|
margin: 0;
|
|
|
|
padding: 16px;
|
|
|
|
box-sizing: border-box;
|
|
|
|
font: inherit;
|
|
|
|
font-weight: normal;
|
|
|
|
font-size: 1em;
|
|
|
|
background: transparent;
|
|
|
|
border: none;
|
|
|
|
border-radius: 0;
|
|
|
|
outline: none;
|
|
|
|
box-shadow: none;
|
|
|
|
color: var(--fg);
|
|
|
|
|
|
|
|
&.code {
|
|
|
|
tab-size: 2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
&.tall {
|
|
|
|
> .input {
|
|
|
|
> textarea {
|
|
|
|
min-height: 200px;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
&.pre {
|
|
|
|
> .input {
|
|
|
|
> textarea {
|
|
|
|
white-space: pre;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</style>
|