@postenbring/hedwig-react 0.0.61 → 0.0.62
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/{chunk-2LKUHKL4.mjs → chunk-Q6REETZD.mjs} +12 -6
- package/dist/chunk-Q6REETZD.mjs.map +1 -0
- package/dist/index-no-css.js +11 -5
- package/dist/index-no-css.js.map +1 -1
- package/dist/index-no-css.mjs +1 -1
- package/dist/index.js +11 -5
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1 -1
- package/dist/show-more/index.js +11 -5
- package/dist/show-more/index.js.map +1 -1
- package/dist/show-more/index.mjs +1 -1
- package/dist/utilities/auto-animate-height.js +11 -5
- package/dist/utilities/auto-animate-height.js.map +1 -1
- package/dist/utilities/auto-animate-height.mjs +1 -1
- package/dist/utilities/index.js +11 -5
- package/dist/utilities/index.js.map +1 -1
- package/dist/utilities/index.mjs +1 -1
- package/package.json +1 -1
- package/dist/chunk-2LKUHKL4.mjs.map +0 -1
|
@@ -28,6 +28,7 @@ var AutoAnimateHeight = forwardRef(
|
|
|
28
28
|
"animationDuration",
|
|
29
29
|
"animationEasing"
|
|
30
30
|
]);
|
|
31
|
+
const timeoutRef = useRef(null);
|
|
31
32
|
const measurementRef = useRef(null);
|
|
32
33
|
const [height, setHeight] = useState(void 0);
|
|
33
34
|
const [clonedChildren, setClonedChildren] = useState(
|
|
@@ -36,13 +37,18 @@ var AutoAnimateHeight = forwardRef(
|
|
|
36
37
|
useEffect(() => {
|
|
37
38
|
if (measurementRef.current) {
|
|
38
39
|
const { height: newHeight } = measurementRef.current.getBoundingClientRect();
|
|
40
|
+
if (timeoutRef.current) {
|
|
41
|
+
clearTimeout(timeoutRef.current);
|
|
42
|
+
}
|
|
39
43
|
if (newHeight < (height != null ? height : 0)) {
|
|
40
|
-
flushSync(() => {
|
|
41
|
-
setHeight(newHeight);
|
|
42
|
-
});
|
|
43
44
|
setTimeout(() => {
|
|
44
|
-
|
|
45
|
-
|
|
45
|
+
flushSync(() => {
|
|
46
|
+
setHeight(newHeight);
|
|
47
|
+
});
|
|
48
|
+
timeoutRef.current = setTimeout(() => {
|
|
49
|
+
setClonedChildren(cloneElement(/* @__PURE__ */ jsx(Fragment, { children }), {}));
|
|
50
|
+
}, animationDurationToValue[animationDuration]);
|
|
51
|
+
});
|
|
46
52
|
} else {
|
|
47
53
|
setHeight(newHeight);
|
|
48
54
|
setClonedChildren(cloneElement(/* @__PURE__ */ jsx(Fragment, { children }), {}));
|
|
@@ -85,4 +91,4 @@ AutoAnimateHeight.displayName = "AutoAnimateHeight";
|
|
|
85
91
|
export {
|
|
86
92
|
AutoAnimateHeight
|
|
87
93
|
};
|
|
88
|
-
//# sourceMappingURL=chunk-
|
|
94
|
+
//# sourceMappingURL=chunk-Q6REETZD.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/utilities/auto-animate-height.tsx"],"sourcesContent":["import { cloneElement, forwardRef, useEffect, useRef, useState } from \"react\";\nimport { flushSync } from \"react-dom\";\nimport type { OverridableComponent } from \"../utils\";\n\nconst animationDurationToValue = {\n quick: 100,\n normal: 300,\n slow: 700,\n};\n\nexport interface AutoAnimateHeightProps {\n /**\n * Time of the animation, using the hedwig animation tokens\n * quick: 0.1s\n * normal: 0.3s\n * slow: 0.7s\n *\n * default is \"quick\"\n */\n animationDuration?: \"quick\" | \"normal\" | \"slow\";\n\n /**\n * Which hedwig easing function to use, default is \"normal\"\n */\n animationEasing?: \"in\" | \"out\" | \"normal\";\n children: React.ReactNode;\n style?: React.CSSProperties;\n}\n\n/**\n * Helper component to animate the height of the children when they change\n * It's done by rendering two versions of the passed children,\n * one hidden to measure the height and one visible to only changes after the height is measured.\n *\n * **IMPORTANT** Do not pass any components with effects (like data fetching), as they will trigger twice.\n */\nexport const AutoAnimateHeight: OverridableComponent<AutoAnimateHeightProps, HTMLDivElement> =\n forwardRef(\n (\n {\n as: Component = \"div\",\n children,\n style,\n animationDuration = \"quick\",\n animationEasing = \"normal\",\n ...rest\n },\n ref,\n ) => {\n const timeoutRef = useRef<NodeJS.Timeout | null>(null);\n const measurementRef = useRef<HTMLDivElement>(null);\n const [height, setHeight] = useState<number | undefined>(undefined);\n const [clonedChildren, setClonedChildren] = useState<React.ReactNode>(() =>\n cloneElement(<>{children}</>, {}),\n );\n useEffect(() => {\n if (measurementRef.current) {\n const { height: newHeight } = measurementRef.current.getBoundingClientRect();\n\n if (timeoutRef.current) {\n clearTimeout(timeoutRef.current);\n }\n if (newHeight < (height ?? 0)) {\n // If the children are shrinking, hold off on replacing until the animation is done\n // This way we don't get a sudden flash of empty content\n setTimeout(() => {\n flushSync(() => {\n setHeight(newHeight);\n });\n timeoutRef.current = setTimeout(() => {\n setClonedChildren(cloneElement(<>{children}</>, {}));\n }, animationDurationToValue[animationDuration]);\n });\n } else {\n setHeight(newHeight);\n setClonedChildren(cloneElement(<>{children}</>, {}));\n }\n }\n // eslint-disable-next-line react-hooks/exhaustive-deps -- I know better\n }, [children]);\n\n return (\n <Component\n ref={ref}\n style={{\n overflow: \"hidden\",\n height,\n transitionProperty: \"height\",\n transitionDuration: `var(--hds-micro-animation-duration-${animationDuration})`,\n transitionTimingFunction: `var(--hds-micro-animation-easing-${animationEasing})`,\n ...style,\n }}\n {...rest}\n >\n <div\n aria-hidden\n ref={measurementRef}\n style={{\n position: \"absolute\",\n visibility: \"hidden\",\n }}\n >\n {children}\n </div>\n {clonedChildren}\n </Component>\n );\n },\n );\nAutoAnimateHeight.displayName = \"AutoAnimateHeight\";\n"],"mappings":";;;;;;;AAAA,SAAS,cAAc,YAAY,WAAW,QAAQ,gBAAgB;AACtE,SAAS,iBAAiB;AAoDL,wBA6Bb,YA7Ba;AAjDrB,IAAM,2BAA2B;AAAA,EAC/B,OAAO;AAAA,EACP,QAAQ;AAAA,EACR,MAAM;AACR;AA4BO,IAAM,oBACX;AAAA,EACE,CACE,IAQA,QACG;AATH,iBACE;AAAA,UAAI,YAAY;A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AA,cACL,OAAO;AAAA,gBACL,UAAU;AAAA,gBACV,YAAY;AAAA,cACd;AAAA,cAEC;AAAA;AAAA,UACH;AAAA,UACC;AAAA;AAAA;AAAA,IACH;AAAA,EAEJ;AACF;AACF,kBAAkB,cAAc;","names":[]}
|
package/dist/index-no-css.js
CHANGED
|
@@ -1516,6 +1516,7 @@ var AutoAnimateHeight = (0, import_react24.forwardRef)(
|
|
|
1516
1516
|
"animationDuration",
|
|
1517
1517
|
"animationEasing"
|
|
1518
1518
|
]);
|
|
1519
|
+
const timeoutRef = (0, import_react24.useRef)(null);
|
|
1519
1520
|
const measurementRef = (0, import_react24.useRef)(null);
|
|
1520
1521
|
const [height, setHeight] = (0, import_react24.useState)(void 0);
|
|
1521
1522
|
const [clonedChildren, setClonedChildren] = (0, import_react24.useState)(
|
|
@@ -1524,13 +1525,18 @@ var AutoAnimateHeight = (0, import_react24.forwardRef)(
|
|
|
1524
1525
|
(0, import_react24.useEffect)(() => {
|
|
1525
1526
|
if (measurementRef.current) {
|
|
1526
1527
|
const { height: newHeight } = measurementRef.current.getBoundingClientRect();
|
|
1528
|
+
if (timeoutRef.current) {
|
|
1529
|
+
clearTimeout(timeoutRef.current);
|
|
1530
|
+
}
|
|
1527
1531
|
if (newHeight < (height != null ? height : 0)) {
|
|
1528
|
-
(0, import_react_dom.flushSync)(() => {
|
|
1529
|
-
setHeight(newHeight);
|
|
1530
|
-
});
|
|
1531
1532
|
setTimeout(() => {
|
|
1532
|
-
|
|
1533
|
-
|
|
1533
|
+
(0, import_react_dom.flushSync)(() => {
|
|
1534
|
+
setHeight(newHeight);
|
|
1535
|
+
});
|
|
1536
|
+
timeoutRef.current = setTimeout(() => {
|
|
1537
|
+
setClonedChildren((0, import_react24.cloneElement)(/* @__PURE__ */ (0, import_jsx_runtime29.jsx)(import_jsx_runtime29.Fragment, { children }), {}));
|
|
1538
|
+
}, animationDurationToValue[animationDuration]);
|
|
1539
|
+
});
|
|
1534
1540
|
} else {
|
|
1535
1541
|
setHeight(newHeight);
|
|
1536
1542
|
setClonedChildren((0, import_react24.cloneElement)(/* @__PURE__ */ (0, import_jsx_runtime29.jsx)(import_jsx_runtime29.Fragment, { children }), {}));
|