@nucleux/input-bar 0.1.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/LICENSE +21 -0
- package/dist/index.cjs +113 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +23 -0
- package/dist/index.d.ts +23 -0
- package/dist/index.js +91 -0
- package/dist/index.js.map +1 -0
- package/package.json +46 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Nucleux
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
var React = require('react');
|
|
5
|
+
var lucideReact = require('lucide-react');
|
|
6
|
+
var utils = require('@nucleux/utils');
|
|
7
|
+
var jsxRuntime = require('react/jsx-runtime');
|
|
8
|
+
|
|
9
|
+
function _interopNamespace(e) {
|
|
10
|
+
if (e && e.__esModule) return e;
|
|
11
|
+
var n = Object.create(null);
|
|
12
|
+
if (e) {
|
|
13
|
+
Object.keys(e).forEach(function (k) {
|
|
14
|
+
if (k !== 'default') {
|
|
15
|
+
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
16
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
17
|
+
enumerable: true,
|
|
18
|
+
get: function () { return e[k]; }
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
n.default = e;
|
|
24
|
+
return Object.freeze(n);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
var React__namespace = /*#__PURE__*/_interopNamespace(React);
|
|
28
|
+
|
|
29
|
+
// src/index.tsx
|
|
30
|
+
var InputBar = React__namespace.forwardRef(
|
|
31
|
+
({
|
|
32
|
+
value,
|
|
33
|
+
onValueChange,
|
|
34
|
+
onSubmit,
|
|
35
|
+
loading = false,
|
|
36
|
+
onStop,
|
|
37
|
+
maxHeight = 200,
|
|
38
|
+
placeholder = "Message the agent\u2026",
|
|
39
|
+
className,
|
|
40
|
+
disabled,
|
|
41
|
+
...props
|
|
42
|
+
}, forwardedRef) => {
|
|
43
|
+
const innerRef = React__namespace.useRef(null);
|
|
44
|
+
React__namespace.useImperativeHandle(forwardedRef, () => innerRef.current);
|
|
45
|
+
React__namespace.useLayoutEffect(() => {
|
|
46
|
+
const el = innerRef.current;
|
|
47
|
+
if (!el) return;
|
|
48
|
+
el.style.height = "auto";
|
|
49
|
+
el.style.height = `${Math.min(el.scrollHeight, maxHeight)}px`;
|
|
50
|
+
}, [value, maxHeight]);
|
|
51
|
+
const canSend = value.trim().length > 0 && !disabled;
|
|
52
|
+
const submit = () => {
|
|
53
|
+
if (!canSend) return;
|
|
54
|
+
onSubmit(value.trim());
|
|
55
|
+
};
|
|
56
|
+
const handleKeyDown = (e) => {
|
|
57
|
+
if (e.key === "Enter" && !e.shiftKey && !e.nativeEvent.isComposing) {
|
|
58
|
+
e.preventDefault();
|
|
59
|
+
submit();
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
63
|
+
"div",
|
|
64
|
+
{
|
|
65
|
+
className: utils.cn(
|
|
66
|
+
"flex items-end gap-2 rounded-2xl border border-input bg-background p-2 shadow-sm focus-within:ring-2 focus-within:ring-ring",
|
|
67
|
+
className
|
|
68
|
+
),
|
|
69
|
+
children: [
|
|
70
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
71
|
+
"textarea",
|
|
72
|
+
{
|
|
73
|
+
ref: innerRef,
|
|
74
|
+
rows: 1,
|
|
75
|
+
value,
|
|
76
|
+
disabled,
|
|
77
|
+
placeholder,
|
|
78
|
+
onChange: (e) => onValueChange(e.target.value),
|
|
79
|
+
onKeyDown: handleKeyDown,
|
|
80
|
+
className: "max-h-[inherit] flex-1 resize-none bg-transparent px-2 py-1.5 text-sm text-foreground outline-none placeholder:text-muted-foreground disabled:opacity-50",
|
|
81
|
+
...props
|
|
82
|
+
}
|
|
83
|
+
),
|
|
84
|
+
loading ? /* @__PURE__ */ jsxRuntime.jsx(
|
|
85
|
+
"button",
|
|
86
|
+
{
|
|
87
|
+
type: "button",
|
|
88
|
+
onClick: onStop,
|
|
89
|
+
"aria-label": "Stop generating",
|
|
90
|
+
className: "inline-flex size-8 shrink-0 items-center justify-center rounded-full bg-primary text-primary-foreground transition-opacity hover:opacity-90 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",
|
|
91
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Square, { className: "size-3.5 fill-current" })
|
|
92
|
+
}
|
|
93
|
+
) : /* @__PURE__ */ jsxRuntime.jsx(
|
|
94
|
+
"button",
|
|
95
|
+
{
|
|
96
|
+
type: "button",
|
|
97
|
+
onClick: submit,
|
|
98
|
+
disabled: !canSend,
|
|
99
|
+
"aria-label": "Send message",
|
|
100
|
+
className: "inline-flex size-8 shrink-0 items-center justify-center rounded-full bg-primary text-primary-foreground transition-opacity hover:opacity-90 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:opacity-40",
|
|
101
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(lucideReact.ArrowUp, { className: "size-4" })
|
|
102
|
+
}
|
|
103
|
+
)
|
|
104
|
+
]
|
|
105
|
+
}
|
|
106
|
+
);
|
|
107
|
+
}
|
|
108
|
+
);
|
|
109
|
+
InputBar.displayName = "InputBar";
|
|
110
|
+
|
|
111
|
+
exports.InputBar = InputBar;
|
|
112
|
+
//# sourceMappingURL=index.cjs.map
|
|
113
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.tsx"],"names":["React","jsxs","cn","jsx","Square","ArrowUp"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAwBO,IAAM,QAAA,GAAiBA,gBAAA,CAAA,UAAA;AAAA,EAC5B,CACE;AAAA,IACE,KAAA;AAAA,IACA,aAAA;AAAA,IACA,QAAA;AAAA,IACA,OAAA,GAAU,KAAA;AAAA,IACV,MAAA;AAAA,IACA,SAAA,GAAY,GAAA;AAAA,IACZ,WAAA,GAAc,yBAAA;AAAA,IACd,SAAA;AAAA,IACA,QAAA;AAAA,IACA,GAAG;AAAA,KAEL,YAAA,KACG;AACH,IAAA,MAAM,QAAA,GAAiBA,wBAA4B,IAAI,CAAA;AACvD,IAAMA,gBAAA,CAAA,mBAAA,CAAoB,YAAA,EAAc,MAAM,QAAA,CAAS,OAA8B,CAAA;AAGrF,IAAMA,iCAAgB,MAAM;AAC1B,MAAA,MAAM,KAAK,QAAA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N;AAAA,UACC,OAAA,mBACCA,cAAA;AAAA,YAAC,QAAA;AAAA,YAAA;AAAA,cACC,IAAA,EAAK,QAAA;AAAA,cACL,OAAA,EAAS,MAAA;AAAA,cACT,YAAA,EAAW,iBAAA;AAAA,cACX,SAAA,EAAU,qNAAA;AAAA,cAEV,QAAA,kBAAAA,cAAA,CAACC,kBAAA,EAAA,EAAO,SAAA,EAAU,uBAAA,EAAwB;AAAA;AAAA,WAC5C,mBAEAD,cAAA;AAAA,YAAC,QAAA;AAAA,YAAA;AAAA,cACC,IAAA,EAAK,QAAA;AAAA,cACL,OAAA,EAAS,MAAA;AAAA,cACT,UAAU,CAAC,OAAA;AAAA,cACX,YAAA,EAAW,cAAA;AAAA,cACX,SAAA,EAAU,yOAAA;AAAA,cAEV,QAAA,kBAAAA,cAAA,CAACE,mBAAA,EAAA,EAAQ,SAAA,EAAU,QAAA,EAAS;AAAA;AAAA;AAC9B;AAAA;AAAA,KAEJ;AAAA,EAEJ;AACF;AACA,QAAA,CAAS,WAAA,GAAc,UAAA","file":"index.cjs","sourcesContent":["import * as React from \"react\";\nimport { ArrowUp, Square } from \"lucide-react\";\nimport { cn } from \"@nucleux/utils\";\n\nexport interface InputBarProps\n extends Omit<React.TextareaHTMLAttributes<HTMLTextAreaElement>, \"onSubmit\" | \"value\" | \"onChange\"> {\n /** Controlled value of the input. */\n value: string;\n /** Called when the value changes. */\n onValueChange: (value: string) => void;\n /** Called with the trimmed value on submit (Enter or button). */\n onSubmit: (value: string) => void;\n /** Show the agent as busy — swaps the send button for a stop button. */\n loading?: boolean;\n /** Called when the stop button is pressed while `loading`. */\n onStop?: () => void;\n /** Max auto-grow height in px before scrolling. */\n maxHeight?: number;\n}\n\n/**\n * Auto-resizing chat composer. Enter submits, Shift+Enter inserts a newline.\n * While `loading`, the send button becomes a stop button wired to `onStop`.\n */\nexport const InputBar = React.forwardRef<HTMLTextAreaElement, InputBarProps>(\n (\n {\n value,\n onValueChange,\n onSubmit,\n loading = false,\n onStop,\n maxHeight = 200,\n placeholder = \"Message the agent…\",\n className,\n disabled,\n ...props\n },\n forwardedRef,\n ) => {\n const innerRef = React.useRef<HTMLTextAreaElement>(null);\n React.useImperativeHandle(forwardedRef, () => innerRef.current as HTMLTextAreaElement);\n\n // Auto-grow the textarea to fit its content, capped at maxHeight.\n React.useLayoutEffect(() => {\n const el = innerRef.current;\n if (!el) return;\n el.style.height = \"auto\";\n el.style.height = `${Math.min(el.scrollHeight, maxHeight)}px`;\n }, [value, maxHeight]);\n\n const canSend = value.trim().length > 0 && !disabled;\n\n const submit = () => {\n if (!canSend) return;\n onSubmit(value.trim());\n };\n\n const handleKeyDown = (e: React.KeyboardEvent<HTMLTextAreaElement>) => {\n if (e.key === \"Enter\" && !e.shiftKey && !e.nativeEvent.isComposing) {\n e.preventDefault();\n submit();\n }\n };\n\n return (\n <div\n className={cn(\n \"flex items-end gap-2 rounded-2xl border border-input bg-background p-2 shadow-sm focus-within:ring-2 focus-within:ring-ring\",\n className,\n )}\n >\n <textarea\n ref={innerRef}\n rows={1}\n value={value}\n disabled={disabled}\n placeholder={placeholder}\n onChange={(e) => onValueChange(e.target.value)}\n onKeyDown={handleKeyDown}\n className=\"max-h-[inherit] flex-1 resize-none bg-transparent px-2 py-1.5 text-sm text-foreground outline-none placeholder:text-muted-foreground disabled:opacity-50\"\n {...props}\n />\n {loading ? (\n <button\n type=\"button\"\n onClick={onStop}\n aria-label=\"Stop generating\"\n className=\"inline-flex size-8 shrink-0 items-center justify-center rounded-full bg-primary text-primary-foreground transition-opacity hover:opacity-90 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring\"\n >\n <Square className=\"size-3.5 fill-current\" />\n </button>\n ) : (\n <button\n type=\"button\"\n onClick={submit}\n disabled={!canSend}\n aria-label=\"Send message\"\n className=\"inline-flex size-8 shrink-0 items-center justify-center rounded-full bg-primary text-primary-foreground transition-opacity hover:opacity-90 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:opacity-40\"\n >\n <ArrowUp className=\"size-4\" />\n </button>\n )}\n </div>\n );\n },\n);\nInputBar.displayName = \"InputBar\";\n"]}
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
|
|
3
|
+
interface InputBarProps extends Omit<React.TextareaHTMLAttributes<HTMLTextAreaElement>, "onSubmit" | "value" | "onChange"> {
|
|
4
|
+
/** Controlled value of the input. */
|
|
5
|
+
value: string;
|
|
6
|
+
/** Called when the value changes. */
|
|
7
|
+
onValueChange: (value: string) => void;
|
|
8
|
+
/** Called with the trimmed value on submit (Enter or button). */
|
|
9
|
+
onSubmit: (value: string) => void;
|
|
10
|
+
/** Show the agent as busy — swaps the send button for a stop button. */
|
|
11
|
+
loading?: boolean;
|
|
12
|
+
/** Called when the stop button is pressed while `loading`. */
|
|
13
|
+
onStop?: () => void;
|
|
14
|
+
/** Max auto-grow height in px before scrolling. */
|
|
15
|
+
maxHeight?: number;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Auto-resizing chat composer. Enter submits, Shift+Enter inserts a newline.
|
|
19
|
+
* While `loading`, the send button becomes a stop button wired to `onStop`.
|
|
20
|
+
*/
|
|
21
|
+
declare const InputBar: React.ForwardRefExoticComponent<InputBarProps & React.RefAttributes<HTMLTextAreaElement>>;
|
|
22
|
+
|
|
23
|
+
export { InputBar, type InputBarProps };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
|
|
3
|
+
interface InputBarProps extends Omit<React.TextareaHTMLAttributes<HTMLTextAreaElement>, "onSubmit" | "value" | "onChange"> {
|
|
4
|
+
/** Controlled value of the input. */
|
|
5
|
+
value: string;
|
|
6
|
+
/** Called when the value changes. */
|
|
7
|
+
onValueChange: (value: string) => void;
|
|
8
|
+
/** Called with the trimmed value on submit (Enter or button). */
|
|
9
|
+
onSubmit: (value: string) => void;
|
|
10
|
+
/** Show the agent as busy — swaps the send button for a stop button. */
|
|
11
|
+
loading?: boolean;
|
|
12
|
+
/** Called when the stop button is pressed while `loading`. */
|
|
13
|
+
onStop?: () => void;
|
|
14
|
+
/** Max auto-grow height in px before scrolling. */
|
|
15
|
+
maxHeight?: number;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Auto-resizing chat composer. Enter submits, Shift+Enter inserts a newline.
|
|
19
|
+
* While `loading`, the send button becomes a stop button wired to `onStop`.
|
|
20
|
+
*/
|
|
21
|
+
declare const InputBar: React.ForwardRefExoticComponent<InputBarProps & React.RefAttributes<HTMLTextAreaElement>>;
|
|
22
|
+
|
|
23
|
+
export { InputBar, type InputBarProps };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import * as React from 'react';
|
|
3
|
+
import { Square, ArrowUp } from 'lucide-react';
|
|
4
|
+
import { cn } from '@nucleux/utils';
|
|
5
|
+
import { jsxs, jsx } from 'react/jsx-runtime';
|
|
6
|
+
|
|
7
|
+
// src/index.tsx
|
|
8
|
+
var InputBar = React.forwardRef(
|
|
9
|
+
({
|
|
10
|
+
value,
|
|
11
|
+
onValueChange,
|
|
12
|
+
onSubmit,
|
|
13
|
+
loading = false,
|
|
14
|
+
onStop,
|
|
15
|
+
maxHeight = 200,
|
|
16
|
+
placeholder = "Message the agent\u2026",
|
|
17
|
+
className,
|
|
18
|
+
disabled,
|
|
19
|
+
...props
|
|
20
|
+
}, forwardedRef) => {
|
|
21
|
+
const innerRef = React.useRef(null);
|
|
22
|
+
React.useImperativeHandle(forwardedRef, () => innerRef.current);
|
|
23
|
+
React.useLayoutEffect(() => {
|
|
24
|
+
const el = innerRef.current;
|
|
25
|
+
if (!el) return;
|
|
26
|
+
el.style.height = "auto";
|
|
27
|
+
el.style.height = `${Math.min(el.scrollHeight, maxHeight)}px`;
|
|
28
|
+
}, [value, maxHeight]);
|
|
29
|
+
const canSend = value.trim().length > 0 && !disabled;
|
|
30
|
+
const submit = () => {
|
|
31
|
+
if (!canSend) return;
|
|
32
|
+
onSubmit(value.trim());
|
|
33
|
+
};
|
|
34
|
+
const handleKeyDown = (e) => {
|
|
35
|
+
if (e.key === "Enter" && !e.shiftKey && !e.nativeEvent.isComposing) {
|
|
36
|
+
e.preventDefault();
|
|
37
|
+
submit();
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
return /* @__PURE__ */ jsxs(
|
|
41
|
+
"div",
|
|
42
|
+
{
|
|
43
|
+
className: cn(
|
|
44
|
+
"flex items-end gap-2 rounded-2xl border border-input bg-background p-2 shadow-sm focus-within:ring-2 focus-within:ring-ring",
|
|
45
|
+
className
|
|
46
|
+
),
|
|
47
|
+
children: [
|
|
48
|
+
/* @__PURE__ */ jsx(
|
|
49
|
+
"textarea",
|
|
50
|
+
{
|
|
51
|
+
ref: innerRef,
|
|
52
|
+
rows: 1,
|
|
53
|
+
value,
|
|
54
|
+
disabled,
|
|
55
|
+
placeholder,
|
|
56
|
+
onChange: (e) => onValueChange(e.target.value),
|
|
57
|
+
onKeyDown: handleKeyDown,
|
|
58
|
+
className: "max-h-[inherit] flex-1 resize-none bg-transparent px-2 py-1.5 text-sm text-foreground outline-none placeholder:text-muted-foreground disabled:opacity-50",
|
|
59
|
+
...props
|
|
60
|
+
}
|
|
61
|
+
),
|
|
62
|
+
loading ? /* @__PURE__ */ jsx(
|
|
63
|
+
"button",
|
|
64
|
+
{
|
|
65
|
+
type: "button",
|
|
66
|
+
onClick: onStop,
|
|
67
|
+
"aria-label": "Stop generating",
|
|
68
|
+
className: "inline-flex size-8 shrink-0 items-center justify-center rounded-full bg-primary text-primary-foreground transition-opacity hover:opacity-90 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",
|
|
69
|
+
children: /* @__PURE__ */ jsx(Square, { className: "size-3.5 fill-current" })
|
|
70
|
+
}
|
|
71
|
+
) : /* @__PURE__ */ jsx(
|
|
72
|
+
"button",
|
|
73
|
+
{
|
|
74
|
+
type: "button",
|
|
75
|
+
onClick: submit,
|
|
76
|
+
disabled: !canSend,
|
|
77
|
+
"aria-label": "Send message",
|
|
78
|
+
className: "inline-flex size-8 shrink-0 items-center justify-center rounded-full bg-primary text-primary-foreground transition-opacity hover:opacity-90 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:opacity-40",
|
|
79
|
+
children: /* @__PURE__ */ jsx(ArrowUp, { className: "size-4" })
|
|
80
|
+
}
|
|
81
|
+
)
|
|
82
|
+
]
|
|
83
|
+
}
|
|
84
|
+
);
|
|
85
|
+
}
|
|
86
|
+
);
|
|
87
|
+
InputBar.displayName = "InputBar";
|
|
88
|
+
|
|
89
|
+
export { InputBar };
|
|
90
|
+
//# sourceMappingURL=index.js.map
|
|
91
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.tsx"],"names":[],"mappings":";;;;;;AAwBO,IAAM,QAAA,GAAiB,KAAA,CAAA,UAAA;AAAA,EAC5B,CACE;AAAA,IACE,KAAA;AAAA,IACA,aAAA;AAAA,IACA,QAAA;AAAA,IACA,OAAA,GAAU,KAAA;AAAA,IACV,MAAA;AAAA,IACA,SAAA,GAAY,GAAA;AAAA,IACZ,WAAA,GAAc,yBAAA;AAAA,IACd,SAAA;AAAA,IACA,QAAA;AAAA,IACA,GAAG;AAAA,KAEL,YAAA,KACG;AACH,IAAA,MAAM,QAAA,GAAiB,aAA4B,IAAI,CAAA;AACvD,IAAM,KAAA,CAAA,mBAAA,CAAoB,YAAA,EAAc,MAAM,QAAA,CAAS,OAA8B,CAAA;AAGrF,IAAM,sBAAgB,MAAM;AAC1B,MAAA,MAAM,KAAK,QAAA,CAAS,OAAA;AACpB,MAAA,IAAI,CAAC,EAAA,EAAI;AACT,MAAA,EAAA,CAAG,MAAM,MAAA,GAAS,MAAA;AAClB,MAAA,EAAA,CAAG,KAAA,CAAM,SAAS,CAAA,EAAG,IAAA,CA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AA,EAAU,qNAAA;AAAA,cAEV,QAAA,kBAAA,GAAA,CAAC,MAAA,EAAA,EAAO,SAAA,EAAU,uBAAA,EAAwB;AAAA;AAAA,WAC5C,mBAEA,GAAA;AAAA,YAAC,QAAA;AAAA,YAAA;AAAA,cACC,IAAA,EAAK,QAAA;AAAA,cACL,OAAA,EAAS,MAAA;AAAA,cACT,UAAU,CAAC,OAAA;AAAA,cACX,YAAA,EAAW,cAAA;AAAA,cACX,SAAA,EAAU,yOAAA;AAAA,cAEV,QAAA,kBAAA,GAAA,CAAC,OAAA,EAAA,EAAQ,SAAA,EAAU,QAAA,EAAS;AAAA;AAAA;AAC9B;AAAA;AAAA,KAEJ;AAAA,EAEJ;AACF;AACA,QAAA,CAAS,WAAA,GAAc,UAAA","file":"index.js","sourcesContent":["import * as React from \"react\";\nimport { ArrowUp, Square } from \"lucide-react\";\nimport { cn } from \"@nucleux/utils\";\n\nexport interface InputBarProps\n extends Omit<React.TextareaHTMLAttributes<HTMLTextAreaElement>, \"onSubmit\" | \"value\" | \"onChange\"> {\n /** Controlled value of the input. */\n value: string;\n /** Called when the value changes. */\n onValueChange: (value: string) => void;\n /** Called with the trimmed value on submit (Enter or button). */\n onSubmit: (value: string) => void;\n /** Show the agent as busy — swaps the send button for a stop button. */\n loading?: boolean;\n /** Called when the stop button is pressed while `loading`. */\n onStop?: () => void;\n /** Max auto-grow height in px before scrolling. */\n maxHeight?: number;\n}\n\n/**\n * Auto-resizing chat composer. Enter submits, Shift+Enter inserts a newline.\n * While `loading`, the send button becomes a stop button wired to `onStop`.\n */\nexport const InputBar = React.forwardRef<HTMLTextAreaElement, InputBarProps>(\n (\n {\n value,\n onValueChange,\n onSubmit,\n loading = false,\n onStop,\n maxHeight = 200,\n placeholder = \"Message the agent…\",\n className,\n disabled,\n ...props\n },\n forwardedRef,\n ) => {\n const innerRef = React.useRef<HTMLTextAreaElement>(null);\n React.useImperativeHandle(forwardedRef, () => innerRef.current as HTMLTextAreaElement);\n\n // Auto-grow the textarea to fit its content, capped at maxHeight.\n React.useLayoutEffect(() => {\n const el = innerRef.current;\n if (!el) return;\n el.style.height = \"auto\";\n el.style.height = `${Math.min(el.scrollHeight, maxHeight)}px`;\n }, [value, maxHeight]);\n\n const canSend = value.trim().length > 0 && !disabled;\n\n const submit = () => {\n if (!canSend) return;\n onSubmit(value.trim());\n };\n\n const handleKeyDown = (e: React.KeyboardEvent<HTMLTextAreaElement>) => {\n if (e.key === \"Enter\" && !e.shiftKey && !e.nativeEvent.isComposing) {\n e.preventDefault();\n submit();\n }\n };\n\n return (\n <div\n className={cn(\n \"flex items-end gap-2 rounded-2xl border border-input bg-background p-2 shadow-sm focus-within:ring-2 focus-within:ring-ring\",\n className,\n )}\n >\n <textarea\n ref={innerRef}\n rows={1}\n value={value}\n disabled={disabled}\n placeholder={placeholder}\n onChange={(e) => onValueChange(e.target.value)}\n onKeyDown={handleKeyDown}\n className=\"max-h-[inherit] flex-1 resize-none bg-transparent px-2 py-1.5 text-sm text-foreground outline-none placeholder:text-muted-foreground disabled:opacity-50\"\n {...props}\n />\n {loading ? (\n <button\n type=\"button\"\n onClick={onStop}\n aria-label=\"Stop generating\"\n className=\"inline-flex size-8 shrink-0 items-center justify-center rounded-full bg-primary text-primary-foreground transition-opacity hover:opacity-90 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring\"\n >\n <Square className=\"size-3.5 fill-current\" />\n </button>\n ) : (\n <button\n type=\"button\"\n onClick={submit}\n disabled={!canSend}\n aria-label=\"Send message\"\n className=\"inline-flex size-8 shrink-0 items-center justify-center rounded-full bg-primary text-primary-foreground transition-opacity hover:opacity-90 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:opacity-40\"\n >\n <ArrowUp className=\"size-4\" />\n </button>\n )}\n </div>\n );\n },\n);\nInputBar.displayName = \"InputBar\";\n"]}
|
package/package.json
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@nucleux/input-bar",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"sideEffects": false,
|
|
6
|
+
"main": "./dist/index.cjs",
|
|
7
|
+
"module": "./dist/index.js",
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"import": "./dist/index.js",
|
|
13
|
+
"require": "./dist/index.cjs"
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
"files": [
|
|
17
|
+
"dist"
|
|
18
|
+
],
|
|
19
|
+
"peerDependencies": {
|
|
20
|
+
"react": ">=18",
|
|
21
|
+
"react-dom": ">=18"
|
|
22
|
+
},
|
|
23
|
+
"dependencies": {
|
|
24
|
+
"lucide-react": "^0.469.0",
|
|
25
|
+
"@nucleux/utils": "0.1.0"
|
|
26
|
+
},
|
|
27
|
+
"devDependencies": {
|
|
28
|
+
"tsup": "^8.3.5",
|
|
29
|
+
"typescript": "^5.7.2",
|
|
30
|
+
"@types/react": "^18.3.18",
|
|
31
|
+
"react": "^18.3.1"
|
|
32
|
+
},
|
|
33
|
+
"publishConfig": {
|
|
34
|
+
"access": "public"
|
|
35
|
+
},
|
|
36
|
+
"license": "MIT",
|
|
37
|
+
"repository": {
|
|
38
|
+
"type": "git",
|
|
39
|
+
"url": "git+https://github.com/intelligaia-open-labs/nucleux.git",
|
|
40
|
+
"directory": "packages/input-bar"
|
|
41
|
+
},
|
|
42
|
+
"homepage": "https://github.com/intelligaia-open-labs/nucleux#readme",
|
|
43
|
+
"scripts": {
|
|
44
|
+
"build": "tsup"
|
|
45
|
+
}
|
|
46
|
+
}
|