@stackshift-ui/form-field 6.0.13 → 7.0.0-beta.1
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/dist/chunk-3EYN2AKU.mjs +1 -0
- package/dist/chunk-I3IICQN4.mjs +1 -0
- package/dist/form-field.js +1 -1
- package/dist/form-field.mjs +1 -1
- package/dist/index.js +1 -1
- package/dist/index.mjs +1 -1
- package/dist/setupTests.d.ts +2 -0
- package/dist/setupTests.js +51 -0
- package/dist/setupTests.mjs +51 -0
- package/package.json +25 -22
- package/src/form-field.test.tsx +40 -2
- package/src/form-field.tsx +70 -38
- package/src/setupTests.ts +4 -0
- package/dist/chunk-A7CS32FD.mjs +0 -1
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stackshift-ui/form-field",
|
|
3
3
|
"description": "",
|
|
4
|
-
"version": "
|
|
4
|
+
"version": "7.0.0-beta.1",
|
|
5
5
|
"private": false,
|
|
6
6
|
"sideEffects": false,
|
|
7
7
|
"main": "./dist/index.js",
|
|
@@ -13,7 +13,9 @@
|
|
|
13
13
|
],
|
|
14
14
|
"author": "WebriQ <info@webriq.com>",
|
|
15
15
|
"devDependencies": {
|
|
16
|
+
"@testing-library/jest-dom": "^6.5.0",
|
|
16
17
|
"@testing-library/react": "^16.0.1",
|
|
18
|
+
"@testing-library/user-event": "^14.6.1",
|
|
17
19
|
"@types/node": "^22.7.0",
|
|
18
20
|
"@types/react": "^18.3.9",
|
|
19
21
|
"@types/react-dom": "^18.3.0",
|
|
@@ -33,32 +35,33 @@
|
|
|
33
35
|
"@stackshift-ui/typescript-config": "6.0.10"
|
|
34
36
|
},
|
|
35
37
|
"dependencies": {
|
|
36
|
-
"@stackshift-ui/
|
|
37
|
-
"@stackshift-ui/
|
|
38
|
-
"@stackshift-ui/
|
|
39
|
-
"@stackshift-ui/input": "
|
|
40
|
-
"@stackshift-ui/
|
|
41
|
-
"@stackshift-ui/
|
|
42
|
-
"@stackshift-ui/
|
|
43
|
-
"@stackshift-ui/
|
|
44
|
-
"@stackshift-ui/
|
|
45
|
-
"@stackshift-ui/textarea": "
|
|
38
|
+
"@stackshift-ui/input": "7.0.0-beta.0",
|
|
39
|
+
"@stackshift-ui/label": "1.0.0-beta.1",
|
|
40
|
+
"@stackshift-ui/checkbox-group": "7.0.0-beta.0",
|
|
41
|
+
"@stackshift-ui/input-file": "7.0.0-beta.0",
|
|
42
|
+
"@stackshift-ui/checkbox": "7.0.0-beta.0",
|
|
43
|
+
"@stackshift-ui/system": "6.1.0-beta.0",
|
|
44
|
+
"@stackshift-ui/scripts": "6.1.0-beta.0",
|
|
45
|
+
"@stackshift-ui/select": "7.0.0-beta.0",
|
|
46
|
+
"@stackshift-ui/radio": "7.0.0-beta.0",
|
|
47
|
+
"@stackshift-ui/textarea": "7.0.0-beta.0",
|
|
48
|
+
"@stackshift-ui/radio-group": "7.0.0-beta.0"
|
|
46
49
|
},
|
|
47
50
|
"peerDependencies": {
|
|
51
|
+
"@stackshift-ui/checkbox": ">=7.0.0-beta.0",
|
|
52
|
+
"@stackshift-ui/checkbox-group": ">=7.0.0-beta.0",
|
|
53
|
+
"@stackshift-ui/input": ">=7.0.0-beta.0",
|
|
54
|
+
"@stackshift-ui/input-file": ">=7.0.0-beta.0",
|
|
55
|
+
"@stackshift-ui/radio": ">=7.0.0-beta.0",
|
|
56
|
+
"@stackshift-ui/radio-group": ">=7.0.0-beta.0",
|
|
57
|
+
"@stackshift-ui/scripts": ">=6.1.0-beta.0",
|
|
58
|
+
"@stackshift-ui/select": ">=7.0.0-beta.0",
|
|
59
|
+
"@stackshift-ui/system": ">=6.1.0-beta.0",
|
|
60
|
+
"@stackshift-ui/textarea": ">=7.0.0-beta.0",
|
|
48
61
|
"@types/react": "16.8 - 19",
|
|
49
62
|
"next": "10 - 14",
|
|
50
63
|
"react": "16.8 - 19",
|
|
51
|
-
"react-dom": "16.8 - 19"
|
|
52
|
-
"@stackshift-ui/scripts": ">=6.0.10",
|
|
53
|
-
"@stackshift-ui/system": ">=6.0.11",
|
|
54
|
-
"@stackshift-ui/checkbox": ">=6.0.11",
|
|
55
|
-
"@stackshift-ui/checkbox-group": ">=6.0.11",
|
|
56
|
-
"@stackshift-ui/input": ">=6.0.12",
|
|
57
|
-
"@stackshift-ui/input-file": ">=6.0.12",
|
|
58
|
-
"@stackshift-ui/radio": ">=6.0.11",
|
|
59
|
-
"@stackshift-ui/radio-group": ">=6.0.11",
|
|
60
|
-
"@stackshift-ui/select": ">=6.0.12",
|
|
61
|
-
"@stackshift-ui/textarea": ">=6.0.12"
|
|
64
|
+
"react-dom": "16.8 - 19"
|
|
62
65
|
},
|
|
63
66
|
"peerDependenciesMeta": {
|
|
64
67
|
"next": {
|
package/src/form-field.test.tsx
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { cleanup, render, screen } from "@testing-library/react";
|
|
1
|
+
import { cleanup, render, screen, waitFor } from "@testing-library/react";
|
|
2
|
+
import userEvent from "@testing-library/user-event";
|
|
2
3
|
import { afterEach, describe, test } from "vitest";
|
|
3
4
|
import { FormField } from "./form-field";
|
|
4
5
|
|
|
@@ -7,7 +8,44 @@ describe.concurrent("form-field", () => {
|
|
|
7
8
|
|
|
8
9
|
test("Common: Form Field - test if renders without errors", ({ expect }) => {
|
|
9
10
|
const clx = "formfield-class";
|
|
10
|
-
|
|
11
|
+
const { unmount } = render(
|
|
12
|
+
<FormField data-testid="textarea" className={clx} name="stackshift-formfield" />,
|
|
13
|
+
);
|
|
11
14
|
expect(screen.getByTestId("textarea").classList).toContain(clx);
|
|
15
|
+
unmount();
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
test("Common: Form Field - test if renders with correct type", ({ expect }) => {
|
|
19
|
+
const { unmount } = render(
|
|
20
|
+
<FormField data-testid="inputText" type="inputText" name="stackshift-inputtext" />,
|
|
21
|
+
);
|
|
22
|
+
expect(screen.getByTestId("inputText").tagName.toLowerCase()).toBe("input");
|
|
23
|
+
unmount();
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
test("Common: Form Field - test if renders with correct label", ({ expect }) => {
|
|
27
|
+
const { unmount } = render(
|
|
28
|
+
<FormField
|
|
29
|
+
data-testid="inputText"
|
|
30
|
+
type="inputText"
|
|
31
|
+
name="stackshift-inputtext"
|
|
32
|
+
label="Stackshift Input Text"
|
|
33
|
+
/>,
|
|
34
|
+
);
|
|
35
|
+
expect(screen.getByText("Stackshift Input Text")).toBeInTheDocument();
|
|
36
|
+
unmount();
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
test("Common: Form Field - test if renders with correct placeholder", ({ expect }) => {
|
|
40
|
+
const { unmount } = render(
|
|
41
|
+
<FormField
|
|
42
|
+
data-testid="inputText"
|
|
43
|
+
type="inputText"
|
|
44
|
+
name="stackshift-inputtext"
|
|
45
|
+
placeholder="Stackshift Input Text"
|
|
46
|
+
/>,
|
|
47
|
+
);
|
|
48
|
+
expect(screen.getByPlaceholderText("Stackshift Input Text")).toBeInTheDocument();
|
|
49
|
+
unmount();
|
|
12
50
|
});
|
|
13
51
|
});
|
package/src/form-field.tsx
CHANGED
|
@@ -2,9 +2,15 @@ import { Checkbox } from "@stackshift-ui/checkbox";
|
|
|
2
2
|
import { CheckboxGroup } from "@stackshift-ui/checkbox-group";
|
|
3
3
|
import { Input } from "@stackshift-ui/input";
|
|
4
4
|
import { InputFile } from "@stackshift-ui/input-file";
|
|
5
|
-
import {
|
|
6
|
-
import { RadioGroup } from "@stackshift-ui/radio-group";
|
|
7
|
-
import {
|
|
5
|
+
import { Label } from "@stackshift-ui/label";
|
|
6
|
+
import { RadioGroup, RadioGroupItem } from "@stackshift-ui/radio-group";
|
|
7
|
+
import {
|
|
8
|
+
Select,
|
|
9
|
+
SelectContent,
|
|
10
|
+
SelectItem,
|
|
11
|
+
SelectTrigger,
|
|
12
|
+
SelectValue,
|
|
13
|
+
} from "@stackshift-ui/select";
|
|
8
14
|
import { Textarea } from "@stackshift-ui/textarea";
|
|
9
15
|
import { FormTypes, Variant } from "./types";
|
|
10
16
|
|
|
@@ -49,31 +55,42 @@ export const FormField = ({
|
|
|
49
55
|
switch (type) {
|
|
50
56
|
case "inputRadio":
|
|
51
57
|
return (
|
|
52
|
-
<RadioGroup
|
|
58
|
+
<RadioGroup name={name} {...props}>
|
|
59
|
+
<Label>{label}</Label>
|
|
53
60
|
{items?.map(item => (
|
|
54
|
-
<
|
|
61
|
+
<div className="flex items-center gap-3">
|
|
62
|
+
{/* // <Radio key={item} ariaLabel={name} name={name} item={item} {...props} /> */}
|
|
63
|
+
<RadioGroupItem id={item} key={item} value={item} />
|
|
64
|
+
<Label htmlFor={item}>{item}</Label>
|
|
65
|
+
</div>
|
|
55
66
|
))}
|
|
56
67
|
</RadioGroup>
|
|
57
68
|
);
|
|
58
69
|
|
|
59
70
|
case "inputSelect":
|
|
60
71
|
return (
|
|
61
|
-
<Select
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
72
|
+
<Select name={name} {...props}>
|
|
73
|
+
<SelectTrigger>
|
|
74
|
+
<SelectValue placeholder={placeholder} />
|
|
75
|
+
</SelectTrigger>
|
|
76
|
+
<SelectContent>
|
|
77
|
+
{items?.map(item => (
|
|
78
|
+
<SelectItem key={item} value={item}>
|
|
79
|
+
{item}
|
|
80
|
+
</SelectItem>
|
|
81
|
+
))}
|
|
82
|
+
</SelectContent>
|
|
83
|
+
</Select>
|
|
70
84
|
);
|
|
71
85
|
|
|
72
86
|
case "inputCheckbox":
|
|
73
87
|
return (
|
|
74
|
-
<CheckboxGroup noLabel={noLabel} name={name} label={label}>
|
|
88
|
+
<CheckboxGroup noLabel={noLabel} name={name} label={label} {...props}>
|
|
75
89
|
{items?.map(item => (
|
|
76
|
-
<
|
|
90
|
+
<div className="flex flex-col gap-2 items-start">
|
|
91
|
+
<Checkbox id={item} key={item} name={item} {...props} />
|
|
92
|
+
<Label htmlFor={item}>{label}</Label>
|
|
93
|
+
</div>
|
|
77
94
|
))}
|
|
78
95
|
</CheckboxGroup>
|
|
79
96
|
);
|
|
@@ -83,32 +100,47 @@ export const FormField = ({
|
|
|
83
100
|
|
|
84
101
|
case "textarea":
|
|
85
102
|
return (
|
|
86
|
-
<Textarea
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
/>
|
|
103
|
+
// <Textarea
|
|
104
|
+
// noLabel={noLabel}
|
|
105
|
+
// ariaLabel={placeholder ?? name}
|
|
106
|
+
// placeholder={placeholder}
|
|
107
|
+
// name={name}
|
|
108
|
+
// variant={variant}
|
|
109
|
+
// required={required}
|
|
110
|
+
// label={label}
|
|
111
|
+
// {...props}
|
|
112
|
+
// />
|
|
113
|
+
<div>
|
|
114
|
+
{!noLabel ? <Label htmlFor={name}>{label}</Label> : null}
|
|
115
|
+
<Textarea id={name} name={name} placeholder={placeholder} {...props}></Textarea>
|
|
116
|
+
</div>
|
|
96
117
|
);
|
|
97
118
|
|
|
98
119
|
default:
|
|
99
120
|
return (
|
|
100
|
-
<
|
|
101
|
-
noLabel={
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
121
|
+
<div className="flex flex-col gap-2 items-start">
|
|
122
|
+
{!noLabel ? <Label htmlFor={name}>{label}</Label> : null}
|
|
123
|
+
<Input
|
|
124
|
+
id={name}
|
|
125
|
+
name={name}
|
|
126
|
+
placeholder={placeholder}
|
|
127
|
+
type={formType as "number" | "text" | "email" | "password"}
|
|
128
|
+
required={required}
|
|
129
|
+
{...props}
|
|
130
|
+
/>
|
|
131
|
+
</div>
|
|
132
|
+
// <Input
|
|
133
|
+
// noLabel={noLabel}
|
|
134
|
+
// textSize={textSize}
|
|
135
|
+
// label={label || name}
|
|
136
|
+
// ariaLabel={label || name}
|
|
137
|
+
// required={required}
|
|
138
|
+
// name={name}
|
|
139
|
+
// placeholder={placeholder}
|
|
140
|
+
// type={formType as "number" | "text" | "email" | "password"}
|
|
141
|
+
// variant={variant}
|
|
142
|
+
// {...props}
|
|
143
|
+
// />
|
|
112
144
|
);
|
|
113
145
|
}
|
|
114
146
|
};
|
package/dist/chunk-A7CS32FD.mjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{Checkbox as x}from"@stackshift-ui/checkbox";import{CheckboxGroup as s}from"@stackshift-ui/checkbox-group";import{Input as d}from"@stackshift-ui/input";import{InputFile as f}from"@stackshift-ui/input-file";import{Radio as F}from"@stackshift-ui/radio";import{RadioGroup as k}from"@stackshift-ui/radio-group";import{Select as y}from"@stackshift-ui/select";import{Textarea as L}from"@stackshift-ui/textarea";import{jsx as e}from"react/jsx-runtime";var P=({type:l="textarea",items:a=[],name:r,label:t="",required:p,placeholder:n,textSize:b,noLabel:u,variant:m,...i})=>{let c={inputText:"text",inputEmail:"email",inputPassword:"password",inputNumber:"number",textarea:"textarea",inputFile:"file",inputRadio:"radio",inputCheckbox:"checkbox",inputSelect:"select"}[l];switch(l){case"inputRadio":return e(k,{noLabel:u,label:t,name:r,children:a==null?void 0:a.map(o=>e(F,{ariaLabel:r,name:r,item:o,...i},o))});case"inputSelect":return e(y,{items:a,label:t,ariaLabel:t,name:r,required:p,noLabel:u,...i});case"inputCheckbox":return e(s,{noLabel:u,name:r,label:t,children:a==null?void 0:a.map(o=>e(x,{label:o,ariaLabel:r,name:r,item:o,...i},o))});case"inputFile":return e(f,{ariaLabel:r,name:r,required:p,...i});case"textarea":return e(L,{noLabel:u,ariaLabel:n!=null?n:r,placeholder:n,name:r,variant:m,required:p,label:t,...i});default:return e(d,{noLabel:u,textSize:b,label:t||r,ariaLabel:t||r,required:p,name:r,placeholder:n,type:c,variant:m,...i})}};export{P as a};
|