Files
outline/shared/components/EventBoundary.tsx
codegen-sh[bot] e978f63217 Fix React 18 implicit children types with codemod
- Applied types-react-codemod implicit-children transform
- Updated 63 components to use React.PropsWithChildren
- Fixed React.FC types to be compatible with React 18
- Ensures proper typing for components that accept children props

This addresses React 18's removal of implicit children from component props.
2025-06-29 10:12:31 +00:00

49 lines
1.1 KiB
TypeScript

import * as React from "react";
type Props = {
children?: React.ReactNode;
className?: string;
/**
* Capture all events, pointer events, or click events.
* @default "all"
*/
captureEvents?: "all" | "pointer" | "click";
};
/**
* EventBoundary is a component that prevents events from propagating to parent elements.
* This is useful for preventing clicks or other interactions from bubbling up the DOM tree.
*/
const EventBoundary: React.FC<React.PropsWithChildren<Props>> = ({
children,
className,
captureEvents = "all",
}: Props) => {
const stopEvent = React.useCallback((event: React.SyntheticEvent) => {
event.preventDefault();
event.stopPropagation();
}, []);
let props = {};
if (captureEvents === "all" || captureEvents === "pointer") {
props = {
onPointerDown: stopEvent,
onPointerUp: stopEvent,
};
}
if (captureEvents === "all" || captureEvents === "click") {
props = {
...props,
onClick: stopEvent,
};
}
return (
<span {...props} className={className}>
{children}
</span>
);
};
export default EventBoundary;