Mod text component
continuous-integration/drone/push Build is passing Details

This commit is contained in:
philipp lang 2024-06-28 11:49:47 +02:00
parent b6c9eea8ea
commit 1ef8cfdec8
1 changed files with 74 additions and 113 deletions

View File

@ -14,11 +14,10 @@
:min="min" :min="min"
:max="max" :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" 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" @input="onInput"
@change="onChange" @change="onChange"
@focus="onFocus" @focus="focus = true"
@blur="onBlur" @blur="focus = false"
/> />
<div v-if="hint" class="h-full items-center flex absolute top-0 right-0"> <div v-if="hint" class="h-full items-center flex absolute top-0 right-0">
<div v-tooltip="hint"> <div v-tooltip="hint">
@ -29,8 +28,11 @@
</label> </label>
</template> </template>
<script> <script setup>
import wNumb from 'wnumb'; import wNumb from 'wnumb';
import {ref, computed} from 'vue';
const emit = defineEmits(['update:modelValue']);
var numb = { var numb = {
natural: wNumb({ natural: wNumb({
@ -89,117 +91,76 @@ var transformers = {
}, },
}; };
export default { const props = defineProps({
props: {
default: {},
mode: { mode: {
default: function () { type: String,
return 'none'; default: () => 'none',
},
}, },
required: { required: {
type: Boolean, type: Boolean,
default: false, default: () => false,
},
inset: {
default: function () {
return null;
},
}, },
size: { size: {
default: function () { type: String,
return 'base'; default: () => 'base',
},
}, },
id: { id: {
type: String,
required: true, required: true,
}, },
hint: { hint: {
default: null, type: String,
default: () => '',
}, },
modelValue: {}, modelValue: {
mask: { type: String,
default: undefined, default: () => '',
}, },
label: { label: {
default: false, type: String,
default: () => '',
}, },
type: { type: {
required: false, type: String,
default: function () { default: () => 'text',
return 'text';
},
}, },
disabled: { disabled: {
default: false, default: () => false,
type: Boolean, type: Boolean,
}, },
min: { min: {
default: () => '', type: Number,
default: () => undefined,
}, },
max: { max: {
default: () => '', type: Number,
default: () => undefined,
}, },
name: {}, name: {
required: true,
type: String,
}, },
data: function () { });
return {
focus: false, const focus = ref(false);
sizes: { const sizes = ref({
sm: 'field-sm', sm: 'field-sm',
base: 'field-base', base: 'field-base',
lg: 'field-lg', lg: 'field-lg',
}, });
};
},
computed: {
transformedValue: {
get() {
return transformers[this.mode][this.focus ? 'edit' : 'display'].to(this.modelValue);
},
set(v) {
this.$emit('update:modelValue', transformers[this.mode][this.focus ? 'edit' : 'display'].from(v));
},
},
insetClass() {
if (this.inset === '') {
return 'bg-inset';
}
if (this.inset === undefined) {
return null;
}
return `bg-${this.inset}`; const transformedValue = computed({
}, get: () => transformers[props.mode][focus.value ? 'edit' : 'display'].to(props.modelValue),
}, set: (v) => emit('update:modelValue', transformers[props.mode][focus.value ? 'edit' : 'display'].from(v)),
created() { });
if (typeof this.modelValue === 'undefined') { function onChange(v) {
this.$emit('update:modelValue', this.default === undefined ? '' : this.default); if (props.mode !== 'none') {
transformedValue.value = v.target.value;
} }
},
methods: {
onFocus() {
this.focus = true;
},
onBlur() {
this.focus = false;
},
onChange(v) {
if (this.mode !== 'none') {
this.transformedValue = v.target.value;
} }
}, function onInput(v) {
onInput(v) { if (props.mode === 'none') {
if (this.mode === 'none') { transformedValue.value = v.target.value;
this.transformedValue = v.target.value; }
} }
},
},
};
</script> </script>
<style scope>
.bg-inset {
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%);
}
</style>