Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/anandchowdhary/prefers-reduced-transparency
๐๏ธ Get a user's transparency preference
https://github.com/anandchowdhary/prefers-reduced-transparency
css media-queries prefers-reduced-transparency typescript
Last synced: 3 months ago
JSON representation
๐๏ธ Get a user's transparency preference
- Host: GitHub
- URL: https://github.com/anandchowdhary/prefers-reduced-transparency
- Owner: AnandChowdhary
- License: mit
- Created: 2019-05-24T13:43:52.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2024-06-18T01:59:30.000Z (8 months ago)
- Last Synced: 2024-10-22T15:44:47.624Z (3 months ago)
- Topics: css, media-queries, prefers-reduced-transparency, typescript
- Language: TypeScript
- Homepage: https://anandchowdhary.github.io/prefers-reduced-transparency/
- Size: 138 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# ๐๏ธ Prefers reduced transparency
[![Travis CI](https://img.shields.io/travis/AnandChowdhary/prefers-reduced-transparency.svg)](https://travis-ci.org/AnandChowdhary/prefers-reduced-transparency)
[![Coverage Status](https://coveralls.io/repos/github/AnandChowdhary/prefers-reduced-transparency/badge.svg?branch=master)](https://coveralls.io/github/AnandChowdhary/prefers-reduced-transparency?branch=master)
[![GitHub](https://img.shields.io/github/license/anandchowdhary/prefers-reduced-transparency.svg)](https://github.com/AnandChowdhary/prefers-reduced-transparency/blob/master/LICENSE)
![Vulnerabilities](https://img.shields.io/snyk/vulnerabilities/github/AnandChowdhary/prefers-reduced-transparency.svg)
![NPM type definitions](https://img.shields.io/npm/types/prefers-reduced-transparency.svg)
[![NPM](https://img.shields.io/npm/v/prefers-reduced-transparency.svg)](https://www.npmjs.com/package/prefers-reduced-transparency)
[![Minzipped size](https://img.shields.io/bundlephobia/minzip/prefers-reduced-transparency.svg)](https://www.npmjs.com/package/prefers-reduced-transparency)[![NPM](https://nodei.co/npm/prefers-reduced-transparency.png)](https://www.npmjs.com/package/prefers-reduced-transparency)
Prefers reduced transparency is a package that tells you whether a user prefers less transparency. It's based on the CSS `@media (prefers-reduced-transparency)`, which is part of [Media Queries Level 5](https://drafts.csswg.org/mediaqueries-5/). It's around 700 bytes minified, 300 bytes gzipped.
## โญ Usage
Add the dependency from NPM:
```bash
npm install prefers-reduced-transparency
```Import the package:
```js
import prefersReducedTransparency from "prefers-reduced-transparency";
```Then call the function:
```js
const contrastPreference = prefersReducedTransparency();
// Returns "reduce" or "no-preference"
```## ๐ก Browser support
This package only works in browsers that natively support `@media (prefers-reduced-transparency)`, so it just returns `"no-preference"` in unsupported browsers. [Current browser support](https://caniuse.com/#feat=prefers-reduced-transparency)
By passing `false` as the argument, you can get `"unsupported"` as the value for unsupported browsers:
```js
const contrastPreference = prefersReducedTransparency(false);
// Returns "reduce", "no-preference", or "unsupported"
```## ๐ ๏ธ Development
Install dependencies:
```bash
yarn
```Compile Typescript to ES6 before publishing to NPM:
```bash
yarn build
```## ๐ Media Queries Level 5
- ๐ `prefers-reduced-motion` ยท [GitHub](https://github.com/AnandChowdhary/prefers-reduced-motion) ยท [NPM](https://www.npmjs.com/package/prefers-reduced-motion)
- ๐จ `prefers-color-scheme` ยท [GitHub](https://github.com/AnandChowdhary/prefers-color-scheme) ยท [NPM](https://www.npmjs.com/package/prefers-color-scheme)
- ๐ถ๏ธ `prefers-contrast` ยท [GitHub](https://github.com/AnandChowdhary/prefers-contrast) ยท [NPM](https://www.npmjs.com/package/prefers-contrast)
- ๐๏ธ `prefers-reduced-transparency` ยท [GitHub](https://github.com/AnandChowdhary/prefers-reduced-transparency) ยท [NPM](https://www.npmjs.com/package/prefers-reduced-transparency)
- ๐ `inverted-colors` ยท [GitHub](https://github.com/AnandChowdhary/inverted-colors) ยท [NPM](https://www.npmjs.com/package/inverted-colors)
- ๐ง `environment-blending` ยท [GitHub](https://github.com/AnandChowdhary/environment-blending) ยท [NPM](https://www.npmjs.com/package/environment-blending)
- ๐ก `light-level` ยท [GitHub](https://github.com/AnandChowdhary/light-level) ยท [NPM](https://www.npmjs.com/package/light-level-css)## ๐ License
MIT