@bonprix-ds/react-collapsible 1.1.4 → 1.2.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.
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import React, { ReactNode, Ref, RefObject } from "react";
|
|
2
|
+
import { TitleLevel } from "@bonprix-ds/utils";
|
|
2
3
|
export interface CollapsibleImperativeHandle {
|
|
3
4
|
expand: () => void;
|
|
4
5
|
collapse: () => void;
|
|
@@ -10,6 +11,8 @@ export interface CollapsibleImperativeHandle {
|
|
|
10
11
|
export interface Props {
|
|
11
12
|
/** Brief summary or label for the content within the component. */
|
|
12
13
|
title: ReactNode;
|
|
14
|
+
/** Renders the title as a heading of this level, so it is part of the page's heading structure. */
|
|
15
|
+
titleLevel?: TitleLevel;
|
|
13
16
|
/** Content of the collapsible, which might be collapsed or expanded. */
|
|
14
17
|
children: ReactNode;
|
|
15
18
|
/** If `true`, the collapsible content will be initially expanded. */
|
|
@@ -43,7 +46,7 @@ export interface Props {
|
|
|
43
46
|
onInitialInView?: () => void;
|
|
44
47
|
}
|
|
45
48
|
declare const Collapsible: {
|
|
46
|
-
({ title, children, initiallyExpanded: initiallyExpandedProp, initiallyOpened, rootRef, imperativeRef, id, onExpand, onCollapse, onOpen, onClose, onInitialInView, }: Props): React.JSX.Element;
|
|
49
|
+
({ title, titleLevel: TitleComponent, children, initiallyExpanded: initiallyExpandedProp, initiallyOpened, rootRef, imperativeRef, id, onExpand, onCollapse, onOpen, onClose, onInitialInView, }: Props): React.JSX.Element;
|
|
47
50
|
displayName: string;
|
|
48
51
|
};
|
|
49
52
|
export default Collapsible;
|
package/dist/src/Collapsible.js
CHANGED
|
@@ -10,57 +10,61 @@ import { jsx as u, jsxs as d } from "react/jsx-runtime";
|
|
|
10
10
|
var f = i({
|
|
11
11
|
slots: {
|
|
12
12
|
root: "preflight [word-break:break-word]",
|
|
13
|
+
heading: "m-0 [font:inherit]",
|
|
13
14
|
trigger: [
|
|
14
15
|
"typography-h5 my-5 flex w-full justify-between gap-6 px-0.25 text-start text-clr-on-bg-high",
|
|
15
16
|
"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
|
+
"[[data-bpds=collapsible]_[data-bpds=collapsible]>*>&]:mt-0 [[data-bpds=collapsible]_[data-bpds=collapsible]>_&]:mt-0"
|
|
17
18
|
],
|
|
18
19
|
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
20
|
content: "typography-body1 overflow-hidden text-clr-on-bg-high"
|
|
20
21
|
},
|
|
21
22
|
variants: { expanded: { true: { root: "mb-5" } } }
|
|
22
|
-
}), p = ({ title: i,
|
|
23
|
-
(
|
|
24
|
-
let
|
|
25
|
-
|
|
26
|
-
},
|
|
27
|
-
|
|
23
|
+
}), p = ({ title: i, titleLevel: p, children: m, initiallyExpanded: h, initiallyOpened: g, rootRef: _, imperativeRef: v, id: y, onExpand: b, onCollapse: x, onOpen: S, onClose: C, onInitialInView: w }) => {
|
|
24
|
+
(g !== void 0 || S || C) && l("collapsible-expanded-props");
|
|
25
|
+
let T = h ?? g ?? !1, [E, D] = r(T), { root: O, heading: k, trigger: A, icon: j, content: M } = f({ expanded: E }), N = o(_, w), P = () => (b ?? S)?.(), F = () => (x ?? C)?.(), I = () => {
|
|
26
|
+
D(!0), P();
|
|
27
|
+
}, L = () => {
|
|
28
|
+
D(!1), F();
|
|
28
29
|
};
|
|
29
|
-
n(
|
|
30
|
-
expand:
|
|
31
|
-
collapse:
|
|
30
|
+
n(v, () => ({
|
|
31
|
+
expand: I,
|
|
32
|
+
collapse: L,
|
|
32
33
|
open: () => {
|
|
33
|
-
l("collapsible-expanded-props"),
|
|
34
|
+
l("collapsible-expanded-props"), I();
|
|
34
35
|
},
|
|
35
36
|
close: () => {
|
|
36
|
-
l("collapsible-expanded-props"),
|
|
37
|
+
l("collapsible-expanded-props"), L();
|
|
37
38
|
}
|
|
38
39
|
}));
|
|
39
|
-
let
|
|
40
|
-
|
|
41
|
-
},
|
|
40
|
+
let R = t(), z = y ?? R, B = () => {
|
|
41
|
+
E ? F() : P(), D(!E);
|
|
42
|
+
}, V = s(), { transitionAfterInitialRender: H } = c(), U = V ? { duration: 0 } : H, W = /* @__PURE__ */ d("button", {
|
|
43
|
+
id: z,
|
|
44
|
+
className: A(),
|
|
45
|
+
onClick: B,
|
|
46
|
+
"aria-expanded": E,
|
|
47
|
+
"aria-controls": `${z}-content`,
|
|
48
|
+
"data-state": E ? "open" : "closed",
|
|
49
|
+
type: "button",
|
|
50
|
+
children: [i, /* @__PURE__ */ u(a, { className: j() })]
|
|
51
|
+
});
|
|
42
52
|
return /* @__PURE__ */ d("div", {
|
|
43
|
-
className:
|
|
44
|
-
ref:
|
|
53
|
+
className: O(),
|
|
54
|
+
ref: N,
|
|
45
55
|
"data-bpds": "collapsible",
|
|
46
|
-
"data-bpds-initially-expanded":
|
|
47
|
-
"data-bpds-initially-opened":
|
|
48
|
-
children: [/* @__PURE__ */
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
id: `${L}-content`,
|
|
59
|
-
className: A(),
|
|
60
|
-
animate: { height: T ? "auto" : 0 },
|
|
61
|
-
transition: V,
|
|
62
|
-
inert: !T,
|
|
63
|
-
children: p
|
|
56
|
+
"data-bpds-initially-expanded": T,
|
|
57
|
+
"data-bpds-initially-opened": T,
|
|
58
|
+
children: [p ? /* @__PURE__ */ u(p, {
|
|
59
|
+
className: k(),
|
|
60
|
+
children: W
|
|
61
|
+
}) : W, /* @__PURE__ */ u(e.div, {
|
|
62
|
+
id: `${z}-content`,
|
|
63
|
+
className: M(),
|
|
64
|
+
animate: { height: E ? "auto" : 0 },
|
|
65
|
+
transition: U,
|
|
66
|
+
inert: !E,
|
|
67
|
+
children: m
|
|
64
68
|
})]
|
|
65
69
|
});
|
|
66
70
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Collapsible.js","names":["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","
|
|
1
|
+
{"version":3,"file":"Collapsible.js","names":["generateClasses","tv","Collapsible","TitleComponent","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","triggerButton","trigger","title","ArrowDownIcon","icon","root","heading","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 { ArrowDownIcon } from \"@bonprix-ds/react-icon/icons\";\nimport { TitleLevel, 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 heading: \"m-0 [font:inherit]\",\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 [[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 /** Renders the title as a heading of this level, so it is part of the page's heading structure. */\n titleLevel?: TitleLevel;\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 titleLevel: TitleComponent,\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, heading, 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 const triggerButton = (\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 <ArrowDownIcon className={icon()} />\n </button>\n );\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 {TitleComponent ? <TitleComponent className={heading()}>{triggerButton}</TitleComponent> : triggerButton}\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"],"mappings":";;;;;;;;;AAUA,IAAMA,IAAkBC,EAAG;CACzB,OAAO;EAGL,MAAM;EACN,SAAS;EACT,SAAS;GACP;GACA;GAEA;EACF;EACA,MAAM;EACN,SAAS;CACX;CACA,UAAU,EACR,UAAU,EACR,MAAM,EACJ,MAAM,OACR,EACF,EACF;AACF,CAAC,GAiDKC,KAAe,EACnB,UACA,YAAYC,GACZ,aACA,mBAAmBC,GACnB,oBACA,YACA,kBACA,OACA,aACA,eACA,WACA,YACA,yBACW;CACX,CAAIC,MAAoB,KAAA,KAAaC,KAAUC,MAASC,EAAe,4BAA4B;CACnG,IAAMC,IAAoBL,KAAyBC,KAAmB,IAChE,CAACK,GAAUC,KAAeC,EAASH,CAAiB,GACpD,EAAE,SAAM,YAAS,YAAS,SAAM,eAAYT,EAAgB,EAAE,YAAS,CAAC,GAExEa,IAAMC,EAAiBC,GAASC,CAAe,GAE/CC,WAAsBC,KAAYZ,EAAA,GAAU,GAC5Ca,WAAwBC,KAAcb,EAAA,GAAW,GAEjDc,UAAe;EAEnB,AADAV,EAAY,EAAI,GAChBM,EAAa;CACf,GAEMK,UAAiB;EAErB,AADAX,EAAY,EAAK,GACjBQ,EAAe;CACjB;CAEA,EAAoBI,UAAsB;EACxC;EACA;EACA,YAAY;GAEV,AADAf,EAAe,4BAA4B,GAC3Ca,EAAO;EACT;EACA,aAAa;GAEX,AADAb,EAAe,4BAA4B,GAC3Cc,EAAS;EACX;CACF,EAAE;CAEF,IAAME,IAAcC,EAAM,GACpBC,IAAgBC,KAAMH,GAEtBI,UAAyB;EAG7B,AAFIlB,IAAUS,EAAe,IACxBF,EAAa,GAClBN,EAAY,CAACD,CAAQ;CACvB,GAEMmB,IAAuBC,EAAwB,GAC/C,EAAE,oCAAiCC,EAAgC,GACnEC,IAAaH,IAAuB,EAAE,UAAU,EAAE,IAAII,GAEtDC,IACJ,kBAAC,UAAD;EACE,IAAIR;EACJ,WAAWS,EAAQ;EACnB,SAASP;EACT,iBAAelB;EACf,iBAAe,GAAGgB,EAAc;EAChC,cAAYhB,IAAW,SAAS;EAChC,MAAK;EAPP,UAAA,CASG0B,GACD,kBAACC,GAAD,EAAe,WAAWC,EAAK,EAAI,CAAA,CAC7B;;CAGV,OACE,kBAAC,OAAD;EACE,WAAWC,EAAK;EACX;EACL,aAAU;EACV,gCAA8B9B;EAE9B,8BAA4BA;EAN9B,UAAA,CAQGN,IAAiB,kBAACA,GAAD;GAAgB,WAAWqC,EAAQ;GAAI,UAAAN;EAA8B,CAAA,IAAIA,GAC3F,kBAACO,EAAO,KAAR;GACE,IAAI,GAAGf,EAAc;GACrB,WAAWgB,EAAQ;GACnB,SAAS,EAAE,QAAQhC,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.1
|
|
3
|
+
"version": "1.2.1",
|
|
4
4
|
"description": "Collapsible component, implemented in React, for the Bonprix Design System.",
|
|
5
5
|
"keywords": [],
|
|
6
6
|
"license": "UNLICENSED",
|
|
@@ -32,14 +32,14 @@
|
|
|
32
32
|
"provenance": true
|
|
33
33
|
},
|
|
34
34
|
"dependencies": {
|
|
35
|
-
"@bonprix-ds/react-icon": "1.
|
|
36
|
-
"@bonprix-ds/utils": "0.
|
|
37
|
-
"motion": "14.
|
|
35
|
+
"@bonprix-ds/react-icon": "1.4.1",
|
|
36
|
+
"@bonprix-ds/utils": "0.7.0",
|
|
37
|
+
"motion": "14.14.0"
|
|
38
38
|
},
|
|
39
39
|
"devDependencies": {
|
|
40
40
|
"@bonprix-ds/vite-config": "0.0.0",
|
|
41
41
|
"@types/react": "19.3.0",
|
|
42
|
-
"vite": "8.3.
|
|
42
|
+
"vite": "8.3.8"
|
|
43
43
|
},
|
|
44
44
|
"peerDependencies": {
|
|
45
45
|
"react": "^19",
|