UNPKG

@progress/kendo-react-common

Version:

React Common package delivers common utilities that can be used with the KendoReact UI components. KendoReact Common Utilities package

85 lines (84 loc) 2.13 kB
/** * @license *------------------------------------------------------------------------------------------- * Copyright © 2025 Progress Software Corporation. All rights reserved. * Licensed under commercial license. See LICENSE.md in the package root for more information *------------------------------------------------------------------------------------------- */ "use client"; import * as n from "react"; import { useDraggable as m } from "./hooks/useDraggable.mjs"; const s = n.forwardRef((e, c) => { const l = n.useRef(null), r = n.useRef(null), t = n.useCallback( () => l.current && l.current.element ? l.current.element : l.current, [l] ); n.useImperativeHandle(r, () => ({ element: t() || null })), n.useImperativeHandle(c, () => r.current), n.useImperativeHandle(e.childRef, () => l.current); const u = n.useCallback( (a) => { e.onPress && e.onPress({ element: t(), target: r.current, event: a }); }, [t, e.onPress] ), g = n.useCallback( (a) => { e.onRelease && e.onRelease({ element: t(), target: r.current, event: a }); }, [t, e.onRelease] ), o = n.useCallback( (a) => { e.onDragStart && e.onDragStart({ element: t(), target: r.current, event: a }); }, [e, t] ), d = n.useCallback( (a) => { e.onDrag && e.onDrag({ element: t(), target: r.current, event: a }); }, [t, e.onDrag] ), i = n.useCallback( (a) => { e.onDragEnd && e.onDragEnd({ element: t(), target: r.current, event: a }); }, [t, e.onDragEnd] ); return m( l, { onPress: u, onRelease: g, onDragStart: o, onDrag: d, onDragEnd: i }, { mouseOnly: e.mouseOnly, autoScroll: e.autoScroll, hint: e.hint, scrollContainer: e.scrollContainer, context: e.context } ), e.children ? n.cloneElement(n.Children.only(e.children), { ref: l }) : null; }); s.displayName = "KendoReactDraggable"; export { s as Draggable };