3.0.1 • Published 6 months ago

@matatrek/vue3-form-inputs v3.0.1

Weekly downloads
-
License
MIT
Repository
github
Last release
6 months ago

@matatrek/vue3-form-inputs

A Vue plugin designed to simplify the creation of interactive and accessible forms. It includes built-in validations and supports translations (en, es).

Install

NPM

npm install @matatrek/vue3-form-inputs

Global Import

You can register the plugin globally in your Vue application as follows:

import { createApp } from 'vue'
import FormInputsPlugin from "@matatrek/vue3-form-inputs";

const app = createApp(App)
app.use(FormInputsPlugin, 
    {i18n} //optional
);
app.mount('#app')

Using i18n (Optional) The i18n parameter is optional. If your application uses an internationalization library like Vue I18n, you can pass the instance to the plugin so it takes advantage of the existing configuration.

If you don't use i18n, simply omit this parameter, and the plugin will work with the default texts.

Usage

<script setup lang="ts">
import { ref } from 'vue';
import { email, required  } from '@vuelidate/validators';

const form = ref({
  email: '',
  name: '',
});

const rules = {
  email: { required, email },
  name: { required },
};


const submitForm = (response: Boolean) => {
  //true is when there are no errors in the validations
  //false is when there are errors in the validations
};
</script>

<template>
  <form-container :form="form" :rules="rules" @submit="submitForm">
    <input-text 
      title="Email"
      validation="email"
      v-model="form.email"
      :type="'text'"
    />
    <input-text 
      title="Name"
      validation="name"
      v-model="form.name"
      :type="'text'"
    />
  </form-container>
</template>

Components

FormContainer

Props
PropsTypeDescriptionDefault
formobjectReactive object with form data (required){}
rulesobjectValidation rules compatible with Vuelidate{}
titleButtonstringSubmit button text. Rendered using i18n, if available"send"
iconButtoncomponentOptional icon component for the submit buttonnull
<!--wrapperFormstringOptional CSS classes to customize the form stylesnull-->
Slots
NameDescription
defaultForm content (inputs, selects, etc.)
Events
NameReturnDescription
submitbooleanWhen the form is submitted, it indicates whether it is valid (true) or not (false)
Methods

You can access the methods using ref in the component | Name | Parameters | Return | Description | |------|------------|--------|-------------| | validate | void | boolean | Validates the form and returns true if it is valid or false if there are errors. It also triggers the submit event. |

Customization with CSS classes
ClassDescripción
.mtk-formGeneral styles for the form
.mtk-form-buttonGeneral styles for the button
.mtk-form-button-iconGeneral styles for the button icon

InputText

Props
PropsTypeDescriptionDefault
modelValuestringThe value bound to the input""
titlestringLabel text for the input. Rendered using i18n, if available""
validationstringKey for the validation rule in Vuelidate.""
typestringInput type (e.g., "text", "password", "email")text
iconcomponentOptional icon component displayed inside the inputnull
disabledbooleanWhether the input is disabledfalse
readonlybooleanWhether the input is read-onlynull
placeholderstringlaceholder text. Rendered using i18n, if available"Enter field"
Slots
NameDescription
errorCustom error message slot
Events
NameReturnDescription
update:modelValuestringEmitted when the input value changes
Customization with CSS classes
ClassDescripción
.mtk-wrapperMain container for the input field
.mtk-labelLabel styling
.mtk-requiredtyle for the required * indicator
.mtk-disabledStyle for the (disabled) label
.mtk-readonlyStyle for the (read-only) label
.mtk-wrapper-inputWrapper around the input field
.mtk-inputDefault input field styling
.mtk-input-icon-rightPositions the right-side icon inside the input
.mtk-input-icon-passwordositions the password visibility toggle
.mtk-errorError message styling

License

@matatrek/vue3-form-inputs is open-sourced software licensed under the MIT license.