11<template >
22 <div >
33 <label class =" sr-only" >{{ label }}</label >
4- <template v-if =" type === ' textarea' " >
4+ <div class =" mt-1 flex rounded-md shadow-sm" >
5+ <span v-if =" prepend"
6+ class =" inline-flex items-center px-3 rounded-l-md border border-r-0 border-gray-300 bg-gray-50 text-gray-500 text-sm" >
7+ {{ prepend }}
8+ </span >
9+ <template v-if =" type === ' textarea' " >
510 <textarea :name =" name"
611 :required =" required"
712 :value =" props.modelValue"
813 @input =" emit('update:modelValue', $event.target.value)"
9- class =" block w-full px-3 py-2 border border-gray-300 placeholder-gray-500 text-gray-900 rounded-md focus:outline-none focus:ring-indigo-500 focus:border-indigo-500 focus:z-10 sm:text-sm "
14+ : class =" inputClasses "
1015 :placeholder =" label" ></textarea >
11- </template >
12- <template v-else-if =" type === ' file' " >
13- <input :type =" type"
14- :name =" name"
15- :required =" required"
16- :value =" props.modelValue"
17- @input =" emit('change', $event.target.files[0])"
18- class =" block w-full px-3 py-2 border border-gray-300 placeholder-gray-500 text-gray-900 rounded-md focus:outline-none focus:ring-indigo-500 focus:border-indigo-500 focus:z-10 sm:text-sm"
19- :placeholder =" label" />
20- </template >
21- <template v-else >
22- <input :type =" type"
23- :name =" name"
24- :required =" required"
25- :value =" props.modelValue"
26- @input =" emit('update:modelValue', $event.target.value)"
27- class =" block w-full px-3 py-2 border border-gray-300 placeholder-gray-500 text-gray-900 rounded-md focus:outline-none focus:ring-indigo-500 focus:border-indigo-500 focus:z-10 sm:text-sm"
28- :placeholder =" label"
29- step =" 0.01" />
30- </template >
16+ </template >
17+ <template v-else-if =" type === ' file' " >
18+ <input :type =" type"
19+ :name =" name"
20+ :required =" required"
21+ :value =" props.modelValue"
22+ @input =" emit('change', $event.target.files[0])"
23+ :class =" inputClasses"
24+ :placeholder =" label" />
25+ </template >
26+ <template v-else >
27+ <input :type =" type"
28+ :name =" name"
29+ :required =" required"
30+ :value =" props.modelValue"
31+ @input =" emit('update:modelValue', $event.target.value)"
32+ :class =" inputClasses"
33+ :placeholder =" label"
34+ step =" 0.01" />
35+ </template >
36+ <span v-if =" append"
37+ class =" inline-flex items-center px-3 rounded-r-md border border-l-0 border-gray-300 bg-gray-50 text-gray-500 text-sm" >
38+ {{ append }}
39+ </span >
40+ </div >
3141 </div >
3242</template >
3343
3444<script setup>
3545
46+ import {computed } from " vue" ;
47+
3648const props = defineProps ({
3749 modelValue: [String , Number , File ],
3850 label: String ,
@@ -41,7 +53,30 @@ const props = defineProps({
4153 default: ' text'
4254 },
4355 name: String ,
44- required: Boolean
56+ required: Boolean ,
57+ prepend: {
58+ type: String ,
59+ default: ' '
60+ },
61+ append: {
62+ type: String ,
63+ default: ' '
64+ }
65+ })
66+
67+ const inputClasses = computed (() => {
68+ const cls = [
69+ ` block w-full px-3 py-2 border border-gray-300 placeholder-gray-500 text-gray-900 focus:outline-none focus:ring-indigo-500 focus:border-indigo-500 focus:z-10 sm:text-sm` ,
70+ ];
71+
72+ if (props .append && ! props .prepend ) {
73+ cls .push (` rounded-l-md` )
74+ } else if (props .prepend && ! props .append ) {
75+ cls .push (` rounded-r-md` )
76+ } else if (! props .prepend && ! props .append ) {
77+ cls .push (' rounded-md' )
78+ }
79+ return cls .join (' ' )
4580})
4681
4782const emit = defineEmits ([' update:modelValue' , ' change' ])
0 commit comments