Files
outline/app/components/ResizingHeightContainer.tsx
codegen-sh[bot] c6fc6230ff Replace useComponentSize with react-use-measure (#9838)
* Replace useComponentSize with react-use-measure

- Add react-use-measure dependency
- Replace all useComponentSize usages with useMeasure hook
- Remove useComponentSize hook file
- Update imports across all affected components:
  - app/components/Header.tsx
  - app/components/ResizingHeightContainer.tsx
  - app/scenes/Document/components/Header.tsx
  - app/scenes/Document/components/MeasuredContainer.tsx
  - shared/editor/embeds/Berrycast.tsx

Fixes #9812

* Remove unused breadcrumbsRef

The breadcrumbsRef is no longer needed since we're using breadcrumbsMeasureRef directly for measuring the breadcrumbs element.

---------

Co-authored-by: codegen-sh[bot] <131295404+codegen-sh[bot]@users.noreply.github.com>
2025-08-05 10:40:10 -04:00

55 lines
1.3 KiB
TypeScript

import { m, TargetAndTransition } from "framer-motion";
import * as React from "react";
import { mergeRefs } from "react-merge-refs";
import useMeasure from "react-use-measure";
type Props = {
/** The children to render */
children: React.ReactNode;
/** Whether to hide overflow. */
hideOverflow?: boolean;
/** A way to calculate height */
componentSizeCalculation?: "clientRectHeight" | "scrollHeight";
/** Optional animation config. */
config?: TargetAndTransition;
/** Optional styles. */
style?: React.CSSProperties;
};
/**
* Automatically animates the height of a container based on it's contents.
*/
export const ResizingHeightContainer = React.forwardRef<HTMLDivElement, Props>(
function ResizingHeightContainer_(props, forwardedRef) {
const {
hideOverflow,
children,
config = {
transition: {
duration: 0.1,
ease: "easeInOut",
},
},
style,
} = props;
const [measureRef, { height }] = useMeasure();
return (
<m.div
animate={{
...config,
height: Math.round(height),
}}
style={{
...style,
overflow: hideOverflow ? "hidden" : "inherit",
position: "relative",
}}
>
<div ref={mergeRefs([measureRef, forwardedRef])}>{children}</div>
</m.div>
);
}
);