2021-04-10 19:45:11 +02:00
|
|
|
<template>
|
2024-06-28 10:23:42 +02:00
|
|
|
<label class="flex flex-col group" :for="id" :class="sizes[size]">
|
|
|
|
<span v-if="label" class="font-semibold leading-none text-gray-400 group-[.field-base]:text-sm group-[.field-sm]:text-xs">
|
2021-08-22 16:15:16 +02:00
|
|
|
{{ label }}
|
|
|
|
<span v-show="required" class="text-red-800"> *</span>
|
|
|
|
</span>
|
2024-06-28 10:23:42 +02:00
|
|
|
<div class="relative flex-none flex">
|
|
|
|
<input
|
|
|
|
:name="name"
|
|
|
|
:type="type"
|
|
|
|
:value="transformedValue"
|
|
|
|
:disabled="disabled"
|
|
|
|
placeholder=""
|
|
|
|
:min="min"
|
|
|
|
:max="max"
|
|
|
|
class="group-[.field-base]:h-[35px] group-[.field-sm]:h-[23px] group-[.field-base]:border-2 group-[.field-sm]:border border-gray-600 border-solid text-gray-300 bg-gray-700 leading-none rounded-lg group-[.field-base]:text-sm group-[.field-sm]:text-xs py-0 group-[.field-base]:px-2 group-[.field-sm]:px-1 w-full"
|
|
|
|
@keypress="$emit('keypress', $event)"
|
|
|
|
@input="onInput"
|
|
|
|
@change="onChange"
|
|
|
|
@focus="onFocus"
|
|
|
|
@blur="onBlur"
|
|
|
|
/>
|
|
|
|
<div v-if="hint" class="h-full items-center flex absolute top-0 right-0">
|
2021-08-22 16:15:16 +02:00
|
|
|
<div v-tooltip="hint">
|
2024-06-28 10:23:42 +02:00
|
|
|
<ui-sprite src="info-button" class="text-primary-700"></ui-sprite>
|
2021-04-10 19:45:11 +02:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</label>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
|
|
|
import wNumb from 'wnumb';
|
|
|
|
|
|
|
|
var numb = {
|
|
|
|
natural: wNumb({
|
|
|
|
mark: '',
|
|
|
|
thousand: '',
|
|
|
|
decimals: 0,
|
2024-06-27 21:42:47 +02:00
|
|
|
decoder: (a) => a * 100,
|
|
|
|
encoder: (a) => a / 100,
|
2021-08-22 16:15:16 +02:00
|
|
|
}),
|
2021-04-10 19:45:11 +02:00
|
|
|
area: wNumb({
|
|
|
|
mark: ',',
|
|
|
|
thousand: '',
|
|
|
|
decimals: 2,
|
2024-06-27 21:42:47 +02:00
|
|
|
decoder: (a) => a * 100,
|
|
|
|
encoder: (a) => a / 100,
|
2022-08-11 23:19:52 +02:00
|
|
|
}),
|
2021-04-10 19:45:11 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
var transformers = {
|
|
|
|
none: {
|
|
|
|
display: {
|
2024-06-27 21:42:47 +02:00
|
|
|
to: (v) => v,
|
|
|
|
from: (v) => v,
|
2021-04-10 19:45:11 +02:00
|
|
|
},
|
|
|
|
edit: {
|
2024-06-27 21:42:47 +02:00
|
|
|
to: (v) => v,
|
|
|
|
from: (v) => v,
|
2022-08-11 23:19:52 +02:00
|
|
|
},
|
2021-04-10 19:45:11 +02:00
|
|
|
},
|
|
|
|
area: {
|
|
|
|
display: {
|
2024-06-27 21:42:47 +02:00
|
|
|
to: (v) => (v === null ? '' : numb.area.to(v)),
|
|
|
|
from: (v) => (v === '' ? null : numb.area.from(v)),
|
2021-04-10 19:45:11 +02:00
|
|
|
},
|
|
|
|
edit: {
|
|
|
|
to(v) {
|
2022-08-11 23:19:52 +02:00
|
|
|
if (v === null) {
|
|
|
|
return '';
|
|
|
|
}
|
|
|
|
if (Math.round(v / 100) * 100 === v) {
|
2024-06-27 21:42:47 +02:00
|
|
|
return numb.natural.to(v);
|
2022-08-11 23:19:52 +02:00
|
|
|
}
|
2024-06-27 21:42:47 +02:00
|
|
|
return numb.area.to(v);
|
2021-08-22 16:15:16 +02:00
|
|
|
},
|
|
|
|
from(v) {
|
2022-08-11 23:19:52 +02:00
|
|
|
if (v === '') {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
if (v.indexOf(',') === -1) {
|
2024-06-27 21:42:47 +02:00
|
|
|
return numb.natural.from(v);
|
2022-08-11 23:19:52 +02:00
|
|
|
}
|
2021-08-22 16:15:16 +02:00
|
|
|
|
2024-06-27 21:42:47 +02:00
|
|
|
return numb.area.from(v);
|
2022-08-11 23:19:52 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2021-04-10 19:45:11 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
export default {
|
|
|
|
props: {
|
|
|
|
default: {},
|
|
|
|
mode: {
|
2022-08-11 23:19:52 +02:00
|
|
|
default: function () {
|
|
|
|
return 'none';
|
|
|
|
},
|
2021-04-10 19:45:11 +02:00
|
|
|
},
|
|
|
|
required: {
|
|
|
|
type: Boolean,
|
2022-08-11 23:19:52 +02:00
|
|
|
default: false,
|
2021-04-10 19:45:11 +02:00
|
|
|
},
|
|
|
|
inset: {
|
2022-08-11 23:19:52 +02:00
|
|
|
default: function () {
|
2021-04-10 19:45:11 +02:00
|
|
|
return null;
|
2022-08-11 23:19:52 +02:00
|
|
|
},
|
2021-04-10 19:45:11 +02:00
|
|
|
},
|
|
|
|
size: {
|
2022-08-11 23:19:52 +02:00
|
|
|
default: function () {
|
2021-08-22 16:15:16 +02:00
|
|
|
return 'base';
|
2022-08-11 23:19:52 +02:00
|
|
|
},
|
2021-04-10 19:45:11 +02:00
|
|
|
},
|
|
|
|
id: {
|
2022-08-11 23:19:52 +02:00
|
|
|
required: true,
|
2021-04-10 19:45:11 +02:00
|
|
|
},
|
|
|
|
hint: {
|
2022-08-11 23:19:52 +02:00
|
|
|
default: null,
|
2021-04-10 19:45:11 +02:00
|
|
|
},
|
2023-07-06 13:56:19 +02:00
|
|
|
modelValue: {},
|
2021-04-10 19:45:11 +02:00
|
|
|
mask: {
|
2022-08-11 23:19:52 +02:00
|
|
|
default: undefined,
|
2021-04-10 19:45:11 +02:00
|
|
|
},
|
|
|
|
label: {
|
2022-08-11 23:19:52 +02:00
|
|
|
default: false,
|
2021-04-10 19:45:11 +02:00
|
|
|
},
|
|
|
|
type: {
|
|
|
|
required: false,
|
2022-08-11 23:19:52 +02:00
|
|
|
default: function () {
|
|
|
|
return 'text';
|
|
|
|
},
|
2021-04-10 19:45:11 +02:00
|
|
|
},
|
|
|
|
disabled: {
|
|
|
|
default: false,
|
2022-08-11 23:19:52 +02:00
|
|
|
type: Boolean,
|
2021-08-22 16:15:16 +02:00
|
|
|
},
|
2023-12-26 00:44:49 +01:00
|
|
|
min: {
|
|
|
|
default: () => '',
|
|
|
|
},
|
|
|
|
max: {
|
|
|
|
default: () => '',
|
|
|
|
},
|
2021-08-22 16:15:16 +02:00
|
|
|
name: {},
|
2021-04-10 19:45:11 +02:00
|
|
|
},
|
2023-12-30 22:21:08 +01:00
|
|
|
data: function () {
|
|
|
|
return {
|
|
|
|
focus: false,
|
|
|
|
sizes: {
|
2024-06-28 10:23:42 +02:00
|
|
|
sm: 'field-sm',
|
|
|
|
base: 'field-base',
|
|
|
|
lg: 'field-lg',
|
2023-12-30 22:21:08 +01:00
|
|
|
},
|
|
|
|
};
|
2021-04-10 19:45:11 +02:00
|
|
|
},
|
|
|
|
computed: {
|
|
|
|
transformedValue: {
|
|
|
|
get() {
|
2023-07-06 13:56:19 +02:00
|
|
|
return transformers[this.mode][this.focus ? 'edit' : 'display'].to(this.modelValue);
|
2021-04-10 19:45:11 +02:00
|
|
|
},
|
|
|
|
set(v) {
|
2023-07-06 13:56:19 +02:00
|
|
|
this.$emit('update:modelValue', transformers[this.mode][this.focus ? 'edit' : 'display'].from(v));
|
2022-08-11 23:19:52 +02:00
|
|
|
},
|
2021-04-10 19:45:11 +02:00
|
|
|
},
|
|
|
|
insetClass() {
|
2022-08-11 23:19:52 +02:00
|
|
|
if (this.inset === '') {
|
|
|
|
return 'bg-inset';
|
|
|
|
}
|
|
|
|
if (this.inset === undefined) {
|
|
|
|
return null;
|
|
|
|
}
|
2021-04-10 19:45:11 +02:00
|
|
|
|
|
|
|
return `bg-${this.inset}`;
|
2022-08-11 23:19:52 +02:00
|
|
|
},
|
2021-04-10 19:45:11 +02:00
|
|
|
},
|
|
|
|
created() {
|
2023-07-06 13:56:19 +02:00
|
|
|
if (typeof this.modelValue === 'undefined') {
|
2023-12-26 00:44:49 +01:00
|
|
|
this.$emit('update:modelValue', this.default === undefined ? '' : this.default);
|
2021-04-10 19:45:11 +02:00
|
|
|
}
|
2022-08-11 23:19:52 +02:00
|
|
|
},
|
2023-12-30 22:21:08 +01:00
|
|
|
methods: {
|
|
|
|
onFocus() {
|
|
|
|
this.focus = true;
|
|
|
|
},
|
|
|
|
onBlur() {
|
|
|
|
this.focus = false;
|
|
|
|
},
|
|
|
|
onChange(v) {
|
|
|
|
if (this.mode !== 'none') {
|
|
|
|
this.transformedValue = v.target.value;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
onInput(v) {
|
|
|
|
if (this.mode === 'none') {
|
|
|
|
this.transformedValue = v.target.value;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
},
|
2021-04-10 19:45:11 +02:00
|
|
|
};
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style scope>
|
|
|
|
.bg-inset {
|
2023-05-08 15:11:16 +02:00
|
|
|
background: linear-gradient(to bottom, hsl(247.5, 66.7%, 97.6%) 0%, hsl(247.5, 66.7%, 97.6%) 41%, hsl(0deg 0% 100%) 41%, hsl(180deg 0% 100%) 100%);
|
2021-04-10 19:45:11 +02:00
|
|
|
}
|
|
|
|
</style>
|