[Feature request]: add contrast provider#360
Open
ihardlight wants to merge 6 commits intopacocoursey:mainfrom
Open
[Feature request]: add contrast provider#360ihardlight wants to merge 6 commits intopacocoursey:mainfrom
ihardlight wants to merge 6 commits intopacocoursey:mainfrom
Conversation
Author
|
@pacocoursey Hi! What do you think about supporting high contrast themes? |
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
I would like to be able to get not only theme from provider but user contrast preferences as well
I have developed a new library called “next-contrast,” which functions similarly to “next-themes” but with a focus on contrast.
📌 Summary
This PR introduces a new ContrastProvider and useContrast API to improve accessibility by enabling explicit support for the prefers-contrast media query. These additions make it possible to handle high-contrast themes in a declarative and ergonomic way within the existing next-themes ecosystem.
🧩 What’s Included
• ✅ ContrastProvider: context provider that detects and responds to user’s contrast preferences.
• ✅ useContrast hook: allows access to the current contrast mode and preference in a fully typed and reactive way.
• ✅ SSR-safe hydration and fallback handling for contrast preference detection.
• ✅ E2E test coverage for both system-based and user-defined contrast modes.
• ✅ Documentation updates in the README, including usage examples and configuration options.
🎯 Motivation
Many operating systems support user preferences for high or low contrast, which is essential for users with vision impairments or accessibility needs. However, there has been no built-in way to integrate this into next-themes. By adding a ContrastProvider, developers can now:
• Respect and respond to system contrast settings.
• Explicitly define and persist contrast themes
• Build UIs that adapt to both theme and contrast preferences.
This lays the groundwork for building more accessible, flexible, and user-centered Next.js applications.