Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

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

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