Files
klz-cables.com/.pnpm-store/v10/files/ff/dca38c515cbdeba6d1830b4243c39e313f2de1e2f740d97398dbdbd70b2d99ebb0fbdd249d8c9270d81fb7c8803445b413484a860ce7c3eb42d0c420a69f3a
Marc Mintel 5397309103
Some checks failed
Build & Deploy / 🔍 Prepare (push) Successful in 20s
Build & Deploy / 🧪 QA (push) Failing after 34s
Build & Deploy / 🏗️ Build (push) Has started running
Build & Deploy / 🚀 Deploy (push) Has been cancelled
Build & Deploy / 🧪 Smoke Test (push) Has been cancelled
Build & Deploy / ⚡ Lighthouse (push) Has been cancelled
Build & Deploy / 🔔 Notify (push) Has been cancelled
fix(products): fix breadcrumbs and product filtering (backport from main)
2026-02-24 16:04:21 +01:00

86 lines
2.4 KiB
Plaintext

import { jsx as _jsx } from "react/jsx-runtime";
import { useDraggable } from '@dnd-kit/core';
import React, { useId, useRef } from 'react';
import './index.scss';
const baseClass = 'draggable-with-click';
export const DraggableWithClick = ({
as = 'div',
children,
className,
disabled = false,
onClick,
onKeyDown,
ref,
thresholdPixels = 3
}) => {
const id = useId();
const {
attributes,
listeners,
setNodeRef
} = useDraggable({
id,
disabled
});
const initialPos = useRef({
x: 0,
y: 0
});
const isDragging = useRef(false);
const handlePointerDown = e => {
initialPos.current = {
x: e.clientX,
y: e.clientY
};
isDragging.current = false;
const handlePointerMove = moveEvent => {
const deltaX = Math.abs(moveEvent.clientX - initialPos.current.x);
const deltaY = Math.abs(moveEvent.clientY - initialPos.current.y);
if (deltaX > thresholdPixels || deltaY > thresholdPixels) {
isDragging.current = true;
if (listeners?.onPointerDown) {
listeners.onPointerDown(e);
// when the user starts dragging
// - call the click handler
// - remove the pointermove listener
onClick(moveEvent);
}
window.removeEventListener('pointermove', handlePointerMove);
}
};
const cleanup = () => {
window.removeEventListener('pointermove', handlePointerMove);
window.removeEventListener('pointerup', handlePointerUp);
};
const handlePointerUp = upEvent => {
cleanup();
if (!isDragging.current) {
// if the user did not drag the element
// - call the click handler
onClick(upEvent);
}
};
window.addEventListener('pointermove', handlePointerMove);
window.addEventListener('pointerup', handlePointerUp);
};
const Component = as || 'div';
return /*#__PURE__*/_jsx(Component, {
role: "button",
tabIndex: 0,
...attributes,
className: [baseClass, className, disabled ? `${baseClass}--disabled` : ''].filter(Boolean).join(' '),
onKeyDown: disabled ? undefined : onKeyDown,
onPointerDown: disabled ? undefined : onClick ? handlePointerDown : undefined,
ref: node => {
if (disabled) {
return;
}
setNodeRef(node);
if (ref) {
ref.current = node;
}
},
children: children
});
};
//# sourceMappingURL=index.js.map