feat(input): Setting validation status and message. (#172)

* feat(input): Setting validation status and message.

* Update src/components/Input/composables/useInputClasses.ts

* Update docs/components/input/examples/InputValidationExample.vue

* Update docs/components/input/examples/InputValidationExample.vue

* Update docs/components/input.md

* Update docs/components/input.md

---------

Co-authored-by: Ilya Artamonov <ilya.sosidka@gmail.com>
This commit is contained in:
Nguyễn Hồng Quân
2023-09-09 00:07:48 +07:00
committed by GitHub
parent df27de24d6
commit 580bf14504
9 changed files with 82 additions and 12 deletions

View File

@@ -6,6 +6,7 @@ import InputHelperExample from './input/examples/InputHelperExample.vue';
import InputPrefixExample from './input/examples/InputPrefixExample.vue';
import InputSuffixExample from './input/examples/InputSuffixExample.vue'
import InputRequiredExample from './input/examples/InputRequiredExample.vue'
import InputValidationExample from './input/examples/InputValidationExample.vue'
</script>
# Vue Input - Flowbite
@@ -124,3 +125,24 @@ import { Input, Button } from 'flowbite-vue'
```
<InputSuffixExample />
## Slot - Validation
- Set validation status via `validationStatus` props, which accepts `'success'` or `'error'`.
- Add validation message via `validationMessage` slot.
```vue
<script setup>
import { Input } from 'flowbite-vue'
</script>
<template>
<Input v-model='email' required placeholder="enter your email address" label="Email" validation-status='success' />
<Input v-model='email' required placeholder="enter your email address" label="Email" validation-status='error'>
<template #validationMessage>
Please enter a valid email address
</template>
</Input>
</template>
```
<InputValidationExample />

View File

@@ -1,6 +1,6 @@
<template>
<div class="vp-raw">
<Input placeholder="enter your first name" label="First name">
<Input v-model='name' placeholder="enter your first name" label="First name">
<template #helper>
Well never share your details. Read our <a href="#" class="font-medium text-blue-600 hover:underline dark:text-blue-500">Privacy Policy</a>.
</template>
@@ -8,5 +8,8 @@
</div>
</template>
<script lang="ts" setup>
import { ref } from 'vue'
import { Input } from '../../../../src/index'
const name = ref('')
</script>

View File

@@ -1,6 +1,6 @@
<template>
<div class="vp-raw">
<Input placeholder="enter your search query" label="Search">
<Input v-model='name' placeholder="enter your search query" label="Search">
<template #prefix>
<svg aria-hidden="true" class="w-5 h-5 text-gray-500 dark:text-gray-400" fill="none" stroke="currentColor" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M21 21l-6-6m2-5a7 7 0 11-14 0 7 7 0 0114 0z"></path></svg>
</template>
@@ -8,5 +8,8 @@
</div>
</template>
<script lang="ts" setup>
import { ref } from 'vue'
import { Input } from '../../../../src/index'
const name = ref('')
</script>

View File

@@ -1,10 +1,12 @@
<template>
<div class="vp-raw flex flex-col align-center gap-2 flex-wrap">
<Input size="sm" placeholder="enter your first name" label="Small" />
<Input size="md" placeholder="enter your last name" label="Medium" />
<Input size="lg" placeholder="enter your second name" label="Large" />
<Input v-model='name' size="sm" placeholder="enter your first name" label="Small" />
<Input v-model='name' size="md" placeholder="enter your last name" label="Medium" />
<Input v-model='name' size="lg" placeholder="enter your second name" label="Large" />
</div>
</template>
<script lang="ts" setup>
import { ref } from 'vue'
import { Input } from '../../../../src/index'
const name = ref('')
</script>

View File

@@ -1,6 +1,6 @@
<template>
<div class="vp-raw">
<Input size="lg" placeholder="enter your search query" label="Search">
<Input v-model='name' size="lg" placeholder="enter your search query" label="Search">
<template #prefix>
<svg aria-hidden="true" class="w-5 h-5 text-gray-500 dark:text-gray-400" fill="none" stroke="currentColor" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M21 21l-6-6m2-5a7 7 0 11-14 0 7 7 0 0114 0z"></path></svg>
</template>
@@ -11,5 +11,8 @@
</div>
</template>
<script lang="ts" setup>
import { ref } from 'vue'
import { Input, Button } from '../../../../src/index'
const name = ref('')
</script>

View File

@@ -0,0 +1,17 @@
<template>
<div class="vp-raw">
<Input v-model='email' required placeholder="enter your email address" label="Email" validation-status='success' />
<hr class='mt-4 border-0'>
<Input v-model='email' required placeholder="enter your email address" label="Email" validation-status='error'>
<template #validationMessage>
Please enter a valid email address
</template>
</Input>
</div>
</template>
<script lang="ts" setup>
import { ref } from 'vue'
import { Input } from '../../../../src/index'
const email = ref('')
</script>