Skip to content

Commit

Permalink
feat(resize-hub): add event when column changes
Browse files Browse the repository at this point in the history
Add the pointer event when column changes.
  • Loading branch information
megheaiulian committed Jul 5, 2024
1 parent 84e4537 commit bf94361
Showing 1 changed file with 30 additions and 27 deletions.
57 changes: 30 additions & 27 deletions lib/cosmoz-omnitable-resize-nub.js
Original file line number Diff line number Diff line change
@@ -1,38 +1,41 @@
import { useEffect, component } from '@pionjs/pion';
import { nothing } from 'lit-html';

const
ResizeNub = host => {
useEffect(() => {
let initial = 0,
initialWidth = 0;
const
move = ev => {
host.dispatchEvent(new CustomEvent('column-resize', {
const ResizeNub = (host) => {
const { column } = host;

useEffect(() => {
let initial = 0;
let initialWidth = 0;
const move = (ev) => {
host.dispatchEvent(
new CustomEvent('column-resize', {

Check warning on line 12 in lib/cosmoz-omnitable-resize-nub.js

View check run for this annotation

Codecov / codecov/patch

lib/cosmoz-omnitable-resize-nub.js#L11-L12

Added lines #L11 - L12 were not covered by tests
bubbles: true,
composed: true,
detail: {
newWidth: Math.ceil(initialWidth + ev.pageX - initial),
column: host.column
}
}));
},
stop = () => {
document.removeEventListener('pointermove', move);
document.removeEventListener('pointerup', stop);
},
start = ev => {
initial = ev.pageX;
initialWidth = host.previousElementSibling.getBoundingClientRect().width;
document.addEventListener('pointermove', move);
document.addEventListener('pointerup', stop);
};
host.addEventListener('pointerdown', start);
column,
},
}),
);

Check warning on line 20 in lib/cosmoz-omnitable-resize-nub.js

View check run for this annotation

Codecov / codecov/patch

lib/cosmoz-omnitable-resize-nub.js#L17-L20

Added lines #L17 - L20 were not covered by tests
},
stop = () => {
document.removeEventListener('pointermove', move);
document.removeEventListener('pointerup', stop);

Check warning on line 24 in lib/cosmoz-omnitable-resize-nub.js

View check run for this annotation

Codecov / codecov/patch

lib/cosmoz-omnitable-resize-nub.js#L23-L24

Added lines #L23 - L24 were not covered by tests
},
start = (ev) => {
initial = ev.pageX;
initialWidth =
host.previousElementSibling.getBoundingClientRect().width;
document.addEventListener('pointermove', move);
document.addEventListener('pointerup', stop);

Check warning on line 31 in lib/cosmoz-omnitable-resize-nub.js

View check run for this annotation

Codecov / codecov/patch

lib/cosmoz-omnitable-resize-nub.js#L27-L31

Added lines #L27 - L31 were not covered by tests
};
host.addEventListener('pointerdown', start);

return () => host.removeEventListener('pointerdown', start);
}, [host.nextElementSibling]);
return () => host.removeEventListener('pointerdown', start);
}, [column]);

return nothing;
};
return nothing;
};

customElements.define('cosmoz-omnitable-resize-nub', component(ResizeNub));

0 comments on commit bf94361

Please sign in to comment.