@nucleux/collapsible 0.2.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 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/collapsible
2
+
3
+ Single collapsible disclosure region — 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/collapsible @nucleux/tokens
11
+ ```
12
+
13
+ `react` / `react-dom` are peer dependencies.
14
+
15
+ ## Usage
16
+
17
+ ```tsx
18
+ import { Collapsible } from "@nucleux/collapsible";
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,116 @@
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 CollapsibleContext = React__namespace.createContext(null);
31
+ var useCollapsible = (component) => {
32
+ const ctx = React__namespace.useContext(CollapsibleContext);
33
+ if (!ctx) throw new Error(`${component} must be used within a Collapsible`);
34
+ return ctx;
35
+ };
36
+ var Collapsible = React__namespace.forwardRef(
37
+ ({ open, defaultOpen = false, onOpenChange, disabled = false, className, children, ...props }, ref) => {
38
+ const isControlled = open !== void 0;
39
+ const [internal, setInternal] = React__namespace.useState(defaultOpen);
40
+ const isOpen = isControlled ? open : internal;
41
+ const baseId = React__namespace.useId();
42
+ const contentId = `${baseId}-content`;
43
+ const triggerId = `${baseId}-trigger`;
44
+ const toggle = React__namespace.useCallback(() => {
45
+ if (disabled) return;
46
+ const next = !isOpen;
47
+ if (!isControlled) setInternal(next);
48
+ onOpenChange?.(next);
49
+ }, [disabled, isOpen, isControlled, onOpenChange]);
50
+ return /* @__PURE__ */ jsxRuntime.jsx("div", { ref, className: utils.cn(className), "data-state": isOpen ? "open" : "closed", ...props, children: /* @__PURE__ */ jsxRuntime.jsx(CollapsibleContext.Provider, { value: { open: isOpen, toggle, contentId, triggerId, disabled }, children }) });
51
+ }
52
+ );
53
+ Collapsible.displayName = "Collapsible";
54
+ var CollapsibleTrigger = React__namespace.forwardRef(
55
+ ({ className, children, hideChevron = false, onClick, ...props }, ref) => {
56
+ const { open, toggle, contentId, triggerId, disabled } = useCollapsible("CollapsibleTrigger");
57
+ return /* @__PURE__ */ jsxRuntime.jsxs(
58
+ "button",
59
+ {
60
+ ref,
61
+ type: "button",
62
+ id: triggerId,
63
+ "aria-expanded": open,
64
+ "aria-controls": contentId,
65
+ disabled,
66
+ onClick: (e) => {
67
+ onClick?.(e);
68
+ if (!e.defaultPrevented) toggle();
69
+ },
70
+ className: utils.cn(
71
+ "flex w-full items-center justify-between gap-2 text-sm font-medium text-foreground",
72
+ "focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-1 focus-visible:ring-offset-background",
73
+ "disabled:cursor-not-allowed disabled:opacity-50",
74
+ className
75
+ ),
76
+ ...props,
77
+ children: [
78
+ children,
79
+ !hideChevron && /* @__PURE__ */ jsxRuntime.jsx(
80
+ lucideReact.ChevronDown,
81
+ {
82
+ "aria-hidden": true,
83
+ className: utils.cn("h-4 w-4 shrink-0 text-muted-foreground transition-transform", open && "rotate-180")
84
+ }
85
+ )
86
+ ]
87
+ }
88
+ );
89
+ }
90
+ );
91
+ CollapsibleTrigger.displayName = "CollapsibleTrigger";
92
+ var CollapsibleContent = React__namespace.forwardRef(
93
+ ({ className, children, ...props }, ref) => {
94
+ const { open, contentId, triggerId } = useCollapsible("CollapsibleContent");
95
+ if (!open) return null;
96
+ return /* @__PURE__ */ jsxRuntime.jsx(
97
+ "div",
98
+ {
99
+ ref,
100
+ id: contentId,
101
+ role: "region",
102
+ "aria-labelledby": triggerId,
103
+ className: utils.cn("animate-nx-fade-in pt-1.5 text-sm text-muted-foreground", className),
104
+ ...props,
105
+ children
106
+ }
107
+ );
108
+ }
109
+ );
110
+ CollapsibleContent.displayName = "CollapsibleContent";
111
+
112
+ exports.Collapsible = Collapsible;
113
+ exports.CollapsibleContent = CollapsibleContent;
114
+ exports.CollapsibleTrigger = CollapsibleTrigger;
115
+ //# sourceMappingURL=index.cjs.map
116
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.tsx"],"names":["React","jsx","cn","jsxs","ChevronDown"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAYA,IAAM,kBAAA,GAA2BA,+BAA8C,IAAI,CAAA;AAEnF,IAAM,cAAA,GAAiB,CAAC,SAAA,KAAsB;AAC5C,EAAA,MAAM,GAAA,GAAYA,4BAAW,kBAAkB,CAAA;AAC/C,EAAA,IAAI,CAAC,GAAA,EAAK,MAAM,IAAI,KAAA,CAAM,CAAA,EAAG,SAAS,CAAA,kCAAA,CAAoC,CAAA;AAC1E,EAAA,OAAO,GAAA;AACT,CAAA;AAUO,IAAM,WAAA,GAAoBA,gBAAA,CAAA,UAAA;AAAA,EAC/B,CAAC,EAAE,IAAA,EAAM,WAAA,GAAc,KAAA,EAAO,YAAA,EAAc,QAAA,GAAW,KAAA,EAAO,SAAA,EAAW,QAAA,EAAU,GAAG,KAAA,IAAS,GAAA,KAAQ;AACrG,IAAA,MAAM,eAAe,IAAA,KAAS,MAAA;AAC9B,IAAA,MAAM,CAAC,QAAA,EAAU,WAAW,CAAA,GAAUA,0BAAS,WAAW,CAAA;AAC1D,IAAA,MAAM,MAAA,GAAS,eAAe,IAAA,GAAO,QAAA;AACrC,IAAA,MAAM,SAAeA,gBAAA,CAAA,KAAA,EAAM;AAC3B,IAAA,MAAM,SAAA,GAAY,GAAG,MAAM,CAAA,QAAA,CAAA;AAC3B,IAAA,MAAM,SAAA,GAAY,GAAG,MAAM,CAAA,QAAA,CAAA;AAE3B,IAAA,MAAM,MAAA,GAAeA,6BAAY,MAAM;AACrC,MAAA,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B,MAAA,EAAO;AAAA,QAClC,CAAA;AAAA,QACA,SAAA,EAAWD,QAAA;AAAA,UACT,oFAAA;AAAA,UACA,0IAAA;AAAA,UACA,iDAAA;AAAA,UACA;AAAA,SACF;AAAA,QACC,GAAG,KAAA;AAAA,QAEH,QAAA,EAAA;AAAA,UAAA,QAAA;AAAA,UACA,CAAC,WAAA,oBACAD,cAAA;AAAA,YAACG,uBAAA;AAAA,YAAA;AAAA,cACC,aAAA,EAAW,IAAA;AAAA,cACX,SAAA,EAAWF,QAAA,CAAG,6DAAA,EAA+D,IAAA,IAAQ,YAAY;AAAA;AAAA;AACnG;AAAA;AAAA,KAEJ;AAAA,EAEJ;AACF;AACA,kBAAA,CAAmB,WAAA,GAAc,oBAAA;AAK1B,IAAM,kBAAA,GAA2BF,gBAAA,CAAA,UAAA;AAAA,EACtC,CAAC,EAAE,SAAA,EAAW,UAAU,GAAG,KAAA,IAAS,GAAA,KAAQ;AAC1C,IAAA,MAAM,EAAE,IAAA,EAAM,SAAA,EAAW,SAAA,EAAU,GAAI,eAAe,oBAAoB,CAAA;AAC1E,IAAA,IAAI,CAAC,MAAM,OAAO,IAAA;AAClB,IAAA,uBACEC,cAAA;AAAA,MAAC,KAAA;AAAA,MAAA;AAAA,QACC,GAAA;AAAA,QACA,EAAA,EAAI,SAAA;AAAA,QACJ,IAAA,EAAK,QAAA;AAAA,QACL,iBAAA,EAAiB,SAAA;AAAA,QACjB,SAAA,EAAWC,QAAA,CAAG,yDAAA,EAA2D,SAAS,CAAA;AAAA,QACjF,GAAG,KAAA;AAAA,QAEH;AAAA;AAAA,KACH;AAAA,EAEJ;AACF;AACA,kBAAA,CAAmB,WAAA,GAAc,oBAAA","file":"index.cjs","sourcesContent":["import * as React from \"react\";\nimport { ChevronDown } from \"lucide-react\";\nimport { cn } from \"@nucleux/utils\";\n\ninterface CollapsibleContextValue {\n open: boolean;\n toggle: () => void;\n contentId: string;\n triggerId: string;\n disabled: boolean;\n}\n\nconst CollapsibleContext = React.createContext<CollapsibleContextValue | null>(null);\n\nconst useCollapsible = (component: string) => {\n const ctx = React.useContext(CollapsibleContext);\n if (!ctx) throw new Error(`${component} must be used within a Collapsible`);\n return ctx;\n};\n\nexport interface CollapsibleProps extends React.HTMLAttributes<HTMLDivElement> {\n open?: boolean;\n defaultOpen?: boolean;\n onOpenChange?: (open: boolean) => void;\n disabled?: boolean;\n}\n\n/** A disclosure region that expands/collapses its content. */\nexport const Collapsible = React.forwardRef<HTMLDivElement, CollapsibleProps>(\n ({ open, defaultOpen = false, onOpenChange, disabled = false, className, children, ...props }, ref) => {\n const isControlled = open !== undefined;\n const [internal, setInternal] = React.useState(defaultOpen);\n const isOpen = isControlled ? open : internal;\n const baseId = React.useId();\n const contentId = `${baseId}-content`;\n const triggerId = `${baseId}-trigger`;\n\n const toggle = React.useCallback(() => {\n if (disabled) return;\n const next = !isOpen;\n if (!isControlled) setInternal(next);\n onOpenChange?.(next);\n }, [disabled, isOpen, isControlled, onOpenChange]);\n\n return (\n <div ref={ref} className={cn(className)} data-state={isOpen ? \"open\" : \"closed\"} {...props}>\n <CollapsibleContext.Provider value={{ open: isOpen, toggle, contentId, triggerId, disabled }}>\n {children}\n </CollapsibleContext.Provider>\n </div>\n );\n },\n);\nCollapsible.displayName = \"Collapsible\";\n\nexport interface CollapsibleTriggerProps\n extends React.ButtonHTMLAttributes<HTMLButtonElement> {\n /** Hide the default chevron affordance. */\n hideChevron?: boolean;\n}\n\n/** The button that toggles a {@link Collapsible}. */\nexport const CollapsibleTrigger = React.forwardRef<HTMLButtonElement, CollapsibleTriggerProps>(\n ({ className, children, hideChevron = false, onClick, ...props }, ref) => {\n const { open, toggle, contentId, triggerId, disabled } = useCollapsible(\"CollapsibleTrigger\");\n return (\n <button\n ref={ref}\n type=\"button\"\n id={triggerId}\n aria-expanded={open}\n aria-controls={contentId}\n disabled={disabled}\n onClick={(e) => {\n onClick?.(e);\n if (!e.defaultPrevented) toggle();\n }}\n className={cn(\n \"flex w-full items-center justify-between gap-2 text-sm font-medium text-foreground\",\n \"focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-1 focus-visible:ring-offset-background\",\n \"disabled:cursor-not-allowed disabled:opacity-50\",\n className,\n )}\n {...props}\n >\n {children}\n {!hideChevron && (\n <ChevronDown\n aria-hidden\n className={cn(\"h-4 w-4 shrink-0 text-muted-foreground transition-transform\", open && \"rotate-180\")}\n />\n )}\n </button>\n );\n },\n);\nCollapsibleTrigger.displayName = \"CollapsibleTrigger\";\n\nexport type CollapsibleContentProps = React.HTMLAttributes<HTMLDivElement>;\n\n/** The region revealed when a {@link Collapsible} is open. */\nexport const CollapsibleContent = React.forwardRef<HTMLDivElement, CollapsibleContentProps>(\n ({ className, children, ...props }, ref) => {\n const { open, contentId, triggerId } = useCollapsible(\"CollapsibleContent\");\n if (!open) return null;\n return (\n <div\n ref={ref}\n id={contentId}\n role=\"region\"\n aria-labelledby={triggerId}\n className={cn(\"animate-nx-fade-in pt-1.5 text-sm text-muted-foreground\", className)}\n {...props}\n >\n {children}\n </div>\n );\n },\n);\nCollapsibleContent.displayName = \"CollapsibleContent\";\n"]}
@@ -0,0 +1,21 @@
1
+ import * as React from 'react';
2
+
3
+ interface CollapsibleProps extends React.HTMLAttributes<HTMLDivElement> {
4
+ open?: boolean;
5
+ defaultOpen?: boolean;
6
+ onOpenChange?: (open: boolean) => void;
7
+ disabled?: boolean;
8
+ }
9
+ /** A disclosure region that expands/collapses its content. */
10
+ declare const Collapsible: React.ForwardRefExoticComponent<CollapsibleProps & React.RefAttributes<HTMLDivElement>>;
11
+ interface CollapsibleTriggerProps extends React.ButtonHTMLAttributes<HTMLButtonElement> {
12
+ /** Hide the default chevron affordance. */
13
+ hideChevron?: boolean;
14
+ }
15
+ /** The button that toggles a {@link Collapsible}. */
16
+ declare const CollapsibleTrigger: React.ForwardRefExoticComponent<CollapsibleTriggerProps & React.RefAttributes<HTMLButtonElement>>;
17
+ type CollapsibleContentProps = React.HTMLAttributes<HTMLDivElement>;
18
+ /** The region revealed when a {@link Collapsible} is open. */
19
+ declare const CollapsibleContent: React.ForwardRefExoticComponent<CollapsibleContentProps & React.RefAttributes<HTMLDivElement>>;
20
+
21
+ export { Collapsible, CollapsibleContent, type CollapsibleContentProps, type CollapsibleProps, CollapsibleTrigger, type CollapsibleTriggerProps };
@@ -0,0 +1,21 @@
1
+ import * as React from 'react';
2
+
3
+ interface CollapsibleProps extends React.HTMLAttributes<HTMLDivElement> {
4
+ open?: boolean;
5
+ defaultOpen?: boolean;
6
+ onOpenChange?: (open: boolean) => void;
7
+ disabled?: boolean;
8
+ }
9
+ /** A disclosure region that expands/collapses its content. */
10
+ declare const Collapsible: React.ForwardRefExoticComponent<CollapsibleProps & React.RefAttributes<HTMLDivElement>>;
11
+ interface CollapsibleTriggerProps extends React.ButtonHTMLAttributes<HTMLButtonElement> {
12
+ /** Hide the default chevron affordance. */
13
+ hideChevron?: boolean;
14
+ }
15
+ /** The button that toggles a {@link Collapsible}. */
16
+ declare const CollapsibleTrigger: React.ForwardRefExoticComponent<CollapsibleTriggerProps & React.RefAttributes<HTMLButtonElement>>;
17
+ type CollapsibleContentProps = React.HTMLAttributes<HTMLDivElement>;
18
+ /** The region revealed when a {@link Collapsible} is open. */
19
+ declare const CollapsibleContent: React.ForwardRefExoticComponent<CollapsibleContentProps & React.RefAttributes<HTMLDivElement>>;
20
+
21
+ export { Collapsible, CollapsibleContent, type CollapsibleContentProps, type CollapsibleProps, CollapsibleTrigger, type CollapsibleTriggerProps };
package/dist/index.js ADDED
@@ -0,0 +1,92 @@
1
+ "use client";
2
+ import * as React from 'react';
3
+ import { ChevronDown } from 'lucide-react';
4
+ import { cn } from '@nucleux/utils';
5
+ import { jsx, jsxs } from 'react/jsx-runtime';
6
+
7
+ // src/index.tsx
8
+ var CollapsibleContext = React.createContext(null);
9
+ var useCollapsible = (component) => {
10
+ const ctx = React.useContext(CollapsibleContext);
11
+ if (!ctx) throw new Error(`${component} must be used within a Collapsible`);
12
+ return ctx;
13
+ };
14
+ var Collapsible = React.forwardRef(
15
+ ({ open, defaultOpen = false, onOpenChange, disabled = false, className, children, ...props }, ref) => {
16
+ const isControlled = open !== void 0;
17
+ const [internal, setInternal] = React.useState(defaultOpen);
18
+ const isOpen = isControlled ? open : internal;
19
+ const baseId = React.useId();
20
+ const contentId = `${baseId}-content`;
21
+ const triggerId = `${baseId}-trigger`;
22
+ const toggle = React.useCallback(() => {
23
+ if (disabled) return;
24
+ const next = !isOpen;
25
+ if (!isControlled) setInternal(next);
26
+ onOpenChange?.(next);
27
+ }, [disabled, isOpen, isControlled, onOpenChange]);
28
+ return /* @__PURE__ */ jsx("div", { ref, className: cn(className), "data-state": isOpen ? "open" : "closed", ...props, children: /* @__PURE__ */ jsx(CollapsibleContext.Provider, { value: { open: isOpen, toggle, contentId, triggerId, disabled }, children }) });
29
+ }
30
+ );
31
+ Collapsible.displayName = "Collapsible";
32
+ var CollapsibleTrigger = React.forwardRef(
33
+ ({ className, children, hideChevron = false, onClick, ...props }, ref) => {
34
+ const { open, toggle, contentId, triggerId, disabled } = useCollapsible("CollapsibleTrigger");
35
+ return /* @__PURE__ */ jsxs(
36
+ "button",
37
+ {
38
+ ref,
39
+ type: "button",
40
+ id: triggerId,
41
+ "aria-expanded": open,
42
+ "aria-controls": contentId,
43
+ disabled,
44
+ onClick: (e) => {
45
+ onClick?.(e);
46
+ if (!e.defaultPrevented) toggle();
47
+ },
48
+ className: cn(
49
+ "flex w-full items-center justify-between gap-2 text-sm font-medium text-foreground",
50
+ "focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-1 focus-visible:ring-offset-background",
51
+ "disabled:cursor-not-allowed disabled:opacity-50",
52
+ className
53
+ ),
54
+ ...props,
55
+ children: [
56
+ children,
57
+ !hideChevron && /* @__PURE__ */ jsx(
58
+ ChevronDown,
59
+ {
60
+ "aria-hidden": true,
61
+ className: cn("h-4 w-4 shrink-0 text-muted-foreground transition-transform", open && "rotate-180")
62
+ }
63
+ )
64
+ ]
65
+ }
66
+ );
67
+ }
68
+ );
69
+ CollapsibleTrigger.displayName = "CollapsibleTrigger";
70
+ var CollapsibleContent = React.forwardRef(
71
+ ({ className, children, ...props }, ref) => {
72
+ const { open, contentId, triggerId } = useCollapsible("CollapsibleContent");
73
+ if (!open) return null;
74
+ return /* @__PURE__ */ jsx(
75
+ "div",
76
+ {
77
+ ref,
78
+ id: contentId,
79
+ role: "region",
80
+ "aria-labelledby": triggerId,
81
+ className: cn("animate-nx-fade-in pt-1.5 text-sm text-muted-foreground", className),
82
+ ...props,
83
+ children
84
+ }
85
+ );
86
+ }
87
+ );
88
+ CollapsibleContent.displayName = "CollapsibleContent";
89
+
90
+ export { Collapsible, CollapsibleContent, CollapsibleTrigger };
91
+ //# sourceMappingURL=index.js.map
92
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.tsx"],"names":[],"mappings":";;;;;;AAYA,IAAM,kBAAA,GAA2B,oBAA8C,IAAI,CAAA;AAEnF,IAAM,cAAA,GAAiB,CAAC,SAAA,KAAsB;AAC5C,EAAA,MAAM,GAAA,GAAY,iBAAW,kBAAkB,CAAA;AAC/C,EAAA,IAAI,CAAC,GAAA,EAAK,MAAM,IAAI,KAAA,CAAM,CAAA,EAAG,SAAS,CAAA,kCAAA,CAAoC,CAAA;AAC1E,EAAA,OAAO,GAAA;AACT,CAAA;AAUO,IAAM,WAAA,GAAoB,KAAA,CAAA,UAAA;AAAA,EAC/B,CAAC,EAAE,IAAA,EAAM,WAAA,GAAc,KAAA,EAAO,YAAA,EAAc,QAAA,GAAW,KAAA,EAAO,SAAA,EAAW,QAAA,EAAU,GAAG,KAAA,IAAS,GAAA,KAAQ;AACrG,IAAA,MAAM,eAAe,IAAA,KAAS,MAAA;AAC9B,IAAA,MAAM,CAAC,QAAA,EAAU,WAAW,CAAA,GAAU,eAAS,WAAW,CAAA;AAC1D,IAAA,MAAM,MAAA,GAA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AAAA,EAEJ;AACF;AACA,kBAAA,CAAmB,WAAA,GAAc,oBAAA","file":"index.js","sourcesContent":["import * as React from \"react\";\nimport { ChevronDown } from \"lucide-react\";\nimport { cn } from \"@nucleux/utils\";\n\ninterface CollapsibleContextValue {\n open: boolean;\n toggle: () => void;\n contentId: string;\n triggerId: string;\n disabled: boolean;\n}\n\nconst CollapsibleContext = React.createContext<CollapsibleContextValue | null>(null);\n\nconst useCollapsible = (component: string) => {\n const ctx = React.useContext(CollapsibleContext);\n if (!ctx) throw new Error(`${component} must be used within a Collapsible`);\n return ctx;\n};\n\nexport interface CollapsibleProps extends React.HTMLAttributes<HTMLDivElement> {\n open?: boolean;\n defaultOpen?: boolean;\n onOpenChange?: (open: boolean) => void;\n disabled?: boolean;\n}\n\n/** A disclosure region that expands/collapses its content. */\nexport const Collapsible = React.forwardRef<HTMLDivElement, CollapsibleProps>(\n ({ open, defaultOpen = false, onOpenChange, disabled = false, className, children, ...props }, ref) => {\n const isControlled = open !== undefined;\n const [internal, setInternal] = React.useState(defaultOpen);\n const isOpen = isControlled ? open : internal;\n const baseId = React.useId();\n const contentId = `${baseId}-content`;\n const triggerId = `${baseId}-trigger`;\n\n const toggle = React.useCallback(() => {\n if (disabled) return;\n const next = !isOpen;\n if (!isControlled) setInternal(next);\n onOpenChange?.(next);\n }, [disabled, isOpen, isControlled, onOpenChange]);\n\n return (\n <div ref={ref} className={cn(className)} data-state={isOpen ? \"open\" : \"closed\"} {...props}>\n <CollapsibleContext.Provider value={{ open: isOpen, toggle, contentId, triggerId, disabled }}>\n {children}\n </CollapsibleContext.Provider>\n </div>\n );\n },\n);\nCollapsible.displayName = \"Collapsible\";\n\nexport interface CollapsibleTriggerProps\n extends React.ButtonHTMLAttributes<HTMLButtonElement> {\n /** Hide the default chevron affordance. */\n hideChevron?: boolean;\n}\n\n/** The button that toggles a {@link Collapsible}. */\nexport const CollapsibleTrigger = React.forwardRef<HTMLButtonElement, CollapsibleTriggerProps>(\n ({ className, children, hideChevron = false, onClick, ...props }, ref) => {\n const { open, toggle, contentId, triggerId, disabled } = useCollapsible(\"CollapsibleTrigger\");\n return (\n <button\n ref={ref}\n type=\"button\"\n id={triggerId}\n aria-expanded={open}\n aria-controls={contentId}\n disabled={disabled}\n onClick={(e) => {\n onClick?.(e);\n if (!e.defaultPrevented) toggle();\n }}\n className={cn(\n \"flex w-full items-center justify-between gap-2 text-sm font-medium text-foreground\",\n \"focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-1 focus-visible:ring-offset-background\",\n \"disabled:cursor-not-allowed disabled:opacity-50\",\n className,\n )}\n {...props}\n >\n {children}\n {!hideChevron && (\n <ChevronDown\n aria-hidden\n className={cn(\"h-4 w-4 shrink-0 text-muted-foreground transition-transform\", open && \"rotate-180\")}\n />\n )}\n </button>\n );\n },\n);\nCollapsibleTrigger.displayName = \"CollapsibleTrigger\";\n\nexport type CollapsibleContentProps = React.HTMLAttributes<HTMLDivElement>;\n\n/** The region revealed when a {@link Collapsible} is open. */\nexport const CollapsibleContent = React.forwardRef<HTMLDivElement, CollapsibleContentProps>(\n ({ className, children, ...props }, ref) => {\n const { open, contentId, triggerId } = useCollapsible(\"CollapsibleContent\");\n if (!open) return null;\n return (\n <div\n ref={ref}\n id={contentId}\n role=\"region\"\n aria-labelledby={triggerId}\n className={cn(\"animate-nx-fade-in pt-1.5 text-sm text-muted-foreground\", className)}\n {...props}\n >\n {children}\n </div>\n );\n },\n);\nCollapsibleContent.displayName = \"CollapsibleContent\";\n"]}
package/package.json ADDED
@@ -0,0 +1,58 @@
1
+ {
2
+ "name": "@nucleux/collapsible",
3
+ "version": "0.2.0",
4
+ "type": "module",
5
+ "sideEffects": false,
6
+ "description": "Single collapsible disclosure region — Nucleux agentic UI for React.",
7
+ "keywords": [
8
+ "nucleux",
9
+ "react",
10
+ "ui",
11
+ "components",
12
+ "agentic",
13
+ "ai",
14
+ "tailwind",
15
+ "collapsible"
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.2.0"
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/collapsible"
53
+ },
54
+ "homepage": "https://github.com/intelligaia-open-labs/nucleux#readme",
55
+ "scripts": {
56
+ "build": "tsup"
57
+ }
58
+ }