@stackshift-ui/form-field 6.0.2 → 6.0.4
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/package.json +12 -11
- package/src/form-field.test.tsx +13 -0
- package/src/form-field.tsx +114 -0
- package/src/index.ts +4 -0
- package/src/types.ts +12 -0
package/package.json
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stackshift-ui/form-field",
|
|
3
3
|
"description": "",
|
|
4
|
-
"version": "6.0.
|
|
4
|
+
"version": "6.0.4",
|
|
5
5
|
"private": false,
|
|
6
6
|
"sideEffects": false,
|
|
7
7
|
"main": "./dist/index.js",
|
|
8
8
|
"module": "./dist/index.mjs",
|
|
9
9
|
"types": "./dist/index.d.ts",
|
|
10
10
|
"files": [
|
|
11
|
-
"dist/**"
|
|
11
|
+
"dist/**",
|
|
12
|
+
"src"
|
|
12
13
|
],
|
|
13
14
|
"author": "WebriQ <info@webriq.com>",
|
|
14
15
|
"devDependencies": {
|
|
@@ -32,16 +33,16 @@
|
|
|
32
33
|
"@stackshift-ui/typescript-config": "6.0.2"
|
|
33
34
|
},
|
|
34
35
|
"dependencies": {
|
|
36
|
+
"@stackshift-ui/checkbox-group": "6.0.3",
|
|
37
|
+
"@stackshift-ui/checkbox": "6.0.3",
|
|
35
38
|
"@stackshift-ui/scripts": "6.0.2",
|
|
36
|
-
"@stackshift-ui/
|
|
37
|
-
"@stackshift-ui/
|
|
38
|
-
"@stackshift-ui/
|
|
39
|
-
"@stackshift-ui/input": "6.0.
|
|
40
|
-
"@stackshift-ui/
|
|
41
|
-
"@stackshift-ui/radio": "6.0.
|
|
42
|
-
"@stackshift-ui/select": "6.0.
|
|
43
|
-
"@stackshift-ui/radio-group": "6.0.2",
|
|
44
|
-
"@stackshift-ui/textarea": "6.0.2"
|
|
39
|
+
"@stackshift-ui/input": "6.0.4",
|
|
40
|
+
"@stackshift-ui/system": "6.0.3",
|
|
41
|
+
"@stackshift-ui/radio": "6.0.3",
|
|
42
|
+
"@stackshift-ui/input-file": "6.0.3",
|
|
43
|
+
"@stackshift-ui/textarea": "6.0.3",
|
|
44
|
+
"@stackshift-ui/radio-group": "6.0.3",
|
|
45
|
+
"@stackshift-ui/select": "6.0.3"
|
|
45
46
|
},
|
|
46
47
|
"peerDependencies": {
|
|
47
48
|
"@types/react": "16.8 - 19",
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { cleanup, render, screen } from "@testing-library/react";
|
|
2
|
+
import { afterEach, describe, test } from "vitest";
|
|
3
|
+
import { FormField } from "./form-field";
|
|
4
|
+
|
|
5
|
+
describe.concurrent("form-field", () => {
|
|
6
|
+
afterEach(cleanup);
|
|
7
|
+
|
|
8
|
+
test("Common: Form Field - test if renders without errors", ({ expect }) => {
|
|
9
|
+
const clx = "formfield-class";
|
|
10
|
+
render(<FormField className={clx} name="stackshift-formfield" />);
|
|
11
|
+
expect(screen.getByTestId("textarea").classList).toContain(clx);
|
|
12
|
+
});
|
|
13
|
+
});
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import { Checkbox } from "@stackshift-ui/checkbox";
|
|
2
|
+
import { CheckboxGroup } from "@stackshift-ui/checkbox-group";
|
|
3
|
+
import { Input } from "@stackshift-ui/input";
|
|
4
|
+
import { InputFile } from "@stackshift-ui/input-file";
|
|
5
|
+
import { Radio } from "@stackshift-ui/radio";
|
|
6
|
+
import { RadioGroup } from "@stackshift-ui/radio-group";
|
|
7
|
+
import { Select } from "@stackshift-ui/select";
|
|
8
|
+
import { Textarea } from "@stackshift-ui/textarea";
|
|
9
|
+
import { FormTypes, Variant } from "./types";
|
|
10
|
+
|
|
11
|
+
type FormFieldProps = {
|
|
12
|
+
type?: FormTypes;
|
|
13
|
+
items?: string[];
|
|
14
|
+
variant?: Variant;
|
|
15
|
+
name: string;
|
|
16
|
+
label?: string;
|
|
17
|
+
required?: boolean;
|
|
18
|
+
placeholder?: string;
|
|
19
|
+
className?: string;
|
|
20
|
+
textSize?: "sm" | "md" | "lg";
|
|
21
|
+
noLabel?: boolean;
|
|
22
|
+
[key: string]: any;
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
export const FormField = ({
|
|
26
|
+
type = "textarea",
|
|
27
|
+
items = [],
|
|
28
|
+
name,
|
|
29
|
+
label = "",
|
|
30
|
+
required,
|
|
31
|
+
placeholder,
|
|
32
|
+
textSize,
|
|
33
|
+
noLabel,
|
|
34
|
+
variant,
|
|
35
|
+
...props
|
|
36
|
+
}: FormFieldProps) => {
|
|
37
|
+
const formType = {
|
|
38
|
+
inputText: "text",
|
|
39
|
+
inputEmail: "email",
|
|
40
|
+
inputPassword: "password",
|
|
41
|
+
inputNumber: "number",
|
|
42
|
+
textarea: "textarea",
|
|
43
|
+
inputFile: "file",
|
|
44
|
+
inputRadio: "radio",
|
|
45
|
+
inputCheckbox: "checkbox",
|
|
46
|
+
inputSelect: "select",
|
|
47
|
+
}[type];
|
|
48
|
+
|
|
49
|
+
switch (type) {
|
|
50
|
+
case "inputRadio":
|
|
51
|
+
return (
|
|
52
|
+
<RadioGroup noLabel={noLabel} label={label} name={name}>
|
|
53
|
+
{items?.map(item => (
|
|
54
|
+
<Radio key={item} ariaLabel={name} name={name} item={item} {...props} />
|
|
55
|
+
))}
|
|
56
|
+
</RadioGroup>
|
|
57
|
+
);
|
|
58
|
+
|
|
59
|
+
case "inputSelect":
|
|
60
|
+
return (
|
|
61
|
+
<Select
|
|
62
|
+
items={items}
|
|
63
|
+
label={label}
|
|
64
|
+
ariaLabel={label}
|
|
65
|
+
name={name}
|
|
66
|
+
required={required}
|
|
67
|
+
noLabel={noLabel}
|
|
68
|
+
{...props}
|
|
69
|
+
/>
|
|
70
|
+
);
|
|
71
|
+
|
|
72
|
+
case "inputCheckbox":
|
|
73
|
+
return (
|
|
74
|
+
<CheckboxGroup noLabel={noLabel} name={name} label={label}>
|
|
75
|
+
{items?.map(item => (
|
|
76
|
+
<Checkbox key={item} label={item} ariaLabel={name} name={name} item={item} {...props} />
|
|
77
|
+
))}
|
|
78
|
+
</CheckboxGroup>
|
|
79
|
+
);
|
|
80
|
+
|
|
81
|
+
case "inputFile":
|
|
82
|
+
return <InputFile ariaLabel={name} name={name} required={required} {...props} />;
|
|
83
|
+
|
|
84
|
+
case "textarea":
|
|
85
|
+
return (
|
|
86
|
+
<Textarea
|
|
87
|
+
noLabel={noLabel}
|
|
88
|
+
ariaLabel={placeholder ?? name}
|
|
89
|
+
placeholder={placeholder}
|
|
90
|
+
name={name}
|
|
91
|
+
variant={variant}
|
|
92
|
+
required={required}
|
|
93
|
+
label={label}
|
|
94
|
+
{...props}
|
|
95
|
+
/>
|
|
96
|
+
);
|
|
97
|
+
|
|
98
|
+
default:
|
|
99
|
+
return (
|
|
100
|
+
<Input
|
|
101
|
+
noLabel={noLabel}
|
|
102
|
+
textSize={textSize}
|
|
103
|
+
label={label || name}
|
|
104
|
+
ariaLabel={label || name}
|
|
105
|
+
required={required}
|
|
106
|
+
name={name}
|
|
107
|
+
placeholder={placeholder}
|
|
108
|
+
type={formType as "number" | "text" | "email" | "password"}
|
|
109
|
+
variant={variant}
|
|
110
|
+
{...props}
|
|
111
|
+
/>
|
|
112
|
+
);
|
|
113
|
+
}
|
|
114
|
+
};
|
package/src/index.ts
ADDED
package/src/types.ts
ADDED