Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ After installing and registering the plugin, this is all you need to get started
- [finalOpacity](#finalopacity)
- [duration](#duration)
- [dissolveDuration](#dissolveduration)
- [waitForRelease](#waitforrelease)
- [easing](#easing)
- [cancellationPeriod](#cancellationperiod)
- [trigger](#trigger)
Expand Down Expand Up @@ -248,6 +249,7 @@ export default {
| [finalOpacity](#finalopacity) | `0.1` | `number` |
| [duration](#duration) | `0.4` | `number` |
| [dissolveDuration](#dissolveduration) | `0.15` | `number` |
| [waitForRelease](#waitforrelease) | `true` | `boolean` |
| [easing](#easing) | `ease-out` | `string` |
| [cancellationPeriod](#cancellationperiod) | `75` | `number` |
| [trigger](#trigger) | `"auto"` | `string \| boolean \| "auto"` |
Expand Down Expand Up @@ -455,6 +457,13 @@ export default {

</details>

#### waitForRelease

- **type:** `boolean`
- _default:_ `true`

> When `true`, the wave will not dissolve until the user releases the pointer.

#### easing

- **type:** `string` ([`<easing-function>`](https://developer.mozilla.org/en-US/docs/Web/CSS/transition-timing-function))
Expand Down
1 change: 1 addition & 0 deletions src/__snapshots__/options.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,6 @@ exports[`has documented default options 1`] = `
"stopPropagation": false,
"tagName": "div",
"trigger": "auto",
"waitForRelease": true,
}
`;
7 changes: 7 additions & 0 deletions src/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@ interface IVWaveDirectiveOptions {
* 0.15
*/
dissolveDuration: number
/* When `true`, the wave will not dissolve until the user releases the pointer.
*
* @default
* true
*/
waitForRelease: boolean
/**
* Any valid CSS `<timing-function>`
*
Expand Down Expand Up @@ -146,6 +152,7 @@ const DEFAULT_PLUGIN_OPTIONS: IVWavePluginOptions = {
finalOpacity: 0.1,
duration: 0.4,
dissolveDuration: 0.15,
waitForRelease: true,
easing: 'ease-out',
cancellationPeriod: 75,
trigger: 'auto',
Expand Down
8 changes: 5 additions & 3 deletions src/wave.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ const wave = (screenPos: Vector, el: HTMLElement, options: IVWaveDirectiveOption
waveContainer.appendChild(waveEl)
el.appendChild(waveContainer)

let shouldDissolveWave = false
let shouldDissolveWave = !options.waitForRelease
const releaseWave = (e?: PointerEvent) => {
if (typeof e !== 'undefined') {
document.removeEventListener('pointerup', releaseWave)
Expand Down Expand Up @@ -67,8 +67,10 @@ const wave = (screenPos: Vector, el: HTMLElement, options: IVWaveDirectiveOption
}, options.dissolveDuration * 1000)
}

document.addEventListener('pointerup', releaseWave)
document.addEventListener('pointercancel', releaseWave)
if (options.waitForRelease) {
document.addEventListener('pointerup', releaseWave)
document.addEventListener('pointercancel', releaseWave)
}

const token = setTimeout(() => {
document.removeEventListener('pointercancel', cancelWave)
Expand Down