Drawer resizable mouse drag
Skill kjuhwa/skills-hub/skills/design/drawer-resizable-mouse-drag
Make Ant Design Drawer resizable via mouse drag with styled-components handle, min/max width constraints, and transition suppression during dragFrom its SKILL.md
npx -y skills add kjuhwa/skills-hub --skill drawer-resizable-mouse-dragAssembled from the repository path, not quoted from the project. Check it against their README if it does not work.
One thing to look at
- 0 stars0 stars. Stars are a popularity signal and not a quality one, but at this level it is likely that nobody has read this closely except its author, and you would be relying on your own review.
SKILL.md
2.1 KB, 417 tokens by cl100k_base, as published. Nobody here has run it
Resizable Drawer with Mouse Drag
Steps
-
Create resize handle with styled-components:
const ResizableHandle = styled.div` position: absolute; left: 0; top: 0; bottom: 0; width: 4px; cursor: col-resize; z-index: 10; &:hover { background: var(--color-border-interactive); } `; -
Add mouse event listeners for drag:
const onMouseDown = (e) => { e.preventDefault(); const startX = e.clientX; const startWidth = currentWidth; // Suppress transition during drag const wrapper = document.querySelector('.ant-drawer-content-wrapper'); if (wrapper) wrapper.style.transition = 'none'; const onMouseMove = (moveE) => { const newWidth = Math.min(MAX_WIDTH, Math.max(MIN_WIDTH, startWidth + (startX - moveE.clientX))); setWidth(newWidth); }; const onMouseUp = () => { if (wrapper) wrapper.style.transition = ''; document.removeEventListener('mousemove', onMouseMove); document.removeEventListener('mouseup', onMouseUp); }; document.addEventListener('mousemove', onMouseMove); document.addEventListener('mouseup', onMouseUp); }; -
Define constraints:
MIN_WIDTH = 440(minimum usable content width)MAX_WIDTH = window.innerWidth - menuOffset(don't overlap sidebar)
-
Apply width to Ant Drawer:
<Drawer width={width} {...props}> <ResizableHandle onMouseDown={onMouseDown} /> {children} </Drawer>
Key details
- Setting
transition: 'none'on.ant-drawer-content-wrapperduring drag prevents jittery animation - Restore transition on mouseup for smooth open/close animation
menuOffsetaccounts for sidebar width in the host layout
What ships with it
Read from the repository
Just SKILL.md. No reference files, no scripts.