Skip to content

FormInput Component

The FormInput component is built with Vue 3 and provides a customizable input field with support for icons, prefixes, and various size variants. It's designed to be flexible and easy to integrate into your forms.

Basic Usage

Import and use FormInput in your Vue components as follows:

vue
<template>
  <FormInput v-model="input1" placeholder="Enter text..." />
</template>

<script setup>
import { FormInput } from '@robuust-digital/vue-components/core';
</script>

Props

The FormInput component accepts the following props:

PropTypeDefaultDescription
modelValueString, NumberundefinedThe input value
prefixIconObject, FunctionnullSpecifies an icon to display on the left side of the input. @heroicons/vue can be used, or you can import your own .svg files.
iconObject, FunctionnullSpecifies an icon to display on the right side of the input
rootClassString''Additional classes for the root div
sizeString'base'Input size variant ('sm' or 'base')

Slots

The FormInput component provides several slots for customization:

Input Slot

The input slot allows you to customize the input element:

Show code
vue
<template>
  <FormInput v-model="input2">
    <template #input="attrs">
      <input v-bind="attrs" placeholder="Custom input..." />
    </template>
  </FormInput>
</template>

Prefix Slot

You can add content before the input using the prefix slot:

Show code
vue
<template>
  <FormInput v-model="input3" root-class="w-fit" class="text-right" placeholder="0,00">
    <template #prefix>
      <span>€</span>
    </template>
  </FormInput>
</template>

Icon Slots

You can customize both left and right icons using the prefixIcon and icon slots:

Show code
vue
<template>
  <FormInput v-model="input3">
    <template #prefixIcon>
      <BeakerIcon />
    </template>
    <template #icon>
      <BeakerIcon />
    </template>
  </FormInput>
</template>

<script setup>
import { BeakerIcon } from '@heroicons/vue/16/solid';
</script>

Examples

Pre-filled Value

Show code
vue
<template>
  <FormInput v-model="input4" />
</template>

<script setup>
const input4 = ref('Default value');
</script>

With Left Icon

Show code
vue
<template>
  <FormInput :icon-left="BeakerIcon" placeholder="Search..." />
</template>

<script setup>
import { BeakerIcon } from '@heroicons/vue/16/solid';
</script>

Small Size Variant

Show code
vue
<template>
  <FormInput size="sm" placeholder="Small input..." />
</template>

CSS Customization ⚡️

To customize the input styles global

css
:root {
  /* Available variables */
  --rvc-input-border-radius: var(--rvc-base-border-radius);
  --rvc-input-border-width: var(--rvc-base-border-width);
  --rvc-input-border-color: var(--rvc-base-border-color);
  --rvc-input-font-size: var(--rvc-base-input-font-size);
  --rvc-input-font-weight: var(--rvc-base-input-font-weight);
  --rvc-input-box-shadow: var(--rvc-base-box-shadow);
  --rvc-input-color: var(--rvc-base-input-color);
  --rvc-input-bg-color: var(--rvc-base-input-bg-color);
  --rvc-input-icon-size: var(--rvc-base-input-icon-size);
  --rvc-input-icon-color: var(--rvc-base-input-icon-color);
  --rvc-input-padding-x: var(--rvc-base-input-padding-x);
  --rvc-input-height: var(--rvc-base-input-height);
  --rvc-input-placeholder-color: var(--rvc-base-input-placeholder-color);

  /* Small variant */
  --rvc-input-font-size-sm: calc(var(--rvc-base-input-font-size) * 0.9);
  --rvc-input-padding-x-sm: calc(var(--rvc-base-input-padding-x) * 0.85);
  --rvc-input-icon-size-sm: calc(var(--rvc-base-input-icon-size) * 0.85);
  --rvc-input-height-sm: 1.875rem;
}