1
1
<template >
2
2
<div >
3
3
<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' " >
5
10
<textarea :name =" name"
6
11
:required =" required"
7
12
:value =" props.modelValue"
8
13
@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 "
10
15
: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 >
31
41
</div >
32
42
</template >
33
43
34
44
<script setup>
35
45
46
+ import {computed } from " vue" ;
47
+
36
48
const props = defineProps ({
37
49
modelValue: [String , Number , File ],
38
50
label: String ,
@@ -41,7 +53,30 @@ const props = defineProps({
41
53
default: ' text'
42
54
},
43
55
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 (' ' )
45
80
})
46
81
47
82
const emit = defineEmits ([' update:modelValue' , ' change' ])
0 commit comments