@uniquedj95/vform 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,140 @@
1
+ # vForm
2
+
3
+ ## Overview
4
+ vForm is a Vue.js component that dynamically generates forms based on a provided schema. It leverages Ionic components for a responsive and mobile-friendly design, supporting complex forms with conditional rendering and validation logic. It provides a robust and flexible form-building solution for Vue.js applications, allowing for a high degree of customization and control over the form behavior and appearance.
5
+
6
+ ## Features
7
+ - **Dynamic Form Generation**: Create forms dynamically based on a schema definition.
8
+ - **Conditional Field Rendering**: Fields can be shown or hidden based on other form values.
9
+ - **Responsive Grid Layout**: Utilizes Ionic Grid for a responsive design that works across different screen sizes.
10
+ - **Enhanced Date Input Field**: Custom date formatting and handling.
11
+ - **Customizable Form Fields**: Support for a variety of input types with customizable properties.
12
+ - **Built-in Validation**: Validate fields with custom or built-in validation functions.
13
+ - **Customizable Button Text**: Easily change the text of action buttons.
14
+
15
+ ## Installation
16
+ 1. Using NPM package manager
17
+ ```sh
18
+ npm install @uniquedj95/vform
19
+ ```
20
+ 2. Using YARN package manager
21
+ ```sh
22
+ yarn add @uniquedj95/vform
23
+ ```
24
+
25
+ ## Usage
26
+ 1. Register `VForm` component in your Vue.js application:
27
+ ```typescript
28
+ // src/main.ts
29
+ import { createApp, Plugin } from 'vue';
30
+ import App from './App.vue';
31
+ import router from './router';
32
+ import { IonicVue } from '@ionic/vue';
33
+ import { VForm } from '@uniquedj95/vform';
34
+
35
+ /* Import CSS styles and other components here */
36
+
37
+ const app = createApp(App)
38
+ .use(IonicVue)
39
+ .use(VForm as Plugin)
40
+ .use(router);
41
+
42
+ router.isReady().then(() => {
43
+ app.mount('#app');
44
+ });
45
+ ```
46
+
47
+ 2. Use the component in your template:
48
+ ```vue
49
+ <template>
50
+ <v-form :schema="formSchema" button-placement="end" @submit="onSubmit" />
51
+ </template>
52
+
53
+ <script setup lang="ts">
54
+ import { reactive } from "vue";
55
+ import { FormSchema, FormData, ComputedData } from "@uniquedj95/vform";
56
+
57
+ const formSchema = reactive<FormSchema>({
58
+ // Define your form schema here
59
+ fieldId: {
60
+ type: 'TextInput', // or other InputType
61
+ label: 'Field Label',
62
+ placeholder: 'Enter a value',
63
+ required: true,
64
+ // additional field configuration options
65
+ },
66
+ // Additional fields
67
+ });
68
+
69
+ function onSubmit(data: FormData, computedData: ComputedData) {
70
+ console.log(data, computedData);
71
+ }
72
+ </script>
73
+ ```
74
+
75
+ ## Schema Structure
76
+ The schema object should define the structure of the form. Each key in the schema represents a form field with its configuration:
77
+
78
+ ### Field Configuration Options
79
+ - **type** (`InputType`): Specifies the type of the input field. Supported types include:
80
+ - `TextInput`
81
+ - `DateInput`
82
+ - `NumberInput`
83
+ - `EmailInput`
84
+ - `PasswordInput`
85
+ - **label** (`string`): The label displayed for the form field.
86
+ - **placeholder** (`string`): Placeholder text for the input field.
87
+ - **required** (`boolean`): Determines if the field is required for form submission.
88
+ - **grid** (`GridSize`): Specifies the grid size for different screen sizes, allowing responsive design:
89
+ - `xs`, `sm`, `md`, `lg`, `xl`: Control the column size at various breakpoints.
90
+ - **validation** (`FormValidator`): A custom validation function that returns an array of error messages if any.
91
+ - The function signature is `(value: FormValue, schema?: FormSchema) => Promise<Array<string> | null> | Array<string> | null`.
92
+ - **condition** (`(data: FormData, computedData: ComputedData) => boolean`): A function to determine if the field should be rendered based on other form values.
93
+ - **computedValue** (`ComputedValueHandler`): A function to compute a value based on the current field value and schema, allowing dynamic updates.
94
+ - The function signature is `(value: FormValue, schema: FormSchema) => Promise<any> | any`.
95
+ - **options** (`FormOptions`): Used for select-type fields, providing options as an array or a function that returns a promise with the options.
96
+ - **multiple** (`boolean`): Allows multiple selections for fields with options.
97
+ - **min**/ **max** (`number | string`): Specifies minimum and maximum values for number inputs.
98
+ - **minLength**/ **maxLength** (`number`): Sets minimum and maximum length for text inputs.
99
+ - **disabled** (`boolean`): Disables the input field if set to `true`.
100
+ - **hidden** (`boolean`): Hides the field completely if set to `true`.
101
+ - **icon** (`string`): Icon to display within the input field.
102
+ - **prefix**/ **suffix** (`string`): Text to display before or after the input value.
103
+ - **error** (`string`): Custom error message for the field.
104
+ - **pattern** (`string`): Regular expression pattern for input validation.
105
+ - **allowUnknown**/ **allowCustom** (`boolean`): Allows unknown or custom values for the input.
106
+ - **autoFocus** (`boolean`): Automatically focuses the input field on form load.
107
+ - **fill** (`"solid" | "outline"`): Defines the fill style of the input field.
108
+ - **labelPlacement** (`"stacked" | "start" | "end" | "fixed" | "floating"`): Determines the position of the label relative to the input field.
109
+ - **onChange** (`(value: FormValue) => FormValue`): Function that is triggered when the field value changes, allowing for dynamic transformations.
110
+
111
+ ### Form Events
112
+ - **submit**: Emitted when the form is submitted successfully after passing validation.
113
+ - Signature: `(formData: FormData, computedFormData: ComputedData) => void`
114
+ - **clear**: Emitted when the form fields are cleared to their initial state.
115
+ - Signature: `() => void`
116
+ - **cancel**: Emitted when the form submission is canceled, resetting fields.
117
+ - Signature: `() => void`
118
+
119
+ ### Form Props
120
+ - **schema** (`FormSchema`): The schema object defining the form structure and field configurations.
121
+ - **showLabels** (`boolean`): Determines if labels are displayed for each field. Default is `true`.
122
+ - **showClearButton** (`boolean`): Controls the visibility of the clear/reset button. Default is `true`.
123
+ - **showCancelButton** (`boolean`): Controls the visibility of the cancel button. Default is `true`.
124
+ - **buttonPlacement** (`'start' | 'middle' | 'end'`): Specifies the alignment of action buttons within the form.
125
+ - **submitButtonText** (`string`): Custom text for the submit button. Default is `"Submit"`.
126
+ - **clearButtonText** (`string`): Custom text for the clear/reset button. Default is `"Reset"`.
127
+ - **cancelButtonText** (`string`): Custom text for the cancel button. Default is `"Cancel"`.
128
+
129
+ ## Issue Reporting and Feedback
130
+ If you encounter any issues or have suggestions for improvements, please feel free to report them on the [GitHub Issues page](https://github.com/uniquedj95/vform/issues). Your feedback is invaluable in helping us enhance this project.
131
+
132
+ ## Contributors
133
+ I welcome contributions from the community! If you'd like to contribute, please follow these steps:
134
+ 1. Fork the repository.
135
+ 2. Create a new branch for your feature or bug fix.
136
+ 3. Implement your changes and commit them to your branch.
137
+ 4. Submit a pull request detailing your changes.
138
+
139
+ Thank you to all the [contributors](https://github.com/uniquedj95/vform/graphs/contributors) who have helped make vForm better!
140
+
@@ -0,0 +1,22 @@
1
+ import { FormSchema, BaseFieldTypes } from 'types';
2
+ import { PropType } from 'vue';
3
+
4
+ declare const _default: import('vue').DefineComponent<{
5
+ modelValue: import('vue').PropType<any>;
6
+ schema: {
7
+ type: PropType<FormSchema>;
8
+ };
9
+ type: {
10
+ type: PropType<BaseFieldTypes>;
11
+ };
12
+ }, {}, unknown, {}, {}, import('vue').ComponentOptionsMixin, import('vue').ComponentOptionsMixin, {}, string, import('vue').PublicProps, Readonly<import('vue').ExtractPropTypes<{
13
+ modelValue: import('vue').PropType<any>;
14
+ schema: {
15
+ type: PropType<FormSchema>;
16
+ };
17
+ type: {
18
+ type: PropType<BaseFieldTypes>;
19
+ };
20
+ }>>, {}, {}>;
21
+ export default _default;
22
+ //# sourceMappingURL=BaseInput.vue.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"BaseInput.vue.d.ts","sourceRoot":"","sources":["../../../src/components/inputs/BaseInput.vue"],"names":[],"mappings":"AA4BA;AAGE,OAAO,EAAa,UAAU,EAAE,cAAc,EAAE,MAAM,OAAO,CAAC;AAC9D,OAAO,EAAE,QAAQ,EAAO,MAAM,KAAK,CAAC;;gBAiD1B,OAAO,KAAK,EAAE,QAAQ,CAAC,GAAG,CAAC;;;;;;;;gBAA3B,OAAO,KAAK,EAAE,QAAQ,CAAC,GAAG,CAAC;;;;;;;;AAqGvC,wBASG"}
@@ -0,0 +1,16 @@
1
+ import { FormSchema } from '../../types';
2
+ import { PropType } from 'vue';
3
+
4
+ declare const _default: import('vue').DefineComponent<{
5
+ modelValue: import('vue').PropType<any>;
6
+ schema: {
7
+ type: PropType<FormSchema>;
8
+ };
9
+ }, {}, unknown, {}, {}, import('vue').ComponentOptionsMixin, import('vue').ComponentOptionsMixin, {}, string, import('vue').PublicProps, Readonly<import('vue').ExtractPropTypes<{
10
+ modelValue: import('vue').PropType<any>;
11
+ schema: {
12
+ type: PropType<FormSchema>;
13
+ };
14
+ }>>, {}, {}>;
15
+ export default _default;
16
+ //# sourceMappingURL=DateInput.vue.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"DateInput.vue.d.ts","sourceRoot":"","sources":["../../../src/components/inputs/DateInput.vue"],"names":[],"mappings":"AA6DA;AAKA,OAAO,KAAK,EAAa,UAAU,EAAE,MAAM,aAAa,CAAC;AACzD,OAAO,EAAuB,QAAQ,EAAO,MAAM,KAAK,CAAC;;gBAgG7C,OAAO,KAAK,EAAE,QAAQ,CAAC,GAAG,CAAC;;;;;gBAA3B,OAAO,KAAK,EAAE,QAAQ,CAAC,GAAG,CAAC;;;;;AAgPvC,wBASG"}
@@ -0,0 +1,16 @@
1
+ import { FormSchema } from 'types';
2
+ import { PropType } from 'vue';
3
+
4
+ declare const _default: import('vue').DefineComponent<{
5
+ modelValue: import('vue').PropType<any>;
6
+ schema: {
7
+ type: PropType<FormSchema>;
8
+ };
9
+ }, {}, unknown, {}, {}, import('vue').ComponentOptionsMixin, import('vue').ComponentOptionsMixin, {}, string, import('vue').PublicProps, Readonly<import('vue').ExtractPropTypes<{
10
+ modelValue: import('vue').PropType<any>;
11
+ schema: {
12
+ type: PropType<FormSchema>;
13
+ };
14
+ }>>, {}, {}>;
15
+ export default _default;
16
+ //# sourceMappingURL=EmailInput.vue.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"EmailInput.vue.d.ts","sourceRoot":"","sources":["../../../src/components/inputs/EmailInput.vue"],"names":[],"mappings":"AAOA;AAEA,OAAO,EAAa,UAAU,EAAE,MAAM,OAAO,CAAC;AAC9C,OAAO,EAAE,QAAQ,EAAE,MAAM,KAAK,CAAC;;gBAQnB,OAAO,KAAK,EAAE,QAAQ,CAAC,GAAG,CAAC;;;;;gBAA3B,OAAO,KAAK,EAAE,QAAQ,CAAC,GAAG,CAAC;;;;;AAsDvC,wBASG"}
@@ -0,0 +1,16 @@
1
+ import { FormSchema } from 'types';
2
+ import { PropType } from 'vue';
3
+
4
+ declare const _default: import('vue').DefineComponent<{
5
+ modelValue: import('vue').PropType<any>;
6
+ schema: {
7
+ type: PropType<FormSchema>;
8
+ };
9
+ }, {}, unknown, {}, {}, import('vue').ComponentOptionsMixin, import('vue').ComponentOptionsMixin, {}, string, import('vue').PublicProps, Readonly<import('vue').ExtractPropTypes<{
10
+ modelValue: import('vue').PropType<any>;
11
+ schema: {
12
+ type: PropType<FormSchema>;
13
+ };
14
+ }>>, {}, {}>;
15
+ export default _default;
16
+ //# sourceMappingURL=NumberInput.vue.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"NumberInput.vue.d.ts","sourceRoot":"","sources":["../../../src/components/inputs/NumberInput.vue"],"names":[],"mappings":"AAOA;AAEA,OAAO,EAAa,UAAU,EAAE,MAAM,OAAO,CAAC;AAC9C,OAAO,EAAE,QAAQ,EAAE,MAAM,KAAK,CAAC;;gBAQnB,OAAO,KAAK,EAAE,QAAQ,CAAC,GAAG,CAAC;;;;;gBAA3B,OAAO,KAAK,EAAE,QAAQ,CAAC,GAAG,CAAC;;;;;AAsDvC,wBASG"}
@@ -0,0 +1,16 @@
1
+ import { FormSchema } from 'types';
2
+ import { PropType } from 'vue';
3
+
4
+ declare const _default: import('vue').DefineComponent<{
5
+ modelValue: import('vue').PropType<any>;
6
+ schema: {
7
+ type: PropType<FormSchema>;
8
+ };
9
+ }, {}, unknown, {}, {}, import('vue').ComponentOptionsMixin, import('vue').ComponentOptionsMixin, {}, string, import('vue').PublicProps, Readonly<import('vue').ExtractPropTypes<{
10
+ modelValue: import('vue').PropType<any>;
11
+ schema: {
12
+ type: PropType<FormSchema>;
13
+ };
14
+ }>>, {}, {}>;
15
+ export default _default;
16
+ //# sourceMappingURL=PasswordInput.vue.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PasswordInput.vue.d.ts","sourceRoot":"","sources":["../../../src/components/inputs/PasswordInput.vue"],"names":[],"mappings":"AAOA;AAEA,OAAO,EAAa,UAAU,EAAE,MAAM,OAAO,CAAC;AAC9C,OAAO,EAAE,QAAQ,EAAE,MAAM,KAAK,CAAC;;gBAQnB,OAAO,KAAK,EAAE,QAAQ,CAAC,GAAG,CAAC;;;;;gBAA3B,OAAO,KAAK,EAAE,QAAQ,CAAC,GAAG,CAAC;;;;;AAsDvC,wBASG"}
@@ -0,0 +1,16 @@
1
+ import { FormSchema } from 'types';
2
+ import { PropType } from 'vue';
3
+
4
+ declare const _default: import('vue').DefineComponent<{
5
+ modelValue: import('vue').PropType<any>;
6
+ schema: {
7
+ type: PropType<FormSchema>;
8
+ };
9
+ }, {}, unknown, {}, {}, import('vue').ComponentOptionsMixin, import('vue').ComponentOptionsMixin, {}, string, import('vue').PublicProps, Readonly<import('vue').ExtractPropTypes<{
10
+ modelValue: import('vue').PropType<any>;
11
+ schema: {
12
+ type: PropType<FormSchema>;
13
+ };
14
+ }>>, {}, {}>;
15
+ export default _default;
16
+ //# sourceMappingURL=TextInput.vue.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"TextInput.vue.d.ts","sourceRoot":"","sources":["../../../src/components/inputs/TextInput.vue"],"names":[],"mappings":"AAOA;AAEA,OAAO,EAAa,UAAU,EAAE,MAAM,OAAO,CAAC;AAC9C,OAAO,EAAE,QAAQ,EAAE,MAAM,KAAK,CAAC;;gBAQnB,OAAO,KAAK,EAAE,QAAQ,CAAC,GAAG,CAAC;;;;;gBAA3B,OAAO,KAAK,EAAE,QAAQ,CAAC,GAAG,CAAC;;;;;AAsDvC,wBASG"}
@@ -0,0 +1,64 @@
1
+ import { FormData, ComputedData, FormSchema } from '../types';
2
+
3
+ interface FormProps {
4
+ schema: FormSchema;
5
+ showLabels?: boolean;
6
+ showClearButton?: boolean;
7
+ showCancelButton?: boolean;
8
+ buttonPlacement?: 'start' | 'middle' | 'end';
9
+ submitButtonText?: string;
10
+ clearButtonText?: string;
11
+ cancelButtonText?: string;
12
+ }
13
+ declare const _default: import('vue').DefineComponent<__VLS_WithDefaults<__VLS_TypePropsToRuntimeProps<FormProps>, {
14
+ showLabels: boolean;
15
+ showClearButton: boolean;
16
+ showCancelButton: boolean;
17
+ buttonPlacement: string;
18
+ submitButtonText: string;
19
+ clearButtonText: string;
20
+ cancelButtonText: string;
21
+ }>, {}, unknown, {}, {}, import('vue').ComponentOptionsMixin, import('vue').ComponentOptionsMixin, {
22
+ submit: (formData: FormData, computedFormData: ComputedData) => void;
23
+ clear: () => void;
24
+ cancel: () => void;
25
+ }, string, import('vue').PublicProps, Readonly<import('vue').ExtractPropTypes<__VLS_WithDefaults<__VLS_TypePropsToRuntimeProps<FormProps>, {
26
+ showLabels: boolean;
27
+ showClearButton: boolean;
28
+ showCancelButton: boolean;
29
+ buttonPlacement: string;
30
+ submitButtonText: string;
31
+ clearButtonText: string;
32
+ cancelButtonText: string;
33
+ }>>> & {
34
+ onSubmit?: ((formData: FormData, computedFormData: ComputedData) => any) | undefined;
35
+ onCancel?: (() => any) | undefined;
36
+ onClear?: (() => any) | undefined;
37
+ }, {
38
+ showLabels: boolean;
39
+ showClearButton: boolean;
40
+ showCancelButton: boolean;
41
+ buttonPlacement: "start" | "middle" | "end";
42
+ submitButtonText: string;
43
+ clearButtonText: string;
44
+ cancelButtonText: string;
45
+ }, {}>;
46
+ export default _default;
47
+ type __VLS_NonUndefinedable<T> = T extends undefined ? never : T;
48
+ type __VLS_TypePropsToRuntimeProps<T> = {
49
+ [K in keyof T]-?: {} extends Pick<T, K> ? {
50
+ type: import('vue').PropType<__VLS_NonUndefinedable<T[K]>>;
51
+ } : {
52
+ type: import('vue').PropType<T[K]>;
53
+ required: true;
54
+ };
55
+ };
56
+ type __VLS_WithDefaults<P, D> = {
57
+ [K in keyof Pick<P, keyof P>]: K extends keyof D ? __VLS_Prettify<P[K] & {
58
+ default: D[K];
59
+ }> : P[K];
60
+ };
61
+ type __VLS_Prettify<T> = {
62
+ [K in keyof T]: T[K];
63
+ } & {};
64
+ //# sourceMappingURL=vForm.vue.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"vForm.vue.d.ts","sourceRoot":"","sources":["../../src/components/vForm.vue"],"names":[],"mappings":"AAqCA;AAIA,OAAO,KAAK,EAAE,QAAQ,EAAE,YAAY,EAAE,UAAU,EAAa,MAAM,UAAU,CAAC;AAK9E,UAAU,SAAS;IACjB,MAAM,EAAE,UAAU,CAAC;IACnB,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B,eAAe,CAAC,EAAE,OAAO,GAAG,QAAQ,GAAG,KAAK,CAAC;IAC7C,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,gBAAgB,CAAC,EAAE,MAAM,CAAC;CAC3B;;;;;;;;;;;;;;;;;;;;;;;;;;gBAPc,OAAO;qBACF,OAAO;sBACN,OAAO;qBACR,OAAO,GAAG,QAAQ,GAAG,KAAK;sBACzB,MAAM;qBACP,MAAM;sBACL,MAAM;;AAqR3B,wBAOG;AACH,KAAK,sBAAsB,CAAC,CAAC,IAAI,CAAC,SAAS,SAAS,GAAG,KAAK,GAAG,CAAC,CAAC;AACjE,KAAK,6BAA6B,CAAC,CAAC,IAAI;KAAG,CAAC,IAAI,MAAM,CAAC,CAAC,CAAC,GAAG,EAAE,SAAS,IAAI,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG;QAAE,IAAI,EAAE,OAAO,KAAK,EAAE,QAAQ,CAAC,sBAAsB,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAA;KAAE,GAAG;QAAE,IAAI,EAAE,OAAO,KAAK,EAAE,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;QAAC,QAAQ,EAAE,IAAI,CAAA;KAAE;CAAE,CAAC;AAC9M,KAAK,kBAAkB,CAAC,CAAC,EAAE,CAAC,IAAI;KAE1B,CAAC,IAAI,MAAM,IAAI,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC,GAAG,CAAC,SAAS,MAAM,CAAC,GAAG,cAAc,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG;QACxE,OAAO,EAAE,CAAC,CAAC,CAAC,CAAC,CAAA;KACb,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;CACT,CAAC;AACN,KAAK,cAAc,CAAC,CAAC,IAAI;KAAG,CAAC,IAAI,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;CAAG,GAAG,EAAE,CAAC"}