@nucleux/voice-input 0.1.1
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/README.md +26 -0
- package/dist/index.cjs +106 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +25 -0
- package/dist/index.d.ts +25 -0
- package/dist/index.js +84 -0
- package/dist/index.js.map +1 -0
- package/package.json +58 -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/README.md
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
# @nucleux/voice-input
|
|
2
|
+
|
|
3
|
+
VoiceInput — a live dictation bar with a waveform — Nucleux agentic UI for React.
|
|
4
|
+
|
|
5
|
+
Part of **[Nucleux](https://github.com/intelligaia-open-labs/nucleux)** — agentic UI components for React. Install a single component, or the full kit via [`@nucleux/react`](https://www.npmjs.com/package/@nucleux/react).
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
pnpm add @nucleux/voice-input @nucleux/tokens
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
`react` / `react-dom` are peer dependencies.
|
|
14
|
+
|
|
15
|
+
## Usage
|
|
16
|
+
|
|
17
|
+
```tsx
|
|
18
|
+
import { VoiceInput } from "@nucleux/voice-input";
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
Requires the theme once in your app: `import "@nucleux/tokens/styles.css";`
|
|
22
|
+
and the Tailwind preset from `@nucleux/tokens/preset`.
|
|
23
|
+
|
|
24
|
+
## License
|
|
25
|
+
|
|
26
|
+
MIT © Nucleux
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
var React = require('react');
|
|
5
|
+
var utils = require('@nucleux/utils');
|
|
6
|
+
var lucideReact = require('lucide-react');
|
|
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 BAR_COUNT = 24;
|
|
31
|
+
function Waveform() {
|
|
32
|
+
return /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex h-8 flex-1 items-center gap-0.5", "aria-hidden": "true", children: Array.from({ length: BAR_COUNT }).map((_, i) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
33
|
+
"span",
|
|
34
|
+
{
|
|
35
|
+
className: "w-0.5 flex-1 rounded-full bg-info/70 animate-nx-typing",
|
|
36
|
+
style: {
|
|
37
|
+
height: `${30 + i * 37 % 60}%`,
|
|
38
|
+
animationDelay: `${i % 6 * 90}ms`
|
|
39
|
+
}
|
|
40
|
+
},
|
|
41
|
+
i
|
|
42
|
+
)) });
|
|
43
|
+
}
|
|
44
|
+
var VoiceInput = React__namespace.forwardRef(
|
|
45
|
+
({ state = "idle", duration, transcript, onStart, onCancel, onConfirm, className, ...props }, ref) => /* @__PURE__ */ jsxRuntime.jsxs(
|
|
46
|
+
"div",
|
|
47
|
+
{
|
|
48
|
+
ref,
|
|
49
|
+
className: utils.cn(
|
|
50
|
+
"flex items-center gap-3 rounded-full border border-border bg-background px-3 py-2",
|
|
51
|
+
className
|
|
52
|
+
),
|
|
53
|
+
role: "group",
|
|
54
|
+
"aria-label": "Voice input",
|
|
55
|
+
...props,
|
|
56
|
+
children: [
|
|
57
|
+
state === "idle" && /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
58
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
59
|
+
"button",
|
|
60
|
+
{
|
|
61
|
+
type: "button",
|
|
62
|
+
"aria-label": "Start dictation",
|
|
63
|
+
onClick: onStart,
|
|
64
|
+
className: "inline-flex size-9 items-center justify-center rounded-full bg-muted text-foreground transition-colors hover:bg-accent focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring [&_svg]:size-4",
|
|
65
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Mic, { "aria-hidden": "true" })
|
|
66
|
+
}
|
|
67
|
+
),
|
|
68
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "flex-1 text-sm text-muted-foreground", children: "Tap to speak" })
|
|
69
|
+
] }),
|
|
70
|
+
state === "recording" && /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
71
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
72
|
+
"button",
|
|
73
|
+
{
|
|
74
|
+
type: "button",
|
|
75
|
+
"aria-label": "Cancel dictation",
|
|
76
|
+
onClick: onCancel,
|
|
77
|
+
className: "inline-flex size-9 items-center justify-center rounded-full text-muted-foreground transition-colors hover:bg-accent hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring [&_svg]:size-4",
|
|
78
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(lucideReact.X, { "aria-hidden": "true" })
|
|
79
|
+
}
|
|
80
|
+
),
|
|
81
|
+
/* @__PURE__ */ jsxRuntime.jsx(Waveform, {}),
|
|
82
|
+
duration && /* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-sm tabular-nums text-muted-foreground", children: duration }),
|
|
83
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
84
|
+
"button",
|
|
85
|
+
{
|
|
86
|
+
type: "button",
|
|
87
|
+
"aria-label": "Stop and use recording",
|
|
88
|
+
onClick: onConfirm,
|
|
89
|
+
className: "inline-flex size-9 items-center justify-center rounded-full bg-info text-info-foreground transition-colors hover:bg-info/90 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring [&_svg]:size-4",
|
|
90
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Check, { "aria-hidden": "true" })
|
|
91
|
+
}
|
|
92
|
+
)
|
|
93
|
+
] }),
|
|
94
|
+
state === "transcribing" && /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
95
|
+
/* @__PURE__ */ jsxRuntime.jsx(lucideReact.Loader2, { className: "size-4 shrink-0 animate-spin text-muted-foreground", "aria-hidden": "true" }),
|
|
96
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "flex-1 truncate text-sm text-muted-foreground", children: transcript ?? "Transcribing\u2026" })
|
|
97
|
+
] })
|
|
98
|
+
]
|
|
99
|
+
}
|
|
100
|
+
)
|
|
101
|
+
);
|
|
102
|
+
VoiceInput.displayName = "VoiceInput";
|
|
103
|
+
|
|
104
|
+
exports.VoiceInput = VoiceInput;
|
|
105
|
+
//# sourceMappingURL=index.cjs.map
|
|
106
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.tsx"],"names":["jsx","React","jsxs","cn","Fragment","Mic","X","Check","Loader2"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAqBA,IAAM,SAAA,GAAY,EAAA;AAElB,SAAS,QAAA,GAAW;AAClB,EAAA,sCACG,KAAA,EAAA,EAAI,SAAA,EAAU,sCAAA,EAAuC,aAAA,EAAY,QAC/D,QAAA,EAAA,KAAA,CAAM,IAAA,CAAK,EAAE,MAAA,EAAQ,WAAW,CAAA,CAAE,GAAA,CAAI,CAAC,GAAG,CAAA,qBACzCA,cAAA;AAAA,IAAC,MAAA;AAAA,IAAA;AAAA,MAEC,SAAA,EAAU,wDAAA;AAAA,MACV,KAAA,EAAO;AAAA,QACL,MAAA,EAAQ,CAAA,EAAG,EAAA,GAAO,CAAA,GAAI,KAAM,EAAG,CAAA,CAAA,CAAA;AAAA,QAC/B,cAAA,EAAgB,CAAA,EAAI,CAAA,GAAI,CAAA,GAAK,EAAE,CAAA,EAAA;AAAA;AACjC,KAAA;AAAA,IALK;AAAA,GAOR,CAAA,EACH,CAAA;AAEJ;AAOO,IAAM,UA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,QAAA,EAAA,EAAS,CAAA;AAAA,UACT,QAAA,oBAAYN,cAAA,CAAC,MAAA,EAAA,EAAK,SAAA,EAAU,8CAA8C,QAAA,EAAA,QAAA,EAAS,CAAA;AAAA,0BACpFA,cAAA;AAAA,YAAC,QAAA;AAAA,YAAA;AAAA,cACC,IAAA,EAAK,QAAA;AAAA,cACL,YAAA,EAAW,wBAAA;AAAA,cACX,OAAA,EAAS,SAAA;AAAA,cACT,SAAA,EAAU,oNAAA;AAAA,cAEV,QAAA,kBAAAA,cAAA,CAACO,iBAAA,EAAA,EAAM,aAAA,EAAY,MAAA,EAAO;AAAA;AAAA;AAC5B,SAAA,EACF,CAAA;AAAA,QAGD,KAAA,KAAU,kCACTL,eAAA,CAAAE,mBAAA,EAAA,EACE,QAAA,EAAA;AAAA,0BAAAJ,cAAA,CAACQ,mBAAA,EAAA,EAAQ,SAAA,EAAU,oDAAA,EAAqD,aAAA,EAAY,MAAA,EAAO,CAAA;AAAA,0BAC3FR,cAAA,CAAC,MAAA,EAAA,EAAK,SAAA,EAAU,+CAAA,EACb,wBAAc,oBAAA,EACjB;AAAA,SAAA,EACF;AAAA;AAAA;AAAA;AAIR;AACA,UAAA,CAAW,WAAA,GAAc,YAAA","file":"index.cjs","sourcesContent":["import * as React from \"react\";\nimport { cn } from \"@nucleux/utils\";\nimport { Mic, X, Check, Loader2 } from \"lucide-react\";\n\nexport type VoiceInputState = \"idle\" | \"recording\" | \"transcribing\";\n\nexport interface VoiceInputProps extends React.HTMLAttributes<HTMLDivElement> {\n /** Current state of the dictation flow. */\n state?: VoiceInputState;\n /** Elapsed time label while recording, e.g. `\"0:12\"`. */\n duration?: React.ReactNode;\n /** Transcribed text shown once available. */\n transcript?: React.ReactNode;\n /** Called from the idle mic button to start recording. */\n onStart?: () => void;\n /** Called to cancel/discard the recording. */\n onCancel?: () => void;\n /** Called to stop recording and confirm. */\n onConfirm?: () => void;\n}\n\nconst BAR_COUNT = 24;\n\nfunction Waveform() {\n return (\n <div className=\"flex h-8 flex-1 items-center gap-0.5\" aria-hidden=\"true\">\n {Array.from({ length: BAR_COUNT }).map((_, i) => (\n <span\n key={i}\n className=\"w-0.5 flex-1 rounded-full bg-info/70 animate-nx-typing\"\n style={{\n height: `${30 + ((i * 37) % 60)}%`,\n animationDelay: `${(i % 6) * 90}ms`,\n }}\n />\n ))}\n </div>\n );\n}\n\n/**\n * A composer in a live-dictation state — mic trigger, animated waveform while\n * recording, and a transcribing state — for voice input to the agent.\n * Source: Figma \"Expressive Input / Voice Input\".\n */\nexport const VoiceInput = React.forwardRef<HTMLDivElement, VoiceInputProps>(\n ({ state = \"idle\", duration, transcript, onStart, onCancel, onConfirm, className, ...props }, ref) => (\n <div\n ref={ref}\n className={cn(\n \"flex items-center gap-3 rounded-full border border-border bg-background px-3 py-2\",\n className,\n )}\n role=\"group\"\n aria-label=\"Voice input\"\n {...props}\n >\n {state === \"idle\" && (\n <>\n <button\n type=\"button\"\n aria-label=\"Start dictation\"\n onClick={onStart}\n className=\"inline-flex size-9 items-center justify-center rounded-full bg-muted text-foreground transition-colors hover:bg-accent focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring [&_svg]:size-4\"\n >\n <Mic aria-hidden=\"true\" />\n </button>\n <span className=\"flex-1 text-sm text-muted-foreground\">Tap to speak</span>\n </>\n )}\n\n {state === \"recording\" && (\n <>\n <button\n type=\"button\"\n aria-label=\"Cancel dictation\"\n onClick={onCancel}\n className=\"inline-flex size-9 items-center justify-center rounded-full text-muted-foreground transition-colors hover:bg-accent hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring [&_svg]:size-4\"\n >\n <X aria-hidden=\"true\" />\n </button>\n <Waveform />\n {duration && <span className=\"text-sm tabular-nums text-muted-foreground\">{duration}</span>}\n <button\n type=\"button\"\n aria-label=\"Stop and use recording\"\n onClick={onConfirm}\n className=\"inline-flex size-9 items-center justify-center rounded-full bg-info text-info-foreground transition-colors hover:bg-info/90 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring [&_svg]:size-4\"\n >\n <Check aria-hidden=\"true\" />\n </button>\n </>\n )}\n\n {state === \"transcribing\" && (\n <>\n <Loader2 className=\"size-4 shrink-0 animate-spin text-muted-foreground\" aria-hidden=\"true\" />\n <span className=\"flex-1 truncate text-sm text-muted-foreground\">\n {transcript ?? \"Transcribing…\"}\n </span>\n </>\n )}\n </div>\n ),\n);\nVoiceInput.displayName = \"VoiceInput\";\n"]}
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
|
|
3
|
+
type VoiceInputState = "idle" | "recording" | "transcribing";
|
|
4
|
+
interface VoiceInputProps extends React.HTMLAttributes<HTMLDivElement> {
|
|
5
|
+
/** Current state of the dictation flow. */
|
|
6
|
+
state?: VoiceInputState;
|
|
7
|
+
/** Elapsed time label while recording, e.g. `"0:12"`. */
|
|
8
|
+
duration?: React.ReactNode;
|
|
9
|
+
/** Transcribed text shown once available. */
|
|
10
|
+
transcript?: React.ReactNode;
|
|
11
|
+
/** Called from the idle mic button to start recording. */
|
|
12
|
+
onStart?: () => void;
|
|
13
|
+
/** Called to cancel/discard the recording. */
|
|
14
|
+
onCancel?: () => void;
|
|
15
|
+
/** Called to stop recording and confirm. */
|
|
16
|
+
onConfirm?: () => void;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* A composer in a live-dictation state — mic trigger, animated waveform while
|
|
20
|
+
* recording, and a transcribing state — for voice input to the agent.
|
|
21
|
+
* Source: Figma "Expressive Input / Voice Input".
|
|
22
|
+
*/
|
|
23
|
+
declare const VoiceInput: React.ForwardRefExoticComponent<VoiceInputProps & React.RefAttributes<HTMLDivElement>>;
|
|
24
|
+
|
|
25
|
+
export { VoiceInput, type VoiceInputProps, type VoiceInputState };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
|
|
3
|
+
type VoiceInputState = "idle" | "recording" | "transcribing";
|
|
4
|
+
interface VoiceInputProps extends React.HTMLAttributes<HTMLDivElement> {
|
|
5
|
+
/** Current state of the dictation flow. */
|
|
6
|
+
state?: VoiceInputState;
|
|
7
|
+
/** Elapsed time label while recording, e.g. `"0:12"`. */
|
|
8
|
+
duration?: React.ReactNode;
|
|
9
|
+
/** Transcribed text shown once available. */
|
|
10
|
+
transcript?: React.ReactNode;
|
|
11
|
+
/** Called from the idle mic button to start recording. */
|
|
12
|
+
onStart?: () => void;
|
|
13
|
+
/** Called to cancel/discard the recording. */
|
|
14
|
+
onCancel?: () => void;
|
|
15
|
+
/** Called to stop recording and confirm. */
|
|
16
|
+
onConfirm?: () => void;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* A composer in a live-dictation state — mic trigger, animated waveform while
|
|
20
|
+
* recording, and a transcribing state — for voice input to the agent.
|
|
21
|
+
* Source: Figma "Expressive Input / Voice Input".
|
|
22
|
+
*/
|
|
23
|
+
declare const VoiceInput: React.ForwardRefExoticComponent<VoiceInputProps & React.RefAttributes<HTMLDivElement>>;
|
|
24
|
+
|
|
25
|
+
export { VoiceInput, type VoiceInputProps, type VoiceInputState };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import * as React from 'react';
|
|
3
|
+
import { cn } from '@nucleux/utils';
|
|
4
|
+
import { Mic, X, Check, Loader2 } from 'lucide-react';
|
|
5
|
+
import { jsxs, Fragment, jsx } from 'react/jsx-runtime';
|
|
6
|
+
|
|
7
|
+
// src/index.tsx
|
|
8
|
+
var BAR_COUNT = 24;
|
|
9
|
+
function Waveform() {
|
|
10
|
+
return /* @__PURE__ */ jsx("div", { className: "flex h-8 flex-1 items-center gap-0.5", "aria-hidden": "true", children: Array.from({ length: BAR_COUNT }).map((_, i) => /* @__PURE__ */ jsx(
|
|
11
|
+
"span",
|
|
12
|
+
{
|
|
13
|
+
className: "w-0.5 flex-1 rounded-full bg-info/70 animate-nx-typing",
|
|
14
|
+
style: {
|
|
15
|
+
height: `${30 + i * 37 % 60}%`,
|
|
16
|
+
animationDelay: `${i % 6 * 90}ms`
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
i
|
|
20
|
+
)) });
|
|
21
|
+
}
|
|
22
|
+
var VoiceInput = React.forwardRef(
|
|
23
|
+
({ state = "idle", duration, transcript, onStart, onCancel, onConfirm, className, ...props }, ref) => /* @__PURE__ */ jsxs(
|
|
24
|
+
"div",
|
|
25
|
+
{
|
|
26
|
+
ref,
|
|
27
|
+
className: cn(
|
|
28
|
+
"flex items-center gap-3 rounded-full border border-border bg-background px-3 py-2",
|
|
29
|
+
className
|
|
30
|
+
),
|
|
31
|
+
role: "group",
|
|
32
|
+
"aria-label": "Voice input",
|
|
33
|
+
...props,
|
|
34
|
+
children: [
|
|
35
|
+
state === "idle" && /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
36
|
+
/* @__PURE__ */ jsx(
|
|
37
|
+
"button",
|
|
38
|
+
{
|
|
39
|
+
type: "button",
|
|
40
|
+
"aria-label": "Start dictation",
|
|
41
|
+
onClick: onStart,
|
|
42
|
+
className: "inline-flex size-9 items-center justify-center rounded-full bg-muted text-foreground transition-colors hover:bg-accent focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring [&_svg]:size-4",
|
|
43
|
+
children: /* @__PURE__ */ jsx(Mic, { "aria-hidden": "true" })
|
|
44
|
+
}
|
|
45
|
+
),
|
|
46
|
+
/* @__PURE__ */ jsx("span", { className: "flex-1 text-sm text-muted-foreground", children: "Tap to speak" })
|
|
47
|
+
] }),
|
|
48
|
+
state === "recording" && /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
49
|
+
/* @__PURE__ */ jsx(
|
|
50
|
+
"button",
|
|
51
|
+
{
|
|
52
|
+
type: "button",
|
|
53
|
+
"aria-label": "Cancel dictation",
|
|
54
|
+
onClick: onCancel,
|
|
55
|
+
className: "inline-flex size-9 items-center justify-center rounded-full text-muted-foreground transition-colors hover:bg-accent hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring [&_svg]:size-4",
|
|
56
|
+
children: /* @__PURE__ */ jsx(X, { "aria-hidden": "true" })
|
|
57
|
+
}
|
|
58
|
+
),
|
|
59
|
+
/* @__PURE__ */ jsx(Waveform, {}),
|
|
60
|
+
duration && /* @__PURE__ */ jsx("span", { className: "text-sm tabular-nums text-muted-foreground", children: duration }),
|
|
61
|
+
/* @__PURE__ */ jsx(
|
|
62
|
+
"button",
|
|
63
|
+
{
|
|
64
|
+
type: "button",
|
|
65
|
+
"aria-label": "Stop and use recording",
|
|
66
|
+
onClick: onConfirm,
|
|
67
|
+
className: "inline-flex size-9 items-center justify-center rounded-full bg-info text-info-foreground transition-colors hover:bg-info/90 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring [&_svg]:size-4",
|
|
68
|
+
children: /* @__PURE__ */ jsx(Check, { "aria-hidden": "true" })
|
|
69
|
+
}
|
|
70
|
+
)
|
|
71
|
+
] }),
|
|
72
|
+
state === "transcribing" && /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
73
|
+
/* @__PURE__ */ jsx(Loader2, { className: "size-4 shrink-0 animate-spin text-muted-foreground", "aria-hidden": "true" }),
|
|
74
|
+
/* @__PURE__ */ jsx("span", { className: "flex-1 truncate text-sm text-muted-foreground", children: transcript ?? "Transcribing\u2026" })
|
|
75
|
+
] })
|
|
76
|
+
]
|
|
77
|
+
}
|
|
78
|
+
)
|
|
79
|
+
);
|
|
80
|
+
VoiceInput.displayName = "VoiceInput";
|
|
81
|
+
|
|
82
|
+
export { VoiceInput };
|
|
83
|
+
//# sourceMappingURL=index.js.map
|
|
84
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.tsx"],"names":[],"mappings":";;;;;;AAqBA,IAAM,SAAA,GAAY,EAAA;AAElB,SAAS,QAAA,GAAW;AAClB,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CAAW,WAAA,GAAc,YAAA","file":"index.js","sourcesContent":["import * as React from \"react\";\nimport { cn } from \"@nucleux/utils\";\nimport { Mic, X, Check, Loader2 } from \"lucide-react\";\n\nexport type VoiceInputState = \"idle\" | \"recording\" | \"transcribing\";\n\nexport interface VoiceInputProps extends React.HTMLAttributes<HTMLDivElement> {\n /** Current state of the dictation flow. */\n state?: VoiceInputState;\n /** Elapsed time label while recording, e.g. `\"0:12\"`. */\n duration?: React.ReactNode;\n /** Transcribed text shown once available. */\n transcript?: React.ReactNode;\n /** Called from the idle mic button to start recording. */\n onStart?: () => void;\n /** Called to cancel/discard the recording. */\n onCancel?: () => void;\n /** Called to stop recording and confirm. */\n onConfirm?: () => void;\n}\n\nconst BAR_COUNT = 24;\n\nfunction Waveform() {\n return (\n <div className=\"flex h-8 flex-1 items-center gap-0.5\" aria-hidden=\"true\">\n {Array.from({ length: BAR_COUNT }).map((_, i) => (\n <span\n key={i}\n className=\"w-0.5 flex-1 rounded-full bg-info/70 animate-nx-typing\"\n style={{\n height: `${30 + ((i * 37) % 60)}%`,\n animationDelay: `${(i % 6) * 90}ms`,\n }}\n />\n ))}\n </div>\n );\n}\n\n/**\n * A composer in a live-dictation state — mic trigger, animated waveform while\n * recording, and a transcribing state — for voice input to the agent.\n * Source: Figma \"Expressive Input / Voice Input\".\n */\nexport const VoiceInput = React.forwardRef<HTMLDivElement, VoiceInputProps>(\n ({ state = \"idle\", duration, transcript, onStart, onCancel, onConfirm, className, ...props }, ref) => (\n <div\n ref={ref}\n className={cn(\n \"flex items-center gap-3 rounded-full border border-border bg-background px-3 py-2\",\n className,\n )}\n role=\"group\"\n aria-label=\"Voice input\"\n {...props}\n >\n {state === \"idle\" && (\n <>\n <button\n type=\"button\"\n aria-label=\"Start dictation\"\n onClick={onStart}\n className=\"inline-flex size-9 items-center justify-center rounded-full bg-muted text-foreground transition-colors hover:bg-accent focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring [&_svg]:size-4\"\n >\n <Mic aria-hidden=\"true\" />\n </button>\n <span className=\"flex-1 text-sm text-muted-foreground\">Tap to speak</span>\n </>\n )}\n\n {state === \"recording\" && (\n <>\n <button\n type=\"button\"\n aria-label=\"Cancel dictation\"\n onClick={onCancel}\n className=\"inline-flex size-9 items-center justify-center rounded-full text-muted-foreground transition-colors hover:bg-accent hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring [&_svg]:size-4\"\n >\n <X aria-hidden=\"true\" />\n </button>\n <Waveform />\n {duration && <span className=\"text-sm tabular-nums text-muted-foreground\">{duration}</span>}\n <button\n type=\"button\"\n aria-label=\"Stop and use recording\"\n onClick={onConfirm}\n className=\"inline-flex size-9 items-center justify-center rounded-full bg-info text-info-foreground transition-colors hover:bg-info/90 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring [&_svg]:size-4\"\n >\n <Check aria-hidden=\"true\" />\n </button>\n </>\n )}\n\n {state === \"transcribing\" && (\n <>\n <Loader2 className=\"size-4 shrink-0 animate-spin text-muted-foreground\" aria-hidden=\"true\" />\n <span className=\"flex-1 truncate text-sm text-muted-foreground\">\n {transcript ?? \"Transcribing…\"}\n </span>\n </>\n )}\n </div>\n ),\n);\nVoiceInput.displayName = \"VoiceInput\";\n"]}
|
package/package.json
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@nucleux/voice-input",
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"sideEffects": false,
|
|
6
|
+
"description": "VoiceInput — a live dictation bar with a waveform — Nucleux agentic UI for React.",
|
|
7
|
+
"keywords": [
|
|
8
|
+
"nucleux",
|
|
9
|
+
"react",
|
|
10
|
+
"ui",
|
|
11
|
+
"components",
|
|
12
|
+
"agentic",
|
|
13
|
+
"ai",
|
|
14
|
+
"tailwind",
|
|
15
|
+
"voice-input"
|
|
16
|
+
],
|
|
17
|
+
"main": "./dist/index.cjs",
|
|
18
|
+
"module": "./dist/index.js",
|
|
19
|
+
"types": "./dist/index.d.ts",
|
|
20
|
+
"exports": {
|
|
21
|
+
".": {
|
|
22
|
+
"types": "./dist/index.d.ts",
|
|
23
|
+
"import": "./dist/index.js",
|
|
24
|
+
"require": "./dist/index.cjs"
|
|
25
|
+
}
|
|
26
|
+
},
|
|
27
|
+
"files": [
|
|
28
|
+
"dist",
|
|
29
|
+
"README.md"
|
|
30
|
+
],
|
|
31
|
+
"peerDependencies": {
|
|
32
|
+
"react": ">=18",
|
|
33
|
+
"react-dom": ">=18"
|
|
34
|
+
},
|
|
35
|
+
"dependencies": {
|
|
36
|
+
"lucide-react": "^0.469.0",
|
|
37
|
+
"@nucleux/utils": "0.1.1"
|
|
38
|
+
},
|
|
39
|
+
"devDependencies": {
|
|
40
|
+
"tsup": "^8.3.5",
|
|
41
|
+
"typescript": "^5.7.2",
|
|
42
|
+
"@types/react": "^18.3.18",
|
|
43
|
+
"react": "^18.3.1"
|
|
44
|
+
},
|
|
45
|
+
"publishConfig": {
|
|
46
|
+
"access": "public"
|
|
47
|
+
},
|
|
48
|
+
"license": "MIT",
|
|
49
|
+
"repository": {
|
|
50
|
+
"type": "git",
|
|
51
|
+
"url": "git+https://github.com/intelligaia-open-labs/nucleux.git",
|
|
52
|
+
"directory": "packages/voice-input"
|
|
53
|
+
},
|
|
54
|
+
"homepage": "https://github.com/intelligaia-open-labs/nucleux#readme",
|
|
55
|
+
"scripts": {
|
|
56
|
+
"build": "tsup"
|
|
57
|
+
}
|
|
58
|
+
}
|