@stackshift-ui/textarea 6.0.2 → 6.0.3

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 CHANGED
@@ -1,14 +1,15 @@
1
1
  {
2
2
  "name": "@stackshift-ui/textarea",
3
3
  "description": "",
4
- "version": "6.0.2",
4
+ "version": "6.0.3",
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": {
@@ -33,8 +34,8 @@
33
34
  },
34
35
  "dependencies": {
35
36
  "classnames": "^2.5.1",
36
- "@stackshift-ui/system": "6.0.2",
37
- "@stackshift-ui/scripts": "6.0.2"
37
+ "@stackshift-ui/scripts": "6.0.2",
38
+ "@stackshift-ui/system": "6.0.3"
38
39
  },
39
40
  "peerDependencies": {
40
41
  "@types/react": "16.8 - 19",
package/src/index.ts ADDED
@@ -0,0 +1,4 @@
1
+ "use client";
2
+
3
+ // component exports
4
+ export * from "./textarea";
@@ -0,0 +1,13 @@
1
+ import { cleanup, render, screen } from "@testing-library/react";
2
+ import { afterEach, describe, test } from "vitest";
3
+ import { Textarea } from "./textarea";
4
+
5
+ describe.concurrent("textarea", () => {
6
+ afterEach(cleanup);
7
+
8
+ test("Common: Textarea - test if renders without errors", ({ expect }) => {
9
+ const clx = "textarea-class";
10
+ render(<Textarea className={clx} name="stackshift-textarea" ariaLabel="text area" />);
11
+ expect(screen.getByTestId("textarea").classList).toContain(clx);
12
+ });
13
+ });
@@ -0,0 +1,80 @@
1
+ import { DefaultComponent, useStackShiftUIComponents } from "@stackshift-ui/system";
2
+ import cn from "classnames";
3
+ import type { ElementType, HTMLProps, ReactNode } from "react";
4
+
5
+ type StyleVariants<T extends string> = Record<T, string>;
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
+ }
23
+
24
+ const displayName = "Textarea";
25
+
26
+ export const Textarea: React.FC<TextareaProps> = ({
27
+ required = false,
28
+ name,
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 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;
55
+
56
+ return (
57
+ <>
58
+ {!noLabel && (
59
+ <label htmlFor={name} className={labelClass}>
60
+ {label || name}
61
+ </label>
62
+ )}
63
+ <Component
64
+ as={as}
65
+ {...props}
66
+ data-testid={displayName}
67
+ onChange={onChange}
68
+ aria-label={ariaLabel || name}
69
+ className={cn(variantClass, className)}
70
+ placeholder={placeholder}
71
+ name={name}
72
+ required={required}
73
+ id={name}
74
+ {...props}
75
+ />
76
+ </>
77
+ );
78
+ };
79
+
80
+ Textarea.displayName = displayName;