@bonprix-ds/react-collapsible 1.0.7 → 1.0.8
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.d.ts +2 -38
- package/dist/index.js +13 -13
- package/dist/index.js.map +1 -1
- package/dist/src/Collapsible.d.ts +30 -0
- package/package.json +29 -28
package/dist/index.d.ts
CHANGED
|
@@ -1,38 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
import { Ref } from 'react';
|
|
4
|
-
import { RefObject } from 'react';
|
|
5
|
-
|
|
6
|
-
declare const Collapsible: {
|
|
7
|
-
({ title, children, initiallyOpened, rootRef, imperativeRef, id, onOpen, onClose, onInitialInView }: CollapsibleProps): default_2.JSX.Element;
|
|
8
|
-
displayName: string;
|
|
9
|
-
};
|
|
10
|
-
export default Collapsible;
|
|
11
|
-
|
|
12
|
-
export declare interface CollapsibleImperativeHandle {
|
|
13
|
-
open: () => void;
|
|
14
|
-
close: () => void;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export declare interface CollapsibleProps {
|
|
18
|
-
/** Brief summary or label for the content within the component. */
|
|
19
|
-
title: ReactNode;
|
|
20
|
-
/** Content of the collapsible, which might be collapsed or expanded. */
|
|
21
|
-
children: ReactNode;
|
|
22
|
-
/** If `true`, the collapsible content will be initially opened. */
|
|
23
|
-
initiallyOpened?: boolean;
|
|
24
|
-
/** A reference to the root element. */
|
|
25
|
-
rootRef?: RefObject<HTMLDivElement | null>;
|
|
26
|
-
/** A reference to the imperative handle of the component. */
|
|
27
|
-
imperativeRef?: Ref<CollapsibleImperativeHandle>;
|
|
28
|
-
/** The id of the collapsible component. */
|
|
29
|
-
id?: string;
|
|
30
|
-
/** Callback function that is called when the collapsible component is opened. */
|
|
31
|
-
onOpen?: () => void;
|
|
32
|
-
/** Callback function that is called when the collapsible component is closed. */
|
|
33
|
-
onClose?: () => void;
|
|
34
|
-
/** Callback function that is called when the collapsible component is initially in view. */
|
|
35
|
-
onInitialInView?: () => void;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
export { }
|
|
1
|
+
export { default } from "./src/Collapsible";
|
|
2
|
+
export type { Props as CollapsibleProps, CollapsibleImperativeHandle } from "./src/Collapsible";
|
package/dist/index.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import e from "
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import
|
|
6
|
-
import {
|
|
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
7
|
import { jsx as l, jsxs as u } from "react/jsx-runtime";
|
|
8
8
|
//#region src/Collapsible.tsx
|
|
9
|
-
var d =
|
|
9
|
+
var d = i({
|
|
10
10
|
slots: {
|
|
11
11
|
root: "preflight [word-break:break-word]",
|
|
12
12
|
trigger: [
|
|
@@ -18,9 +18,9 @@ var d = c({
|
|
|
18
18
|
content: "typography-body1 text-clr-on-bg-high overflow-hidden"
|
|
19
19
|
},
|
|
20
20
|
variants: { isOpen: { true: { root: "mb-5" } } }
|
|
21
|
-
}), f = ({ title:
|
|
22
|
-
let [b, x] =
|
|
23
|
-
|
|
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
24
|
open: () => {
|
|
25
25
|
x(!0), _?.();
|
|
26
26
|
},
|
|
@@ -28,9 +28,9 @@ var d = c({
|
|
|
28
28
|
x(!1), v?.();
|
|
29
29
|
}
|
|
30
30
|
}));
|
|
31
|
-
let D =
|
|
31
|
+
let D = t(), O = g ?? D, k = () => {
|
|
32
32
|
b ? v && v() : _ && _(), x(!b);
|
|
33
|
-
}, A =
|
|
33
|
+
}, A = s(), { transitionAfterInitialRender: j } = c(), M = A ? { duration: 0 } : j;
|
|
34
34
|
return /* @__PURE__ */ u("div", {
|
|
35
35
|
className: S(),
|
|
36
36
|
ref: E,
|
|
@@ -44,11 +44,11 @@ var d = c({
|
|
|
44
44
|
"aria-controls": `${O}-content`,
|
|
45
45
|
"data-state": b ? "open" : "closed",
|
|
46
46
|
type: "button",
|
|
47
|
-
children: [
|
|
47
|
+
children: [i, /* @__PURE__ */ l(a, {
|
|
48
48
|
variant: "arrow-down",
|
|
49
49
|
className: w()
|
|
50
50
|
})]
|
|
51
|
-
}), /* @__PURE__ */ l(
|
|
51
|
+
}), /* @__PURE__ */ l(e.div, {
|
|
52
52
|
id: `${O}-content`,
|
|
53
53
|
className: T(),
|
|
54
54
|
animate: { height: b ? "auto" : 0 },
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[],"sources":["../src/Collapsible.tsx"],"sourcesContent":["\"use client\";\n\nimport
|
|
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,EACF;AACF,CAAC,GA4BK,KAAe,EAAE,UAAO,aAAU,qBAAkB,IAAO,YAAS,kBAAe,OAAI,WAAQ,YAAS,yBAA6B;CACzI,IAAM,CAAC,GAAM,KAAW,EAAS,CAAe,GAC1C,EAAE,SAAM,YAAS,SAAM,eAAY,EAAgB,EAAE,QAAQ,EAAK,CAAC,GAEnE,IAAM,EAAiB,GAAS,CAAe;CAErD,EAAoB,UAAsB;EACxC,YAAY;GAEV,AADA,EAAQ,EAAI,GACZ,IAAS;EACX;EACA,aAAa;GAEX,AADA,EAAQ,EAAK,GACb,IAAU;EACZ;CACF,EAAE;CAEF,IAAM,IAAc,EAAM,GACpB,IAAgB,KAAM,GAEtB,UAAqB;EAMzB,AALI,IACE,KAAS,EAAQ,IAEjB,KAAQ,EAAO,GAErB,EAAQ,CAAC,CAAI;CACf,GAEM,IAAuB,EAAwB,GAC/C,EAAE,oCAAiC,EAAgC,GACnE,IAAa,IAAuB,EAAE,UAAU,EAAE,IAAI;CAE5D,OACE,kBAAC,OAAD;EAAK,WAAW,EAAK;EAAQ;EAAK,aAAU;EAAc,8BAA4B;EAAtF,UAAA,CACE,kBAAC,UAAD;GACE,IAAI;GACJ,WAAW,EAAQ;GACnB,SAAS;GACT,iBAAe;GACf,iBAAe,GAAG,EAAc;GAChC,cAAY,IAAO,SAAS;GAC5B,MAAK;GAPP,UAAA,CASG,GACD,kBAAC,GAAD;IAAM,SAAQ;IAAa,WAAW,EAAK;GAAI,CAAA,CACzC;EACR,CAAA,GAAA,kBAAC,EAAO,KAAR;GACE,IAAI,GAAG,EAAc;GACrB,WAAW,EAAQ;GACnB,SAAS,EAAE,QAAQ,IAAO,SAAS,EAAE;GACzB;GACZ,OAAO,CAAC;GAEP;EACS,CAAA,CACT;;AAET;AAEA,EAAY,cAAc"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import React, { ReactNode, Ref, RefObject } from "react";
|
|
2
|
+
export interface CollapsibleImperativeHandle {
|
|
3
|
+
open: () => void;
|
|
4
|
+
close: () => void;
|
|
5
|
+
}
|
|
6
|
+
export interface Props {
|
|
7
|
+
/** Brief summary or label for the content within the component. */
|
|
8
|
+
title: ReactNode;
|
|
9
|
+
/** Content of the collapsible, which might be collapsed or expanded. */
|
|
10
|
+
children: ReactNode;
|
|
11
|
+
/** If `true`, the collapsible content will be initially opened. */
|
|
12
|
+
initiallyOpened?: boolean;
|
|
13
|
+
/** A reference to the root element. */
|
|
14
|
+
rootRef?: RefObject<HTMLDivElement | null>;
|
|
15
|
+
/** A reference to the imperative handle of the component. */
|
|
16
|
+
imperativeRef?: Ref<CollapsibleImperativeHandle>;
|
|
17
|
+
/** The id of the collapsible component. */
|
|
18
|
+
id?: string;
|
|
19
|
+
/** Callback function that is called when the collapsible component is opened. */
|
|
20
|
+
onOpen?: () => void;
|
|
21
|
+
/** Callback function that is called when the collapsible component is closed. */
|
|
22
|
+
onClose?: () => void;
|
|
23
|
+
/** Callback function that is called when the collapsible component is initially in view. */
|
|
24
|
+
onInitialInView?: () => void;
|
|
25
|
+
}
|
|
26
|
+
declare const Collapsible: {
|
|
27
|
+
({ title, children, initiallyOpened, rootRef, imperativeRef, id, onOpen, onClose, onInitialInView }: Props): React.JSX.Element;
|
|
28
|
+
displayName: string;
|
|
29
|
+
};
|
|
30
|
+
export default Collapsible;
|
package/package.json
CHANGED
|
@@ -1,14 +1,25 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bonprix-ds/react-collapsible",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.8",
|
|
4
4
|
"description": "Collapsible component, implemented in React, for the Bonprix Design System.",
|
|
5
|
-
"
|
|
6
|
-
"
|
|
7
|
-
|
|
8
|
-
|
|
5
|
+
"keywords": [],
|
|
6
|
+
"license": "UNLICENSED",
|
|
7
|
+
"author": "",
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "git+https://github.com/bonprix/design-system.git",
|
|
11
|
+
"directory": "packages/react/collapsible"
|
|
9
12
|
},
|
|
10
|
-
"
|
|
13
|
+
"files": [
|
|
14
|
+
"dist",
|
|
15
|
+
"!dist/tsconfig.tsbuildinfo",
|
|
16
|
+
"!dist/vite.config.d.ts",
|
|
17
|
+
"!dist/**/*.test.d.ts"
|
|
18
|
+
],
|
|
19
|
+
"type": "module",
|
|
11
20
|
"sideEffects": false,
|
|
21
|
+
"module": "./dist/index.js",
|
|
22
|
+
"types": "./dist/index.d.ts",
|
|
12
23
|
"exports": {
|
|
13
24
|
".": {
|
|
14
25
|
"import": "./dist/index.js",
|
|
@@ -16,35 +27,25 @@
|
|
|
16
27
|
"default": "./dist/index.js"
|
|
17
28
|
}
|
|
18
29
|
},
|
|
19
|
-
"
|
|
20
|
-
|
|
21
|
-
"
|
|
22
|
-
],
|
|
23
|
-
"keywords": [],
|
|
24
|
-
"author": "",
|
|
25
|
-
"license": "UNLICENSED",
|
|
26
|
-
"repository": {
|
|
27
|
-
"type": "git",
|
|
28
|
-
"url": "git+https://github.com/bonprix/design-system.git",
|
|
29
|
-
"directory": "packages/react/collapsible"
|
|
30
|
+
"publishConfig": {
|
|
31
|
+
"access": "public",
|
|
32
|
+
"provenance": true
|
|
30
33
|
},
|
|
31
34
|
"dependencies": {
|
|
32
|
-
"motion": "13.
|
|
33
|
-
"@bonprix-ds/react-icon": "1.2.
|
|
35
|
+
"motion": "13.4.0",
|
|
36
|
+
"@bonprix-ds/react-icon": "1.2.1",
|
|
34
37
|
"@bonprix-ds/utils": "0.2.2"
|
|
35
38
|
},
|
|
36
|
-
"peerDependencies": {
|
|
37
|
-
"react": "^19.0.0",
|
|
38
|
-
"react-dom": "^19.0.0",
|
|
39
|
-
"tailwind-variants": "0.3.1"
|
|
40
|
-
},
|
|
41
39
|
"devDependencies": {
|
|
42
|
-
"
|
|
43
|
-
"@types/react": "19.2.18",
|
|
40
|
+
"@types/react": "19.3.0",
|
|
44
41
|
"@vitejs/plugin-react": "6.1.1",
|
|
45
42
|
"rollup-preserve-directives": "1.1.3",
|
|
46
|
-
"
|
|
47
|
-
|
|
43
|
+
"vite": "8.3.0"
|
|
44
|
+
},
|
|
45
|
+
"peerDependencies": {
|
|
46
|
+
"react": "^19.3.0",
|
|
47
|
+
"react-dom": "^19.3.0",
|
|
48
|
+
"tailwind-variants": "0.3.1"
|
|
48
49
|
},
|
|
49
50
|
"scripts": {
|
|
50
51
|
"build": "vite build"
|