@nucleux/structured-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 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/structured-input
2
+
3
+ StructuredInput — an agent's structured clarifying question — 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/structured-input @nucleux/tokens
11
+ ```
12
+
13
+ `react` / `react-dom` are peer dependencies.
14
+
15
+ ## Usage
16
+
17
+ ```tsx
18
+ import { StructuredInput } from "@nucleux/structured-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,149 @@
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 StructuredInput = React__namespace.forwardRef(
31
+ ({
32
+ question,
33
+ options,
34
+ multiple = false,
35
+ value,
36
+ defaultValue = [],
37
+ onValueChange,
38
+ allowOther = false,
39
+ otherPlaceholder = "Something else\u2026",
40
+ onSubmit,
41
+ onSkip,
42
+ submitLabel = "Continue",
43
+ skipLabel = "Skip",
44
+ className,
45
+ ...props
46
+ }, ref) => {
47
+ const [internal, setInternal] = React__namespace.useState(defaultValue);
48
+ const [other, setOther] = React__namespace.useState("");
49
+ const selected = value !== void 0 ? value : internal;
50
+ const setSelected = (next) => {
51
+ if (value === void 0) setInternal(next);
52
+ onValueChange?.(next);
53
+ };
54
+ const toggle = (val) => {
55
+ if (multiple) {
56
+ setSelected(selected.includes(val) ? selected.filter((v) => v !== val) : [...selected, val]);
57
+ } else {
58
+ setSelected([val]);
59
+ }
60
+ };
61
+ return /* @__PURE__ */ jsxRuntime.jsxs(
62
+ "div",
63
+ {
64
+ ref,
65
+ className: utils.cn("flex flex-col gap-4 rounded-xl border border-border bg-background p-5", className),
66
+ ...props,
67
+ children: [
68
+ /* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-base font-medium text-foreground", children: question }),
69
+ /* @__PURE__ */ jsxRuntime.jsx(
70
+ "div",
71
+ {
72
+ role: multiple ? "group" : "radiogroup",
73
+ "aria-label": typeof question === "string" ? question : "Options",
74
+ className: "flex flex-col gap-2",
75
+ children: options.map((option) => {
76
+ const active = selected.includes(option.value);
77
+ return /* @__PURE__ */ jsxRuntime.jsxs(
78
+ "button",
79
+ {
80
+ type: "button",
81
+ role: multiple ? "checkbox" : "radio",
82
+ "aria-checked": active,
83
+ onClick: () => toggle(option.value),
84
+ className: utils.cn(
85
+ "flex items-center gap-3 rounded-lg border px-3 py-2.5 text-left text-sm transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",
86
+ active ? "border-brand bg-brand-muted/50 text-foreground" : "border-border bg-background text-foreground hover:bg-accent"
87
+ ),
88
+ children: [
89
+ /* @__PURE__ */ jsxRuntime.jsx(
90
+ "span",
91
+ {
92
+ className: utils.cn(
93
+ "inline-flex size-5 shrink-0 items-center justify-center border transition-colors [&_svg]:size-3.5",
94
+ multiple ? "rounded-md" : "rounded-full",
95
+ active ? "border-brand bg-brand text-brand-foreground" : "border-border"
96
+ ),
97
+ children: active && /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Check, { "aria-hidden": "true" })
98
+ }
99
+ ),
100
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "flex-1", children: option.label })
101
+ ]
102
+ },
103
+ option.value
104
+ );
105
+ })
106
+ }
107
+ ),
108
+ allowOther && /* @__PURE__ */ jsxRuntime.jsx(
109
+ "input",
110
+ {
111
+ type: "text",
112
+ value: other,
113
+ onChange: (e) => setOther(e.target.value),
114
+ placeholder: otherPlaceholder,
115
+ "aria-label": otherPlaceholder,
116
+ className: "rounded-lg border border-input bg-background px-3 py-2 text-sm text-foreground placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring"
117
+ }
118
+ ),
119
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-end gap-2", children: [
120
+ onSkip && /* @__PURE__ */ jsxRuntime.jsx(
121
+ "button",
122
+ {
123
+ type: "button",
124
+ onClick: onSkip,
125
+ className: "inline-flex items-center rounded-lg px-3 py-2 text-sm font-medium text-muted-foreground transition-colors hover:bg-accent hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",
126
+ children: skipLabel
127
+ }
128
+ ),
129
+ onSubmit && /* @__PURE__ */ jsxRuntime.jsx(
130
+ "button",
131
+ {
132
+ type: "button",
133
+ onClick: () => onSubmit(selected, allowOther ? other : void 0),
134
+ disabled: selected.length === 0 && !(allowOther && other.trim()),
135
+ className: "inline-flex items-center rounded-lg bg-info px-3 py-2 text-sm font-medium text-info-foreground transition-colors hover:bg-info/90 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:pointer-events-none disabled:opacity-50",
136
+ children: submitLabel
137
+ }
138
+ )
139
+ ] })
140
+ ]
141
+ }
142
+ );
143
+ }
144
+ );
145
+ StructuredInput.displayName = "StructuredInput";
146
+
147
+ exports.StructuredInput = StructuredInput;
148
+ //# sourceMappingURL=index.cjs.map
149
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.tsx"],"names":["React","jsxs","cn","jsx","Check"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AA0CO,IAAM,eAAA,GAAwBA,gBAAA,CAAA,UAAA;AAAA,EACnC,CACE;AAAA,IACE,QAAA;AAAA,IACA,OAAA;AAAA,IACA,QAAA,GAAW,KAAA;AAAA,IACX,KAAA;AAAA,IACA,eAAe,EAAC;AAAA,IAChB,aAAA;AAAA,IACA,UAAA,GAAa,KAAA;AAAA,IACb,gBAAA,GAAmB,sBAAA;AAAA,IACnB,QAAA;AAAA,I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O,KAAA;AAAA,cACP,UAAU,CAAC,CAAA,KAAM,QAAA,CAAS,CAAA,CAAE,OAAO,KAAK,CAAA;AAAA,cACxC,WAAA,EAAa,gBAAA;AAAA,cACb,YAAA,EAAY,gBAAA;AAAA,cACZ,SAAA,EAAU;AAAA;AAAA,WACZ;AAAA,0BAEFF,eAAA,CAAC,KAAA,EAAA,EAAI,SAAA,EAAU,qCAAA,EACZ,QAAA,EAAA;AAAA,YAAA,MAAA,oBACCE,cAAA;AAAA,cAAC,QAAA;AAAA,cAAA;AAAA,gBACC,IAAA,EAAK,QAAA;AAAA,gBACL,OAAA,EAAS,MAAA;AAAA,gBACT,SAAA,EAAU,yNAAA;AAAA,gBAET,QAAA,EAAA;AAAA;AAAA,aACH;AAAA,YAED,QAAA,oBACCA,cAAA;AAAA,cAAC,QAAA;AAAA,cAAA;AAAA,gBACC,IAAA,EAAK,QAAA;AAAA,gBACL,SAAS,MAAM,QAAA,CAAS,QAAA,EAAU,UAAA,GAAa,QAAQ,MAAS,CAAA;AAAA,gBAChE,UAAU,QAAA,CAAS,MAAA,KAAW,KAAK,EAAE,UAAA,IAAc,MAAM,IAAA,EAAK,CAAA;AAAA,gBAC9D,SAAA,EAAU,4PAAA;AAAA,gBAET,QAAA,EAAA;AAAA;AAAA;AACH,WAAA,EAEJ;AAAA;AAAA;AAAA,KACF;AAAA,EAEJ;AACF;AACA,eAAA,CAAgB,WAAA,GAAc,iBAAA","file":"index.cjs","sourcesContent":["import * as React from \"react\";\nimport { cn } from \"@nucleux/utils\";\nimport { Check } from \"lucide-react\";\n\nexport interface StructuredOption {\n /** Stable value. */\n value: string;\n /** Display label. */\n label: React.ReactNode;\n}\n\nexport interface StructuredInputProps\n extends Omit<React.HTMLAttributes<HTMLDivElement>, \"onChange\" | \"onSubmit\"> {\n /** The clarifying question the agent is asking. */\n question: React.ReactNode;\n /** The selectable answers. */\n options: StructuredOption[];\n /** Allow selecting more than one option. */\n multiple?: boolean;\n /** Selected values (controlled). */\n value?: string[];\n /** Initial selection (uncontrolled). */\n defaultValue?: string[];\n /** Called when the selection changes. */\n onValueChange?: (values: string[]) => void;\n /** Show a free-text \"something else\" escape. */\n allowOther?: boolean;\n /** Label for the other escape. Defaults to `\"Something else…\"`. */\n otherPlaceholder?: string;\n /** Called when the answer is submitted. */\n onSubmit?: (values: string[], other?: string) => void;\n /** Called when the user skips the question. Renders the skip control when set. */\n onSkip?: () => void;\n submitLabel?: React.ReactNode;\n skipLabel?: React.ReactNode;\n}\n\n/**\n * An agent-generated clarifying question rendered as a structured choice —\n * single or multi-select options, a free-text escape, and a skip.\n * Source: Figma \"Expressive Input / Structured Input\".\n */\nexport const StructuredInput = React.forwardRef<HTMLDivElement, StructuredInputProps>(\n (\n {\n question,\n options,\n multiple = false,\n value,\n defaultValue = [],\n onValueChange,\n allowOther = false,\n otherPlaceholder = \"Something else…\",\n onSubmit,\n onSkip,\n submitLabel = \"Continue\",\n skipLabel = \"Skip\",\n className,\n ...props\n },\n ref,\n ) => {\n const [internal, setInternal] = React.useState<string[]>(defaultValue);\n const [other, setOther] = React.useState(\"\");\n const selected = value !== undefined ? value : internal;\n\n const setSelected = (next: string[]) => {\n if (value === undefined) setInternal(next);\n onValueChange?.(next);\n };\n const toggle = (val: string) => {\n if (multiple) {\n setSelected(selected.includes(val) ? selected.filter((v) => v !== val) : [...selected, val]);\n } else {\n setSelected([val]);\n }\n };\n\n return (\n <div\n ref={ref}\n className={cn(\"flex flex-col gap-4 rounded-xl border border-border bg-background p-5\", className)}\n {...props}\n >\n <p className=\"text-base font-medium text-foreground\">{question}</p>\n <div\n role={multiple ? \"group\" : \"radiogroup\"}\n aria-label={typeof question === \"string\" ? question : \"Options\"}\n className=\"flex flex-col gap-2\"\n >\n {options.map((option) => {\n const active = selected.includes(option.value);\n return (\n <button\n key={option.value}\n type=\"button\"\n role={multiple ? \"checkbox\" : \"radio\"}\n aria-checked={active}\n onClick={() => toggle(option.value)}\n className={cn(\n \"flex items-center gap-3 rounded-lg border px-3 py-2.5 text-left text-sm transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring\",\n active\n ? \"border-brand bg-brand-muted/50 text-foreground\"\n : \"border-border bg-background text-foreground hover:bg-accent\",\n )}\n >\n <span\n className={cn(\n \"inline-flex size-5 shrink-0 items-center justify-center border transition-colors [&_svg]:size-3.5\",\n multiple ? \"rounded-md\" : \"rounded-full\",\n active ? \"border-brand bg-brand text-brand-foreground\" : \"border-border\",\n )}\n >\n {active && <Check aria-hidden=\"true\" />}\n </span>\n <span className=\"flex-1\">{option.label}</span>\n </button>\n );\n })}\n </div>\n {allowOther && (\n <input\n type=\"text\"\n value={other}\n onChange={(e) => setOther(e.target.value)}\n placeholder={otherPlaceholder}\n aria-label={otherPlaceholder}\n className=\"rounded-lg border border-input bg-background px-3 py-2 text-sm text-foreground placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring\"\n />\n )}\n <div className=\"flex items-center justify-end gap-2\">\n {onSkip && (\n <button\n type=\"button\"\n onClick={onSkip}\n className=\"inline-flex items-center rounded-lg px-3 py-2 text-sm font-medium text-muted-foreground transition-colors hover:bg-accent hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring\"\n >\n {skipLabel}\n </button>\n )}\n {onSubmit && (\n <button\n type=\"button\"\n onClick={() => onSubmit(selected, allowOther ? other : undefined)}\n disabled={selected.length === 0 && !(allowOther && other.trim())}\n className=\"inline-flex items-center rounded-lg bg-info px-3 py-2 text-sm font-medium text-info-foreground transition-colors hover:bg-info/90 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:pointer-events-none disabled:opacity-50\"\n >\n {submitLabel}\n </button>\n )}\n </div>\n </div>\n );\n },\n);\nStructuredInput.displayName = \"StructuredInput\";\n"]}
@@ -0,0 +1,40 @@
1
+ import * as React from 'react';
2
+
3
+ interface StructuredOption {
4
+ /** Stable value. */
5
+ value: string;
6
+ /** Display label. */
7
+ label: React.ReactNode;
8
+ }
9
+ interface StructuredInputProps extends Omit<React.HTMLAttributes<HTMLDivElement>, "onChange" | "onSubmit"> {
10
+ /** The clarifying question the agent is asking. */
11
+ question: React.ReactNode;
12
+ /** The selectable answers. */
13
+ options: StructuredOption[];
14
+ /** Allow selecting more than one option. */
15
+ multiple?: boolean;
16
+ /** Selected values (controlled). */
17
+ value?: string[];
18
+ /** Initial selection (uncontrolled). */
19
+ defaultValue?: string[];
20
+ /** Called when the selection changes. */
21
+ onValueChange?: (values: string[]) => void;
22
+ /** Show a free-text "something else" escape. */
23
+ allowOther?: boolean;
24
+ /** Label for the other escape. Defaults to `"Something else…"`. */
25
+ otherPlaceholder?: string;
26
+ /** Called when the answer is submitted. */
27
+ onSubmit?: (values: string[], other?: string) => void;
28
+ /** Called when the user skips the question. Renders the skip control when set. */
29
+ onSkip?: () => void;
30
+ submitLabel?: React.ReactNode;
31
+ skipLabel?: React.ReactNode;
32
+ }
33
+ /**
34
+ * An agent-generated clarifying question rendered as a structured choice —
35
+ * single or multi-select options, a free-text escape, and a skip.
36
+ * Source: Figma "Expressive Input / Structured Input".
37
+ */
38
+ declare const StructuredInput: React.ForwardRefExoticComponent<StructuredInputProps & React.RefAttributes<HTMLDivElement>>;
39
+
40
+ export { StructuredInput, type StructuredInputProps, type StructuredOption };
@@ -0,0 +1,40 @@
1
+ import * as React from 'react';
2
+
3
+ interface StructuredOption {
4
+ /** Stable value. */
5
+ value: string;
6
+ /** Display label. */
7
+ label: React.ReactNode;
8
+ }
9
+ interface StructuredInputProps extends Omit<React.HTMLAttributes<HTMLDivElement>, "onChange" | "onSubmit"> {
10
+ /** The clarifying question the agent is asking. */
11
+ question: React.ReactNode;
12
+ /** The selectable answers. */
13
+ options: StructuredOption[];
14
+ /** Allow selecting more than one option. */
15
+ multiple?: boolean;
16
+ /** Selected values (controlled). */
17
+ value?: string[];
18
+ /** Initial selection (uncontrolled). */
19
+ defaultValue?: string[];
20
+ /** Called when the selection changes. */
21
+ onValueChange?: (values: string[]) => void;
22
+ /** Show a free-text "something else" escape. */
23
+ allowOther?: boolean;
24
+ /** Label for the other escape. Defaults to `"Something else…"`. */
25
+ otherPlaceholder?: string;
26
+ /** Called when the answer is submitted. */
27
+ onSubmit?: (values: string[], other?: string) => void;
28
+ /** Called when the user skips the question. Renders the skip control when set. */
29
+ onSkip?: () => void;
30
+ submitLabel?: React.ReactNode;
31
+ skipLabel?: React.ReactNode;
32
+ }
33
+ /**
34
+ * An agent-generated clarifying question rendered as a structured choice —
35
+ * single or multi-select options, a free-text escape, and a skip.
36
+ * Source: Figma "Expressive Input / Structured Input".
37
+ */
38
+ declare const StructuredInput: React.ForwardRefExoticComponent<StructuredInputProps & React.RefAttributes<HTMLDivElement>>;
39
+
40
+ export { StructuredInput, type StructuredInputProps, type StructuredOption };
package/dist/index.js ADDED
@@ -0,0 +1,127 @@
1
+ "use client";
2
+ import * as React from 'react';
3
+ import { cn } from '@nucleux/utils';
4
+ import { Check } from 'lucide-react';
5
+ import { jsxs, jsx } from 'react/jsx-runtime';
6
+
7
+ // src/index.tsx
8
+ var StructuredInput = React.forwardRef(
9
+ ({
10
+ question,
11
+ options,
12
+ multiple = false,
13
+ value,
14
+ defaultValue = [],
15
+ onValueChange,
16
+ allowOther = false,
17
+ otherPlaceholder = "Something else\u2026",
18
+ onSubmit,
19
+ onSkip,
20
+ submitLabel = "Continue",
21
+ skipLabel = "Skip",
22
+ className,
23
+ ...props
24
+ }, ref) => {
25
+ const [internal, setInternal] = React.useState(defaultValue);
26
+ const [other, setOther] = React.useState("");
27
+ const selected = value !== void 0 ? value : internal;
28
+ const setSelected = (next) => {
29
+ if (value === void 0) setInternal(next);
30
+ onValueChange?.(next);
31
+ };
32
+ const toggle = (val) => {
33
+ if (multiple) {
34
+ setSelected(selected.includes(val) ? selected.filter((v) => v !== val) : [...selected, val]);
35
+ } else {
36
+ setSelected([val]);
37
+ }
38
+ };
39
+ return /* @__PURE__ */ jsxs(
40
+ "div",
41
+ {
42
+ ref,
43
+ className: cn("flex flex-col gap-4 rounded-xl border border-border bg-background p-5", className),
44
+ ...props,
45
+ children: [
46
+ /* @__PURE__ */ jsx("p", { className: "text-base font-medium text-foreground", children: question }),
47
+ /* @__PURE__ */ jsx(
48
+ "div",
49
+ {
50
+ role: multiple ? "group" : "radiogroup",
51
+ "aria-label": typeof question === "string" ? question : "Options",
52
+ className: "flex flex-col gap-2",
53
+ children: options.map((option) => {
54
+ const active = selected.includes(option.value);
55
+ return /* @__PURE__ */ jsxs(
56
+ "button",
57
+ {
58
+ type: "button",
59
+ role: multiple ? "checkbox" : "radio",
60
+ "aria-checked": active,
61
+ onClick: () => toggle(option.value),
62
+ className: cn(
63
+ "flex items-center gap-3 rounded-lg border px-3 py-2.5 text-left text-sm transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",
64
+ active ? "border-brand bg-brand-muted/50 text-foreground" : "border-border bg-background text-foreground hover:bg-accent"
65
+ ),
66
+ children: [
67
+ /* @__PURE__ */ jsx(
68
+ "span",
69
+ {
70
+ className: cn(
71
+ "inline-flex size-5 shrink-0 items-center justify-center border transition-colors [&_svg]:size-3.5",
72
+ multiple ? "rounded-md" : "rounded-full",
73
+ active ? "border-brand bg-brand text-brand-foreground" : "border-border"
74
+ ),
75
+ children: active && /* @__PURE__ */ jsx(Check, { "aria-hidden": "true" })
76
+ }
77
+ ),
78
+ /* @__PURE__ */ jsx("span", { className: "flex-1", children: option.label })
79
+ ]
80
+ },
81
+ option.value
82
+ );
83
+ })
84
+ }
85
+ ),
86
+ allowOther && /* @__PURE__ */ jsx(
87
+ "input",
88
+ {
89
+ type: "text",
90
+ value: other,
91
+ onChange: (e) => setOther(e.target.value),
92
+ placeholder: otherPlaceholder,
93
+ "aria-label": otherPlaceholder,
94
+ className: "rounded-lg border border-input bg-background px-3 py-2 text-sm text-foreground placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring"
95
+ }
96
+ ),
97
+ /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-end gap-2", children: [
98
+ onSkip && /* @__PURE__ */ jsx(
99
+ "button",
100
+ {
101
+ type: "button",
102
+ onClick: onSkip,
103
+ className: "inline-flex items-center rounded-lg px-3 py-2 text-sm font-medium text-muted-foreground transition-colors hover:bg-accent hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",
104
+ children: skipLabel
105
+ }
106
+ ),
107
+ onSubmit && /* @__PURE__ */ jsx(
108
+ "button",
109
+ {
110
+ type: "button",
111
+ onClick: () => onSubmit(selected, allowOther ? other : void 0),
112
+ disabled: selected.length === 0 && !(allowOther && other.trim()),
113
+ className: "inline-flex items-center rounded-lg bg-info px-3 py-2 text-sm font-medium text-info-foreground transition-colors hover:bg-info/90 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:pointer-events-none disabled:opacity-50",
114
+ children: submitLabel
115
+ }
116
+ )
117
+ ] })
118
+ ]
119
+ }
120
+ );
121
+ }
122
+ );
123
+ StructuredInput.displayName = "StructuredInput";
124
+
125
+ export { StructuredInput };
126
+ //# sourceMappingURL=index.js.map
127
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.tsx"],"names":[],"mappings":";;;;;;AA0CO,IAAM,eAAA,GAAwB,KAAA,CAAA,UAAA;AAAA,EACnC,CACE;AAAA,IACE,QAAA;AAAA,IACA,OAAA;AAAA,IACA,QAAA,GAAW,KAAA;AAAA,IACX,KAAA;AAAA,IACA,eAAe,EAAC;AAAA,IAChB,aAAA;AAAA,IACA,UAAA,GAAa,KAAA;AAAA,IACb,gBAAA,GAAmB,sBAAA;AAAA,IACnB,QAAA;AAAA,IACA,MAAA;AAAA,IACA,WAAA,GAAc,UAAA;AAAA,IACd,SAAA,GAAY,MAAA;AAAA,IACZ,SAAA;AAAA,IACA,GAAG;AAAA,KAEL,GAAA,KACG;AACH,IAAA,MAAM,CAAC,QAAA,EAAU,WAAW,CAAA,GAAU,eAAmB,YAAY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AAC,KAAA,EAAA,EAAI,SAAA,EAAU,qCAAA,EACZ,QAAA,EAAA;AAAA,YAAA,MAAA,oBACC,GAAA;AAAA,cAAC,QAAA;AAAA,cAAA;AAAA,gBACC,IAAA,EAAK,QAAA;AAAA,gBACL,OAAA,EAAS,MAAA;AAAA,gBACT,SAAA,EAAU,yNAAA;AAAA,gBAET,QAAA,EAAA;AAAA;AAAA,aACH;AAAA,YAED,QAAA,oBACC,GAAA;AAAA,cAAC,QAAA;AAAA,cAAA;AAAA,gBACC,IAAA,EAAK,QAAA;AAAA,gBACL,SAAS,MAAM,QAAA,CAAS,QAAA,EAAU,UAAA,GAAa,QAAQ,MAAS,CAAA;AAAA,gBAChE,UAAU,QAAA,CAAS,MAAA,KAAW,KAAK,EAAE,UAAA,IAAc,MAAM,IAAA,EAAK,CAAA;AAAA,gBAC9D,SAAA,EAAU,4PAAA;AAAA,gBAET,QAAA,EAAA;AAAA;AAAA;AACH,WAAA,EAEJ;AAAA;AAAA;AAAA,KACF;AAAA,EAEJ;AACF;AACA,eAAA,CAAgB,WAAA,GAAc,iBAAA","file":"index.js","sourcesContent":["import * as React from \"react\";\nimport { cn } from \"@nucleux/utils\";\nimport { Check } from \"lucide-react\";\n\nexport interface StructuredOption {\n /** Stable value. */\n value: string;\n /** Display label. */\n label: React.ReactNode;\n}\n\nexport interface StructuredInputProps\n extends Omit<React.HTMLAttributes<HTMLDivElement>, \"onChange\" | \"onSubmit\"> {\n /** The clarifying question the agent is asking. */\n question: React.ReactNode;\n /** The selectable answers. */\n options: StructuredOption[];\n /** Allow selecting more than one option. */\n multiple?: boolean;\n /** Selected values (controlled). */\n value?: string[];\n /** Initial selection (uncontrolled). */\n defaultValue?: string[];\n /** Called when the selection changes. */\n onValueChange?: (values: string[]) => void;\n /** Show a free-text \"something else\" escape. */\n allowOther?: boolean;\n /** Label for the other escape. Defaults to `\"Something else…\"`. */\n otherPlaceholder?: string;\n /** Called when the answer is submitted. */\n onSubmit?: (values: string[], other?: string) => void;\n /** Called when the user skips the question. Renders the skip control when set. */\n onSkip?: () => void;\n submitLabel?: React.ReactNode;\n skipLabel?: React.ReactNode;\n}\n\n/**\n * An agent-generated clarifying question rendered as a structured choice —\n * single or multi-select options, a free-text escape, and a skip.\n * Source: Figma \"Expressive Input / Structured Input\".\n */\nexport const StructuredInput = React.forwardRef<HTMLDivElement, StructuredInputProps>(\n (\n {\n question,\n options,\n multiple = false,\n value,\n defaultValue = [],\n onValueChange,\n allowOther = false,\n otherPlaceholder = \"Something else…\",\n onSubmit,\n onSkip,\n submitLabel = \"Continue\",\n skipLabel = \"Skip\",\n className,\n ...props\n },\n ref,\n ) => {\n const [internal, setInternal] = React.useState<string[]>(defaultValue);\n const [other, setOther] = React.useState(\"\");\n const selected = value !== undefined ? value : internal;\n\n const setSelected = (next: string[]) => {\n if (value === undefined) setInternal(next);\n onValueChange?.(next);\n };\n const toggle = (val: string) => {\n if (multiple) {\n setSelected(selected.includes(val) ? selected.filter((v) => v !== val) : [...selected, val]);\n } else {\n setSelected([val]);\n }\n };\n\n return (\n <div\n ref={ref}\n className={cn(\"flex flex-col gap-4 rounded-xl border border-border bg-background p-5\", className)}\n {...props}\n >\n <p className=\"text-base font-medium text-foreground\">{question}</p>\n <div\n role={multiple ? \"group\" : \"radiogroup\"}\n aria-label={typeof question === \"string\" ? question : \"Options\"}\n className=\"flex flex-col gap-2\"\n >\n {options.map((option) => {\n const active = selected.includes(option.value);\n return (\n <button\n key={option.value}\n type=\"button\"\n role={multiple ? \"checkbox\" : \"radio\"}\n aria-checked={active}\n onClick={() => toggle(option.value)}\n className={cn(\n \"flex items-center gap-3 rounded-lg border px-3 py-2.5 text-left text-sm transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring\",\n active\n ? \"border-brand bg-brand-muted/50 text-foreground\"\n : \"border-border bg-background text-foreground hover:bg-accent\",\n )}\n >\n <span\n className={cn(\n \"inline-flex size-5 shrink-0 items-center justify-center border transition-colors [&_svg]:size-3.5\",\n multiple ? \"rounded-md\" : \"rounded-full\",\n active ? \"border-brand bg-brand text-brand-foreground\" : \"border-border\",\n )}\n >\n {active && <Check aria-hidden=\"true\" />}\n </span>\n <span className=\"flex-1\">{option.label}</span>\n </button>\n );\n })}\n </div>\n {allowOther && (\n <input\n type=\"text\"\n value={other}\n onChange={(e) => setOther(e.target.value)}\n placeholder={otherPlaceholder}\n aria-label={otherPlaceholder}\n className=\"rounded-lg border border-input bg-background px-3 py-2 text-sm text-foreground placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring\"\n />\n )}\n <div className=\"flex items-center justify-end gap-2\">\n {onSkip && (\n <button\n type=\"button\"\n onClick={onSkip}\n className=\"inline-flex items-center rounded-lg px-3 py-2 text-sm font-medium text-muted-foreground transition-colors hover:bg-accent hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring\"\n >\n {skipLabel}\n </button>\n )}\n {onSubmit && (\n <button\n type=\"button\"\n onClick={() => onSubmit(selected, allowOther ? other : undefined)}\n disabled={selected.length === 0 && !(allowOther && other.trim())}\n className=\"inline-flex items-center rounded-lg bg-info px-3 py-2 text-sm font-medium text-info-foreground transition-colors hover:bg-info/90 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:pointer-events-none disabled:opacity-50\"\n >\n {submitLabel}\n </button>\n )}\n </div>\n </div>\n );\n },\n);\nStructuredInput.displayName = \"StructuredInput\";\n"]}
package/package.json ADDED
@@ -0,0 +1,58 @@
1
+ {
2
+ "name": "@nucleux/structured-input",
3
+ "version": "0.1.1",
4
+ "type": "module",
5
+ "sideEffects": false,
6
+ "description": "StructuredInput — an agent's structured clarifying question — Nucleux agentic UI for React.",
7
+ "keywords": [
8
+ "nucleux",
9
+ "react",
10
+ "ui",
11
+ "components",
12
+ "agentic",
13
+ "ai",
14
+ "tailwind",
15
+ "structured-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/structured-input"
53
+ },
54
+ "homepage": "https://github.com/intelligaia-open-labs/nucleux#readme",
55
+ "scripts": {
56
+ "build": "tsup"
57
+ }
58
+ }