-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #12 from HE-Arc/7-creating-button-and-input-form
7 creating button and input form
- Loading branch information
Showing
5 changed files
with
111 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
<script setup> | ||
import { ref, computed, defineProps, defineEmits } from 'vue'; | ||
const props = defineProps({ | ||
label: { | ||
type: String, | ||
required: true, | ||
}, | ||
hasLabel: { | ||
type: Boolean, | ||
default: true, | ||
required: false, | ||
}, | ||
value: { | ||
type: String, | ||
required: true, | ||
}, | ||
type: { | ||
type: String, | ||
default: 'text', | ||
required: false, | ||
}, | ||
required: { | ||
type: Boolean, | ||
default: false, | ||
required: false, | ||
}, | ||
}); | ||
const name = computed(() => props.label.toLowerCase()); | ||
const emit = defineEmits(['input', 'change']); | ||
// Peut ajouter la validation ici | ||
const onInput = (event) => { | ||
emit('input', event.target.value); | ||
}; | ||
const onChange = (event) => { | ||
emit('change', event.target.value); | ||
}; | ||
</script> | ||
|
||
<template> | ||
<div class="input-container"> | ||
<label v-if="hasLabel" :for="name">{{ label }}<span v-if="props.required">*</span></label> | ||
<input :type="type" :id="name" :name="name" :value="value" @input="onInput" @change="onChange" maxlength="250" :required="required"/> | ||
</div> | ||
</template> | ||
|
||
<style scoped> | ||
input | ||
{ | ||
display: block; | ||
width: 100%; | ||
padding: 0.5rem 1rem; | ||
border-radius: 2rem; | ||
border-color: var(--color-border); | ||
border-style: solid; | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,32 @@ | ||
<script setup> | ||
import CustomInput from '@/components/CustomInput.vue'; | ||
import { ref, computed } from 'vue'; | ||
const username = ref(''); | ||
const updateUsername = (value) => { | ||
username.value = value; | ||
}; | ||
const password = ref(''); | ||
const updatePassword = (value) => { | ||
password.value = value; | ||
}; | ||
const submitForm = () => { | ||
console.log('Form submitted'); | ||
// TODO call api | ||
}; | ||
</script> | ||
<template> | ||
<section class="login"> | ||
<h1>This is login page</h1> | ||
<form @submit.prevent="submitForm"> | ||
{{ username }} <!-- TODO debug purpose remove this line --> | ||
<CustomInput label="Username" :value="username" @input="updateUsername" required /> | ||
{{ password }} <!-- TODO debug purpose remove this line --> | ||
<CustomInput label="Password" type="password" :value="password" @input="updatePassword" required /> | ||
<button type="submit" class="btn">Submit</button> | ||
</form> | ||
</section> | ||
</template> |