@stackshift-ui/textarea 6.0.12 → 7.0.0-beta.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/package.json +4 -4
- package/src/textarea.test.tsx +23 -3
- package/src/textarea.tsx +17 -71
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stackshift-ui/textarea",
|
|
3
3
|
"description": "",
|
|
4
|
-
"version": "
|
|
4
|
+
"version": "7.0.0-beta.0",
|
|
5
5
|
"private": false,
|
|
6
6
|
"sideEffects": false,
|
|
7
7
|
"main": "./dist/index.js",
|
|
@@ -34,15 +34,15 @@
|
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
36
|
"classnames": "^2.5.1",
|
|
37
|
-
"@stackshift-ui/system": "6.0.
|
|
38
|
-
"@stackshift-ui/scripts": "6.0.
|
|
37
|
+
"@stackshift-ui/system": "6.1.0-beta.0",
|
|
38
|
+
"@stackshift-ui/scripts": "6.1.0-beta.0"
|
|
39
39
|
},
|
|
40
40
|
"peerDependencies": {
|
|
41
41
|
"@types/react": "16.8 - 19",
|
|
42
42
|
"next": "10 - 14",
|
|
43
43
|
"react": "16.8 - 19",
|
|
44
44
|
"react-dom": "16.8 - 19",
|
|
45
|
-
"@stackshift-ui/system": ">=6.0.
|
|
45
|
+
"@stackshift-ui/system": ">=6.1.0-beta.0"
|
|
46
46
|
},
|
|
47
47
|
"peerDependenciesMeta": {
|
|
48
48
|
"next": {
|
package/src/textarea.test.tsx
CHANGED
|
@@ -3,11 +3,31 @@ import { afterEach, describe, test } from "vitest";
|
|
|
3
3
|
import { Textarea } from "./textarea";
|
|
4
4
|
|
|
5
5
|
describe.concurrent("textarea", () => {
|
|
6
|
-
afterEach(
|
|
6
|
+
afterEach(() => {
|
|
7
|
+
cleanup();
|
|
8
|
+
});
|
|
7
9
|
|
|
8
10
|
test("Common: Textarea - test if renders without errors", ({ expect }) => {
|
|
9
11
|
const clx = "textarea-class";
|
|
10
|
-
render(<Textarea className={clx}
|
|
11
|
-
|
|
12
|
+
const { unmount } = render(<Textarea className={clx} placeholder="Enter text here" />);
|
|
13
|
+
const textarea = screen.getByPlaceholderText("Enter text here");
|
|
14
|
+
expect(textarea.classList).toContain(clx);
|
|
15
|
+
expect(textarea.tagName.toLowerCase()).toBe("textarea");
|
|
16
|
+
unmount();
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
test("Common: Textarea - test with aria-label", ({ expect }) => {
|
|
20
|
+
const { unmount } = render(<Textarea aria-label="Text area input" />);
|
|
21
|
+
const textarea = screen.getByLabelText("Text area input");
|
|
22
|
+
expect(textarea.tagName.toLowerCase()).toBe("textarea");
|
|
23
|
+
unmount();
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
test("Common: Textarea - test with rows prop", ({ expect }) => {
|
|
27
|
+
const { unmount } = render(<Textarea placeholder="Test rows" rows={3} />);
|
|
28
|
+
const textarea = screen.getByPlaceholderText("Test rows");
|
|
29
|
+
screen.debug(textarea);
|
|
30
|
+
expect(textarea.getAttribute("rows")).toBe("3");
|
|
31
|
+
unmount();
|
|
12
32
|
});
|
|
13
33
|
});
|
package/src/textarea.tsx
CHANGED
|
@@ -1,80 +1,26 @@
|
|
|
1
|
-
import
|
|
2
|
-
import cn from "classnames";
|
|
3
|
-
import type { ElementType, HTMLProps, ReactNode } from "react";
|
|
1
|
+
import * as React from "react";
|
|
4
2
|
|
|
5
|
-
|
|
6
|
-
type Variant = "primary" | "outline" | "secondary";
|
|
7
|
-
|
|
8
|
-
export interface TextareaProps extends Omit<HTMLProps<HTMLTextAreaElement>, "as"> {
|
|
9
|
-
required?: boolean;
|
|
10
|
-
name: string;
|
|
11
|
-
ariaLabel: string;
|
|
12
|
-
placeholder?: string;
|
|
13
|
-
onChange?: (...args: any) => any;
|
|
14
|
-
labelClass?: string;
|
|
15
|
-
variant?: Variant;
|
|
16
|
-
label?: string;
|
|
17
|
-
noLabel?: boolean;
|
|
18
|
-
[key: string]: any;
|
|
19
|
-
children?: ReactNode;
|
|
20
|
-
className?: string;
|
|
21
|
-
as?: ElementType;
|
|
22
|
-
}
|
|
3
|
+
import { cn, DefaultComponent, useStackShiftUIComponents } from "@stackshift-ui/system";
|
|
23
4
|
|
|
24
5
|
const displayName = "Textarea";
|
|
25
6
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
ariaLabel,
|
|
30
|
-
placeholder,
|
|
31
|
-
onChange,
|
|
32
|
-
labelClass,
|
|
33
|
-
variant = "primary",
|
|
34
|
-
label,
|
|
35
|
-
noLabel,
|
|
36
|
-
children,
|
|
37
|
-
className,
|
|
38
|
-
as = "textarea",
|
|
39
|
-
...props
|
|
40
|
-
}) => {
|
|
41
|
-
const { [displayName]: Component = DefaultComponent } = useStackShiftUIComponents();
|
|
42
|
-
|
|
43
|
-
const commonStyle = "h-24 w-full resize rounded-global p-4 text-xs leading-none";
|
|
44
|
-
const primary = `${commonStyle}`;
|
|
45
|
-
const secondary = `${commonStyle} p-4 outline-none`;
|
|
46
|
-
const outline = `${commonStyle} py-3 border border-slate-300`;
|
|
47
|
-
|
|
48
|
-
const variants: StyleVariants<Variant> = {
|
|
49
|
-
primary,
|
|
50
|
-
outline,
|
|
51
|
-
secondary,
|
|
52
|
-
};
|
|
53
|
-
|
|
54
|
-
const variantClass = variants[variant] ?? primary;
|
|
7
|
+
const Textarea = React.forwardRef<HTMLTextAreaElement, React.ComponentProps<"textarea">>(
|
|
8
|
+
({ className, ...props }, ref) => {
|
|
9
|
+
const { [displayName]: Component = DefaultComponent } = useStackShiftUIComponents();
|
|
55
10
|
|
|
56
|
-
|
|
57
|
-
<>
|
|
58
|
-
{!noLabel && (
|
|
59
|
-
<label htmlFor={name} className={labelClass}>
|
|
60
|
-
{label || name}
|
|
61
|
-
</label>
|
|
62
|
-
)}
|
|
11
|
+
return (
|
|
63
12
|
<Component
|
|
64
|
-
as=
|
|
65
|
-
{
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
placeholder={placeholder}
|
|
71
|
-
name={name}
|
|
72
|
-
required={required}
|
|
73
|
-
id={name}
|
|
13
|
+
as="textarea"
|
|
14
|
+
className={cn(
|
|
15
|
+
"flex min-h-[80px] w-full rounded-md border border-input bg-background px-3 py-2 text-base ring-offset-background placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 md:text-sm",
|
|
16
|
+
className,
|
|
17
|
+
)}
|
|
18
|
+
ref={ref}
|
|
74
19
|
{...props}
|
|
75
20
|
/>
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
21
|
+
);
|
|
22
|
+
},
|
|
23
|
+
);
|
|
80
24
|
Textarea.displayName = displayName;
|
|
25
|
+
|
|
26
|
+
export { Textarea };
|