ptitlutins/app/components/atoms/Input.vue
2025-09-27 04:05:48 +02:00

81 lines
1.4 KiB
Vue

<template>
<div class="input-wrapper">
<label v-if="label" :for="id">{{ label }}</label>
<component
class="input"
:is="type == 'textarea' ? 'textarea' : 'input'"
:id="id"
:type="type"
:value="modelValue"
@input="$emit('update:modelValue', $event.target.value)"
@blur="$emit('blur', $event)"
@focus="$emit('focus', $event)"
@change="$emit('change', $event)"
v-bind="$attrs"
/>
<p v-if="error" class="error-message">{{ error }}</p>
</div>
</template>
<script setup>
defineProps({
id: {
type: String,
required: true,
},
label: {
type: String,
default: "",
},
type: {
type: String,
default: "text",
},
modelValue: {
type: [String, Number],
default: "",
},
error: {
type: String,
default: "",
},
});
defineEmits(["update:modelValue", "blur", "focus", "change"]);
</script>
<style scoped>
.input-wrapper {
display: flex;
flex-direction: column;
gap: 0.5rem;
max-width: 100%;
}
.input-wrapper label {
font-weight: 500;
}
.input {
padding: 0.5rem;
border: 2px solid var(--neutral-30);
border-radius: 8px;
background-color: #f7f3f3;
font-size: 1rem;
width: 30rem;
max-width: 100%;
box-shadow: var(--shadow-1);
&:focus {
outline: none;
border-color: var(--primary-color);
box-shadow: var(--shadow-2);
}
}
.error-message {
color: #ff4444;
font-size: 0.875rem;
margin-top: 0.25rem;
}
</style>