Files
flowbite-vue/docs/components/input.md
Nguyễn Hồng Quân 580bf14504 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>
2023-09-08 20:07:48 +03:00

4.5 KiB
Raw Blame History

<script setup> import InputExample from './input/examples/InputExample.vue'; import InputSizeExample from './input/examples/InputSizeExample.vue'; import InputDisabledExample from './input/examples/InputDisabledExample.vue'; 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

Get started with a collection of input fields built with Tailwind CSS to start accepting data from the user based on multiple sizes, variants, and input types


:::tip Original reference: https://flowbite.com/docs/forms/input-field/ :::

The input field is an important part of the form element that can be used to create interactive controls to accept data from the user based on multiple input types, such as text, email, number, password, URL, phone number, and more.

On this page you will find all of the input types based on multiple variants, styles, colors, and sizes built with the utility classes from Tailwind CSS and components from Flowbite.

Default

<script setup>
import { Input } from 'flowbite-vue'
import { ref } from 'vue'

const name = ref('')
</script>
<template>
    <Input v-model="name" placeholder="enter your first name" label="First name" />
</template>

Size

<script setup>
import { Input } from 'flowbite-vue'
</script>
<template>
    <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" />
</template>

Disabled

<script setup>
import { Input } from 'flowbite-vue'
</script>
<template>
  <Input :disabled="true" placeholder="enter your first name" label="First name" />
</template>

Required

<script setup>
import { Input } from 'flowbite-vue'
</script>
<template>
  <Input required placeholder="enter your first name" label="First name" />
</template>

Slot - Helper

<script setup>
import { Input } from 'flowbite-vue'
</script>
<template>
  <Input 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>
  </Input>
</template>

Slot - Prefix

<script setup>
import { Input } from 'flowbite-vue'
</script>
<template>
  <Input placeholder="enter your first name" label="First name">
    <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>
  </Input>
</template>

Slot - Suffix

<script setup>
import { Input, Button } from 'flowbite-vue'
</script>
<template>
  <Input 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>
    <template #suffix>
      <Button>Search</Button>
    </template>
  </Input>
</template>

Slot - Validation

  • Set validation status via validationStatus props, which accepts 'success' or 'error'.
  • Add validation message via validationMessage slot.
<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>