97 lines
2.0 KiB
Vue
97 lines
2.0 KiB
Vue
<script setup lang="ts">
|
|
withDefaults(
|
|
defineProps<{
|
|
modelValue?: string | number
|
|
label?: string
|
|
type?: string
|
|
placeholder?: string
|
|
hint?: string
|
|
error?: string
|
|
disabled?: boolean
|
|
min?: number
|
|
max?: number
|
|
step?: number
|
|
maxlength?: number | string
|
|
inputmode?: 'none' | 'text' | 'decimal' | 'numeric' | 'tel' | 'search' | 'email' | 'url'
|
|
autocomplete?: string
|
|
dir?: string
|
|
align?: 'start' | 'center' | 'end'
|
|
}>(),
|
|
{
|
|
align: 'start',
|
|
},
|
|
)
|
|
|
|
defineEmits<{
|
|
'update:modelValue': [value: string]
|
|
blur: [event: FocusEvent]
|
|
}>()
|
|
</script>
|
|
|
|
<template>
|
|
<div class="form-group">
|
|
<label v-if="label" class="form-label">{{ label }}</label>
|
|
<input
|
|
class="input"
|
|
:class="[`input--align-${align}`, { 'input-error': error }]"
|
|
:type="type ?? 'text'"
|
|
:value="modelValue"
|
|
:placeholder="placeholder"
|
|
:disabled="disabled"
|
|
:min="min"
|
|
:max="max"
|
|
:step="step"
|
|
:maxlength="maxlength"
|
|
:inputmode="inputmode"
|
|
:autocomplete="autocomplete"
|
|
:dir="dir"
|
|
@input="$emit('update:modelValue', ($event.target as HTMLInputElement).value)"
|
|
@blur="$emit('blur', $event)"
|
|
/>
|
|
<p v-if="error" class="input-error-text">{{ error }}</p>
|
|
<p v-else-if="hint" class="form-hint">{{ hint }}</p>
|
|
</div>
|
|
</template>
|
|
|
|
<style scoped>
|
|
.input {
|
|
width: 100%;
|
|
height: var(--btn-height);
|
|
padding: 0 14px;
|
|
border: 1px solid var(--color-border);
|
|
border-radius: var(--radius-sm);
|
|
font-size: 0.9375rem;
|
|
background: var(--color-surface);
|
|
color: var(--color-text);
|
|
transition: border-color 0.15s;
|
|
}
|
|
|
|
.input--align-start {
|
|
text-align: start;
|
|
}
|
|
|
|
.input--align-center {
|
|
text-align: center;
|
|
letter-spacing: 0.04em;
|
|
}
|
|
|
|
.input--align-end {
|
|
text-align: end;
|
|
}
|
|
|
|
.input:focus {
|
|
outline: none;
|
|
border-color: var(--color-primary);
|
|
}
|
|
|
|
.input-error {
|
|
border-color: var(--color-danger);
|
|
}
|
|
|
|
.input-error-text {
|
|
color: var(--color-danger);
|
|
font-size: 0.8125rem;
|
|
margin: 4px 0 0;
|
|
}
|
|
</style>
|