mirror of
https://github.com/outline/outline.git
synced 2026-11-28 00:09:58 +03:00
- 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.
49 lines
1.1 KiB
TypeScript
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;
|