@dust-tt/sparkle 0.2.236 → 0.2.237
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/cjs/index.js +2 -16
- package/dist/cjs/index.js.map +1 -1
- package/dist/esm/components/TextArea.d.ts +2 -2
- package/dist/esm/components/TextArea.d.ts.map +1 -1
- package/dist/esm/components/TextArea.js +3 -17
- package/dist/esm/components/TextArea.js.map +1 -1
- package/dist/esm/stories/TextArea.stories.js +1 -1
- package/dist/esm/stories/TextArea.stories.js.map +1 -1
- package/package.json +1 -1
- package/src/components/TextArea.tsx +4 -20
- package/src/stories/TextArea.stories.tsx +1 -1
|
@@ -6,8 +6,8 @@ type TextAreaProps = {
|
|
|
6
6
|
error?: string | null;
|
|
7
7
|
showErrorLabel?: boolean;
|
|
8
8
|
className?: string;
|
|
9
|
-
|
|
9
|
+
minRows?: number;
|
|
10
10
|
};
|
|
11
|
-
export declare function TextArea({ placeholder, value, onChange, error, showErrorLabel, className,
|
|
11
|
+
export declare function TextArea({ placeholder, value, onChange, error, showErrorLabel, className, minRows }: TextAreaProps): React.JSX.Element;
|
|
12
12
|
export {};
|
|
13
13
|
//# sourceMappingURL=TextArea.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TextArea.d.ts","sourceRoot":"","sources":["../../../src/components/TextArea.tsx"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"TextArea.d.ts","sourceRoot":"","sources":["../../../src/components/TextArea.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAiB,MAAM,OAAO,CAAC;AAItC,KAAK,aAAa,GAAG;IACnB,WAAW,EAAE,MAAM,CAAC;IACpB,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IACrB,QAAQ,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IAClC,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACtB,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB,CAAC;AAEF,wBAAgB,QAAQ,CAAC,EACvB,WAAW,EACX,KAAK,EACL,QAAQ,EACR,KAAK,EACL,cAAsB,EACtB,SAAS,EACT,OAAY,EACb,EAAE,aAAa,qBA4Bf"}
|
|
@@ -1,26 +1,12 @@
|
|
|
1
|
-
import React, {
|
|
1
|
+
import React, { useRef } from "react";
|
|
2
2
|
import { classNames } from "../lib/utils";
|
|
3
3
|
export function TextArea(_a) {
|
|
4
|
-
var placeholder = _a.placeholder, value = _a.value, onChange = _a.onChange, error = _a.error, _b = _a.showErrorLabel, showErrorLabel = _b === void 0 ? false : _b, className = _a.className, _c = _a.
|
|
4
|
+
var placeholder = _a.placeholder, value = _a.value, onChange = _a.onChange, error = _a.error, _b = _a.showErrorLabel, showErrorLabel = _b === void 0 ? false : _b, className = _a.className, _c = _a.minRows, minRows = _c === void 0 ? 10 : _c;
|
|
5
5
|
var textareaRef = useRef(null);
|
|
6
|
-
useEffect(function () {
|
|
7
|
-
var textarea = textareaRef.current;
|
|
8
|
-
if (textarea) {
|
|
9
|
-
textarea.style.height = 'auto'; // Reset height
|
|
10
|
-
textarea.style.height = "".concat(textarea.scrollHeight, "px"); // Set to scroll height
|
|
11
|
-
}
|
|
12
|
-
}, [value]); // Re-run when value changes
|
|
13
6
|
return (React.createElement("div", { className: "s-flex s-flex-col s-gap-1 s-p-px" },
|
|
14
|
-
React.createElement("textarea", { rows:
|
|
7
|
+
React.createElement("textarea", { rows: minRows, ref: textareaRef, className: classNames("overflow-y-auto s-block s-w-full s-min-w-0 s-rounded-xl s-text-sm s-placeholder-element-700 s-transition-all s-duration-200 s-scrollbar-hide", !error
|
|
15
8
|
? "s-border-structure-100 focus:s-border-action-300 focus:s-ring-action-300"
|
|
16
9
|
: "s-border-red-500 focus:s-border-red-500 focus:s-ring-red-500", "s-border-structure-200 s-bg-structure-50", "s-resize-y", className !== null && className !== void 0 ? className : ""), placeholder: placeholder, value: value !== null && value !== void 0 ? value : "", onChange: function (e) {
|
|
17
|
-
var newValue = e.target.value;
|
|
18
|
-
var textAreaComponent = textareaRef.current;
|
|
19
|
-
if (textAreaComponent &&
|
|
20
|
-
(value === null || value === void 0 ? void 0 : value.length) &&
|
|
21
|
-
newValue.length < value.length) {
|
|
22
|
-
textAreaComponent.style.height = "auto"; // Reset height to recalculate
|
|
23
|
-
}
|
|
24
10
|
onChange(e.target.value);
|
|
25
11
|
} }),
|
|
26
12
|
error && showErrorLabel && (React.createElement("div", { className: "s-ml-2 s-text-sm s-text-warning-500" }, error))));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TextArea.js","sourceRoot":"","sources":["../../../src/components/TextArea.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,
|
|
1
|
+
{"version":3,"file":"TextArea.js","sourceRoot":"","sources":["../../../src/components/TextArea.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AAEtC,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAYhD,MAAM,UAAU,QAAQ,CAAC,EAQT;QAPd,WAAW,iBAAA,EACX,KAAK,WAAA,EACL,QAAQ,cAAA,EACR,KAAK,WAAA,EACL,sBAAsB,EAAtB,cAAc,mBAAG,KAAK,KAAA,EACtB,SAAS,eAAA,EACT,eAAY,EAAZ,OAAO,mBAAG,EAAE,KAAA;IAEZ,IAAM,WAAW,GAAG,MAAM,CAAsB,IAAI,CAAC,CAAC;IAEtD,OAAO,CACL,6BAAK,SAAS,EAAC,kCAAkC;QAC/C,kCACE,IAAI,EAAE,OAAO,EACb,GAAG,EAAE,WAAW,EAChB,SAAS,EAAE,UAAU,CACnB,8IAA8I,EAC9I,CAAC,KAAK;gBACJ,CAAC,CAAC,0EAA0E;gBAC5E,CAAC,CAAC,8DAA8D,EAClE,0CAA0C,EAC1C,YAAY,EACZ,SAAS,aAAT,SAAS,cAAT,SAAS,GAAI,EAAE,CAChB,EACD,WAAW,EAAE,WAAW,EACxB,KAAK,EAAE,KAAK,aAAL,KAAK,cAAL,KAAK,GAAI,EAAE,EAClB,QAAQ,EAAE,UAAC,CAAC;gBACV,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;YAC3B,CAAC,GACD;QACD,KAAK,IAAI,cAAc,IAAI,CAC1B,6BAAK,SAAS,EAAC,qCAAqC,IAAE,KAAK,CAAO,CACnE,CACG,CACP,CAAC;AACJ,CAAC"}
|
|
@@ -17,7 +17,7 @@ export var TextAreaExample = function () {
|
|
|
17
17
|
React.createElement("div", { className: "s-grid s-grid-cols-3 s-gap-4" },
|
|
18
18
|
React.createElement(TextArea, { placeholder: "placeholder", value: textValues[0], onChange: function (v) {
|
|
19
19
|
return setTextValues([v, textValues[1], textValues[2], textValues[3]]);
|
|
20
|
-
},
|
|
20
|
+
}, minRows: 2 }),
|
|
21
21
|
React.createElement(TextArea, { placeholder: "placeholder", value: textValues[1], error: "errored because blah", onChange: function (v) {
|
|
22
22
|
return setTextValues([textValues[0], v, textValues[2], textValues[3]]);
|
|
23
23
|
}, showErrorLabel: true }),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TextArea.stories.js","sourceRoot":"","sources":["../../../src/stories/TextArea.stories.tsx"],"names":[],"mappings":";AACA,OAAO,KAAK,EAAE,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAExC,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AAEjD,IAAM,IAAI,GAAG;IACX,KAAK,EAAE,qBAAqB;IAC5B,SAAS,EAAE,QAAQ;CACY,CAAC;AAElC,eAAe,IAAI,CAAC;AAEpB,MAAM,CAAC,IAAM,eAAe,GAAG;IACvB,IAAA,KAAA,OAA8B,QAAQ,CAAC;QAC3C,EAAE;QACF,kBAAkB;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AC,EAAE,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC;gBAA/D,CAA+D,EAEjE,OAAO,EAAE,CAAC,GACV;YACF,oBAAC,QAAQ,IACP,WAAW,EAAC,aAAa,EACzB,KAAK,EAAE,UAAU,CAAC,CAAC,CAAC,EACpB,KAAK,EAAE,sBAAsB,EAC7B,QAAQ,EAAE,UAAC,CAAC;oBACV,OAAA,aAAa,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,UAAU,CAAC,CAAC,CAAC,EAAE,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC;gBAA/D,CAA+D,EAEjE,cAAc,SACd;YACF,oBAAC,QAAQ,IACP,WAAW,EAAC,aAAa,EACzB,KAAK,EAAE,UAAU,CAAC,CAAC,CAAC,EACpB,QAAQ,EAAE,UAAC,CAAC;oBACV,OAAA,aAAa,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,EAAE,UAAU,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC;gBAA/D,CAA+D,EAEjE,KAAK,EAAE,sBAAsB,GAC7B,CACE,CACF,CACP,CAAC;AACJ,CAAC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React, {
|
|
1
|
+
import React, { useRef } from "react";
|
|
2
2
|
|
|
3
3
|
import { classNames } from "@sparkle/lib/utils";
|
|
4
4
|
|
|
@@ -9,7 +9,7 @@ type TextAreaProps = {
|
|
|
9
9
|
error?: string | null;
|
|
10
10
|
showErrorLabel?: boolean;
|
|
11
11
|
className?: string;
|
|
12
|
-
|
|
12
|
+
minRows?: number;
|
|
13
13
|
};
|
|
14
14
|
|
|
15
15
|
export function TextArea({
|
|
@@ -19,21 +19,14 @@ export function TextArea({
|
|
|
19
19
|
error,
|
|
20
20
|
showErrorLabel = false,
|
|
21
21
|
className,
|
|
22
|
-
|
|
22
|
+
minRows = 10
|
|
23
23
|
}: TextAreaProps) {
|
|
24
24
|
const textareaRef = useRef<HTMLTextAreaElement>(null);
|
|
25
25
|
|
|
26
|
-
useEffect(() => {
|
|
27
|
-
const textarea = textareaRef.current;
|
|
28
|
-
if (textarea) {
|
|
29
|
-
textarea.style.height = 'auto'; // Reset height
|
|
30
|
-
textarea.style.height = `${textarea.scrollHeight}px`; // Set to scroll height
|
|
31
|
-
}
|
|
32
|
-
}, [value]); // Re-run when value changes
|
|
33
26
|
return (
|
|
34
27
|
<div className="s-flex s-flex-col s-gap-1 s-p-px">
|
|
35
28
|
<textarea
|
|
36
|
-
rows={
|
|
29
|
+
rows={minRows}
|
|
37
30
|
ref={textareaRef}
|
|
38
31
|
className={classNames(
|
|
39
32
|
"overflow-y-auto s-block s-w-full s-min-w-0 s-rounded-xl s-text-sm s-placeholder-element-700 s-transition-all s-duration-200 s-scrollbar-hide",
|
|
@@ -47,15 +40,6 @@ export function TextArea({
|
|
|
47
40
|
placeholder={placeholder}
|
|
48
41
|
value={value ?? ""}
|
|
49
42
|
onChange={(e) => {
|
|
50
|
-
const newValue = e.target.value;
|
|
51
|
-
const textAreaComponent = textareaRef.current;
|
|
52
|
-
if (
|
|
53
|
-
textAreaComponent &&
|
|
54
|
-
value?.length &&
|
|
55
|
-
newValue.length < value.length
|
|
56
|
-
) {
|
|
57
|
-
textAreaComponent.style.height = "auto"; // Reset height to recalculate
|
|
58
|
-
}
|
|
59
43
|
onChange(e.target.value);
|
|
60
44
|
}}
|
|
61
45
|
/>
|