Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: disabled wave effect if prefers-reduced-motion: set to reduce #745

Merged
merged 1 commit into from
Jul 16, 2024
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
37 changes: 23 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ After installing and registering the plugin, this is all you need to get started
- [trigger](#trigger)
- [disabled](#disabled)
- [respectDisabledAttribute](#respectdisabledattribute)
- [respectPrefersReducedMotion](#respectprefersreducedmotion)
- [stopPropagation](#stoppropagation)
- [tagName](#tagname)
- [Using triggers](#using-triggers)
Expand Down Expand Up @@ -240,20 +241,21 @@ export default {

### Summary

| Name | Default | Type |
| ----------------------------------------------------- | :--------------: | ----------------------------- |
| [color](#color) | `"currentColor"` | `string` |
| [initialOpacity](#initialopacity) | `0.2` | `number` |
| [finalOpacity](#finalopacity) | `0.1` | `number` |
| [duration](#duration) | `0.4` | `number` |
| [dissolveDuration](#dissolveduration) | `0.15` | `number` |
| [easing](#easing) | `ease-out` | `string` |
| [cancellationPeriod](#cancellationperiod) | `75` | `number` |
| [trigger](#trigger) | `"auto"` | `string \| boolean \| "auto"` |
| [disabled](#disabled) | `false` | `boolean` |
| [respectDisabledAttribute](#respectdisabledattribute) | `true` | `boolean` |
| [stopPropagation](#stoppropagation) | `false` | `boolean` |
| [tagName](#tagname) | `"div"` | `string` |
| Name | Default | Type |
| ------------------------------------------------------ | :--------------: | ----------------------------- |
| [color](#color) | `"currentColor"` | `string` |
| [initialOpacity](#initialopacity) | `0.2` | `number` |
| [finalOpacity](#finalopacity) | `0.1` | `number` |
| [duration](#duration) | `0.4` | `number` |
| [dissolveDuration](#dissolveduration) | `0.15` | `number` |
| [easing](#easing) | `ease-out` | `string` |
| [cancellationPeriod](#cancellationperiod) | `75` | `number` |
| [trigger](#trigger) | `"auto"` | `string \| boolean \| "auto"` |
| [disabled](#disabled) | `false` | `boolean` |
| [respectDisabledAttribute](#respectdisabledattribute) | `true` | `boolean` |
| [respectPrefersReducedMotion](#respectpreferredmotion) | `true` | `boolean` |
| [stopPropagation](#stoppropagation) | `false` | `boolean` |
| [tagName](#tagname) | `"div"` | `string` |

### Details

Expand Down Expand Up @@ -545,6 +547,13 @@ export default {
<button v-wave="{respectDisabledAttribute: false}" disabled>Click me!</button>
```

#### respectPrefersReducedMotion

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

> If `true`, the wave effect will be disabled if the user's [`prefers-reduced-motion`](https://developer.mozilla.org/en-US/docs/Web/CSS/@media/prefers-reduced-motion) preference is set to `reduce`.

#### stopPropagation

- **type:** `boolean`
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 @@ -12,6 +12,7 @@ exports[`has documented default options 1`] = `
"finalOpacity": 0.1,
"initialOpacity": 0.2,
"respectDisabledAttribute": true,
"respectPrefersReducedMotion": true,
"stopPropagation": false,
"tagName": "div",
"trigger": "auto",
Expand Down
9 changes: 9 additions & 0 deletions src/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,14 @@ interface IVWaveDirectiveOptions {
*/
respectDisabledAttribute: boolean

/**
* If `true`, the wave effect will be disabled if the user's `prefers-reduced-motion` preference is set to `reduce`.
*
* @default
* true
*/
respectPrefersReducedMotion: boolean

/**
* Prevents the pointerdown event from propagating to parent elements
*
Expand Down Expand Up @@ -144,6 +152,7 @@ const DEFAULT_PLUGIN_OPTIONS: IVWavePluginOptions = {
tagName: 'div',
disabled: false,
respectDisabledAttribute: true,
respectPrefersReducedMotion: true,
stopPropagation: false,
}

Expand Down
1 change: 1 addition & 0 deletions src/wave.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const SCALE_FACTOR = 2.05
const wave = (screenPos: Vector, el: HTMLElement, options: IVWaveDirectiveOptions) => {
if (options.disabled) return
if (options.respectDisabledAttribute && el.hasAttribute('disabled')) return
if (options.respectPrefersReducedMotion && window.matchMedia('(prefers-reduced-motion: reduce)').matches) return

const rect = el.getBoundingClientRect()
const computedStyles = window.getComputedStyle(el)
Expand Down