react-form-dto 0.0.1 → 0.0.2

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.
@@ -0,0 +1,50 @@
1
+ export type LayoutDTO = {
2
+ columns?: number;
3
+ gap?: string;
4
+ direction?: "row" | "column";
5
+ align?: "start" | "center" | "end" | "stretch";
6
+ justify?: "start" | "center" | "end" | "space-between";
7
+ };
8
+ export type InputType = "text" | "email" | "password" | "textarea" | "number" | "select" | "checkbox" | "date" | "autocomplete" | "multi-autocomplete" | "radio";
9
+ export type FieldDTO = {
10
+ id: string;
11
+ type: InputType;
12
+ label: string;
13
+ placeholder?: string;
14
+ options?: string[];
15
+ required?: boolean;
16
+ rows?: number;
17
+ disabled?: boolean;
18
+ defaultValue?: any;
19
+ layout?: {
20
+ col?: number;
21
+ direction?: "row" | "column";
22
+ };
23
+ validations?: Validations;
24
+ };
25
+ export type SectionDTO = {
26
+ id: string;
27
+ heading?: string;
28
+ headingFontSize?: number;
29
+ description?: string;
30
+ descriptionFontSize?: number;
31
+ layout?: LayoutDTO;
32
+ fields: FieldDTO[];
33
+ };
34
+ export type FormDTO = {
35
+ title?: string;
36
+ titleFontSize?: number;
37
+ description?: string;
38
+ descriptionFontSize?: number;
39
+ layout?: LayoutDTO;
40
+ sections: SectionDTO[];
41
+ };
42
+ export type Validations = {
43
+ required?: boolean | string;
44
+ min?: number;
45
+ max?: number;
46
+ minLength?: number;
47
+ maxLength?: number;
48
+ pattern?: RegExp;
49
+ validate?: (value: any) => string | null;
50
+ };
@@ -0,0 +1 @@
1
+ export * from './dto';
@@ -0,0 +1,2 @@
1
+ export * from './layout';
2
+ export * from './validation';
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Maps a span value to a responsive size configuration for different screen breakpoints.
3
+ * Ensures mobile devices always use full width (12) while other breakpoints use the provided span.
4
+ *
5
+ * @param span - The number of columns (1-12) the element should span. Defaults to 12 (full width).
6
+ * @returns An object with responsive breakpoint sizes (xs, sm, md, lg, xl)
7
+ *
8
+ * @example
9
+ * mapSpanToSize(6) // Returns { xs: 12, sm: 6, md: 6, lg: 6, xl: 6 }
10
+ * mapSpanToSize() // Returns { xs: 12, sm: 12, md: 12, lg: 12, xl: 12 }
11
+ */
12
+ export declare function mapSpanToSize(span?: number): {
13
+ xs: number;
14
+ sm: number;
15
+ md: number;
16
+ lg: number;
17
+ xl: number;
18
+ };
@@ -0,0 +1,24 @@
1
+ import { FieldDTO, FormDTO } from '../types';
2
+ type ValidationFn = (field: FieldDTO, value: any) => string | null;
3
+ /**
4
+ * A collection of validation functions for form fields.
5
+ * Each function takes a field definition and value, returning an error message or null.
6
+ */
7
+ export declare const validationRules: Record<string, ValidationFn>;
8
+ /**
9
+ * Validates all fields in a form DTO against their respective validation rules.
10
+ * @param dto - The form DTO containing sections and fields
11
+ * @param values - An object containing current values for all fields (keyed by field ID)
12
+ * @returns An object mapping field IDs to arrays of error messages
13
+ */
14
+ export declare const validateAll: (dto: FormDTO, values: Record<string, any>) => Record<string, string[]>;
15
+ /**
16
+ * Validates a specific field in the form DTO.
17
+ * Useful for real-time validation as the user interacts with individual fields.
18
+ * @param dto - The form DTO containing sections and fields
19
+ * @param values - An object containing current values for all fields (keyed by field ID)
20
+ * @param fieldId - The ID of the specific field to validate
21
+ * @returns An array of error messages for the field, empty if no errors or field not found
22
+ */
23
+ export declare const validateField: (dto: FormDTO, values: Record<string, any>, fieldId: string) => string[];
24
+ export {};
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "react-form-dto",
3
- "version": "0.0.1",
4
- "type": "module",
3
+ "description": "A React library for building forms using DTOs with MUI and TypeScript.",
4
+ "version": "0.0.2",
5
5
  "main": "dist/react-form-dto.umd.js",
6
6
  "module": "dist/react-form-dto.es.js",
7
7
  "types": "dist/index.d.ts",
@@ -10,36 +10,29 @@
10
10
  ],
11
11
  "scripts": {
12
12
  "dev": "vite",
13
- "build": "tsc -b && vite build",
13
+ "build": "vite build",
14
14
  "lint": "eslint .",
15
15
  "preview": "vite preview",
16
16
  "docs:dev": "vitepress dev docs",
17
17
  "docs:build": "vitepress build docs",
18
18
  "docs:preview": "vitepress preview docs"
19
19
  },
20
- "dependencies": {
21
- "@emotion/react": "^11.14.0",
22
- "@emotion/styled": "^11.14.1",
23
- "@mui/material": "^7.3.6",
24
- "markdown-it-prism": "^3.0.1",
25
- "react": "^19.2.0",
26
- "react-dom": "^19.2.0"
20
+ "peerDependencies": {
21
+ "react": ">=17",
22
+ "react-dom": ">=17",
23
+ "@mui/material": ">=7"
27
24
  },
28
25
  "devDependencies": {
29
- "@eslint/js": "^9.39.1",
30
- "@types/node": "^24.10.1",
31
- "@types/react": "^19.2.5",
32
- "@types/react-dom": "^19.2.3",
33
26
  "@vitejs/plugin-react": "^5.1.1",
34
- "eslint": "^9.39.1",
35
- "eslint-plugin-react-hooks": "^7.0.1",
36
- "eslint-plugin-react-refresh": "^0.4.24",
37
- "globals": "^16.5.0",
38
- "typescript": "~5.9.3",
39
- "typescript-eslint": "^8.46.4",
40
27
  "vite": "^7.2.4",
41
28
  "vite-plugin-dts": "^4.5.4",
42
- "vitepress": "^1.6.4"
29
+ "typescript": "~5.9.3",
30
+ "vitepress": "^1.6.4",
31
+ "eslint": "^9.39.1",
32
+ "typescript-eslint": "^8.46.4",
33
+ "@types/react": "^19.2.5",
34
+ "@types/react-dom": "^19.2.3",
35
+ "@types/node": "^24.10.1"
43
36
  },
44
37
  "repository": {
45
38
  "type": "git",
@@ -49,17 +42,10 @@
49
42
  "react",
50
43
  "form",
51
44
  "dto",
52
- "form-dto",
53
- "react-form-dto",
54
- "form-data-transfer-object",
55
- "data-transfer-object",
56
- "dto-pattern",
57
- "typescript",
58
45
  "mui",
59
- "material-ui",
60
- "hooks",
61
- "library",
62
- "validation"
46
+ "typescript",
47
+ "validation",
48
+ "library"
63
49
  ],
64
50
  "author": "Shakir Ullah",
65
51
  "license": "MIT"