slate/components/core/Selectable/selectable.js
2021-02-09 19:38:24 +01:00

27 lines
666 B
JavaScript

import * as React from "react";
import { useSelectable } from "./groupSelectable";
export default function Selectable({ children, selectableKey, style, ...props }) {
const ref = React.useRef();
const selectable = useSelectable();
React.useEffect(() => {
if (selectable) {
selectable.register(selectableKey, ref.current);
return () => selectable.unregister(selectableKey);
}
});
return (
<div
ref={ref}
style={{
cursor: selectable?.enabled ? "default" : "pointer",
pointerEvents: selectable?.enabled ? "none" : "auto",
...style,
}}
{...props}
>
{children}
</div>
);
}