react-restyle-components 0.3.80 → 0.3.81
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/lib/src/core-components/src/components/FormField/components/CssMultilineInput.d.ts +4 -1
- package/lib/src/core-components/src/components/FormField/components/CssMultilineInput.d.ts.map +1 -1
- package/lib/src/core-components/src/components/FormField/components/CssMultilineInput.js +61 -7
- package/lib/src/core-components/src/core-components/atoms/Input/Input.d.ts +5 -1
- package/lib/src/core-components/src/core-components/atoms/Input/Input.d.ts.map +1 -1
- package/lib/src/core-components/src/core-components/atoms/Input/Input.js +59 -2
- package/lib/src/core-components/src/core-components/atoms/Textarea/Textarea.d.ts +5 -1
- package/lib/src/core-components/src/core-components/atoms/Textarea/Textarea.d.ts.map +1 -1
- package/lib/src/core-components/src/core-components/atoms/Textarea/Textarea.js +59 -2
- package/package.json +1 -1
|
@@ -5,7 +5,10 @@ export interface CssMultilineInputProps {
|
|
|
5
5
|
error?: string;
|
|
6
6
|
required?: boolean;
|
|
7
7
|
value?: string;
|
|
8
|
-
onChange
|
|
8
|
+
/** onChange handler - supports both standard React event or direct value callback */
|
|
9
|
+
onChange?: (e: React.ChangeEvent<HTMLTextAreaElement> | string) => void;
|
|
10
|
+
/** onBlur handler - supports both standard React event or direct value callback */
|
|
11
|
+
onBlur?: (e: React.FocusEvent<HTMLTextAreaElement> | string) => void;
|
|
9
12
|
disabled?: boolean;
|
|
10
13
|
cssProperties?: Array<[string, string[]]>;
|
|
11
14
|
onReset?: (value: string) => void;
|
package/lib/src/core-components/src/components/FormField/components/CssMultilineInput.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CssMultilineInput.d.ts","sourceRoot":"","sources":["../../../../../../../src/core-components/src/components/FormField/components/CssMultilineInput.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAoC,MAAM,OAAO,CAAC;AAkBzD,MAAM,WAAW,sBAAsB;IACrC,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;
|
|
1
|
+
{"version":3,"file":"CssMultilineInput.d.ts","sourceRoot":"","sources":["../../../../../../../src/core-components/src/components/FormField/components/CssMultilineInput.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAoC,MAAM,OAAO,CAAC;AAkBzD,MAAM,WAAW,sBAAsB;IACrC,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,qFAAqF;IACrF,QAAQ,CAAC,EAAE,CAAC,CAAC,EAAE,KAAK,CAAC,WAAW,CAAC,mBAAmB,CAAC,GAAG,MAAM,KAAK,IAAI,CAAC;IACxE,mFAAmF;IACnF,MAAM,CAAC,EAAE,CAAC,CAAC,EAAE,KAAK,CAAC,UAAU,CAAC,mBAAmB,CAAC,GAAG,MAAM,KAAK,IAAI,CAAC;IACrE,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,aAAa,CAAC,EAAE,KAAK,CAAC,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,CAAC,CAAC;IAC1C,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IAClC,UAAU,CAAC,EAAE,MAAM,IAAI,CAAC;IACxB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,UAAU,CAAC,EAAE,GAAG,CAAC;IACjB,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;CACpB;AAED,eAAO,MAAM,iBAAiB,iHA8R7B,CAAC"}
|
|
@@ -15,7 +15,7 @@ const mapToArray = (arr) => {
|
|
|
15
15
|
});
|
|
16
16
|
return res;
|
|
17
17
|
};
|
|
18
|
-
export const CssMultilineInput = React.forwardRef(({ id, label, error, required, value, onChange, disabled, cssProperties, onReset, onMoreInfo, placeholder = "fontSize: 12,backgroundColor:'#000000'", className, labelProps, ...props }, ref) => {
|
|
18
|
+
export const CssMultilineInput = React.forwardRef(({ id, label, error, required, value, onChange, onBlur, disabled, cssProperties, onReset, onMoreInfo, placeholder = "fontSize: 12,backgroundColor:'#000000'", className, labelProps, ...props }, ref) => {
|
|
19
19
|
const [isCssListOpen, setIsCssListOpen] = useState(false);
|
|
20
20
|
const [cssPropertiesList, setCssPropertiesList] = useState(cssProperties || mapToArray(defaultCssProperties));
|
|
21
21
|
const cssValueRef = useRef(value || '');
|
|
@@ -62,8 +62,64 @@ export const CssMultilineInput = React.forwardRef(({ id, label, error, required,
|
|
|
62
62
|
const handleCssChange = (css) => {
|
|
63
63
|
cssValueRef.current = css;
|
|
64
64
|
handleCssFilter(css);
|
|
65
|
+
};
|
|
66
|
+
// Handle onChange - support both event and value patterns
|
|
67
|
+
const handleChange = (e) => {
|
|
68
|
+
const css = e.target.value;
|
|
69
|
+
handleCssChange(css);
|
|
70
|
+
setIsCssListOpen(true);
|
|
65
71
|
if (onChange) {
|
|
66
|
-
|
|
72
|
+
// Support both patterns:
|
|
73
|
+
// 1. Standard React: onChange={(e) => { const val = e.target.value; ... }}
|
|
74
|
+
// 2. Custom: onChange={(value) => { ... value ... }}
|
|
75
|
+
// Check if onChange expects a string (custom pattern) by examining function signature
|
|
76
|
+
// If parameter name suggests it expects a value (not 'e' or 'event'), call with value
|
|
77
|
+
// Otherwise, call with event (standard React pattern)
|
|
78
|
+
const funcStr = onChange.toString();
|
|
79
|
+
const paramMatch = funcStr.match(/\(([^)]+)\)/);
|
|
80
|
+
if (paramMatch) {
|
|
81
|
+
const param = paramMatch[1].trim();
|
|
82
|
+
// If parameter is not 'e', 'event', or starts with 'e:', it might expect value
|
|
83
|
+
if (param &&
|
|
84
|
+
param !== 'e' &&
|
|
85
|
+
param !== 'event' &&
|
|
86
|
+
!param.startsWith('e:')) {
|
|
87
|
+
// Custom pattern - call with value
|
|
88
|
+
onChange(css);
|
|
89
|
+
}
|
|
90
|
+
else {
|
|
91
|
+
// Standard React pattern - call with event
|
|
92
|
+
onChange(e);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
else {
|
|
96
|
+
// Default to standard React pattern
|
|
97
|
+
onChange(e);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
};
|
|
101
|
+
// Handle onBlur - support both event and value patterns
|
|
102
|
+
const handleBlur = (e) => {
|
|
103
|
+
if (onBlur) {
|
|
104
|
+
const css = e.target.value;
|
|
105
|
+
// Similar logic for onBlur
|
|
106
|
+
const funcStr = onBlur.toString();
|
|
107
|
+
const paramMatch = funcStr.match(/\(([^)]+)\)/);
|
|
108
|
+
if (paramMatch) {
|
|
109
|
+
const param = paramMatch[1].trim();
|
|
110
|
+
if (param &&
|
|
111
|
+
param !== 'e' &&
|
|
112
|
+
param !== 'event' &&
|
|
113
|
+
!param.startsWith('e:')) {
|
|
114
|
+
onBlur(css);
|
|
115
|
+
}
|
|
116
|
+
else {
|
|
117
|
+
onBlur(e);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
else {
|
|
121
|
+
onBlur(e);
|
|
122
|
+
}
|
|
67
123
|
}
|
|
68
124
|
};
|
|
69
125
|
const handleReset = () => {
|
|
@@ -79,14 +135,12 @@ export const CssMultilineInput = React.forwardRef(({ id, label, error, required,
|
|
|
79
135
|
onReset(cssValueRef.current);
|
|
80
136
|
}
|
|
81
137
|
if (onChange) {
|
|
138
|
+
// When resetting, we call onChange with the value directly (custom pattern)
|
|
139
|
+
// since we don't have an event object
|
|
82
140
|
onChange(cssValueRef.current);
|
|
83
141
|
}
|
|
84
142
|
};
|
|
85
|
-
return (_jsxs("div", { className: cn(s['flex'], s['flex-col'], s['w-full'], s['relative'], className), ref: cssWrapperRef, children: [_jsxs("div", { className: cn(s['flex'], s['absolute'], s['gap-2'], s['right-2'], s['z-10']), children: [onReset && (_jsx(Icon, { nameIcon: "MdLockReset", propsIcon: { color: '#000000', size: 24 }, onClick: handleReset })), onMoreInfo && (_jsx(Icon, { nameIcon: "MdInfoOutline", propsIcon: { color: '#000000', size: 24 }, onClick: onMoreInfo }))] }), _jsx(Textarea, { ref: ref, id: id, label: label, error: error, required: required, placeholder: placeholder, value: cssValueRef.current, onChange: (
|
|
86
|
-
const css = e.target.value;
|
|
87
|
-
handleCssChange(css);
|
|
88
|
-
setIsCssListOpen(true);
|
|
89
|
-
}, onKeyUp: () => setIsCssListOpen(true), disabled: disabled, ...labelProps, ...props }), isCssListOpen && cssPropertiesList.length > 0 && (_jsx("div", { children: _jsx("ul", { className: cn(s['flex'], s['flex-col'], s['bg-black'], s['text-white'], s['overflow-y-scroll'], s['w-full']), style: { maxHeight: 'calc(100vh - 20vh)' }, children: cssPropertiesList?.map((item, index) => (_jsxs("li", { className: cn(s['flex'], s['gap-4'], s['p-2']), children: [_jsx("span", { className: cn(s['underline']), children: item[0] }), item[1]?.map((prop, propIndex) => (_jsxs("li", { className: cn(s['flex'], s['bg-slate-800'], s['rounded-md'], s['items-center'], s['cursor-pointer']), onClick: () => {
|
|
143
|
+
return (_jsxs("div", { className: cn(s['flex'], s['flex-col'], s['w-full'], s['relative'], className), ref: cssWrapperRef, children: [_jsxs("div", { className: cn(s['flex'], s['absolute'], s['gap-2'], s['right-2'], s['z-10']), children: [onReset && (_jsx(Icon, { nameIcon: "MdLockReset", propsIcon: { color: '#000000', size: 24 }, onClick: handleReset })), onMoreInfo && (_jsx(Icon, { nameIcon: "MdInfoOutline", propsIcon: { color: '#000000', size: 24 }, onClick: onMoreInfo }))] }), _jsx(Textarea, { ref: ref, id: id, label: label, error: error, required: required, placeholder: placeholder, value: cssValueRef.current, onChange: handleChange, onBlur: handleBlur, onKeyUp: () => setIsCssListOpen(true), disabled: disabled, ...labelProps, ...props }), isCssListOpen && cssPropertiesList.length > 0 && (_jsx("div", { children: _jsx("ul", { className: cn(s['flex'], s['flex-col'], s['bg-black'], s['text-white'], s['overflow-y-scroll'], s['w-full']), style: { maxHeight: 'calc(100vh - 20vh)' }, children: cssPropertiesList?.map((item, index) => (_jsxs("li", { className: cn(s['flex'], s['gap-4'], s['p-2']), children: [_jsx("span", { className: cn(s['underline']), children: item[0] }), item[1]?.map((prop, propIndex) => (_jsxs("li", { className: cn(s['flex'], s['bg-slate-800'], s['rounded-md'], s['items-center'], s['cursor-pointer']), onClick: () => {
|
|
90
144
|
let existsString = cssValueRef.current?.split(',');
|
|
91
145
|
if (cssValueRef.current.includes(',')) {
|
|
92
146
|
existsString = existsString.map((item) => {
|
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
export interface InputProps extends React.InputHTMLAttributes<HTMLInputElement> {
|
|
2
|
+
export interface InputProps extends Omit<React.InputHTMLAttributes<HTMLInputElement>, 'onChange' | 'onBlur'> {
|
|
3
3
|
error?: string;
|
|
4
4
|
label?: string;
|
|
5
|
+
/** onChange handler - supports both standard React event or direct value callback */
|
|
6
|
+
onChange?: (e: React.ChangeEvent<HTMLInputElement> | string) => void;
|
|
7
|
+
/** onBlur handler - supports both standard React event or direct value callback */
|
|
8
|
+
onBlur?: (e: React.FocusEvent<HTMLInputElement> | string) => void;
|
|
5
9
|
}
|
|
6
10
|
export declare const Input: React.ForwardRefExoticComponent<InputProps & React.RefAttributes<HTMLInputElement>>;
|
|
7
11
|
//# sourceMappingURL=Input.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Input.d.ts","sourceRoot":"","sources":["../../../../../../../src/core-components/src/core-components/atoms/Input/Input.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAI1B,MAAM,WAAW,UACf,SAAQ,KAAK,CAAC,mBAAmB,CAAC,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"Input.d.ts","sourceRoot":"","sources":["../../../../../../../src/core-components/src/core-components/atoms/Input/Input.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAI1B,MAAM,WAAW,UACf,SAAQ,IAAI,CACV,KAAK,CAAC,mBAAmB,CAAC,gBAAgB,CAAC,EAC3C,UAAU,GAAG,QAAQ,CACtB;IACD,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,qFAAqF;IACrF,QAAQ,CAAC,EAAE,CAAC,CAAC,EAAE,KAAK,CAAC,WAAW,CAAC,gBAAgB,CAAC,GAAG,MAAM,KAAK,IAAI,CAAC;IACrE,mFAAmF;IACnF,MAAM,CAAC,EAAE,CAAC,CAAC,EAAE,KAAK,CAAC,UAAU,CAAC,gBAAgB,CAAC,GAAG,MAAM,KAAK,IAAI,CAAC;CACnE;AAED,eAAO,MAAM,KAAK,qFAuIjB,CAAC"}
|
|
@@ -2,11 +2,68 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
|
2
2
|
import React from 'react';
|
|
3
3
|
import s from '../../../tc.module.css';
|
|
4
4
|
import { cn } from '../../../utils';
|
|
5
|
-
export const Input = React.forwardRef(({ className, error, label, id, ...props }, ref) => {
|
|
5
|
+
export const Input = React.forwardRef(({ className, error, label, id, onChange, onBlur, ...props }, ref) => {
|
|
6
6
|
const inputId = id || `input-${Math.random().toString(36).substr(2, 9)}`;
|
|
7
|
+
// Handle onChange - support both event and value patterns
|
|
8
|
+
const handleChange = (e) => {
|
|
9
|
+
if (onChange) {
|
|
10
|
+
const value = e.target.value;
|
|
11
|
+
// Support both patterns:
|
|
12
|
+
// 1. Standard React: onChange={(e) => { const val = e.target.value; ... }}
|
|
13
|
+
// 2. Custom: onChange={(value) => { ... value ... }}
|
|
14
|
+
// Check if onChange expects a string (custom pattern) by examining function signature
|
|
15
|
+
// If parameter name suggests it expects a value (not 'e' or 'event'), call with value
|
|
16
|
+
// Otherwise, call with event (standard React pattern)
|
|
17
|
+
const funcStr = onChange.toString();
|
|
18
|
+
const paramMatch = funcStr.match(/\(([^)]+)\)/);
|
|
19
|
+
if (paramMatch) {
|
|
20
|
+
const param = paramMatch[1].trim();
|
|
21
|
+
// If parameter is not 'e', 'event', or starts with 'e:', it might expect value
|
|
22
|
+
if (param &&
|
|
23
|
+
param !== 'e' &&
|
|
24
|
+
param !== 'event' &&
|
|
25
|
+
!param.startsWith('e:')) {
|
|
26
|
+
// Custom pattern - call with value
|
|
27
|
+
onChange(value);
|
|
28
|
+
}
|
|
29
|
+
else {
|
|
30
|
+
// Standard React pattern - call with event
|
|
31
|
+
onChange(e);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
// Default to standard React pattern
|
|
36
|
+
onChange(e);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
// Handle onBlur - support both event and value patterns
|
|
41
|
+
const handleBlur = (e) => {
|
|
42
|
+
if (onBlur) {
|
|
43
|
+
const value = e.target.value;
|
|
44
|
+
// Similar logic for onBlur
|
|
45
|
+
const funcStr = onBlur.toString();
|
|
46
|
+
const paramMatch = funcStr.match(/\(([^)]+)\)/);
|
|
47
|
+
if (paramMatch) {
|
|
48
|
+
const param = paramMatch[1].trim();
|
|
49
|
+
if (param &&
|
|
50
|
+
param !== 'e' &&
|
|
51
|
+
param !== 'event' &&
|
|
52
|
+
!param.startsWith('e:')) {
|
|
53
|
+
onBlur(value);
|
|
54
|
+
}
|
|
55
|
+
else {
|
|
56
|
+
onBlur(e);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
else {
|
|
60
|
+
onBlur(e);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
};
|
|
7
64
|
return (_jsxs("div", { className: cn(s['w-full']), children: [label && (_jsx("label", { className: cn(s['block'], s['text-sm'], s['font-medium'], s['text-gray-700'], s['dark:text-gray-300'], s['mb-1']), children: label })), _jsx("input", { ref: ref, id: inputId, className: cn(s['w-full'], s['px-4'], s['py-2'], s['border'], s['rounded-lg'], s['transition-colors'], s['bg-white'], s['dark:bg-gray-800'], s['border-gray-300'], s['dark:border-gray-600'], s['text-gray-900'], s['dark:text-gray-100'], s['placeholder-gray-500'], s['dark:placeholder-gray-400'], s['focus:outline-none'], s['focus:ring-2'], s['focus:ring-primary'], s['focus:ring-offset-1'], error && s['border-red-500'], error && s['focus:ring-red-500'], className), style: {
|
|
8
65
|
...props.style,
|
|
9
66
|
'--tw-ring-offset-color': '#ffffff',
|
|
10
|
-
}, ...props }), error && (_jsx("p", { className: cn(s['mt-1'], s['text-sm'], s['text-red-600'], s['dark:text-red-400']), children: error }))] }));
|
|
67
|
+
}, onChange: handleChange, onBlur: handleBlur, ...props }), error && (_jsx("p", { className: cn(s['mt-1'], s['text-sm'], s['text-red-600'], s['dark:text-red-400']), children: error }))] }));
|
|
11
68
|
});
|
|
12
69
|
Input.displayName = 'Input';
|
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
export interface TextareaProps extends React.TextareaHTMLAttributes<HTMLTextAreaElement> {
|
|
2
|
+
export interface TextareaProps extends Omit<React.TextareaHTMLAttributes<HTMLTextAreaElement>, 'onChange' | 'onBlur'> {
|
|
3
3
|
error?: string;
|
|
4
4
|
label?: string;
|
|
5
|
+
/** onChange handler - supports both standard React event or direct value callback */
|
|
6
|
+
onChange?: (e: React.ChangeEvent<HTMLTextAreaElement> | string) => void;
|
|
7
|
+
/** onBlur handler - supports both standard React event or direct value callback */
|
|
8
|
+
onBlur?: (e: React.FocusEvent<HTMLTextAreaElement> | string) => void;
|
|
5
9
|
}
|
|
6
10
|
export declare const Textarea: React.ForwardRefExoticComponent<TextareaProps & React.RefAttributes<HTMLTextAreaElement>>;
|
|
7
11
|
//# sourceMappingURL=Textarea.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Textarea.d.ts","sourceRoot":"","sources":["../../../../../../../src/core-components/src/core-components/atoms/Textarea/Textarea.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAI1B,MAAM,WAAW,aACf,SAAQ,KAAK,CAAC,sBAAsB,CAAC,mBAAmB,CAAC;
|
|
1
|
+
{"version":3,"file":"Textarea.d.ts","sourceRoot":"","sources":["../../../../../../../src/core-components/src/core-components/atoms/Textarea/Textarea.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAI1B,MAAM,WAAW,aACf,SAAQ,IAAI,CACV,KAAK,CAAC,sBAAsB,CAAC,mBAAmB,CAAC,EACjD,UAAU,GAAG,QAAQ,CACtB;IACD,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,qFAAqF;IACrF,QAAQ,CAAC,EAAE,CAAC,CAAC,EAAE,KAAK,CAAC,WAAW,CAAC,mBAAmB,CAAC,GAAG,MAAM,KAAK,IAAI,CAAC;IACxE,mFAAmF;IACnF,MAAM,CAAC,EAAE,CAAC,CAAC,EAAE,KAAK,CAAC,UAAU,CAAC,mBAAmB,CAAC,GAAG,MAAM,KAAK,IAAI,CAAC;CACtE;AAED,eAAO,MAAM,QAAQ,2FAmIpB,CAAC"}
|
|
@@ -2,8 +2,65 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
|
2
2
|
import React from 'react';
|
|
3
3
|
import s from '../../../tc.module.css';
|
|
4
4
|
import { cn } from '../../../utils';
|
|
5
|
-
export const Textarea = React.forwardRef(({ className, error, label, id, ...props }, ref) => {
|
|
5
|
+
export const Textarea = React.forwardRef(({ className, error, label, id, onChange, onBlur, ...props }, ref) => {
|
|
6
6
|
const textareaId = id || `textarea-${Math.random().toString(36).substr(2, 9)}`;
|
|
7
|
-
|
|
7
|
+
// Handle onChange - support both event and value patterns
|
|
8
|
+
const handleChange = (e) => {
|
|
9
|
+
if (onChange) {
|
|
10
|
+
const value = e.target.value;
|
|
11
|
+
// Support both patterns:
|
|
12
|
+
// 1. Standard React: onChange={(e) => { const val = e.target.value; ... }}
|
|
13
|
+
// 2. Custom: onChange={(value) => { ... value ... }}
|
|
14
|
+
// Check if onChange expects a string (custom pattern) by examining function signature
|
|
15
|
+
// If parameter name suggests it expects a value (not 'e' or 'event'), call with value
|
|
16
|
+
// Otherwise, call with event (standard React pattern)
|
|
17
|
+
const funcStr = onChange.toString();
|
|
18
|
+
const paramMatch = funcStr.match(/\(([^)]+)\)/);
|
|
19
|
+
if (paramMatch) {
|
|
20
|
+
const param = paramMatch[1].trim();
|
|
21
|
+
// If parameter is not 'e', 'event', or starts with 'e:', it might expect value
|
|
22
|
+
if (param &&
|
|
23
|
+
param !== 'e' &&
|
|
24
|
+
param !== 'event' &&
|
|
25
|
+
!param.startsWith('e:')) {
|
|
26
|
+
// Custom pattern - call with value
|
|
27
|
+
onChange(value);
|
|
28
|
+
}
|
|
29
|
+
else {
|
|
30
|
+
// Standard React pattern - call with event
|
|
31
|
+
onChange(e);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
// Default to standard React pattern
|
|
36
|
+
onChange(e);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
// Handle onBlur - support both event and value patterns
|
|
41
|
+
const handleBlur = (e) => {
|
|
42
|
+
if (onBlur) {
|
|
43
|
+
const value = e.target.value;
|
|
44
|
+
// Similar logic for onBlur
|
|
45
|
+
const funcStr = onBlur.toString();
|
|
46
|
+
const paramMatch = funcStr.match(/\(([^)]+)\)/);
|
|
47
|
+
if (paramMatch) {
|
|
48
|
+
const param = paramMatch[1].trim();
|
|
49
|
+
if (param &&
|
|
50
|
+
param !== 'e' &&
|
|
51
|
+
param !== 'event' &&
|
|
52
|
+
!param.startsWith('e:')) {
|
|
53
|
+
onBlur(value);
|
|
54
|
+
}
|
|
55
|
+
else {
|
|
56
|
+
onBlur(e);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
else {
|
|
60
|
+
onBlur(e);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
return (_jsxs("div", { className: cn(s['w-full']), children: [label && (_jsx("label", { className: cn(s['block'], s['text-sm'], s['font-medium'], s['text-gray-700'], s['dark:text-gray-300'], s['mb-1']), children: label })), _jsx("textarea", { ref: ref, id: textareaId, className: cn(s['w-full'], s['px-4'], s['py-2'], s['border'], s['rounded-lg'], s['transition-colors'], s['resize-vertical'], s['bg-white'], s['dark:bg-gray-800'], s['border-gray-300'], s['dark:border-gray-600'], s['text-gray-900'], s['dark:text-gray-100'], s['placeholder-gray-500'], s['dark:placeholder-gray-400'], s['focus:outline-none'], s['focus:ring-2'], s['focus:ring-primary'], s['focus:ring-offset-1'], error && s['border-red-500'], error && s['focus:ring-red-500'], className), onChange: handleChange, onBlur: handleBlur, ...props }), error && (_jsx("p", { className: cn(s['mt-1'], s['text-sm'], s['text-red-600'], s['dark:text-red-400']), children: error }))] }));
|
|
8
65
|
});
|
|
9
66
|
Textarea.displayName = 'Textarea';
|