-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(usePreferredReducedTransparency): add new function (#4201)
Co-authored-by: Anthony Fu <[email protected]> Co-authored-by: Anthony Fu <[email protected]>
- Loading branch information
1 parent
230f800
commit 34cd7dc
Showing
6 changed files
with
76 additions
and
0 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
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
16 changes: 16 additions & 0 deletions
16
packages/core/usePreferredReducedTransparency/component.ts
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 |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { usePreferredReducedTransparency } from '@vueuse/core' | ||
import { defineComponent, reactive } from 'vue' | ||
|
||
export const UsePreferredReducedTransparency = /* #__PURE__ */ defineComponent({ | ||
name: 'UsePreferredReducedTransparency', | ||
setup(props, { slots }) { | ||
const data = reactive({ | ||
transparency: usePreferredReducedTransparency(), | ||
}) | ||
|
||
return () => { | ||
if (slots.default) | ||
return slots.default(data) | ||
} | ||
}, | ||
}) |
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 |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<script setup lang="ts"> | ||
import { usePreferredReducedTransparency } from '@vueuse/core' | ||
const transparency = usePreferredReducedTransparency() | ||
</script> | ||
|
||
<template> | ||
<note class="mb-2"> | ||
Preferred Transparency: | ||
</note> | ||
<code>{{ transparency }}</code> | ||
</template> |
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 |
---|---|---|
@@ -0,0 +1,25 @@ | ||
--- | ||
category: Browser | ||
--- | ||
|
||
# usePreferredReducedTransparency | ||
|
||
Reactive [prefers-reduced-transparency](https://developer.mozilla.org/en-US/docs/Web/CSS/@media/prefers-reduced-transparency) media query. | ||
|
||
## Usage | ||
|
||
```js | ||
import { usePreferredReducedTransparency } from '@vueuse/core' | ||
|
||
const preferredTransparency = usePreferredReducedTransparency() | ||
``` | ||
|
||
## Component Usage | ||
|
||
```vue | ||
<template> | ||
<UsePreferredReducedTransparency v-slot="{ transparency }"> | ||
Preferred Reduced transparency: {{ transparency }} | ||
</UsePreferredReducedTransparency> | ||
</template> | ||
``` |
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 |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import type { ConfigurableWindow } from '../_configurable' | ||
import { computed } from 'vue' | ||
import { useMediaQuery } from '../useMediaQuery' | ||
|
||
export type ReducedTransparencyType = 'reduce' | 'no-preference' | ||
|
||
/** | ||
* Reactive prefers-reduced-transparency media query. | ||
* | ||
* @see https://vueuse.org/usePreferredReducedTransparency | ||
* @param [options] | ||
*/ | ||
export function usePreferredReducedTransparency(options?: ConfigurableWindow) { | ||
const isReduced = useMediaQuery('(prefers-reduced-transparency: reduce)', options) | ||
|
||
return computed<ReducedTransparencyType>(() => { | ||
if (isReduced.value) | ||
return 'reduce' | ||
return 'no-preference' | ||
}) | ||
} |