All Projects β†’ anatoliygatt β†’ use-prefers-color-scheme

anatoliygatt / use-prefers-color-scheme

Licence: MIT license
πŸͺ React hook for subscribing to user's color scheme preference.

Programming Languages

typescript
32286 projects
shell
77523 projects

Projects that are alternatives of or similar to use-prefers-color-scheme

cluse
Sketch Plugin to check and adjust color contrast accessibility with live preview and sliders. Endorsed by Sketch.
Stars: ✭ 54 (+92.86%)
Mutual labels:  accessibility, a11y
csvConf2021
Data visualization accessibility talk for csv,conf,v6 (2021)
Stars: ✭ 19 (-32.14%)
Mutual labels:  accessibility, a11y
react-awesome-toasts
Toast notifications for react.
Stars: ✭ 64 (+128.57%)
Mutual labels:  accessibility, a11y
dorai-ui
Accessible, unstyled, open-sourced, and fully functional react component library for building design systems
Stars: ✭ 34 (+21.43%)
Mutual labels:  accessibility, a11y
svelte-accessible-dialog
An accessible dialog component for Svelte apps
Stars: ✭ 24 (-14.29%)
Mutual labels:  accessibility, a11y
a11ycolor
🌈 Generate the nearest accessible color
Stars: ✭ 29 (+3.57%)
Mutual labels:  accessibility, a11y
auto-vo
Screen reader automation tools by AccessLint, including VoiceOver.js and Auto-VO
Stars: ✭ 118 (+321.43%)
Mutual labels:  accessibility, a11y
AStack
The Missing SwiftUI Adaptive and Accessible Stacks Library.
Stars: ✭ 110 (+292.86%)
Mutual labels:  accessibility, a11y
aria-collapsible
A lightweight, dependency-free JavaScript module for generating progressively-enhanced collapsible regions using ARIA States and Properties.
Stars: ✭ 25 (-10.71%)
Mutual labels:  accessibility, a11y
van11y-accessible-simple-tooltip-aria
ES2015 accessible simple tooltip, using ARIA
Stars: ✭ 22 (-21.43%)
Mutual labels:  accessibility, a11y
buttonbuddy
Learn about accessible button contrast then generate your own accessible button color palette
Stars: ✭ 60 (+114.29%)
Mutual labels:  accessibility, a11y
a11y breadcrumbs
Accessible breadcrumb pattern
Stars: ✭ 44 (+57.14%)
Mutual labels:  accessibility, a11y
accessibility-for-teams
A β€˜quick-start’ guide for embedding accessibility and inclusive design practices into your team’s workflow
Stars: ✭ 80 (+185.71%)
Mutual labels:  accessibility, a11y
accessibility-ruleset-runner
eBay Accessibility Ruleset Runner automates 20% of WCAG 2.0 AA recommendations, saving time on manual testing.
Stars: ✭ 24 (-14.29%)
Mutual labels:  accessibility, a11y
aria-at
Assistive Technology ARIA Experience Assessment
Stars: ✭ 115 (+310.71%)
Mutual labels:  accessibility, a11y
sa11y
Sa11y is an accessibility quality assurance tool that visually highlights common accessibility and usability issues. Geared towards content authors, Sa11y straightforwardly identifies errors or warnings at the source with a simple tooltip on how to fix them.
Stars: ✭ 137 (+389.29%)
Mutual labels:  accessibility, a11y
lint-html-with-css
Lint HTML with CSS. A collection of CSS snippets from the hashtag #lintHTMLwithCSS on twitter. These CSS snippets intend to warn developers about common mistakes made in HTML.
Stars: ✭ 35 (+25%)
Mutual labels:  accessibility, a11y
togglific
Do you find web animations distracting? Togglific provides a distraction-free web experience!
Stars: ✭ 17 (-39.29%)
Mutual labels:  accessibility, a11y
accessible-forms
A series of HTML test cases to determine how specific elements are announced in different screen reader / browser combinations.
Stars: ✭ 159 (+467.86%)
Mutual labels:  accessibility, a11y
inclusive-elements
Accessible, lightweight, unstyled implementations of common UI controls.
Stars: ✭ 17 (-39.29%)
Mutual labels:  accessibility, a11y

use-prefers-color-scheme Logo

use-prefers-color-scheme

React hook for subscribing to user's color scheme preference.


Github CI Workflow Status NPM Version License


πŸš€ Getting Started

πŸ‡ Jump Start

npm install @anatoliygatt/use-prefers-color-scheme
import { usePrefersColorScheme } from '@anatoliygatt/use-prefers-color-scheme';

function Example() {
  const preferredColorScheme = usePrefersColorScheme();
  const isDarkColorSchemePreferred = preferredColorScheme === 'dark';
  return (
    <div>
      Preferred Color Scheme:{' '}
      {isDarkColorSchemePreferred ? '🌚 Dark' : '🌞 Light'}
    </div>
  );
}

πŸ’» Live Demo

Open in CodeSandbox

βš™οΈ Usage with Server Side Rendering (SSR)

Frameworks like Next.js and Gatsby take advantage of server-side rendering, which means that the HTML is pre-rendered at some point before it's sent to the browser. When we first render our React component tree, we don't know whether the user prefers light or dark color scheme.

It may lead to the markup mismatches during hydration. In order to prevent this, we need to set the ssr option provided by the usePrefersColorScheme() hook to true, like so:

usePrefersColorScheme({ ssr: true });

This will guarantee no markup mismatches between the original server render and the first client render, however, we will have to make a compromise: force a dark color scheme for all users in the very first render.

πŸ‘¨πŸΌβ€βš–οΈ License

MIT

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].