-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(resize-hub): add event when column changes
Add the pointer event when column changes.
- Loading branch information
1 parent
84e4537
commit bf94361
Showing
1 changed file
with
30 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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', { | ||
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, | ||
}, | ||
}), | ||
); | ||
}, | ||
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); | ||
|
||
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)); |