Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/anandchowdhary/prefers-color-scheme
🎨 Get a user's preferred color scheme using CSS @media(prefers-color-scheme)
https://github.com/anandchowdhary/prefers-color-scheme
css media-queries prefers-color-scheme typescript
Last synced: 3 months ago
JSON representation
🎨 Get a user's preferred color scheme using CSS @media(prefers-color-scheme)
- Host: GitHub
- URL: https://github.com/anandchowdhary/prefers-color-scheme
- Owner: AnandChowdhary
- License: mit
- Created: 2019-03-12T14:15:14.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2024-06-18T01:47:51.000Z (7 months ago)
- Last Synced: 2024-10-24T04:51:01.577Z (3 months ago)
- Topics: css, media-queries, prefers-color-scheme, typescript
- Language: TypeScript
- Homepage: https://anandchowdhary.github.io/prefers-color-scheme/
- Size: 139 KB
- Stars: 7
- Watchers: 3
- Forks: 1
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# 🎨 Prefers color scheme
[![Travis CI](https://img.shields.io/travis/AnandChowdhary/prefers-color-scheme.svg)](https://travis-ci.org/AnandChowdhary/prefers-color-scheme)
[![Coverage Status](https://coveralls.io/repos/github/AnandChowdhary/prefers-color-scheme/badge.svg?branch=master)](https://coveralls.io/github/AnandChowdhary/prefers-color-scheme?branch=master)
[![GitHub](https://img.shields.io/github/license/anandchowdhary/prefers-color-scheme.svg)](https://github.com/AnandChowdhary/prefers-color-scheme/blob/master/LICENSE)
![Vulnerabilities](https://img.shields.io/snyk/vulnerabilities/github/AnandChowdhary/prefers-color-scheme.svg)
![NPM type definitions](https://img.shields.io/npm/types/prefers-color-scheme.svg)
[![NPM](https://img.shields.io/npm/v/prefers-color-scheme.svg)](https://www.npmjs.com/package/prefers-color-scheme)
[![Minzipped size](https://img.shields.io/bundlephobia/minzip/prefers-color-scheme.svg)](https://www.npmjs.com/package/prefers-color-scheme)[![NPM](https://nodei.co/npm/prefers-color-scheme.png)](https://www.npmjs.com/package/prefers-color-scheme)
Prefers color scheme is a package that tells you a user's preferred color scheme. It's based on the CSS `@media (prefers-color-scheme)`. It's around 700 bytes minified, 300 bytes gzipped.
## ⭐ Usage
Add the dependency from NPM:
```bash
npm install prefers-color-scheme
```Import the package:
```js
import prefersColorScheme from "prefers-color-scheme";
```Then call the function:
```js
const colorScheme = prefersColorScheme();
// Returns "light" or "dark"
```## 💡 Browser support
This package only works in browsers that natively support `@media (prefers-color-scheme)`, so it just returns `"light"` in unsupported browsers. [Current browser support](https://caniuse.com/#feat=prefers-color-scheme)
By passing `false` as the argument, you can get `"unsupported"` as the value for unsupported browsers:
```js
const colorScheme = prefersColorScheme(false);
// Returns "light", "dark", 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