Skip to content

Commit ea6a124

Browse files
committed
Add reuseable form input field
1 parent 194096e commit ea6a124

File tree

2 files changed

+55
-49
lines changed

2 files changed

+55
-49
lines changed

src/components/contact/ContactForm.vue

+9-49
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<script>
22
import Button from '../reusable/Button.vue';
3-
export default { components: { Button } };
3+
import FormInput from '../reusable/FormInput.vue';
4+
export default { components: { Button, FormInput } };
45
</script>
56

67
<template>
@@ -14,54 +15,13 @@ export default { components: { Button } };
1415
Contact Form
1516
</p>
1617
<form action="#" class="font-general-regular space-y-7">
17-
<div>
18-
<label
19-
class="block text-lg text-primary-dark dark:text-primary-light mb-2"
20-
for="name"
21-
>Full Name</label
22-
>
23-
<input
24-
class="w-full px-5 py-2 border border-gray-300 dark:border-primary-dark border-opacity-50 text-primary-dark dark:text-secondary-light bg-ternary-light dark:bg-ternary-dark rounded-md shadow-sm text-md"
25-
id="name"
26-
name="name"
27-
type="text"
28-
required=""
29-
placeholder="Your Name"
30-
aria-label="Name"
31-
/>
32-
</div>
33-
<div>
34-
<label
35-
class="block text-lg text-primary-dark dark:text-primary-light mb-2"
36-
for="email"
37-
>Email</label
38-
>
39-
<input
40-
class="w-full px-5 py-2 border border-gray-300 dark:border-primary-dark border-opacity-50 text-primary-dark dark:text-secondary-light bg-ternary-light dark:bg-ternary-dark rounded-md shadow-sm text-md"
41-
id="email"
42-
name="email"
43-
type="text"
44-
required=""
45-
placeholder="Your Email"
46-
aria-label="Email"
47-
/>
48-
</div>
49-
<div>
50-
<label
51-
class="block text-lg text-primary-dark dark:text-primary-light mb-2"
52-
for="subject"
53-
>Subject</label
54-
>
55-
<input
56-
class="w-full px-5 py-2 border border-gray-300 dark:border-primary-dark border-opacity-50 text-primary-dark dark:text-secondary-light bg-ternary-light dark:bg-ternary-dark rounded-md shadow-sm text-md"
57-
id="subject"
58-
name="subject"
59-
type="text"
60-
required=""
61-
placeholder="Subject"
62-
aria-label="Subject"
63-
/>
64-
</div>
18+
<FormInput label="Full Name" inputIdentifier="name" />
19+
<FormInput
20+
label="Email"
21+
inputIdentifier="email"
22+
inputType="email"
23+
/>
24+
<FormInput label="Subject" inputIdentifier="subject" />
6525

6626
<div>
6727
<label

src/components/reusable/FormInput.vue

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<script>
2+
export default {
3+
props: {
4+
label: {
5+
type: String,
6+
default: '',
7+
},
8+
inputIdentifier: {
9+
type: String,
10+
default: '',
11+
},
12+
val: {
13+
type: [String, Number],
14+
default: '',
15+
},
16+
inputType: {
17+
type: String,
18+
default: 'text',
19+
},
20+
},
21+
};
22+
</script>
23+
24+
<template>
25+
<div>
26+
<label
27+
class="block mb-2 text-lg text-primary-dark dark:text-primary-light"
28+
:for="label"
29+
>{{ label }}</label
30+
>
31+
<input
32+
class="w-full px-5 py-3 border border-gray-300 dark:border-primary-dark border-opacity-50 text-primary-dark dark:text-secondary-light bg-ternary-light dark:bg-ternary-dark rounded-md shadow-sm text-md"
33+
:id="inputIdentifier"
34+
:name="inputIdentifier"
35+
:placeholder="label"
36+
:aria-label="inputIdentifier"
37+
required
38+
v-bind="$attrs"
39+
:value="val"
40+
@input="$emit('update:val', $event.target.value)"
41+
:type="inputType"
42+
/>
43+
</div>
44+
</template>
45+
46+
<style lang="scss" scoped></style>

0 commit comments

Comments
 (0)