1.0.6 • Published 10 months ago

@mythicaldev/md-vue3-forms v1.0.6

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

Vue3 Forms


Set of simple form components for Vue 3

Installation

npm install @mythicaldev/md-vue3-forms

OR

npm i @mythicaldev/md-vue3-forms

Tailwind configuration

You will need to update your tailwind.config.js file to include the following in your content array.

./node_modules/@mythicaldev/md-vue3-forms/**/*.vue

Components

Below is the list of components, their properties and examples of how to use them.

MDForm

(Required)

Every form is wrapped in this base MFForm component. This component provides a submit button, optional cancel button and assignable actions for those buttons. You next the form elements you need for your form within this base element.

<template>
  <MDForm class="my-5">Form at it's most basic level, only a submit button</MDForm>
  <MDForm class="mb-5" :showCancel="true">Form that includes a cancel button</MDForm>
  <MDForm class="mb-5" :showCancel="true" submitText="Add" cancelText="Back">
    Form that includes a cancel button and custom text for each button
  </MDForm>
  <MDForm
    class="mb-20"
    :showCancel="true"
    submitText="Add"
    cancelText="Back"
    @onSubmitClicked="submit"
    @onCancelClicked="cancel">
    Form that includes a cancel button, custom text and methods assigned to those buttons
  </MDForm>
</template>
<script setup>
  // Import the main form component
  import { MDForm } from '@mythicaldev/md-vue3-forms';

  const submit = () => {};
  const cancel = () => {};
</script>

Form Only

MDForm Props

PropTypeDefaultRequiredDescription
showCancelBooleanfalsefalseDisplay/Hide the cancel button
showSubmitBooleantruefalseDisplay/Hide the submit button
cancelTextStringCancelfalseText for the cancel button
submitTextStringSubmitfalseText for the cancel button

MDForm Emitted Events

EventDescription
onCancelClickedEmitted when the cancel button is clicked
onSubmitClickedEmitted when the submit button is clicked

MDGroup

Wrapper element to group related form fields in.

<template>
  <MDForm>
    <MDGroup>Add your form fields here.</MDGroup>
  </MDForm>
</template>
<script setup>
  // Import the base form component and the optional group component.
  import { MDForm, MDGroup } from '@mythicaldev/md-vue3-forms';
</script>

Group Example

MDText

This is a basic text input field.

<template>
  <MDForm :showCancel="true" submitText="Add" @onSubmitClicked="submit">
    <MDGroup>
      <!-- Bare bones basic text field -->
      <MDText class="mb-5" id="first_name" v-model="state.name.first" />
      <!-- Text field with a placeholder -->
      <MDText class="mb-5" id="last_name" placeholder="Last Name" v-model="state.name.last" />
      <!-- Secure field with a label and placeholder -->
      <MDText
        class="mb-5"
        type="password"
        id="password"
        label="Password"
        placeholder="******"
        v-model="state.password"
      />
      <!-- Required field with a label (Label is used as a placeholder by default) -->
      <MDText class="mb-5" type="email" id="email" label="Email" v-model="state.email" :required="true" />
      <!-- Required, Label, and error state. -->
      <MDText
        class="mb-5"
        id="nickname"
        label="Nick Name"
        v-model="state.nickname"
        :required="true"
        :error="state.errors.nickname"
      />
    </MDGroup>
  </MDForm>
</template>
<script setup>
  import { reactive } from 'vue';
  // Import the main form component, a group to wrap a set of fields in and the text field.
  import { MDForm, MDGroup, MDText } from '@mythicaldev/md-vue3-forms';

  const state = reactive({
    name: {
      first: '',
      last: '',
    },
    email: '',
    nickname: '',
    password: '',
    errors: {
      nickname: 'Nicknames are always required.',
    },
  });

  const submit = () => {
    console.log(state);
  };
</script>

Text Field Examples

MDText Props

PropTypeDefaultRequiredDescription
idStringtrueThe id of the field.
labelStringfalseThe label to add to the field. Empty by default providing no label.
typeStringtextfalseThe type of field to use. Defaults to a basic text field.
modelValueString, NumberfalseThe property to update. This should be passed as v-model when implementing
placeholderStringfalseThe placeholder to use for the field. Empty by default providing no placeholder.
describedByStringfalseThe aria-describedby value for the field.
helpStringfalseText that will display under the field to give help or context.
errorStringfalseError text to display under the field.
enabledBooleantruefalseDetermines if the field is enabled or not.
successBooleanfalsefalseStyle the field indicating success.
infoBooleanfalsefalseStyle the field for information feedback
warningBooleanfalsefalseStyle the field as warning, for example when there is an error displayed.
requiredBooleanfalsefalseDetermines if the field is required or not.

MDCheckbox

Simple checkbox. Can default to checked or not and emits a single event.

<template>
  <MDForm class="my-10">
    <MDGroup>
      <!-- Bare bones, checkbox only -->
      <MDCheckbox :isChecked="false" @selected="selected" />
      <!-- Include a label if desired -->
      <MDLabel id="check1" label="Unchecked" />
      <MDCheckbox :isChecked="false" @selected="selected" />
      <!-- Default to being checked -->
      <MDLabel id="check2" label="Checked" />
      <MDCheckbox :isChecked="true" @selected="selected" />
    </MDGroup>
  </MDForm>
</template>
<script setup>
  // Import the form, group, label and checkbox components.
  import { MDForm, MDGroup, MDCheckbox, MDLabel } from '@mythicaldev/md-vue3-forms';
  
  const selected = () => {};
</script>

Checkbox Examples

MDCheckbox Props

PropTypeDefaultRequiredDescription
isCheckedBooleanfalsefalseDetermines if the checkbox is checked or not.

MDCheckbox Emitted Events

EventDescription
selectedEmitted when the checkbox is checked or unchecked

MDDatePicker

Integrates the @vuepic/vue-datepicker package for a flexible datepicker field.

@vuepic/vue-datepicker

<template>
  <MDForm class="my-10">
    <MDGroup>
      <!-- Basic, bare bones -->
      <MDDatePicker id="date" v-model="state.start" />
      <!-- With the time picker enabled -->
      <MDDatePicker id="date" v-model="state.end" :enableTimePicker="true" />
    </MDGroup>
  </MDForm>
</template>
<script setup>
  import { reactive } from 'vue';
  // Import the form, group, label and checkbox components.
  import { MDForm, MDGroup, MDDatePicker } from '@mythicaldev/md-vue3-forms';

  const state = reactive({
    start: new Date(),
    end: new Date(),
  });
</script>

Basic, Bare bones

MDDatePicker Examples

With time picker enabled

MDDatePicker w/ timepicker 1 Examples MDDatePicker w/ timepicker 2 Examples

MDDatePicker Props

PropTypeDefaultRequiredDescription
idStringtrueThe id of the form field.
modelValueDatenew Date()trueThe property to update. This should be passed as v-model when implementing.
enableTimePickerBooleanfalsefalseDetermines if the time picker is enabled.
formatStringMM/dd/yyyyfalseThe format to apply to the date-time.
labelStringfalseThe label to add to the field. Empty by default providing no label.
describedByStringfalseThe aria-describedby value for the field.
helpStringfalseText that will display under the field to give help or context.
errorStringfalseError text to display under the field.
successBooleanfalsefalseStyle the field indicating success.
infoBooleanfalsefalseStyle the field for information feedback
warningBooleanfalsefalseStyle the field as warning, for example when there is an error displayed.
requiredBooleanfalsefalseDetermines if the field is required or not.

MDDraggablePicker

Integrates the sortableJS library to allow moving items from one list to another.

sortableJS

<template>
  <MDForm class="my-10">
    <MDGroup>
      <MDDraggablePicker 
        id="test"
        v-model="state.books"
        selectedLabel="Selected Items"
        availableLabel="Available Items"
      />
    </MDGroup>
  </MDForm>
</template>
<script setup>
  import { reactive } from 'vue';
  // Import the form, group and draggable components.
  import { MDForm, MDGroup, MDDraggablePicker } from '@mythicaldev/md-vue3-forms';
  
  const state = reactive({
    books: {
      available: [
        {
          id: 1,
          name: 'The Shining',
        },
        {
          id: 1,
          name: 'Pride and Prejudice',
        },
        {
          id: 1,
          name: '1984',
        },
        {
          id: 1,
          name: 'The Lord of the Rings',
        },
        {
          id: 1,
          name: 'The Old Man and the Sea',
        },
      ],
      selected: [],
    },
  });
</script>

Draggable Examples

MDDraggablePicker Props

PropTypeDefaultRequiredDescription
idBooleantrueThe id of the element.
availableLabelStringtrueLabel for the available column
selectedLabelStringtrueLabel for the selected column
modelValueObject{ available: [], selected: [] }trueThe property to update. This should be passed as v-model when implementing
labelStringfalseUsed to add a label.
errorStringfalseUsed to display an error to the lists.
requiredBooleanfalsefalseDetermines if the lists should be marked as required or not.

MDDraggablePicker Emitted Events

EventDescription
onUpdateEmitted when an item is dragged from one list to another.

MDDropZone

Simple dropzone for image uploads. Utilizes the vue3-dropzone and sweetalert2 libraries.

<template>
  <MDForm>
    <MDGroup>
      <MDDropZone id="images" v-model="state.images" @onDrop="imageAddedToDropzone" />
    </MDGroup>
  </MDForm>
</template>
<script setup>
  import { reactive } from 'vue';
  // Import the components
  import { MDForm, MDGroup, MDDropZone } from '@mythicaldev/md-vue3-forms';

  const state = reactive({
    images: [],
  });
  const imageAddedToDropzone = () => {};
</script>

Empty Dropzone

Dropzone 1

One Image Added

Dropzone 2

Deleting Image

Dropzone 3

MDDropZone Props

PropTypeDefaultRequiredDescription
idBooleantrueThe id of the element.
modelValueArray[]trueThe property to update. This should be passed as v-model when implementing.
labelStringfalseUsed to add a label.
requiredBooleanfalsefalseDetermines if the lists should be marked as required or not.
showPreviewBooleantruefalseShow the uploaded images below the dropzone.
helpTextStringDrag and drop some files here, or click to select filesfalseText to show in the dropzone.
hoverTextStringDrop the files here ...falseText to display when image is hovered over the dropzone.
showConfirmationBooleantruefalseDetermines if a confirmation is shown when removing an image.
confirmationConfigObjectsee configuration object belowfalseConfiguration to use in the Sweet Alert when deleting an image.
{
    title: '',
    text: 'Are you sure?',
    icon: 'warning',
    showCancel: true,
    button: {
    color: '#3085d6',
    text: 'OK',
}

MDDropZone Emitted Events

EventDescription
onDropEmitted when an an image is added to the dropzone.

MDSelect

Single select utilizing @headlessui/vue. YOu are able to filter the options by typing into the field or selected them using the dropdown directly.

<template>
  <MDForm>
    <MDGroup>
      <MDSelect label="Book Titles" id="book_titles" :options="selectOptions" v-model="state.selectedBook" />
    </MDGroup>
  </MDForm>
</template>
<script setup>
  import { reactive } from 'vue';
  // Import the components
  import { MDForm, MDGroup, MDSelect } from '@mythicaldev/md-vue3-forms';

  const selectOptions = [
    {
      value: '1',
      label: 'The Shining',
    },
    {
      value: '2',
      label: 'Pride and Prejudice',
    },
    {
      value: '3',
      label: '1984',
    },
    ...
  ];
  
  const state = reactive({
    selectedBook: '',
  });
</script>

Select 1 Select 2 Select 3

MDSelect Props

PropTypeDefaultRequiredDescription
idStringtrueThe id of the field.
optionsArray[]trueValues to display in the list. See the object below for formatting.
labelStringfalseThe label to add to the field. Empty by default providing no label.
typeStringtextfalseThe type of field to use. Defaults to a basic text field.
modelValueString, NumberfalseThe property to update. This should be passed as v-model when implementing
placeholderStringfalseThe placeholder to use for the field. Empty by default providing no placeholder.
describedByStringfalseThe aria-describedby value for the field.
helpStringfalseText that will display under the field to give help or context.
errorStringfalseError text to display under the field.
successBooleanfalsefalseStyle the field indicating success.
infoBooleanfalsefalseStyle the field for information feedback
warningBooleanfalsefalseStyle the field as warning, for example when there is an error displayed.
requiredBooleanfalsefalseDetermines if the field is required or not.

Format for options property.

[
  {
    label: '',
    value: '',
  },
];

MDTextArea

Text area with limit if needed.

<template>
  <MDForm class="my-10">
    <MDGroup>
      <MDTextArea label="Description 1" id="description1" v-model="state.description1" />
      <MDTextArea label="Description 2" id="description2" rows="5" v-model="state.description2" />
      <MDTextArea label="Description 3" id="description3" rows="8" v-model="state.description3" :hasLimit="true" />
      <MDTextArea label="Description 4" id="description4" rows="8" v-model="state.description4" :hasLimit="true" />
    </MDGroup>
  </MDForm>
</template>
<script setup>
  import { reactive } from 'vue';
  // Import the components
  import { MDForm, MDGroup, MDTextArea } from '@mythicaldev/md-vue3-forms';
  
  const state = reactive({
    description1: '',
    description2: '',
    description3: '',
    description4: '',
  });
</script>

Text Area Example

MDTextArea Props

PropTypeDefaultRequiredDescription
idStringtrueThe id of the field.
labelStringfalseThe label to add to the field. Empty by default providing no label.
typeStringtextfalseThe type of field to use. Defaults to a basic text field.
modelValueString, NumberfalseThe property to update. This should be passed as v-model when implementing
rowsString4falseThe number of rows for the textarea
hasLimitBooleanfalsefalseDetermines if the field should have a limit or not.
limitNumber255falseThe limit to impose on the textarea.
placeholderStringfalseThe placeholder to use for the field. Empty by default providing no placeholder.
describedByStringfalseThe aria-describedby value for the field.
helpStringfalseText that will display under the field to give help or context.
errorStringfalseError text to display under the field.
successBooleanfalsefalseStyle the field indicating success.
infoBooleanfalsefalseStyle the field for information feedback
warningBooleanfalsefalseStyle the field as warning, for example when there is an error displayed.
requiredBooleanfalsefalseDetermines if the field is required or not.

License

MIT