@bonprix-ds/react-collapsible 1.0.8 → 1.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/dist/index.js +2 -65
- package/dist/src/Collapsible.d.ts +23 -4
- package/dist/src/Collapsible.js +74 -0
- package/dist/src/Collapsible.js.map +1 -0
- package/package.json +8 -9
- package/dist/index.js.map +0 -1
package/dist/index.js
CHANGED
|
@@ -1,65 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
import { useId as t, useImperativeHandle as n, useState as r } from "react";
|
|
4
|
-
import { tv as i } from "tailwind-variants";
|
|
5
|
-
import a from "@bonprix-ds/react-icon";
|
|
6
|
-
import { useInitialInView as o, usePrefersReducedMotion as s, useTransitionAfterInitialRender as c } from "@bonprix-ds/utils";
|
|
7
|
-
import { jsx as l, jsxs as u } from "react/jsx-runtime";
|
|
8
|
-
//#region src/Collapsible.tsx
|
|
9
|
-
var d = i({
|
|
10
|
-
slots: {
|
|
11
|
-
root: "preflight [word-break:break-word]",
|
|
12
|
-
trigger: [
|
|
13
|
-
"flex gap-6 justify-between w-full my-5 px-0.25 typography-h5 text-clr-on-bg-high text-start",
|
|
14
|
-
"rounded-sm focus-visible:outline outline-offset-2 outline-2 outline-clr-on-bg-high group hover:text-clr-on-bg-low",
|
|
15
|
-
"[[data-bpds=collapsible]_[data-bpds=collapsible]>_&]:mt-0"
|
|
16
|
-
],
|
|
17
|
-
icon: "fill-clr-on-bg-high transition [button[data-state='open']>&]:rotate-180 ease-out duration-300 group-hover:fill-clr-on-bg-low",
|
|
18
|
-
content: "typography-body1 text-clr-on-bg-high overflow-hidden"
|
|
19
|
-
},
|
|
20
|
-
variants: { isOpen: { true: { root: "mb-5" } } }
|
|
21
|
-
}), f = ({ title: i, children: f, initiallyOpened: p = !1, rootRef: m, imperativeRef: h, id: g, onOpen: _, onClose: v, onInitialInView: y }) => {
|
|
22
|
-
let [b, x] = r(p), { root: S, trigger: C, icon: w, content: T } = d({ isOpen: b }), E = o(m, y);
|
|
23
|
-
n(h, () => ({
|
|
24
|
-
open: () => {
|
|
25
|
-
x(!0), _?.();
|
|
26
|
-
},
|
|
27
|
-
close: () => {
|
|
28
|
-
x(!1), v?.();
|
|
29
|
-
}
|
|
30
|
-
}));
|
|
31
|
-
let D = t(), O = g ?? D, k = () => {
|
|
32
|
-
b ? v && v() : _ && _(), x(!b);
|
|
33
|
-
}, A = s(), { transitionAfterInitialRender: j } = c(), M = A ? { duration: 0 } : j;
|
|
34
|
-
return /* @__PURE__ */ u("div", {
|
|
35
|
-
className: S(),
|
|
36
|
-
ref: E,
|
|
37
|
-
"data-bpds": "collapsible",
|
|
38
|
-
"data-bpds-initially-opened": p,
|
|
39
|
-
children: [/* @__PURE__ */ u("button", {
|
|
40
|
-
id: O,
|
|
41
|
-
className: C(),
|
|
42
|
-
onClick: k,
|
|
43
|
-
"aria-expanded": b,
|
|
44
|
-
"aria-controls": `${O}-content`,
|
|
45
|
-
"data-state": b ? "open" : "closed",
|
|
46
|
-
type: "button",
|
|
47
|
-
children: [i, /* @__PURE__ */ l(a, {
|
|
48
|
-
variant: "arrow-down",
|
|
49
|
-
className: w()
|
|
50
|
-
})]
|
|
51
|
-
}), /* @__PURE__ */ l(e.div, {
|
|
52
|
-
id: `${O}-content`,
|
|
53
|
-
className: T(),
|
|
54
|
-
animate: { height: b ? "auto" : 0 },
|
|
55
|
-
transition: M,
|
|
56
|
-
inert: !b,
|
|
57
|
-
children: f
|
|
58
|
-
})]
|
|
59
|
-
});
|
|
60
|
-
};
|
|
61
|
-
f.displayName = "Collapsible";
|
|
62
|
-
//#endregion
|
|
63
|
-
export { f as default };
|
|
64
|
-
|
|
65
|
-
//# sourceMappingURL=index.js.map
|
|
1
|
+
import e from "./src/Collapsible.js";
|
|
2
|
+
export { e as default };
|
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import React, { ReactNode, Ref, RefObject } from "react";
|
|
2
2
|
export interface CollapsibleImperativeHandle {
|
|
3
|
+
expand: () => void;
|
|
4
|
+
collapse: () => void;
|
|
5
|
+
/** @deprecated [collapsible-expanded-props] Use `expand` instead. */
|
|
3
6
|
open: () => void;
|
|
7
|
+
/** @deprecated [collapsible-expanded-props] Use `collapse` instead. */
|
|
4
8
|
close: () => void;
|
|
5
9
|
}
|
|
6
10
|
export interface Props {
|
|
@@ -8,7 +12,12 @@ export interface Props {
|
|
|
8
12
|
title: ReactNode;
|
|
9
13
|
/** Content of the collapsible, which might be collapsed or expanded. */
|
|
10
14
|
children: ReactNode;
|
|
11
|
-
/** If `true`, the collapsible content will be initially
|
|
15
|
+
/** If `true`, the collapsible content will be initially expanded. */
|
|
16
|
+
initiallyExpanded?: boolean;
|
|
17
|
+
/**
|
|
18
|
+
* If `true`, the collapsible content will be initially expanded.
|
|
19
|
+
* @deprecated [collapsible-expanded-props] Use `initiallyExpanded` instead.
|
|
20
|
+
*/
|
|
12
21
|
initiallyOpened?: boolean;
|
|
13
22
|
/** A reference to the root element. */
|
|
14
23
|
rootRef?: RefObject<HTMLDivElement | null>;
|
|
@@ -16,15 +25,25 @@ export interface Props {
|
|
|
16
25
|
imperativeRef?: Ref<CollapsibleImperativeHandle>;
|
|
17
26
|
/** The id of the collapsible component. */
|
|
18
27
|
id?: string;
|
|
19
|
-
/** Callback function that is called when the collapsible component is
|
|
28
|
+
/** Callback function that is called when the collapsible component is expanded. */
|
|
29
|
+
onExpand?: () => void;
|
|
30
|
+
/** Callback function that is called when the collapsible component is collapsed. */
|
|
31
|
+
onCollapse?: () => void;
|
|
32
|
+
/**
|
|
33
|
+
* Callback function that is called when the collapsible component is expanded.
|
|
34
|
+
* @deprecated [collapsible-expanded-props] Use `onExpand` instead.
|
|
35
|
+
*/
|
|
20
36
|
onOpen?: () => void;
|
|
21
|
-
/**
|
|
37
|
+
/**
|
|
38
|
+
* Callback function that is called when the collapsible component is collapsed.
|
|
39
|
+
* @deprecated [collapsible-expanded-props] Use `onCollapse` instead.
|
|
40
|
+
*/
|
|
22
41
|
onClose?: () => void;
|
|
23
42
|
/** Callback function that is called when the collapsible component is initially in view. */
|
|
24
43
|
onInitialInView?: () => void;
|
|
25
44
|
}
|
|
26
45
|
declare const Collapsible: {
|
|
27
|
-
({ title, children, initiallyOpened, rootRef, imperativeRef, id, onOpen, onClose, onInitialInView }: Props): React.JSX.Element;
|
|
46
|
+
({ title, children, initiallyExpanded: initiallyExpandedProp, initiallyOpened, rootRef, imperativeRef, id, onExpand, onCollapse, onOpen, onClose, onInitialInView, }: Props): React.JSX.Element;
|
|
28
47
|
displayName: string;
|
|
29
48
|
};
|
|
30
49
|
export default Collapsible;
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { motion as e } from "motion/react";
|
|
3
|
+
import { useId as t, useImperativeHandle as n, useState as r } from "react";
|
|
4
|
+
import { tv as i } from "tailwind-variants";
|
|
5
|
+
import a from "@bonprix-ds/react-icon";
|
|
6
|
+
import { useInitialInView as o, usePrefersReducedMotion as s, useTransitionAfterInitialRender as c } from "@bonprix-ds/utils";
|
|
7
|
+
import { warnDeprecated as l } from "@bonprix-ds/utils/deprecation";
|
|
8
|
+
import { jsx as u, jsxs as d } from "react/jsx-runtime";
|
|
9
|
+
//#region src/Collapsible.tsx
|
|
10
|
+
var f = i({
|
|
11
|
+
slots: {
|
|
12
|
+
root: "preflight [word-break:break-word]",
|
|
13
|
+
trigger: [
|
|
14
|
+
"typography-h5 my-5 flex w-full justify-between gap-6 px-0.25 text-start text-clr-on-bg-high",
|
|
15
|
+
"group rounded-sm outline-2 outline-offset-2 outline-clr-on-bg-high hover:text-clr-on-bg-low focus-visible:outline",
|
|
16
|
+
"[[data-bpds=collapsible]_[data-bpds=collapsible]>_&]:mt-0"
|
|
17
|
+
],
|
|
18
|
+
icon: "fill-clr-on-bg-high transition duration-300 ease-out group-hover:fill-clr-on-bg-low [button[data-state='open']>&]:rotate-180",
|
|
19
|
+
content: "typography-body1 overflow-hidden text-clr-on-bg-high"
|
|
20
|
+
},
|
|
21
|
+
variants: { expanded: { true: { root: "mb-5" } } }
|
|
22
|
+
}), p = ({ title: i, children: p, initiallyExpanded: m, initiallyOpened: h, rootRef: g, imperativeRef: _, id: v, onExpand: y, onCollapse: b, onOpen: x, onClose: S, onInitialInView: C }) => {
|
|
23
|
+
(h !== void 0 || x || S) && l("collapsible-expanded-props");
|
|
24
|
+
let w = m ?? h ?? !1, [T, E] = r(w), { root: D, trigger: O, icon: k, content: A } = f({ expanded: T }), j = o(g, C), M = () => (y ?? x)?.(), N = () => (b ?? S)?.(), P = () => {
|
|
25
|
+
E(!0), M();
|
|
26
|
+
}, F = () => {
|
|
27
|
+
E(!1), N();
|
|
28
|
+
};
|
|
29
|
+
n(_, () => ({
|
|
30
|
+
expand: P,
|
|
31
|
+
collapse: F,
|
|
32
|
+
open: () => {
|
|
33
|
+
l("collapsible-expanded-props"), P();
|
|
34
|
+
},
|
|
35
|
+
close: () => {
|
|
36
|
+
l("collapsible-expanded-props"), F();
|
|
37
|
+
}
|
|
38
|
+
}));
|
|
39
|
+
let I = t(), L = v ?? I, R = () => {
|
|
40
|
+
T ? N() : M(), E(!T);
|
|
41
|
+
}, z = s(), { transitionAfterInitialRender: B } = c(), V = z ? { duration: 0 } : B;
|
|
42
|
+
return /* @__PURE__ */ d("div", {
|
|
43
|
+
className: D(),
|
|
44
|
+
ref: j,
|
|
45
|
+
"data-bpds": "collapsible",
|
|
46
|
+
"data-bpds-initially-expanded": w,
|
|
47
|
+
"data-bpds-initially-opened": w,
|
|
48
|
+
children: [/* @__PURE__ */ d("button", {
|
|
49
|
+
id: L,
|
|
50
|
+
className: O(),
|
|
51
|
+
onClick: R,
|
|
52
|
+
"aria-expanded": T,
|
|
53
|
+
"aria-controls": `${L}-content`,
|
|
54
|
+
"data-state": T ? "open" : "closed",
|
|
55
|
+
type: "button",
|
|
56
|
+
children: [i, /* @__PURE__ */ u(a, {
|
|
57
|
+
variant: "arrow-down",
|
|
58
|
+
className: k()
|
|
59
|
+
})]
|
|
60
|
+
}), /* @__PURE__ */ u(e.div, {
|
|
61
|
+
id: `${L}-content`,
|
|
62
|
+
className: A(),
|
|
63
|
+
animate: { height: T ? "auto" : 0 },
|
|
64
|
+
transition: V,
|
|
65
|
+
inert: !T,
|
|
66
|
+
children: p
|
|
67
|
+
})]
|
|
68
|
+
});
|
|
69
|
+
};
|
|
70
|
+
p.displayName = "Collapsible";
|
|
71
|
+
//#endregion
|
|
72
|
+
export { p as default };
|
|
73
|
+
|
|
74
|
+
//# sourceMappingURL=Collapsible.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Collapsible.js","names":["Icon","generateClasses","tv","Collapsible","initiallyExpandedProp","initiallyOpened","onOpen","onClose","warnDeprecated","initiallyExpanded","expanded","setExpanded","useState","ref","useInitialInView","rootRef","onInitialInView","handleExpand","onExpand","handleCollapse","onCollapse","expand","collapse","imperativeRef","generatedId","useId","collapsibleId","id","onExpandedChange","prefersReducedMotion","usePrefersReducedMotion","useTransitionAfterInitialRender","transition","transitionAfterInitialRender","root","trigger","title","icon","motion","content"],"sources":["../../src/Collapsible.tsx"],"sourcesContent":["\"use client\";\n\nimport { motion } from \"motion/react\";\nimport React, { ReactNode, Ref, RefObject, useId, useImperativeHandle, useState } from \"react\";\nimport { tv } from \"tailwind-variants\";\n\nimport Icon from \"@bonprix-ds/react-icon\";\nimport { useInitialInView, usePrefersReducedMotion, useTransitionAfterInitialRender } from \"@bonprix-ds/utils\";\nimport { warnDeprecated } from \"@bonprix-ds/utils/deprecation\";\n\nconst generateClasses = tv({\n slots: {\n // `word-break` not `overflow-wrap`: only the legacy `break-word` value also relaxes the\n // content-based minimum size of the flex `trigger`, so a long title wraps instead of widening it.\n root: \"preflight [word-break:break-word]\",\n trigger: [\n \"typography-h5 my-5 flex w-full justify-between gap-6 px-0.25 text-start text-clr-on-bg-high\",\n \"group rounded-sm outline-2 outline-offset-2 outline-clr-on-bg-high hover:text-clr-on-bg-low focus-visible:outline\",\n // Reduce spacing between nested Collapsibles\n \"[[data-bpds=collapsible]_[data-bpds=collapsible]>_&]:mt-0\",\n ],\n icon: \"fill-clr-on-bg-high transition duration-300 ease-out group-hover:fill-clr-on-bg-low [button[data-state='open']>&]:rotate-180\",\n content: \"typography-body1 overflow-hidden text-clr-on-bg-high\",\n },\n variants: {\n expanded: {\n true: {\n root: \"mb-5\",\n },\n },\n },\n});\n\nexport interface CollapsibleImperativeHandle {\n expand: () => void;\n collapse: () => void;\n /** @deprecated [collapsible-expanded-props] Use `expand` instead. */\n open: () => void;\n /** @deprecated [collapsible-expanded-props] Use `collapse` instead. */\n close: () => void;\n}\n\nexport interface Props {\n /** Brief summary or label for the content within the component. */\n title: ReactNode;\n /** Content of the collapsible, which might be collapsed or expanded. */\n children: ReactNode;\n /** If `true`, the collapsible content will be initially expanded. */\n initiallyExpanded?: boolean;\n /**\n * If `true`, the collapsible content will be initially expanded.\n * @deprecated [collapsible-expanded-props] Use `initiallyExpanded` instead.\n */\n initiallyOpened?: boolean;\n /** A reference to the root element. */\n rootRef?: RefObject<HTMLDivElement | null>;\n /** A reference to the imperative handle of the component. */\n imperativeRef?: Ref<CollapsibleImperativeHandle>;\n /** The id of the collapsible component. */\n id?: string;\n /** Callback function that is called when the collapsible component is expanded. */\n onExpand?: () => void;\n /** Callback function that is called when the collapsible component is collapsed. */\n onCollapse?: () => void;\n /**\n * Callback function that is called when the collapsible component is expanded.\n * @deprecated [collapsible-expanded-props] Use `onExpand` instead.\n */\n onOpen?: () => void;\n /**\n * Callback function that is called when the collapsible component is collapsed.\n * @deprecated [collapsible-expanded-props] Use `onCollapse` instead.\n */\n onClose?: () => void;\n /** Callback function that is called when the collapsible component is initially in view. */\n onInitialInView?: () => void;\n}\n\nconst Collapsible = ({\n title,\n children,\n initiallyExpanded: initiallyExpandedProp,\n initiallyOpened,\n rootRef,\n imperativeRef,\n id,\n onExpand,\n onCollapse,\n onOpen,\n onClose,\n onInitialInView,\n}: Props) => {\n if (initiallyOpened !== undefined || onOpen || onClose) warnDeprecated(\"collapsible-expanded-props\");\n const initiallyExpanded = initiallyExpandedProp ?? initiallyOpened ?? false;\n const [expanded, setExpanded] = useState(initiallyExpanded);\n const { root, trigger, icon, content } = generateClasses({ expanded });\n\n const ref = useInitialInView(rootRef, onInitialInView);\n\n const handleExpand = () => (onExpand ?? onOpen)?.();\n const handleCollapse = () => (onCollapse ?? onClose)?.();\n\n const expand = () => {\n setExpanded(true);\n handleExpand();\n };\n\n const collapse = () => {\n setExpanded(false);\n handleCollapse();\n };\n\n useImperativeHandle(imperativeRef, () => ({\n expand,\n collapse,\n open: () => {\n warnDeprecated(\"collapsible-expanded-props\");\n expand();\n },\n close: () => {\n warnDeprecated(\"collapsible-expanded-props\");\n collapse();\n },\n }));\n\n const generatedId = useId();\n const collapsibleId = id ?? generatedId;\n\n const onExpandedChange = () => {\n if (expanded) handleCollapse();\n else handleExpand();\n setExpanded(!expanded);\n };\n\n const prefersReducedMotion = usePrefersReducedMotion();\n const { transitionAfterInitialRender } = useTransitionAfterInitialRender();\n const transition = prefersReducedMotion ? { duration: 0 } : transitionAfterInitialRender;\n\n return (\n <div\n className={root()}\n ref={ref}\n data-bpds=\"collapsible\"\n data-bpds-initially-expanded={initiallyExpanded}\n // @deprecated [collapsible-expanded-props] data-bpds-initially-opened goes in the major, use data-bpds-initially-expanded\n data-bpds-initially-opened={initiallyExpanded}\n >\n <button\n id={collapsibleId}\n className={trigger()}\n onClick={onExpandedChange}\n aria-expanded={expanded}\n aria-controls={`${collapsibleId}-content`}\n data-state={expanded ? \"open\" : \"closed\"}\n type=\"button\"\n >\n {title}\n <Icon variant=\"arrow-down\" className={icon()} />\n </button>\n <motion.div\n id={`${collapsibleId}-content`}\n className={content()}\n animate={{ height: expanded ? \"auto\" : 0 }}\n transition={transition}\n inert={!expanded}\n >\n {children}\n </motion.div>\n </div>\n );\n};\n\nCollapsible.displayName = \"Collapsible\";\nexport default Collapsible;\n"],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AAD;GACE,IAAIiB;GACJ,WAAWS,EAAQ;GACnB,SAASP;GACT,iBAAelB;GACf,iBAAe,GAAGgB,EAAc;GAChC,cAAYhB,IAAW,SAAS;GAChC,MAAK;GAPP,UAAA,CASG0B,GACD,kBAACpC,GAAD;IAAM,SAAQ;IAAa,WAAWqC,EAAK;GAAI,CAAA,CACzC;EACR,CAAA,GAAA,kBAACC,EAAO,KAAR;GACE,IAAI,GAAGZ,EAAc;GACrB,WAAWa,EAAQ;GACnB,SAAS,EAAE,QAAQ7B,IAAW,SAAS,EAAE;GAC7B;GACZ,OAAO,CAACA;GAEP;EACS,CAAA,CACT;;AAET;AAEA,EAAY,cAAc"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bonprix-ds/react-collapsible",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"description": "Collapsible component, implemented in React, for the Bonprix Design System.",
|
|
5
5
|
"keywords": [],
|
|
6
6
|
"license": "UNLICENSED",
|
|
@@ -32,19 +32,18 @@
|
|
|
32
32
|
"provenance": true
|
|
33
33
|
},
|
|
34
34
|
"dependencies": {
|
|
35
|
-
"motion": "
|
|
36
|
-
"@bonprix-ds/react-icon": "1.2.
|
|
37
|
-
"@bonprix-ds/utils": "0.
|
|
35
|
+
"motion": "14.0.0",
|
|
36
|
+
"@bonprix-ds/react-icon": "1.2.2",
|
|
37
|
+
"@bonprix-ds/utils": "0.3.0"
|
|
38
38
|
},
|
|
39
39
|
"devDependencies": {
|
|
40
40
|
"@types/react": "19.3.0",
|
|
41
|
-
"
|
|
42
|
-
"
|
|
43
|
-
"vite": "8.3.0"
|
|
41
|
+
"vite": "8.3.2",
|
|
42
|
+
"@bonprix-ds/vite-config": "0.0.0"
|
|
44
43
|
},
|
|
45
44
|
"peerDependencies": {
|
|
46
|
-
"react": "^19
|
|
47
|
-
"react-dom": "^19
|
|
45
|
+
"react": "^19",
|
|
46
|
+
"react-dom": "^19",
|
|
48
47
|
"tailwind-variants": "0.3.1"
|
|
49
48
|
},
|
|
50
49
|
"scripts": {
|
package/dist/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[],"sources":["../src/Collapsible.tsx"],"sourcesContent":["\"use client\";\n\nimport { motion } from \"motion/react\";\nimport React, { ReactNode, Ref, RefObject, useId, useImperativeHandle, useState } from \"react\";\nimport { tv } from \"tailwind-variants\";\n\nimport Icon from \"@bonprix-ds/react-icon\";\nimport { useInitialInView, usePrefersReducedMotion, useTransitionAfterInitialRender } from \"@bonprix-ds/utils\";\n\nconst generateClasses = tv({\n slots: {\n // `word-break` not `overflow-wrap`: only the legacy `break-word` value also relaxes the\n // content-based minimum size of the flex `trigger`, so a long title wraps instead of widening it.\n root: \"preflight [word-break:break-word]\",\n trigger: [\n \"flex gap-6 justify-between w-full my-5 px-0.25 typography-h5 text-clr-on-bg-high text-start\",\n \"rounded-sm focus-visible:outline outline-offset-2 outline-2 outline-clr-on-bg-high group hover:text-clr-on-bg-low\",\n // Reduce spacing between nested Collapsibles\n \"[[data-bpds=collapsible]_[data-bpds=collapsible]>_&]:mt-0\",\n ],\n icon: \"fill-clr-on-bg-high transition [button[data-state='open']>&]:rotate-180 ease-out duration-300 group-hover:fill-clr-on-bg-low\",\n content: \"typography-body1 text-clr-on-bg-high overflow-hidden\",\n },\n variants: {\n isOpen: {\n true: {\n root: \"mb-5\",\n },\n },\n },\n});\n\nexport interface CollapsibleImperativeHandle {\n open: () => void;\n close: () => void;\n}\n\nexport interface Props {\n /** Brief summary or label for the content within the component. */\n title: ReactNode;\n /** Content of the collapsible, which might be collapsed or expanded. */\n children: ReactNode;\n /** If `true`, the collapsible content will be initially opened. */\n initiallyOpened?: boolean;\n /** A reference to the root element. */\n rootRef?: RefObject<HTMLDivElement | null>;\n /** A reference to the imperative handle of the component. */\n imperativeRef?: Ref<CollapsibleImperativeHandle>;\n /** The id of the collapsible component. */\n id?: string;\n /** Callback function that is called when the collapsible component is opened. */\n onOpen?: () => void;\n /** Callback function that is called when the collapsible component is closed. */\n onClose?: () => void;\n /** Callback function that is called when the collapsible component is initially in view. */\n onInitialInView?: () => void;\n}\n\nconst Collapsible = ({ title, children, initiallyOpened = false, rootRef, imperativeRef, id, onOpen, onClose, onInitialInView }: Props) => {\n const [open, setOpen] = useState(initiallyOpened);\n const { root, trigger, icon, content } = generateClasses({ isOpen: open });\n\n const ref = useInitialInView(rootRef, onInitialInView);\n\n useImperativeHandle(imperativeRef, () => ({\n open: () => {\n setOpen(true);\n onOpen?.();\n },\n close: () => {\n setOpen(false);\n onClose?.();\n },\n }));\n\n const generatedId = useId();\n const collapsibleId = id ?? generatedId;\n\n const onOpenChange = () => {\n if (open) {\n if (onClose) onClose();\n } else {\n if (onOpen) onOpen();\n }\n setOpen(!open);\n };\n\n const prefersReducedMotion = usePrefersReducedMotion();\n const { transitionAfterInitialRender } = useTransitionAfterInitialRender();\n const transition = prefersReducedMotion ? { duration: 0 } : transitionAfterInitialRender;\n\n return (\n <div className={root()} ref={ref} data-bpds=\"collapsible\" data-bpds-initially-opened={initiallyOpened}>\n <button\n id={collapsibleId}\n className={trigger()}\n onClick={onOpenChange}\n aria-expanded={open}\n aria-controls={`${collapsibleId}-content`}\n data-state={open ? \"open\" : \"closed\"}\n type=\"button\"\n >\n {title}\n <Icon variant=\"arrow-down\" className={icon()} />\n </button>\n <motion.div\n id={`${collapsibleId}-content`}\n className={content()}\n animate={{ height: open ? \"auto\" : 0 }}\n transition={transition}\n inert={!open}\n >\n {children}\n </motion.div>\n </div>\n );\n};\n\nCollapsible.displayName = \"Collapsible\";\nexport default Collapsible;\n"],"mappings":";;;;;;;;AASA,IAAM,IAAkB,EAAG;CACzB,OAAO;EAGL,MAAM;EACN,SAAS;GACP;GACA;GAEA;EACF;EACA,MAAM;EACN,SAAS;CACX;CACA,UAAU,EACR,QAAQ,EACN,MAAM,EACJ,MAAM,OACR,EACF,EAC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