Custom Stencil #3032
Custom Stencil
#3032
-
IntroductionPlease advise on whether this is the correct implementation. The problem is that when I start dragging my shape and hover the mouse over my stencil, it ends up on the paper, but I don't want that to happen (as in the original stencil). Am I thinking correctly? import { Icon } from '~/components'
import { FC, PointerEvent, useRef } from 'react';
import { ShapeNamesEnum } from '~/services/bpmn-jointjs/shapes/consts';
import { baseShadow } from '~/services/bpmn-jointjs/shapes/shadow';
import { useBpmnService } from '../_atomic/useBpmnService';
export const CustomStencil: FC = () => {
const { bpmnService } = useBpmnService();
const stencilRef = useRef<HTMLDivElement>(null);
const handlePointerDown = (event: PointerEvent<HTMLDivElement>) => {
const shapeShadow = event.currentTarget.dataset.shapeShadow as ShapeNamesEnum;
bpmnService?.stencil.startDragging(
baseShadow.getByName(shapeShadow),
event as unknown as Event,
);
const handlePointerUp = (event: Event) => {
if (stencilRef.current?.contains(event.target as Node)) {
bpmnService?.stencil.cancelDrag();
}
window.removeEventListener('pointerup', () => handlePointerUp);
};
window.addEventListener('pointerup', event => {
event.stopPropagation();
event.preventDefault();
handlePointerUp(event);
});
};
return (
<div
className="absolute flex flex-col items-center w-[2.75rem] top-3 left-20 p-1.5 bg-white rounded-md overflow-hidden shadow-[0px_4px_24px_0px_hsla(0,0%,40%,0.1)]"
id="stenceil"
ref={stencilRef}
>
<div
className="w-8 h-8 rounded-md base-transition hover:bg-gray-8 flex-center cursor-grab"
data-shape-shadow={baseShadow.ns.shadow.Task.get('name')}
onPointerDown={handlePointerDown}
>
<Icon className="pointer-events-none" name="activity" size={18} />
</div>
</div>
);
};Steps to reproduceNo response Restrictions & ConstraintsNo response Does your question relate to JointJS or JointJS+. Select both if applicable.JointJS+ |
Beta Was this translation helpful? Give feedback.
Answered by
kumilingus
Aug 6, 2025
Replies: 1 comment 3 replies
-
The stencil checks the drop area already:
Since you are not rendering the stencil (and use a custom one instead), this check fails. I think it would be nice to add a new option to the stencil that enables you to provide a custom stencil node. |
Beta Was this translation helpful? Give feedback.
3 replies
Answer selected by
VictorPulzz
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
stencileventelement:dragendinstead of windowpointerup.The stencil checks the drop area already:
Since you are not rendering the stencil (and use a custom one instead), this check fails. I think it would be nice to add a new option to the stencil that enables you to provide a custom stencil node.